Browse Source

probes from kamailio

drop_requests
lazedo 8 years ago
parent
commit
6a37893cbb
5 changed files with 73 additions and 4 deletions
  1. +2
    -1
      kamailio/db_queries_kazoo.cfg
  2. +16
    -0
      kamailio/defs.cfg
  3. +1
    -1
      kamailio/nodes-role.cfg
  4. +1
    -0
      kamailio/presence-reset.cfg
  5. +53
    -2
      kamailio/presence-role.cfg

+ 2
- 1
kamailio/db_queries_kazoo.cfg View File

@ -1,7 +1,7 @@
####### Database queries ######## ####### Database queries ########
#!substdef "!KZQ_CHECK_MEDIA_SERVER_INSERT!insert into dispatcher (setid, destination) select \$var(SetId), \"\$var(MediaUrl)\" where not exists(select * from dispatcher where destination = \"\$var(MediaUrl)\")!g" #!substdef "!KZQ_CHECK_MEDIA_SERVER_INSERT!insert into dispatcher (setid, destination) select \$var(SetId), \"\$var(MediaUrl)\" where not exists(select * from dispatcher where destination = \"\$var(MediaUrl)\")!g"
#!substdef "!KZQ_COUNT_ALL_SUBSCRIBERS!select a.event, count(distinct watcher_username || \"@\" || watcher_domain) count_unique, count(*) count from event_list a, active_watchers b where b.event = a.event group by a.event!g" #!substdef "!KZQ_COUNT_ALL_SUBSCRIBERS!select a.event, count(distinct watcher_username || \"@\" || watcher_domain) count_unique, count(*) count from event_list a, active_watchers b where b.event = a.event group by a.event!g"
#!substdef "!KZQ_COUNT_PRESENTITIES!select event, (select count(*) from presentity b where username = \"\$(kzE{kz.json,From}{uri.user})\" and domain = \"\$(kzE{kz.json,From}{uri.domain})\" and b.event = a.event) count from event_list a!g"
#!substdef "!KZQ_COUNT_PRESENTITIES!select event, (select count(*) from presentity b where username = \"\$(var(payload){kz.json,From}{uri.user})\" and domain = \"\$(var(payload){kz.json,From}{uri.domain})\" and b.event = a.event) count from event_list a!g"
#!substdef "!KZQ_COUNT_SUBSCRIBERS!select event, (select count(*) from active_watchers b where presentity_uri = \"\$var(presentity)\" and b.event = a.event) count from event_list a!g" #!substdef "!KZQ_COUNT_SUBSCRIBERS!select event, (select count(*) from active_watchers b where presentity_uri = \"\$var(presentity)\" and b.event = a.event) count from event_list a!g"
#!substdef "!KZQ_EVENT_PRESENCE_RESET_DELETE!delete from presentity where domain=\"\$(kzE{kz.json,Realm})\" and username = \"\$(kzE{kz.json,Username})\"!g" #!substdef "!KZQ_EVENT_PRESENCE_RESET_DELETE!delete from presentity where domain=\"\$(kzE{kz.json,Realm})\" and username = \"\$(kzE{kz.json,Username})\"!g"
#!substdef "!KZQ_HANDLE_NEW_SUBSCRIBE_DELETE1!delete from active_watchers where callid = \"\$ci\"!g" #!substdef "!KZQ_HANDLE_NEW_SUBSCRIBE_DELETE1!delete from active_watchers where callid = \"\$ci\"!g"
@ -11,3 +11,4 @@
#!substdef "!KZQ_RESET_PUBLISHER_UPDATE!update active_watchers set expires = \$TS where id in (select b.id from presentity a inner join active_watchers b on a.username = b.to_user and a.domain = b.to_domain and a.event = b.event where a.sender = \"\$var(MediaUrl)\")!g" #!substdef "!KZQ_RESET_PUBLISHER_UPDATE!update active_watchers set expires = \$TS where id in (select b.id from presentity a inner join active_watchers b on a.username = b.to_user and a.domain = b.to_domain and a.event = b.event where a.sender = \"\$var(MediaUrl)\")!g"
#!substdef "!KZQ_PRESENCE_SEARCH_DETAIL!select * from active_watchers_log where presentity_uri = \"\$var(presentity_uri)\"!g" #!substdef "!KZQ_PRESENCE_SEARCH_DETAIL!select * from active_watchers_log where presentity_uri = \"\$var(presentity_uri)\"!g"
#!substdef "!KZQ_PRESENCE_SEARCH_SUMMARY!select * from active_watchers where watcher_domain = \"\$var(Domain)\"!g" #!substdef "!KZQ_PRESENCE_SEARCH_SUMMARY!select * from active_watchers where watcher_domain = \"\$var(Domain)\"!g"
#!substdef "!KZQ_HAS_PRESENTITY!select count(*) as count from presentity where username = \"\$subs(to_user)\" and domain = \"\$subs(to_domain)\" and event = \"\$subs(event)\"!g"

+ 16
- 0
kamailio/defs.cfg View File

@ -83,4 +83,20 @@
#!endif #!endif
#!endif #!endif
#!ifndef MEDIA_SERVERS_HASH_SIZE
#!substdef "!MEDIA_SERVERS_HASH_SIZE!256!g"
#!endif
#!ifndef KZ_PRESENCE_AMQP_PUBLISH
#!define KZ_PRESENCE_AMQP_PUBLISH 0
#!endif
#!ifndef KZ_PRESENCE_REQUEST_RESUBSCRIBE_PROBE
#!define KZ_PRESENCE_REQUEST_RESUBSCRIBE_PROBE 0
#!endif
#!ifndef KZ_PRESENCE_REQUEST_PROBE
#!define KZ_PRESENCE_REQUEST_PROBE 1
#!endif
# vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab

+ 1
- 1
kamailio/nodes-role.cfg View File

@ -5,7 +5,7 @@
#!endif #!endif
#!ifndef NODES_FUDGE_FACTOR #!ifndef NODES_FUDGE_FACTOR
#!define NODES_FUDGE_FACTOR 3
#!define NODES_FUDGE_FACTOR 10
#!endif #!endif
modparam("htable", "htable", "nodes=>size=8;initval=0;autoexpire=180;"); modparam("htable", "htable", "nodes=>size=8;initval=0;autoexpire=180;");


+ 1
- 0
kamailio/presence-reset.cfg View File

@ -40,6 +40,7 @@ route[RESET_PUBLISHER]
route[RESET_ALL] route[RESET_ALL]
{ {
xlog("L_INFO", "$var(Msg-ID)|reset|received presence reset ALL\n");
sql_query("exec", "delete from presentity"); sql_query("exec", "delete from presentity");
$var(presentities) = $sqlrows(exec); $var(presentities) = $sqlrows(exec);
xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|removed $var(presentities) presentities\n"); xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|removed $var(presentities) presentities\n");


+ 53
- 2
kamailio/presence-role.cfg View File

@ -53,7 +53,9 @@ modparam("nat_traversal", "keepalive_state_file", "KAZOO_DATA_DIR/keep_alive_sta
modparam("nat_traversal", "keepalive_interval", 45) modparam("nat_traversal", "keepalive_interval", 45)
#!endif #!endif
kazoo.presence_sync_amqp = 0 descr "sync subscriptions to amqp"
kazoo.presence_sync_amqp = KZ_PRESENCE_AMQP_PUBLISH descr "sync subscriptions to amqp"
kazoo.presence_request_probe = KZ_PRESENCE_REQUEST_PROBE descr "request probe for new subscriptions"
kazoo.presence_request_resubscribe_probe = KZ_PRESENCE_REQUEST_RESUBSCRIBE_PROBE descr "request probe for resubscriptions"
#!ifdef FAST_PICKUP_ROLE #!ifdef FAST_PICKUP_ROLE
#!include_file "fast-pickup-role.cfg" #!include_file "fast-pickup-role.cfg"
@ -158,8 +160,9 @@ route[HANDLE_NEW_SUBSCRIBE]
} }
if (handle_subscribe()) { if (handle_subscribe()) {
route(SUBSCRIBE_AMQP);
xlog("L_INFO","$ci|end|new $hdr(Event) subscription from $fU to $tU in realm $fd : $sht(first=>$ci) : $sht(first=>$fU::$tU::$fd::$hdr(Event))\n"); xlog("L_INFO","$ci|end|new $hdr(Event) subscription from $fU to $tU in realm $fd : $sht(first=>$ci) : $sht(first=>$fU::$tU::$fd::$hdr(Event))\n");
route(SUBSCRIBE_AMQP);
route(REQUEST_PROBE);
} else { } else {
xlog("L_INFO", "$ci|stop|error $T_reply_code for new $hdr(Event) subscription from $fU to $tU in realm $fd\n"); xlog("L_INFO", "$ci|stop|error $T_reply_code for new $hdr(Event) subscription from $fU to $tU in realm $fd\n");
} }
@ -178,6 +181,37 @@ route[SUBSCRIBE_AMQP]
} }
} }
route[REQUEST_PROBE]
{
if( (@cfg_get.kazoo.presence_request_probe == 1 && (!has_totag()))
|| (@cfg_get.kazoo.presence_request_resubscribe_probe == 1 && has_totag()) ) {
if( route(HAS_PRESENTITY) == 0) {
if($hdr(event) == "message-summary") {
$var(mwi) = $tU;
route(REQUEST_MWI);
} else {
if($tU =~ "\*98") {
$var(mwi) = $(tU{s.substr,3,0});
route(REQUEST_MWI);
} else {
xlog("L_INFO", "$ci|sub|requesting $hdr(Event) probe for $subs(to_user) in realm $subs(to_domain)\n");
$var(rk) = "probes." + $hdr(Event);
$var(amqp_payload_request) = $_s({"Event-Category" : "presence", "Event-Name" : "probe", "Event-Package" : "$hdr(event)", "Username" : "$tU", "Realm" : "$fd", "Call-ID" : "$ci"});
kazoo_publish("presence", "$var(rk)", $var(amqp_payload_request));
}
}
}
}
}
route[REQUEST_MWI]
{
xlog("L_INFO", "$ci|sub|requesting mwi probe for $var(mwi) in realm $subs(to_domain)\n");
$var(rk) = "mwi_queries." + $(subs(to_domain){kz.encode});
$var(amqp_payload_request) = $_s({"Event-Category" : "presence", "Event-Name" : "mwi_query", "Username" : "$var(mwi)", "Realm" : "$fd", "Call-ID" : "$ci"});
kazoo_publish("presence", "$var(rk)", $var(amqp_payload_request));
}
route[HANDLE_PUBLISH] route[HANDLE_PUBLISH]
{ {
if (is_method("PUBLISH")) { if (is_method("PUBLISH")) {
@ -194,6 +228,23 @@ route[HANDLE_PUBLISH]
} }
} }
route[HAS_PRESENTITY]
{
$var(pr_user) = $subs(to_user);
$var(pr_domain) = $subs(to_domain);
$var(pr_event) = $subs(event);
$var(Query) = $_s(KZQ_HAS_PRESENTITY);
$var(res) = 0;
if (sql_xquery("cb", "$var(Query)", "subs") == 1)
{
if($xavp(subs) != $null) {
$var(res) = $xavp(subs=>count);
pv_unset("$xavp(subs)");
}
}
return $var(res);
}
route[COUNT_PRESENTITIES] route[COUNT_PRESENTITIES]
{ {
$var(Query) = $_s(KZQ_COUNT_PRESENTITIES); $var(Query) = $_s(KZQ_COUNT_PRESENTITIES);


Loading…
Cancel
Save