I’m running aah2.8 and i need to import the /var/log/asterisk/queue_log.1 into MySQL.
How would I go about doing that?
thanks
I’m running aah2.8 and i need to import the /var/log/asterisk/queue_log.1 into MySQL.
How would I go about doing that?
thanks
this is my PHP file, run every minute. keep in mind that i use a mysql class in an included file - you’ll need to modify to suit your needs.
also, this script is hard coded to use the queue_log file - you could easily modify this to take a GET or POST variable, or scan for all queue_log* files in the directory - this is what i use for my queue stats system, and it works damn near flawlessly.
<?php
include 'mysql_connect.php';
$logfile = '/var/log/asterisk/queue_log';
$delimiter = '|';
$data=file($logfile);
$numlines = count($data);
$num_rows = explode($delimiter, $data[0]);
if (count($num_rows) >= 5)
{
for($i=1; $i<$numlines; $i++)
{
$row = explode($delimiter, eregi_replace("[\'\"]", "", $data[$i]));
$epoch = trim($row[0]);
$uniqueid = trim($row[1]);
$queuename = trim($row[2]);
$agent = trim($row[3]);
$event = trim($row[4]);
$arg1 = trim($row[5]);
$arg2 = trim($row[6]);
$arg3 = trim($row[7]);
$check_log = "select uniqueid from queue_log where epoch='$epoch' and uniqueid='$uniqueid' and event='$event'";
$result = $db->query($check_log);
$num_rows = $result->size();
if($num_rows == 0) {
$sql = "insert into queue_log (`epoch`,`uniqueid`,`queuename`,`agent`,`event`,`arg1`,`arg2`,`arg3`)
values ('$epoch','$uniqueid','$queuename','$agent','$event','$arg1','$arg2','$arg3')";
$result = $db->query($sql);
}
}
}
?>