I have a rsyslog server that sends messages.
I wonder, is it possible that I can edit any of the data I forward?
In other words, one of the logs I send includes the following information:
<13>Nov 29 08:00:00 localhost CEF: 0|212|656|1|1|Bot Access Control|4| fileId=739000180002315518 sourceServiceName=
And I would be interested in changing the host name, for example. From localhost to HOST01
<13>Nov 29 08:00:00 HOST01 CEF: 0|212|656|1|1|Bot Access Control|4| fileId=739000180002315518 sourceServiceName=
I have no control over where the logs are received, only the delivery.
Best Answer
You can do this using property replacers working on the
msg
property, assuming this is where the stringlocalhost
is found.Put in your
rsyslog.conf
or similar a line defining a template called, say,newmsg
:To make this more readable here it is split over several lines, but you must use the above version:
This contains 2 uses of a replacer like this:
%msg:R,ERE,1: ...(...)... --end%
where%msg%
is the property used as input for a regexpR
, extended regexpERE
, keep only capture group 1, followed by the regexp pattern which has a capture group()
, with the replacer ended by--end
.Since this template always adds the word
HOST01
to the message you should only use it if the message actually containslocalhost
, so edit the action where you log the message to test for this, eg:Note the use of the template at the end:
; newmsg
.You can use templates when sending to a remote too, eg: