Nagios XI variables
Posted: Thu Jun 11, 2015 8:30 am
Hello everybody.
I am running Nagios XI 2014R2.0.
I have the following command definition:
$USER1$/check_procs --user=nagios -C nsca -w 76 -c 97 $ARG1$ $_HOSTCOUNT_NSCA_PROCS_OVERRIDE$
If I use it in a service definition and don’t define anything for $ARG1$, the command is run with $ARG1$ removed from the executed string. However if the host doesn't have the custom variable _count_nsca_procs_override defined, it looks like the macro placeholder $_HOSTCOUNT_NSCA_PROCS_OVERRIDE$ is left exactly as is and is executed. This results in the shell replacing $_HOSTCOUNT_NSCA_PROCS_OVERRIDE with nothing (we don’t export vars at the moment) but it leaves the trailing '$' on the command line to confuse the poor check command 8-(.
So I guess my questions are:
Is this expected?
Why isn’t the custom host macro treated the same as $ARGn$ macros. I can’t imagine that leaving the placeholder there is useful and the variable
placeholders are unique enough $_(HOST|SERVICE|...)[A-z_]+$ that they are very unlikely to match any real value on the command line.
Is there any way to have a macro expansion with a default value when the macro doesn’t exist. E.g. in the shell you can do ${variable:-default}
that is replaced by the default value if variable isn’t defined. I could easily see:
$_HOSTSOMECUSTOMVAR:-A default value if the custom \$ var isn’t defined$
as a suitable syntax.
In my original command definition, I can replace $_HOSTCOUNT_NSCA_PROCS_OVERRIDE$ with $_HOSTCOUNT_NSCA_PROCS_OVERRIDE and send the custom vars to the environment. This will use the shell to do what I want, but it is suboptimal since I have different layers replacing macros and IIRC there are performance considerations with the variables being exported to the environment.
Other suggestion on how to handle this so I can define a single command and allow overriding of the parameters at the service and host level?
Thanks.
I am running Nagios XI 2014R2.0.
I have the following command definition:
$USER1$/check_procs --user=nagios -C nsca -w 76 -c 97 $ARG1$ $_HOSTCOUNT_NSCA_PROCS_OVERRIDE$
If I use it in a service definition and don’t define anything for $ARG1$, the command is run with $ARG1$ removed from the executed string. However if the host doesn't have the custom variable _count_nsca_procs_override defined, it looks like the macro placeholder $_HOSTCOUNT_NSCA_PROCS_OVERRIDE$ is left exactly as is and is executed. This results in the shell replacing $_HOSTCOUNT_NSCA_PROCS_OVERRIDE with nothing (we don’t export vars at the moment) but it leaves the trailing '$' on the command line to confuse the poor check command 8-(.
So I guess my questions are:
Is this expected?
Why isn’t the custom host macro treated the same as $ARGn$ macros. I can’t imagine that leaving the placeholder there is useful and the variable
placeholders are unique enough $_(HOST|SERVICE|...)[A-z_]+$ that they are very unlikely to match any real value on the command line.
Is there any way to have a macro expansion with a default value when the macro doesn’t exist. E.g. in the shell you can do ${variable:-default}
that is replaced by the default value if variable isn’t defined. I could easily see:
$_HOSTSOMECUSTOMVAR:-A default value if the custom \$ var isn’t defined$
as a suitable syntax.
In my original command definition, I can replace $_HOSTCOUNT_NSCA_PROCS_OVERRIDE$ with $_HOSTCOUNT_NSCA_PROCS_OVERRIDE and send the custom vars to the environment. This will use the shell to do what I want, but it is suboptimal since I have different layers replacing macros and IIRC there are performance considerations with the variables being exported to the environment.
Other suggestion on how to handle this so I can define a single command and allow overriding of the parameters at the service and host level?
Thanks.