【发布时间】:2017-03-15 20:25:14
【问题描述】:
<?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>
我想添加一个整体消息,该消息会根据在线的服务器而变化。类似于https://demo.cachethq.io/,它有一个整体的绿色 div,告诉访问者一切都已启动并正在运行,但如果其中一台服务器出现故障,它会变为橙色,如果所有服务器都停机,它会变为红色。
【问题讨论】: