Page 4 of 5

Re: SMS Notifications with Custom script

Posted: Fri Dec 09, 2016 1:58 am
by mindspring
Thanks I made the change to the command. Mine was slightly different yes as it used $CONTACTSMS$. I changed it to yours but still no SMS comes through.

The testing output is below:

Code: Select all


[root]@nagiosxi $ cat /tmp/TESTINGOUTPUT.txt 
$CONTACTPAGER$

Below is my contacts.cfg. My notification times are 247. I have sanatized the email and cell number

Code: Select all


define contact {
        contact_name                            waleed
        alias                                   Waleed 
        host_notifications_enabled              1
        host_notification_period                waleed_notification_times
        service_notification_period             waleed_notification_times
        host_notification_options               d,u,r,f,s,
        service_notification_options            w,u,c,r,f,s,
        host_notification_commands              host_notify_by_sms,notify-host-by-email
        service_notification_commands           notify-host-by-email
        can_submit_commands                     1
        email                                   waleed@xxxxxx
        pager                                  xxxxxxxxxx
        host_notifications_enabled              1
        service_notifications_enabled           1
        use                                     xi_contact_generic
        }       


Re: SMS Notifications with Custom script

Posted: Fri Dec 09, 2016 2:06 am
by mindspring
Yes so the difference is that on Nagios Core it has in commands.cfg

Code: Select all

define command {
        command_name    host-notify-by-sms
        command_line    /usr/local/bin/sms-notification host
}


and below in misccommands.cfg

Code: Select all


define command{
        command_name    host-notify-by-sms
        command_line    /usr/bin/printf "%b" "Host '$HOSTALIAS$' is $HOSTSTATE$\nInfo: $OUTPUT$\nTime: $DATETIME$" | /bin/mail -s "$NOTIFICATIONTYPE$ alert - Host $HOSTNAME$ is $HOSTSTATE$" $CONTACTSMS$
        }

I've just added the commands.cfg bit in XI originally.

I tested the definition suggested by @ssax's but how do these two files link to each other when misccommands.cfg doesn't exist on NagiosXI.

To invoke my sms script, it needs to be run as a command "/usr/local/bin/sms-notification host" for host

Re: SMS Notifications with Custom script

Posted: Fri Dec 09, 2016 2:41 pm
by ssax
Are you testing against a host or a service when trying to reproduce it?

misccommands.cfg is not used in XI as you stated, please go to Configure > Core Config Manager > Commands change the current one and apply config, this will put it into commands.cfg where it belongs.

Then test it and let us know the results.

Thank you

Re: SMS Notifications with Custom script

Posted: Tue Dec 13, 2016 8:55 am
by mindspring
I am testing against a host .The commands.cfg is configured as what you suggested. I also configured it like this which is the way it is on the Nagios server:

Code: Select all


/usr/local/bin/sms-notification host

This is becoming quite a challenge. I am open to trying to different mechanism for sending SMS's from within NagiosXI.

Which option would you recommend regarding this?

Re: SMS Notifications with Custom script

Posted: Tue Dec 13, 2016 6:03 pm
by ssax
Please PM me an updated copy of your profile, you can download it by going to Admin > System Config > System Profile and click the Download Profile button in the top right corner. so that I can lab it up and find out where the problem lies, this is really the only option you have for doing this (well, it requires getting the custom commands to work).

Re: SMS Notifications with Custom script

Posted: Wed Dec 14, 2016 3:33 am
by mindspring
Sure - done

Re: SMS Notifications with Custom script

Posted: Wed Dec 14, 2016 3:31 pm
by ssax
Did you restart the nagios process when you set enable_environment_macros=1 in your nagios.cfg? If not, please do that and test again.

Change your notification command to this:

Code: Select all

/bin/env > /tmp/DEBUGOUTPUT.txt
Then look at the file to see what environmental variables are set and their names, I guess you will need to use the NAGIOS_CONTACTPAGER for it to work but the script should already pull that.

We either need to get the environmental variables working or redo the script to accept passed in parameters.

Re: SMS Notifications with Custom script

Posted: Tue Dec 20, 2016 1:00 am
by mindspring
Hi There,

Thanks, I tried that but the file seems to be blank and is not being written to.

Code: Select all


[root]@nagiosxi ~] $ ls -al /tmp/DEBUGOUTPUT.txt 
-rw-r--r-- 1 root root 0 Dec 20 07:49 /tmp/DEBUGOUTPUT.txt

See the attached two pics of how I configured. Did I miss something?

Thanks.

Re: SMS Notifications with Custom script

Posted: Tue Dec 20, 2016 4:18 pm
by avandemore
You do know event handlers aren't triggered unless there is a state change right?

Re: SMS Notifications with Custom script

Posted: Thu Dec 22, 2016 6:24 am
by mindspring
Yes I did bring the server down then up again to test it but I checked in on it today and it wrote something to the file so maybe it didn't pick it up as a state change because it was too quick? Only two entries in the log file.

This is what I have in the file now. Where do we go from here?

Code: Select all


[root]@nagiosxi~] $ cat /tmp/TESTINGOUTPUT.txt 
$CONTACTPAGER$
$CONTACTPAGER$