Page 1 of 1

Optional parameters in plugins

Posted: Fri Jan 23, 2015 1:45 pm
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!

Re: Optional parameters in plugins

Posted: Fri Jan 23, 2015 1:50 pm
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

Re: Optional parameters in plugins

Posted: Fri Jan 23, 2015 2:53 pm
by larryq
Thanks for the tip, I'll give it a shot.

Re: Optional parameters in plugins

Posted: Fri Jan 23, 2015 3:01 pm
by slansing
Awesome, let us know if you need further help with the definition.