Hi all,
Doing a bit of a complicated setup so in this one I’m trying to assign a default to a checkcommand if a variable is not populated by a servicecheck.
So in my object Service I include a custom variable:
vars.snmp_community = “my_community”
Then in my CheckCommand I want to test, if that variable exists then use it, otherwise use default. I’ve tried two ways and neither seem to provide the desired result:
object CheckCommand "check_ifoperstatus_ifdescr" {
import “plugin-check-command”
command = [ PluginDir + “/check_ifoperstatus” ]
arguments = {
“-H” = “$address$”
“-C” = {
if (service.vars.snmp_community) {
value = “$snmp_community$”
} else {
value = “default_community”
}
}
“-v” = “2”
“-d” = “$ARG1$”
“-D” = “i”
“-t” = “35”
}
}
object CheckCommand “check_ifoperstatus_ifindex” {
import “plugin-check-command”
command = [ PluginDir + “/check_ifoperstatus” ]
arguments = {
“-H” = “$address$”
“-C” = {
if ("$snmp_community$" != “”) {
value = “$snmp_community$”
} else {
value = “default_community”
}
}
“-k” = “$ARG2$”
“-D” = “i”
“-t” = “35”
}
}
The first one errors out:
[2020-07-10 11:45:47 +0100] critical/config: Error: Error while evaluating expression: Tried to access undefined script variable ‘service’
The second one is valid, but never seems to evaluate correctly.
Any tips please guys?
Thanks