Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
could you post your scripts? – pablo Mar 2 '11 at 18:13
I'd prefer not to - they work from the command line just fine and contain information I'm not comfortable sharing here. It's the processing that Nagios is doing with the output that is stripping the characters. The illegal_object_name_chars and illegal_macro_output_chars from the nagios.cfg have no effect on the SERVICEOUTPUT. – timd Mar 2 '11 at 18:22

Remove the characters from the illegal_macro_output_chars config option.

share|improve this answer
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. – timd Mar 2 '11 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. – Mark Wagner Mar 2 '11 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? – timd Mar 2 '11 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.)

share|improve this answer
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.) – kasperd Dec 3 '14 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.) – Tomáš Záluský Dec 3 '14 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 @_;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.