原理:
1。利用SHELL脚本取出系统数据,整合为POST的参数,想整点成几个就几个吧。
2。 /usr/bin/curl -d menu="diskstat" 形式是POST的数据,基本上是利用这个桥来做事了。
3。 当然是PHP的MAIL 函数了。。。。
vi diskstat_send
#!/bin/sh
LANG=zh_cn
disk=$(/bin/df -kP | grep / | awk -F ' ' ' {print $6":"$5}' | awk -F '%' ' {print $1}' | tr -s '\n'
';')
date=$(date -d "today" +"%Y-%m-%d_%H:%M:%S")
ip=$(/sbin/ifconfig | grep "inet addr" | grep -v "127.0.0.1" | awk '{print $2;}' | awk -F':' '{print $2;}' | tr -s '\n' ';') #不用这个了,因有有多个IP
/usr/bin/curl -d menu="diskstat" -d password=$2 -d date=$date -d ip="xxx.xxx.xxx.xxx" -d data=$disk $1
#end
看到吗它有几个参数被POST: MENU 当然是在多个事件要POST时做区别的, password 安全起见。
date 事件发生的时间 ip 不说了。 data 就是硬盘空间的情况。。。 $1就是接口程序要加URL哦。。
#
[root@mail htdocs]# vi inf.php #简单得无面见人
echo "abc";
$disk_max = "90";//´ÅÅÌ·ÖÇøʹÓðٷֱȳ¬¹ý´ËÖµ£¬Ôò±¨¾¯¡£Ä¬ÈÏΪ90%
$headers='From: monitor < . "\r\n";
$to="";
$subject="test";
$body="yes";
echo "dddd";
if (htmlspecialchars($_POST["menu"]) == "diskstat")
{ //htmlspecialchars 函数就是在POST中去掉《HTML》
echo "abc1" ;
$is_send_mail = "0";//ÊÇ·ñ·¢Óʼþ£¬0Ϊ²»·¢Óʼþ //标识是否需要发邮件,0 --on 1 --yes
$date = htmlspecialchars($_POST["date"]);
$ip = htmlspecialchars($_POST["ip"]);
$data = htmlspecialchars($_POST["data"]);
#这个鬼东西 [root@mail bin]# /bin/df -kP | grep / | awk -F ' ' ' {print $6":"$5}' | awk -F '%' ' {print $1}' | tr -s '\n' :
/:35:/boot:19:/home:41:/var:83:/usr:16:/opt:100:/tmp:1:/dev/shm:0:/opt/email/vmail/domains:48:
$subject = "[ϵͳ¼à¿Ø]_´ÅÅÌ·ÖÇø¿Õ¼ä²»×ã_" . $ip;
$message = "·þÎñÆ÷¼à¿Øϵͳ ServMon V1.0\r\n";
$message = $message . "-------------------------------------------------------\r\n";
$message = $message . "±¨¾¯·þÎñÆ÷£º" . $ip . "\r\n";
$message = $message . "-------------------------------------------------------\r\n";
$message = $message . "±¨¾¯Ê±¼ä£º" . $date . "\r\n";
$message = $message . "-------------------------------------------------------\r\n";
$message = $message . "±¨¾¯ÄÚÈÝ£º\r\n";
$arr1 = explode(";", $data); #以:为基,数组
foreach ($arr1 as $key1 => $value1)
{
$arr2 = explode(":", $value1);
if ($arr2[0] != "" && $arr2[1] != "" && $arr2[1] >= $disk_max)#判断哕
{
$message = $message . "¡ñ´ÅÅÌ·ÖÇø " . $arr2[0] . " ¿Õ¼ä²»×㣨¿Õ¼äʹÓÃÂÊ´ïµ½" . $arr2[1]
. "%£©\r\n";
$is_send_mail = "1";//ÊÇ·ñ·¢Óʼþ£¬1Ϊ·¢ËÍÓʼþ #无办法,大于MAX就通知你了
}
}
if ($is_send_mail == "1")
{ echo "bc";
//for($i=0;$i<50;$i++){
if(mail("$to", "$subject","$message",$headers)) #动作已经来到实际,如果$to 是个数组加上外面的for ,以数组为长度,想发给谁就发吧.
echo "
OK! the mail to $to has been he send
";
else
echo "fail to send mail
";
//}
}
}
?>
#不爽的话就让它在crontab跑一世人吧
5 * * * * /........sendisk
更加安全的方法请利用smtp类来发邮件,这样不会被当成垃圾邮件了...
~
SWAP: #!/bin/sh
LANG=zh_cn
data=$(/usr/bin/free -m | grep Swap | awk '{print $2":"$3":"$4}')
date=$(date -d "today" +"%Y-%m-%d_%H:%M:%S")
ip=$(/sbin/ifconfig | grep "inet addr" | grep -v "127.0.0.1" | awk '{print $2;}' | awk -F':' '{print $2;}' | tr -s '\n' ';')
/usr/bin/curl -d menu=swapstat -d password=$2 -d date=$date -d ip="121.9.205.13x" -d data=$data $1
[root@mail bin]# cat loadstat_send
#!/bin/sh
LANG=zh_cn
load=$(/usr/bin/uptime | awk -F'load average: ' '{print $2}' | awk '{print $1$2$3}')
date=$(date -d "today" +"%Y-%m-%d_%H:%M:%S")
ip=$(/sbin/ifconfig | grep "inet addr" | grep -v "127.0.0.1" | awk '{print $2;}' | awk -F':' '{print $2;}' | tr -s '\n' ';')
/usr/bin/curl -d menu=loadstat -d password=$2 -d date=$date -d ip="121.9.205.135x" -d data=$load $1
原理一样,不会复杂.
HTTP:
#!/bin/bash
ser_list=(\
121.9.205.135:80 \
121.9.205.162:80 \
121.9.202.134:8080)
date=$(date -d "today" +"%Y-%m-%d_%H:%M:%S")
ser_len=${#ser_list[*]}
sub_dopost(){
/usr/bin/curl -m 600 -d menu=http -d date=$date -d ip=$ip -d port=$port -d status=$status
.0.0.1:8888/boobooke.php
}
for((i=0;i<$ser_len;i++))
do
# echo "${ser_list[$i]}"
ip=$(echo "${ser_list[$i]}"|awk -F":" '{print $1}');
#echo "$ip";
port=$(echo "${ser_list[$i]}"|awk -F":" '{print $2}');
if curl -m 10 -G >/dev/null 2>&1
then
# echo " ${ser_list[$i]} yes"
status=1
#echo "status 111111111111"
else
if ping -c 1 $ip >/dev/null 2>&1
then
status=2
# echo "$status 2"
else
status=3
# echo "$status 3333"
fi
fi
sub_dopost
INTERFACE.PHP
if (htmlspecialchars($_POST["menu"]) == "http")
{
$date = htmlspecialchars($_POST["date"]);
$ip = htmlspecialchars($_POST["ip"]);
$port = htmlspecialchars($_POST["port"]);
$status = htmlspecialchars($_POST["status"]);
echo "$status $ip \n";
// if ($status = "1"){
// $messagehttp="http ·þÎñ¿ØÖÆ̨ $ip work normal\r\n";
// $messagehttp=$messagehttp."";
// if(mail("$to", "$subject","$messagehttp",$headers))
// echo "
OK! the mail to $to has been he send httpd
";
// else
// echo "fail to send mail
";
//}
if($status =="2"){
// echo $status;
$messagehttp="http $ip work nonormal\r\n";
$messagehttp=$messagehttp." $ip:$port\r\n";
if(mail("$to", "$subject","$messagehttp",$headers))
echo "
OK! the mail to $to has already done
";
else
echo "fail to send mail
";
}
MMD design to write a function
send_to_interface()
{
}
阅读(839) | 评论(0) | 转发(0) |