Page 1 of 1

NagiosXI don't get right command parameters (Python plugin)

Posted: Tue Nov 11, 2014 6:41 am
by wally
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

Code: Select all

define command {
   command_name           teapinagios01
   command_line           $USER1$/te-plugins/te-api-nagios01.py gen-data -t $ARG1$
}
>>>>> /usr/local/nagios/etc/services/localhost.cfg

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
}
Here is the Python code relevant to this task:

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..>
And here is what I am seeing in the the NagiosXI web interface:
Pasted_Image_11_11_2014_12_26.png
Pasted_Image_11_11_2014_12_29.png
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 241
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

Re: NagiosXI don't get right command parameters (Python plug

Posted: Tue Nov 11, 2014 10:40 am
by tmcdonald
If you want to run this:

Code: Select all

./te-api-nagios01.py gen-data -t 28936
and control the number only, then your command needs to be this:

Code: Select all

define command {
   command_name           teapinagios01
   command_line           $USER1$/te-plugins/te-api-nagios01.py gen-data -t $ARG1$
}
and your service needs to be this:

Code: Select all

define service {
   use                     generic-service
   host_name               localhost
   service_description     Check Latency-Network Test-testId: 28936
   check_command           teapinagios01!28936
}

Re: NagiosXI don't get right command parameters (Python plug

Posted: Tue Nov 11, 2014 12:02 pm
by wally
Hi Tmc,

it seems to be working, that's great! I'd like to understand the logic behind your solution, so do you have a link pointing to some explanations on how the command line parameters (and the meta carachter '!') are used in the comman{} and service{} configs?

Thanks again!

Re: NagiosXI don't get right command parameters (Python plug

Posted: Tue Nov 11, 2014 12:06 pm
by tmcdonald
As a matter of fact we do:

http://nagios.sourceforge.net/docs/3_0/macros.html#arg

It is written for Core but works the same in XI.

Re: NagiosXI don't get right command parameters (Python plug

Posted: Wed Nov 19, 2014 4:57 am
by wally
Thanks, that works!

You can close this thread if you wish.

Re: NagiosXI don't get right command parameters (Python plug

Posted: Wed Nov 19, 2014 11:23 am
by slansing
Great, yeah I'd take a look at the sourceforge documentation site, you should find tons of useful information there!