SMS Notifications with Custom script

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
mindspring
Posts: 117
Joined: Thu Jul 19, 2012 10:24 am

Re: SMS Notifications with Custom script

Post by mindspring »

When I make the File_APPEND change, it stopped writing to /tmp/smsdebug.

Let me get our Dev to see if she can figure that out.

Any other ideas from your side though?
avandemore
Posts: 1597
Joined: Tue Sep 27, 2016 4:57 pm

Re: SMS Notifications with Custom script

Post by avandemore »

All we can really offer is the documentation for the function call:
http://php.net/manual/en/function.file-put-contents.php

It's pretty straight forward. You can get the logs for any related errors like a typo or something.

The other thing you could try is something like this:

Code: Select all

# script nagios.test
# watch "cat /tmp/smsdebug"
# exit
Then upload nagios.test after output has changed a few time.
Previous Nagios employee
mindspring
Posts: 117
Joined: Thu Jul 19, 2012 10:24 am

Re: SMS Notifications with Custom script

Post by mindspring »

Thanks, we have done some more digging here.

When we specifically put in the cell phone number into the script


$to ="083123456";


The number gets written to when the script is called by XI. So this tells me that there must be something wrong with the variable name we are using which is:

NAGIOS_CONTACTPAGER



I actually can't tell where these environmental variables are coming from because if I look up the Macro documentation for nagios, the contact pager variable is called


$CONTACTPAGER$


I tried this but it then didn't write to the /tmp/smsdebug file


//$to = $_ENV['CONTACTPAGER']
]

Any other ideas regarding the variable called NAGIOS_CONTACTPAGER?
mindspring
Posts: 117
Joined: Thu Jul 19, 2012 10:24 am

Re: SMS Notifications with Custom script

Post by mindspring »

Hi There,

Another update.

I see Nagios core has the misccommands.cfg which NagiosXI doesn't have. The file has a section it like this which might relate to the running of the script.

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$
        }

So the command is defined in two places, in misccommands.cfg and in commands.cfg on NagiosCore.
Could this be why the variables are not recognized on XI?

I tried changing the host-notify-by-sms in NagioXI commands to the above but that didn't work either.

Thanks.
avandemore
Posts: 1597
Joined: Tue Sep 27, 2016 4:57 pm

Re: SMS Notifications with Custom script

Post by avandemore »

misccommands.cfg is not present on a current standard install of Nagios Core.

Nagios XI has builtin SMS sending, why aren't you using that?
Previous Nagios employee
mindspring
Posts: 117
Joined: Thu Jul 19, 2012 10:24 am

Re: SMS Notifications with Custom script

Post by mindspring »

Thanks I am happy to give it to a go but not sure how reliable it is.

The SMS portal is a local provider and the SMS's come through quickly and reliably.

Which documentation would you recommend I follow on the built in SMS functionality?
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: SMS Notifications with Custom script

Post by rkennedy »

mindspring wrote:Thanks, we have done some more digging here.

When we specifically put in the cell phone number into the script


$to ="083123456";


The number gets written to when the script is called by XI. So this tells me that there must be something wrong with the variable name we are using which is:

NAGIOS_CONTACTPAGER



I actually can't tell where these environmental variables are coming from because if I look up the Macro documentation for nagios, the contact pager variable is called


$CONTACTPAGER$


I tried this but it then didn't write to the /tmp/smsdebug file


//$to = $_ENV['CONTACTPAGER']
]

Any other ideas regarding the variable called NAGIOS_CONTACTPAGER?
Where are you attempting to use these variables? Each one has a different use, and will work a bit differently depending on where you're using it.

$CONTACTPAGER$ will work a lot of places, see this link - https://assets.nagios.com/downloads/nag ... olist.html

For the environmental variables, you'll need to modify your nagios.cfg and turn them on with enable_environment_macros=1
Former Nagios Employee
mindspring
Posts: 117
Joined: Thu Jul 19, 2012 10:24 am

Re: SMS Notifications with Custom script

Post by mindspring »

I am using the variables in the script attached in the previous posting.

Thanks I added the enable_environment_macros=1 in the nagios.cfg but the script still doesn't send out SMS.

Anything else you need that I could try?
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: SMS Notifications with Custom script

Post by ssax »

You need to use $CONTACTPAGER$. Also, Using ENV is not the proper way in Core 4.X (apparently it was like that in Core 3.X), please use this:

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$" $CONTACTPAGER$
        }
I validated it works on mine by doing this:

Code: Select all

define command {
       command_name                             notify-host-by-email_copy_1
       command_line                             echo '$CONTACTPAGER$' >> /tmp/TESTINGOUTPUT.txt
}
Please post your contact definition from /usr/local/nagios/etc/contacts.cfg as well.

Thank you
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: SMS Notifications with Custom script

Post by dwhitfield »

If @ssax's suggestion doesn't work, can you PM me your Profile? You can download it by going to Admin > System Config > System Profile and click the Download Profile (not Show Profile) button in the top right corner. If for whatever reason you cannot download the profile, please put the output of Show Profile in the thread (that will at least get us some info).

After you PM the profile, please update this thread. Updating this thread is the only way for it to show back up on our dashboard.

EDIT: Profile received and shared with techs.
Locked