You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

32 lines
1.8 KiB

######## Presence sync server module ########
####### SQL OPS module ##########
#!ifndef SQLOPS-LOADED
loadmodule "sqlops.so"
modparam("sqlops","sqlcon", "cb=>KAZOO_DB_URL")
#!trydef SQLOPS-LOADED
#!endif
event_route[kazoo:consumer-event-directory-reg-sync]
{
$var(Server) = $(kzE{kz.json,Server-ID});
xlog("L_INFO", "received registrar sync from $var(Server) : $kzE");
if (sql_xquery("cb", "select * from location", "ra") == 1)
{
while($xavp(ra) != $null) {
$var(runloop) = 1;
while($xavp(ra) != $null && $var(runloop) < MAX_WHILE_LOOPS ) {
if(registered("location", "sip:$xavp(ra=>username)@$xavp(ra=>domain)", 0, 1)) {
xlog("L_INFO", "[id, username, domain] = [$xavp(ra=>id), $xavp(ra=>username), $xavp(ra=>domain)]");
$var(Expires) = $xavp(ra=>expires) - $TS;
$var(amqp_payload_request) = '{"Event-Category" : "directory", "Event-Name" : "reg_success", "Status" : "Success", "Event-Timestamp" : $TS, "Expires" : $(var(Expires){s.int}), "First-Registration" : false, "Contact" : "$(xavp(ra=>contact){s.escape.common})", "Call-ID" : "$xavp(ra=>callid)", "Realm" : "$xavp(ra=>domain)", "Username" : "$xavp(ra=>username)", "From-User" : "$xavp(ra=>username)", "From-Host" : "$xavp(ra=>domain)", "To-User" : "$xavp(ra=>username)", "To-Host" : "$xavp(ra=>domain)", "User-Agent" : "$(xavp(ra=>user_agent){s.escape.common})" , "Custom-Channel-Vars" : $xavp(ulattrs=>custom_channel_vars), "Proxy-Path" : "sip:$(xavp(ra=>socket){s.substr,4,0})" }';
kazoo_publish("targeted", "$var(Server)", $var(amqp_payload_request));
}
pv_unset("$xavp(ra)");
$var(runloop) = $var(runloop) + 1;
}
}
}
}