Development -> Sand Box -> Event Notification Interface
OpenSIPS will be improved with an event notification mechanism. This new feature will provide an interface for external applications to be notified when certain events occur.
External applications can interact with OpenSIPS through the MI commands. This is a pull based mechanism, meaning when you need an information you have to interrogate the proxy. If an application needs to take some actions based on a certain event, it needs to periodically query OpenSIPS and decide if that event occurred or not. As you figured out, this is not an optimal solution since the external application will spend a lot of time and load detecting if the event was raised or not, instead of executing the desired action. That's why we needed a push based mechanism, so that OpenSIPS can notify an external application each time an event is raised.
Each OpenSIPS module will export a number of events, managed by the event notification mechanism. External applications will be able to subscribe for these events through the event interface. When an event is raised by a module, OpenSIPS searches for all applications subscribed for it, and sends them a notification message. Once an external application receives a notification, it can execute the desired action.
2011/05/25 - Initial implementation This version implements the following functions:
You can push different events from script, modules and even core. There are two types of events:
raise_event(event_name[, attrs] [, vals])
This function receives the event name, and optionally two AVPs. 'attrs' should contain a list of attributes name. 'vals' should contain the attributes values. Note that 'attrs' and 'vals' cardinality must be the same. An example of usage is:
$avp(s:attr) = "number";
$avp(s:val) = 0;
$avp(s:attr) = "string";
$avp(s:val) = "dummy value";
raise_event("E_DUMMY", $avp(s:attr), $avp(s:val));
In order to subscribe for an event you should send to OpenSIPS MI command the command event_subscribe with three parameters:
An example of FIFO subscribe command is:
This command subscribes the external application for the event E_DUMMY. It also informs OpenSIPS Event Interface that it wants to be notified when events occur using UDP transfer protocol on localhost, port 8081, and the subscription will expire after 1800 seconds.
For more information about socket description and transport modules you can consult OpenSIPS documentation.
You can unsubscribe for an event by simply send an MI command with the expiration field 0. Note that the socket must be the same with the initial subscription, otherwise it won't be matched.
When an event is fired, OpenSIPS event notification will try to notify all the subscribers. For that it will search for the desired transport protocol, pack the data and send it to the destination specified in subscription.
This version contains only 'event_datagram' transport module that supports UNIX and UDP sockets.