Optional parameters in plugins

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
larryq
Posts: 8
Joined: Thu Aug 28, 2014 3:11 pm

Optional parameters in plugins

Post by larryq »

Hi all,

We've written a nagios plugin using a bash shell script. It works fine, takes a few arguments, and we'd like to allow for optional parameters. I'm not sure a good way to do it however?

The plugin definition looks like this in nagios_command.cfg:

Code: Select all

define command {
        command_line                   /usr/lib/my_shell_script.sh -H $ARG1$ -P $ARG2$ -I $ARG3$ -T $ARG4$ -W $ARG5$
        command_name                   my_nagios_plugin
}
Right now a sample call to the plugin call looks like this:

Code: Select all

my_nagios_plugin!a-server-name!9200!/a/server/path!250!150
...so we have 5 parameters. What if a sixth or seventh parameter is optional, is there a way to pass a 'blank' value in there in some circumstances?
Is it ok to define $ARG6 and $ARG7 in the define command above and call the plugin like this?

Code: Select all

my_nagios_plugin!a-server-name!9200!/a/server/path!250!150!!
Worst case I suppose I can create another command definition and call it my_nagios_plugin_2 or something and pass those optional arguments to it, but wondered if there's a way to do it as described above.

Thanks!
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Optional parameters in plugins

Post by tmcdonald »

If a given argument is blank it will simply be ignored. What I would do is give it an ARG6, and if you need two args passed in just do something like this:

Code: Select all

define command {
        command_line                   /usr/lib/my_shell_script.sh -H $ARG1$ -P $ARG2$ -I $ARG3$ -T $ARG4$ -W $ARG5$ $ARG6$
        command_name                   my_nagios_plugin
}

my_nagios_plugin!a-server-name!9200!/a/server/path!250!150!-X somearg -Y anotherarg -Z moreargs
Former Nagios employee
larryq
Posts: 8
Joined: Thu Aug 28, 2014 3:11 pm

Re: Optional parameters in plugins

Post by larryq »

Thanks for the tip, I'll give it a shot.
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: Optional parameters in plugins

Post by slansing »

Awesome, let us know if you need further help with the definition.
Locked