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

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
wally
Posts: 13
Joined: Thu Oct 23, 2014 10:10 am

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

Post 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
You do not have the required permissions to view the files attached to this post.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

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

Post 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
}
Former Nagios employee
wally
Posts: 13
Joined: Thu Oct 23, 2014 10:10 am

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

Post 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!
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

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

Post 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.
Former Nagios employee
wally
Posts: 13
Joined: Thu Oct 23, 2014 10:10 am

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

Post by wally »

Thanks, that works!

You can close this thread if you wish.
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

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

Post by slansing »

Great, yeah I'd take a look at the sourceforge documentation site, you should find tons of useful information there!
Locked