Table of Contents
List of Examples
Table of Contents
This module performs destinations monitoring either for itself, or on the behalf of other modules. The monitoring is done by sending SIP OPTIONS requests, more or less in the same fashion as the dispatcher module (which was the initial source for this module).
As an example of usage by other modules, see drouting, which was enhanced to use this module to monitor its gateways.
The following modules must be loaded before this module:
tm - Transaction module
The following libraries or applications must be installed before running Kamailio with this module loaded:
none
Define the interval (in seconds) ping requests are sent to destinations
Default value is 30 seconds.
Get destination status.
The Parameter destination is destination you want to check status
Returned value:
This function can be used from ANY_ROUTE.
Table of Contents
The KeepAlive module provides an internal API to be used by other Kamailio modules. This API offers support for destinations monitoring.
For internal (non-script) usage, the KeepAlive module offers to other module the possibility to register callback functions to be executed for each destination's status change.
This function registers a new destination to monitor. Monitoring of the destination starts as soon as it returns with success (0 value).
Meaning of the parameters is as follows:
uri (string) - address of destination to monitor. Valid format is [proto:]ip[:port], with:
owner (string) - module name “owning” the destination (for information purpose)
flags (integer) - destination flags (unused for now, use 0 value)
callback (ka_statechanged_f, optional) - callback function, executed on destination's state change.
The callback function is of type void (*ka_statechanged_f)(str *uri, int state, void *user_attr);
. Use NULL to set no callback.
destination's state value is one of:
user_attr (void * pointer, optional) - If callback function is setup, this parameter will be forwarded to it, as last parameter. Use NULL to set no user_attr parameter.
Returned values:
Example 2.1. Loading KeepAlive module's API from another module, adding a destination to monitor & registering a callback
... #include "../keepalive/api.h" ... keepalive_api_t ka_api; ... ... /* loading keepalive API */ if (bind_keepalive( &ka_api ) != 0) { LM_ERR("can't load KeepAlive API\n"); goto error; } ... ... /* callback function */ void my_callback(str uri, int state, void *user_attr) { printf("%.*s new state is: %d\n", uri.len, uri.str, state) } /* register a new destination */ str dest = str_init("sip:192.168.10.21:5060"); str owner = str_init("mymodule"); if (ka_api.add_destination(dest, owner, 0, my_callback, NULL) != 0) { LM_ERR("can't add destination\n"); goto error; } ...