SMS Notifications with Custom script
-
mindspring
- Posts: 117
- Joined: Thu Jul 19, 2012 10:24 am
Re: SMS Notifications with Custom script
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.
I did put my cell number in the pager field under my contact, which is how it is configured in Core.
-
mindspring
- Posts: 117
- Joined: Thu Jul 19, 2012 10:24 am
Re: SMS Notifications with Custom script
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.
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
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.
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.
/Luke
-
mindspring
- Posts: 117
- Joined: Thu Jul 19, 2012 10:24 am
Re: SMS Notifications with Custom script
Ok I have attached the script and it's zipped.
Thanks.
Thanks.
You do not have the required permissions to view the files attached to this post.
Re: SMS Notifications with Custom script
I'm a little confused, on line 12 is:
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:
Also, add this directly below $NAGIOS_HOSTALIAS=$_ENV['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.
Code: Select all
$NAGIOS_HOSTALIAS=$_ENV['NAGIOS_HOSTALIAS'];Anyways, add this to line 4 of your script:
Code: Select all
file_put_contents('/tmp/smsdebug', $to);Code: Select all
file_put_contents('/tmp/smsdebug', $_ENV['NAGIOS_HOSTALIAS']);
file_put_contents('/tmp/smsdebug', $NAGIOS_HOSTALIAS);/Luke
-
mindspring
- Posts: 117
- Joined: Thu Jul 19, 2012 10:24 am
Re: SMS Notifications with Custom script
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?
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
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.
/Luke
-
mindspring
- Posts: 117
- Joined: Thu Jul 19, 2012 10:24 am
Re: SMS Notifications with Custom script
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
[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
-
mindspring
- Posts: 117
- Joined: Thu Jul 19, 2012 10:24 am
Re: SMS Notifications with Custom script
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] $
[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] $
-
avandemore
- Posts: 1597
- Joined: Tue Sep 27, 2016 4:57 pm
Re: SMS Notifications with Custom script
Try using this syntax for all your file_put_contents calls:
Code: Select all
file_put_contents('/tmp/smsdebug', $to, FILE_APPEND);Previous Nagios employee