How to monitor the health of the MailScanner architecture

Gordon Colyn gordon at itnt.co.za
Mon Jul 9 21:11:57 IST 2007


Skipped content of type multipart/alternative-------------- next part --------------
#!/usr/bin/php -q 
<? 
//Name: queuecheck.php 
//Purpose: Notify email recipient if queue exceeds threshold. 
//chmod 750 /etc/MailScanner/queuecheck
// ##################Configurable Variables################## 
//This is the Username/Pass Combo for the mailwatch database 
$myUSER = "root"; 
$myPASS = ""; 
//The Server and DB name for the mailwatch database. 
$mySERVER = "sentialsql.itnt.co.za"; 
$myDB = "mailscanner"; 
//Silent is just a troubleshooting variable for DB connectivity that i have in all my scripts. 
//leave it be and you will get a 'quiet' page. 
$silent = 1; 
//now the fun stuff. the limits are self explanitory 
//if it exceeds these numbers, the queue triggers a message 
$inlimit = 1000; 
$outlimit = 800; 
$outlimit2 = 200; 
$outlimit3 = 400; 
$outlimit4 = 700; 
$outlimit5 = 1000; 
//This is the end user who gets the email about the queue reaching its 
//maximum size. make this a distro email if you have more then one email address 
$mailto = 'support at itnt.co.za'; 
// #################End of Config Variables################## 

//Build Database Connection 
if(isset($silent)){ 
//Do no say anything, keep headers clean 
}else{ 
echo "<br><font color='000066' size=1>Verifying Stateful Database Connection..."; 
} 

$link = mysql_connect($mySERVER, $myUSER, $myPASS) 
or die("<font color='red'>Database Connection 
Check FAILED</font>: " . mysql_error()); 
if(isset($silent)){ 
//Do not say anything, keep headers clean 
}else{ 
echo "<font color='green'>OK</font>"; 
echo "<br><font color='000066' size=1>Verifying Database Integrity..."; 
} 
mysql_select_db($myDB) or die("<font color='red'>Database Integrity Check FAILED</font>: " . mysql_error()); 
if(isset($silent)){ 
//Do not say anything, keep headers clean 
}else{ 
echo "<font color='green'>OK</font>"; 
} 
//DATABASE CONNECTION BUILT 




$inq = mysql_result(mysql_query("SELECT COUNT(*) FROM inq"),0); 
$outq = mysql_result(mysql_query("SELECT COUNT(*) FROM outq"),0); 
#$outq2 = mysql_result(mysql_query("SELECT COUNT(*) FROM outq2"),0); 
#$outq3 = mysql_result(mysql_query("SELECT COUNT(*) FROM outq3"),0); 
#$outq4 = mysql_result(mysql_query("SELECT COUNT(*) FROM outq4"),0); 
#$outq5 = mysql_result(mysql_query("SELECT COUNT(*) FROM outq5"),0); 


//echo "<br>Incoming: " . $inq . "<br>"; 
//echo "Outgoing: " . $outq . "<br>"; 
$mailme = 0; 
$mailsubject = "Relay MailQ Alert: "; 
if($inq > $inlimit){ 
$mailme = 1; 
$mailsubject = $mailsubject . "Inbound Queue"; 
} 
$outerror=0; 
if($outq > $outlimit){ 
$outerror=1; 
} 
if($outq2 > $outlimit2){ 
$outerror=1; 
} 
if($outq3 > $outlimit3){ 
$outerror=1; 
} 
if($outq4 > $outlimit4){ 
$outerror=1; 
} 
if($outq4 > $outlimit4){ 
$outerror=1; 
} 
if($outq5 > $outlimit5){ 
$outerror=1; 
} 


if($outerror==1){ 
if($mailme == 1){ 
$mailsubject = $mailsubject . " & "; 
} 
$mailme = 1; 
$mailsubject = $mailsubject . "OutBound Queue"; 
} 

if($mailme == 1){ 
//send report 
//echo "<br>Report<br>"; 
$mailsubject = $mailsubject . " Limits Exceeded"; 
$mailbody = "Status \r\nInbound: " . $inq . "\r\nOutbound: " . $outq . /*"\r\nOutbound 2: " . $outq2 . " \r\nOutbound 3: " . $outq3 . " \r\nOutbound 4: " . $outq4 . "\r\nOutbound 5: " . $outq5 . */"\r\n\r\n This report was generated by an automated script, please do not reply to this address \r\n"; 
//echo "<br>Subject: " . $mailsubject . "<br>"; 
//echo "<br>Body: " . $mailbody . "<br>"; 
mail($mailto,$mailsubject,$mailbody); 
}else{ 
//no report 
//echo "<br>no report<br>"; 
} 


?> 



More information about the MailScanner mailing list