Created
December 3, 2012 22:17
-
-
Save artbikes/4198643 to your computer and use it in GitHub Desktop.
Asterisk Queue Email
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# | |
# coll.pl - This script queries asterisk for the members of the | |
# Collections Queue, finds the Agents' names from agents.conf, | |
# then mails the output. | |
# | |
my $TITLE = "Members of Collections Queue"; | |
my $RECIPIENTS = "operations\@example.com,user\@example.com"; | |
my $numberOfElements = 0; | |
my @agentlist = (); | |
# | |
# Agents are collected in a while loop since asterisk occasionally | |
# returns no values. | |
# | |
while ( $numberOfElements eq 0 ){ | |
&get_agents; | |
$numberOfElements = @agentlist; | |
} | |
# | |
# This section builds a hash of all agents in agents.conf. | |
# | |
$confile = "/etc/asterisk/agents.conf"; | |
%queue = (); | |
open(CONFILE, $confile); | |
while(<CONFILE>) { | |
my $line = $_; | |
chomp($line); | |
if ($line =~ /^[aA]gent => \d\d\d\d,\s?(\d\d\d\d),\s?(\w.*)/) | |
{ | |
$queue{$1} = $2; | |
} | |
} | |
close(CONFILE); | |
# | |
# Here we mail a dynamically created list of agents in the Collections | |
# Queue derived from the hash of all agents. | |
# | |
open (MAIL, "|mail -s '$TITLE' $RECIPIENTS"); | |
foreach (@agentlist){ | |
print MAIL "$_ -> $queue{$_} \n"; | |
} | |
close (MAIL); | |
# | |
# Subroutine which populates an array of agents in the UK Collections | |
# Queue. | |
# | |
sub get_agents { | |
open(PWD_HANDLE, "/usr/sbin/asterisk -rx 'queue show col'|"); | |
while(<PWD_HANDLE>) { | |
my $line = $_; | |
chomp($line); | |
if ($line =~ /Agent\/(\d\d\d\d)/) | |
{ | |
unshift(@agentlist, $1); | |
} | |
} | |
close(PWD_HANDLE); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment