Icinga2 director: Own command definitions and variables

Hello Icinga community,

i defined a command in icinga2 director for a self developed plugin that expects some arguments, among them a string with an url, as option -u. so , like …/check_xml.pl -u http://foo.bar/bla
So, what i did was add the commamdn, under “Command*” put like
PluginDir +check_xml.pl -u http://foo.bar/bla
But that would mean the URL is hardcoded in the command definition, which is pretty ugly imho.
I tried adding “Arguments” in the command definition, but as i understood it, these are like fixed arguments like “–secure” or “–perfdate=yes” or so.
I fail to understand how to define that thing in a way, that i make a Service template using that command and and add this service as single service to a host and then, in this single service, add the URL that is to check. This would make the command more flexible and reusable for other URls as well. I tried playing around a bit, but did not succeed. Would the command definition then look something like this “pluginDir + check_xml.pl -u $var.httpurl$” ?
If someone could point me in the right direction i would be very thankful.



Not quite.
The correct/nice/pretty way would be to define this in the arguments tab.
Put -u in the “Argument name” line, and your variable in the “Value” line, e.g. $check_xml_http_url$ (I like to name vars according to the check they belong to and what the do/hold)
After that you can add the variable as a field via the “Fields” tab. This will have the field displayed and fillable when you use that command in a service template.

Also you don’t need to add the pluginDir to the “Command” field when creating the command. If the check script is in the default pluginDir location (/usr/lib/nagios/plugins (deb/ubuntu) or /usr/lib64/nagios/plugins rhel/centos/suse) it will be added automatically.



1 Like

To think the whole thing further, in addition to the explanations::
If you do so like described from @log1c and assign the defined command to a service, the service inherits the whole fields from the check command. So you can write the website directly to the service.
Or, if you write this information to the host object, you can access this with the macro $host.vars.[field name]$.

Which brings us back to the point that we have discussed here: Apply Serivce multiple times depending on a dict/array? - #3 by Killerloop :wink:

1 Like


thanks a lot, that worked. Of course it did. Why wouldn’t it? You are the experts. :slight_smile:
I think this will come in handy with other commands and services as well.

Again, thanks and greetings


1 Like

Hey there :slight_smile:
I would like to ask you to mark an answer as the solution, if it resolves your topic.