Jelajahi Sumber

modules/sipcapture: Added RTCP and LOG functionality. Updated kamilio.cfg, SQL schema, rotation script for Homer 3.6

Alexandr Dubovikov 11 tahun lalu
induk
melakukan
94f1d28e2a

+ 503 - 15
modules/sipcapture/examples/kamailio.cfg

@@ -19,8 +19,10 @@ children=5
 disable_tcp=yes
 disable_tcp=yes
 
 
 /* IP and port for HEP capturing) */
 /* IP and port for HEP capturing) */
-listen=udp:10.0.0.41:5060
+listen=udp:10.0.1.77:9060
 
 
+#Max loops
+max_while_loops=100
 
 
 mpath="/usr/local/lib64/kamailio/modules"
 mpath="/usr/local/lib64/kamailio/modules"
 
 
@@ -28,11 +30,26 @@ loadmodule "pv.so"
 loadmodule "db_mysql.so"
 loadmodule "db_mysql.so"
 loadmodule "sipcapture.so"
 loadmodule "sipcapture.so"
 loadmodule "textops.so"
 loadmodule "textops.so"
+loadmodule "rtimer.so"
+loadmodule "xlog.so"
+loadmodule "sqlops.so"
+loadmodule "htable.so"
+loadmodule "sl.so"
+loadmodule "siputils.so"
+
+
+modparam("htable", "htable", "a=>size=8;autoexpire=400")
+modparam("htable", "htable", "b=>size=8;autoexpire=31")
+
+modparam("rtimer", "timer", "name=ta;interval=60;mode=1;")
+modparam("rtimer", "exec", "timer=ta;route=TIMER_STATS")
+
+modparam("sqlops","sqlcon","cb=>mysql://homer_user:[email protected]/homer_db")
 
 
 # ----- mi_fifo params -----
 # ----- mi_fifo params -----
 
 
 ####### Routing Logic ########
 ####### Routing Logic ########
-modparam("sipcapture", "db_url", "mysql://homer_user:homerpasswd@localhost/homer_data")
+modparam("sipcapture", "db_url", "mysql://homer_user:123456@localhost/homer_db")
 modparam("sipcapture", "capture_on", 1)
 modparam("sipcapture", "capture_on", 1)
 /* activate HEP capturing */
 /* activate HEP capturing */
 modparam("sipcapture", "hep_capture_on", 1)
 modparam("sipcapture", "hep_capture_on", 1)
@@ -54,26 +71,497 @@ modparam("sipcapture", "raw_moni_capture_on", 0)
 #modparam("sipcapture", "promiscious_on", 1)
 #modparam("sipcapture", "promiscious_on", 1)
 /* activate Linux Socket Filter (LSF/BPF) on mirroring interface. Linux only */
 /* activate Linux Socket Filter (LSF/BPF) on mirroring interface. Linux only */
 #modparam("sipcapture", "raw_moni_bpf_on", 1)
 #modparam("sipcapture", "raw_moni_bpf_on", 1)
-/* !!! old schema !!!! */
-#modparam("sipcapture", "authorization_column", "authorization")
 
 
 # Main SIP request routing logic
 # Main SIP request routing logic
 # - processing of any incoming SIP request starts with this route
 # - processing of any incoming SIP request starts with this route
+
 route {
 route {
 
 
-	#For example, you can capture only needed methods...
-	#if (is_method("INVITE|UPDATE|NOTIFY|SUBSCRIBE|OPTIONS|REGISTER|BYE")) {
-		sip_capture();
-	#}
-	drop;
+        if($sht(a=>method::all) == $null) $sht(a=>method::all) = 0;
+        $sht(a=>method::all) = $sht(a=>method::all) + 1;
+
+        if($sht(b=>$rm::$cs::$ci) != $null) {
+                $var(a) = "sip_capture";
+                sip_capture("$var(a)");
+                drop;
+        }
+
+        $sht(b=>$rm::$cs::$ci) = 1;
+
+        if (is_method("INVITE|REGISTER")) {
+
+                if($ua =~ "(friendly-scanner|sipvicious)") {
+                        sql_query("cb", "INSERT INTO alarm_data_mem (create_date, type, total, source_ip, description) VALUES(NOW(), 'scanner', 1, '$si', 'Friendly scanner alarm!') ON DUPLICATE KEY UPDATE total=total+1");
+                }
+
+                #IP Method
+                sql_query("cb", "INSERT INTO stats_ip_mem ( method, source_ip, total) VALUES('$rm', '$si', 1) ON DUPLICATE KEY UPDATE total=total+1");
+
+                if($au != $null)  $var(anumber) = $au;
+                else $var(anumber) = $fU;
+
+                #hostname in contact
+                if($sel(contact.uri.host) =~ "^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$") {
+                        if($sht(a=>alarm::dns) == $null) $sht(a=>alarm::dns) = 0;
+                        $sht(a=>alarm::dns) = $sht(a=>alarm::dns) + 1;
+                }
+
+                if($sel(contact.uri.host) != $si) {
+                        if($sht(a=>alarm::spoofing) == $null) $sht(a=>alarm::spoofing) = 0;
+                        $sht(a=>alarm::spoofing) = $sht(a=>alarm::spoofing) + 1;
+                }
+
+                if($au =~ "(\=)|(\-\-)|(\')|(\#)|(\%27)|(\%24)") {
+                        if($sht(a=>alarm::sqlinjection) == $null) $sht(a=>alarm::sqlinjection) = 0;
+                        $sht(a=>alarm::sqlinjection) = $sht(a=>alarm::sqlijnection) + 1;
+                }
+
+                if($(hdr(Record-Route)[0]{nameaddr.uri}) != $si) {
+                        if($sht(a=>alarm::spoofing) == $null) $sht(a=>alarm::spoofing) = 0;
+                        $sht(a=>alarm::spoofing) = $sht(a=>alarm::spoofing) + 1;
+                }
+
+
+                if (is_method("INVITE")) {
+
+                        if (has_totag()) {
+                                if($sht(a=>method::reinvite) == $null) $sht(a=>method::reinvite) = 0;
+                                $sht(a=>method::reinvite) = $sht(a=>method::reinvite) + 1;
+                        }
+                        else {
+                                if($sht(a=>method::invite) == $null) $sht(a=>method::invite) = 0;
+                                $sht(a=>method::invite) = $sht(a=>method::invite) + 1;
+
+                                if($adu != $null) {
+                                        if($sht(a=>method::invite::auth) == $null) $sht(a=>method::invite::auth) = 0;
+                                        $sht(a=>method::invite::auth) = $sht(a=>method::invite::auth) + 1;
+                                }
+
+                                if($ua != $null) {
+                                        sql_query("cb", "INSERT INTO stats_useragent_mem (useragent, method, total) VALUES('$ua', 'INVITE', 1) ON DUPLICATE KEY UPDATE total=total+1");
+                                }
+
+                        }
+                }
+                else {
+                        if($sht(a=>method::register) == $null) $sht(a=>method::register) = 0;
+                        $sht(a=>method::register) = $sht(a=>method::register) + 1;
+
+                        if($adu != $null) {
+                                if($sht(a=>method::register::auth) == $null) $sht(a=>method::register::auth) = 0;
+                                $sht(a=>method::register::auth) = $sht(a=>method::register::auth) + 1;
+                        }
+
+                        if($ua != $null) {
+                                sql_query("cb", "INSERT INTO stats_useragent_mem (useragent, method, total) VALUES('$ua', 'REGISTER', 1) ON DUPLICATE KEY UPDATE total=total+1");
+                        }
+                }
+
+        }
+        else if(is_method("BYE")) {
+                if($sht(a=>method::bye) == $null) $sht(a=>method::bye) = 0;
+                $sht(a=>method::bye) = $sht(a=>method::bye) + 1;
+                if(is_present_hf("Reason")) {
+                       $var(cause) = $(hdr(Reason){param.value,cause}{s.int});
+                       if($var(cause) != 16 && $var(cause) !=17) {
+                                if($sht(a=>stats::sdf) == $null) $sht(a=>stats::sdf) = 0;
+                                $sht(a=>stats::sdf) = $sht(a=>stats::sdf) + 1;
+                       }
+                }
+
+        }
+        else if(is_method("CANCEL")) {
+                if($sht(a=>method::cancel) == $null) $sht(a=>method::cancel) = 0;
+                $sht(a=>method::cancel) = $sht(a=>method::cancel) + 1;
+
+        }
+        else if(is_method("OPTIONS")) {
+                if($sht(a=>method::options) == $null) $sht(a=>method::options) = 0;
+                $sht(a=>method::options) = $sht(a=>method::options) + 1;
+
+        }
+        else if(is_method("REFER")) {
+                if($sht(a=>method::refer) == $null) $sht(a=>method::refer) = 0;
+                $sht(a=>method::refer) = $sht(a=>method::refer) + 1;
+
+        }
+        else if(is_method("UPDATE")) {
+                if($sht(a=>method::update) == $null) $sht(a=>method::update) = 0;
+                $sht(a=>method::update) = $sht(a=>method::update) + 1;
+        }
+
+
+        $var(a) = "sip_capture";
+        # Kamailio 4.1 only
+        #sip_capture("$var(a)"); 
+        
+        sip_capture();
+
+        drop;
 }
 }
 
 
 onreply_route {
 onreply_route {
 
 
-	#And replies of request methods
-	#if(status =~ "^(1[0-9][0-9]|[3[0-9][0-9]|4[0-9]|[56][0-9][0-9])$") {
-	#if($rm =~ "^(INVITE|UPDATE|NOTIFY|SUBSCRIBE|OPTIONS|REGISTER|BYE)$") {
-		sip_capture();
-	#}	
-	drop;
+        if($sht(a=>method::all) == $null) $sht(a=>method::all) = 0;
+        $sht(a=>method::all) = $sht(a=>method::all) + 1;
+
+        if($sht(b=>$rs::$cs::$rm::$ci) != $null) {
+                $var(a) = "sip_capture";
+                sip_capture("$var(a)");
+                drop;
+        }
+
+        $sht(b=>$rs::$cs::$rm::$ci) = 1;
+
+        #413 Too large
+        if(status == "413") {
+
+                if($sht(a=>alarm::413) == $null) $sht(a=>alarm::413) = 0;
+                $sht(a=>alarm::413) = $sht(a=>alarm::413) + 1;
+        }
+        # Too many hops
+        else if(status == "483") {
+                if($sht(a=>alarm::483) == $null) $sht(a=>alarm::483) = 0;
+                $sht(a=>alarm::483) = $sht(a=>alarm::483) + 1;
+
+        }
+        # loops
+        else if(status == "482") {
+                if($sht(a=>alarm::482) == $null) $sht(a=>alarm::482) = 0;
+                $sht(a=>alarm::482) = $sht(a=>alarm::482) + 1;
+
+        }
+        # 400
+        else if(status == "400") {
+                if($sht(a=>alarm::400) == $null) $sht(a=>alarm::400) = 0;
+                $sht(a=>alarm::400) = $sht(a=>alarm::400) + 1;
+
+        }
+
+        # 500
+        else if(status == "500") {
+                if($sht(a=>alarm::500) == $null) $sht(a=>alarm::500) = 0;
+                $sht(a=>alarm::500) = $sht(a=>alarm::500) + 1;
+        }
+        # 503
+        else if(status == "503") {
+                if($sht(a=>alarm::503) == $null) $sht(a=>alarm::503) = 0;
+                $sht(a=>alarm::503) = $sht(a=>alarm::503) + 1;
+        }
+        # 403
+        else if(status == "403") {
+                if($sht(a=>alarm::403) == $null) $sht(a=>alarm::403) = 0;
+                $sht(a=>alarm::403) = $sht(a=>alarm::403) + 1;
+        }
+        # MOVED
+        else if(status =~ "^(30[012])$") {
+                if($sht(a=>response::300) == $null) $sht(a=>response::300) = 0;
+                $sht(a=>response::300) = $sht(a=>response::300) + 1;
+        }
+
+        if($rm == "INVITE") {
+                #ISA
+                if(status =~ "^(408|50[03])$") {
+                        if($sht(a=>stats::isa) == $null) $sht(a=>stats::isa) = 0;
+                        $sht(a=>stats::isa) = $sht(a=>stats::isa) + 1;
+                }
+                #Bad486
+                if(status =~ "^(486|487|603)$") {
+                        if($sht(a=>stats::bad::invite) == $null) $sht(a=>stats::bad::invite) = 0;
+                        $sht(a=>stats::bad::invite) = $sht(a=>stats::bad::invite) + 1;
+                }
+
+                #SD
+                if(status =~ "^(50[034])$") {
+                        if($sht(a=>stats::sd) == $null) $sht(a=>stats::sd) = 0;
+                        $sht(a=>stats::sd) = $sht(a=>stats::sd) + 1;
+                }
+
+                if(status == "407") {
+                        if($sht(a=>response::407::invite) == $null) $sht(a=>response::407::invite)= 0;
+                        $sht(a=>response::407::invite) = $sht(a=>response::407::invite) + 1;
+                }
+                else if(status == "401") {
+                        if($sht(a=>response::401::invite) == $null) $sht(a=>response::401::invite)= 0;
+                        $sht(a=>response::401::invite) = $sht(a=>response::401::invite) + 1;
+                }
+                else if(status == "200") {
+                        if($sht(a=>response::200::invite) == $null) $sht(a=>response::200::invite)= 0;
+                        $sht(a=>response::200::invite) = $sht(a=>response::200::invite) + 1;
+                }
+        }
+        else if($rm == "BYE") {
+
+                if(status == "407") {
+                        if($sht(a=>response::407::bye) == $null) $sht(a=>response::407::bye) = 0;
+                        $sht(a=>response::407::bye) = $sht(a=>response::407::bye) + 1;
+                }
+                else if(status == "401") {
+                        if($sht(a=>response::401::bye) == $null) $sht(a=>response::401::bye) = 0;
+                        $sht(a=>response::401::bye) = $sht(a=>response::401::bye) + 1;
+                }
+                else if(status == "200") {
+                        if($sht(a=>response::200::bye) == $null) $sht(a=>response::200::bye) = 0;
+                        $sht(a=>response::200::bye) = $sht(a=>response::200::bye) + 1;
+                }
+        }
+
+        sip_capture();
+
+        drop;
 }
 }
+
+
+route[TIMER_STATS] {
+
+    #ALARM SCANNERS
+    sql_query("cb", "INSERT INTO alarm_data (create_date, type, total, source_ip, description) SELECT create_date, type, total, source_ip, description FROM alarm_data_mem;");
+    sql_query("cb", "TRUNCATE TABLE alarm_data_mem");
+
+    #413
+    if($sht(a=>alarm::413) > 0) {
+        sql_query("cb", "INSERT INTO alarm_data (create_date, type, total, description) VALUES(NOW(), 'Too Many 413', $sht(a=>alarm::413), 'Too many big messages')");
+    }
+
+    $sht(a=>alarm::413) = 0;
+
+    #483
+    if($sht(a=>alarm::483) > 0) {
+        sql_query("cb", "INSERT INTO alarm_data (create_date, type, total, description) VALUES(NOW(), 'Too Many 483', $sht(a=>alarm::483), 'Too many hops messages')");
+    }
+
+    $sht(a=>alarm::483) = 0;
+
+    #482
+    if($sht(a=>alarm::482) > 0) {
+        sql_query("cb", "INSERT INTO alarm_data (create_date, type, total, description) VALUES(NOW(), 'Too Many 482', $sht(a=>alarm::482), 'Too many loops messages')");
+    }
+
+    $sht(a=>alarm::482) = 0;
+
+    #403
+    if($sht(a=>alarm::403) > 0) {
+        sql_query("cb", "INSERT INTO alarm_data (create_date, type, total, description) VALUES(NOW(), 'Too Many 403', $sht(a=>alarm::403), 'fraud alarm')");
+    }
+    $sht(a=>alarm::403) = 0;
+
+    #503
+    if($sht(a=>alarm::503) > 0) {
+        sql_query("cb", "INSERT INTO alarm_data (create_date, type, total, description) VALUES(NOW(), 'Too Many 503', $sht(a=>alarm::503), 'service unavailable')");
+    }
+    $sht(a=>alarm::503) = 0;
+
+    #500
+    if($sht(a=>alarm::500) > 0) {
+        sql_query("cb", "INSERT INTO alarm_data (create_date, type, total, description) VALUES(NOW(), 'Too Many 500', $sht(a=>alarm::500), 'server errors')");
+    }
+    $sht(a=>alarm::500) = 0;
+
+    #408
+    if($sht(a=>alarm::408) > 0) {
+        sql_query("cb", "INSERT INTO alarm_data (create_date, type, total, description) VALUES(NOW(), 'Too Many 408', $sht(a=>alarm::408), 'Timeout')");
+    }
+
+    $sht(a=>alarm::408) = 0;
+
+    #400
+    if($sht(a=>alarm::400) > 0) {
+        sql_query("cb", "INSERT INTO alarm_data (create_date, type, total, description) VALUES(NOW(), 'Too Many 400', $sht(a=>alarm::400), 'Too many bad request')");
+    }
+    $sht(a=>alarm::400) = 0;
+
+    #delete old alarms
+    sql_query("cb", "DELETE FROM alarm_data WHERE create_date < DATE_SUB(NOW(), INTERVAL 5 DAY)");
+
+    #SQL STATS
+
+    $var(tm) = ($time(min) mod 10);
+
+    if($var(tm) != 0 && $var(tm) != 5) return;
+
+    $var(t1) = $TS;
+    $var(t2) = $var(t1) - 300;
+
+    $var(t_date) = "FROM_UNIXTIME(" + $var(t1) + ", '%Y-%m-%d %H:%i:00')";
+    $var(f_date) = "FROM_UNIXTIME(" + $var(t2) + ", '%Y-%m-%d %H:%i:00')";
+
+    #STATS Useragent
+    sql_query("cb", "INSERT INTO stats_useragent (from_date, to_date, useragent, method, total) SELECT $var(f_date) as from_date, $var(t_date) as to_date, useragent, method, total FROM stats_useragent_mem;");
+    sql_query("cb", "TRUNCATE TABLE stats_useragent_mem");
+
+    #STATS IP
+    sql_query("cb", "INSERT INTO stats_ip (from_date, to_date, method, source_ip, total) SELECT $var(f_date) as from_date, $var(t_date) as to_date, method, source_ip, total FROM stats_ip_mem;");
+    sql_query("cb", "TRUNCATE TABLE stats_ip_mem");
+
+    #INSERT SQL STATS
+    #SDF
+    if($sht(a=>stats::sdf) != $null && $sht(a=>stats::sdf) > 0) {
+        sql_query("cb", "INSERT INTO stats_data (from_date, to_date, type, total) VALUES($var(f_date), $var(t_date), 'sdf', $sht(a=>stats::sdf))");
+        $sht(a=>stats::sdf) = 0;
+    }
+
+    #ISA
+    if($sht(a=>stats::isa) != $null && $sht(a=>stats::isa) > 0) {
+        sql_query("cb", "INSERT INTO stats_data (from_date, to_date, type, total) VALUES($var(f_date), $var(t_date), 'isa', $sht(a=>stats::isa))");
+        $sht(a=>stats::isa) = 0;
+    }
+
+    #SD
+    if($sht(a=>stats::sd) != $null && $sht(a=>stats::sd) > 0) {
+        sql_query("cb", "INSERT INTO stats_data (from_date, to_date, type, total) VALUES($var(f_date), $var(t_date), 'isa', $sht(a=>stats::sd))");
+        $sht(a=>stats::sd) = 0;
+    }
+
+    #SSR
+    if($sht(a=>stats::ssr) != $null && $sht(a=>stats::ssr) > 0) {
+        sql_query("cb", "INSERT INTO stats_data (from_date, to_date, type, total) VALUES($var(f_date), $var(t_date), 'ssr', $sht(a=>stats::ssr))");
+        $sht(a=>stats::ssr) = 0;
+    }
+
+    #ASR
+    $var(asr) = 0;
+    #if($sht(a=>response::200::invite) > 0) {
+    if($sht(a=>method::invite) > 0) {
+        if($sht(a=>response::407::invite) == $null) $sht(a=>response::407::invite) = 0;
+        if($sht(a=>response::200::invite) == $null) $sht(a=>response::200::invite) = 0;
+        $var(d) = $sht(a=>method::invite) - $sht(a=>response::407::invite);
+        if($var(d) > 0) {
+                $var(asr) =  $sht(a=>response::200::invite) / $var(d) * 100;
+                if($var(asr) > 100)  $var(asr) = 100;
+        }
+    }
+
+    #Stats DATA
+    sql_query("cb", "INSERT INTO stats_data (from_date, to_date, type, total) VALUES($var(f_date), $var(t_date), 'asr', $var(asr))");
+
+
+    #NER
+    $var(ner) = 0;
+    #if($sht(a=>response::200::invite) > 0 || $sht(a=>stats::bad::invite) > 0) {
+    if($sht(a=>method::invite) > 0) {
+
+        if($sht(a=>response::200::invite) == $null) $sht(a=>response::200::invite) = 0;
+        if($sht(a=>response::bad::invite) == $null) $sht(a=>response::bad::invite) = 0;
+        if($sht(a=>response::407::invite) == $null) $sht(a=>response::407::invite) = 0;
+
+        $var(d) = $sht(a=>method::invite) - $sht(a=>response::407::invite);
+
+        if($var(d) > 0) {
+                $var(ner) =  ($sht(a=>response::200::invite) + $sht(a=>stats::bad::invite)) / $var(d) * 100;
+                if($var(ner) > 100)  $var(ner) = 100;
+        }
+    }
+
+    sql_query("cb", "INSERT INTO stats_data (from_date, to_date, type, total) VALUES($var(f_date), $var(t_date), 'ner', $var(ner))");
+
+    #INVITE
+    if($sht(a=>method::reinvite) > 0) {
+        sql_query("cb", "INSERT INTO stats_method (from_date, to_date, method, totag, total) VALUES($var(f_date), $var(t_date),'INVITE', 1, $sht(a=>method::reinvite))");
+        $sht(a=>method::reinvite) = 0;
+    }
+
+    #INVITE
+    if($sht(a=>method::invite) > 0) {
+        sql_query("cb", "INSERT INTO stats_method (from_date, to_date, method, total) VALUES($var(f_date), $var(t_date), 'INVITE', $sht(a=>method::invite))");
+        $sht(a=>method::invite) = 0;
+    }
+
+    #INVITE AUTH
+    if($sht(a=>method::invite::auth) > 0) {
+        sql_query("cb", "INSERT INTO stats_method (from_date, to_date, method, auth, total) VALUES($var(f_date), $var(t_date), 'INVITE', 1, $sht(a=>method::invite::auth))");
+        $sht(a=>method::invite::auth) = 0;
+    }
+
+    #REGISTER
+    if($sht(a=>method::register) > 0) {
+        sql_query("cb", "INSERT INTO stats_method (from_date, to_date, method, total) VALUES($var(f_date), $var(t_date), 'REGISTER', $sht(a=>method::register))");
+        $sht(a=>method::register) = 0;
+    }
+
+    #REGISTER AUTH
+    if($sht(a=>method::register::auth) > 0) {
+        sql_query("cb", "INSERT INTO stats_method (from_date, to_date, method, auth, total) VALUES($var(f_date), $var(t_date), 'REGISTER', 1, $sht(a=>method::register::auth))");
+        $sht(a=>method::register::auth) = 0;
+    }
+
+    #BYE
+    if($sht(a=>method::bye) > 0) {
+        sql_query("cb", "INSERT INTO stats_method (from_date, to_date, method, total) VALUES($var(f_date), $var(t_date), 'BYE', $sht(a=>method::bye))");
+        $sht(a=>method::bye) = 0;
+    }
+
+    #CANCEL
+    if($sht(a=>method::cancel) > 0) {
+        sql_query("cb", "INSERT INTO stats_method (from_date, to_date, method, total) VALUES($var(f_date), $var(t_date), 'CANCEL', $sht(a=>method::cancel))");
+        $sht(a=>method::cancel) = 0;
+    }
+
+    #OPTIONS
+    if($sht(a=>method::options) > 0) {
+        sql_query("cb", "INSERT INTO stats_method (from_date, to_date, method, total) VALUES($var(f_date), $var(t_date), 'OPTIONS', $sht(a=>method::options))");
+        $sht(a=>method::options) = 0;
+    }
+
+    #REFER
+    if($sht(a=>method::refer) > 0) {
+        sql_query("cb", "INSERT INTO stats_method (from_date, to_date, method, total) VALUES($var(f_date), $var(t_date), 'REFER', $sht(a=>method::refer))");
+        $sht(a=>method::refer) = 0;
+    }
+
+    #UPDATE
+    if($sht(a=>method::update) > 0) {
+        sql_query("cb", "INSERT INTO stats_method (from_date, to_date, method, total) VALUES($var(f_date), $var(t_date), 'UPDATE', $sht(a=>method::update))");
+        $sht(a=>method::update) = 0;
+    }
+
+    #RESPONSE
+
+    #300
+    if($sht(a=>response::300) > 0) {
+        sql_query("cb", "INSERT INTO stats_method (from_date, to_date, method, total) VALUES($var(f_date), $var(t_date), '300', $sht(a=>response::300))");
+        $sht(a=>response::300) = 0;
+    }
+
+    #407 INVITE
+    if($sht(a=>response::407::invite) > 0) {
+        sql_query("cb", "INSERT INTO stats_method (from_date, to_date, method, cseq, total) VALUES($var(f_date), $var(t_date), '407', 'INVITE', $sht(a=>response::407::invite))");
+        $sht(a=>response::407::invite) = 0;
+    }
+
+    #401 INVITE
+    if($sht(a=>response::401::invite) > 0) {
+        sql_query("cb", "INSERT INTO stats_method (from_date, to_date, method, cseq, total) VALUES($var(f_date), $var(t_date), '401', 'INVITE', $sht(a=>response::401::invite))");
+        $sht(a=>response::401::invite) = 0;
+    }
+
+    #200 INVITE
+    if($sht(a=>response::200::invite) > 0) {
+        sql_query("cb", "INSERT INTO stats_method (from_date, to_date, method, cseq, total) VALUES($var(f_date), $var(t_date), '200', 'INVITE', $sht(a=>response::200::invite))");
+        $sht(a=>response::200::invite) = 0;
+    }
+
+    #407 BYE
+    if($sht(a=>response::407::bye) > 0) {
+        sql_query("cb", "INSERT INTO stats_method (from_date, to_date, method, cseq, total) VALUES($var(f_date), $var(t_date), '407', 'BYE', $sht(a=>response::407::bye))");
+        $sht(a=>response::407::bye) = 0;
+    }
+
+    #401 BYE
+    if($sht(a=>response::401::bye) > 0) {
+        sql_query("cb", "INSERT INTO stats_method (from_date, to_date, method, cseq, total) VALUES($var(f_date), $var(t_date), '401', 'BYE', $sht(a=>response::401::bye))");
+        $sht(a=>response::401::bye) = 0;
+    }
+
+    #200 BYE
+    if($sht(a=>response::200::bye) > 0) {
+        sql_query("cb", "INSERT INTO stats_method (from_date, to_date, method, cseq, total) VALUES($var(f_date), $var(t_date), '200', 'BYE', $sht(a=>response::200::bye))");
+        $sht(a=>response::200::bye) = 0;
+    }
+
+    #ALL MESSAGES
+    if($sht(a=>method::all) > 0) {
+        sql_query("cb", "INSERT INTO stats_method (from_date, to_date, method, total) VALUES($var(f_date), $var(t_date), 'ALL', $sht(a=>method::all))");
+        $sht(a=>method::all) = 0;
+    }
+}
+

+ 35 - 49
modules/sipcapture/examples/partrotate_unixtimestamp.pl

@@ -2,7 +2,7 @@
 #
 #
 # partrotate_unixtimestamp - perl script for mySQL partition rotation
 # partrotate_unixtimestamp - perl script for mySQL partition rotation
 #
 #
-# Copyright (C) 2011 Alexandr Dubovikov (QSC AG) ([email protected])
+# Copyright (C) 2011-2014 Alexandr Dubovikov ([email protected])
 #
 #
 # This file is part of webhomer, a free capture server.
 # This file is part of webhomer, a free capture server.
 #
 #
@@ -18,11 +18,11 @@
 #
 #
 # You should have received a copy of the GNU General Public License
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
 # along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 
 use DBI;
 use DBI;
 
 
-$version = "0.2.5";
+$version = "0.3.0";
 $mysql_table = "sip_capture";
 $mysql_table = "sip_capture";
 $mysql_dbname = "homer_db";
 $mysql_dbname = "homer_db";
 $mysql_user = "mysql_login";
 $mysql_user = "mysql_login";
@@ -32,7 +32,8 @@ $maxparts = 6; #6 days How long keep the data in the DB
 $newparts = 2; #new partitions for 2 days. Anyway, start this script daily!
 $newparts = 2; #new partitions for 2 days. Anyway, start this script daily!
 @stepsvalues = (86400, 3600, 1800, 900); 
 @stepsvalues = (86400, 3600, 1800, 900); 
 $partstep = 0; # 0 - Day, 1 - Hour, 2 - 30 Minutes, 3 - 15 Minutes 
 $partstep = 0; # 0 - Day, 1 - Hour, 2 - 30 Minutes, 3 - 15 Minutes 
-$engine = "MyISAM";
+$engine = "InnoDB"; #MyISAM or InnoDB
+$compress = "ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8"; #Enable this if you want use barracuda format or set var to empty.
 $sql_schema_version = 2;
 $sql_schema_version = 2;
 $auth_column = "auth";
 $auth_column = "auth";
 $check_table = 1; #Check if table exists. For PostgreSQL change creation schema!
 $check_table = 1; #Check if table exists. For PostgreSQL change creation schema!
@@ -54,6 +55,7 @@ $coof=int(86400/$mystep);
 #How much partitions
 #How much partitions
 $maxparts*=$coof;
 $maxparts*=$coof;
 $newparts*=$coof;
 $newparts*=$coof;
+$totalparts = ($maxparts+$newparts);
 
 
 my $db = DBI->connect("DBI:mysql:$mysql_dbname:$mysql_host:3306", $mysql_user, $mysql_password);
 my $db = DBI->connect("DBI:mysql:$mysql_dbname:$mysql_host:3306", $mysql_user, $mysql_password);
 
 
@@ -75,7 +77,7 @@ $sql = "CREATE TABLE IF NOT EXISTS `".$mysql_table."` (
   `to_tag` varchar(64) NOT NULL,
   `to_tag` varchar(64) NOT NULL,
   `pid_user` varchar(100) NOT NULL DEFAULT '',
   `pid_user` varchar(100) NOT NULL DEFAULT '',
   `contact_user` varchar(120) NOT NULL,
   `contact_user` varchar(120) NOT NULL,
-  `".$auth_column."` varchar(120) NOT NULL,
+  `auth_user` varchar(120) NOT NULL,  
   `callid` varchar(100) NOT NULL DEFAULT '',
   `callid` varchar(100) NOT NULL DEFAULT '',
   `callid_aleg` varchar(100) NOT NULL DEFAULT '',
   `callid_aleg` varchar(100) NOT NULL DEFAULT '',
   `via_1` varchar(256) NOT NULL,
   `via_1` varchar(256) NOT NULL,
@@ -84,7 +86,7 @@ $sql = "CREATE TABLE IF NOT EXISTS `".$mysql_table."` (
   `diversion` varchar(256) NOT NULL,
   `diversion` varchar(256) NOT NULL,
   `reason` varchar(200) NOT NULL,
   `reason` varchar(200) NOT NULL,
   `content_type` varchar(256) NOT NULL,
   `content_type` varchar(256) NOT NULL,
-  `authorization` varchar(256) NOT NULL,
+  `".$auth_column."` varchar(120) NOT NULL,
   `user_agent` varchar(256) NOT NULL,
   `user_agent` varchar(256) NOT NULL,
   `source_ip` varchar(60) NOT NULL DEFAULT '',
   `source_ip` varchar(60) NOT NULL DEFAULT '',
   `source_port` int(10) NOT NULL,
   `source_port` int(10) NOT NULL,
@@ -112,7 +114,7 @@ $sql = "CREATE TABLE IF NOT EXISTS `".$mysql_table."` (
   KEY `method` (`method`),
   KEY `method` (`method`),
   KEY `source_ip` (`source_ip`),
   KEY `source_ip` (`source_ip`),
   KEY `destination_ip` (`destination_ip`)
   KEY `destination_ip` (`destination_ip`)
-) ENGINE=".$engine." DEFAULT CHARSET=latin1
+) ENGINE=".$engine." DEFAULT CHARSET=utf8 $compress
 PARTITION BY RANGE ( UNIX_TIMESTAMP(`date`)) (PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE = ".$engine.")";
 PARTITION BY RANGE ( UNIX_TIMESTAMP(`date`)) (PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE = ".$engine.")";
 
 
 my $sth = $db->do($sql) if($check_table == 1);
 my $sth = $db->do($sql) if($check_table == 1);
@@ -133,76 +135,60 @@ $sth = $db->prepare($query);
 $sth->execute();
 $sth->execute();
 my ($curtstamp) = $sth->fetchrow_array();
 my ($curtstamp) = $sth->fetchrow_array();
 $curtstamp+=0; 
 $curtstamp+=0; 
+$todaytstamp+=0;
 
 
-my $query = "SELECT COUNT(*) FROM INFORMATION_SCHEMA.PARTITIONS"
-            ."\n WHERE TABLE_NAME='".$mysql_table."' AND TABLE_SCHEMA='".$mysql_dbname."'";
-$sth = $db->prepare($query);
-$sth->execute();
-my ($partcount) = $sth->fetchrow_array();
-
-while($partcount > $maxparts ) {
 
 
-    $query = "SELECT PARTITION_NAME, MIN(PARTITION_DESCRIPTION)"
+my %PARTS;
+#Geting all partitions
+$query = "SELECT PARTITION_NAME, PARTITION_DESCRIPTION"
              ."\n FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME='".$mysql_table."'"
              ."\n FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME='".$mysql_table."'"
-             ."\n AND TABLE_SCHEMA='".$mysql_dbname."';";
+             ."\n AND TABLE_SCHEMA='".$mysql_dbname."' ORDER BY PARTITION_DESCRIPTION ASC;";
+$sth = $db->prepare($query);
+$sth->execute();
+my ($partcount) = $sth->rows;
+while(my ($minpart,$todaytstamp) = $sth->fetchrow_array()) {
 
 
-    $sth = $db->prepare($query);
-    $sth->execute();
-    my ($minpart,$todaytstamp) = $sth->fetchrow_array();
-    $todaytstamp+=0;
-    
-    #Dont' delete the partition for the current day or for future. Bad idea!
-    if($curtstamp <= $todaytstamp) {    
-          $partcount = 0;
+    if($partcount <= $totalparts || $curtstamp <= $todaytstamp) {
+          #Creating HASH of existing partitions  
+          $PARTS{$minpart."_".$todaytstamp} = 1;
           next;
           next;
     }
     }
-           
-    #Delete
+    
+    next if($minpart eq "pmax");
+    
     $query = "ALTER TABLE ".$mysql_table." DROP PARTITION ".$minpart;
     $query = "ALTER TABLE ".$mysql_table." DROP PARTITION ".$minpart;
     $db->do($query);
     $db->do($query);
     if (!$db->{Executed}) {
     if (!$db->{Executed}) {
            print "Couldn't drop partition: $minpart\n";
            print "Couldn't drop partition: $minpart\n";
            break;
            break;
     }
     }
-    
-    #decrease partcount
-    $partcount--;
+
+    $partcount--;      
 }
 }
 
 
 # < condition
 # < condition
 $curtstamp+=(86400);
 $curtstamp+=(86400);
 
 
-#Create new partitions 
+#Create new partitions
 for(my $i=0; $i<$newparts; $i++) {
 for(my $i=0; $i<$newparts; $i++) {
 
 
     $oldstamp = $curtstamp;
     $oldstamp = $curtstamp;
-    $curtstamp+=$mystep;
-    
+    $curtstamp+=$mystep;   
+
     ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($oldstamp);
     ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($oldstamp);
 
 
-    my $newpartname = sprintf("p%04d%02d%02d%02d",($year+=1900),(++$mon),$mday,$hour);    
+    my $newpartname = sprintf("p%04d%02d%02d%02d",($year+=1900),(++$mon),$mday,$hour);
     $newpartname.= sprintf("%02d", $min) if($partstep > 1);
     $newpartname.= sprintf("%02d", $min) if($partstep > 1);
-    
-    $query = "SELECT COUNT(*) "
-             ."\n FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME='".$mysql_table."'"
-             ."\n AND TABLE_SCHEMA='".$mysql_dbname."' AND PARTITION_NAME='".$newpartname."'"
-             ."\n AND PARTITION_DESCRIPTION = '".$curtstamp."'";
-             
-    $sth = $db->prepare($query);
-    $sth->execute();
-    my ($exist) = $sth->fetchrow_array();
-    $exist+=0;
-    
-    if(!$exist) {
 
 
-	# Fix MAXVALUE. Thanks Dorn B. <[email protected]> for report and fix.
-        $query = "ALTER TABLE ".$mysql_table." REORGANIZE PARTITION pmax INTO (PARTITION ".$newpartname
-                                ."\n VALUES LESS THAN (".$curtstamp.") ENGINE = ".$engine.", PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE = ".$engine.")";  
+    if(!defined $PARTS{$newpartname."_".$curtstamp}) {
 
 
+        # Fix MAXVALUE. Thanks Dorn B. <[email protected]> for report and fix.
+        $query = "ALTER TABLE ".$mysql_table." REORGANIZE PARTITION pmax INTO (PARTITION ".$newpartname
+                                ."\n VALUES LESS THAN (".$curtstamp.") ENGINE = ".$engine.", PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE = ".$engine.")";
         $db->do($query);
         $db->do($query);
-                    
         if (!$db->{Executed}) {
         if (!$db->{Executed}) {
              print "Couldn't add partition: $newpartname\n";
              print "Couldn't add partition: $newpartname\n";
         }
         }
     }    
     }    
 }
 }
+

+ 0 - 156
modules/sipcapture/examples/statistic.pl

@@ -1,156 +0,0 @@
-#!/usr/bin/perl
-#
-# statistics.pl - perl script for Homer statistic
-#
-# Copyright (C) 2011 Alexandr Dubovikov (QSC AG) ([email protected])
-#
-# This file is part of webhomer, a free capture server.
-#
-# statistics is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version
-#
-# statistics is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
-
-use DBI;
-
-$version = "0.0.2";
-$mysql_table = "sip_capture";
-$mysql_dbname = "homer_db";
-$mysql_user = "homer_user";
-$mysql_password = "homer_password";
-$mysql_host = "localhost";
-$statsmethod = "stats_method";
-$statsuseragent = "stats_useragent";
-$keepdays = 100; #How long statistic must be keeped in DB
-$step = 300; # in seconds! for 5 minutes statistic. Script must start each 5 minutes 
-#Crontab:
-#*/5 * * * * statistic.pl 2>&1 > /dev/null
-
-my $db = DBI->connect("DBI:mysql:$mysql_dbname:$mysql_host:3306", $mysql_user, $mysql_password);
-
-#$db->{PrintError} = 0;
-
-@nowtime = localtime();
-@oldtime = localtime(time()-$step);
-
-#($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
-
-my $to_date = sprintf("'%04d-%02d-%02d %02d:%02d:00'",($nowtime[5]+=1900),(++$nowtime[4]),$nowtime[3],$nowtime[2], $nowtime[1]);
-my $from_date = sprintf("'%04d-%02d-%02d %02d:%02d:00'",($oldtime[5]+=1900),(++$oldtime[4]),$oldtime[3],$oldtime[2], $oldtime[1]);
-
-#QUERY
-my $mainquery = "FROM ".$mysql_table.$wheredata." WHERE `date` BETWEEN $from_date AND $to_date";
-#My ASR AND NER == 0 at this time;
-$ner = 0;
-$asr = 0;
-
-#statistic
-#ALL AND CURRENT PACKETS. ALL = ALL MESSAGES IN DB. CURRENT = MESSAGES IN THIS INTERVALL
-##############################################################################################
-$all = loadResult("SELECT COUNT(*) FROM ".$mysql_table);
-insertStat("stats_method","method='ALL',total='".$all."'");
-
-$current = loadResult("SELECT COUNT(*) ".$mainquery);
-insertStat("stats_method","method='CURRENT',total='".$current."'");
-
-##################################   INVITE ########################################################
-#ALL INVITES
-$invites = loadResult("SELECT COUNT(*) ".$mainquery." AND method = 'INVITE'");
-#ALL 407 for INVITE
-$auth = loadResult("SELECT COUNT(*) ".$mainquery." AND method = '407' AND cseq like '% INVITE'");
-#Total invites without AUTH
-$totalinvites = $invites - $auth;
-
-#ASR/NER
-#Ansered INVITES
-$answered = loadResult("SELECT COUNT(*) ".$mainquery." AND method='200' AND cseq like '% INVITE'");
-#NER
-$bad486 = loadResult("SELECT COUNT(*) ".$mainquery." AND method IN ('486','487','603') AND cseq like '% INVITE'");
-#UNSANSWERED
-$unanswered = $totalinvites - $answered;
-
-#fix for retransmitions
-if($unanswered < 0) { $unanswered = 0; }
-if($answered > $totalinvites) { $answered=$totalinvites; }
-
-if($totalinvites > 0) {
-  $ner = sprintf( "%.0f", ($answered+$bad486)/$totalinvites*100);
-  $asr = sprintf( "%.0f", $answered/$totalinvites*100);
-}
-
-$value="method='INVITE',total='".$invites."',auth='".$auth."',completed='"
-    .$answered."',uncompleted='".$unanswered."',rejected='".$bad486."',asr='".$asr."',ner='".$ner."'";
-insertStat($statsmethod,$value);
-
-##################################  REGISTERED ########################################################
-#ALL REGISTRATION
-$registers = loadResult("SELECT COUNT(*) ".$mainquery." AND method = 'REGISTER'");
-#ALL 401 for REGISTER
-$regiserauth = loadResult("SELECT COUNT(*) ".$mainquery." AND method = '401' AND cseq like '% REGISTER'");
-#REGISTERED! for expire =0 will be also calculate as registered. Bad idea but no chance :-/
-$registered = loadResult("SELECT COUNT(*) ".$mainquery." AND method='200' AND cseq like '% REGISTER'");
-
-#Bad register
-$badregister=0;
-$badregister = $regiserauth - $registered if($registered < $regiserauth);
-insertStat($statsmethod,"method='REGISTER', uncompleted='".$badregister."', total='".$registers."',auth='".$regiserauth."',completed='".$registered."'");
-
-#USER AGENT
-#REGISTRATION
-$query = "SELECT user_agent, COUNT(*) as cnt ".$mainquery." AND method = 'REGISTER' GROUP BY user_agent";
-$sth = $db->prepare($query);
-$sth->execute();
-while ( @row = $sth->fetchrow_array ) {
-    $myuas = $db->quote($row[0]);
-    insertStat($statsuseragent,"method='REGISTER',useragent=".$myuas.",total=".$row[1]);
-}
-
-#INVITES
-$query = "SELECT user_agent, COUNT(*) as cnt ".$mainquery." AND method = 'INVITE' GROUP BY user_agent";
-$sth = $db->prepare($query);
-$sth->execute();
-while ( @row = $sth->fetchrow_array ) {
-    $myuas = $db->quote($row[0]);
-    insertStat($statsuseragent,"method='INVITE',useragent=".$myuas.",total=".$row[1]);
-}
-
-#Time for CLEAR OLD records;
-clearOldData() if($nowtime[2] == 0 && $nowtime[1] == 0) ;
-
-sub loadResult() {
-    my $query = shift;
-    $sth = $db->prepare($query);
-    $sth->execute();
-    my $result = $sth->fetchrow_array();
-    return $result;
-}
-
-sub insertStat() {
-    my $table = shift;
-    my $values = shift;
-    my $query = "INSERT INTO ".$table." SET `from_date`=".$from_date.", `to_date`=".$to_date.",".$values;
-    $sth2 = $db->prepare($query);
-    $sth2->execute();
-    return 1;
-}
-
-sub clearOldData() {
-  $query = "DELETE FROM ".$statsmethod." WHERE `from_date` < UNIX_TIMESTAMP(CURDATE() - INTERVAL ".$keepdays." DAY)";
-  $sth = $db->prepare($query);
-  $sth->execute();
-
-  $query = "DELETE FROM ".$statsuseragent." WHERE `from_date` < UNIX_TIMESTAMP(CURDATE() - INTERVAL ".$keepdays." DAY)";
-  $sth = $db->prepare($query);
-  $sth->execute();
-}
-
-

+ 19 - 9
modules/sipcapture/hep.c

@@ -3,7 +3,7 @@
  *
  *
  * hep related functions
  * hep related functions
  *
  *
- * Copyright (C) 2011-12 Alexandr Dubovikov <[email protected]>
+ * Copyright (C) 2011-14 Alexandr Dubovikov <[email protected]>
  *
  *
  * This file is part of Kamailio, a free SIP server.
  * This file is part of Kamailio, a free SIP server.
  *
  *
@@ -31,8 +31,12 @@
 #include "../../mem/mem.h"
 #include "../../mem/mem.h"
 #include "../../mem/shm_mem.h"
 #include "../../mem/shm_mem.h"
 #include "../../lib/srdb1/db.h"
 #include "../../lib/srdb1/db.h"
+#include "../../receive.h"
 
 
 #include "hep.h"
 #include "hep.h"
+#include "sipcapture.h"
+
+
 
 
 static int count = 0;
 static int count = 0;
 
 
@@ -208,8 +212,7 @@ int hepv2_received(char *buf, unsigned int len, struct receive_info *ri){
 
 
         hep_payload = buf + hep_offset;
         hep_payload = buf + hep_offset;
 
 
-        receive_msg(hep_payload,(unsigned int)(len - hep_offset) , ri);
-	//memset(buf, '\n', hep_offset); /* the parser will ignore the starting \n no need to do expensive memmove */
+        receive_msg(hep_payload,(unsigned int)(len - hep_offset), ri);
 	
 	
 	return -1;
 	return -1;
 }
 }
@@ -386,7 +389,6 @@ int parsing_hepv3_message(char *buf, unsigned int len) {
                                         hg->capt_id  = (hep_chunk_uint32_t *) (tmp);
                                         hg->capt_id  = (hep_chunk_uint32_t *) (tmp);
                                         i+=chunk_length;
                                         i+=chunk_length;
                                         heptime->captid = ntohs(hg->capt_id->data);
                                         heptime->captid = ntohs(hg->capt_id->data);
-                                        //LM_ERR("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX: [%i] vs [%i]\n", heptime->captid, ntohl(hg->capt_id->data));
                                         totelem++;
                                         totelem++;
                                         break;
                                         break;
 
 
@@ -396,7 +398,7 @@ int parsing_hepv3_message(char *buf, unsigned int len) {
                                         break;                                                     
                                         break;                                                     
 
 
                                 case 14:
                                 case 14:
-                                        hg->auth_key  = (hep_chunk_str_t *) (tmp);
+                                        authkey = (char *) tmp + sizeof(hep_chunk_t);
                                         i+=chunk_length;                                                                             
                                         i+=chunk_length;                                                                             
                                         break;
                                         break;
                                                      
                                                      
@@ -407,6 +409,12 @@ int parsing_hepv3_message(char *buf, unsigned int len) {
                                         i+=chunk_length;
                                         i+=chunk_length;
                                         totelem++;
                                         totelem++;
                                         break;
                                         break;
+                                case 17:
+                                
+                                        correlation_id = (char *) tmp + sizeof(hep_chunk_t);
+                                        i+=chunk_length;                                                                            
+					break;
+
                                                      
                                                      
                                 default:
                                 default:
                                         i+=chunk_length;
                                         i+=chunk_length;
@@ -474,12 +482,14 @@ int parsing_hepv3_message(char *buf, unsigned int len) {
         heptime->tv_usec = hg->time_usec->data;
         heptime->tv_usec = hg->time_usec->data;
         heptime->captid = ntohs(hg->capt_id->data);
         heptime->captid = ntohs(hg->capt_id->data);
           
           
- 
+
         if(payload != NULL ) {
         if(payload != NULL ) {
-                /* and now recieve message */
-                receive_msg(payload, payload_len, &ri);
+                /* and now recieve message */                
+                if (hg->proto_t->data == 5) receive_logging_json_msg(payload, payload_len, hg, "rtcp_capture");
+                else if (hg->proto_t->data == 100) receive_logging_json_msg(payload, payload_len, hg, "logs_capture");                
+                else receive_msg(payload, payload_len, &ri);
         }
         }
-        
+
 done:
 done:
         if(si) pkg_free(si);
         if(si) pkg_free(si);
         if(hg) pkg_free(hg);                     
         if(hg) pkg_free(hg);                     

+ 4 - 3
modules/sipcapture/hep.h

@@ -3,7 +3,7 @@
  *
  *
  * hep related structure
  * hep related structure
  *
  *
- * Copyright (C) 2011-12 Alexandr Dubovikov <[email protected]>
+ * Copyright (C) 2011-14 Alexandr Dubovikov <[email protected]>
  *
  *
  * This file is part of Kamailio, a free SIP server.
  * This file is part of Kamailio, a free SIP server.
  *
  *
@@ -36,8 +36,8 @@ typedef uint32_t u_int32_t;
 
 
 extern int hep_capture_on;
 extern int hep_capture_on;
 extern int hep_offset;
 extern int hep_offset;
-
-#include "../../receive.h"
+extern char *authkey;
+extern char *correlation_id;
 
 
 /* int hep_msg_received(char * buf, unsigned int len, struct receive_info * ri);*/
 /* int hep_msg_received(char * buf, unsigned int len, struct receive_info * ri);*/
 int hep_msg_received(void *data);
 int hep_msg_received(void *data);
@@ -154,6 +154,7 @@ struct hep_generic_recv {
         hep_chunk_uint32_t *capt_id;
         hep_chunk_uint32_t *capt_id;
         hep_chunk_uint16_t *keep_tm;
         hep_chunk_uint16_t *keep_tm;
         hep_chunk_str_t    *auth_key;
         hep_chunk_str_t    *auth_key;
+        hep_chunk_str_t    *correlation_id;        
         hep_chunk_t   *payload_chunk;
         hep_chunk_t   *payload_chunk;
 } __attribute__((packed));
 } __attribute__((packed));
 
 

+ 181 - 20
modules/sipcapture/sipcapture.c

@@ -3,7 +3,7 @@
  *
  *
  * sipcapture module - helper module to capture sip messages
  * sipcapture module - helper module to capture sip messages
  *
  *
- * Copyright (C) 2011 Alexandr Dubovikov (QSC AG) ([email protected])
+ * Copyright (C) 2011-2014 Alexandr Dubovikov (QSC AG) ([email protected])
  *
  *
  * This file is part of Kamailio, a free SIP server.
  * This file is part of Kamailio, a free SIP server.
  *
  *
@@ -39,6 +39,7 @@
 #include <netinet/in.h>
 #include <netinet/in.h>
 #include <net/if.h> 
 #include <net/if.h> 
 #include <netdb.h>
 #include <netdb.h>
+#include <arpa/inet.h>
 
 
 /* BPF structure */
 /* BPF structure */
 #ifdef __OS_linux
 #ifdef __OS_linux
@@ -93,7 +94,8 @@ MODULE_VERSION
 
 
 #define TABLE_LEN 256
 #define TABLE_LEN 256
 
 
-#define NR_KEYS 36
+#define NR_KEYS 37
+#define RTCP_NR_KEYS 12
 
 
 /*multiple table mode*/
 /*multiple table mode*/
 enum e_mt_mode{
 enum e_mt_mode{
@@ -149,6 +151,7 @@ static str date_column		= str_init("date");
 static str micro_ts_column 	= str_init("micro_ts");
 static str micro_ts_column 	= str_init("micro_ts");
 static str method_column 	= str_init("method"); 	
 static str method_column 	= str_init("method"); 	
 static str reply_reason_column 	= str_init("reply_reason");        
 static str reply_reason_column 	= str_init("reply_reason");        
+static str correlation_column 	= str_init("correlation_id");
 static str ruri_column 		= str_init("ruri");     	
 static str ruri_column 		= str_init("ruri");     	
 static str ruri_user_column 	= str_init("ruri_user");  
 static str ruri_user_column 	= str_init("ruri_user");  
 static str from_user_column 	= str_init("from_user");  
 static str from_user_column 	= str_init("from_user");  
@@ -203,6 +206,7 @@ int insert_retry_timeout = 60;
 int hep_offset = 0;
 int hep_offset = 0;
 str raw_socket_listen = { 0, 0 };
 str raw_socket_listen = { 0, 0 };
 str raw_interface = { 0, 0 };
 str raw_interface = { 0, 0 };
+char *authkey = NULL, *correlation_id = NULL;
 
 
 struct ifreq ifr; 	/* interface structure */
 struct ifreq ifr; 	/* interface structure */
 
 
@@ -258,6 +262,7 @@ static param_export_t params[] = {
 	{"date_column",        		PARAM_STR, &date_column       },
 	{"date_column",        		PARAM_STR, &date_column       },
 	{"micro_ts_column",     	PARAM_STR, &micro_ts_column	},
 	{"micro_ts_column",     	PARAM_STR, &micro_ts_column	},
 	{"method_column",      		PARAM_STR, &method_column 	},
 	{"method_column",      		PARAM_STR, &method_column 	},
+        {"correlation_column",     	PARAM_STR, &correlation_column.s },
 	{"reply_reason_column",		PARAM_STR, &reply_reason_column	},
 	{"reply_reason_column",		PARAM_STR, &reply_reason_column	},
 	{"ruri_column",      		PARAM_STR, &ruri_column     	},
 	{"ruri_column",      		PARAM_STR, &ruri_column     	},
 	{"ruri_user_column",      	PARAM_STR, &ruri_user_column  },
 	{"ruri_user_column",      	PARAM_STR, &ruri_user_column  },
@@ -1082,7 +1087,7 @@ static int sip_capture_store(struct _sipcapture_object *sco, str *dtable, _captu
 	db_key_t db_keys[NR_KEYS];
 	db_key_t db_keys[NR_KEYS];
 	db_val_t db_vals[NR_KEYS];
 	db_val_t db_vals[NR_KEYS];
 
 
-	str tmp;
+	str tmp, corrtmp;
 	int ii = 0;
 	int ii = 0;
 	int ret = 0;
 	int ret = 0;
 	int counter = 0;
 	int counter = 0;
@@ -1104,6 +1109,11 @@ static int sip_capture_store(struct _sipcapture_object *sco, str *dtable, _captu
 		return -1;
 		return -1;
 	}
 	}
 	
 	
+	if(correlation_id) {
+	         corrtmp.s = correlation_id;
+	         corrtmp.len = strlen(correlation_id);        
+        }
+	
 	db_keys[0] = &date_column;
 	db_keys[0] = &date_column;
 	db_vals[0].type = DB1_DATETIME;
 	db_vals[0].type = DB1_DATETIME;
 	db_vals[0].nul = 0;
 	db_vals[0].nul = 0;
@@ -1278,29 +1288,21 @@ static int sip_capture_store(struct _sipcapture_object *sco, str *dtable, _captu
 	db_vals[34].type = DB1_STR;
 	db_vals[34].type = DB1_STR;
 	db_vals[34].nul = 0;
 	db_vals[34].nul = 0;
 	db_vals[34].val.str_val = sco->node;
 	db_vals[34].val.str_val = sco->node;
-	
-	db_keys[35] = &msg_column;
-	db_vals[35].type = DB1_BLOB;
-	db_vals[35].nul = 0;
-		
-	/* need to be removed in the future */
-        /* if message was captured via hep skip trailing empty spaces(newlines) from the start of the buffer */
-	/* if(hep_offset>0){
-		tmp.s = sco->msg.s + hep_offset;
-		tmp.len = sco->msg.len - hep_offset;
-		hep_offset = 0;
-	} else {
 
 
-		tmp.s = sco->msg.s;
-		tmp.len = sco->msg.len;
-	}
-	*/
+	db_keys[35] = &correlation_column;
+	db_vals[35].type = DB1_STR;
+	db_vals[35].nul = 0;
+	db_vals[35].val.str_val = (correlation_id) ? corrtmp : sco->callid;	
 	
 	
+	db_keys[36] = &msg_column;
+	db_vals[36].type = DB1_BLOB;
+	db_vals[36].nul = 0;
+
 	/*we don't have empty spaces now */
 	/*we don't have empty spaces now */
 	tmp.s = sco->msg.s;
 	tmp.s = sco->msg.s;
 	tmp.len = sco->msg.len;
 	tmp.len = sco->msg.len;
 
 
-	db_vals[35].val.blob_val = tmp;
+	db_vals[36].val.blob_val = tmp;
 
 
 	if (dtable){
 	if (dtable){
 		table = dtable;
 		table = dtable;
@@ -2041,3 +2043,162 @@ static int sipcapture_init_rpc(void)
 	return 0;
 	return 0;
 }
 }
 
 
+
+
+/* for rtcp and logging */
+int receive_logging_json_msg(char * buf, unsigned int len, struct hep_generic_recv *hg, char *log_table) {
+
+
+	db_key_t db_keys[RTCP_NR_KEYS];
+	db_val_t db_vals[RTCP_NR_KEYS];
+        struct _sipcapture_object sco;
+	char ipstr_dst[INET6_ADDRSTRLEN], ipstr_src[INET6_ADDRSTRLEN];
+	char tmp_node[100];
+        struct timeval tvb;
+        struct timezone tz;    
+        time_t epoch_time_as_time_t;
+        
+	str tmp, corrtmp, table;
+	_capture_mode_data_t *c = NULL;
+
+	c = capture_def;
+	if (!c){
+		LM_ERR("no connection mode available to store data\n");
+		return -1;
+	}
+
+	memset(&sco, 0, sizeof(struct _sipcapture_object));
+	gettimeofday( &tvb, &tz );
+
+        /* PROTO TYPE */
+        if(hg->ip_proto->data == IPPROTO_TCP) sco.proto=PROTO_TCP;
+        else if(hg->ip_proto->data == IPPROTO_UDP) sco.proto=PROTO_UDP;
+        /* FAMILY TYPE */
+        sco.family = hg->ip_family->data;
+
+        /* IP source and destination */
+
+	if ( hg->ip_family->data == AF_INET6 ) {
+        	inet_ntop(AF_INET6, &(hg->hep_dst_ip6->data), ipstr_dst, INET6_ADDRSTRLEN);	       
+        	inet_ntop(AF_INET6, &(hg->hep_src_ip6->data), ipstr_src, INET6_ADDRSTRLEN);	       
+        }
+	else if ( hg->ip_family->data == AF_INET ) {
+        	inet_ntop(AF_INET, &(hg->hep_src_ip4->data), ipstr_src, INET_ADDRSTRLEN);
+        	inet_ntop(AF_INET, &(hg->hep_dst_ip4->data), ipstr_dst, INET_ADDRSTRLEN);
+	}
+
+
+        /*source ip*/
+        sco.source_ip.s = ipstr_src;
+        sco.source_ip.len = strlen(ipstr_src);
+        sco.source_port = hg->src_port->data;        
+        
+        sco.destination_ip.s = ipstr_dst;
+        sco.destination_ip.len = strlen(ipstr_dst);
+        sco.destination_port = hg->dst_port->data;
+
+	if(heptime && heptime->tv_sec != 0) {
+               sco.tmstamp = (unsigned long long)heptime->tv_sec*1000000+heptime->tv_usec; /* micro ts */
+               snprintf(tmp_node, 100, "%.*s:%i", capture_node.len, capture_node.s, heptime->captid);
+               sco.node.s = tmp_node;
+               sco.node.len = strlen(tmp_node);
+               epoch_time_as_time_t = heptime->tv_sec;;
+        }
+        else {
+               sco.tmstamp = (unsigned long long)tvb.tv_sec*1000000+tvb.tv_usec; /* micro ts */
+               sco.node = capture_node;
+               epoch_time_as_time_t = tvb.tv_sec;
+        }
+
+        if(correlation_id) {
+                corrtmp.s = correlation_id;
+                corrtmp.len = strlen(correlation_id);
+                if(!strncmp(log_table, "rtcp_capture",12)) corrtmp.len--;
+        }
+
+	db_keys[0] = &date_column;
+	db_vals[0].type = DB1_DATETIME;
+	db_vals[0].nul = 0;
+	db_vals[0].val.time_val = epoch_time_as_time_t;
+	
+	db_keys[1] = &micro_ts_column;
+        db_vals[1].type = DB1_BIGINT;
+        db_vals[1].nul = 0;
+        db_vals[1].val.ll_val = sco.tmstamp;
+	
+	db_keys[2] = &correlation_column;
+	db_vals[2].type = DB1_STR;
+	db_vals[2].nul = 0;
+	db_vals[2].val.str_val = corrtmp;
+	
+	db_keys[3] = &source_ip_column;
+	db_vals[3].type = DB1_STR;
+	db_vals[3].nul = 0;
+	db_vals[3].val.str_val = sco.source_ip;
+	
+	db_keys[4] = &source_port_column;
+        db_vals[4].type = DB1_INT;
+        db_vals[4].nul = 0;
+        db_vals[4].val.int_val = sco.source_port;
+        
+	db_keys[5] = &dest_ip_column;
+	db_vals[5].type = DB1_STR;
+	db_vals[5].nul = 0;
+	db_vals[5].val.str_val = sco.destination_ip;
+	
+	db_keys[6] = &dest_port_column;
+        db_vals[6].type = DB1_INT;
+        db_vals[6].nul = 0;
+        db_vals[6].val.int_val = sco.destination_port;        
+        
+        db_keys[7] = &proto_column;			
+        db_vals[7].type = DB1_INT;
+        db_vals[7].nul = 0;
+        db_vals[7].val.int_val = sco.proto;        
+
+        db_keys[8] = &family_column;			
+        db_vals[8].type = DB1_INT;
+        db_vals[8].nul = 0;
+        db_vals[8].val.int_val = sco.family;        
+        
+        db_keys[9] = &type_column;			
+        db_vals[9].type = DB1_INT;
+        db_vals[9].nul = 0;
+        db_vals[9].val.int_val = sco.type;                
+
+	db_keys[10] = &node_column;
+	db_vals[10].type = DB1_STR;
+	db_vals[10].nul = 0;
+	db_vals[10].val.str_val = sco.node;
+	
+	db_keys[11] = &msg_column;
+	db_vals[11].type = DB1_BLOB;
+	db_vals[11].nul = 0;
+		
+	tmp.s = buf;
+	tmp.len = len;
+	
+	db_vals[11].val.blob_val = tmp;
+
+	table.s = log_table;
+	table.len = strlen(log_table);
+
+	c->db_funcs.use_table(c->db_con, &table);
+
+	if(db_insert_mode==1 && c->db_funcs.insert_delayed!=NULL) {
+                if (c->db_funcs.insert_delayed(c->db_con, db_keys, db_vals, RTCP_NR_KEYS) < 0) {
+                	LM_ERR("failed to insert delayed into database\n");
+                        goto error;
+                }
+        } else if (c->db_funcs.insert(c->db_con, db_keys, db_vals, RTCP_NR_KEYS) < 0) {
+		LM_ERR("failed to insert into database\n");
+                goto error;               
+	}
+                
+	
+	return 1;
+error:
+	return -1;
+}
+
+

+ 10 - 1
modules/sipcapture/sipcapture.h

@@ -3,7 +3,7 @@
  *
  *
  * hep related structure
  * hep related structure
  *
  *
- * Copyright (C) 2011 Alexandr Dubovikov (QSC AG) ([email protected])
+ * Copyright (C) 2011-2014 Alexandr Dubovikov (QSC AG) ([email protected])
  *
  *
  * This file is part of Kamailio, a free SIP server.
  * This file is part of Kamailio, a free SIP server.
  *
  *
@@ -23,6 +23,9 @@
  *
  *
  */
  */
 
 
+#ifndef _sipcapture_h
+#define _sipcapture_h
+
 struct _sipcapture_object {
 struct _sipcapture_object {
 	str method;
 	str method;
 	str reply_reason;
 	str reply_reason;
@@ -64,3 +67,9 @@ struct _sipcapture_object {
 	stat_var *stat;
 	stat_var *stat;
 #endif
 #endif
 };
 };
+
+
+struct hep_generic_recv;
+int receive_logging_json_msg(char * buf, unsigned int len, struct hep_generic_recv *hg, char *log_table);
+
+#endif /* _sipcapture_h */

+ 25 - 0
modules/sipcapture/sql/create_logs_capture.sql

@@ -0,0 +1,25 @@
+CREATE TABLE IF NOT EXISTS `logs_capture` (
+  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+  `date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+  `micro_ts` bigint(18) NOT NULL DEFAULT '0',
+  `correlation_id` varchar(256) NOT NULL DEFAULT '',
+  `source_ip` varchar(60) NOT NULL DEFAULT '',
+  `source_port` int(10) NOT NULL,
+  `destination_ip` varchar(60) NOT NULL DEFAULT '',
+  `destination_port` int(10) NOT NULL,
+  `proto` int(5) NOT NULL,
+  `family` int(1) DEFAULT NULL,
+  `type` int(2) NOT NULL,
+  `node` varchar(125) NOT NULL,
+  `msg` varchar(2500) NOT NULL,
+  PRIMARY KEY (`id`,`date`),
+  KEY `date` (`date`),
+  KEY `correlationid` (`correlation_id`(255))
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8
+/*!50100 PARTITION BY RANGE ( UNIX_TIMESTAMP(`date`))
+(PARTITION p2013082901 VALUES LESS THAN (1377734400) ENGINE = InnoDB,
+ PARTITION p2013090821 VALUES LESS THAN (1378670400) ENGINE = InnoDB,
+ PARTITION p2013090822 VALUES LESS THAN (1378674000) ENGINE = InnoDB,
+ PARTITION p2013090823 VALUES LESS THAN (1378677600) ENGINE = InnoDB,
+ PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */
+

+ 25 - 0
modules/sipcapture/sql/create_rtcp_capture.sql

@@ -0,0 +1,25 @@
+CREATE TABLE IF NOT EXISTS `rtcp_capture` (
+  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+  `date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+  `micro_ts` bigint(18) NOT NULL DEFAULT '0',
+  `correlation_id` varchar(256) NOT NULL DEFAULT '',
+  `source_ip` varchar(60) NOT NULL DEFAULT '',
+  `source_port` int(10) NOT NULL,
+  `destination_ip` varchar(60) NOT NULL DEFAULT '',
+  `destination_port` int(10) NOT NULL,
+  `proto` int(5) NOT NULL,
+  `family` int(1) DEFAULT NULL,
+  `type` int(2) NOT NULL,
+  `node` varchar(125) NOT NULL,
+  `msg` varchar(1500) NOT NULL,
+  PRIMARY KEY (`id`,`date`),
+  KEY `date` (`date`),
+  KEY `correlationid` (`correlation_id`(255))
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8
+/*!50100 PARTITION BY RANGE ( UNIX_TIMESTAMP(`date`))
+(PARTITION p2013082901 VALUES LESS THAN (1377734400) ENGINE = InnoDB,
+ PARTITION p2013090821 VALUES LESS THAN (1378670400) ENGINE = InnoDB,
+ PARTITION p2013090822 VALUES LESS THAN (1378674000) ENGINE = InnoDB,
+ PARTITION p2013090823 VALUES LESS THAN (1378677600) ENGINE = InnoDB,
+ PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */
+

+ 8 - 5
modules/sipcapture/sql/create_sipcapture.sql

@@ -2,7 +2,7 @@
  * only for MYSQL >= 5.1.43
  * only for MYSQL >= 5.1.43
 */
 */
 
 
-/* schema version 2 */
+/* this SQL schema version # 3 */
 
 
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
 /*!40101 SET character_set_client = utf8 */;
 /*!40101 SET character_set_client = utf8 */;
@@ -14,9 +14,12 @@ CREATE TABLE `sip_capture` (
   `reply_reason` varchar(100) NOT NULL,
   `reply_reason` varchar(100) NOT NULL,
   `ruri` varchar(200) NOT NULL DEFAULT '',
   `ruri` varchar(200) NOT NULL DEFAULT '',
   `ruri_user` varchar(100) NOT NULL DEFAULT '',
   `ruri_user` varchar(100) NOT NULL DEFAULT '',
+  `ruri_domain` varchar(150) NOT NULL DEFAULT '',
   `from_user` varchar(100) NOT NULL DEFAULT '',
   `from_user` varchar(100) NOT NULL DEFAULT '',
+  `from_domain` varchar(150) NOT NULL DEFAULT '',
   `from_tag` varchar(64) NOT NULL DEFAULT '',
   `from_tag` varchar(64) NOT NULL DEFAULT '',
   `to_user` varchar(100) NOT NULL DEFAULT '',
   `to_user` varchar(100) NOT NULL DEFAULT '',
+  `to_domain` varchar(150) NOT NULL DEFAULT '',
   `to_tag` varchar(64) NOT NULL,
   `to_tag` varchar(64) NOT NULL,
   `pid_user` varchar(100) NOT NULL DEFAULT '',
   `pid_user` varchar(100) NOT NULL DEFAULT '',
   `contact_user` varchar(120) NOT NULL,
   `contact_user` varchar(120) NOT NULL,
@@ -26,14 +29,14 @@ CREATE TABLE `sip_capture` (
   `via_1` varchar(256) NOT NULL,
   `via_1` varchar(256) NOT NULL,
   `via_1_branch` varchar(80) NOT NULL,
   `via_1_branch` varchar(80) NOT NULL,
   `cseq` varchar(25) NOT NULL,
   `cseq` varchar(25) NOT NULL,
-  `diversion` varchar(256) NOT NULL,
+  `diversion` varchar(256) NOT NULL DEFAULT '',
   `reason` varchar(200) NOT NULL,
   `reason` varchar(200) NOT NULL,
   `content_type` varchar(256) NOT NULL,
   `content_type` varchar(256) NOT NULL,
   `auth` varchar(256) NOT NULL,
   `auth` varchar(256) NOT NULL,
   `user_agent` varchar(256) NOT NULL,
   `user_agent` varchar(256) NOT NULL,
-  `source_ip` varchar(50) NOT NULL DEFAULT '',
+  `source_ip` varchar(60) NOT NULL DEFAULT '',
   `source_port` int(10) NOT NULL,
   `source_port` int(10) NOT NULL,
-  `destination_ip` varchar(50) NOT NULL DEFAULT '',
+  `destination_ip` varchar(60) NOT NULL DEFAULT '',
   `destination_port` int(10) NOT NULL,
   `destination_port` int(10) NOT NULL,
   `contact_ip` varchar(60) NOT NULL,
   `contact_ip` varchar(60) NOT NULL,
   `contact_port` int(10) NOT NULL,
   `contact_port` int(10) NOT NULL,
@@ -54,7 +57,7 @@ CREATE TABLE `sip_capture` (
   KEY `callid_aleg` (`callid_aleg`),
   KEY `callid_aleg` (`callid_aleg`),
   KEY `date` (`date`),
   KEY `date` (`date`),
   KEY `callid` (`callid`)
   KEY `callid` (`callid`)
-) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
+) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8
 PARTITION BY RANGE ( UNIX_TIMESTAMP(`date`) ) (
 PARTITION BY RANGE ( UNIX_TIMESTAMP(`date`) ) (
 PARTITION pmax VALUES LESS THAN (MAXVALUE)
 PARTITION pmax VALUES LESS THAN (MAXVALUE)
 );
 );

+ 150 - 15
modules/sipcapture/sql/statistics.sql

@@ -1,29 +1,147 @@
+--
+-- structure for table `alarm_data`
+--
+DROP TABLE IF EXISTS alarm_data;
+CREATE TABLE IF NOT EXISTS `alarm_data` (
+  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+  `create_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+  `type` varchar(50) NOT NULL DEFAULT '',
+  `total` int(20) NOT NULL,
+  `source_ip` varchar(150) NOT NULL DEFAULT '0.0.0.0',
+  `description` varchar(256) NOT NULL,
+  `status` int(1) NOT NULL DEFAULT '1',
+  PRIMARY KEY (`id`),
+  KEY `to_date` (`create_date`),
+  KEY `method` (`type`)
+) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `alarm_data_mem`
+--
+DROP TABLE IF EXISTS alarm_data_mem;
+CREATE TABLE IF NOT EXISTS `alarm_data_mem` (
+  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+  `create_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+  `type` varchar(50) NOT NULL DEFAULT '',
+  `total` int(20) NOT NULL,
+  `source_ip` varchar(150) NOT NULL DEFAULT '0.0.0.0',
+  `description` varchar(256) NOT NULL,
+  `status` int(1) NOT NULL DEFAULT '1',
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `type` (`type`,`source_ip`),
+  KEY `to_date` (`create_date`),
+  KEY `method` (`type`)
+) ENGINE=MEMORY DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `stats_data`
+--
+DROP TABLE IF EXISTS stats_data;
+
+CREATE TABLE IF NOT EXISTS `stats_data` (
+  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+  `from_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+  `to_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+  `type` varchar(50) NOT NULL DEFAULT '',
+  `total` int(20) NOT NULL,
+  PRIMARY KEY (`id`),
+  KEY `from_date` (`from_date`),
+  KEY `to_date` (`to_date`),
+  KEY `method` (`type`)
+) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `stats_ip`
+--
+DROP TABLE IF EXISTS stats_ip;
+CREATE TABLE IF NOT EXISTS `stats_ip` (
+  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+  `from_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+  `to_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+  `method` varchar(50) NOT NULL DEFAULT '',
+  `source_ip` varchar(255) NOT NULL DEFAULT '0.0.0.0',
+  `total` int(20) NOT NULL,
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `datemethod` (`to_date`,`method`,`source_ip`),
+  KEY `from_date` (`from_date`),
+  KEY `to_date` (`to_date`),
+  KEY `method` (`method`)
+) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `stats_ip_mem`
+--
+DROP TABLE IF EXISTS stats_ip_mem;
+CREATE TABLE IF NOT EXISTS `stats_ip_mem` (
+  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+  `create_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+  `method` varchar(50) NOT NULL DEFAULT '',
+  `source_ip` varchar(255) NOT NULL DEFAULT '0.0.0.0',
+  `total` int(20) NOT NULL,
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `datemethod` (`method`,`source_ip`)
+) ENGINE=MEMORY DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `stats_method`
+--
 DROP TABLE IF EXISTS stats_method;
 DROP TABLE IF EXISTS stats_method;
 CREATE TABLE IF NOT EXISTS `stats_method` (
 CREATE TABLE IF NOT EXISTS `stats_method` (
   `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
   `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
   `from_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
   `from_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
   `to_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
   `to_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
   `method` varchar(50) NOT NULL DEFAULT '',
   `method` varchar(50) NOT NULL DEFAULT '',
-  `total` int(10) NOT NULL DEFAULT '0',
-  `auth` int(10) NOT NULL DEFAULT '0',
-  `completed` int(10) NOT NULL DEFAULT '0',
-  `uncompleted` int(10) NOT NULL DEFAULT '0',
-  `rejected` int(10) NOT NULL DEFAULT '0',
-  `asr` int(10) NOT NULL DEFAULT '0',
-  `ner` int(10) NOT NULL DEFAULT '0',
-  PRIMARY KEY (`id`),
-  UNIQUE KEY `datemethod` (`to_date`,`method`),
+  `auth` tinyint(1) NOT NULL DEFAULT '0',
+  `cseq` varchar(100) NOT NULL,
+  `totag` tinyint(1) NOT NULL,
+  `total` int(20) NOT NULL,
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `datemethod` (`to_date`,`method`,`auth`,`totag`,`cseq`),
   KEY `from_date` (`from_date`),
   KEY `from_date` (`from_date`),
   KEY `to_date` (`to_date`),
   KEY `to_date` (`to_date`),
   KEY `method` (`method`),
   KEY `method` (`method`),
-  KEY `total` (`total`),
-  KEY `completed` (`completed`),
-  KEY `uncompleted` (`uncompleted`)
-) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=latin1;
+  KEY `completed` (`cseq`)
+) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `stats_method_mem`
+--
+DROP TABLE IF EXISTS stats_method_mem;
+CREATE TABLE IF NOT EXISTS `stats_method_mem` (
+  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+  `create_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+  `method` varchar(50) NOT NULL DEFAULT '',
+  `auth` tinyint(1) NOT NULL DEFAULT '0',
+  `cseq` varchar(100) NOT NULL,
+  `totag` tinyint(1) NOT NULL,
+  `total` int(20) NOT NULL,
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `datemethod` (`method`,`auth`,`totag`, `cseq`),
+  KEY `from_date` (`create_date`),
+  KEY `method` (`method`),
+  KEY `completed` (`cseq`)
+) ENGINE=MEMORY DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
+
+-- --------------------------------------------------------
 
 
+--
+-- Table structure for table `stats_useragent`
+--
 DROP TABLE IF EXISTS stats_useragent;
 DROP TABLE IF EXISTS stats_useragent;
 CREATE TABLE IF NOT EXISTS `stats_useragent` (
 CREATE TABLE IF NOT EXISTS `stats_useragent` (
-`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
   `from_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
   `from_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
   `to_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
   `to_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
   `useragent` varchar(100) NOT NULL DEFAULT '',
   `useragent` varchar(100) NOT NULL DEFAULT '',
@@ -36,4 +154,21 @@ CREATE TABLE IF NOT EXISTS `stats_useragent` (
   KEY `useragent` (`useragent`),
   KEY `useragent` (`useragent`),
   KEY `method` (`method`),
   KEY `method` (`method`),
   KEY `total` (`total`)
   KEY `total` (`total`)
-) ENGINE=MyISAM AUTO_INCREMENT=2771 DEFAULT CHARSET=latin1;
+) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `stats_useragent_mem`
+--
+DROP TABLE IF EXISTS stats_useragent_mem;
+CREATE TABLE IF NOT EXISTS `stats_useragent_mem` (
+  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+  `create_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+  `useragent` varchar(100) NOT NULL DEFAULT '',
+  `method` varchar(50) NOT NULL DEFAULT '',
+  `total` int(10) NOT NULL DEFAULT '0',
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `useragent` (`useragent`,`method`)
+) ENGINE=MEMORY DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
+