res_pjsip: Add AMI events for chan_pjsip contact lifecycle changes

Add a new ContactStatus AMI event.
Publish the following status/state changes:
Created
Removed
Reachable
Unreachable
Unknown

Contact URI, new status/state, aor and endpoint names, and the
last qualify rtt result are included in the event.

ASTERISK-25114 #close

Change-Id: Id25aae5f7122facba183273efb3e8f36c20fb61e
Reported-by: George Joseph <george.joseph@fairview5.com>
Tested-by: George Joseph <george.joseph@fairview5.com>
This commit is contained in:
George Joseph
2015-05-21 16:21:01 -06:00
parent 3a8eb3c476
commit b8ac683822
7 changed files with 173 additions and 34 deletions

View File

@@ -71,6 +71,35 @@ ASTERISK_REGISTER_FILE()
</syntax>
</managerEventInstance>
</managerEvent>
<managerEvent language="en_US" name="ContactStatus">
<managerEventInstance class="EVENT_FLAG_SYSTEM">
<synopsis>Raised when the state of a contact changes.</synopsis>
<syntax>
<parameter name="URI">
<para>This contact's URI.</para>
</parameter>
<parameter name="ContactStatus">
<para>New status of the contact.</para>
<enumlist>
<enum name="Unknown"/>
<enum name="Unreachable"/>
<enum name="Reachable"/>
<enum name="Created"/>
<enum name="Removed"/>
</enumlist>
</parameter>
<parameter name="AOR">
<para>The name of the associated aor.</para>
</parameter>
<parameter name="EndpointName">
<para>The name of the associated endpoint.</para>
</parameter>
<parameter name="RoundtripUsec">
<para>The RTT measured during the last qualify.</para>
</parameter>
</syntax>
</managerEventInstance>
</managerEvent>
***/
static struct stasis_cp_all *endpoint_cache_all;
@@ -137,6 +166,46 @@ static struct ast_manager_event_blob *peerstatus_to_ami(struct stasis_message *m
ast_str_buffer(peerstatus_event_string));
}
static struct ast_manager_event_blob *contactstatus_to_ami(struct stasis_message *msg);
STASIS_MESSAGE_TYPE_DEFN(ast_endpoint_contact_state_type,
.to_ami = contactstatus_to_ami,
);
static struct ast_manager_event_blob *contactstatus_to_ami(struct stasis_message *msg)
{
struct ast_endpoint_blob *obj = stasis_message_data(msg);
RAII_VAR(struct ast_str *, contactstatus_event_string, ast_str_create(64), ast_free);
const char *value;
if (!(value = ast_json_string_get(ast_json_object_get(obj->blob, "uri")))) {
return NULL;
}
ast_str_append(&contactstatus_event_string, 0, "URI: %s\r\n", value);
if (!(value = ast_json_string_get(ast_json_object_get(obj->blob, "contact_status")))) {
return NULL;
}
ast_str_append(&contactstatus_event_string, 0, "ContactStatus: %s\r\n", value);
if (!(value = ast_json_string_get(ast_json_object_get(obj->blob, "aor")))) {
return NULL;
}
ast_str_append(&contactstatus_event_string, 0, "AOR: %s\r\n", value);
if (!(value = ast_json_string_get(ast_json_object_get(obj->blob, "endpoint_name")))) {
return NULL;
}
ast_str_append(&contactstatus_event_string, 0, "EndpointName: %s\r\n", value);
if ((value = ast_json_string_get(ast_json_object_get(obj->blob, "roundtrip_usec")))) {
ast_str_append(&contactstatus_event_string, 0, "RoundtripUsec: %s\r\n", value);
}
return ast_manager_event_blob_create(EVENT_FLAG_SYSTEM, "ContactStatus",
"%s", ast_str_buffer(contactstatus_event_string));
}
static void endpoint_blob_dtor(void *obj)
{
struct ast_endpoint_blob *event = obj;
@@ -294,6 +363,7 @@ static void endpoints_stasis_cleanup(void)
{
STASIS_MESSAGE_TYPE_CLEANUP(ast_endpoint_snapshot_type);
STASIS_MESSAGE_TYPE_CLEANUP(ast_endpoint_state_type);
STASIS_MESSAGE_TYPE_CLEANUP(ast_endpoint_contact_state_type);
ao2_cleanup(endpoint_cache_all);
endpoint_cache_all = NULL;
@@ -312,6 +382,7 @@ int ast_endpoint_stasis_init(void)
res |= STASIS_MESSAGE_TYPE_INIT(ast_endpoint_snapshot_type);
res |= STASIS_MESSAGE_TYPE_INIT(ast_endpoint_state_type);
res |= STASIS_MESSAGE_TYPE_INIT(ast_endpoint_contact_state_type);
return res;
}