Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Fixed a couple of syntax errors

...

Code Block
languageperl
titlemessagedunmp.pl
borderStylesolid
use OpenSIPS qw ( log );
use OpenSIPS::Constants;
use DBI;

$my_database=voip;
$my_user=voip;
$my_password=password;
$my_host="127.0.0.1";
$my_platform="Pg";
# For MYSQL database use
# $my_platform="mysql";

sub messagedump {
    my $m = shift;
    my $name;
    my $number;
    my $localUA;
    my $remoteUA;
    my $callID;
    my $packetLoss;
    my $moslq;
    my $moscq;
    my $rtd;
    my $timeStart;
    my $timeStop;

#	open F,">>/tmp/opensips-perl-messagedump";
    my $fh = $m->getHeader("From");
    if($fh =~ /"(.*)"\s+<sip:(\d+)@.*$/)
    {
        $name=$1;
        $number=$2;
    }
#	print F "NAME:$name\nNUMBER:$number\n";
    my $mb = $m->getBody();
#	print F "$mb\n";
    if($mb =~ /.*CallID:(.+).*/)
    {
        $callID = $1;
        $callID =~ s/\@.*//g; #remove the @symbol and everthing after
    }
    if($mb =~ /.*LocalAddr:IP=(.+)\s+PORT.*/)
    {
        $localUA = $1;
    }
    if($mb =~ /.*RemoteAddr:IP=(.+)\s+PORT.*/)
    {
        $remoteUA = $1;
    }
    if($mb =~ /.*RTD=(.+)\s+ESD.*/)
    {
        $rtd = $1;
    }
    if($mb =~ /.*PacketLoss:NLR=(\d+\.\d+).*/)
    {
    $packetLoss=$1;
    }
    if($mb =~ /.*MOSLQ=(\d.\d)\s+MOSCQ=(\d.\d).*/)
    {
        $moslq = $1;
        $moscq = $2;
    }
    if($mb =~ /.*START=(.+)\s+STOP=(.+).*/)
    {
        $timeStart = $1;
        $timeStop = $2;
    }

 
#	print F "CallID:$callID\n";
#	print F "timeStart:$timeStart\n";
#	print F "timeStop:$timeStop\n";
#	print F "lUA:$localUA\n";
#	print F "rUA:$remoteUA\n";
#	print F "rtd:$rtd\n";
#	print F "moslq:$moslq\n";
#	print F "moscq:$moscq\n";
#	print F "loss:$packetLoss\n";


my $insert = "INSERT INTO qos VALUES ('$callID','$name','$number','$timeStart','$timeStop','$localUA','$remoteUA','$rtd','$moslq','$moscq','$packetLoss')";
 
#	print F "$insert\n";
#	close(F);

my $cn = DBI->connect("DBI:$my_platform:database=$my_database;host=$my_host", "$my_user", "$my_password");

# update record with existing callid if any, otherwise insert the new call quality data
if($perl_my$cn) {
        my $q_str;
        my $testQuery = $perl_my$cn->prepare("SELECT rtd from qos where callid='$callID'");
        $testQuery->execute();
        if($testQuery->rows() > 0){
                $q_str = "UPDATE qos set timestop='$timeStop', rtd='$rtd', moslq='$moslq', moscq='$moscq', packetloss='$packetLoss' where callid='$callID'";
        }
        else {
                $q_str = "INSERT INTO qos VALUES ('$callID','$name','$number','$timeStart','$timeStop','$localUA','$remoteUA','$rtd','$moslq','$moscq','$packetLoss')";
        }
        my $query = $perl_my$cn->prepare($q_str);
        $query->execute();
}


#email sending
if($moslq < 2.0){
$Mailer = '/usr/sbin/sendmail -t';
open MAIL,"|$Mailer";
print MAIL <<THE_EMAIL;
From: root\@sip.example.com
To: noc\@example.com 
Subject: Poor Voice Quality
Content-type: text/plain\n\n

The user $name experienced a MOS score of $moslq
on a call ending at: $timeStop.\n

This call was between $localUA and $remoteUA.
THE_EMAIL
close MAIL;
	}
}
    return 1;
}
Code Block
languagesql
titledatabase_structure_postgresql
borderStylesolid
CREATE TABLE qos (
    callid character varying(50),
    name character varying(50),
    number character varying(12),
    timestart timestamp without time zone,
    timestop timestamp without time zone,
    localua character varying(20),
    remoteua character varying(20),
    rtd integer,
    moslq character varying(10),
    moscq character varying(10),
    packetloss character varying(10)
);

...