Page 1 of 1

EDIT: Nagios does not generate Alerts.

Posted: Tue Sep 03, 2013 6:33 am
by GenericM
Hello, we're moving from an old version of Nagios to NagiosXI and since we're located in Sweden we have some custom notification scripts which all seem to work except for this one which we use in our own GSM-modem in case our own email-to-sms-service would be out of order. (Centos 6.4 32-bit)

Code: Select all

/usr/bin/printf "%b" "Nagios Says: $SERVICEDESC$ on  $HOSTALIAS$ is: $SERVICESTATE$ $LONGDATETIME$ Info is: $SERVICEOUTPUT$" | /usr/local/bin/sendsms $CONTACTPAGER$
The issue here is that $CONTACTPAGER$ somehow seems to be interpreted as two strings, first being $CONTACTPAGER which is undefined and therefor null and then a normal $-sign.

This results with an SMS that tries to reach the destination "$", which of course fails.

Also tried using:

Code: Select all

/usr/local/bin/sendsms $CONTACTPAGER$ "$LONGDATETIME$ ** $NOTIFICATIONTYPE$ $HOSTALIAS$ Service Alert: $SERVICEDESC$ is $SERVICESTATE$ **"
Printing the commands normally in the shell works (replacing the variables with data and replacing $CONTACTPAGER$ with the phone number). Pager is defined to the right user.

What am I missing?

Edit: Using

Code: Select all

/usr/local/bin/sendsms $CONTACTPAGER$ "$LONGDATETIME$ ** $NOTIFICATIONTYPE$ $HOSTALIAS$ Service Alert: $SERVICEDESC$ is $SERVICESTATE$ **"
with the phone number instead of $CONTACTPAGERS$ results in a success but the management_mobile profile does not execute the appropriate notification.

Contact:

Code: Select all

define contact {
        contact_name                            testmobil
        alias                                   test
        host_notifications_enabled              1
        service_notifications_enabled           1
        host_notification_period                24x7
        service_notification_period             24x7
        host_notification_options               d,u,r,f,s,n,
        service_notification_options            w,u,c,r,f,s,n,
        host_notification_commands              notify_by_mobile
        service_notification_commands           notify_by_mobile
        can_submit_commands                     1
        retain_status_information               1
        retain_nonstatus_information            1
        pager                                   +4676#######
        }
Command:

Code: Select all

define command {
       command_name                             notify_by_mobile
       command_line                             /usr/local/bin/sendsms +4676####### "$LONGDATETIME$ ** $NOTIFICATI\
ONTYPE$ $HOSTALIAS$ Service Alert: $SERVICEDESC$ is $SERVICESTATE$ **"
}
Unless I specify "notify_by_mobile" in the event handler for the service it doesn't work.

Re: EDIT: Nagios does not generate Alerts.

Posted: Wed Sep 04, 2013 10:32 am
by sreinhardt
On point 1, I would guess and have to verify, that the alias after the pipe is not being interpreted by nagios and that is why it is showing separately. I would also suggest not using two sets of "" as printf will only send the first, or as I have done below enclose in single quotes first. You might try:

Code: Select all

/usr/bin/printf '$CONTACTPAGER$ "%b" "Nagios Says: $SERVICEDESC$ on  $HOSTALIAS$ is: $SERVICESTATE$ $LONGDATETIME$ Info is: $SERVICEOUTPUT$"' | /usr/local/bin/sendsms


Could you give more detail on what you mean by:
with the phone number instead of $CONTACTPAGERS$ results in a success but the management_mobile profile does not execute the appropriate notification.
Otherwise, the contact definition and command definition, look to be correct, and should not need to be event handlers at all, just set in the contacts notification options.