用python实现监控网站状态,并发送告警邮件
2014-11-23 23:33
1071 查看
#!/usr/bin/env python #coding:utf8 import os import time import smtplib from email.mime.text import MIMEText from email import Utils import socket def sendmail(to,subject,content): msg = MIMEText(content) lable_pwd="password" msg['from'] = '****@sina.com' msg['to'] = to msg['subject'] = subject msg['date'] = Utils.formatdate(localtime=1) msg['message-id'] = Utils.make_msgid() try: smtpObj = smtplib.SMTP() smtpObj.connect("smtp.sina.com:25") try: smtpObj.login("****@sina.com",lable_pwd) me = "****@sina.com" smtpObj.sendmail(me,to,msg.as_string()) print "Congratulations !Your mail have been sended Success !" except smtplib.SMTPAuthenticationError,smtplib.SMTPException: print "Login failed ,Please check the username/password." finally: try: smtpObj.close() except smtplib.SMTPException: pass except smtplib.SMTPException,e: print "Error: unable to send email %s" % e def check_server(f): try: fo = open(f) for line in fo: now = str(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))) s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) line = line.rstrip('\n') print '正在检测%s的80端口是否正常 %s:......' % (line,now) try: s.connect((line,80)) print "地址%s检测正常" % line except socket.error,e: print "地址%s检测挂啦" % line sc = 'The web server %s is down '% line cc = 'The web server %s is down at %s' % (line,now) sendmail('****@****.com',sc,cc) finally: s.close() except IOError,e: print "error: %s" % e finally: try: fo.close() except IOError,e: print "error : %s" % e if __name__=='__main__': check_server('D:/workspace/studd/company_list')
相关文章推荐
- 用python实现监控网站状态,并发送告警邮件
- python实现自动监控网站并发送邮件告警 推荐
- python实现自动监控网站并发送邮件告警
- Python&Shell 简易实现监控公司网站,邮件发送异常
- 利用Python自动监控网站并发送邮件告警的方法
- 利用Python自动监控网站并发送邮件告警的方法
- Python实现监控某个服务,服务崩溃发送邮件报告
- python实现监控某个服务 服务崩溃即发送邮件报告
- python实现自动发送报警监控邮件
- Python2.7实现监控Linux内存、CPU并发送预警邮件
- python监控文件,并且发送告警邮件
- shell+curl监控网站页面(域名访问状态),并利用sendemail发送邮件
- python监控文件并且发送告警邮件
- Linux用shell脚本监控网站运行状态并发告警邮件
- shell+curl监控网站页面(域名访问状态),并利用sedemail发送邮件
- python监控网站运行异常并发送邮件的方法
- Python实现监控某个服务,服务崩溃发送邮件报告
- 利用oracle发送邮件功能简单监控数据库运行状态
- 1.制作客户端邮件发送系统(winform版)实现用户注册时,向其油箱发送激活码邮件,并进行状态处理。