Evening all,
I'm trying to get a script then will run on a CRON job at some point. it works as you see it, however when more than one server is down it sends a new email for every server, how would i go about getting it to grab all down servers and sending in just 1 email?
Thanks guys! (code below).
<? $hosts = array( array ( "hostdescription" => "B1", "hostaddress" => "IP HIDDEN" ), array ( "hostdescription" => "B2", "hostaddress" => "IP HIDDEN" ), array ( "hostdescription" => "BB1","hostaddress" => "IP HIDDEN" ), array ( "hostdescription" => "BB2", "hostaddress" => "IP HIDDEN" ), array ( "hostdescription" => "BB3", "hostaddress" => "IP HIDDEN" ), array ( "hostdescription" => "BBB1", "hostaddress" => "IP HIDDEN" ), array ( "hostdescription" => "BBB2", "hostaddress" => "IP HIDDEN" ), array ( "hostdescription" => "BBBB1", "hostaddress" => "IP HIDDEN" ), array ( "hostdescription" => "BBBB2", "hostaddress" => "IP HIDDEN" ), array ( "hostdescription" => "BBBB3", "hostaddress" => "IP HIDDEN" ) ); $pingcount = 1; foreach ($hosts as $host){ $hostdescription = $host["hostdescription"]; $hostaddress = $host["hostaddress"]; exec("ping -c $pingcount -w $pingcount $hostaddress", $pingoutput, $Spingstatuscode); if($Spingstatuscode === 0){ echo("$hostdescription ($hostaddress) is Up <BR>"); }else{ echo("$hostdescription ($hostaddress) is Down <BR>"); $to = "EMAIL HIDDEN"; $subject = "SERVER DOWN: $hostdescription"; $message = "ATTENTION: $hostdescription is currently down please investigate"; $headers .= "From: EMAIL HIDDEN\r\n"; $mail_sent = @mail( $to, $subject, $message, $headers ); } } ?>