3 # Asterisk Queue Viewer
4 # Uses management interface to query call queues on a machine
5 # (C) 2003 David C. Troy -- dave@toad.net
7 # This program is free software, distributed under the terms of the
8 # GNU General Public License
12 use CGI
qw(:standard);
13 use CGI
::Carp qw
/fatalsToBrowser/;
15 $host = "asterisk.yourdomain.com";
17 $user = "manager_user";
18 $secret = "Manager_secret";
21 $queue = param
('queue');
23 $remote = IO
::Socket
::INET
->new(
24 Proto
=> 'tcp', # protocol
25 PeerAddr
=> $host, # Address of server
26 PeerPort
=> $port, # port of server
30 $remote->autoflush(1); # Send immediately
32 # Login and get our booty from Asterisk
33 $logres = send_cmd
("Action: Login${EOL}Username: $user${EOL}Secret: $secret$BLANK");
34 $qinfo = send_cmd
("Action: queues$BLANK$EOL");
35 $logres = send_cmd
("Action: Logoff$BLANK");
36 close $remote; # Close socket
38 my %qcalls = map { /(\S+)\s+has (\d+) calls.*?\n\n/sg; } $qinfo;
39 my %qmax = map { /(\S+)\s+has \d+ calls \(max (\S+)\).*?\n\n/sg; } $qinfo;
40 my %qstrat = map { /(\S+)\s+has \d+ calls \(max \S+\) in (\S+) strategy.*?\n\n/sg; } $qinfo;
41 my %qmems = map { /(\S+)\s+has \d+ calls.*?Members:.*?\s{6}(.*?)\s{3}\S*?\s*?Callers/sg; } $qinfo;
42 my %qcallers = map { /(\S+)\s+has \d+ calls.*?([No ]*Callers.*?)\n\n/sg; } $qinfo;
45 print start_html
(-head
=>meta
({-http_equiv
=>'Refresh', -content
=>'120'}),
46 -title
=>"PBX Queue Viewer",
47 -style
=>{'src'=>'/pbxinfo.css'});
48 print "<table width=850><tr>";
52 foreach $q (keys %qcalls) {
56 $mems =~ s/\n/<br>\n/g;
57 $callers = $qcallers{$q};
59 $callers =~ s/Callers:.*\n//g;
60 $callers =~ s/\n/<br>/g;
62 print qq{<td valign
=top width
=48%><table width
=100%>
63 <tr
><th colspan
=2><A HREF
=/mrtg/qmon
-$q.html
>$q</A> $qcalls{$q} calls (max $qmax{$q}), $qstrat{$q} strategy</th
></tr
>
64 <tr
><td valign
=top width
=55%>$mems</td><td valign=top width=45%>$callers</td
></tr
>
68 print "</tr><tr>" if $col;