I have a Nagios check_log style perl script that is called via check_by_ssh. The log file entries can contain characters like '>' and '$', which are dangerous and not allowed in SERVICEOUTPUT or LONGSERVICEOUTPUT. The output is stripping these characters making the alerts hard to read. Is there a workaround for escaping characters in SERVICEOUTPUT, or an option to tun on this dangerous activity?
3 Answers
Remove the characters from the illegal_macro_output_chars
config option.
-
This doesn't work. I've tried this even though the comments in the nagios.cfg clearly state: This DOES NOT affect macros used in service or host check commands.– timdMar 2, 2011 at 18:29
-
Works for me(tm). I removed "$" from illegal_macro_output_chars and SERVICEOUTPUT could then contain that character. Note you remove a character from this list to allow it to be in the output macros. Mar 2, 2011 at 18:43
-
Interesting. I'm going to run some test cases to see if it works with SERVICEOUTPUT but not LONGSERVICEOUTPUT. This might be the difference. Are you calling your plugins locally, or using NRPE or check_by_ssh?– timdMar 2, 2011 at 19:03
You can bypass Nagios macros and use system variables $${NAGIOS_SERVICEOUTPUT}
and $${NAGIOS_LONGSERVICEOUTPUT}
instead, i.e. type:
command_line /usr/bin/printf "%b" "$${NAGIOS_SERVICEOUTPUT}" | /usr/bin/mail ...
in command definition. This trick utilizes fact that there exists system variable NAGIOS_FOO
for every Nagios macro $FOO$
. More info.
(Parameter illegal_macro_output_chars
seems to me to work only when showing values in Nagios web interface. It seems have no effect when used in definition of command in command_line
- the sensitive characters were still removed in that case.)
-
Please include sufficient information that the answer can be used even if the link stops working. (With the distracting animations on that page, the link is btw. not as useful as it could have been.)– kasperdDec 3, 2014 at 9:10
-
Thanks kasperd, I improved answer. (Frankly, I don't have merest problem with animation on page which terminates my 2 hours of googling.) Dec 3, 2014 at 11:53
Try escaping the output with a perl function. Without the scripts I can't provide a solution to you but here is an example:
sub esc_chars {
# will change, for example, a!!a to a\!\!a
@_ =~ s/([;<>\*\|`&\$!#\(\)\[\]\{\}:'"])/\\$1/g;
return @_;
}
or to just remove them:
sub esc_chars {
# will change, for example, a!!a to a\!\!a
@_ =~ s/([;<>\*\|`&\$!#\(\)\[\]\{\}:'"])//g;
return @_;
}
illegal_object_name_chars
andillegal_macro_output_chars
from the nagios.cfg have no effect on the SERVICEOUTPUT.