<?php
//Page Variables
$online='<td style="background-color:#00FF00; padding:5px;">Operational</td>';
$offline='<td style="background-color:#FF0000; padding:5px;">Failed</td>';
//Functions
function servercheck($server,$port){
//Check that the port value is not empty
if(empty($port)){
$port=80;
}
//Check that the server value is not empty
if(empty($server)){
$server='domain.com';
}
//Connection
$fp=@fsockopen($server, $port, $errno, $errstr, 1);
//Check if connection is present
if($fp){
//Return Alive
return 1;
} else{
//Return Dead
return 0;
}
//Close Connection
fclose($fp);
}
//Ports and Services to check
$services=array(
'Website Access' => array('domain.com' => 80),
'Another Service' => array('domain.com' => 443),
'Another Service' => array('domain.com' => 21),
);
?>
<div class="infobox">
<?php
//Check All Services
foreach($services as $name => $server){
?>
<tr>
<td><?php echo $name; ?></td>
<?php
foreach($server as $host => $port){
if(servercheck($host,$port)){ echo $online; }else{ echo $offline; }
}
?>
</tr>
<?php
}
?>
</div>
<div class="overallmesssage">
<h3>
<!--Need this bit to show green and a message if all servers online if not show orange for not all of them and red for none of them-->
</div>
I would like to add an overall message which changes depending on the servers being online. Similar to https://demo.cachethq.io/ which has an overall green div telling the visitor that everything is up and running but if 1 of the servers go down it changes to orange and if all the servers go down, it changes to red.