Recently I was working on a project that required Kamailio to constantly re-evaluate something, and generate a UAC request if the condition was met.
There’s a few use cases for this: For example you might want to get Kamailio to constantly check the number of SIP registrations and send an alert if they drop below a certain number. If a subscriber drops out in that their Registration just expires, there’s no SIP message that will come in to tell us, so we’d never be able to trigger something in the normal Kamailio request_route.
Of you might want to continually send a SIP MESSAGE to pop up on someone’s phone to drive them crazy. That’s what this example will focus on.
This is where the rtimer module comes in. You can define the check in a routing block, and then
modparam("rtimer", "timer", "name=ta;interval=60;mode=1;") modparam("rtimer", "exec", "timer=ta;route=SendMessage") route[SendMessage] { xlog("Sending annoying message"); $uac_req(method)="MESSAGE"; $uac_req(ruri)="sip:10.0.1.5:5060"; $uac_req(furi)="sip:Annoyatron 2000"; $uac_req(turi)="sip:thisphone"; $uac_req(hdrs)="Subject: Hello\r\n"; $uac_req(hdrs)=$uac_req(hdrs) + "Content-Type: text/plain\r\n"; $uac_req(body)="Hi Buddy. Just here to irritate you."; $uac_req(evroute)=1; $uac_req_send(); }