Nagios Not Passing Variables To Custom Commands
Posted: Tue Feb 07, 2017 2:47 pm
Wanted to get some general help in terms of variable passing from Nagios into custom scripts. I'm currently attempting to use a script which will allow for sending a ticket into JIRA (through a SOAP URL), but only if the notification is being sent is an acknowledgment. It's a PHP script, for what it's worth.
As I dig into it, I see instances where it's requesting an environment variable:
getenv("NAGIOS_NOTIFICATIONTYPE")
getenv("NAGIOS_SERVICEDESC")
But, later in the script, I get an error saying that the Nagios environment variables were never set, and it errors out.
{
// Neither the NAGIOS_SERVICEDESC or NAGIOS_HOSTNAME environment variables were set - which indicates that this scripty wasn't called from Nagios
$errstr = "Script was called, but there were no Nagios environment variables present. Script was most likely not called from Nagios. Aborting.";
trigger_error($errstr, E_USER_ERROR);
exit(1);
}
I've put a copy of the script at http://pastebin.com/HFwdkAUQ. Can't attach it as PHP's aren't liked as attachments (underatandably so). It's an older script but it's worked for me in past revisions of Nagios (I'm using the most current revision of XI right now). Questions might be:
1) In a default Nagios installation, what owner/group and permissions should this script have?
2) How can I best in a PHP script figure out if variables are being passed in, and is there a better way with a PHP script for it to request the environment variables? Realize this is being called by Nagios through a command that is part of a contact (as opposed to sending an e-mail)
Any help here is appreciated, I'm kind of lost on where to look.
As I dig into it, I see instances where it's requesting an environment variable:
getenv("NAGIOS_NOTIFICATIONTYPE")
getenv("NAGIOS_SERVICEDESC")
But, later in the script, I get an error saying that the Nagios environment variables were never set, and it errors out.
{
// Neither the NAGIOS_SERVICEDESC or NAGIOS_HOSTNAME environment variables were set - which indicates that this scripty wasn't called from Nagios
$errstr = "Script was called, but there were no Nagios environment variables present. Script was most likely not called from Nagios. Aborting.";
trigger_error($errstr, E_USER_ERROR);
exit(1);
}
I've put a copy of the script at http://pastebin.com/HFwdkAUQ. Can't attach it as PHP's aren't liked as attachments (underatandably so). It's an older script but it's worked for me in past revisions of Nagios (I'm using the most current revision of XI right now). Questions might be:
1) In a default Nagios installation, what owner/group and permissions should this script have?
2) How can I best in a PHP script figure out if variables are being passed in, and is there a better way with a PHP script for it to request the environment variables? Realize this is being called by Nagios through a command that is part of a contact (as opposed to sending an e-mail)
Any help here is appreciated, I'm kind of lost on where to look.