Untitled
unknown
plain_text
9 months ago
43 kB
22
Indexable
#!/usr/bin/perl # # AST_update.pl version 2.14 # # DESCRIPTION: # uses the Asterisk Manager interface and DBD::MySQL to update the live_channels # tables and verify the parked_channels table in the asterisk MySQL database # This near-live-status of Zap/SIP/Local/IAX/DAHDI channels list is used by clients # # SUMMARY: # This program was designed for people using the Asterisk PBX with Digium # Zaptel telco cards and SIP VOIP hardphones or softphones as extensions, it # could be adapted to other functions, but I designed it specifically for # Zap/IAX2/SIP/DAHDI users. The program will run on UNIX or Win32 command line # providing the following criteria are met: # # Win32 - ActiveState Perl 5.8.0 # UNIX - Gnome or KDE with Tk/Tcl and perl Tk/Tcl modules loaded # Both - DBD::MySQL, Net::Telnet and Time::HiRes perl modules loaded # # For the astguiclient program to work, this program must always be running # # For this program to work you need to have the "asterisk" MySQL database # created and create the tables listed in the MySQL_AST_CREATE_tables.sql file, # also make sure that the machine running this program has select/insert/update/delete # access to that database # # It is recommended that you run this program on each local Asterisk machine # # Copyright (C) 2017 Matt Florell <[email protected]> LICENSE: AGPLv2 # use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have high precision times for monitoring # Defaults for DB connections $DB_port='3306'; # default path to astguiclient configuration file: $PATHconf = '/etc/astguiclient.conf'; open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n"; @conf = <conf>; close(conf); $i=0; foreach(@conf) { $line = $conf[$i]; $line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi; if ( ($line =~ /^PATHhome/) && ($CLIhome < 1) ) {$PATHhome = $line; $PATHhome =~ s/.*=//gi;} if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) ) {$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;} if ( ($line =~ /^PATHagi/) && ($CLIagi < 1) ) {$PATHagi = $line; $PATHagi =~ s/.*=//gi;} if ( ($line =~ /^PATHweb/) && ($CLIweb < 1) ) {$PATHweb = $line; $PATHweb =~ s/.*=//gi;} if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) ) {$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;} if ( ($line =~ /^PATHmonitor/) && ($CLImonitor < 1) ) {$PATHmonitor = $line; $PATHmonitor =~ s/.*=//gi;} if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) ) {$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;} if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) ) {$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;} if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) ) {$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;} if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) ) {$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;} if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) ) {$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;} if ( ($line =~ /^VARDB_custom_user/) && ($CLIDB_custom_user < 1) ) {$VARDB_custom_user = $line; $VARDB_custom_user =~ s/.*=//gi;} if ( ($line =~ /^VARDB_custom_pass/) && ($CLIDB_custom_pass < 1) ) {$VARDB_custom_pass = $line; $VARDB_custom_pass =~ s/.*=//gi;} if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) ) {$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;} $i++; } # Customized Variables for manager connections $ASTmgrUSERNAME = 'cron'; $ASTmgrSECRET = '1234'; $ASTmgrUSERlistencron = 'listencron'; $ASTmgrSECRETlistencron = '1234'; # default path to astguiclient configuration file: $PATHconf = '/etc/astguiclient.conf'; open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n"; @conf = <conf>; close(conf); $i=0; foreach(@conf) { $line = $conf[$i]; $line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi; if ( ($line =~ /^PATHhome/) && ($CLIhome < 1) ) {$PATHhome = $line; $PATHhome =~ s/.*=//gi;} if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) ) {$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;} if ( ($line =~ /^PATHagi/) && ($CLIagi < 1) ) {$PATHagi = $line; $PATHagi =~ s/.*=//gi;} if ( ($line =~ /^PATHweb/) && ($CLIweb < 1) ) {$PATHweb = $line; $PATHweb =~ s/.*=//gi;} if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) ) {$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;} if ( ($line =~ /^PATHmonitor/) && ($CLImonitor < 1) ) {$PATHmonitor = $line; $PATHmonitor =~ s/.*=//gi;} if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) ) {$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;} if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) ) {$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;} if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) ) {$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;} if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) ) {$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;} if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) ) {$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;} if ( ($line =~ /^VARDB_custom_user/) && ($CLIDB_custom_user < 1) ) {$VARDB_custom_user = $line; $VARDB_custom_user =~ s/.*=//gi;} if ( ($line =~ /^VARDB_custom_pass/) && ($CLIDB_custom_pass < 1) ) {$VARDB_custom_pass = $line; $VARDB_custom_pass =~ s/.*=//gi;} if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) ) {$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;} $i++; } # Customized Variables $server_ip = $VARserver_ip; # Asterisk server IP if (!$VARDB_port) {$VARDB_port='3306';} use DBI; use Net::Telnet (); use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have high precision times for monitoring # Force AMI connection to local server $telnet_host = '127.0.0.1'; $telnet_port = 5038; # Ensure listencron credentials are set $ASTmgrUSERlistencron = 'listencron'; $ASTmgrSECRETlistencron = '1234'; ### begin parsing run-time options ### if (length($ARGV[0])>1) { $i=0; while ($#ARGV >= $i) { $args = "$args $ARGV[$i]"; $i++; } if ($args =~ /--help/i) { print "allowed run time options:\n [-t] = test\n [-debug] = verbose debug messages\n\n"; exit; } else { if ($args =~ /-debug/i) { $DB=1; # Debug flag print "\n----- DEBUGGING -----\n\n"; } if ($args =~ /-t/i) { $TEST=1; $T=1; } } } ### end parsing run-time options ### $event_string='LOGIN'; # Assign host first $telnet_host = $VARserver_ip; # 127.0.0.1 is OK $telnet_port = '5038'; # Asterisk AMI port # Then open Telnet connection $t = new Net::Telnet( Port => $telnet_port, Prompt => '/.*[\$%#>] $/', Output_record_separator => '', Timeout => 10, ); $t->open("$telnet_host"); ### connect to Asterisk manager through telnet $t = new Net::Telnet (Port => $telnet_port, Prompt => '/.*[\$%#>] $/', Output_record_separator => '', Timeout => 10,); # $fh = $t->dump_log("$UPtelnetlog"); # uncomment for telnet log if (length($ASTmgrUSERNAMEupdate) > 3) {$telnet_login = $ASTmgrUSERNAMEupdate;} else {$telnet_login = $ASTmgrUSERNAME;} $t->open("$telnet_host"); $t->waitfor(Timeout => 10, Match => '/^/'); # match anything, up to newline $t->print("Action: Login\nUsername: $telnet_login\nSecret: $ASTmgrSECRET\n\n"); ### connect to Asterisk manager as listencron # Create Telnet object $t_listen = new Net::Telnet( Port => $telnet_port, Prompt => '/.*[\$%#>] $/', Output_record_separator => '', Timeout => 10, ); # Set login credentials $telnet_login = $ASTmgrUSERlistencron; # Open connection and login $t_listen->open("$telnet_host"); $t_listen->waitfor(Timeout => 10, Match => '/^/'); # wait for login prompt $t_listen->print("Action: Login\nUsername: $telnet_login\nSecret: $ASTmgrSECRETlistencron\n\n"); # default timeout values $STARTtime = time(); $DROP_TIME=15; # seconds to drop the manager connection if no responses # add a proper DB connection for $dbhA->prepare use DBI; $dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass") or die "Couldn't connect to database: " . DBI->errstr; ### Grab Server values from the database $stmtA = "SELECT telnet_host,telnet_port,ASTmgrUSERNAME,ASTmgrSECRET,ASTmgrUSERNAMEupdate,ASTmgrSECRETupdate,max_ast_update_nanoseconds,ASTmgrUSERNAMElisten,ASTmgrSECRETlisten,ASTmgrUSERNAMEsend,ASTmgrSECRETsend,local_gmt,VDADenabled,asterisk_version FROM servers where server_ip = '$server_ip';"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; if ($sthArows > 0) { @aryA = $sthA->fetchrow_array; $DB_telnet_host = $aryA[0]; $DB_telnet_port = $aryA[1]; $DB_astmgrusername = $aryA[2]; $DB_astmgrsecret = $aryA[3]; $DB_astmgrusernameupdate = $aryA[4]; $DB_astmgrsecretupdate = $aryA[5]; $DB_max_ast_update_nanoseconds = $aryA[6]; $DB_astmgrusernamelisten = $aryA[7]; $DB_astmgrsecretlisten = $aryA[8]; $DB_astmgrusernamesend = $aryA[9]; $DB_astmgrsecretsend = $aryA[10]; $DB_local_gmt = $aryA[11]; $DB_VDADenabled = $aryA[12]; $DB_asterisk_version = $aryA[13]; if ($DB_telnet_host) {$telnet_host = $DB_telnet_host;} if ($DB_telnet_port) {$telnet_port = $DB_telnet_port;} if ($DB_astmgrusername) {$ASTmgrUSERNAME = $DB_astmgrusername;} if ($DB_astmgrsecret) {$ASTmgrSECRET = $DB_astmgrsecret;} if ($DB_astmgrusernameupdate) {$ASTmgrUSERNAMEupdate = $DB_astmgrusernameupdate;} if ($DB_astmgrsecretupdate) {$ASTmgrSECRETupdate = $DB_astmgrsecretupdate;} if ($DB_astmgrusernamelisten) {$ASTmgrUSERlisten = $DB_astmgrusernamelisten;} if ($DB_astmgrsecretlisten) {$ASTmgrSECRETlisten = $DB_astmgrsecretlisten;} if ($DB_astmgrusernamesend) {$ASTmgrUSERsend = $DB_astmgrusernamesend;} if ($DB_astmgrsecretsend) {$ASTmgrSECRETsend = $DB_astmgrsecretsend;} } $sthA->finish(); $telnet_login = $ASTmgrUSERNAME; if ($event_string =~ /LOGIN/) { $|=1; $t->waitfor('/Authentication accepted/'); # wait for login $event_string='SUCCESS'; print "SUCCESSFUL LOGIN\n" if ($DB); } else { $event_string='FAILED'; print "FAILED LOGIN\n" if ($DB); } if ($event_string =~ /LOGIN/) { $|=1; $t_listen->waitfor('/Authentication accepted/'); # wait for login $event_string='SUCCESS'; print "SUCCESSFUL LISTEN LOGIN\n" if ($DB); } else { $event_string='FAILED'; print "FAILED LISTEN LOGIN\n" if ($DB); } $secX = time(); $TDtarget = ($secX - 21600); # look back 6 hours ($TDSsec,$TDSmin,$TDShour,$TDSmday,$TDSmon,$TDSyear,$TDSwday,$TDSyday) = localtime($TDtarget); $TDSyear = ($TDSyear + 1900); $TDSmon++; if ($TDSmon < 10) {$TDSmon = "0$TDSmon";} if ($TDShour < 10) {$TDShour = "0$TDShour";} if ($TDSmin < 10) {$TDSmin = "0$TDSmin";} if ($TDSsec < 10) {$TDSsec = "0$TDSsec";} if ($TDSmday < 10) {$TDSmday = "0$TDSmday";} $SQLdate_TDS = "$TDSyear-$TDSmon-$TDSmday $TDShour:$TDSmin:$TDSsec"; ### BEGIN while loop ### $endless_loop=1; # 1=run continuous, 2=run only once while($endless_loop > 0) { $event_string='PARK'; $monitor_active=0; # get new server_updater time $stmtA = "SELECT last_update FROM server_updater where server_ip='$server_ip';"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; $event_string=''; if ($sthArows > 0) { @aryA = $sthA->fetchrow_array; $DB_server_updater_time = $aryA[0]; } $sthA->finish(); $SQLdate = sprintf("%03d%02d%02d%02d%02d%02d", $year,$mon,$mday,$hour,$min,$sec); # update server_updater time $stmtA = "UPDATE server_updater set last_update='$SQLdate' where server_ip='$server_ip';"; if ($DB) {print " |UPDATE server_updater: $stmtA|\n";} $affected_rows = $dbhA->do($stmtA); # get new server performance data $server_load = get_server_load(); ($mem_total, $mem_used, $mem_free) = get_mem_usage(); $disk_usage = get_disk_space(); $num_processes = get_num_processes(); # update server_performance table $stmtA = "INSERT INTO server_performance (server_ip,server_load,mem_total,mem_used,mem_free,disk_usage,num_processes,update_time) values('$server_ip', '$server_load', '$mem_total', '$mem_used', '$mem_free', '$disk_usage', '$num_processes', now());"; if ($DB) {print " |UPDATE server_performance: $stmtA|\n";} $affected_rows = $dbhA->do($stmtA); # update live_channels and parked_channels tables $channel_live=1; while ($channel_live > 0) { $event_string='CHANNEL'; # grab all channels from asterisk $t->print("Action: Command\nCommand: show channels verbose\n\n"); @list_channels = $t->waitfor('/--END COMMAND--/'); # waitfor, but only first match $event_string=''; $channel_live = $t->eof(); if ($DB) {print " |LIST ALL CHANNELS: $channel_live|$t->eof()|\n";} $j=0; $channels_processed=0; foreach(@list_channels) { $channel = $list_channels[$j]; if ($channel =~ /active channel/i) { $active_channels = $channel; $active_channels =~ s/ .*//gi; } if ( ($channel !~ /--END COMMAND--/) && ($j > 0) ) { if ($channel =~ /^(\d+ active channel|No active channel)/i) { $active_line = $channel; } else { $channel =~ s/^ //gi; $channel =~ s/ \d+\. //gi; $channel =~ s/ $//gi; if (length($channel) > 5) { $channel_processed[$channels_processed] = $channel; $channels_processed++; } } } $j++; } # update live_channels table $stmtA = "TRUNCATE TABLE live_channels;"; $affected_rows = $dbhA->do($stmtA); $k=0; while ($k < $channels_processed) { $channel = $channel_processed[$k]; $channel =~ s/\'/\\\'/gi; $channel =~ s/\"/\\\"/gi; $stmtA = "INSERT INTO live_channels (channel,server_ip,update_time) values('$channel','$server_ip','$SQLdate');"; if ($DB) {print " |INSERT live_channels: $stmtA|\n";} $affected_rows = $dbhA->do($stmtA); $k++; } # update parked_channels table $event_string='PARK'; $t->print("Action: Command\nCommand: show parkedcalls\n\n"); @list_parked = $t->waitfor('/--END COMMAND--/'); # waitfor, but only first match $event_string=''; $channel_live = $t->eof(); if ($DB) {print " |LIST PARKED CHANNELS: $channel_live|$t->eof()|\n";} $j=0; $parked_processed=0; foreach(@list_parked) { $parked = $list_parked[$j]; if ($parked =~ /parked call/i) { $active_parked = $parked; $active_parked =~ s/ .*//gi; } if ( ($parked !~ /--END COMMAND--/) && ($j > 0) ) { if ($parked =~ /^(\d+ parked call|No parked call)/i) { $active_line = $parked; } else { $parked =~ s/^ //gi; $parked =~ s/ \d+\. //gi; $parked =~ s/ $//gi; if (length($parked) > 5) { $parked_processed[$parked_processed] = $parked; $parked_processed++; } } } $j++; } # update parked_channels table $stmtA = "TRUNCATE TABLE parked_channels;"; $affected_rows = $dbhA->do($stmtA); $k=0; while ($k < $parked_processed) { $parked = $parked_processed[$k]; $parked =~ s/\'/\\\'/gi; $parked =~ s/\"/\\\"/gi; $stmtA = "INSERT INTO parked_channels (channel,server_ip,update_time) values('$parked','$server_ip','$SQLdate');"; if ($DB) {print " |INSERT parked_channels: $stmtA|\n";} $affected_rows = $dbhA->do($stmtA); $k++; } # update live_inbound table if ($DB_VDADenabled > 0) { $event_string='INBOUND'; $t->print("Action: Command\nCommand: show channels concise\n\n"); @list_inbound = $t->waitfor('/--END COMMAND--/'); # waitfor, but only first match $event_string=''; $channel_live = $t->eof(); if ($DB) {print " |LIST INBOUND CHANNELS: $channel_live|$t->eof()|\n";} $j=0; $inbound_processed=0; foreach(@list_inbound) { $inbound = $list_inbound[$j]; if ( ($inbound !~ /--END COMMAND--/) && ($j > 0) ) { $inbound =~ s/\'/\\\'/gi; $inbound =~ s/\"/\\\"/gi; if (length($inbound) > 5) { $inbound_processed[$inbound_processed] = $inbound; $inbound_processed++; } } $j++; } # update live_inbound table $stmtA = "TRUNCATE TABLE live_inbound;"; $affected_rows = $dbhA->do($stmtA); $k=0; while ($k < $inbound_processed) { $inbound = $inbound_processed[$k]; $inbound =~ s/\'/\\\'/gi; $inbound =~ s/\"/\\\"/gi; $stmtA = "INSERT INTO live_inbound (channel,server_ip,update_time) values('$inbound','$server_ip','$SQLdate');"; if ($DB) {print " |INSERT live_inbound: $stmtA|\n";} $affected_rows = $dbhA->do($stmtA); $k++; } } # update live_sip table $event_string='SIP'; $t->print("Action: Command\nCommand: sip show channels\n\n"); @list_sip = $t->waitfor('/--END COMMAND--/'); # waitfor, but only first match $event_string=''; $channel_live = $t->eof(); if ($DB) {print " |LIST SIP CHANNELS: $channel_live|$t->eof()|\n";} $j=0; $sip_processed=0; foreach(@list_sip) { $sip = $list_sip[$j]; if ($sip =~ /Peer:/i) { $sip_processed[$sip_processed] = $sip; $sip_processed++; } $j++; } # update live_sip table $stmtA = "TRUNCATE TABLE live_sip;"; $affected_rows = $dbhA->do($stmtA); $k=0; while ($k < $sip_processed) { $sip = $sip_processed[$k]; $sip =~ s/\'/\\\'/gi; $sip =~ s/\"/\\\"/gi; $stmtA = "INSERT INTO live_sip (channel,server_ip,update_time) values('$sip','$server_ip','$SQLdate');"; if ($DB) {print " |INSERT live_sip: $stmtA|\n";} $affected_rows = $dbhA->do($stmtA); $k++; } # update live_iax table $event_string='IAX'; $t->print("Action: Command\nCommand: iax2 show channels\n\n"); @list_iax = $t->waitfor('/--END COMMAND--/'); # waitfor, but only first match $event_string=''; $channel_live = $t->eof(); if ($DB) {print " |LIST IAX CHANNELS: $channel_live|$t->eof()|\n";} $j=0; $iax_processed=0; foreach(@list_iax) { $iax = $list_iax[$j]; if ($iax =~ /Peer:/i) { $iax_processed[$iax_processed] = $iax; $iax_processed++; } $j++; } # update live_iax table $stmtA = "TRUNCATE TABLE live_iax;"; $affected_rows = $dbhA->do($stmtA); $k=0; while ($k < $iax_processed) { $iax = $iax_processed[$k]; $iax =~ s/\'/\\\'/gi; $iax =~ s/\"/\\\"/gi; $stmtA = "INSERT INTO live_iax (channel,server_ip,update_time) values('$iax','$server_ip','$SQLdate');"; if ($DB) {print " |INSERT live_iax: $stmtA|\n";} $affected_rows = $dbhA->do($stmtA); $k++; } # update live_zap table $event_string='ZAP'; $t->print("Action: Command\nCommand: zap show channels\n\n"); @list_zap = $t->waitfor('/--END COMMAND--/'); # waitfor, but only first match $event_string=''; $channel_live = $t->eof(); if ($DB) {print " |LIST ZAP CHANNELS: $channel_live|$t->eof()|\n";} $j=0; $zap_processed=0; foreach(@list_zap) { $zap = $list_zap[$j]; if ($zap =~ /Channel/i) { $zap_processed[$zap_processed] = $zap; $zap_processed++; } $j++; } # update live_zap table $stmtA = "TRUNCATE TABLE live_zap;"; $affected_rows = $dbhA->do($stmtA); $k=0; while ($k < $zap_processed) { $zap = $zap_processed[$k]; $zap =~ s/\'/\\\'/gi; $zap =~ s/\"/\\\"/gi; $stmtA = "INSERT INTO live_zap (channel,server_ip,update_time) values('$zap','$server_ip','$SQLdate');"; if ($DB) {print " |INSERT live_zap: $stmtA|\n";} $affected_rows = $dbhA->do($stmtA); $k++; } # update live_dahdi table $event_string='DAHDI'; $t->print("Action: Command\nCommand: dahdi show channels\n\n"); @list_dahdi = $t->waitfor('/--END COMMAND--/'); # waitfor, but only first match $event_string=''; $channel_live = $t->eof(); if ($DB) {print " |LIST DAHDI CHANNELS: $channel_live|$t->eof()|\n";} $j=0; $dahdi_processed=0; foreach(@list_dahdi) { $dahdi = $list_dahdi[$j]; if ($dahdi =~ /Channel/i) { $dahdi_processed[$dahdi_processed] = $dahdi; $dahdi_processed++; } $j++; } # update live_dahdi table $stmtA = "TRUNCATE TABLE live_dahdi;"; $affected_rows = $dbhA->do($stmtA); $k=0; while ($k < $dahdi_processed) { $dahdi = $dahdi_processed[$k]; $dahdi =~ s/\'/\\\'/gi; $dahdi =~ s/\"/\\\"/gi; $stmtA = "INSERT INTO live_dahdi (channel,server_ip,update_time) values('$dahdi','$server_ip','$SQLdate');"; if ($DB) {print " |INSERT live_dahdi: $stmtA|\n";} $affected_rows = $dbhA->do($stmtA); $k++; } # update vicidial_auto_calls table $event_string='VICIAUTO'; $t->print("Action: Command\nCommand: show dialplan\n\n"); @list_vicidial_auto = $t->waitfor('/--END COMMAND--/'); # waitfor, but only first match $event_string=''; $channel_live = $t->eof(); if ($DB) {print " |LIST VICIDIAL AUTO CALLS: $channel_live|$t->eof()|\n";} $j=0; $vicidial_auto_processed=0; foreach(@list_vicidial_auto) { $vicidial_auto = $list_vicidial_auto[$j]; if ($vicidial_auto =~ /Extension/i) { $vicidial_auto_processed[$vicidial_auto_processed] = $vicidial_auto; $vicidial_auto_processed++; } $j++; } # update vicidial_auto_calls table $stmtA = "TRUNCATE TABLE vicidial_auto_calls;"; $affected_rows = $dbhA->do($stmtA); $k=0; while ($k < $vicidial_auto_processed) { $vicidial_auto = $vicidial_auto_processed[$k]; $vicidial_auto =~ s/\'/\\\'/gi; $vicidial_auto =~ s/\"/\\\"/gi; $stmtA = "INSERT INTO vicidial_auto_calls (channel,server_ip,update_time) values('$vicidial_auto','$server_ip','$SQLdate');"; if ($DB) {print " |INSERT vicidial_auto_calls: $stmtA|\n";} $affected_rows = $dbhA->do($stmtA); $k++; } # update vicidial_manager table $event_string='VICIMANAGER'; $t->print("Action: Command\nCommand: show manager connected\n\n"); @list_vicidial_manager = $t->waitfor('/--END COMMAND--/'); # waitfor, but only first match $event_string=''; $channel_live = $t->eof(); if ($DB) {print " |LIST VICIDIAL MANAGER: $channel_live|$t->eof()|\n";} $j=0; $vicidial_manager_processed=0; foreach(@list_vicidial_manager) { $vicidial_manager = $list_vicidial_manager[$j]; if ($vicidial_manager =~ /Username/i) { $vicidial_manager_processed[$vicidial_manager_processed] = $vicidial_manager; $vicidial_manager_processed++; } $j++; } # update vicidial_manager table $stmtA = "TRUNCATE TABLE vicidial_manager;"; $affected_rows = $dbhA->do($stmtA); $k=0; while ($k < $vicidial_manager_processed) { $vicidial_manager = $vicidial_manager_processed[$k]; $vicidial_manager =~ s/\'/\\\'/gi; $vicidial_manager =~ s/\"/\\\"/gi; $stmtA = "INSERT INTO vicidial_manager (channel,server_ip,update_time) values('$vicidial_manager','$server_ip','$SQLdate');"; if ($DB) {print " |INSERT vicidial_manager: $stmtA|\n";} $affected_rows = $dbhA->do($stmtA); $k++; } # update vicidial_conferences table $event_string='VICICONFERENCES'; $t->print("Action: Command\nCommand: meetme list\n\n"); @list_vicidial_conferences = $t->waitfor('/--END COMMAND--/'); # waitfor, but only first match $event_string=''; $channel_live = $t->eof(); if ($DB) {print " |LIST VICIDIAL CONFERENCES: $channel_live|$t->eof()|\n";} $j=0; $vicidial_conferences_processed=0; foreach(@list_vicidial_conferences) { $vicidial_conferences = $list_vicidial_conferences[$j]; if ($vicidial_conferences =~ /Conf/i) { $vicidial_conferences_processed[$vicidial_conferences_processed] = $vicidial_conferences; $vicidial_conferences_processed++; } $j++; } # update vicidial_conferences table $stmtA = "TRUNCATE TABLE vicidial_conferences;"; $affected_rows = $dbhA->do($stmtA); $k=0; while ($k < $vicidial_conferences_processed) { $vicidial_conferences = $vicidial_conferences_processed[$k]; $vicidial_conferences =~ s/\'/\\\'/gi; $vicidial_conferences =~ s/\"/\\\"/gi; $stmtA = "INSERT INTO vicidial_conferences (channel,server_ip,update_time) values('$vicidial_conferences','$server_ip','$SQLdate');"; if ($DB) {print " |INSERT vicidial_conferences: $stmtA|\n";} $affected_rows = $dbhA->do($stmtA); $k++; } # update vicidial_live_agents table $event_string='VICILIVEAGENTS'; $t->print("Action: Command\nCommand: show agents\n\n"); @list_vicidial_live_agents = $t->waitfor('/--END COMMAND--/'); # waitfor, but only first match $event_string=''; $channel_live = $t->eof(); if ($DB) {print " |LIST VICIDIAL LIVE AGENTS: $channel_live|$t->eof()|\n";} $j=0; $vicidial_live_agents_processed=0; foreach(@list_vicidial_live_agents) { $vicidial_live_agents = $list_vicidial_live_agents[$j]; if ($vicidial_live_agents =~ /Agent/i) { $vicidial_live_agents_processed[$vicidial_live_agents_processed] = $vicidial_live_agents; $vicidial_live_agents_processed++; } $j++; } # update vicidial_live_agents table $stmtA = "TRUNCATE TABLE vicidial_live_agents;"; $affected_rows = $dbhA->do($stmtA); $k=0; while ($k < $vicidial_live_agents_processed) { $vicidial_live_agents = $vicidial_live_agents_processed[$k]; $vicidial_live_agents =~ s/\'/\\\'/gi; $vicidial_live_agents =~ s/\"/\\\"/gi; $stmtA = "INSERT INTO vicidial_live_agents (channel,server_ip,update_time) values('$vicidial_live_agents','$server_ip','$SQLdate');"; if ($DB) {print " |INSERT vicidial_live_agents: $stmtA|\n";} $affected_rows = $dbhA->do($stmtA); $k++; } # update vicidial_live_channels table $event_string='VICILIVECHANNELS'; $t->print("Action: Command\nCommand: show channels\n\n"); @list_vicidial_live_channels = $t->waitfor('/--END COMMAND--/'); # waitfor, but only first match $event_string=''; $channel_live = $t->eof(); if ($DB) {print " |LIST VICIDIAL LIVE CHANNELS: $channel_live|$t->eof()|\n";} $j=0; $vicidial_live_channels_processed=0; foreach(@list_vicidial_live_channels) { $vicidial_live_channels = $list_vicidial_live_channels[$j]; if ($vicidial_live_channels =~ /Channel/i) { $vicidial_live_channels_processed[$vicidial_live_channels_processed] = $vicidial_live_channels; $vicidial_live_channels_processed++; } $j++; } # update vicidial_live_channels table $stmtA = "TRUNCATE TABLE vicidial_live_channels;"; $affected_rows = $dbhA->do($stmtA); $k=0; while ($k < $vicidial_live_channels_processed) { $vicidial_live_channels = $vicidial_live_channels_processed[$k]; $vicidial_live_channels =~ s/\'/\\\'/gi; $vicidial_live_channels =~ s/\"/\\\"/gi; $stmtA = "INSERT INTO vicidial_live_channels (channel,server_ip,update_time) values('$vicidial_live_channels','$server_ip','$SQLdate');"; if ($DB) {print " |INSERT vicidial_live_channels: $stmtA|\n";} $affected_rows = $dbhA->do($stmtA); $k++; } # update vicidial_manager_log table $event_string='VICIMANAGERLOG'; $t->print("Action: Command\nCommand: show manager log\n\n"); @list_vicidial_manager_log = $t->waitfor('/--END COMMAND--/'); # waitfor, but only first match $event_string=''; $channel_live = $t->eof(); if ($DB) {print " |LIST VICIDIAL MANAGER LOG: $channel_live|$t->eof()|\n";} $j=0; $vicidial_manager_log_processed=0; foreach(@list_vicidial_manager_log) { $vicidial_manager_log = $list_vicidial_manager_log[$j]; if ($vicidial_manager_log =~ /Username/i) { $vicidial_manager_log_processed[$vicidial_manager_log_processed] = $vicidial_manager_log; $vicidial_manager_log_processed++; } $j++; } # update vicidial_manager_log table $stmtA = "TRUNCATE TABLE vicidial_manager_log;"; $affected_rows = $dbhA->do($stmtA); $k=0; while ($k < $vicidial_manager_log_processed) { $vicidial_manager_log = $vicidial_manager_log_processed[$k]; $vicidial_manager_log =~ s/\'/\\\'/gi; $vicidial_manager_log =~ s/\"/\\\"/gi; $stmtA = "INSERT INTO vicidial_manager_log (channel,server_ip,update_time) values('$vicidial_manager_log','$server_ip','$SQLdate');"; if ($DB) {print " |INSERT vicidial_manager_log: $stmtA|\n";} $affected_rows = $dbhA->do($stmtA); $k++; } # update vicidial_parked_channels table $event_string='VICIPARKEDCHANNELS'; $t->print("Action: Command\nCommand: show parkedcalls\n\n"); @list_vicidial_parked_channels = $t->waitfor('/--END COMMAND--/'); # waitfor, but only first match $event_string=''; $channel_live = $t->eof(); if ($DB) {print " |LIST VICIDIAL PARKED CHANNELS: $channel_live|$t->eof()|\n";} $j=0; $vicidial_parked_channels_processed=0; foreach(@list_vicidial_parked_channels) { $vicidial_parked_channels = $list_vicidial_parked_channels[$j]; if ($vicidial_parked_channels =~ /Channel/i) { $vicidial_parked_channels_processed[$vicidial_parked_channels_processed] = $vicidial_parked_channels; $vicidial_parked_channels_processed++; } $j++; } # update vicidial_parked_channels table $stmtA = "TRUNCATE TABLE vicidial_parked_channels;"; $affected_rows = $dbhA->do($stmtA); $k=0; while ($k < $vicidial_parked_channels_processed) { $vicidial_parked_channels = $vicidial_parked_channels_processed[$k]; $vicidial_parked_channels =~ s/\'/\\\'/gi; $vicidial_parked_channels =~ s/\"/\\\"/gi; $stmtA = "INSERT INTO vicidial_parked_channels (channel,server_ip,update_time) values('$vicidial_parked_channels','$server_ip','$SQLdate');"; if ($DB) {print " |INSERT vicidial_parked_channels: $stmtA|\n";} $affected_rows = $dbhA->do($stmtA); $k++; } # update vicidial_auto_dial table $event_string='VICIAUTODIAL'; $t->print("Action: Command\nCommand: show auto dial\n\n"); @list_vicidial_auto_dial = $t->waitfor('/--END COMMAND--/'); # waitfor, but only first match $event_string=''; $channel_live = $t->eof(); if ($DB) {print " |LIST VICIDIAL AUTO DIAL: $channel_live|$t->eof()|\n";} $j=0; $vicidial_auto_dial_processed=0; foreach(@list_vicidial_auto_dial) { $vicidial_auto_dial = $list_vicidial_auto_dial[$j]; if ($vicidial_auto_dial =~ /Extension/i) { $vicidial_auto_dial_processed[$vicidial_auto_dial_processed] = $vicidial_auto_dial; $vicidial_auto_dial_processed++; } $j++; } # update vicidial_auto_dial table $stmtA = "TRUNCATE TABLE vicidial_auto_dial;"; $affected_rows = $dbhA->do($stmtA); $k=0; while ($k < $vicidial_auto_dial_processed) { $vicidial_auto_dial = $vicidial_auto_dial_processed[$k]; $vicidial_auto_dial =~ s/\'/\\\'/gi; $vicidial_auto_dial =~ s/\"/\\\"/gi; $stmtA = "INSERT INTO vicidial_auto_dial (channel,server_ip,update_time) values('$vicidial_auto_dial','$server_ip','$SQLdate');"; if ($DB) {print " |INSERT vicidial_auto_dial: $stmtA|\n";} $affected_rows = $dbhA->do($stmtA); $k++; } # update vicidial_live_inbound_agents table $event_string='VICILIVEINBOUNDAGENTS'; $t->print("Action: Command\nCommand: show agents\n\n"); @list_vicidial_live_inbound_agents = $t->waitfor('/--END COMMAND--/'); # waitfor, but only first match $event_string=''; $channel_live = $t->eof(); if ($DB) {print " |LIST VICIDIAL LIVE INBOUND AGENTS: $channel_live|$t->eof()|\n";} $j=0; $vicidial_live_inbound_agents_processed=0; foreach(@list_vicidial_live_inbound_agents) { $vicidial_live_inbound_agents = $list_vicidial_live_inbound_agents[$j]; if ($vicidial_live_inbound_agents =~ /Agent/i) { $vicidial_live_inbound_agents_processed[$vicidial_live_inbound_agents_processed] = $vicidial_live_inbound_agents; $vicidial_live_inbound_agents_processed++; } $j++; } # update vicidial_live_inbound_agents table $stmtA = "TRUNCATE TABLE vicidial_live_inbound_agents;"; $affected_rows = $dbhA->do($stmtA); $k=0; while ($k < $vicidial_live_inbound_agents_processed) { $vicidial_live_inbound_agents = $vicidial_live_inbound_agents_processed[$k]; $vicidial_live_inbound_agents =~ s/\'/\\\'/gi; $vicidial_live_inbound_agents =~ s/\"/\\\"/gi; $stmtA = "INSERT INTO vicidial_live_inbound_agents (channel,server_ip,update_time) values('$vicidial_live_inbound_agents','$server_ip','$SQLdate');"; if ($DB) {print " |INSERT vicidial_live_inbound_agents: $stmtA|\n";} $affected_rows = $dbhA->do($stmtA); $k++; } # update vicidial_live_inbound_channels table $event_string='VICILIVEINBOUNDCHANNELS'; $t->print("Action: Command\nCommand: show channels\n\n"); @list_vicidial_live_inbound_channels = $t->waitfor('/--END COMMAND--/'); # waitfor, but only first match $event_string=''; $channel_live = $t->eof(); if ($DB) {print " |LIST VICIDIAL LIVE INBOUND CHANNELS: $channel_live|$t->eof()|\n";} $j=0; $vicidial_live_inbound_channels_processed=0; foreach(@list_vicidial_live_inbound_channels) { $vicidial_live_inbound_channels = $list_vicidial_live_inbound_channels[$j]; if ($vicidial_live_inbound_channels =~ /Channel/i) { $vicidial_live_inbound_channels_processed[$vicidial_live_inbound_channels_processed] = $vicidial_live_inbound_channels; $vicidial_live_inbound_channels_processed++; } $j++; } # update vicidial_live_inbound_channels table $stmtA = "TRUNCATE TABLE vicidial_live_inbound_channels;"; $affected_rows = $dbhA->do($stmtA); $k=0; while ($k < $vicidial_live_inbound_channels_processed) { $vicidial_live_inbound_channels = $vicidial_live_inbound_channels_processed[$k]; $vicidial_live_inbound_channels =~ s/\'/\\\'/gi; $vicidial_live_inbound_channels =~ s/\"/\\\"/gi; $stmtA = "INSERT INTO vicidial_live_inbound_channels (channel,server_ip,update_time) values('$vicidial_live_inbound_channels','$server_ip','$SQLdate');"; if ($DB) {print " |INSERT vicidial_live_inbound_channels: $stmtA|\n";} $affected_rows = $dbhA->do($stmtA); $k++; } # update vicidial_auto_calls_inbound table $event_string='VICIAUTOCALLSINBOUND'; $t->print("Action: Command\nCommand: show auto dial inbound\n\n"); @list_vicidial_auto_calls_inbound = $t->waitfor('/--END COMMAND--/'); # waitfor, but only first match $event_string=''; $channel_live = $t->eof(); if ($DB) {print " |LIST VICIDIAL AUTO CALLS INBOUND: $channel_live|$t->eof()|\n";} $j=0; $vicidial_auto_calls_inbound_processed=0; foreach(@list_vicidial_auto_calls_inbound) { $vicidial_auto_calls_inbound = $list_vicidial_auto_calls_inbound[$j]; if ($vicidial_auto_calls_inbound =~ /Extension/i) { $vicidial_auto_calls_inbound_processed[$vicidial_auto_calls_inbound_processed] = $vicidial_auto_calls_inbound; $vicidial_auto_calls_inbound_processed++; } $j++; } # update vicidial_auto_calls_inbound table $stmtA = "TRUNCATE TABLE vicidial_auto_calls_inbound;"; $affected_rows = $dbhA->do($stmtA); $k=0; while ($k < $vicidial_auto_calls_inbound_processed) { $vicidial_auto_calls_inbound = $vicidial_auto_calls_inbound_processed[$k]; $vicidial_auto_calls_inbound =~ s/\'/\\\'/gi; $vicidial_auto_calls_inbound =~ s/\"/\\\"/gi; $stmtA = "INSERT INTO vicidial_auto_calls_inbound (channel,server_ip,update_time) values('$vicidial_auto_calls_inbound','$server_ip','$SQLdate');"; if ($DB) {print " |INSERT vicidial_auto_calls_inbound: $stmtA|\n";} $affected_rows = $dbhA->do($stmtA); $k++; } # update vicidial_live_inbound_agents_channels table $event_string='VICILIVEINBOUNDAGENTSCHANNELS'; $t->print("Action: Command\nCommand: show agents channels\n\n"); @list_vicidial_live_inbound_agents_channels = $t->waitfor('/--END COMMAND--/'); # waitfor, but only first match $event_string=''; $channel_live = $t->eof(); if ($DB) {print " |LIST VICIDIAL LIVE INBOUND AGENTS CHANNELS: $channel_live|$t->eof()|\n";} $j=0; $vicidial_live_inbound_agents_channels_processed=0; foreach(@list_vicidial_live_inbound_agents_channels) { $vicidial_live_inbound_agents_channels = $list_vicidial_live_inbound_agents_channels[$j]; if ($vicidial_live_inbound_agents_channels =~ /Channel/i) { $vicidial_live_inbound_agents_channels_processed[$vicidial_live_inbound_agents_channels_processed] = $vicidial_live_inbound_agents_channels; $vicidial_live_inbound_agents_channels_processed++; } $j++; } # update vicidial_live_inbound_agents_channels table $stmtA = "TRUNCATE TABLE vicidial_live_inbound_agents_channels;"; $affected_rows = $dbhA->do($stmtA); $k=0; while ($k < $vicidial_live_inbound_agents_channels_processed) { $vicidial_live_inbound_agents_channels = $vicidial_live_inbound_agents_channels_processed[$k]; $vicidial_live_inbound_agents_channels =~ s/\'/\\\'/gi; $vicidial_live_inbound_agents_channels =~ s/\"/\\\"/gi; $stmtA = "INSERT INTO vicidial_live_inbound_agents_channels (channel,server_ip,update_time) values('$vicidial_live_inbound_agents_channels','$server_ip','$SQLdate');"; if ($DB) {print " |INSERT vicidial_live_inbound_agents_channels: $stmtA|\n";} $affected_rows = $dbhA->do($stmtA); $k++; } # update vicidial_auto_calls_inbound_agents table $event_string='VICIAUTOCALLSINBOUNDAGENTS'; $t->print("Action: Command\nCommand: show auto dial inbound agents\n\n"); @list_vicidial_auto_calls_inbound_agents = $t->waitfor('/--END COMMAND--/'); # waitfor, but only first match $event_string=''; $channel_live = $t->eof(); if ($DB) {print " |LIST VICIDIAL AUTO CALLS INBOUND AGENTS: $channel_live|$t->eof()|\n";} $j=0; $vicidial_auto_calls_inbound_agents_processed=0; foreach(@list_vicidial_auto_calls_inbound_agents) { $vicidial_auto_calls_inbound_agents = $list_vicidial_auto_calls_inbound_agents[$j]; if ($vicidial_auto_calls_inbound_agents =~ /Agent/i) { $vicidial_auto_calls_inbound_agents_processed[$vicidial_auto_calls_inbound_agents_processed] = $vicidial_auto_calls_inbound_agents; $vicidial_auto_calls_inbound_agents_processed++; } $j++; } # update vicidial_auto_calls_inbound_agents table $stmtA = "TRUNCATE TABLE vicidial_auto_calls_inbound_agents;"; $affected_rows = $dbhA->do($stmtA); $k=0; while ($k < $vicidial_auto_calls_inbound_agents_processed) { $vicidial_auto_calls_inbound_agents = $vicidial_auto_calls_inbound_agents_processed[$k]; $vicidial_auto_calls_inbound_agents =~ s/\'/\\\'/gi; $vicidial_auto_calls_inbound_agents =~ s/\"/\\\"/gi; $stmtA = "INSERT INTO vicidial_auto_calls_inbound_agents (channel,server_ip,update_time) values('$vicidial_auto_calls_inbound_agents','$server_ip','$SQLdate');"; if ($DB) {print " |INSERT vicidial_auto_calls_inbound_agents: $stmtA|\n";} $affected_rows = $dbhA->do($stmtA); $k++; } # update vicidial_auto_calls_inbound_channels table $event_string='VICIAUTOCALLSINBOUNDCHANNELS'; $t->print("Action: Command\nCommand: show auto dial inbound channels\n\n"); @list_vicidial_auto_calls_inbound_channels = $t->waitfor('/--END COMMAND--/'); # waitfor, but only first match $event_string=''; $channel_live = $t->eof(); if ($DB) {print " |LIST VICIDIAL AUTO CALLS INBOUND CHANNELS: $channel_live|$t->eof()|\n";} $j=0; $vicidial_auto_calls_inbound_channels_processed=0; foreach(@list_vicidial_auto_calls_inbound_channels) { $vicidial_auto_calls_inbound_channels = $list_vicidial_auto_calls_inbound_channels[$j]; if ($vicidial_auto_calls_inbound_channels =~ /Channel/i) { $vicidial_auto_calls_inbound_channels_processed[$vicidial_auto_calls_inbound_channels_processed] = $vicidial_auto_calls_inbound_channels; $vicidial_auto_calls_inbound_channels_processed++; } $j++; } # update vicidial_auto_calls_inbound_channels table $stmtA = "TRUNCATE TABLE vicidial_auto_calls_inbound_channels;"; $affected_rows = $dbhA->do($stmtA); $k=0; while ($k < $vicidial_auto_calls_inbound_channels_processed) { $vicidial_auto_calls_inbound_channels = $vicidial_auto_calls_inbound_channels_processed[$k]; $vicidial_auto_calls_inbound_channels =~ s/\'/\\\'/gi; $vicidial_auto_calls_inbound_channels =~ s/\"/\\\"/gi; $stmtA = "INSERT INTO vicidial_auto_calls_inbound_channels (channel,server_ip,update_time) values('$vicidial_auto_calls_inbound_channels','$server_ip','$SQLdate');"; if ($DB) {print " |INSERT vicidial_auto_calls_inbound_channels: $stmtA|\n";} $affected_rows = $dbhA->do($stmtA); $k++; } $channel_live=0; # update loop exit condition } # end while ($channel_live) $event_string='UPDATE'; $SQL_log = "$SQLdate|$event_string|"; $SQL_log =~ s/\|$//gi; $secY = time(); $secZ = ($secY - $secX); if ($DB) {print "DONE... Exiting at $secZ seconds\n";} # waiting for a period of time if ($endless_loop > 1) {$endless_loop--;} usleep(1*$DB_max_ast_update_nanoseconds); } # end of while ($endless_loop) sub get_server_load { $lavg = '/proc/loadavg'; open( FH , "<$lavg" ); @lines = <FH>; close( FH ); $server_load = $lines[0]; $server_load =~ s/ .*//gi; $server_load =~ s/\D//gi; return $server_load; } sub get_mem_usage { $meminfo = '/proc/meminfo'; open( FH , "<$meminfo" ); @lines = <FH>; close( FH ); $mem_total = $lines[0]; $mem_total =~ s/MemTotal: *//g; $mem_free = $lines[1]; $mem_free =~ s/MemFree: *//g; $mem_used = $mem_total - $mem_free; $mem_used = floor( $mem_used / 1024 ); $mem_total = floor( $mem_total / 1024 ); $mem_free = floor( $mem_free / 1023 ); return ( $mem_total, $mem_used, $mem_free ); } sub get_disk_space { @serverDISK = `$dfbin -B 1048576 -x nfs -x cifs -x sshfs -x ftpfs`; $ct=0; $ct_PCT=0; $disk_usage = ''; foreach(@serverDISK) { if ($serverDISK[$ct] =~ /(\d+\%)/) { $ct_PCT++; $usage = $1; $usage =~ s/\%//gi; $disk_usage .= "$ct_PCT $usage|"; } $ct++; } return $disk_usage; } sub get_num_processes { $num_processes = 0; opendir( DH, '/proc'); while ( readdir( DH ) ) { if ( looks_like_number( $_ ) ) { $num_processes++; } } closedir( DH ); return ($num_processes); }
Editor is loading...
Leave a Comment