Page 3 of 5
Re: SMS Notifications with Custom script
Posted: Thu Nov 10, 2016 2:01 am
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?
Re: SMS Notifications with Custom script
Posted: Thu Nov 10, 2016 2:27 pm
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.
Re: SMS Notifications with Custom script
Posted: Mon Nov 28, 2016 8:42 am
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?
Re: SMS Notifications with Custom script
Posted: Mon Nov 28, 2016 9:47 am
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.
Re: SMS Notifications with Custom script
Posted: Mon Nov 28, 2016 2:42 pm
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?
Re: SMS Notifications with Custom script
Posted: Wed Nov 30, 2016 4:11 am
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?
Re: SMS Notifications with Custom script
Posted: Wed Nov 30, 2016 11:16 am
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
Re: SMS Notifications with Custom script
Posted: Thu Dec 08, 2016 5:38 am
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?
Re: SMS Notifications with Custom script
Posted: Thu Dec 08, 2016 5:09 pm
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
Re: SMS Notifications with Custom script
Posted: Thu Dec 08, 2016 5:17 pm
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.