Difference between revisions of "Check calls duration using sniffer's api"

From VoIPmonitor.org
Jump to navigation Jump to search
(Created page with "= request = Print list of calls that are still UP with duration longer then N seconds = details = Currently there is no alert for checking the calls duration in a realtime (...")
 
Line 3: Line 3:
  
 
= details =
 
= details =
Currently there is no alert for checking the calls duration in a realtime (before call ended and stored its CDR in db) in the GUI.
+
Currently (11/2021) there is no alert for checking the calls duration in a realtime (before call ended and stored its CDR in db) in the GUI.
 
But you can use the api of a sniffer service to list active calls to ouptput/print only longer calls, and set cron to check periodically and when output present let the crond send you the email.
 
But you can use the api of a sniffer service to list active calls to ouptput/print only longer calls, and set cron to check periodically and when output present let the crond send you the email.
  

Revision as of 15:26, 19 November 2021

request

Print list of calls that are still UP with duration longer then N seconds

details

Currently (11/2021) there is no alert for checking the calls duration in a realtime (before call ended and stored its CDR in db) in the GUI. But you can use the api of a sniffer service to list active calls to ouptput/print only longer calls, and set cron to check periodically and when output present let the crond send you the email.

requirements

You need to tell to sniffer service, that you are interested in calls longer then 4 hours (4 hours and longer calls are truncated when intercepting by default) We will set there 6 hours instead (in /etc/voipmonitor.conf):

absolute_timeout = 21600

Then the service needs to be restarted to apply change in settings

service voipmonitor restart 

script

Content of the script, it will print the calls where duration is longer then 5 hours (you can change duration to connect_duration in line if ($call[$keys['duration']] > $limit))

<?php
#limit duration to 5 hours (in seconds)
$limit = 5 * 60 * 60;

exec("echo listcalls | nc 127.0.0.1 5029",$retstr,$rt);
$data=json_decode($retstr[0]);

#ensure some active calls returned
if (!array_key_exists ("1",$data)) exit;

#get the list of column names returned, use the keys then in $keys array
$cols = array_shift($data);
foreach ($cols as $n=>$col) $keys[$col]=$n;

#list the possible keys
//print_r($keys); 

#process the calls, use key 'duration' as a limit, and return these keys calldate,duration, connect_duration, caller, called, callerip,calledip
$results = array();
foreach ($data as $n=>$call) {
        if ($call[$keys['duration']] > $limit) {
                $results[]=array("calldate" => $call[$keys['calldate']],
                                "duration" => $call[$keys['duration']],
                                "connect_duration" => $call[$keys['connect_duration']],
                                "caller" => $call[$keys['caller']],
                                "called" => $call[$keys['called']],
                                "callerip" => long2ip($call[$keys['callerip']]),
                                "calledip" => long2ip($call[$keys['calledip']]));
        }
}
#print all matching results
if (array_key_exists ("0",$results)) print_r($results);
?>

use of the script

the script can be started from CLI of the linux (requires php processor and requires to have api of the sniffer service accessible - by default 127.0.0.1 5029) then you can run the script

php duration.php

When no output it means there are no longer calls Output is detail about calls with duration longer then specified in $limit