I’m using the notification object with commands to send SNMP traps to another system. This is working fine while using custom vars in my service.
I need to use our vars as the receiving system is using other states than the standard icinga service states - e.g.:
Icinga service state = “0” => Target system state = 2
icinga “1” => Target 1
Icinga “2” => Target 4
As you can imagine now, a critical event in Icinga would trigger a clear on the other side.
My question is now: How can I change the service.state within a command’s argument using DSL?
Currently I used things like:
if (service.state == 2){
return 4
} else if (service.state == 1){
return 1
} else {
return 2
}
Not working - always a “2” is sent out.
Than I tried
var servicestate = macro("$service.state$")
if (servicestate == 2) { //or "CRITICAL"
return 4
}
...
Not working - always an empty string.
Maybe it’s quite simply, but currently I’m stucked…
System info:
Version used: icinga2 - The Icinga 2 network monitoring daemon (version: r2.14.2-1)
OS: Debian 11
Enabled features: api checker icingadb mainlog notification
Some, like the one for Teams, are DSL directly in the notification command without a separate script / program. But besides this caveat, a very valid approach.
so I finally got it running. May ideas were all ok so far - only the bash script being called had an issue
So the final solution is looking like this:
var service_host = macro("$host.name$")
var service_name = "Reachability"
if ( get_service(service_host, service_name).state == 1){
return 1
} else if (get_service(service_host, service_name).state == 2){
return 4
} else {
return 2
}
The only think which drove me crazy was sending a 0 (zero) as command argument value. It looks as Icinga is ommiting such value some how (or I didn’t find it in the doc).
By changing now value type to Icinga DSL and value to return 0
I could solve this also.