中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

python監(jiān)控網(wǎng)站運行異常并發(fā)送郵件

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用
一個簡單的python開發(fā)的監(jiān)控程序,當指定網(wǎng)頁狀態(tài)不正常是通過smtp發(fā)送通知郵件
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#author  libertyspy
#link    http://www.lastme.com
 
import socket
import smtplib
import urllib
 
mail_options = {
    'server':'smtp.qq.com',#使用了QQ的SMTP服務,需要在郵箱中設置開啟SMTP服務
    'port':25,             #端口
    'user':'hacker@qq.com',#發(fā)送人
    'pwd':'hacker',        #發(fā)送人的密碼
    'send_to':'sniper@qq.com',  #收件者
}
msg_options={
    'user':'hacker',    #短信平臺的用戶名
    'pwd':'74110',      #短信平臺的密碼
    'phone':'12345678910',   #需要發(fā)短信的電話號碼
}
test_host = 'http://www.lastme.com/'
def url_request(host,port=80):
    try:
        response = urllib.urlopen(host)
        response_code = response.getcode()
        if 200 != response_code:
            return response_code
        else:
            return True
    except IOError,e:
        return False
 
def send_message(msg,host,status):
    send_msg='服務器:%s掛了!狀態(tài)碼:%s' % (host,status)
    request_api="http://www.uoleem.com.cn/api/uoleemApi?username=%s&pwd=%s&mobile=%s&content=%s"  \
            % (msg['user'],msg['pwd'],msg['phone'],send_msg)
    return url_request(request_api)
 
def send_email(mail,host,status):
    smtp = smtplib.SMTP()
    smtp.connect(mail['server'], mail['port'])
    smtp.login(mail['user'],mail['pwd'])
    msg="From:%s\rTo:%s\rSubject:服務器: %s 掛了 !狀態(tài)碼:%s\r\n" \
         % (mail['user'],mail['send_to'],host,status)
    smtp.sendmail(mail['user'],mail['send_to'], msg)
    smtp.quit()
"""
def check_status(host,port=80):
    s = socket.socket()
    ret_msg = []
    try:
        s.connect((host,port))
        return True
    except socket.error,e:
        return False
"""
if __name__=='__main__':
    status = url_request(test_host)
    if status is not True and status is not None:
        send_email(mail_options,test_host,status)
        send_message(msg_options,test_host,status)
    else:
        pass

標簽: 服務器

版權申明:本站文章部分自網(wǎng)絡,如有侵權,請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:tornado登陸豆瓣代碼實例

下一篇:python插入排序算法