Browse Source

KAZOO-5623: Added PostgreSQL support

4.2
Sergey Safarov 8 years ago
committed by lazedo
parent
commit
fac9dcbd43
10 changed files with 59 additions and 20 deletions
  1. +12
    -1
      kamailio/db_queries_kazoo.cfg
  2. +12
    -1
      kamailio/db_queries_mysql.cfg
  3. +13
    -0
      kamailio/db_queries_postgres.cfg
  4. +1
    -1
      kamailio/default.cfg
  5. +1
    -1
      kamailio/dispatcher-role.cfg
  6. +4
    -0
      kamailio/local.cfg
  7. +8
    -8
      kamailio/presence-reset.cfg
  8. +5
    -5
      kamailio/presence-role.cfg
  9. +2
    -2
      kamailio/presence_query-role.cfg
  10. +1
    -1
      kamailio/registrar-sync-role.cfg

+ 12
- 1
kamailio/db_queries_kazoo.cfg View File

@ -1,2 +1,13 @@
####### Database queries ######## ####### Database queries ########
#!substdef "!DISPATCHER_CHECK_MEDIA_SERVER_INSERT_QUERY!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_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_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_HANDLE_NEW_SUBSCRIBE_DELETE1!delete from active_watchers where callid = \"\$ci\"!g"
#!substdef "!KZQ_HANDLE_NEW_SUBSCRIBE_DELETE2!delete from active_watchers where watcher_username=\"\$fU\" and presentity_uri=\"\$var(presentity_uri)\" and to_user=\"\$tU\" and watcher_domain=\"\$fd\" and event=\"\$hdr(Event)\"!g"
#!substdef "!KZQ_RESET_ACCOUNT_DELETE!delete from presentity where domain=\"\$(kzE{kz.json,Realm})\"!g"
#!substdef "!KZQ_RESET_ACCOUNT_UPDATE!update active_watchers set expires = \$TS where watcher_domain=\"\$(kzE{kz.json,Realm})\"!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_SUMMARY!select * from active_watchers where watcher_domain = \"\$var(Domain)\"!g"

+ 12
- 1
kamailio/db_queries_mysql.cfg View File

@ -1,2 +1,13 @@
####### Database queries ######## ####### Database queries ########
#!substdef "!DISPATCHER_CHECK_MEDIA_SERVER_INSERT_QUERY!insert into dispatcher (setid, destination) select \$var(SetId), \"\$var(MediaUrl)\" from DUAL 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)\" from DUAL 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_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_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_HANDLE_NEW_SUBSCRIBE_DELETE1!delete from active_watchers where callid = \"\$ci\"!g"
#!substdef "!KZQ_HANDLE_NEW_SUBSCRIBE_DELETE2!delete from active_watchers where watcher_username=\"\$fU\" and presentity_uri=\"\$var(presentity_uri)\" and to_user=\"\$tU\" and watcher_domain=\"\$fd\" and event=\"\$hdr(Event)\"!g"
#!substdef "!KZQ_RESET_ACCOUNT_DELETE!delete from presentity where domain=\"\$(kzE{kz.json,Realm})\"!g"
#!substdef "!KZQ_RESET_ACCOUNT_UPDATE!update active_watchers set expires = \$TS where watcher_domain=\"\$(kzE{kz.json,Realm})\"!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_SUMMARY!select * from active_watchers where watcher_domain = \"\$var(Domain)\"!g"

+ 13
- 0
kamailio/db_queries_postgres.cfg View File

@ -0,0 +1,13 @@
####### 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_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_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_HANDLE_NEW_SUBSCRIBE_DELETE1!delete from active_watchers where callid = '\$ci'!g"
#!substdef "!KZQ_HANDLE_NEW_SUBSCRIBE_DELETE2!delete from active_watchers where watcher_username='\$fU' and presentity_uri='\$var(presentity_uri)' and to_user='\$tU' and watcher_domain='\$fd' and event='\$hdr(Event)'!g"
#!substdef "!KZQ_RESET_ACCOUNT_DELETE!delete from presentity where domain='\$(kzE{kz.json,Realm})'!g"
#!substdef "!KZQ_RESET_ACCOUNT_UPDATE!update active_watchers set expires = \$TS where watcher_domain='\$(kzE{kz.json,Realm})'!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_SUMMARY!select * from active_watchers where watcher_domain = '\$var(Domain)'!g"

+ 1
- 1
kamailio/default.cfg View File

@ -181,7 +181,7 @@ modparam("sqlops","sqlcon", "cb=>KAZOO_DB_URL")
modparam("sqlops","sqlcon", "exec=>KAZOO_DB_URL") modparam("sqlops","sqlcon", "exec=>KAZOO_DB_URL")
####### DATABASE module ########## ####### DATABASE module ##########
loadmodule "db_kazoo.so"
loadmodule "db_KAMAILIO_DBMS.so"
####### Kazoo Integration module ########## ####### Kazoo Integration module ##########
loadmodule "kazoo.so" loadmodule "kazoo.so"


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

@ -221,7 +221,7 @@ route[DISPATCHER_CHECK_MEDIA_SERVER]
if($var(Zone) != "MY_AMQP_ZONE") { if($var(Zone) != "MY_AMQP_ZONE") {
$var(SetId) = 2; $var(SetId) = 2;
} }
sql_query("exec", "DISPATCHER_CHECK_MEDIA_SERVER_INSERT_QUERY");
sql_query("exec", "KZQ_CHECK_MEDIA_SERVER_INSERT");
if($sqlrows(exec) > 0) { if($sqlrows(exec) > 0) {
xlog("L_WARNING", "reloading dispatcher table\n"); xlog("L_WARNING", "reloading dispatcher table\n");
ds_reload(); ds_reload();


+ 4
- 0
kamailio/local.cfg View File

@ -23,6 +23,10 @@
# # #!trydef REGISTRAR_SYNC_ROLE # # #!trydef REGISTRAR_SYNC_ROLE
# # #!trydef PRESENCE_NOTIFY_SYNC_ROLE # # #!trydef PRESENCE_NOTIFY_SYNC_ROLE
## PostgreSQL usage - remove all but the last '#' to enable
# # #!substdef "!KAMAILIO_DBMS!postgres!g"
# # #!substdef "!KAZOO_DB_URL!postgres://kamailio:kamailio@127.0.0.1/kamailio!g"
################################################################################ ################################################################################
## SERVER INFORMATION ## SERVER INFORMATION
################################################################################ ################################################################################


+ 8
- 8
kamailio/presence-reset.cfg View File

@ -27,9 +27,9 @@ route[PRESENCE_RESET_BINDINGS]
route[RESET_PUBLISHER] route[RESET_PUBLISHER]
{ {
xlog("L_INFO", "$var(Msg-ID)|reset|received presence reset for publisher $var(MediaUrl))\n");
xlog("L_INFO", "$var(Msg-ID)|reset|received presence reset for publisher $var(MediaUrl))\n");
if(@cfg_get.kazoo.presence_reset_blf_defer_update == 0) { if(@cfg_get.kazoo.presence_reset_blf_defer_update == 0) {
$var(Query) = $_s(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)"));
$var(Query) = $_s(KZQ_RESET_PUBLISHER_UPDATE);
sql_query("exec", "$var(Query)"); sql_query("exec", "$var(Query)");
} }
$var(Query) = $_s(delete from presentity where sender = "$var(MediaUrl)"); $var(Query) = $_s(delete from presentity where sender = "$var(MediaUrl)");
@ -61,9 +61,9 @@ route[RESET_SERVER]
route[RESET_ACCOUNT] route[RESET_ACCOUNT]
{ {
xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|received presence reset for realm $(kzE{kz.json,Realm})\n"); xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|received presence reset for realm $(kzE{kz.json,Realm})\n");
sql_query("exec", 'delete from presentity where domain="$(kzE{kz.json,Realm})" ');
sql_query("exec", 'KZQ_RESET_ACCOUNT_DELETE');
$var(presentities) = $sqlrows(exec); $var(presentities) = $sqlrows(exec);
sql_query("exec", 'update active_watchers set expires = $TS where watcher_domain="$(kzE{kz.json,Realm})" ');
sql_query("exec", 'KZQ_RESET_ACCOUNT_UPDATE');
$var(watchers) = $sqlrows(exec); $var(watchers) = $sqlrows(exec);
xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|removed $var(presentities) presentities and expired $var(watchers) subscribers for realm $(kzE{kz.json,Realm})\n"); xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|removed $var(presentities) presentities and expired $var(watchers) subscribers for realm $(kzE{kz.json,Realm})\n");
} }
@ -94,7 +94,7 @@ route[RESET_WILDCARD]
route(RESET_ACCOUNT); route(RESET_ACCOUNT);
} }
} }
} }
@ -104,12 +104,12 @@ event_route[kazoo:consumer-event-presence-reset]
route(RESET_WILDCARD); route(RESET_WILDCARD);
exit(); exit();
} }
xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|received presence reset for $(kzE{kz.json,Username})@$(kzE{kz.json,Realm})\n"); xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|received presence reset for $(kzE{kz.json,Username})@$(kzE{kz.json,Realm})\n");
$var(presentity) = $_s(sip:$(kzE{kz.json,Username})@$(kzE{kz.json,Realm})); $var(presentity) = $_s(sip:$(kzE{kz.json,Username})@$(kzE{kz.json,Realm}));
route(COUNT_SUBSCRIBERS); route(COUNT_SUBSCRIBERS);
sql_query("exec", 'delete from presentity where domain="$(kzE{kz.json,Realm})" and username = "$(kzE{kz.json,Username})"');
sql_query("exec", 'KZQ_EVENT_PRESENCE_RESET_DELETE');
if($xavp(watchers=>message-summary) > 0) { if($xavp(watchers=>message-summary) > 0) {
xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|notifying $xavp(watchers=>message-summary) message-summary subscribers of $var(presentity)\n"); xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|notifying $xavp(watchers=>message-summary) message-summary subscribers of $var(presentity)\n");
pres_refresh_watchers("$var(presentity)", "message-summary", 1); pres_refresh_watchers("$var(presentity)", "message-summary", 1);


+ 5
- 5
kamailio/presence-role.cfg View File

@ -131,7 +131,7 @@ route[HANDLE_NEW_SUBSCRIBE]
} }
if($shtinc(first=>$ci) > 1) { if($shtinc(first=>$ci) > 1) {
sql_query("exec", 'delete from active_watchers where callid = "$ci"');
sql_query("exec", 'KZQ_HANDLE_NEW_SUBSCRIBE_DELETE1');
xlog("L_INFO", "$ci|subscribe|resetting $hdr(Event) subscription from $fU to $tU in realm $fd : $sqlrows(exec)\n"); xlog("L_INFO", "$ci|subscribe|resetting $hdr(Event) subscription from $fU to $tU in realm $fd : $sqlrows(exec)\n");
} else { } else {
$var(presentity_uri) = $ru; $var(presentity_uri) = $ru;
@ -139,7 +139,7 @@ route[HANDLE_NEW_SUBSCRIBE]
$var(presentity_uri) = $tu; $var(presentity_uri) = $tu;
} }
if($shtinc(first=>$fU::$var(presentity_uri)::$fd::$hdr(Event)) > 1) { if($shtinc(first=>$fU::$var(presentity_uri)::$fd::$hdr(Event)) > 1) {
sql_query("exec", 'delete from active_watchers where watcher_username="$fU" and presentity_uri="$var(presentity_uri)" and to_user="$tU" and watcher_domain="$fd" and event="$hdr(Event)"');
sql_query("exec", 'KZQ_HANDLE_NEW_SUBSCRIBE_DELETE2');
xlog("L_INFO", "$ci|subscribe|resetting $hdr(Event) subscription from $fU to $var(presentity_uri) in realm $fd : $sqlrows(exec)\n"); xlog("L_INFO", "$ci|subscribe|resetting $hdr(Event) subscription from $fU to $var(presentity_uri) in realm $fd : $sqlrows(exec)\n");
} }
} }
@ -181,7 +181,7 @@ route[HANDLE_PUBLISH]
route[COUNT_PRESENTITIES] route[COUNT_PRESENTITIES]
{ {
$var(Query) = $_s(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);
$var(Query) = $_s(KZQ_COUNT_PRESENTITIES);
$var(p) = "uri="+$(kzE{kz.json,From}); $var(p) = "uri="+$(kzE{kz.json,From});
if (sql_xquery("cb", "$var(Query)", "subs") == 1) if (sql_xquery("cb", "$var(Query)", "subs") == 1)
{ {
@ -209,7 +209,7 @@ route[COUNT_ALL_PRESENTITIES]
route[COUNT_ALL_SUBSCRIBERS] route[COUNT_ALL_SUBSCRIBERS]
{ {
$var(Query) = $_s(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);
$var(Query) = $_s(KZQ_COUNT_ALL_SUBSCRIBERS);
if (sql_xquery("cb", "$var(Query)", "subs") == 1) if (sql_xquery("cb", "$var(Query)", "subs") == 1)
{ {
$var(sep) = ""; $var(sep) = "";
@ -226,7 +226,7 @@ route[COUNT_ALL_SUBSCRIBERS]
route[COUNT_SUBSCRIBERS] route[COUNT_SUBSCRIBERS]
{ {
$var(Query) = $_s(select event, (select count(*) from active_watchers b where presentity_uri = "$var(presentity)" and b.event = a.event) count from event_list a);
$var(Query) = $_s(KZQ_COUNT_SUBSCRIBERS);
$var(p) = $_s(uri=$var(presentity)); $var(p) = $_s(uri=$var(presentity));
if (sql_xquery("cb", "$var(Query)", "subs") == 1) if (sql_xquery("cb", "$var(Query)", "subs") == 1)
{ {


+ 2
- 2
kamailio/presence_query-role.cfg View File

@ -9,7 +9,7 @@ route[PRESENCE_SEARCH_SUMMARY]
$var(Username) = $(kzE{kz.json,Username}); $var(Username) = $(kzE{kz.json,Username});
$var(Now) = $TS; $var(Now) = $TS;
$var(Items) = ""; $var(Items) = "";
$var(Query) = $_s(select * from active_watchers where watcher_domain = "$var(Domain)");
$var(Query) = $_s(KZQ_PRESENCE_SEARCH_SUMMARY);
if($var(Event) != "") { if($var(Event) != "") {
$var(Query) = $var(Query) + $_s( and event = "$var(Event)"); $var(Query) = $var(Query) + $_s( and event = "$var(Event)");
} }
@ -62,7 +62,7 @@ route[PRESENCE_SEARCH_DETAIL]
$var(presentity_uri) = "sip:" + $var(Username) + "@" + $var(Domain); $var(presentity_uri) = "sip:" + $var(Username) + "@" + $var(Domain);
$var(Now) = $TS; $var(Now) = $TS;
$var(Items) = ""; $var(Items) = "";
$var(Query) = $_s(select * from active_watchers_log where presentity_uri = "$var(presentity_uri)");
$var(Query) = $_s(KZQ_PRESENCE_SEARCH_DETAIL);
if($var(Event) != "") { if($var(Event) != "") {
$var(Query) = $var(Query) + $_s( and event = "$var(Event)"); $var(Query) = $var(Query) + $_s( and event = "$var(Event)");
} }


+ 1
- 1
kamailio/registrar-sync-role.cfg View File

@ -4,7 +4,7 @@ event_route[kazoo:consumer-event-directory-reg-sync]
{ {
$var(Server) = $(kzE{kz.json,Server-ID}); $var(Server) = $(kzE{kz.json,Server-ID});
xlog("L_INFO", "received registrar sync from $var(Server) : $kzE\n"); xlog("L_INFO", "received registrar sync from $var(Server) : $kzE\n");
if (sql_xquery("cb", "select * from location", "ra") == 1) if (sql_xquery("cb", "select * from location", "ra") == 1)
{ {
while($xavp(ra) != $null) { while($xavp(ra) != $null) {


Loading…
Cancel
Save