NagiosXI don't get right command parameters (Python plugin)
Posted: Tue Nov 11, 2014 6:41 am
Hi All.
I am writing a Python plugin to integrate my own monitoring system into Nagios. I am having trouble in having Nagios executing my script using the correct parameters that I am trying to pass.
So first of all here are my command.cfg and localhost.cfg extracts controlling my script:
>>>>> /usr/local/nagios/etc/commands.cfg
>>>>> /usr/local/nagios/etc/services/localhost.cfg
Here is the Python code relevant to this task:
And here is what I am seeing in the the NagiosXI web interface:
I tried a zillion of combinations between command{} and service{} configurations, but I was never able to make NagiosXI run the command understanding the meaning of the command line parameters. On NagiosXI console my script works fine:
So basically I am able to run my Python plugin on the NagiosXI console and get the right results (see the line "script output" above). It seems I don't understand how to explain to Nagios to use the testid and the command (gen-data) to control my script as the input is mixed up.
I am getting desperate after so much time spent on this..any help please?
Thanks,
Wally
I am writing a Python plugin to integrate my own monitoring system into Nagios. I am having trouble in having Nagios executing my script using the correct parameters that I am trying to pass.
So first of all here are my command.cfg and localhost.cfg extracts controlling my script:
>>>>> /usr/local/nagios/etc/commands.cfg
Code: Select all
define command {
command_name teapinagios01
command_line $USER1$/te-plugins/te-api-nagios01.py gen-data -t $ARG1$
}Code: Select all
define service {
use generic-service
host_name localhost
service_description Check Latency-Network Test-testId: 28936
check_command teapinagios01!get-data! -t 28936
}Code: Select all
parser = optparse.OptionParser()
parser.add_option('-t', '--testid', action='store', type="int", help='Test ID to monitor')
(options, args) = parser.parse_args()
if (args[0] == 'gen-data'):
<...SNIP..>I tried a zillion of combinations between command{} and service{} configurations, but I was never able to make NagiosXI run the command understanding the meaning of the command line parameters. On NagiosXI console my script works fine:
Code: Select all
[root@localhost]# ./te-api-nagios01.py -help
Usage: te-api-nagios01.py [options]
Options:
-h, --help show this help message and exit
-t TESTID, --testid=TESTID Test ID to monitor
[root@localhost te-plugins]# ./te-api-nagios01.py gen-data -t 28936
(options, args) from Python optparse:
options: {'testid': 28936}
args: ['gen-data']
SCRIPT OUTPUT >>> OK - Average Latency is 241I am getting desperate after so much time spent on this..any help please?
Thanks,
Wally