web 網(wǎng)站實(shí)時(shí)監(jiān)控與報(bào)警

#!/bin/bash

#Created by yangjie

#mail:xtxdfl@163.com

#blog:http:flower-fz.com

lang=C

#被監(jiān)控服務(wù)器\端口列表

server_all_list={\

10.10.10.10:10 \

100.100.100.100:100 \

0.0.0.0:0 \

}

telnum=134********

passwd=12345

date=$(date -d "today" +"%Y-%m-%d_%H:%M:%S")

#采用http post 方式發(fā)送檢測(cè)信息給接口程序interface.php,接口程序負(fù)責(zé)分析信息。決定是否發(fā)送報(bào)警MSN信息、手機(jī)短信、電子郵件

send_msg_to_interface()

{

if [[ $2 = "0" ]] || [[ $2 = "2" ]];then

#開始發(fā)送警報(bào)郵件,xtxdfl@163.com 即是發(fā)送方也是接收方

sendEmail -f xtxdfl@163.com -t xtxdfl@163.com -s smtp.139.com -u "from http_monitor" -xu xtxdfl@163.com -xp james -o message -charset=utf-8 -m $1

#發(fā)送MSB警報(bào)消息(如果不需要MSN警報(bào)可以注釋這行)

#curl -m 600 -d menu=http -d date=$date -d ip=$server_ip -d port =$server_port -d status=$status http://127.0.0.1/monitor/interface.php,接口程序負(fù)責(zé)分析信息。決定是否發(fā)送報(bào)警MSN信息、手機(jī)短信、電子郵件

fi

}

server_all_len=${#server_all_list[*]}

i=0

while [$i -lt $server_all_len]

do

server_ip=$(echo ${server_all_list[$i]} | awk -F ':' '{print $1}')

server_port=$(echo ${server_all_list[$i]} | awk -F ':' '{print $2}')

server_message=""

if curl -m 10 -G http:// ${server_all_list[$i]} / > /dev/null 2>&1

then

# status: 0,http down 1,http ok 2,http down but ping ok

status=1

echo "服務(wù)器${server_ip},端口${server_port}能夠正常訪問!";

server_message="服務(wù)器${server_ip},端口{server_port}能夠正常訪問!"

else

if curl -m 30 -G http://${server_all_list[$i]}/ > /dev/null 2>&1

then

status=1

echo "服務(wù)器${server_ip},端口${server_port}能夠正常訪問!";

server_message="服務(wù)器${server_ip},端口{server_port}能夠正常訪問!"

else

if ping -c 1 $server_ip > /dev/null 2>&1

then

status=2

echo "服務(wù)器${server_ip},端口${server_port}不能夠正常訪問,但是可以ping通!";

server_message="服務(wù)器${server_ip},端口{server_port}不能夠正常訪問,但是可以ping通!"

else

status=0

echo "服務(wù)器${server_ip},端口${server_port}不能夠正常訪問,并且無法ping通!";

server_message="服務(wù)器${server_ip},端口{server_port}不能夠正常訪問,并且無法ping通!"

fi

fi

fi

send_msg_to_interface "${server_message}" "${status}";

let i++

done

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,506評(píng)論 19 139
  • 一、項(xiàng)目目標(biāo) 搭建一個(gè)高可用web集群網(wǎng)站 二、項(xiàng)目規(guī)劃 2.1 ip地址規(guī)劃 2.2 拓?fù)鋱D 2.3 相關(guān)說明 ...
    夏日之光閱讀 4,272評(píng)論 0 1
  • 一、Nagios簡(jiǎn)介 Nagios是一款開源的電腦系統(tǒng)和網(wǎng)絡(luò)監(jiān)視工具,能有效監(jiān)控Windows、Linux和Uni...
    1b3bd36d9d21閱讀 8,380評(píng)論 3 13
  • win7 cmd管理員權(quán)限設(shè)置 net localgroup administrators 用戶名 /add 把“...
    f675b1a02698閱讀 5,502評(píng)論 0 11
  • 二月十八日朗讀者初播,喜歡董卿有深度,有內(nèi)涵的言談舉止,處事、說話游刃有余,非常優(yōu)秀的主持人,制作人,節(jié)目第一期主...
    茉莉花蕊閱讀 1,464評(píng)論 0 0

友情鏈接更多精彩內(nèi)容