Page 2 of 5

Re: SMS Notifications with Custom script

Posted: Wed Oct 05, 2016 1:32 am
by mindspring
Is it possible that the link to the pager variable in Nagios is the problem?

I did put my cell number in the pager field under my contact, which is how it is configured in Core.

Re: SMS Notifications with Custom script

Posted: Wed Oct 05, 2016 9:23 am
by mindspring
Ok our developer asked me to switch the commands around in the script to this, it is meant to then show my number here, which it takes from pager I think.
I think this is where it's broken. Pager has my mobile number in there but perhaps it's the wrong field.

$to = $_ENV['NAGIOS_CONTACTPAGER'];
file_put_contents('/tmp/smsdebug', $to);

It now displays nothing in the smsdebug but it also comes up with this error log in apache:

wproc: stderr line 03: PHP Notice: Undefined index: NAGIOS_HOSTALIAS in /usr/local/bin/sms-notification on line 10

Not sure if this is highlighting an issue or not.
Thanks.

Re: SMS Notifications with Custom script

Posted: Wed Oct 05, 2016 1:57 pm
by lgroschen
Can you attach a copy of the entire script here?

I would guess you just have to define NAGIOS_HOSTALIAS and check if it is empty. If it's empty use a default or take the NAGIOS_HOSTALIAS out of the command.

Re: SMS Notifications with Custom script

Posted: Thu Oct 06, 2016 1:11 am
by mindspring
Ok I have attached the script and it's zipped.

Thanks.

Re: SMS Notifications with Custom script

Posted: Thu Oct 06, 2016 9:50 am
by lgroschen
I'm a little confused, on line 12 is:

Code: Select all

$NAGIOS_HOSTALIAS=$_ENV['NAGIOS_HOSTALIAS'];
but the error is on line 10, are you sure this is the same script that had the error?

Anyways, add this to line 4 of your script:

Code: Select all

file_put_contents('/tmp/smsdebug', $to);
Also, add this directly below $NAGIOS_HOSTALIAS=$_ENV['NAGIOS_HOSTALIAS'];

Code: Select all

file_put_contents('/tmp/smsdebug', $_ENV['NAGIOS_HOSTALIAS']);
file_put_contents('/tmp/smsdebug', $NAGIOS_HOSTALIAS);
Then trigger your script to get it to generate some logs and post in code blocks what the variable looks like. Have your dev look to make sure the globals are all set.

Re: SMS Notifications with Custom script

Posted: Fri Oct 07, 2016 9:09 am
by mindspring
Many thanks.
This Code:
file_put_contents('/tmp/smsdebug', $to);

was in line 4 already. I added the other lines to the script.

The file is unfortunately still blank.

Where do you think the problem lies?

Re: SMS Notifications with Custom script

Posted: Fri Oct 07, 2016 11:22 am
by lgroschen
Wasn't this log file working a few posts earlier? If it isn't check the permissions on the log file again like tmcdonald suggested. You will have to verify it's working with the 'Testing' first and then add the debugging lines from my post.

Re: SMS Notifications with Custom script

Posted: Tue Oct 11, 2016 9:08 am
by mindspring
Ok, I made the script changes. It looks like the file is being written to , but it is blank when I check the file. It did come up with this when I tailed it.


[root]@nagiosxi.mindspring.co.za /usr/local/bin] $ tail -f /tmp/smsdebug

Testingtail: /tmp/smsdebug: file truncated
Testingtail: /tmp/smsdebug: file truncated
Testingtail: /tmp/smsdebug: file truncated
Testingtail: /tmp/smsdebug: file truncated
Testingtail: /tmp/smsdebug: file truncated
Testingtail: /tmp/smsdebug: file truncated

The modified date is very current though so it's like something is being written to it and then removed again:

[root]@nagiosxi.mindspring.co.za /usr/local/bin] $ ls -al /tmp/smsdebug
-rwxrwxrwx 1 root root 0 Oct 11 16:06 /tmp/smsdebug

Re: SMS Notifications with Custom script

Posted: Tue Oct 11, 2016 9:12 am
by mindspring
Here is more proof of that:

[root]@nagiosxi.mindspring.co.za /usr/local/bin] $ ls -al /tmp/smsdebug
-rwxrwxrwx 1 root root 0 Oct 11 16:06 /tmp/smsdebug
[root]@nagiosxi.mindspring.co.za /usr/local/bin] $ ls -al /tmp/smsdebug
-rwxrwxrwx 1 root root 0 Oct 11 16:10 /tmp/smsdebug
[root]@nagiosxi.mindspring.co.za /usr/local/bin] $ cat /tmp/smsdebug
[root]@nagiosxi.mindspring.co.za /usr/local/bin] $

Re: SMS Notifications with Custom script

Posted: Tue Oct 11, 2016 11:32 am
by avandemore
Try using this syntax for all your file_put_contents calls:

Code: Select all

file_put_contents('/tmp/smsdebug', $to, FILE_APPEND);