Page 1 of 5
SMS Notifications with Custom script
Posted: Thu Sep 29, 2016 3:51 am
by mindspring
Hi There,
I inherited a Nagios Core server which I migrated to Nagiosxi. I am trying to get the SMS notifications working, which I migrated from Core to XI. I can see that the command is being sent but no SMS Is being sent out. See the record of this in the sms.png file attached.
I have also attached the script, which works on Core,
Is there any way I can troubleshoot this to find out where it went wrong? Perhaps using the details from sms.PNG?
See the attached commands.png which shows how the script is configured, it is done in this way on Nagios Core.
I would be grateful if someone could assist.
Thanks.
Re: SMS Notifications with Custom script
Posted: Thu Sep 29, 2016 4:14 am
by mindspring
Some more information.
Attached pic is what the contact looks like. The Pager is where I put the mobile number for SMS. This is how it was configured in Nagios Core.
Re: SMS Notifications with Custom script
Posted: Thu Sep 29, 2016 3:38 pm
by mcapra
Can you share the command line (or the entire definition) for Host_Notify_By_SMS? If you're viewing the command definition from the Core Config Manager, it would be the "Command Line" field.
Re: SMS Notifications with Custom script
Posted: Fri Sep 30, 2016 1:13 am
by mindspring
Here you go, I copied it from my Nagios Core where it worked.
Re: SMS Notifications with Custom script
Posted: Fri Sep 30, 2016 12:00 pm
by lmiltchev
Can you run the following command and show the output?
Code: Select all
ls -la /usr/local/bin | grep -i sms
Re: SMS Notifications with Custom script
Posted: Mon Oct 03, 2016 1:20 am
by mindspring
It's a symbolic link. I made the permissions the same as on the Nagios Core server.
[root]@nagiosxi.mindspring.co.za /usr/local/bin] $ ls -al | grep sms
lrwxrwxrwx 1 root root 14 Oct 3 08:18 sms-notification -> postSample.php
-rwxr-xr-x 1 root root 6589 Sep 29 09:59 postSample.php
lrwxrwxrwx 1 root root 14 Oct 3 08:18 sms-notification -> postSample.php
Re: SMS Notifications with Custom script
Posted: Mon Oct 03, 2016 4:37 pm
by tmcdonald
Do you have any links or other information about where this command script is coming from? Looking at the PHP all I can think of is to look at the Apache error logs regarding this function:
do_post_request('http://www.mymobileapi.com/api5/http5.aspx', $data);
That seems to be what is doing the bulk of the actual sending. Above that line (#109) there are settings for the username and password, which are set to literally "username" and "password" respectively. Did you sanitize those for posting here? Otherwise those will need to be set in the PHP file.
Re: SMS Notifications with Custom script
Posted: Tue Oct 04, 2016 3:13 am
by mindspring
Yes thanks I sanatized the login details.
I checked the Apache logs and grep'd for "mymobileapi" and didn't find anything. I also tried to find a way to run the script and test it on the command line but I couldn't figure that out.
Is there a way I can run the command within Nagios so it looks at all the variables. I would run ./sms-notification host ( whatever host I have configured)
Re: SMS Notifications with Custom script
Posted: Tue Oct 04, 2016 3:48 pm
by tmcdonald
The grep might not match that specific string, since usually PHP error logs do not contain the function arguments used. Try just grepping for
error instead and see if that comes up with anything.
In regards to testing it through Nagios, you've pretty much already done that by setting up the command and letting it run its course. Running it outside of nagios, even if you are using the nagios user on the CLI, won't be as accurate since the environment variables will not reflect what they would be when run through the daemon.
The only other thing I can think of at this point is to add the following the top of the PHP script:
file_put_contents('/tmp/smsdebug', 'Testing');
just underneath the
<?php bit. Then run the following as well:
Code: Select all
touch /tmp/smsdebug
chmod 777 /tmp/smsdebug
and watch that
/tmp/smsdebug file. If it is filling up with "Testing" over and over, you know the script is being fired appropriately. From there it is just a matter of debugging further. Unfortunately we are somewhat limited in how much of that we can do directly since we did not write this script, but we can give you pointers and advice on what/how to test.
Re: SMS Notifications with Custom script
Posted: Wed Oct 05, 2016 1:18 am
by mindspring
Thanks for your assistance. It looks like the script is being fired up. Let me investigate further.
[root]@nagiosxi.mindspring.co.za /usr/local/bin] $ less /tmp/smsdebug
Testing
The script is firing up.