From a7cf060c10cb5e723a40027f50a2d5cdd97e1467 Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Wed, 27 Apr 2016 10:41:58 +0200 Subject: [PATCH 01/24] fixed new rotation script. --- scripts/new/homer_mysql_rotate.pl | 259 +++++++++++++++++------------- scripts/new/rotation.ini | 24 +-- 2 files changed, 163 insertions(+), 120 deletions(-) diff --git a/scripts/new/homer_mysql_rotate.pl b/scripts/new/homer_mysql_rotate.pl index 5e29137..9a84331 100755 --- a/scripts/new/homer_mysql_rotate.pl +++ b/scripts/new/homer_mysql_rotate.pl @@ -30,8 +30,12 @@ $script_location =~ s/^\s+|\s+$//g; $default_ini = $script_location."/rotation.ini"; +#*DEBUG = STDOUT; + $config = $ARGV[0] // $default_ini; +$| =1; + @stepsvalues = (86400, 3600, 1800, 900); $AFTER_FIX = 1; @@ -49,12 +53,15 @@ $engine = $CONFIG{"MYSQL"}{"engine"}; $compress = $CONFIG{"MYSQL"}{"compress"}; -# Debug only -#foreach my $section (sort keys %CONFIG) { -# foreach my $value (keys %{ $CONFIG{$section} }) { -# print "$section, $value: $CONFIG{$section}{$value}\n"; -# } -#} +if($CONFIG{"SYSTEM"}{"debug"} == 1) +{ + #Debug only + foreach my $section (sort keys %CONFIG) { + foreach my $value (keys %{ $CONFIG{$section} }) { + print "$section, $value: $CONFIG{$section}{$value}\n"; + } + } +} $ORIGINAL_DATA_TABLE=<connect("DBI:mysql:".$CONFIG{"MYSQL"}{"db_data"}.":".$CONFIG{"MYSQL"}{"host"}.":".$CONFIG{"MYSQL"}{"port"}, $CONFIG{"MYSQL"}{"user"}, $CONFIG{"MYSQL"}{"password"}); - - for(my $y = 0 ; $y < ($newtables+1); $y++) - { - $curtstamp = time()+(86400*$y); - new_data_table($curtstamp, $mystep, $partstep, $ORIGINAL_DATA_TABLE, $table); - } - #And remove - $ltable = $DROP_DATA_TABLE; - $ltable =~s/\[TRANSACTION\]/$table/ig; - - for(my $y = 0 ; $y < 2; $y++) + #SIP Data tables + if($table=~/^sip_/) { - $curtstamp = time()-(86400*($maxparts[$i]+$y)); - my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($curtstamp); - my $kstamp = mktime (0, 0, 0, $mday, $mon, $year, $wday, $yday, $isdst); - my $table_timestamp = sprintf("%04d%02d%02d",($year+=1900),(++$mon),$mday); - - $query = $ltable; - $query=~s/\[TIMESTAMP\]/$table_timestamp/ig; - $db->do($query); + + for(my $y = 0 ; $y < ($newtables+1); $y++) + { + $curtstamp = time()+(86400*$y); + new_data_table($curtstamp, $mystep, $partstep, $ORIGINAL_DATA_TABLE, $table); + } + + #And remove + $ltable = $DROP_DATA_TABLE; + $ltable =~s/\[TRANSACTION\]/$table/ig; + + for(my $y = 0 ; $y < 2; $y++) + { + $curtstamp = time()-(86400*($maxparts[$i]+$y)); + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($curtstamp); + my $kstamp = mktime (0, 0, 0, $mday, $mon, $year, $wday, $yday, $isdst); + my $table_timestamp = sprintf("%04d%02d%02d",($year+=1900),(++$mon),$mday); + $query = $ltable; + $query=~s/\[TIMESTAMP\]/$table_timestamp/ig; + $db->do($query); + } + } + #Rtcp, Logs, Reports tables + else { + $coof=int(86400/$mystep); + #How much partitions + $maxparts*=$coof; + $newparts*=$coof; + #Now + new_partition_table($CONFIG{"MYSQL"}{"db_data"}, $table, $mystep, $partstep, $maxparts, $newparts); } } @@ -171,23 +191,117 @@ END #How much partitions $maxparts*=$coof; $newparts*=$coof; - $totalparts = ($maxparts+$newparts); + #$totalparts = ($maxparts+$newparts); $db = DBI->connect("DBI:mysql:".$CONFIG{"MYSQL"}{"db_stats"}.":".$CONFIG{"MYSQL"}{"host"}.":".$CONFIG{"MYSQL"}{"port"}, $CONFIG{"MYSQL"}{"user"}, $CONFIG{"MYSQL"}{"password"}); + + new_partition_table($CONFIG{"MYSQL"}{"db_stats"}, $table, $mystep, $partstep, $maxparts, $newparts); + +} + +if($AFTER_FIX) { + + $db = DBI->connect("DBI:mysql:".$CONFIG{"MYSQL"}{"db_data"}.":".$CONFIG{"MYSQL"}{"host"}.":".$CONFIG{"MYSQL"}{"port"}, $CONFIG{"MYSQL"}{"user"}, $CONFIG{"MYSQL"}{"password"}); + + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time() - 24*60*60*30); + + my $oldest = sprintf("%04d%02d%02d",($year+=1900),(++$mon),$mday,$hour); + $oldest+=0; + + my $query = "SHOW TABLES LIKE 'sip_capture_%';"; + $sth = $db->prepare($query); + $sth->execute(); + while(my @ref = $sth->fetchrow_array()) + { + my $table_full = $ref[0]; + my($proto, $cap, $type, $ts) = split(/_/, $table_full, 4); + $ts+=0; + if($ts < $oldest) { + my $drop = "DROP TABLE $full_table;"; + $drh = $db->prepare($query); + $drh->execute(); + + } + } +} + + +exit; + + +sub new_data_table() +{ + + my $cstamp = shift; + my $mystep = shift; + my $partstep = shift; + my $sqltable = shift; + my $table = shift; + + $newparts=int(86400/$mystep); + + my @partsadd; + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($cstamp); + my $kstamp = mktime (0, 0, 0, $mday, $mon, $year, $wday, $yday, $isdst); + + my $table_timestamp = sprintf("%04d%02d%02d",($year+=1900),(++$mon),$mday); + + $sqltable=~s/\[TIMESTAMP\]/$table_timestamp/ig; + + # < condition + for(my $i=0; $i<$newparts; $i++) { + my $oldstamp = $kstamp; + $kstamp+=$mystep; + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($oldstamp); + + my $newpartname = sprintf("p%04d%02d%02d%02d",($year+=1900),(++$mon),$mday,$hour); + $newpartname.= sprintf("%02d", $min) if($partstep > 1); + $query = "PARTITION ".$newpartname." VALUES LESS THAN (".$kstamp.")"; + push(@partsadd,$query); + + } + + my $parts_count=scalar @partsadd; + if($parts_count > 0) + { + $val = join(','."\n", @partsadd).","; + $sqltable=~s/\[PARTITIONS\]/$val/ig; + + $sqltable=~s/\[TRANSACTION\]/$table/ig; + $db->do($sqltable) or printf(STDERR "Failed to execute query [%s] with error: %s", ,$db->errstr); + print "create data table: $sqltable\n" if($CONFIG{"SYSTEM"}{"debug"} == 1); + #print "$sqltable\n"; + } +} + +sub new_partition_table() +{ + + my $database = shift; + my $table = shift; + my $mystep = shift; + my $partstep = shift; + my $maxparts = shift; + my $newparts = shift; + $part_key = "date"; #Name of part key if( $table =~/alarm_/) { $part_key = "create_date"; } elsif( $table =~/stats_/) { $part_key = "from_date"; } - + #check if the table has partitions. If not, create one - my $query = "SHOW TABLE STATUS FROM ".$CONFIG{"MYSQL"}{"db_stats"}. " WHERE Name='".$table."'"; - $sth = $db->prepare($query); + ##my $query = "SHOW TABLE STATUS FROM ".$CONFIG{"MYSQL"}{"db_stats"}. " WHERE Name='".$table."'"; + my $query="SELECT create_options FROM information_schema.tables WHERE table_schema = '".$database."' and table_name = '".$table."'"; + print "Debug: $query\n" if($CONFIG{"SYSTEM"}{"debug"} == 1); + $sth = $db->prepare($query); $sth->execute(); - my $tstatus = $sth->fetchrow_hashref()->{Create_options}; - if ($tstatus !~ /partitioned/) { + my ($tstatus) = $sth->fetchrow_array(); + #my $tstatus = $sth->fetchrow_hashref()->{Create_options}; + if ($tstatus !~ /partitioned/) { my $query = "ALTER TABLE ".$table. " PARTITION BY RANGE ( UNIX_TIMESTAMP(`".$part_key."`)) (PARTITION pmax VALUES LESS THAN MAXVALUE)"; - $sth = $db->prepare($query); + print "Table is not partitioned..[$table]" if($CONFIG{"SYSTEM"}{"debug"} == 1); + $sth = $db->prepare($query); $sth->execute(); } @@ -202,7 +316,7 @@ END #Geting all partitions $query = "SELECT PARTITION_NAME, PARTITION_DESCRIPTION" ."\n FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME='".$table."'" - ."\n AND TABLE_SCHEMA='".$$CONFIG{"MYSQL"}{"db_stats"}."' ORDER BY PARTITION_DESCRIPTION ASC;"; + ."\n AND TABLE_SCHEMA='".$database."' ORDER BY PARTITION_DESCRIPTION ASC;"; $sth = $db->prepare($query); $sth->execute(); my @oldparts; @@ -238,6 +352,7 @@ END { $query = "ALTER TABLE ".$table." DROP PARTITION ".join(',', @partsremove); $db->do($query) or printf(STDERR "Failed to execute query [%s] with error: %s", ,$db->errstr); + print "DROP Partition: [$query]\n" if($CONFIG{"SYSTEM"}{"debug"} == 1); if (!$db->{Executed}) { print "Couldn't drop partition: $minpart\n"; break; @@ -254,7 +369,7 @@ END my $newpartname = sprintf("p%04d%02d%02d%02d",($year+=1900),(++$mon),$mday,$hour); $newpartname.= sprintf("%02d", $min) if($partstep > 1); if(!defined $PARTS{$newpartname."_".$curtstamp}) { - $query = "\nPARTITION ".$newpartname." VALUES LESS THAN (".$curtstamp.")"; + $query = "\nPARTITION ".$newpartname." VALUES LESS THAN (".$curtstamp.")"; push(@partsadd,$query); } } @@ -265,86 +380,13 @@ END # Fix MAXVALUE. Thanks Dorn B. for report and fix. $query = "ALTER TABLE ".$table." REORGANIZE PARTITION pmax INTO (".join(',', @partsadd) ."\n, PARTITION pmax VALUES LESS THAN MAXVALUE)"; $db->do($query) or printf(STDERR "Failed to execute query [%s] with error: %s", ,$db->errstr); + print "Alter partition: [$query]\n" if($CONFIG{"SYSTEM"}{"debug"} == 1); if (!$db->{Executed}) { print "Couldn't drop partition: $minpart\n"; break; } } -} - -if($AFTER_FIX) { - - $db = DBI->connect("DBI:mysql:".$CONFIG{"MYSQL"}{"db_data"}.":".$CONFIG{"MYSQL"}{"host"}.":".$CONFIG{"MYSQL"}{"port"}, $CONFIG{"MYSQL"}{"user"}, $CONFIG{"MYSQL"}{"password"}); - - my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time() - 24*60*60*30); - - my $oldest = sprintf("%04d%02d%02d",($year+=1900),(++$mon),$mday,$hour); - $oldest+=0; - - my $query = "SHOW TABLES LIKE 'sip_capture_%';"; - $sth = $db->prepare($query); - $sth->execute(); - - while(my @ref = $sth->fetchrow_array()) - { - my $table_full = $ref[0]; - my($proto, $cap, $type, $ts) = split(/_/, $table_full, 4); - $ts+=0; - if($ts < $oldest) { - my $drop = "DROP TABLE $full_table;"; - $drh = $db->prepare($query); - $drh->execute(); - - } - } -} - -exit; - - -sub new_data_table() -{ - - my $cstamp = shift; - my $mystep = shift; - my $partstep = shift; - my $sqltable = shift; - my $table = shift; - - $newparts=int(86400/$mystep); - - my @partsadd; - my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($cstamp); - my $kstamp = mktime (0, 0, 0, $mday, $mon, $year, $wday, $yday, $isdst); - - my $table_timestamp = sprintf("%04d%02d%02d",($year+=1900),(++$mon),$mday); - - $sqltable=~s/\[TIMESTAMP\]/$table_timestamp/ig; - - # < condition - for(my $i=0; $i<$newparts; $i++) { - my $oldstamp = $kstamp; - $kstamp+=$mystep; - my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($oldstamp); - - my $newpartname = sprintf("p%04d%02d%02d%02d",($year+=1900),(++$mon),$mday,$hour); - $newpartname.= sprintf("%02d", $min) if($partstep > 1); - $query = "PARTITION ".$newpartname." VALUES LESS THAN (".$kstamp.")"; - push(@partsadd,$query); - - } - - my $parts_count=scalar @partsadd; - if($parts_count > 0) - { - $val = join(','."\n", @partsadd).","; - $sqltable=~s/\[PARTITIONS\]/$val/ig; - - $sqltable=~s/\[TRANSACTION\]/$table/ig; - $db->do($query) or printf(STDERR "Failed to execute query [%s] with error: %s", ,$db->errstr); - #print "$sqltable\n"; - } } @@ -362,7 +404,6 @@ () if ((/^(.*)=(.*)$/)) { my($keyword, $value) = split(/=/, $_, 2); $keyword =~ s/^\s+|\s+$//g; - print "ZZ: [$keyword]\n"; $value =~ s/(#.*)$//; $value =~ s/^\s+//; $value =~ s/\s+$//; diff --git a/scripts/new/rotation.ini b/scripts/new/rotation.ini index e61ee36..9ed76f6 100644 --- a/scripts/new/rotation.ini +++ b/scripts/new/rotation.ini @@ -12,36 +12,38 @@ engine = InnoDB #MyISAM or InnoDB compress=ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8 - [DATA_TABLE_ROTATION] #how long data keeps sip_capture_call = 10 #days sip_capture_registration = 10 # 10 days sip_capture_rest = 10 # 10 days - + rtcp_capture = 10 # days + logs_capture = 10 # days + report_capture = 10 # days + [DATA_TABLE_STEP] # 0 - Day, 1 - Hour, 2 - 30 Minutes, 3 - 15 Minutes sip_capture_call = 0 - sip_capture_registration = 0 + sip_capture_registration = 0 sip_capture_rest = 0 + rtcp_capture = 0 + logs_capture = 0 + report_capture = 0 [STATS_TABLE_ROTATION] - rtcp_capture = 10 # days - logs_capture = 10 # days - report_capture = 10 # days stats_ip = 20 # days stats_geo = 20 # days alarm_data = 10 # days stats_method = 10 # days stats_useragent = 20 # days - + [STATS_TABLE_STEP] #0 - Day, 1 - Hour, 2 - 30 Minutes, 3 - 15 Minutes - rtcp_capture = 0 - logs_capture = 0 - report_capture = 0 - stats_ip = 0 + stats_ip = 0 stats_geo = 0 alarm_data = 0 stats_method = 0 stats_useragent = 0 + +[SYSTEM] + debug = 0 From b26c1c109082e89acdc20aad5dae513ae3b3d7f0 Mon Sep 17 00:00:00 2001 From: dougbtv Date: Wed, 27 Apr 2016 13:28:59 -0400 Subject: [PATCH 02/24] [bugfix] rotation was deleting tables for today's date, implemented ini horizons. found while testing #81 --- scripts/new/homer_mysql_rotate.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/new/homer_mysql_rotate.pl b/scripts/new/homer_mysql_rotate.pl index 9a84331..e456ecb 100755 --- a/scripts/new/homer_mysql_rotate.pl +++ b/scripts/new/homer_mysql_rotate.pl @@ -154,7 +154,8 @@ END $ltable = $DROP_DATA_TABLE; $ltable =~s/\[TRANSACTION\]/$table/ig; - for(my $y = 0 ; $y < 2; $y++) + my $rotation_horizon = $CONFIG{"DATA_TABLE_ROTATION"}{$table}; + for(my $y = $rotation_horizon ; $y < ($rotation_horizon + $newtables); $y++) { $curtstamp = time()-(86400*($maxparts[$i]+$y)); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($curtstamp); From 42424604d6e5154a9cc16236172d50a5242bf4ac Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Thu, 28 Apr 2016 10:34:59 +0200 Subject: [PATCH 03/24] Update rotation.ini --- scripts/new/rotation.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/new/rotation.ini b/scripts/new/rotation.ini index 9ed76f6..30852d6 100644 --- a/scripts/new/rotation.ini +++ b/scripts/new/rotation.ini @@ -8,7 +8,7 @@ db_data = homer_data db_stats = homer_statistic # Extra param - newtables = 2 + newtables = 2 # Create new tables for next 2 days engine = InnoDB #MyISAM or InnoDB compress=ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8 From 5427e7152dbed27267a83a03ae21f444e86ea6da Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Thu, 28 Apr 2016 10:35:19 +0200 Subject: [PATCH 04/24] Update rotation.ini --- scripts/new/rotation.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/new/rotation.ini b/scripts/new/rotation.ini index 30852d6..1fdfd4e 100644 --- a/scripts/new/rotation.ini +++ b/scripts/new/rotation.ini @@ -8,7 +8,7 @@ db_data = homer_data db_stats = homer_statistic # Extra param - newtables = 2 # Create new tables for next 2 days + newtables = 2 # Create new tables or partitions for next 2 days engine = InnoDB #MyISAM or InnoDB compress=ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8 From 58fc5ab413583fc5b104a868413e8f7a7cb42ed9 Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Fri, 29 Apr 2016 11:37:55 +0200 Subject: [PATCH 05/24] Update schema_statistic.sql --- sql/schema_statistic.sql | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sql/schema_statistic.sql b/sql/schema_statistic.sql index 91dad25..9e54be1 100644 --- a/sql/schema_statistic.sql +++ b/sql/schema_statistic.sql @@ -1,5 +1,5 @@ -SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; +SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO,ALLOW_INVALID_DATES"; -- -- Database: `homer_statistic` @@ -76,7 +76,7 @@ CREATE TABLE IF NOT EXISTS `alarm_data_mem` ( CREATE TABLE IF NOT EXISTS `stats_data` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `from_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `to_date` timestamp NOT NULL DEFAULT '1970-01-01 00:00:01', + `to_date` timestamp NOT NULL DEFAULT '1971-01-01 00:00:01', `type` varchar(50) NOT NULL DEFAULT '', `total` int(20) NOT NULL DEFAULT 0, PRIMARY KEY (`id`,`from_date`), @@ -97,7 +97,7 @@ CREATE TABLE IF NOT EXISTS `stats_data` ( CREATE TABLE IF NOT EXISTS `stats_ip` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `from_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `to_date` timestamp NOT NULL DEFAULT '1970-01-01 00:00:01', + `to_date` timestamp NOT NULL DEFAULT '1971-01-01 00:00:01', `method` varchar(50) NOT NULL DEFAULT '', `source_ip` varchar(255) NOT NULL DEFAULT '0.0.0.0', `total` int(20) NOT NULL DEFAULT 0, @@ -155,7 +155,7 @@ CREATE TABLE IF NOT EXISTS `stats_geo_mem` ( CREATE TABLE IF NOT EXISTS `stats_geo` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `from_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `to_date` timestamp NOT NULL DEFAULT '1970-01-01 00:00:01', + `to_date` timestamp NOT NULL DEFAULT '1971-01-01 00:00:01', `method` varchar(50) NOT NULL DEFAULT '', `country` varchar(255) NOT NULL DEFAULT 'UN', `lat` float NOT NULL DEFAULT '0', @@ -179,7 +179,7 @@ CREATE TABLE IF NOT EXISTS `stats_geo` ( CREATE TABLE IF NOT EXISTS `stats_method` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `from_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `to_date` timestamp NOT NULL DEFAULT '1970-01-01 00:00:01', + `to_date` timestamp NOT NULL DEFAULT '1971-01-01 00:00:01', `method` varchar(50) NOT NULL DEFAULT '', `auth` tinyint(1) NOT NULL DEFAULT '0', `cseq` varchar(100) NOT NULL DEFAULT '', @@ -225,7 +225,7 @@ CREATE TABLE IF NOT EXISTS `stats_method_mem` ( CREATE TABLE IF NOT EXISTS `stats_useragent` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `from_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `to_date` timestamp NOT NULL DEFAULT '1970-01-01 00:00:01', + `to_date` timestamp NOT NULL DEFAULT '1971-01-01 00:00:01', `useragent` varchar(100) NOT NULL DEFAULT '', `method` varchar(50) NOT NULL DEFAULT '', `total` int(10) NOT NULL DEFAULT '0', @@ -260,7 +260,7 @@ CREATE TABLE IF NOT EXISTS `stats_useragent_mem` ( CREATE TABLE IF NOT EXISTS `stats_generic` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `from_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `to_date` timestamp NOT NULL DEFAULT '1970-01-01 00:00:01', + `to_date` timestamp NOT NULL DEFAULT '1971-01-01 00:00:01', `type` varchar(50) NOT NULL DEFAULT '', `tag` varchar(50) NOT NULL DEFAULT '', `total` int(20) NOT NULL, From 4fee4fb1215342dedae2f9f65c5286281efc56c3 Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Sun, 1 May 2016 11:24:34 +0200 Subject: [PATCH 06/24] fixed duration for no report --- api/RestApi/Report.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/api/RestApi/Report.php b/api/RestApi/Report.php index 95872ab..934d209 100644 --- a/api/RestApi/Report.php +++ b/api/RestApi/Report.php @@ -378,6 +378,14 @@ public function doQOSReport($timestamp, $param){ } } + + if(!array_key_exists('main', $bigReport["global"])){ + $mainData = array(); + $mainData["duration"] = $duration; + $bigReport["global"]["main"] = &$mainData; + } + + $answer['sid'] = session_id(); $answer['auth'] = 'true'; $answer['status'] = 200; From 00a7883ec3801e4c01d23bd5f2951ccaa5fd34af Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Mon, 2 May 2016 11:27:32 +0200 Subject: [PATCH 07/24] fixed new parts rotate --- scripts/new/homer_mysql_rotate.pl | 17 +++++++++-------- scripts/new/rotation.ini | 1 + 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/scripts/new/homer_mysql_rotate.pl b/scripts/new/homer_mysql_rotate.pl index e456ecb..2023ecb 100755 --- a/scripts/new/homer_mysql_rotate.pl +++ b/scripts/new/homer_mysql_rotate.pl @@ -171,9 +171,9 @@ END $coof=int(86400/$mystep); #How much partitions $maxparts*=$coof; - $newparts*=$coof; + #$newparts*=$coof; #Now - new_partition_table($CONFIG{"MYSQL"}{"db_data"}, $table, $mystep, $partstep, $maxparts, $newparts); + new_partition_table($CONFIG{"MYSQL"}{"db_data"}, $table, $mystep, $partstep, $maxparts, $newtables); } } @@ -191,12 +191,12 @@ END $coof=int(86400/$mystep); #How much partitions $maxparts*=$coof; - $newparts*=$coof; + #$newparts*=$coof; #$totalparts = ($maxparts+$newparts); $db = DBI->connect("DBI:mysql:".$CONFIG{"MYSQL"}{"db_stats"}.":".$CONFIG{"MYSQL"}{"host"}.":".$CONFIG{"MYSQL"}{"port"}, $CONFIG{"MYSQL"}{"user"}, $CONFIG{"MYSQL"}{"password"}); - new_partition_table($CONFIG{"MYSQL"}{"db_stats"}, $table, $mystep, $partstep, $maxparts, $newparts); + new_partition_table($CONFIG{"MYSQL"}{"db_stats"}, $table, $mystep, $partstep, $maxparts, $newtables); } @@ -270,7 +270,7 @@ () $sqltable=~s/\[PARTITIONS\]/$val/ig; $sqltable=~s/\[TRANSACTION\]/$table/ig; - $db->do($sqltable) or printf(STDERR "Failed to execute query [%s] with error: %s", ,$db->errstr); + $db->do($sqltable) or printf(STDERR "Failed to execute query [%s] with error: %s", ,$db->errstr) if($CONFIG{"SYSTEM"}{"exec"} == 1); print "create data table: $sqltable\n" if($CONFIG{"SYSTEM"}{"debug"} == 1); #print "$sqltable\n"; } @@ -352,14 +352,16 @@ () if($#partsremove > 0) { $query = "ALTER TABLE ".$table." DROP PARTITION ".join(',', @partsremove); - $db->do($query) or printf(STDERR "Failed to execute query [%s] with error: %s", ,$db->errstr); print "DROP Partition: [$query]\n" if($CONFIG{"SYSTEM"}{"debug"} == 1); + $db->do($query) or printf(STDERR "Failed to execute query [%s] with error: %s\n", ,$db->errstr) if($CONFIG{"SYSTEM"}{"exec"} == 1); if (!$db->{Executed}) { print "Couldn't drop partition: $minpart\n"; break; } } + print "Newparts: $newparts\n" if($CONFIG{"SYSTEM"}{"debug"} == 1); + # < condition $curtstamp+=(86400); for(my $i=0; $i<$newparts; $i++) @@ -380,14 +382,13 @@ () { # Fix MAXVALUE. Thanks Dorn B. for report and fix. $query = "ALTER TABLE ".$table." REORGANIZE PARTITION pmax INTO (".join(',', @partsadd) ."\n, PARTITION pmax VALUES LESS THAN MAXVALUE)"; - $db->do($query) or printf(STDERR "Failed to execute query [%s] with error: %s", ,$db->errstr); print "Alter partition: [$query]\n" if($CONFIG{"SYSTEM"}{"debug"} == 1); + $db->do($query) or printf(STDERR "Failed to execute query [%s] with error: %s\n", ,$db->errstr) if($CONFIG{"SYSTEM"}{"exec"} == 1); if (!$db->{Executed}) { print "Couldn't drop partition: $minpart\n"; break; } } - } diff --git a/scripts/new/rotation.ini b/scripts/new/rotation.ini index 1fdfd4e..6812a79 100644 --- a/scripts/new/rotation.ini +++ b/scripts/new/rotation.ini @@ -47,3 +47,4 @@ [SYSTEM] debug = 0 + exec = 1 From d740f687dce571be9fd56966ea9fba62224d0e93 Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Mon, 2 May 2016 11:42:09 +0200 Subject: [PATCH 08/24] just another fix --- scripts/new/homer_mysql_rotate.pl | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/scripts/new/homer_mysql_rotate.pl b/scripts/new/homer_mysql_rotate.pl index 2023ecb..0197a6f 100755 --- a/scripts/new/homer_mysql_rotate.pl +++ b/scripts/new/homer_mysql_rotate.pl @@ -171,9 +171,9 @@ END $coof=int(86400/$mystep); #How much partitions $maxparts*=$coof; - #$newparts*=$coof; + $newparts*=$coof; #Now - new_partition_table($CONFIG{"MYSQL"}{"db_data"}, $table, $mystep, $partstep, $maxparts, $newtables); + new_partition_table($CONFIG{"MYSQL"}{"db_data"}, $table, $mystep, $partstep, $maxparts, $newparts); } } @@ -191,12 +191,12 @@ END $coof=int(86400/$mystep); #How much partitions $maxparts*=$coof; - #$newparts*=$coof; + $newparts*=$coof; #$totalparts = ($maxparts+$newparts); $db = DBI->connect("DBI:mysql:".$CONFIG{"MYSQL"}{"db_stats"}.":".$CONFIG{"MYSQL"}{"host"}.":".$CONFIG{"MYSQL"}{"port"}, $CONFIG{"MYSQL"}{"user"}, $CONFIG{"MYSQL"}{"password"}); - new_partition_table($CONFIG{"MYSQL"}{"db_stats"}, $table, $mystep, $partstep, $maxparts, $newtables); + new_partition_table($CONFIG{"MYSQL"}{"db_stats"}, $table, $mystep, $partstep, $maxparts, $newparts); } @@ -364,6 +364,8 @@ () # < condition $curtstamp+=(86400); + $stopstamp = time() + (86400*$newtables); + for(my $i=0; $i<$newparts; $i++) { $oldstamp = $curtstamp; @@ -374,7 +376,12 @@ () if(!defined $PARTS{$newpartname."_".$curtstamp}) { $query = "\nPARTITION ".$newpartname." VALUES LESS THAN (".$curtstamp.")"; push(@partsadd,$query); - } + } + + if($curtstamp >= $stopstamp) { + print "Stop partition: [$curtstamp] > [$stopstamp]. Last partition: [$newpartname]\n" if($CONFIG{"SYSTEM"}{"debug"} == 1); + last; + } } my $parts_count=scalar @partsadd; From a1fc35760af571693840ca3f3598ca45b1647f9e Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Wed, 4 May 2016 08:54:51 +0200 Subject: [PATCH 09/24] fixed kamailio config --- examples/sipcapture/sipcapture.kamailio | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/sipcapture/sipcapture.kamailio b/examples/sipcapture/sipcapture.kamailio index 1de58e5..0c4df4a 100644 --- a/examples/sipcapture/sipcapture.kamailio +++ b/examples/sipcapture/sipcapture.kamailio @@ -744,19 +744,19 @@ route[CHECK_STATS] { #!ifdef WITH_STATISTIC_INVITE_1XX #100 INVITE if($sht(a=>response::100::invite) > 0) { - sql_query("cb", "INSERT INTO stats_method (from_date, to_date, method, cseq, total) VALUES($var(f_date), $var(t_date), '100', 'INVITE', $sht(a=>response::100::invite)) ON DUPLICATE KEY UPDATE total=total+$sht(a=>response::100::i + sql_query("cb", "INSERT INTO stats_method (from_date, to_date, method, cseq, total) VALUES($var(f_date), $var(t_date), '100', 'INVITE', $sht(a=>response::100::invite)) ON DUPLICATE KEY UPDATE total=total+$sht(a=>response::100::invite)"); $sht(a=>response::100::invite) = 0; } #180 INVITE if($sht(a=>response::180::invite) > 0) { - sql_query("cb", "INSERT INTO stats_method (from_date, to_date, method, cseq, total) VALUES($var(f_date), $var(t_date), '180', 'INVITE', $sht(a=>response::180::invite)) ON DUPLICATE KEY UPDATE total=total+$sht(a=>response::180::i + sql_query("cb", "INSERT INTO stats_method (from_date, to_date, method, cseq, total) VALUES($var(f_date), $var(t_date), '180', 'INVITE', $sht(a=>response::180::invite)) ON DUPLICATE KEY UPDATE total=total+$sht(a=>response::180::invite)"); $sht(a=>response::180::invite) = 0; } #183 INVITE if($sht(a=>response::183::invite) > 0) { - sql_query("cb", "INSERT INTO stats_method (from_date, to_date, method, cseq, total) VALUES($var(f_date), $var(t_date), '183', 'INVITE', $sht(a=>response::183::invite)) ON DUPLICATE KEY UPDATE total=total+$sht(a=>response::183::i + sql_query("cb", "INSERT INTO stats_method (from_date, to_date, method, cseq, total) VALUES($var(f_date), $var(t_date), '183', 'INVITE', $sht(a=>response::183::invite)) ON DUPLICATE KEY UPDATE total=total+$sht(a=>response::183::invite)"); $sht(a=>response::183::invite) = 0; } From be958412964fcb84c86db21478a5afc4d0d627cf Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Wed, 4 May 2016 12:48:47 +0200 Subject: [PATCH 10/24] added opensips 2.2 config for Homer5 --- examples/sipcapture/sipcapture.opensips | 630 ++++++++++++++++++++++++ 1 file changed, 630 insertions(+) create mode 100644 examples/sipcapture/sipcapture.opensips diff --git a/examples/sipcapture/sipcapture.opensips b/examples/sipcapture/sipcapture.opensips new file mode 100644 index 0000000..c7659d5 --- /dev/null +++ b/examples/sipcapture/sipcapture.opensips @@ -0,0 +1,630 @@ +################################################# +# +# HOMER & OpenSIPs +# +################################################# + +log_level=3 +log_stderror=no +log_facility=LOG_LOCAL0 + +children=4 + +listen=udp:10.0.0.1:5062 +listen=hep_udp:10.0.1:9063 + + +### CHANGEME path to your opensips modules here +mpath="/usr/local/opensips/lib64/opensips/modules/" + +loadmodule "proto_udp.so" +loadmodule "cfgutils.so" +loadmodule "signaling.so" +loadmodule "sl.so" +loadmodule "tm.so" +loadmodule "rr.so" +loadmodule "maxfwd.so" +loadmodule "sipmsgops.so" +loadmodule "mi_fifo.so" +loadmodule "uri.so" +loadmodule "db_mysql.so" +loadmodule "sipcapture.so" +loadmodule "proto_hep.so" +loadmodule "cachedb_local.so" +loadmodule "avpops.so" +loadmodule "mmgeoip.so" +loadmodule "exec.so" + +#settings + +### CHANGEME hep interface +# should be loaded After proto_hep + +#Cache +modparam("cachedb_local", "cache_table_size", 10) +modparam("cachedb_local", "cache_clean_period", 600) + +modparam("tm", "fr_timeout", 2) +modparam("tm", "fr_inv_timeout", 3) +modparam("tm", "restart_fr_on_each_reply", 0) +modparam("tm", "onreply_avp_mode", 1) + +#### Record Route Module +/* do not append from tag to the RR (no need for this script) */ +modparam("rr", "append_fromtag", 0) + +#### FIFO Management Interface + +modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo") +modparam("mi_fifo", "fifo_mode", 0666) + +#### SIP MSG OPerationS module +#### URI module +#### MAX ForWarD module + +modparam("uri", "use_uri_table", 0) + +### CHANGEME mysql uri here if you do sip_capture() +modparam("sipcapture", "db_url", "mysql://homer_user:homer_password@127.0.0.1/homer_data") +modparam("sipcapture", "capture_on", 1) +modparam("sipcapture", "hep_capture_on", 1) + +# +modparam("avpops","db_url","mysql://homer_user:homer_password@127.0.0.1/homer_statistic") + + +modparam("mmgeoip", "mmgeoip_city_db_path", "/usr/share/GeoIP/GeoIP.dat") + + +route{ + + cache_add("local", "a=>method::total", 1, 320); + cache_add("local", "a=>packet::count", 1, 320); + cache_add("local", "a=>packet::size", $ml, 320); + + if(cache_fetch("local","b=>$rm::$cs::$ci",$var(tmpvar))) { + route(STORE); + exit; + } + + cache_add("local", "b=>$rm::$cs::$ci", 1, 320); + cache_add("local", "a=>method::all", 1, 320); + + + if (is_method("INVITE|REGISTER")) { + + if($ua =~ "(friendly-scanner|sipvicious|sipcli)") { + avp_db_query("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"); + route(KILL_VICIOUS); + } + + #IP Method + avp_db_query("INSERT INTO stats_ip_mem ( method, source_ip, total) VALUES('$rm', '$si', 1) ON DUPLICATE KEY UPDATE total=total+1"); + + #GEO + if(mmg_lookup("lon:lat","$si","$avp(lat_lon)")) { + avp_db_query("INSERT INTO stats_geo_mem ( method, country, lat, lon, total) VALUES('$rm', '$(avp(lat_lon)[3])', '$(avp(lat_lon)[0])', '$(avp(lat_lon)[1])', 1) ON DUPLICATE KEY UPDATE total=total+1"); + }; + + + if (is_method("INVITE")) { + + if (has_totag()) { + cache_add("local", "a=>method::reinvite", 1, 320); + } + else { + cache_add("local", "a=>method::invite", 1, 320); + if($adu != "") { + cache_add("local", "a=>method::invite::auth", 1, 320); + } + + if($ua != "") { + avp_db_query("INSERT INTO stats_useragent_mem (useragent, method, total) VALUES('$ua', 'INVITE', 1) ON DUPLICATE KEY UPDATE total=total+1"); + } + + } + } + else { + cache_add("local", "a=>method::register", 1, 320); + + if($adu != "") { + cache_add("local", "a=>method::register::auth", 1, 320); + } + + if($ua != "") { + avp_db_query("INSERT INTO stats_useragent_mem (useragent, method, total) VALUES('$ua', 'REGISTER', 1) ON DUPLICATE KEY UPDATE total=total+1"); + } + } + } + + else if(is_method("BYE")) { + + cache_add("local", "a=>method::bye", 1, 320); + + if(is_present_hf("Reason")) { + $var(cause) = $(hdr(Reason){param.value,cause}{s.int}); + if($var(cause) != 16 && $var(cause) !=17) { + cache_add("local", "a=>stats::sdf", 1, 320); + } + } + + } + else if(is_method("CANCEL")) { + cache_add("local", "a=>method::cancel", 1, 320); + } + else if(is_method("OPTIONS")) { + cache_add("local", "a=>method::options", 1, 320); + } + else if(is_method("REFER")) { + cache_add("local", "a=>method::refer", 1, 320); + } + else if(is_method("UPDATE")) { + cache_add("local", "a=>method::update", 1, 320); + } + else if(is_method("PUBLISH")) + { + if(has_body("application/vq-rtcpxr") && $(rb{s.substr,0,1}) != "x") { + $var(table) = "report_capture"; + $var(reg) = "/.*CallID:([0-9A-Za-z@-_\.]{5,120}).*$/\1/s"; + $var(callid) = $(rb{re.subst,$var(reg)}); + #Local IP. Only for stats + report_capture("report_capture", "$var(callid)"); + drop; + } + } + + else if(is_method("ACK")) { + cache_add("local", "a=>method::ack", 1, 320); + } + else { + cache_add("local", "a=>method::unknown", 1, 320); + } + + #Store + route(STORE); + exit; + +} + +onreply_route { + + cache_add("local", "a=>method::total", 1, 320); + + if(cache_fetch("local","b=>$rs::$cs::$rm::$ci",$var(tmpvar))) { + route(STORE); + exit; + } + + cache_add("local", "b=>$rs::$cs::$rm::$ci", 1, 320); + cache_add("local", "a=>method::all", 1, 320); + + #413 Too large + if(status == "413") { + cache_add("local", "a=>response::413", 1, 320); + cache_add("local", "a=>alarm::413", 1, 320); + } + #403 Unauthorize + else if(status == "403") { + cache_add("local", "a=>response::403", 1, 320); + cache_add("local", "a=>alarm::403", 1, 320); + } + # Too many hops + else if(status == "483") { + cache_add("local", "a=>response::483", 1, 320); + cache_add("local", "a=>alarm::483", 1, 320); + } + # loops + else if(status == "482") { + cache_add("local", "a=>response::482", 1, 320); + cache_add("local", "a=>alarm::482", 1, 320); + } + # Call Transaction Does not exist + else if(status == "481") { + cache_add("local", "a=>alarm::481", 1, 320); + } + # 408 Timeout + else if(status == "408") { + cache_add("local", "a=>alarm::408", 1, 320); + } + # 400 + else if(status == "400") { + cache_add("local", "a=>alarm::400", 1, 320); + } + # MOVED + else if(status =~ "^(30[012])$") { + cache_add("local", "a=>response::300", 1, 320); + } + + if($rm == "INVITE") { + #ISA + if(status =~ "^(408|50[03])$") { + cache_add("local", "a=>stats::isa", 1, 320); + } + #Bad486 + if(status =~ "^(486|487|603)$") { + cache_add("local", "a=>stats::bad::invite", 1, 320); + } + + #SD + if(status =~ "^(50[034])$") { + cache_add("local", "a=>stats::sd", 1, 320); + } + + if(status == "407") { + cache_add("local", "a=>response::407::invite", 1, 320); + } + else if(status == "401") { + cache_add("local", "a=>response::401::invite", 1, 320); + } + else if(status == "200") { + cache_add("local", "a=>response::200::invite", 1, 320); + } + #Aditional stats + else if(status == "100") { + cache_add("local", "a=>response::100::invite", 1, 320); + } + else if(status == "180") { + cache_add("local", "a=>response::180::invite", 1, 320); + } + else if(status == "183") { + cache_add("local", "a=>response::183::invite", 1, 320); + } + } + else if($rm == "BYE") { + + if(status == "407") { + cache_add("local", "a=>response::407::bye", 1, 320); + } + else if(status == "401") { + cache_add("local", "a=>response::401::bye", 1, 320); + } + else if(status == "200") { + cache_add("local", "a=>response::200::bye", 1, 320); + } + } + + #Store + route(STORE); + drop; +} + +route[KILL_VICIOUS] { + xlog("Kill-Vicious ! si : $si ru : $ru ua : $ua\n"); + return; +} + + + +timer_route[stats_alarms_update, 60] { + + route(CHECK_ALARM); + #Check statistics + route(CHECK_STATS); + +} + +route[SEND_ALARM] { + exec('echo "Value: $var(thvalue), Type: $var(atype), Desc: $var(aname)" | mail -s "Homer Alarm $var(atype) - $var(thvalue)" $var(aemail) ') ; +} + +route[CHECK_ALARM] +{ + + #POPULATE ALARM THRESHOLDS + #Homer 5 sql schema + avp_db_query("SELECT type,value,name,notify,email FROM alarm_config WHERE NOW() between startdate AND stopdate AND active = 1", "$avp(type);$avp(value);$avp(name);$avp(notify);$avp(email)"); + $var(i) = 0; + while ( $(avp(type)[$var(i)]) != NULL ) + { + $var(atype) = $(avp(type)[$var(i)]); + $var(avalue) = $(avp(value)[$var(i)]); + $var(aname) = $(avp(name)[$var(i)]); + $var(anotify) = $(avp(notify)[$var(i)]); + $var(aemail) = $(avp(email)[$var(i)]); + $avp($var(atype)) = $var(avalue); + + $var(anotify) = $(var(anotify){s.int}); + + if(cache_fetch("local","a=>alarm::$var(atype)",$var(thvalue))) { + + cache_remove("local","a=>alarm::var(atype)"); + + #If Alarm - go here + if($var(thvalue) > $var(avalue)) { + + avp_db_query("INSERT INTO alarm_data (create_date, type, total, description) VALUES(NOW(), '$var(aname)', $var(thvalue), '$var(aname) - $var(atype)');"); + #Notify + if($var(anotify) == 1) { + route(SEND_ALARM); + } + } + + #Alarm for Scanner; + if($var(atype) == "scanner") { + avp_db_query("DELETE FROM alarm_data_mem WHERE type='scanner' AND total < $var(avalue)"); + if($var(anotify) == 1) + { + avp_db_query("SELECT * FROM alarm_data_mem WHERE type='scanner' AND total >= $var(avalue) LIMIT 2", "$avp(as)"); + if($(avp(as){s.int}) > 0) { + route(SEND_ALARM); + } + } + } + } + + $var(i) = $var(i) + 1; + } + + avp_db_query("DELETE FROM alarm_data WHERE create_date < DATE_SUB(NOW(), INTERVAL 5 DAY)"); +} + + +route[CHECK_STATS] { + + #SQL STATS + + $var(interval) = 5; + $var(tz) = $ctime(min); + $var(tm) = ($ctime(min) % 10); + + if($var(tm) != 0 && $var(tm) != $var(interval)) return; + + $var(t1) = $Ts; + $var(t2) = $var(t1) - (30*60); + + $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')"; + + #ALARM SCANNERS + avp_db_query("INSERT INTO alarm_data (create_date, type, total, source_ip, description) SELECT create_date, type, total, source_ip, description FROM alarm_data_mem;"); + avp_db_query("TRUNCATE TABLE alarm_data_mem"); + + #STATS Useragent + avp_db_query("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;"); + avp_db_query("TRUNCATE TABLE stats_useragent_mem"); + + #STATS IP + avp_db_query("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;"); + avp_db_query("TRUNCATE TABLE stats_ip_mem"); + + avp_db_query("INSERT INTO stats_geo (from_date, to_date, method, country, lat, lon, total) SELECT $var(f_date) as from_date, $var(t_date) as to_date, method, country, lat, lon, total FROM stats_geo_mem;"); + avp_db_query("TRUNCATE TABLE stats_geo_mem"); + + #INSERT SQL STATS + #Packet HEP stats + if(cache_fetch("local","a=>packet::count",$var(tmpvar))) { + cache_remove("local","a=>packet::count"); + avp_db_query("INSERT INTO stats_data (from_date, to_date, type, total) VALUES($var(f_date), $var(t_date), 'packet_count', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + if(cache_fetch("local","a=>packet::size",$var(tmpvar))) { + cache_remove("local","a=>packet::size"); + avp_db_query("INSERT INTO stats_data (from_date, to_date, type, total) VALUES($var(f_date), $var(t_date), 'packet_size', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + #SDF + if(cache_fetch("local","a=>stats::sdf",$var(tmpvar))) { + cache_remove("local","a=>stats::sdf"); + avp_db_query("INSERT INTO stats_data (from_date, to_date, type, total) VALUES($var(f_date), $var(t_date), 'sdf', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + #ISA + if(cache_fetch("local","a=>stats::isa",$var(tmpvar))) { + cache_remove("local","a=>stats::isa"); + avp_db_query("INSERT INTO stats_data (from_date, to_date, type, total) VALUES($var(f_date), $var(t_date), 'isa', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + #SD + if(cache_fetch("local","a=>stats::sd",$var(tmpvar))) { + cache_remove("local","a=>stats::sd"); + avp_db_query("INSERT INTO stats_data (from_date, to_date, type, total) VALUES($var(f_date), $var(t_date), 'isa', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + #SSR + if(cache_fetch("local","a=>stats::ssr",$var(tmpvar))) { + cache_remove("local","a=>stats::ssr"); + avp_db_query("INSERT INTO stats_data (from_date, to_date, type, total) VALUES($var(f_date), $var(t_date), 'ssr', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + + #ASR + $var(asr) = 0; + $var(ner) = 0; + if(cache_fetch("local","a=>method::invite",$var(invite))) + { + if($var(invite) > 0) + { + if(!cache_fetch("local","a=>response::407::invite",$var(invite407))) $var(invite407) = 0; + if(!cache_fetch("local","a=>response::200::invite",$var(invite200))) $var(invite200) = 0; + if(!cache_fetch("local","a=>response::bad::invite",$var(invitebad))) $var(invitebad) = 0; + $var(d) = $var(invite) - $var(invite407); + if($var(d) > 0) { + $var(asr) = $var(invite200) * 100 / $var(d); + if($var(asr) > 100) $var(asr) = 100; + $var(ner) = ($var(invite200) + $var(invitebad)) * 100 / $var(d); + if($var(ner) > 100) $var(ner) = 100; + } + } + } + + #Stats DATA + avp_db_query("INSERT INTO stats_data (from_date, to_date, type, total) VALUES($var(f_date), $var(t_date), 'asr', $var(asr)) ON DUPLICATE KEY UPDATE total=(total+$var(asr))/2"); + avp_db_query("INSERT INTO stats_data (from_date, to_date, type, total) VALUES($var(f_date), $var(t_date), 'ner', $var(ner)) ON DUPLICATE KEY UPDATE total=(total+$var(ner))/2"); + + #INVITE + if(cache_fetch("local","a=>method::reinvite",$var(tmpvar))) { + cache_remove("local","a=>method::reinvite"); + avp_db_query("INSERT INTO stats_method (from_date, to_date, method, totag, total) VALUES($var(f_date), $var(t_date),'INVITE', 1, $var(tmpvar))) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + #INVITE + if(cache_fetch("local","a=>method::invite",$var(tmpvar))) { + cache_remove("local","a=>method::invite"); + avp_db_query("INSERT INTO stats_method (from_date, to_date, method, total) VALUES($var(f_date), $var(t_date), 'INVITE', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + #INVITE AUTH + if(cache_fetch("local","a=>method::invite::auth",$var(tmpvar))) { + cache_remove("local","a=>method::invite::auth"); + avp_db_query("INSERT INTO stats_method (from_date, to_date, method, auth, total) VALUES($var(f_date), $var(t_date), 'INVITE', 1, $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + #REGISTER + if(cache_fetch("local","a=>method::register",$var(tmpvar))) { + cache_remove("local","a=>method::register"); + avp_db_query("INSERT INTO stats_method (from_date, to_date, method, total) VALUES($var(f_date), $var(t_date), 'REGISTER', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + #REGISTER AUTH + if(cache_fetch("local","a=>method::register::auth",$var(tmpvar))) { + cache_remove("local","a=>method::register::auth"); + avp_db_query("INSERT INTO stats_method (from_date, to_date, method, auth, total) VALUES($var(f_date), $var(t_date), 'REGISTER', 1, $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + #BYE + if(cache_fetch("local","a=>method::bye",$var(tmpvar))) { + cache_remove("local","a=>method::bye"); + avp_db_query("INSERT INTO stats_method (from_date, to_date, method, total) VALUES($var(f_date), $var(t_date), 'BYE', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + #CANCEL + if(cache_fetch("local","a=>method::cancel",$var(tmpvar))) { + cache_remove("local","a=>method::cancel"); + avp_db_query("INSERT INTO stats_method (from_date, to_date, method, total) VALUES($var(f_date), $var(t_date), 'CANCEL', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + #OPTIONS + if(cache_fetch("local","a=>method::options",$var(tmpvar))) { + cache_remove("local","a=>method::options"); + avp_db_query("INSERT INTO stats_method (from_date, to_date, method, total) VALUES($var(f_date), $var(t_date), 'OPTIONS', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + if(cache_fetch("local","a=>method::unknown",$var(tmpvar))) { + cache_remove("local","a=>method::unknown"); + avp_db_query("INSERT INTO stats_method (from_date, to_date, method, total) VALUES($var(f_date), $var(t_date), 'UNKNOWN', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + #ACK + if(cache_fetch("local","a=>method::ack",$var(tmpvar))) { + cache_remove("local","a=>method::ack"); + avp_db_query("INSERT INTO stats_method (from_date, to_date, method, total) VALUES($var(f_date), $var(t_date), 'ACK', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + #REFER + if(cache_fetch("local","a=>method::refer",$var(tmpvar))) { + cache_remove("local","a=>method::refer"); + avp_db_query("INSERT INTO stats_method (from_date, to_date, method, total) VALUES($var(f_date), $var(t_date), 'REFER', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + #UPDATE + if(cache_fetch("local","a=>method::update",$var(tmpvar))) { + cache_remove("local","a=>method::update"); + avp_db_query("INSERT INTO stats_method (from_date, to_date, method, total) VALUES($var(f_date), $var(t_date), 'UPDATE', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + #RESPONSE + #300 + if(cache_fetch("local","a=>response::300",$var(tmpvar))) { + cache_remove("local","a=>response::300"); + avp_db_query("INSERT INTO stats_method (from_date, to_date, method, total) VALUES($var(f_date), $var(t_date), '300', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + #407 INVITE + if(cache_fetch("local","a=>response::407::invite",$var(tmpvar))) { + cache_remove("local","a=>response::407::invite"); + avp_db_query("INSERT INTO stats_method (from_date, to_date, method, cseq, total) VALUES($var(f_date), $var(t_date), '407', 'INVITE', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + #401 INVITE + if(cache_fetch("local","a=>response::401::invite",$var(tmpvar))) { + cache_remove("local","a=>response::401::invite"); + avp_db_query("INSERT INTO stats_method (from_date, to_date, method, cseq, total) VALUES($var(f_date), $var(t_date), '401', 'INVITE', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + #100 INVITE + if(cache_fetch("local","a=>response::100::invite",$var(tmpvar))) { + cache_remove("local","a=>response::100::invite"); + avp_db_query("INSERT INTO stats_method (from_date, to_date, method, cseq, total) VALUES($var(f_date), $var(t_date), '100', 'INVITE', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + #180 INVITE + if(cache_fetch("local","a=>response::401::invite",$var(tmpvar))) { + cache_remove("local","a=>response::401::invite"); + avp_db_query("INSERT INTO stats_method (from_date, to_date, method, cseq, total) VALUES($var(f_date), $var(t_date), '180', 'INVITE', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + #183 INVITE + if(cache_fetch("local","a=>response::183::invite",$var(tmpvar))) { + cache_remove("local","a=>response::183::invite"); + avp_db_query("INSERT INTO stats_method (from_date, to_date, method, cseq, total) VALUES($var(f_date), $var(t_date), '183', 'INVITE', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + #200 INVITE + if(cache_fetch("local","a=>response::200::invite",$var(tmpvar))) { + cache_remove("local","a=>response::200::invite"); + avp_db_query("INSERT INTO stats_method (from_date, to_date, method, cseq, total) VALUES($var(f_date), $var(t_date), '200', 'INVITE', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + #407 BYE + if(cache_fetch("local","a=>response::407::bye",$var(tmpvar))) { + cache_remove("local","a=>response::407::bye"); + avp_db_query("INSERT INTO stats_method (from_date, to_date, method, cseq, total) VALUES($var(f_date), $var(t_date), '407', 'BYE', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + #401 BYE + if(cache_fetch("local","a=>response::401::bye",$var(tmpvar))) { + cache_remove("local","a=>response::401::bye"); + avp_db_query("INSERT INTO stats_method (from_date, to_date, method, cseq, total) VALUES($var(f_date), $var(t_date), '401', 'BYE', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + #200 BYE + if(cache_fetch("local","a=>response::200::bye",$var(tmpvar))) { + cache_remove("local","a=>response::200::bye"); + avp_db_query("INSERT INTO stats_method (from_date, to_date, method, cseq, total) VALUES($var(f_date), $var(t_date), '200', 'BYE', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + #ALL TRANSACTIONS MESSAGES + if(cache_fetch("local","a=>method::all",$var(tmpvar))) { + cache_remove("local","a=>method::all"); + avp_db_query("INSERT INTO stats_method (from_date, to_date, method, total) VALUES($var(f_date), $var(t_date), 'ALL', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } + + #ALL MESSAGES ON INTERFACE + if(cache_fetch("local","a=>method::total",$var(tmpvar))) { + cache_remove("local","a=>method::total"); + avp_db_query("INSERT INTO stats_method (from_date, to_date, method, total) VALUES($var(f_date), $var(t_date), 'TOTAL', $var(tmpvar)) ON DUPLICATE KEY UPDATE total=total+$var(tmpvar)"); + } +} + + +route[STORE] { + + if($rm == "REGISTER") { + $var(table) = "sip_capture_registration"; + } + else if($rm =~ "(INVITE|UPDATE|BYE|ACK|PRACK|REFER|CANCEL)$") + { + $var(table) = "sip_capture_call"; + } + else if($rm =~ "(NOTIFY)$" && is_present_hf("Event") && $hdr(Event)=~"refer;") + { + $var(table) = "sip_capture_call"; + } + else if($rm =~ "(INFO)$") + { + $var(table) = "sip_capture_call"; + } + else if($rm =~ "(OPTIONS)$" ) + { + $var(table) = "sip_capture_rest"; + } + else { + $var(table) = "sip_capture_rest"; + } + + # or sipcapture style + #$var(utc) = "%Y%m%d"; + + + if($var(table) == "sip_capture_call") sip_capture("sip_capture_call_%Y%m%d"); + else if($var(table) == "sip_capture_registration") sip_capture("sip_capture_registration_%Y%m%d"); + else sip_capture("sip_capture_rest_%Y%m%d"); +} From 9df5e83f69a2ad00181f293a7b6b77b51043bf3f Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Wed, 4 May 2016 14:43:47 +0200 Subject: [PATCH 11/24] added another regexp --- examples/sipcapture/sipcapture.opensips | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/sipcapture/sipcapture.opensips b/examples/sipcapture/sipcapture.opensips index c7659d5..7c1f99f 100644 --- a/examples/sipcapture/sipcapture.opensips +++ b/examples/sipcapture/sipcapture.opensips @@ -165,7 +165,9 @@ route{ { if(has_body("application/vq-rtcpxr") && $(rb{s.substr,0,1}) != "x") { $var(table) = "report_capture"; - $var(reg) = "/.*CallID:([0-9A-Za-z@-_\.]{5,120}).*$/\1/s"; + #$var(reg) = "/.*CallID:([0-9A-Za-z@-_\.]{5,120}).*$/\1/s"; + #Regexp ignores - ? + $var(reg) = "/.*CallID:((\d|\-|\w|\@){5,120}).*$/\1/s"; $var(callid) = $(rb{re.subst,$var(reg)}); #Local IP. Only for stats report_capture("report_capture", "$var(callid)"); From 97e6e53297607e96b3b5846e7d6f655310465f8b Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Wed, 4 May 2016 14:54:09 +0200 Subject: [PATCH 12/24] change schema --- sql/schema_data.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sql/schema_data.sql b/sql/schema_data.sql index 75de2ce..f9adbe8 100644 --- a/sql/schema_data.sql +++ b/sql/schema_data.sql @@ -17,7 +17,7 @@ CREATE TABLE IF NOT EXISTS `logs_capture` ( `destination_port` int(10) NOT NULL DEFAULT 0, `proto` int(5) NOT NULL DEFAULT 0, `family` int(1) DEFAULT NULL, - `type` int(2) NOT NULL DEFAULT 0, + `type` int(5) NOT NULL DEFAULT 0, `node` varchar(125) NOT NULL DEFAULT '', `msg` varchar(1500) NOT NULL DEFAULT '', PRIMARY KEY (`id`,`date`), @@ -48,7 +48,7 @@ CREATE TABLE IF NOT EXISTS `report_capture` ( `destination_port` int(10) NOT NULL DEFAULT 0, `proto` int(5) NOT NULL DEFAULT 0, `family` int(1) DEFAULT NULL, - `type` tinyint(2) NOT NULL DEFAULT 0, + `type` int(5) NOT NULL DEFAULT 0, `node` varchar(125) NOT NULL DEFAULT '', `msg` varchar(1500) NOT NULL DEFAULT '', PRIMARY KEY (`id`,`date`), @@ -79,7 +79,7 @@ CREATE TABLE IF NOT EXISTS `rtcp_capture` ( `destination_port` int(10) NOT NULL DEFAULT 0, `proto` int(5) NOT NULL DEFAULT 0, `family` int(1) DEFAULT NULL, - `type` int(2) NOT NULL DEFAULT 0, + `type` int(5) NOT NULL DEFAULT 0, `node` varchar(125) NOT NULL DEFAULT '', `msg` varchar(1500) NOT NULL DEFAULT '', PRIMARY KEY (`id`,`date`), From 5e908041196938bc7bf12e55a999b3bc36b60d39 Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Wed, 4 May 2016 15:56:00 +0200 Subject: [PATCH 13/24] fixed correlation in some scenarios --- api/RestApi/Report.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/api/RestApi/Report.php b/api/RestApi/Report.php index 934d209..c38f54b 100644 --- a/api/RestApi/Report.php +++ b/api/RestApi/Report.php @@ -302,27 +302,25 @@ public function doQOSReport($timestamp, $param){ foreach($timearray as $tkey=>$tval) { - if(count($newcorrid) > $limit) break; + if(count($mapsCallid) > $limit) break; $order = " LIMIT ".$limit; $table = "sip_capture_call_".$tkey; $query = "SELECT DISTINCT(correlation_id) "; $query .= "FROM ".$table; $query .= " WHERE (date BETWEEN FROM_UNIXTIME(".$time['from_ts'].") AND FROM_UNIXTIME(".$time['to_ts']."))"; - if(count($callwhere)) $query .= " AND ( " .implode(" AND ", $callwhere). ")"; + if(count($callwhere)) $query .= " AND correlation_id != '' AND ( " .implode(" AND ", $callwhere). ")"; $noderows = $db->loadObjectArray($query.$order); foreach($noderows as $k=>$d) { - $newcorrid[$d["correlation_id"]]=$d["correlation_id"]; + $mapsCallid[$d["correlation_id"]]=$d["correlation_id"]; $kz = substr($d["correlation_id"], 0, -1); - $newcorrid[$kz] = $kz; + $mapsCallid[$kz] = $kz; } } } - if(!empty($newcorrid)) - { - $search=array(); - $callids = $newcorrid; - } + + $search=array(); + $callids = $mapsCallid; /* codecs */ list($export,$duration, $xrtpreport) = $this->getCodecsFromMessagesForTransaction($timestamp, $param); @@ -614,7 +612,7 @@ public function doRTCPXRServerReport($timestamp, $param, $callids){ $table = "report_capture"; $query = "SELECT *, '".$node['name']."' as dbnode FROM ".$table." WHERE (`date` BETWEEN FROM_UNIXTIME(".$time['from_ts'].") AND FROM_UNIXTIME(".$time['to_ts']."))"; if(count($callwhere)) $query .= " AND ( " .implode(" AND ", $callwhere). ")"; - $query.= " AND type = 1"; + $query.= " AND type = 1"; $noderows = $db->loadObjectArray($query); $data = array_merge($data,$noderows); $limit -= count($noderows); From d5af5042e4612c29c9e88f207314ef13c6f35518 Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Wed, 4 May 2016 16:01:13 +0200 Subject: [PATCH 14/24] added type id --- examples/sipcapture/sipcapture.opensips | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/sipcapture/sipcapture.opensips b/examples/sipcapture/sipcapture.opensips index 7c1f99f..0f56f62 100644 --- a/examples/sipcapture/sipcapture.opensips +++ b/examples/sipcapture/sipcapture.opensips @@ -170,7 +170,7 @@ route{ $var(reg) = "/.*CallID:((\d|\-|\w|\@){5,120}).*$/\1/s"; $var(callid) = $(rb{re.subst,$var(reg)}); #Local IP. Only for stats - report_capture("report_capture", "$var(callid)"); + report_capture("report_capture", "$var(callid)", "1"); drop; } } From 4df2395013a278e1c9d0f7d3c2e53feeb796e42b Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Fri, 6 May 2016 11:12:30 +0200 Subject: [PATCH 15/24] added logs --- examples/sipcapture/sipcapture.opensips | 56 ++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/examples/sipcapture/sipcapture.opensips b/examples/sipcapture/sipcapture.opensips index 0f56f62..8aebe26 100644 --- a/examples/sipcapture/sipcapture.opensips +++ b/examples/sipcapture/sipcapture.opensips @@ -10,8 +10,8 @@ log_facility=LOG_LOCAL0 children=4 -listen=udp:10.0.0.1:5062 -listen=hep_udp:10.0.1:9063 +listen=udp:5.9.8.22:5062 +listen=hep_udp:5.9.8.22:9063 ### CHANGEME path to your opensips modules here @@ -34,6 +34,7 @@ loadmodule "cachedb_local.so" loadmodule "avpops.so" loadmodule "mmgeoip.so" loadmodule "exec.so" +loadmodule "json.so" #settings @@ -68,6 +69,11 @@ modparam("uri", "use_uri_table", 0) modparam("sipcapture", "db_url", "mysql://homer_user:homer_password@127.0.0.1/homer_data") modparam("sipcapture", "capture_on", 1) modparam("sipcapture", "hep_capture_on", 1) +modparam("sipcapture", "hep_route", "my_hep_route") + + +### hep version here 1, 2 or 3 +#modparam("proto_hep", "hep_version", 3) # modparam("avpops","db_url","mysql://homer_user:homer_password@127.0.0.1/homer_statistic") @@ -83,6 +89,7 @@ route{ cache_add("local", "a=>packet::size", $ml, 320); if(cache_fetch("local","b=>$rm::$cs::$ci",$var(tmpvar))) { + xlog("TEST: $var(tmpvar)\n"); route(STORE); exit; } @@ -165,11 +172,10 @@ route{ { if(has_body("application/vq-rtcpxr") && $(rb{s.substr,0,1}) != "x") { $var(table) = "report_capture"; - #$var(reg) = "/.*CallID:([0-9A-Za-z@-_\.]{5,120}).*$/\1/s"; - #Regexp ignores - ? $var(reg) = "/.*CallID:((\d|\-|\w|\@){5,120}).*$/\1/s"; $var(callid) = $(rb{re.subst,$var(reg)}); #Local IP. Only for stats + xlog("PUBLISH: $var(callid)\n"); report_capture("report_capture", "$var(callid)", "1"); drop; } @@ -193,6 +199,7 @@ onreply_route { cache_add("local", "a=>method::total", 1, 320); if(cache_fetch("local","b=>$rs::$cs::$rm::$ci",$var(tmpvar))) { + xlog("TEST: $var(tmpvar)\n"); route(STORE); exit; } @@ -299,6 +306,7 @@ route[KILL_VICIOUS] { timer_route[stats_alarms_update, 60] { + #xlog("timer routine: time is $Ts\n"); route(CHECK_ALARM); #Check statistics route(CHECK_STATS); @@ -363,14 +371,19 @@ route[CHECK_ALARM] route[CHECK_STATS] { + #xlog("TIMER UPDATE\n"); #SQL STATS $var(interval) = 5; $var(tz) = $ctime(min); $var(tm) = ($ctime(min) % 10); + #xlog("TIMER MIN: $var(tz) $var(tm)\n"); + if($var(tm) != 0 && $var(tm) != $var(interval)) return; + #xlog("TIMER IN: $var(tz) $var(tm)\n"); + $var(t1) = $Ts; $var(t2) = $var(t1) - (30*60); @@ -432,11 +445,19 @@ route[CHECK_STATS] { $var(ner) = 0; if(cache_fetch("local","a=>method::invite",$var(invite))) { + $var(invite) = $(var(invite){s.int}); + if($var(invite) > 0) { if(!cache_fetch("local","a=>response::407::invite",$var(invite407))) $var(invite407) = 0; if(!cache_fetch("local","a=>response::200::invite",$var(invite200))) $var(invite200) = 0; if(!cache_fetch("local","a=>response::bad::invite",$var(invitebad))) $var(invitebad) = 0; + + $var(invite407) = $(var(invite407){s.int}); + $var(invite200) = $(var(invite200){s.int}); + $var(invitebad) = $(var(invitebad){s.int}); + + $var(d) = $var(invite) - $var(invite407); if($var(d) > 0) { $var(asr) = $var(invite200) * 100 / $var(d); @@ -622,11 +643,34 @@ route[STORE] { $var(table) = "sip_capture_rest"; } - # or sipcapture style #$var(utc) = "%Y%m%d"; - if($var(table) == "sip_capture_call") sip_capture("sip_capture_call_%Y%m%d"); else if($var(table) == "sip_capture_registration") sip_capture("sip_capture_registration_%Y%m%d"); else sip_capture("sip_capture_rest_%Y%m%d"); } + + +route[my_hep_route] { + + ### hep_get([data type,] chunk_id, vendor_id_pvar, chunk_data_pvar) + ### data type is optional for most of the generic chunks + ### Full list here: http://www.opensips.org/html/docs/modules/2.2.x/sipcapture#hep_set_id + + #Protocol ID + hep_get("11", "$var(vid)", "$var(data)"); + + $var(proto) = $(var(data){s.int}); + + #Logs Or Stats + if($var(proto) == 100 || $var(proto) == 99) { + + #hep_set("uint8", "2", , "1"); + hep_get("utf8-string", "0x11", "$var(vid)", "$var(correlation_id)"); + report_capture("logs_capture", "$var(correlation_id)", "1"); + exit; + } + + hep_resume_sip(); + +} From 551f199e759175a175e3968d4797f0eb62d0e673 Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Fri, 6 May 2016 13:03:20 +0200 Subject: [PATCH 16/24] added correct count --- api/Database/Layer/mysql.php | 4 ++-- api/RestApi/Search.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/Database/Layer/mysql.php b/api/Database/Layer/mysql.php index 5a81ad4..8fd071d 100644 --- a/api/Database/Layer/mysql.php +++ b/api/Database/Layer/mysql.php @@ -48,7 +48,7 @@ function querySearchData($layerHelper) $time = $layerHelper['time']; $callwhere = $layerHelper['where']['param']; - $query = "SELECT t.".$values; + $query = "SELECT ".$values; $query .= " FROM ".$table." as t "; $query .= " WHERE (t.date BETWEEN FROM_UNIXTIME(".$time['from_ts'].") AND FROM_UNIXTIME(".$time['to_ts']."))"; if(count($callwhere)) $query .= " AND ( " .implode(" ".$layerHelper['where']['type']." ", $callwhere). ")"; @@ -72,7 +72,7 @@ function querySearchMessagesData($layerHelper) $time = $layerHelper['time']; $callwhere = $layerHelper['where']['param']; - $query = "SELECT t.".$values; + $query = "SELECT ".$values; $query .= " FROM ".$table." as t "; $query .= " WHERE (t.date BETWEEN FROM_UNIXTIME(".$time['from_ts'].") AND FROM_UNIXTIME(".$time['to_ts']."))"; if(count($callwhere)) $query .= " AND ( " .implode(" ".$layerHelper['where']['type']." ", $callwhere). ")"; diff --git a/api/RestApi/Search.php b/api/RestApi/Search.php index eca1551..8b15d67 100644 --- a/api/RestApi/Search.php +++ b/api/RestApi/Search.php @@ -368,7 +368,7 @@ public function doSearchMessagesData($timestamp, $param, $full = false, $count = if($uniq) $layerHelper['values'][] = "MD5(msg) as md5sum"; } else { - $layerHelper['values'][] = "id, count(*) as cnt"; + $layerHelper['values'][] = "count(*) as cnt"; } $query = $layer->querySearchMessagesData($layerHelper); From 188de114d00f33d99f3baaac7f90e69d7df939bd Mon Sep 17 00:00:00 2001 From: Lorenzo Mangani Date: Sat, 7 May 2016 03:36:24 +0200 Subject: [PATCH 17/24] Update sipcapture.opensips --- examples/sipcapture/sipcapture.opensips | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/sipcapture/sipcapture.opensips b/examples/sipcapture/sipcapture.opensips index 8aebe26..db9eb2c 100644 --- a/examples/sipcapture/sipcapture.opensips +++ b/examples/sipcapture/sipcapture.opensips @@ -10,8 +10,8 @@ log_facility=LOG_LOCAL0 children=4 -listen=udp:5.9.8.22:5062 -listen=hep_udp:5.9.8.22:9063 +listen=udp:10.0.0.22:5062 +listen=hep_udp:10.0.0.22:9063 ### CHANGEME path to your opensips modules here From 6c8bcad474fffd24342ac8fb6cfd4b768cf6f11a Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Fri, 13 May 2016 22:18:26 +0200 Subject: [PATCH 18/24] rtc report --- api/RestApi/Report.php | 158 +++++++++++++++++++++++++++++++++++++++++ api/index.php | 2 + 2 files changed, 160 insertions(+) diff --git a/api/RestApi/Report.php b/api/RestApi/Report.php index c38f54b..7c9f184 100644 --- a/api/RestApi/Report.php +++ b/api/RestApi/Report.php @@ -1418,6 +1418,125 @@ public function doLogReport($timestamp, $param){ return $answer; } + + public function doRtcReport($timestamp, $param){ + + /* get our DB */ + $db = $this->getContainer('db'); + + $data = array(); + $search = array(); + $lnodes = array(); + $answer = array(); + $callwhere = array(); + + //if(array_key_exists('node', $param)) $lnodes = $param['node']; + if(isset($param['location'])) $lnodes = $param['location']['node']; + + $time['from'] = getVar('from', round((microtime(true) - 300) * 1000), $timestamp, 'long'); + $time['to'] = getVar('to', round(microtime(true) * 1000), $timestamp, 'long'); + $time['from_ts'] = floor($time['from']/1000); + $time['to_ts'] = round($time['to']/1000); + + $time['from_ts']-=600; + $time['to_ts']+=60; + + /* search fields */ + $type = getVar('uniq', -1, $param['search'], 'int'); + $node = getVar('node', NULL, $param['search'], 'string'); + $proto = getVar('proto', -1, $param['search'], 'int'); + $family = getVar('family', -1, $param['search'], 'int'); + $and_or = getVar('orand', NULL, $param['search'], 'string'); + $limit_orig = getVar('limit', 100, $param, 'int'); + $callids = getVar('callid', array(), $param['search'], 'array'); + + $mapsCallid = array(); + + $cn = count($callids); + for($i=0; $i < $cn; $i++) { + $mapsCallid[$callids[$i]] = $callids[$i]; + + if(BLEGCID == "b2b") { + $length = strlen(BLEGTAIL); + if(substr($callids[$i], -$length) == BLEGTAIL) { + $k = substr($callids[$i], 0, -$length); + $mapsCallid[$k] = $k; + } + else { + $k = $callids[$i].BLEGTAIL; + $mapsCallid[$k] = $k; + } + + $s = substr($k, 0, -1); + $mapsCallid[$s] = $s; + } + + $k = substr($callids[$i], 0, -1); + $mapsCallid[$k] = $k; + } + + + $answer = array(); + + if(empty($mapsCallid)) + { + $answer['sid'] = session_id(); + $answer['auth'] = 'true'; + $answer['status'] = 200; + $answer['message'] = 'no data'; + $answer['data'] = $data; + $answer['count'] = count($data); + return $answer; + } + + $search['correlation_id'] = implode(";", array_keys($mapsCallid)); + + $nodes = array(); + if(SINGLE_NODE == 1) $nodes[] = array( "dbname" => DB_HOMER, "name" => "single"); + else { + foreach($lnodes as $lnd) $nodes[] = $this->getNode($lnd['name']); + } + + foreach($nodes as $node) + { + + $db->dbconnect_node($node); + $limit = $limit_orig; + if(empty($callwhere)) $callwhere = generateWhere($search, $and_or, $db, 0); + + $table = "webrtc_capture"; + $query = "SELECT *, '".$node['name']."' as dbnode FROM ".$table." WHERE (`date` BETWEEN FROM_UNIXTIME(".$time['from_ts'].") AND FROM_UNIXTIME(".$time['to_ts']."))"; + if(count($callwhere)) $query .= " AND ( " .implode(" AND ", $callwhere). ")"; + $noderows = $db->loadObjectArray($query); + $data = array_merge($data,$noderows); + $limit -= count($noderows); + } + + /* sorting */ + usort($data, create_function('$a, $b', 'return $a["micro_ts"] > $b["micro_ts"] ? 1 : -1;')); + + + if(empty($data)) { + + $answer['sid'] = session_id(); + $answer['auth'] = 'true'; + $answer['status'] = 200; + $answer['message'] = 'no data'; + $answer['data'] = $data; + $answer['count'] = count($data); + } + else { + $answer['status'] = 200; + $answer['sid'] = session_id(); + $answer['auth'] = 'true'; + $answer['message'] = 'ok'; + $answer['data'] = $data; + $answer['count'] = count($data); + } + + return $answer; + + } public function doQualityReport($id, $timestamp, $param){ @@ -1597,6 +1716,45 @@ public function doLogReportById($param){ } } + /*share */ + public function doRtcReportById($param){ + + $data = array(); + $db = $this->getContainer('db'); + $db->select_db(DB_CONFIGURATION); + $db->dbconnect(); + + $uuid = getVar('transaction_id', "", $param, 'string'); + + $query = "SELECT data FROM link_share WHERE uuid='?' limit 1"; + $query = $db->makeQuery($query, $uuid ); + $json = $db->loadObjectArray($query); + + if(!empty($json)) { + + $djson = json_decode($json[0]['data'], true); + + $timestamp = $djson['timestamp']; + $param = $djson['param']; + + $data = $this->doRtcReport($timestamp, $param); + + } + + if(empty($data)) { + + $answer['sid'] = session_id(); + $answer['auth'] = 'true'; + $answer['status'] = 200; + $answer['message'] = 'no data'; + $answer['data'] = $data; + $answer['count'] = count($data); + return $answer; + } else { + return $data; + } + } + /*share */ public function doRTCPReportById($param){ diff --git a/api/index.php b/api/index.php index 851e6ce..723d676 100644 --- a/api/index.php +++ b/api/index.php @@ -121,9 +121,11 @@ ->addPostRoute('rtcp', 'doRTCPReport') // => /api/session ->addPostRoute('qos', 'doQOSReport') // => /api/session ->addPostRoute('log', 'doLogReport') // => /api/session + ->addPostRoute('rtc', 'doRtcReport') // => /api/session/rtc ->addPostRoute('share/log', 'doLogReportById') // => /api/report/share/log ->addPostRoute('share/rtcp', 'doRTCPReportById') // => /api/report/share/log ->addPostRoute('share/qos', 'doQOSReportById') // => /api/report/share/log + ->addPostRoute('share/rtc', 'doRtcReportById') // => /api/report/share/rtc ->addPostRoute('share/quality/short', 'doQualityReportById') // => /api/report/share/log ->addPostRoute('quality/([A-Za-z]+)', 'doQualityReport') // => /api/session ->addPostRoute('share/rtpagent/short', 'doRtpAgentReportById') // => /api/report/share/log From b396af58324591cdd5546f6e94a242a7edea1106 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 15 May 2016 10:39:29 +0200 Subject: [PATCH 19/24] first rtc callflow api --- api/RestApi/Search.php | 94 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/api/RestApi/Search.php b/api/RestApi/Search.php index 8b15d67..c9835de 100644 --- a/api/RestApi/Search.php +++ b/api/RestApi/Search.php @@ -808,6 +808,95 @@ public function getMessagesForTransaction($timestamp, $param) { return $data; } + public function getRTCForTransaction($timestamp, $param) { + + /* get our DB */ + $db = $this->getContainer('db'); + $db->select_db(DB_CONFIGURATION); + $db->dbconnect(); + + $trans = array(); + $data = array(); + $lnodes = array(); + + if(isset($param['location'])) $lnodes = $param['location']['node']; + + $trans['webrtc'] = true; + + $location = $param['location']; + + $time['from'] = getVar('from', round((microtime(true) - 300) * 1000), $timestamp, 'long'); + $time['to'] = getVar('to', round(microtime(true) * 1000), $timestamp, 'long'); + $time['from_ts'] = floor($time['from']/1000); + $time['to_ts'] = round($time['to']/1000); + + //workaround for BYE click + $time['from_ts'] -=600; + + $limit_orig = getVar('limit', 200, $param['search'], 'int'); + if($limit_orig <= 0) $limit_orig = 200; + + $record_id = getVar('id', 0, $param['search'], 'int'); + $callids = getVar('callid', array(), $param['search'], 'array'); + $b2b = getVar('b2b', true, $param['search'], 'bool'); + $uniq = getVar('uniq', false, $param['search'], 'bool'); + + $callwhere = array(); + + $utils['logic_or'] = getVar('logic', false, array_key_exists('query', $param) ? $param['query'] : array(), 'bool'); + $and_or = $utils['logic_or'] ? " OR " : " AND "; + + $search = array(); + /* make array */ + $search['callid'] = implode(";", $callids); + $callwhere = generateWhere($search, $and_or, $db, $b2b); + + $nodes = array(); + if(SINGLE_NODE == 1) $nodes[] = array( "dbname" => DB_HOMER, "name" => "single"); + else { + foreach($lnodes as $lnd) $nodes[] = $this->getNode($lnd['name']); + } + + $timearray = $this->getTimeArray($time['from_ts'], $time['to_ts']); + + foreach($nodes as $node) + { + $db->dbconnect_node($node); + $limit = $limit_orig; + $ts = $time['from_ts']; + if($limit < 1) break; + $order = " order by id DESC LIMIT ".$limit; + $table = "webrtcp_capture"; + $query = "SELECT t.*, 'webrtc' as trans,'".$node['name']."' as dbnode"; + if($uniq) $query .= ", MD5(msg) as md5sum"; + $query .= " FROM ".$table." as t"; + $query .= " WHERE (t.date BETWEEN FROM_UNIXTIME(".$time['from_ts'].") AND FROM_UNIXTIME(".$time['to_ts']."))"; + if(count($callwhere)) $query .= " AND ( " .implode(" AND ", $callwhere). ")"; + $noderows = $db->loadObjectArray($query.$order); + $data = array_merge($data,$noderows); + $limit -= count($noderows); + } + + /* apply aliases */ + $this->applyAliases($data); + + if($uniq) { + $message = array(); + foreach($data as $key=>$row) + { + if(isset($message[$row['md5sum']])) unset($data[$key]); + else $message[$row['md5sum']] = $row['node']; + } + } + + /* sorting */ + usort($data, create_function('$a, $b', 'return $a["micro_ts"] > $b["micro_ts"] ? 1 : -1;')); + + return $data; + } + + + public function doSearchTransaction($timestamp, $param) { if(count(($adata = $this->getLoggedIn()))) return $adata; @@ -827,12 +916,15 @@ public function doSearchTransaction($timestamp, $param) { $localdata = array(); $data = $this->getMessagesForTransaction($timestamp, $param); - + foreach($data as $row) { $localdata[] = $this->getSIPCflow((object) $row, $hosts, $info, $uac, $hostcount, $rtpinfo, true); if(!$min_ts) $min_ts = $row['micro_ts']; } + /* RTC call */ + //$data = $this->getRTCForTransaction($timestamp, $param); + if(!$max_ts) { $max_ts_tmp = end($data); $max_ts = $max_ts_tmp['micro_ts']; From 2ae8d755228c7758182bbf7145e7310d24c09f07 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 15 May 2016 20:56:13 +0200 Subject: [PATCH 20/24] adapted version.... --- api/RestApi/Search.php | 273 +++++++++++++++++++++++++++++++++-------- 1 file changed, 222 insertions(+), 51 deletions(-) diff --git a/api/RestApi/Search.php b/api/RestApi/Search.php index c9835de..7504485 100644 --- a/api/RestApi/Search.php +++ b/api/RestApi/Search.php @@ -815,83 +815,124 @@ public function getRTCForTransaction($timestamp, $param) { $db->select_db(DB_CONFIGURATION); $db->dbconnect(); - $trans = array(); $data = array(); + $search = array(); $lnodes = array(); + $answer = array(); + $callwhere = array(); - if(isset($param['location'])) $lnodes = $param['location']['node']; - - $trans['webrtc'] = true; - - $location = $param['location']; - + //if(array_key_exists('node', $param)) $lnodes = $param['node']; + if(isset($param['location'])) $lnodes = $param['location']['node']; + $time['from'] = getVar('from', round((microtime(true) - 300) * 1000), $timestamp, 'long'); - $time['to'] = getVar('to', round(microtime(true) * 1000), $timestamp, 'long'); + $time['to'] = getVar('to', round(microtime(true) * 1000), $timestamp, 'long'); $time['from_ts'] = floor($time['from']/1000); $time['to_ts'] = round($time['to']/1000); - //workaround for BYE click - $time['from_ts'] -=600; - - $limit_orig = getVar('limit', 200, $param['search'], 'int'); - if($limit_orig <= 0) $limit_orig = 200; + $time['from_ts']-=600; + $time['to_ts']+=60; + + /* search fields */ + $type = getVar('uniq', -1, $param['search'], 'int'); + $node = getVar('node', NULL, $param['search'], 'string'); + $proto = getVar('proto', -1, $param['search'], 'int'); + $family = getVar('family', -1, $param['search'], 'int'); + $and_or = getVar('orand', NULL, $param['search'], 'string'); + $limit_orig = getVar('limit', 100, $param, 'int'); + $callids = getVar('callid', array(), $param['search'], 'array'); + + $mapsCallid = array(); + + $cn = count($callids); + for($i=0; $i < $cn; $i++) { + $mapsCallid[$callids[$i]] = $callids[$i]; + + if(BLEGCID == "b2b") { + $length = strlen(BLEGTAIL); + if(substr($callids[$i], -$length) == BLEGTAIL) { + $k = substr($callids[$i], 0, -$length); + $mapsCallid[$k] = $k; + } + else { + $k = $callids[$i].BLEGTAIL; + $mapsCallid[$k] = $k; + } + + $s = substr($k, 0, -1); + $mapsCallid[$s] = $s; + } - $record_id = getVar('id', 0, $param['search'], 'int'); - $callids = getVar('callid', array(), $param['search'], 'array'); - $b2b = getVar('b2b', true, $param['search'], 'bool'); - $uniq = getVar('uniq', false, $param['search'], 'bool'); + $k = substr($callids[$i], 0, -1); + $mapsCallid[$k] = $k; + } - $callwhere = array(); - $utils['logic_or'] = getVar('logic', false, array_key_exists('query', $param) ? $param['query'] : array(), 'bool'); - $and_or = $utils['logic_or'] ? " OR " : " AND "; + $answer = array(); - $search = array(); - /* make array */ - $search['callid'] = implode(";", $callids); - $callwhere = generateWhere($search, $and_or, $db, $b2b); + if(empty($mapsCallid)) + { + $answer['sid'] = session_id(); + $answer['auth'] = 'true'; + $answer['status'] = 200; + $answer['message'] = 'no data'; + $answer['data'] = $data; + $answer['count'] = count($data); + return $answer; + } + + $search['correlation_id'] = implode(";", array_keys($mapsCallid)); $nodes = array(); if(SINGLE_NODE == 1) $nodes[] = array( "dbname" => DB_HOMER, "name" => "single"); else { foreach($lnodes as $lnd) $nodes[] = $this->getNode($lnd['name']); } - - $timearray = $this->getTimeArray($time['from_ts'], $time['to_ts']); foreach($nodes as $node) - { - $db->dbconnect_node($node); + { + + $db->dbconnect_node($node); $limit = $limit_orig; - $ts = $time['from_ts']; - if($limit < 1) break; - $order = " order by id DESC LIMIT ".$limit; - $table = "webrtcp_capture"; - $query = "SELECT t.*, 'webrtc' as trans,'".$node['name']."' as dbnode"; - if($uniq) $query .= ", MD5(msg) as md5sum"; - $query .= " FROM ".$table." as t"; - $query .= " WHERE (t.date BETWEEN FROM_UNIXTIME(".$time['from_ts'].") AND FROM_UNIXTIME(".$time['to_ts']."))"; + if(empty($callwhere)) $callwhere = generateWhere($search, $and_or, $db, 0); + + $table = "webrtc_capture"; + $query = "SELECT *, '".$node['name']."' as dbnode, (UNIX_TIMESTAMP(date)) as unixts FROM ".$table." WHERE (`date` BETWEEN FROM_UNIXTIME(".$time['from_ts'].") AND FROM_UNIXTIME(".$time['to_ts']."))"; if(count($callwhere)) $query .= " AND ( " .implode(" AND ", $callwhere). ")"; - $noderows = $db->loadObjectArray($query.$order); - $data = array_merge($data,$noderows); - $limit -= count($noderows); + $noderows = $db->loadObjectArray($query); + $data = array_merge($data,$noderows); + $limit -= count($noderows); } - - /* apply aliases */ - $this->applyAliases($data); - if($uniq) { - $message = array(); - foreach($data as $key=>$row) - { - if(isset($message[$row['md5sum']])) unset($data[$key]); - else $message[$row['md5sum']] = $row['node']; - } + $y = count($data); + for($i=0; $i < $y; $i++) { + $dz = $data[$i]; + $ts = intval(substr($dz['micro_ts'], 2, 6)); + $data[$i]['micro_ts'] = $dz['unixts']*1000000+$ts; + $data[$i]['milli_ts'] = intval($data[$i]['micro_ts']/1000); } - + /* sorting */ usort($data, create_function('$a, $b', 'return $a["micro_ts"] > $b["micro_ts"] ? 1 : -1;')); + + if(empty($data)) { + + $answer['sid'] = session_id(); + $answer['auth'] = 'true'; + $answer['status'] = 200; + $answer['message'] = 'no data'; + $answer['data'] = $data; + $answer['count'] = count($data); + } + else { + $answer['status'] = 200; + $answer['sid'] = session_id(); + $answer['auth'] = 'true'; + $answer['message'] = 'ok'; + $answer['data'] = $data; + $answer['count'] = count($data); + } + return $data; } @@ -921,9 +962,22 @@ public function doSearchTransaction($timestamp, $param) { $localdata[] = $this->getSIPCflow((object) $row, $hosts, $info, $uac, $hostcount, $rtpinfo, true); if(!$min_ts) $min_ts = $row['micro_ts']; } + + //print_r($localdata); + //exit; /* RTC call */ - //$data = $this->getRTCForTransaction($timestamp, $param); + $data = $this->getRTCForTransaction($timestamp, $param); + foreach($data as $row) { + $localdata[] = $this->getRTCflow((object) $row, $hosts, $info, $uac, $hostcount, $rtpinfo, true); + //if(!$min_ts) $min_ts = $row['micro_ts']; + } + + //print_r($data); + //exit; + + usort($localdata, create_function('$a, $b', 'return $a["micro_ts"] > $b["micro_ts"] ? 1 : -1;')); + if(!$max_ts) { $max_ts_tmp = end($data); @@ -1065,6 +1119,7 @@ function getSIPCflow($data, &$hosts, &$info, &$uac, &$hostcount, &$rtpinfo, $mes else if(preg_match('/[3][0-9][0-9]/',$data->method)) $statuscall = 5; $calldata['id'] = $data->id; + $calldata['protocol'] = "sip"; $calldata['method'] = $data->method; $calldata['src_port'] = $data->source_port; $calldata['dst_port'] = $data->destination_port; @@ -1241,6 +1296,122 @@ function getSIPCflow($data, &$hosts, &$info, &$uac, &$hostcount, &$rtpinfo, $mes return $calldata; } + + function getRTCflow($data, &$hosts, &$info, &$uac, &$hostcount, &$rtpinfo, $message_include) { + $calldata = array(); + $arrow_step=1; + $host_step=1; + + $msg = json_decode($data->msg); + + $IPv6 = (strpos($data->source_ip, '::') === 0); + + // compress IPv6 addresses for UI + if ($IPv6) { + $data->source_ip = inet_ntop(inet_pton($data->source_ip)); + $data->destination_ip = inet_ntop(inet_pton($data->destination_ip)); + } + + if($msg->method == "call.start") $statuscall = 1; + else if($msg->method == "call.end") $statuscall = 3; + else if($msg->method == "call.accept") $statuscall = 4; + + $calldata['id'] = $data->id; + $calldata['protocol'] = "rtc"; + $calldata['method'] = $msg->method; + $calldata['src_port'] = $data->source_port; + $calldata['dst_port'] = $data->destination_port; + $calldata['trans'] = "rtc"; + $calldata['callid'] = $data->correlation_id; + $calldata['node'] = $data->node; + $calldata['dbnode'] = $data->dbnode; + $calldata['micro_ts'] = $data->micro_ts; + $calldata['ruri_user'] = $msg->body->target; + if(!empty($data->source_alias)) { $calldata['source_alias'] = $data->source_alias;} + if(!empty($data->destination_alias)) { $calldata['destination_alias'] = $data->destination_alias;} + $calldata['source_ip'] = $data->source_ip; + $calldata['destination_ip'] = $data->destination_ip; + + if($message_include) { + $calldata['msg'] = $msg; + } + + if(!array_key_exists('callid', $info)) $info['callid'] = array(); + + //array_push($info['callid'], $data->callid); + if(!in_array($data->callid, $info['callid'])) { + array_push($info['callid'], $data->callid); + } + + if (CFLOW_HPORT == true) { + + $src_id = $data->source_ip.":".$data->source_port; + $dst_id = $data->destination_ip.":".$data->destination_port; + + if(!isset($hosts[$src_id])) { $hosts[$src_id] = $hostcount; $hostcount+=$host_step; } + if(!isset($hosts[$dst_id])) { $hosts[$dst_id] = $hostcount; $hostcount+=$host_step; } + + $ssrc = ":".$data->source_port; + + } else { + + $src_id = $data->source_ip; + $dst_id = $data->destination_ip; + + if(!isset($hosts[$src_id])) { $hosts[$src_id] = $hostcount; $hostcount+=$host_step;} + if(!isset($hosts[$dst_id])) { $hosts[$dst_id] = $hostcount; $hostcount+=$host_step;} + + $ssrc = ""; + } + + $calldata['src_id'] = $src_id; + $calldata['dst_id'] = $dst_id; + + // SIP SWITCHES + + if(preg_match('/asterisk/i', $data->user_agent)) { + $uac[$src_id] = array("image" => "asterisk", "agent" => $data->user_agent); + } + else if(preg_match('/FreeSWITCH/i', $data->user_agent)) { + $uac[$src_id] = array("image" => "freeswitch", "agent" => $data->user_agent); + } + else if(preg_match('/kamailio|openser|opensip|sip-router/i', $data->user_agent)) { + $uac[$src_id] = array("image" => "openser", "agent" => $data->user_agent); + } + else if(preg_match('/softx/i', $data->user_agent)) { + $uac[$src_id] = array("image" => "sipgateway", "agent" => $data->user_agent); + } + else if(preg_match('/sipXecs/i', $data->user_agent)) { + $uac[$src_id] = array("image" => "sipxecs", "agent" => $data->user_agent); + } + + //$timestamp = floor($data->micro_ts / 1000000); + //$milliseconds = round( $data->micro_ts - ($timestamp * 1000000) ); + //$tstamp = date("Y-m-d H:i:s.".$milliseconds." T",$data->micro_ts / 1000000); + $calldata['milli_ts'] = floor($data->micro_ts / 1000); + $method_text = $msg->method; + if(strlen($method_text) > 15) $method_text = substr($data->method." ".$data->reply_reason, 0, 22)."..."; + + //SDP ? + $val = "content_type"; + if(preg_match('/sdp/i', $data->content_type)) $method_text .= " (SDP) "; + if(preg_match('/[0-9A-Za-z_-]/i', $data->auth_user)) $method_text .= " (AUTH)"; + $calldata["method_text"] = $method_text; + + // MSG Temperature + if(preg_match('/^40|50/', $method_text )) $msgcol = "red"; + else if(preg_match('/^30|SUBSCRIBE|OPTIONS|NOTIFY/', $method_text)) $msgcol = "purple"; + else if(preg_match('/^20/', $method_text)) $msgcol = "green"; + else if(preg_match('/^INVITE/', $method_text)) $msgcol = 'blue'; + else $msgcol = 'blue'; + $calldata["msg_color"] = $msgcol; + + /*IF */ + if($hosts[$src_id] > $hosts[$dst_id]) $calldata["destination"] = 2; + else $calldata["destination"] = 1; + + return $calldata; + } public function doPcapExport($timestamp, $param){ From 3d4e517af250e7010064805a91d1f470301c2b20 Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Sun, 15 May 2016 22:58:57 +0200 Subject: [PATCH 21/24] added fix --- api/RestApi/Search.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/RestApi/Search.php b/api/RestApi/Search.php index 7504485..614e385 100644 --- a/api/RestApi/Search.php +++ b/api/RestApi/Search.php @@ -906,7 +906,7 @@ public function getRTCForTransaction($timestamp, $param) { $y = count($data); for($i=0; $i < $y; $i++) { $dz = $data[$i]; - $ts = intval(substr($dz['micro_ts'], 2, 6)); + $ts = intval(substr($dz['micro_ts'], 2, 7)); $data[$i]['micro_ts'] = $dz['unixts']*1000000+$ts; $data[$i]['milli_ts'] = intval($data[$i]['micro_ts']/1000); } @@ -1322,7 +1322,7 @@ function getRTCflow($data, &$hosts, &$info, &$uac, &$hostcount, &$rtpinfo, $mess $calldata['src_port'] = $data->source_port; $calldata['dst_port'] = $data->destination_port; $calldata['trans'] = "rtc"; - $calldata['callid'] = $data->correlation_id; + $calldata['callid'] = "rtc:".$data->correlation_id; $calldata['node'] = $data->node; $calldata['dbnode'] = $data->dbnode; $calldata['micro_ts'] = $data->micro_ts; From f3f0ecc3d51a7a7cf5e74e9366defff8e9430b7d Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Sun, 15 May 2016 23:11:05 +0200 Subject: [PATCH 22/24] add --- api/RestApi/Search.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api/RestApi/Search.php b/api/RestApi/Search.php index 614e385..a6085d3 100644 --- a/api/RestApi/Search.php +++ b/api/RestApi/Search.php @@ -1322,7 +1322,7 @@ function getRTCflow($data, &$hosts, &$info, &$uac, &$hostcount, &$rtpinfo, $mess $calldata['src_port'] = $data->source_port; $calldata['dst_port'] = $data->destination_port; $calldata['trans'] = "rtc"; - $calldata['callid'] = "rtc:".$data->correlation_id; + $calldata['callid'] = $data->correlation_id; $calldata['node'] = $data->node; $calldata['dbnode'] = $data->dbnode; $calldata['micro_ts'] = $data->micro_ts; @@ -1403,7 +1403,8 @@ function getRTCflow($data, &$hosts, &$info, &$uac, &$hostcount, &$rtpinfo, $mess else if(preg_match('/^30|SUBSCRIBE|OPTIONS|NOTIFY/', $method_text)) $msgcol = "purple"; else if(preg_match('/^20/', $method_text)) $msgcol = "green"; else if(preg_match('/^INVITE/', $method_text)) $msgcol = 'blue'; - else $msgcol = 'blue'; + else $msgcol = 'red'; + $calldata["msg_color"] = $msgcol; /*IF */ From a971662cf2308e374ed86d0eebd447da1471c3be Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Sun, 15 May 2016 23:19:51 +0200 Subject: [PATCH 23/24] fixed popup --- api/RestApi/Search.php | 66 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/api/RestApi/Search.php b/api/RestApi/Search.php index a6085d3..33f172f 100644 --- a/api/RestApi/Search.php +++ b/api/RestApi/Search.php @@ -510,7 +510,9 @@ public function doSearchMethod($timestamp, $param){ if(count(($adata = $this->getLoggedIn()))) return $adata; /* get our DB */ - $data = $this->getMessagesByMethod($timestamp, $param); + $rtc = getVar('rtc', false, $param['transaction'], 'bool'); + if(!$rtc) $data = $this->getMessagesByMethod($timestamp, $param); + else $data = $this->getMessagesRTCByMethod($timestamp, $param); $answer = array(); @@ -609,6 +611,68 @@ public function getMessagesByMethod($timestamp, $param){ return $data; } + public function getMessagesRTCByMethod($timestamp, $param){ + + if(count(($adata = $this->getLoggedIn()))) return $adata; + + /* get our DB */ + $db = $this->getContainer('db'); + $db->select_db(DB_CONFIGURATION); + $db->dbconnect(); + + $data = array(); + + $record_id = getVar('id', 0, $param['search'], 'int'); + $callid = getVar('callid', "", $param['search'], 'string'); + + $location = $param['location']; + + $time['from'] = getVar('from', round((microtime(true) - 300) * 1000), $timestamp, 'long'); + $time['to'] = getVar('to', round(microtime(true) * 1000), $timestamp, 'long'); + $time['from_ts'] = floor($time['from']/1000) - 300; + $time['to_ts'] = round($time['to']/1000) + 300; + + $utils['logic_or'] = getVar('logic', false, array_key_exists('query', $param) ? $param['query'] : array(), 'bool'); + $and_or = $utils['logic_or'] ? " OR " : " AND "; + + $limit = 1; + $search['id'] = $record_id; + $callwhere = generateWhere($search, $and_or, $db, 0); + + $nodes = array(); + if(SINGLE_NODE == 1) $nodes[] = array( "dbname" => DB_HOMER); + else { + $nodes[] = $this->getNode($location['node']); + } + + $timearray = $this->getTimeArray($time['from_ts'], $time['to_ts']); + + foreach($nodes as $node) { + $db->dbconnect_node($node); + if($limit < 1) break; + $order = " LIMIT ".$limit; + $table = "webrtc_capture"; + $query = "SELECT *, '".$node['name']."' as dbnode, (UNIX_TIMESTAMP(date)) as unixts FROM ".$table." WHERE (`date` BETWEEN FROM_UNIXTIME(".$time['from_ts'].") AND FROM_UNIXTIME(".$time['to_ts']."))"; + if(count($callwhere)) $query .= " AND ( " .implode(" AND ", $callwhere). ")"; + $noderows = $db->loadObjectArray($query.$order); + $data = array_merge($data,$noderows); + $limit -= count($noderows); + } + + $y = count($data); + for($i=0; $i < $y; $i++) { + $dz = $data[$i]; + $ts = intval(substr($dz['micro_ts'], 2, 7)); + $data[$i]['micro_ts'] = $dz['unixts']*1000000+$ts; + $data[$i]['milli_ts'] = intval($data[$i]['micro_ts']/1000); + } + + /* apply aliases */ + $this->applyAliases($data); + + return $data; + } + public function doSearchMessage($timestamp, $param) { From 2edfcbd4d9273c211381c1347966c3125d09143c Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Sun, 15 May 2016 23:37:56 +0200 Subject: [PATCH 24/24] last fix for cflow --- api/RestApi/Search.php | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/api/RestApi/Search.php b/api/RestApi/Search.php index 33f172f..40687aa 100644 --- a/api/RestApi/Search.php +++ b/api/RestApi/Search.php @@ -1020,8 +1020,15 @@ public function doSearchTransaction($timestamp, $param) { $rtpinfo = array(); $localdata = array(); + /* RTC call */ + $data = $this->getRTCForTransaction($timestamp, $param); + foreach($data as $row) { + $localdata[] = $this->getRTCflow((object) $row, $hosts, $info, $uac, $hostcount, $rtpinfo, true); + //if(!$min_ts) $min_ts = $row['micro_ts']; + } + $data = $this->getMessagesForTransaction($timestamp, $param); - + foreach($data as $row) { $localdata[] = $this->getSIPCflow((object) $row, $hosts, $info, $uac, $hostcount, $rtpinfo, true); if(!$min_ts) $min_ts = $row['micro_ts']; @@ -1030,12 +1037,7 @@ public function doSearchTransaction($timestamp, $param) { //print_r($localdata); //exit; - /* RTC call */ - $data = $this->getRTCForTransaction($timestamp, $param); - foreach($data as $row) { - $localdata[] = $this->getRTCflow((object) $row, $hosts, $info, $uac, $hostcount, $rtpinfo, true); - //if(!$min_ts) $min_ts = $row['micro_ts']; - } + //print_r($data); //exit; @@ -1463,11 +1465,11 @@ function getRTCflow($data, &$hosts, &$info, &$uac, &$hostcount, &$rtpinfo, $mess $calldata["method_text"] = $method_text; // MSG Temperature - if(preg_match('/^40|50/', $method_text )) $msgcol = "red"; - else if(preg_match('/^30|SUBSCRIBE|OPTIONS|NOTIFY/', $method_text)) $msgcol = "purple"; - else if(preg_match('/^20/', $method_text)) $msgcol = "green"; - else if(preg_match('/^INVITE/', $method_text)) $msgcol = 'blue'; - else $msgcol = 'red'; + if(preg_match('/^call.end/', $method_text )) $msgcol = "red"; + else if(preg_match('/^call.accept/', $method_text)) $msgcol = "green"; + else if(preg_match('/^call.ringing/', $method_text)) $msgcol = "purple"; + else if(preg_match('/^call.start/', $method_text)) $msgcol = 'blue'; + else $msgcol = 'black'; $calldata["msg_color"] = $msgcol;