Dynamic Notifications based on state of specific service check

Hi folks,

we decided to use SIGNL4 as primary notification target, but in case that there is a problem with internet connectivity we want to send the notification via SMS. The idea is to check the connectivity to the API of SIGNL4, and dependent on that the notfications for all configured notification object should call this last state to decide whether to send the notifications to SIGNL4 or via SMS. Has anybody build something like this already or can give me hints on how to call the check states within the notfication object?

Many thanks
Robert

Assuming you already have a script that sends to SIGNL4 now - can you catch the error condition when it cannot connect and call another script/function that sends the same notification via SMS?

Well yes, now we have two seperate scripts. My idea was to handle it in the notification object with an if clause. something like
if service_signl4-connect = ok
command send signl4
else
command send sms

I am struggling with the syntax of this on how to call state of the signl4 connect check at the time when it is needed, if it is possible. Otherwise the combined script with an built in check of the connectivity is the 2nd option

I think you could create a host object for your SIGNL4 host and a service which checks the API. Then you could implement something like this, using Icinga2’s DSL:

if (get_service(HostName, "signl4a-api-status")["state"] == 0) {
    # send noticication via SIGNL4
} else {
    # send command via SMS 
}

Best,
Daniel

2 Likes