Check calls duration using sniffer's api
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 output/print only longer calls, and set cron to check periodically and when output present let the crond send you the email.
requirements & limitations
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
The script is tested on ipv4, if you need it also for ipv6 please send email to support@voipmonitor.org
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 options managerip and managerport in /etc/voipmonitor.conf) the check of remote probes is also possible - you need to modify the exec line in the script (IP and port):
then you can run the script in CLI
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 variable