大型网站运维工具—-msn机器人、mail通知
大型网站的运维人员工作压力非常大,就怕服务器出现异常。为了保证服务器运行正常,就需要经常测试服务器的状态,一旦出现情况,尽快排除。现在为大家提供两种服务器自动监控的通知手段。
以下的代码全部采用php编写。
一、msn报警
监控过程不再描述,最后检测的结果可以通过以下代码,发送到管理员的msn。PHP MSN Class(http://code.google.com/p/phpmsnclass/)是一个msn协议的实现类,支持MSNP9 (MSN 6.2)和最新的MSNP15 (WLM 8.1)协议(MSNP15协议支持离线消息),可以作为MSN机器人使用,或者给MSN、雅虎通发消息。
注意:必须确保发送人、接收人的MSN互相加为好友。
<?php
include_once(‘msn.class.php’);
$msn_username = “xxx@hotmail.com”;//消息发送人MSN帐号
$msn_password = “****”;//消息发送人MSN密码
$msn_list = array(“xxx@hotmail.com”,”xxx@live.cn”);//消息接收人MSN帐号
$msn = new MSN(‘MSNP15′);//采用MSNP15协议,支持离线消息
if ($msn->connect($msn_username, $msn_password)) {
$msn->sendMessage(“UTF-8编码的中文和英文”, $msn_list);
}
?>
<?php
include_once(‘msn.class.php’);
$msn_username = “username@live.cn”;//消息发送人MSN帐号
$msn_password = “12345678″;//消息发送人MSN密码
$msn_list = array(“xxx@hotmail.com”,”xxx@live.cn”);//消息接收人MSN帐号
$msn = new MSN(‘MSNP15′);//采用MSNP15协议,支持离线消息
if ($msn->connect($msn_username, $msn_password)) {
$msn->sendMessage(“UTF-8编码的中文和英文”, $msn_list);
}
?>
二、邮件报警
监控过程不再描述,最后检测的结果可以通过以下代码,发送到管理员的邮箱。
<?php
//HTTP服务器监控
if (htmlspecialchars($_POST["menu"]) == “http”)
{
$date = htmlspecialchars($_POST["date"]);
$ip = htmlspecialchars($_POST["ip"]);
$port = htmlspecialchars($_POST["port"]);
$status = htmlspecialchars($_POST["status"]);//状态,0表示无法访问,1表示正常,2表示无法访问但能ping通
//…下一步处理(省略)…
}
//TCP服务器监控
if (htmlspecialchars($_POST["menu"]) == “tcp”)
{
$date = htmlspecialchars($_POST["date"]);
$ip = htmlspecialchars($_POST["ip"]);
$port = htmlspecialchars($_POST["port"]);
$status = htmlspecialchars($_POST["status"]);//状态,0表示无法访问,1表示正常,2表示无法访问但能ping通
//…下一步处理(省略)…
}
//MySQL服务器监控
if (htmlspecialchars($_POST["menu"]) == “mysql”)
{
$date = htmlspecialchars($_POST["date"]);
$ip = htmlspecialchars($_POST["ip"]);
$port = htmlspecialchars($_POST["port"]);
$abstract = htmlspecialchars($_POST["abstract"]);//故障摘要(必须为全角)
$info = htmlspecialchars($_POST["info"]);//故障详细描述
$failback = htmlspecialchars($_POST["failback"]);//如果服务器存活,此处接收的值为active
//…下一步处理(省略)…
}
?>
Thank you for your post today. It offers us wisdom in so many ways. Thanks also for that tiny thread!
It’s easier side view.
I磎 so happy today
Feels like a lot of pieces has fallen into place.