Search code examples
sipkamailio

Kamailio - Dispatcher determine availability via http?


We are currently using the dispatcher module in kamailio to get the availability of gateways via the dispatch list.

It uses a health check based on if it can talk to the gateway via SIP by default. However, I would like to know if we can make the check better by also checking via a http health check?

The reason for this is because when the gateway on the other end is in courtesy shutdown the dispatcher still sends calls to it even though we would like the box to shutdown. This leads to the gateway always staying up.

Alternatively there might be a better way of handling this by sending a message back in the sip packet to kamailio.

I have read through the documentation but I can't seem to find anything like what I am looking for.


Solution

  • The Dispatcher module has Event Routes that can be called when a SIP destination goes down / up. There are no Event Routes for HTTP as it's not constantly queried in it's own thread by Dispatcher.

    Alternatively there might be a better way of handling this by sending a message back in the sip packet to kamailio.

    You can however set the dispatcher state using the ds_mark_dst([state]) function. Through this you could add a custom header in any SIP message from your box that's shutting down to tell Kamailio's Dispatcher to not use it as a destination in the future.

    If we added an imaginary header called "X-SetState" with the value "Shutdown" and send it from our box that's shutting down to Kamailio in a SIP message we could pick it up with something like this:

    is_present_hf("X-SetState"){     //If custom header is present
        xlog("Received state change request ($ru) with value $hdr(X-SetState)") 
        if($hdr(X-SetState) == "Shutdown"){ //If value of header is Shutdown
                ds_mark_dst("dp");       //Mark destatination as disabled & probing
        }
    }
    

    Obviously you'd need to add your own code to select the right dispatcher to mark inactive and ensure that the X-SetState header was only parsed if it came from your internal boxes you want to mark as down but you get the idea.

    However, I would like to know if we can make the check better by also checking via a http health check?

    Dispatcher at the moment has no support for monitoring HTTP state, but adding it wouldn't be that difficult to implement, if you're handy at C you could add support or add a feature request.

    Alternatively you could write an script to monitor HTTP status of each device and the using Kamcmd / Kamctl set the dispatcher group to down if it doesn't get a response.