def SendMail(comproom): message = MIMEText("%s network exception,please note!" % comproom, 'plain', 'utf-8') subject = "%s network exception" % comproom message['Subject'] = Header(subject, 'utf-8') try: smtpObj = smtplib.SMTP() smtpObj.connect(mail_host, 25) smtpObj.login(mail_user,mail_pass) smtpObj.sendmail(sender, receivers, message.as_string()) mylogger.info("send mail success") except smtplib.SMTPException: mylogger.info("send mail fail")
def CheckNet(SwitchIP): sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sk.settimeout(10) res = True try: sk.connect((SwitchIP, 23)) mylogger.info('remote addr %s conn success' % SwitchIP) except Exception: mylogger.info('remote addr %s conn false' % SwitchIP) res = False sk.close() return res
def CheckNet(SwitchIP): sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sk.settimeout(10) res = True try: sk.connect((SwitchIP,23)) mylogger.info('remote addr %s conn success' % SwitchIP) except Exception: mylogger.info('remote addr %s conn false' % SwitchIP) res = False sk.close() return res
def SendMail(comproom): message = MIMEText("%s network exception,please note!" % comproom, 'plain', 'utf-8') subject = "%s network exception" % comproom message['Subject'] = Header(subject, 'utf-8') try: smtpObj = smtplib.SMTP() smtpObj.connect(mail_host, 25) smtpObj.login(mail_user, mail_pass) smtpObj.sendmail(sender, receivers, message.as_string()) mylogger.info("send mail success") except smtplib.SMTPException: mylogger.info("send mail fail")
def NetDown(SwitchIP,compRoom): num = 0 flag = 0 for i in range(5): NetStatus = CheckNet(SwitchIP) if not NetStatus: num = num + 1 time.sleep(2) if num == 5: mylogger.info("###########5 connect fail,going to down #############") do(compRoom,flag) return True else: mylogger.info("###########5 connect success,going to mail #############") SendMail(compRoom)
def UrlDown(comp_ip,comp_name): num = 0 flag = 0 for i in range(2): ResStatus = CheckUrl(comp_ip) if ResStatus['result'] == 0: num = num + 1 time.sleep(2) if num == 2: mylogger.info("###########5 connect fail,going to down #############") #do(compRoom,flag) #SendMail(comp_name) print comp_name + "going to down" + comp_ip return True else: print comp_name + "is successful-------------------------"
def NetDown(SwitchIP, compRoom): num = 0 flag = 0 for i in range(5): NetStatus = CheckNet(SwitchIP) if not NetStatus: num = num + 1 time.sleep(2) if num == 5: mylogger.info("###########5 connect fail,going to down #############") do(compRoom, flag) return True else: mylogger.info( "###########5 connect success,going to mail #############") SendMail(compRoom)
def UrlDown(comp_ip, comp_name): num = 0 flag = 0 for i in range(2): ResStatus = CheckUrl(comp_ip) if ResStatus['result'] == 0: num = num + 1 time.sleep(2) if num == 2: mylogger.info("###########5 connect fail,going to down #############") #do(compRoom,flag) #SendMail(comp_name) print comp_name + "going to down" + comp_ip return True else: print comp_name + "is successful-------------------------"
def SendInfo(url,data): url = url + '?' + "key=" + data['key'] + '&' + "compRoom=" + data['compRoom'] + '&' + "flag=" + data['flag'] + "&" + "nowtime=" + data['nowtime'] mylogger.info("The room down requested URL is:%s" % url) try: req = urllib2.Request(url.encode("utf8")) response = urllib2.urlopen(req) except Exception as e: mylogger.info('The server could not fulfill the request,%s' % e) else: mylogger.info("The room down received response is:%s" % response.read().strip()) return True
def SendInfo(url, data): url = url + '?' + "key=" + data['key'] + '&' + "compRoom=" + data[ 'compRoom'] + '&' + "flag=" + data['flag'] + "&" + "nowtime=" + data[ 'nowtime'] mylogger.info("The room down requested URL is:%s" % url) try: req = urllib2.Request(url.encode("utf8")) response = urllib2.urlopen(req) except Exception as e: mylogger.info('The server could not fulfill the request,%s' % e) else: mylogger.info("The room down received response is:%s" % response.read().strip()) return True