Added AST_timecheck.pl script to check for Asterisk update sync issues. Also added red indicator on Reports page servers table if server falls out of sync.
git-svn-id: svn://192.168.202.10@1977 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
@@ -272,6 +272,10 @@ OTHER CHANGES:
|
||||
the amount of time the person called will have to respond after the
|
||||
survey message is played.
|
||||
|
||||
46. Added AST_timecheck.pl script to check for Asterisk update sync issues. Also
|
||||
added red indicator on Reports page servers table if server falls out of
|
||||
sync.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,259 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# AST_timecheck.pl version: 2.6
|
||||
#
|
||||
# This script is designed to send an email when an asterisk server is out of sync
|
||||
#
|
||||
# /usr/share/astguiclient/AST_VDsales_export.pl --campaign=GOODB-GROUP1-GROUP3-GROUP4-SPECIALS-DNC_BEDS --output-format=fixed-as400 --sale-statuses=SALE --debug --filename=BEDSsaleMMDD.txt --date=yesterday --email-list=test@gmail.com --email-sender=test@test.com
|
||||
#
|
||||
# Copyright (C) 2013 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
|
||||
#
|
||||
# CHANGES
|
||||
# 130503-1515 - First version
|
||||
#
|
||||
|
||||
$txt = '.txt';
|
||||
$US = '_';
|
||||
$MT[0] = '';
|
||||
$Q=0;
|
||||
$DB=0;
|
||||
|
||||
$secX = time();
|
||||
$time = $secX;
|
||||
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
|
||||
$year = ($year + 1900);
|
||||
$mon++;
|
||||
if ($mon < 10) {$mon = "0$mon";}
|
||||
if ($mday < 10) {$mday = "0$mday";}
|
||||
if ($hour < 10) {$hour = "0$hour";}
|
||||
if ($min < 10) {$min = "0$min";}
|
||||
if ($sec < 10) {$sec = "0$sec";}
|
||||
$timestamp = "$year-$mon-$mday $hour:$min:$sec";
|
||||
$filedate = "$year$mon$mday";
|
||||
$ABIfiledate = "$mon-$mday-$year$us$hour$min$sec";
|
||||
$shipdate = "$year-$mon-$mday";
|
||||
$start_date = "$year$mon$mday";
|
||||
$datestamp = "$year/$mon/$mday $hour:$min";
|
||||
|
||||
|
||||
### 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";
|
||||
print " [--seconds=XXX] = number of seconds considered out of sync. Default is 10\n";
|
||||
print " [--conffile=/path/from/root] = define configuration file path from root at runtime\n";
|
||||
print " [--email-list=test@test.com:test2@test.com] = send email results to these addresses\n";
|
||||
print " [--email-sender=vicidial@localhost] = sender for the email results\n";
|
||||
print " [--quiet] = quiet\n";
|
||||
print " [--debug] = debugging messages\n";
|
||||
print " [--debugX] = Super debugging messages\n";
|
||||
print "\n";
|
||||
|
||||
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($args =~ /--debug/i)
|
||||
{
|
||||
$DB=1;
|
||||
print "\n----- DEBUG MODE -----\n\n";
|
||||
}
|
||||
if ($args =~ /--debugX/i)
|
||||
{
|
||||
$DBX=1;
|
||||
print "\n----- SUPER DEBUG MODE -----\n\n";
|
||||
}
|
||||
if ($args =~ /-quiet/i)
|
||||
{
|
||||
$q=1; $Q=1;
|
||||
}
|
||||
if ($args =~ /--seconds=/i)
|
||||
{
|
||||
@data_in = split(/--seconds=/,$args);
|
||||
$seconds = $data_in[1];
|
||||
$seconds =~ s/ .*//gi;
|
||||
if (!$Q) {print "\n----- SECONDS: $seconds -----\n\n";}
|
||||
}
|
||||
else
|
||||
{$seconds = 10;}
|
||||
|
||||
if ($args =~ /--email-list=/i)
|
||||
{
|
||||
@data_in = split(/--email-list=/,$args);
|
||||
$email_list = $data_in[1];
|
||||
$email_list =~ s/ .*//gi;
|
||||
$email_list =~ s/:/,/gi;
|
||||
if (!$Q) {print "\n----- EMAIL NOTIFICATION: $email_list -----\n\n";}
|
||||
}
|
||||
else
|
||||
{$email_list = '';}
|
||||
|
||||
if ($args =~ /--email-sender=/i)
|
||||
{
|
||||
@data_in = split(/--email-sender=/,$args);
|
||||
$email_sender = $data_in[1];
|
||||
$email_sender =~ s/ .*//gi;
|
||||
$email_sender =~ s/:/,/gi;
|
||||
if (!$Q) {print "\n----- EMAIL NOTIFICATION SENDER: $email_sender -----\n\n";}
|
||||
}
|
||||
else
|
||||
{$email_sender = 'vicidial@localhost';}
|
||||
|
||||
if ($args =~ /--conffile=/i) # CLI defined conffile path
|
||||
{
|
||||
@CLIconffileARY = split(/--conffile=/,$args);
|
||||
@CLIconffileARX = split(/ /,$CLIconffileARY[1]);
|
||||
if (length($CLIconffileARX[0])>2)
|
||||
{
|
||||
$PATHconf = $CLIconffileARX[0];
|
||||
$PATHconf =~ s/\/$| |\r|\n|\t//gi;
|
||||
$CLIconffile=1;
|
||||
if (!$Q) {print " CLI defined conffile path: $PATHconf\n";}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "no command line options set, nothing is going to happen.\n";
|
||||
}
|
||||
### end parsing run-time options ###
|
||||
|
||||
# default path to astguiclient configuration file:
|
||||
if (length($PATHconf) < 5)
|
||||
{$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_port/) && ($CLIDB_port < 1) )
|
||||
{$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^VARREPORT_host/) && ($CLIREPORT_host < 1) )
|
||||
{$VARREPORT_host = $line; $VARREPORT_host =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^VARREPORT_user/) && ($CLIREPORT_user < 1) )
|
||||
{$VARREPORT_user = $line; $VARREPORT_user =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^VARREPORT_pass/) && ($CLIREPORT_pass < 1) )
|
||||
{$VARREPORT_pass = $line; $VARREPORT_pass =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^VARREPORT_port/) && ($CLIREPORT_port < 1) )
|
||||
{$VARREPORT_port = $line; $VARREPORT_port =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^VARREPORT_dir/) && ($CLIREPORT_dir < 1) )
|
||||
{$VARREPORT_dir = $line; $VARREPORT_dir =~ s/.*=//gi;}
|
||||
$i++;
|
||||
}
|
||||
|
||||
# Customized Variables
|
||||
$server_ip = $VARserver_ip; # Asterisk server IP
|
||||
|
||||
|
||||
|
||||
$web_u_time = time();
|
||||
$servers=0;
|
||||
|
||||
if ($DBX) {print "Start time: $timestamp($web_u_time) TIME SYNC SECONDS: $seconds\n";}
|
||||
|
||||
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;
|
||||
|
||||
$stmtA = "SELECT su.server_ip,last_update,UNIX_TIMESTAMP(last_update),server_description FROM server_updater su,servers s where s.server_ip=su.server_ip;";
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
if ($DBX) {print " $sthArows|$stmtA|\n";}
|
||||
$i=0;
|
||||
while ($sthArows > $i)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$server_ip = $aryA[0];
|
||||
$s_time = $aryA[1];
|
||||
$u_time = ($aryA[2] + $seconds);
|
||||
$server_name = $aryA[3];
|
||||
if ($DBX) {print "Server time: $server_ip($server_name) Last time: $s_time($u_time|$aryA[2])\n";}
|
||||
|
||||
if ($web_u_time > $u_time)
|
||||
{
|
||||
if ($DBX) {print "Time sync issue - SERVER: $server_ip($server_name)\n LAST TIME: $s_time($u_time)\n TIME NOW: $timestamp($web_u_time)\n\n";}
|
||||
$Ealert .= "SERVER: $server_ip($server_name)\n LAST TIME: $s_time($u_time)\n TIME NOW: $timestamp($web_u_time)\n\n";
|
||||
$servers++;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
|
||||
|
||||
###### EMAIL SECTION
|
||||
|
||||
if ( (length($Ealert)>5) && (length($email_list) > 3) )
|
||||
{
|
||||
if (!$Q) {print "Sending email: $email_list\n ";}
|
||||
|
||||
use MIME::QuotedPrint;
|
||||
use MIME::Base64;
|
||||
use Mail::Sendmail;
|
||||
|
||||
$mailsubject = "Time sync issue: $VARDB_database $timestamp";
|
||||
|
||||
%mail = ( To => "$email_list",
|
||||
From => "$email_sender",
|
||||
Subject => "$mailsubject",
|
||||
);
|
||||
$boundary = "====" . time() . "====";
|
||||
$mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
|
||||
|
||||
$message = encode_qp( "Time sync issue: $VARDB_database\n Servers: $servers\n\n$Ealert\n\n" );
|
||||
|
||||
$boundary = '--'.$boundary;
|
||||
$mail{body} .= "$boundary\n";
|
||||
$mail{body} .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
|
||||
$mail{body} .= "Content-Transfer-Encoding: quoted-printable\n\n";
|
||||
$mail{body} .= "$message\n";
|
||||
$mail{body} .= "$boundary";
|
||||
$mail{body} .= "--\n";
|
||||
|
||||
sendmail(%mail) or die $mail::Sendmail::error;
|
||||
if (!$Q)
|
||||
{
|
||||
print "ok. log says:\n", $mail::sendmail::log; ### print mail log for status
|
||||
}
|
||||
}
|
||||
|
||||
exit;
|
||||
+21
-14
@@ -3243,12 +3243,13 @@ else
|
||||
# 130414-1924 - Added report logging and display
|
||||
# 130424-1601 - Added survey_wait_sec campaign survey option
|
||||
# 130425-0700 - Added DROP option for survey_no_response_action to go to campaign drop method
|
||||
# 130503-1509 - Added red color to server table on reports page if asterisk out of sync
|
||||
#
|
||||
|
||||
# make sure you have added a user to the vicidial_users MySQL table with at least user_level 8 to access this page the first time
|
||||
|
||||
$admin_version = '2.6-399a';
|
||||
$build = '130425-0700';
|
||||
$admin_version = '2.6-400a';
|
||||
$build = '130503-1509';
|
||||
|
||||
$STARTtime = date("U");
|
||||
$SQLdate = date("Y-m-d H:i:s");
|
||||
@@ -35545,6 +35546,7 @@ if ($ADD==999999)
|
||||
}
|
||||
|
||||
$o=0;
|
||||
$web_u_time = date('U');
|
||||
while ($servers_to_print > $o)
|
||||
{
|
||||
$cpu = (100 - $cpu_idle_percent[$o]);
|
||||
@@ -35563,7 +35565,23 @@ if ($ADD==999999)
|
||||
$k++;
|
||||
}
|
||||
$disk = "$disk%";
|
||||
echo "<TR>\n";
|
||||
$s_time=' ';
|
||||
$s_ver=' ';
|
||||
$u_time=$web_u_time;
|
||||
$stmt="SELECT last_update,UNIX_TIMESTAMP(last_update) from server_updater where server_ip='$server_ip[$o]';";
|
||||
$rslt=mysql_query($stmt, $link);
|
||||
if ($DB) {echo "$stmt\n";}
|
||||
$servertime_to_print = mysql_num_rows($rslt);
|
||||
if ($servertime_to_print)
|
||||
{
|
||||
$row=mysql_fetch_row($rslt);
|
||||
$s_time = $row[0];
|
||||
$u_time = ($row[1] + 10);
|
||||
}
|
||||
$server_bgcolor='';
|
||||
if ($web_u_time > $u_time)
|
||||
{$server_bgcolor=' bgcolor=red';}
|
||||
echo "<TR$server_bgcolor>\n";
|
||||
echo "<TD><a href=\"$PHP_SELF?ADD=311111111111&server_id=$server_id[$o]\">$server_id[$o]</a></TD>\n";
|
||||
echo "<TD>$server_description[$o]</TD>\n";
|
||||
echo "<TD>$server_ip[$o]</TD>\n";
|
||||
@@ -35573,17 +35591,6 @@ if ($ADD==999999)
|
||||
echo "<TD ALIGN=RIGHT>$disk</TD>\n";
|
||||
if ($stage == 'TIME')
|
||||
{
|
||||
$s_time=' ';
|
||||
$s_ver=' ';
|
||||
$stmt="SELECT last_update from server_updater where server_ip='$server_ip[$o]';";
|
||||
$rslt=mysql_query($stmt, $link);
|
||||
if ($DB) {echo "$stmt\n";}
|
||||
$servertime_to_print = mysql_num_rows($rslt);
|
||||
if ($servertime_to_print)
|
||||
{
|
||||
$row=mysql_fetch_row($rslt);
|
||||
$s_time = $row[0];
|
||||
}
|
||||
$stmt="SELECT svn_revision from servers where server_ip='$server_ip[$o]';";
|
||||
$rslt=mysql_query($stmt, $link);
|
||||
if ($DB) {echo "$stmt\n";}
|
||||
|
||||
Reference in New Issue
Block a user