Passive checks and multiline


#1

Maybe this is a stupid question, but I could not find the answer:
Can I have multi-line output with passive checks?

when I send a passive service check result to nagios with multiple lines, the output is cut after the first return …

Is there a way to have mulitple lines in passive checks. Would be awesome!


#2

You’ll have to create duplicate contacts and in the duplicates you would set a command for host_notification_commands/service_notification_commands that is defined to run a script.

define contact{
contact_name contact_name
alias alias
contactgroups contactgroup_names
host_notifications_enabled [0/1]
service_notifications_enabled [0/1]
host_notification_period timeperiod_name
service_notification_period timeperiod_name
host_notification_options [d,u,r,f,s,n]
service_notification_options [w,u,c,r,f,s,n]
host_notification_commands script_command
service_notification_commands script_command
email email_address
pager pager_number or pager_email_gateway
addressx additional_contact_address
can_submit_commands [0/1]
retain_status_information [0/1]
retain_nonstatus_information [0/1]
}

define command{ command_name script_command command_line /path/to/multi.sh }

The multi.sh script would read the multiline output to a variable which you could send by an email:
#!/bin/bash
output=cat /tmp/output.file
/usr/bin/printf “%b” “***** Nagios \n\nNotification Type: $NOTIFICATIONTYPE\n\nService: $SERVICEDESC\nHost: $HOSTALIAS\nAddress
: $HOSTADDRESS\nState: $SERVICESTATE\n\nDate/Time: $LONGDATETIME\n\nAdditional Info:\n\n$SERVICEOUTPUT\n
$output
" | /usr/bin/mail -a"X
-Alert: nagios" -s "
* $NOTIFICATIONTYPE Service Alert: $HOSTALIAS/$SERVICEDESC is $SERVICESTATE **” $CONTACTEMAIL

The bolded part is an output from a file with multiline output. The only thing you’ll have to deal with is handling the macro variables from nagios. You can forward them to this script through a command definition after a command_line variable as input variables for a bash script ($1, $2, $3 etc.) or you can enable environment variables in nagios.cfg which would make them accesible all over the system (but it slows down the system, read the explanation about it in nagios.cfg).


#3

I am slightly confused about the answer.
What I am trying is simply to have multiple lines in a passive check shown within nagios itself.
When I submit a check result to the …/rw/nagios.cmd file to a passive service, I have only one line because a return is interpreted as the end of the message. I mean “plugin_output” can’t contain a newline character?

] PROCESS_SERVICE_CHECK_RESULT;<host_name>;<svc_description>;<return_code>;<plugin_output>


#4

That is not possible if you’re using version 2 of Nagios, that’s why I have written a workaround.

For version 3:
nagios.sourceforge.net/docs/3_0/pluginapi.html