[Asterisk-Users] queue_log

Joe Dennick joe at dennick.net
Tue Jan 4 17:52:42 MST 2005


I've got a little PhP script that I stole off the wiki and modified.  It
was originally designed to send the Queue Log data to PostGresSQL, but I
modified it (my PhP skills are also very weak) to send the data to a
MySQL database.  I've got it set up to run as a cron job every night so
that each day, you can view the previous day's statistics.  I've copied
the script below for anyone who's interested in it.  Please note that it
converts the dates and times appropriately, and the database
configuration is on the very last few lines.

*************** BEGIN Logque.php ***************

#!/usr/bin/php
<?php
// #!/usr/bin/php -q
/*
  Analyze the queue and send to the server once a day

        o This file should be call just after midnight
        o Make sure the postgresql server allows you to connect from
this box
        o Make sure you have php and php-pgsql or the postgresql
functions for p
hp installed
  o Be sure you have a table setup on your database server to receive
this data.
        o The script process each file with a single digit after the
file name o
f queue
          and then expects to move the file to an archive spot and
rename it wit
h the
                processed date.

        Send update suggestions to 78 @ ekn dot com

        No warranty, no gurantee that this will not blow up your system.

*/

$pg_server = "localhost";
$pg_user   = "root";
$pg_dbname = "asteriskcdrdb";

$conn = mysql_connect("localhost", "root", "password");
mysql_select_db("asteriskcdrdb", $conn);

$out = ""; //clear the out var
$dir = '/var/log/asterisk/';
$d = dir($dir); //Set the main directory

$day = date("mdy");

//Look what files we have.
while (false !== ($entry = $d->read())) {
        if ($entry == "." || $entry == ".."){           //Don't display
the dots
        } else {
                //File Listing
//      if(is_numeric(substr($entry,10,1)) && substr($entry,0,1) =="q"){
                if (substr($entry,0,1) == "q") {
                        echo "\nFound Valid file to process - $entry\n";
                        //Process the file
                        processfile($dir.$entry);
                        //Back up the file
                        copy($dir.$entry,
"/root/logarchive/${entry}_$day");
                        //Remove the file
                        unlink($dir.$entry);
                }

        }
}

$d->close();

function processfile($file){
        global $conn;

        $fl = fopen($file,"r"); if(!$fl){echo "Error occured";exit;}
        $dt = fread($fl,filesize($file));
        fclose($fl);

        $log = explode("\n",$dt);

        while (list($key,$val) = each($log)){
                $data = explode("|",$val);

                $data[0] = date("H:i:s",$data[0]);
                $data[1] = date("y/m/d",$data[1]);

                // If you want to see the data first, you can comment
these line
s out
                //echo $data[0]
                //      .       " : " . $data[1]
                //      . " : " . $data[2] . " : " . $data[3] . " : " .
$data[4]

                //      . " : " . $data[5] . " : " . $data[6]
                //      . "\n";

                if(!empty($data[2])){
                        $ret = mysql_query("INSERT INTO csr_queue VALUES
 
('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]'
,'$data[5]','$data[6]','$data[7]')");
                }


        }
}

mysql_close($conn);


/* Create table layout */

/* Past the following in your postgresql command prompt to remove the
existing t
able
   and create it back.
         WARNING: This will destroy any data you have in this table

 drop table csr_queue;
 create table csr_queue
        (qtime time,qdate date,qname text,agent text,action text,info1
text,info
2 text,info3 text);

*/
?>

*************** BEGIN Logque.php ***************
-----Original Message-----
From: asterisk-users-bounces at lists.digium.com
[mailto:asterisk-users-bounces at lists.digium.com] On Behalf Of Brian Roy
Sent: Tuesday, January 04, 2005 2:56 PM
To: Asterisk Users Mailing List - Non-Commercial Discussion
Subject: Re: [Asterisk-Users] queue_log


On Tue, 4 Jan 2005 12:19:31 -0500, John Bittner <john at simlab.net> wrote:
> Anyone know how to get app_queue to send logs to MySQL or
> any other sql server.
> I found info for cdr's and even configs but nothing on queue_log.
> 
> If sql is not supported in the current app_queue I will be willing to 
> pay someone to add it.
> 
> John Bittner
> Simlab.net
> 

John,

I wrote a little perl routine that monitors the log and sends it to
MySQL as it's written. Now, my perl skills are very weak. The app works
fine and we have been running it in production for months, but keep in
mind it was written by a total non-programmer type (me).

If you don't find what you are looking for, I would be glad to send this
to you. Just let me know.

-Chuji
_______________________________________________
Asterisk-Users mailing list
Asterisk-Users at lists.digium.com
http://lists.digium.com/mailman/listinfo/asterisk-users
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

-- 
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.296 / Virus Database: 265.6.7 - Release Date: 12/30/2004
 

-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.296 / Virus Database: 265.6.7 - Release Date: 12/30/2004
 




More information about the asterisk-users mailing list