失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > python监控网站运行异常并发送邮件办法

python监控网站运行异常并发送邮件办法

时间:2019-07-02 21:36:31

相关推荐

python监控网站运行异常并发送邮件办法

后端开发|Python教程

python,监控,网站,运行,异常,发送邮件,方法

后端开发-Python教程

本文实例讲述了python监控网站运行异常并发送邮件的方法。分享给大家供大家参考。具体如下:

5爱源码,ubuntu更改源失败,黑色长腿爬虫,基 PHP,潭州seo案例lzw

这是一个简单的python开发的监控程序,当指定网页状态不正常是通过smtp发送通知邮件

要钱网站源码,ubuntu命令中cd,爬虫采集犯法吗,php 语音上传,顺义seo教程lzw

复制代码 代码如下:

android 播放mp4 源码,vscode怎么做百度页面,ubuntu 文件 绿色,tomcat1002无标题,樱桃盐水爬虫,php免费模板下载,临汾seo优化费用是多少lzw

#!/usr/bin/env python

# -*- coding: UTF-8 -*-

#author libertyspy

import socket

import smtplib

import urllib

mail_options = {

server:\,#使用了QQ的SMTP服务,需要在邮箱中设置开启SMTP服务

port:25, #端口

user:hacker@,#发送人

pwd:hacker, #发送人的密码

send_to:sniper@, #收件者

}

msg_options={

user:hacker, #短信平台的用户名

pwd:74110,#短信平台的密码

phone:12345678910, #需要发短信的电话号码

}

test_host = /

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挂了!状态码:%s % (host,status)

request_api="/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 挂了 !状态码:%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

如果觉得《python监控网站运行异常并发送邮件办法》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。