对Python 网络设备巡检脚本的实例讲解
1、基本信息
我公司之前采用的是人工巡检,但奈何有大量网络设备,往往巡检需要花掉一上午(还是手速快的话),浪费时间浪费生命。
这段时间正好在学Python,于是乎想(其)要(实)解(就)放(是)双(懒)手。
好了,脚本很长又比较挫,有耐心就看看吧。
需要巡检的设备如下:
设备清单 设备型号 防火墙 华为E8000E H3CM9006 飞塔FG3950B 交换机 华为S9306 H3CS12508 CiscoN7K 路由器 华为NE40E 负载 RadwareRD5412 RadwareRD6420
#相关设备巡检命令就不介绍了。。。
01DMZ-E8000E.py#华为E8000E交互脚本
#!/usr/bin/envpython importpexpect importsys importdatetime d1=datetime.datetime.now() d3=d1+datetime.timedelta(days=-1) tdy=d3.strftime('%b%d') today=datetime.date.today().strftime('%Y%m%d') tt=tdy.split() ifint(tt[-1])<10: tdy=tdy.replace('0','') ip=str(sys.argv[1]) passwd=str(sys.argv[2]) password=str(sys.argv[3]) child=pexpect.spawn('ssh用户名@%s'%ip) fout=file('/usr/sh/shell/linux/xunjian/'+today+'/01DMZ-E8000E.txt','w') child.logfile=fout child.expect('(?i)ssword:') child.sendline("%s"%passwd) child.expect('(?i)E8000E-1>') child.sendline("su") child.expect("(?i)assword:") child.sendline("%s"%password) child.expect("(?i)E8000E-1>") child.sendline("disdevice|exNormal") child.expect("(?i)E8000E-1>") child.sendline("disversion") index=child.expect(["(?i)----More----","(?i)E8000E-1>"]) if(index==0): child.send("a") child.expect("(?i)E8000E-1>") child.sendline("distemperature") child.expect("(?i)E8000E-1>") child.sendline("dir") index=child.expect(["(?i)----More----","(?i)E8000E-1>"]) if(index==0): child.send("a") child.expect("(?i)E8000E-1>") child.sendline("dismemory-usage") child.expect("(?i)E8000E-1>") child.sendline("dishrpstate") child.expect("(?i)E8000E-1>") child.sendline("disfirewallsessiontable") index=child.expect(["(?i)----More----","(?i)E8000E-1>"]) if(index==0): child.send("a") child.expect("(?i)E8000E-1>") child.sendline("disiprouting-tableprotocolstatic") child.expect("(?i)E8000E-1>") child.sendline("disintbrief|inup") child.expect("(?i)E8000E-1>") child.sendline("disacl3004") index=child.expect(["(?i)----More----","(?i)E8000E-1>"]) if(index==0): child.send("a") child.expect("(?i)E8000E-1>") child.sendline("disacl3005") index=child.expect(["(?i)----More----","(?i)E8000E-1>"]) if(index==0): child.send("a") child.expect("(?i)E8000E-1>") child.sendline("disacl3006") index=child.expect(["(?i)----More----","(?i)E8000E-1>"]) if(index==0): child.send("a") child.expect("(?i)E8000E-1>") child.sendline("disacl3007") index=child.expect(["(?i)----More----","(?i)E8000E-1>"]) if(index==0): child.send("a") child.expect("(?i)E8000E-1>") child.sendline("disalarmall") child.expect("(?i)E8000E-1>") child.sendline("dislogbuffer|in%s"%tdy) foriinrange(20): index=child.expect(["(?i)----More----","(?i)E8000E-1>"]) if(index==0): child.send("") else: child.sendline("q") break
02_03-M9006.py#H3CM9006交互脚本
#!/usr/bin/envpython importpexpect importsys importdatetime d1=datetime.datetime.now() d3=d1+datetime.timedelta(days=-1) tdy=d3.strftime('%b') today=datetime.date.today().strftime('%Y%m%d') ip=str(sys.argv[1]) passwd=str(sys.argv[2]) password=str(sys.argv[3]) ifip=='判断ip,手动打码': txt='03SM-M9006.txt' else: txt='02DMZ-M9006.txt' child=pexpect.spawn('ssh用户名@%s'%ip) fout=file('/usr/sh/shell/linux/xunjian/'+today+'/'+txt,'w') child.logfile=fout child.expect('(?i)ssword:') child.sendline("%s"%passwd) child.expect('(?i)M9006>') child.sendline("su") child.expect("(?i)assword:") child.sendline("%s"%password) child.expect("M9006>") child.sendline("disdevice|exNormal") child.expect("M9006>") child.sendline("disversion|inuptime") child.expect("M9006>") child.sendline("disenvironment") foriinrange(10): index=child.expect(["(?i)----More----","M9006>"]) if(index==0): child.send("") else: child.sendline("dir|intotal") break child.expect("M9006>") child.sendline("dismemory") foriinrange(10): index=child.expect(["(?i)----More----","M9006>"]) if(index==0): child.send("") else: child.sendline("disirflink") break child.expect("M9006>") child.sendline("disredundancygroup") child.expect("----More----") child.send('a') child.expect("M9006>") child.sendline("dissessionstatisticssummary") child.expect("M9006>") child.sendline("disiprouting-tableprotocolstatic") child.expect("M9006>") child.sendline("disintbrief|inUP") foriinrange(10): index=child.expect(["(?i)----More----","M9006>"]) if(index==0): child.send("") else: break ifip=='判断ip': child.sendline("disacl3001") foriinrange(10): index=child.expect(["(?i)----More----","M9006>"]) if(index==0): child.send("") else: child.sendline("disacl3002") child.expect("M9006>") child.sendline("disalarm") break else: child.sendline("disobject-policyip") foriinrange(20): index=child.expect(["(?i)----More----","M9006>"]) if(index==0): child.send("") else: child.sendline("disalarm") break child.expect("M9006>") child.sendline("dislogbufferreverse|in%s"%tdy) index=child.expect(["(?i)----More----","M9006>"])这边其实只要一个for循环就可以了,不高兴改了 if(index==0): child.send("") index=child.expect(["(?i)----More----","M9006>"]) if(index==0): child.send("") index=child.expect(["(?i)----More----","M9006>"]) if(index==0): child.send("") index=child.expect(["(?i)----More----","M9006>"]) if(index==0): child.send("") index=child.expect(["(?i)----More----","M9006>"]) if(index==0): child.send("") index=child.expect(["(?i)----More----","M9006>"]) if(index==0): child.send("") index=child.expect(["(?i)----More----","M9006>"]) if(index==0): child.send("") index=child.expect(["(?i)----More----","M9006>"]) if(index==0): child.send("") index=child.expect(["(?i)----More----","M9006>"]) if(index==0): child.send("") index=child.expect(["(?i)----More----","M9006>"]) if(index==0): child.send("a") index=child.expect(["(?i)----More----","M9006>"]) if(index==0): child.send("a") else: child.sendline('') child.expect("M9006>") child.sendline("q")
04IN-FG3950B.py#飞塔FG3950B交互脚本
#!/usr/bin/envpython importpexpect importsys importdatetime today=datetime.date.today().strftime('%Y%m%d') ip=str(sys.argv[1]) passwd=str(sys.argv[2]) child=pexpect.spawn('ssh用户@%s'%ip) fout=file('/usr/sh/shell/linux/xunjian/'+today+'/04IN-FG3950B.txt','w') child.logfile=fout child.expect('(?i)ssword:') child.sendline("%s"%passwd) child.expect('W-IN-FG3950-1#') child.sendline("getsysperformancestatus") foriinrange(5): index=child.expect(["(?i)--More--","W-IN-FG3950-1#"]) if(index==0): child.send("") else: child.sendline("diagnosesyssessionstat") break child.expect('W-IN-FG3950-1#') child.sendline("getrouteinforouting-tablestatic") child.expect('--More--') child.send('') child.expect('W-IN-FG3950-1#') child.sendline("exit")
05_06DMZ-S9306.py#华为S9306交互脚本
#!/usr/bin/envpython importpexpect importsys importdatetime d1=datetime.datetime.now() d3=d1+datetime.timedelta(days=-1) tdy=d3.strftime('%b%d') today=datetime.date.today().strftime('%Y%m%d') tt=tdy.split() ifint(tt[-1])<10: tdy=tdy.replace('0','') ip=str(sys.argv[1]) passwd=str(sys.argv[2]) password=str(sys.argv[3]) child=pexpect.spawn('ssh用户名@%s'%ip) ifip=='判断ip,不止一个该类型设备': txt='05DMZ-S9306-1.txt' else: txt='06DMZ-S9306-2.txt' fout=file('/usr/sh/shell/linux/xunjian/'+today+'/'+txt,'w') child.logfile=fout child.expect('(?i)ssword:') child.sendline("%s"%passwd) child.expect('07_08-S12508.py#H3CS12508交互脚本
#!/usr/bin/envpython importpexpect importsys importdatetime d1=datetime.datetime.now() d3=d1+datetime.timedelta(days=-1) tdy=d3.strftime('%b%d') today=datetime.date.today().strftime('%Y%m%d') tt=tdy.split() ifint(tt[-1])<10: tdy=tdy.replace('0','') ip=str(sys.argv[1]) passwd=str(sys.argv[2]) password=str(sys.argv[3]) child=pexpect.spawn('ssh用户名@%s'%ip) IP=['ip1','ip2'] ifip==IP[0]: txt='07DMZ-S12508.txt' name='' else: txt='08IN-S12508.txt' name=' ' fout=file('/usr/sh/shell/linux/xunjian/'+today+'/'+txt,'w') child.logfile=fout child.expect('(?i)ssword:') child.sendline("%s"%passwd) child.expect("%s"%name) child.sendline("su") child.expect("(?i)assword:") child.sendline("%s"%password) child.expect("%s"%name) child.sendline("disdevice|exNormal") child.expect("%s"%name) child.sendline("disversion|inH3CS12508") child.expect("%s"%name) child.sendline("dir") child.expect("%s"%name) child.sendline("dismemory") child.expect("%s"%name) child.sendline("disirflink") foriinrange(10): index=child.expect(["(?i)----More----","%s"%name]) if(index==0): child.send("") else: child.sendline("disintbrief|inUP") break foriinrange(20): index=child.expect(["(?i)----More----","%s"%name]) if(index==0): child.send("") else: child.sendline("dismac-addresscount") break child.expect("%s"%name) child.sendline("disarpallcount") ifip=="手动打码": child.expect("%s"%name) child.sendline("disiprouting-tablevpn-instanceDmzprotocolstatic") foriinrange(20): index=child.expect(["(?i)----More----","%s"%name]) if(index==0): child.send("") else: child.sendline("disiprouting-tablevpn-instanceInsideprotocolstatic") foriinrange(20): index=child.expect(["(?i)----More----","%s"%name]) if(index==0): child.send("") else: child.sendline("") break break child.expect("%s"%name) child.sendline("disenvironment") foriinrange(50): index=child.expect(["(?i)----More----","%s"%name]) if(index==0): child.send("") else: child.sendline("disalarm") break child.expect("%s"%name) child.sendline("dislogbuffer|in%s"%tdy) foriinrange(50): index=child.expect(["(?i)----More----","%s"%name]) if(index==0): child.send("") else: child.sendline("q") sys.exit() 09_10SM-N7K.py#CiscoN7K交互脚本
#!/usr/bin/envpython importpexpect importsys importdatetime today=datetime.date.today().strftime('%Y%m%d') ip=str(sys.argv[1]) passwd=str(sys.argv[2]) child=pexpect.spawn('telnet%s'%ip) ifip=='是个ip': txt='09SM-N7K-1.txt' name='W-SM-N7K-1#' else: txt='10SM-N7K-2.txt' name='W-SM-N7K-2#' fout=file('/usr/sh/shell/linux/xunjian/'+today+'/'+txt,'w') child.logfile=fout child.expect('login:') child.sendline("发送用户名") child.expect('(?i)ssword:') child.sendline("%s"%passwd) child.expect("%s"%name) child.sendline("shhardware|inok") child.expect("%s"%name) child.sendline("shversion|inuptime") child.expect("%s"%name) child.sendline("dir") child.expect("%s"%name) child.sendline("shintbrief|inup") foriinrange(10): index=child.expect(["(?i)More--","%s"%name]) if(index==0): child.send("") else: child.sendline("shhsrpbrief") break child.expect("%s"%name) child.sendline("shmacaddress-tablecount") child.expect("%s"%name) child.sendline("shiparp|innumber") child.expect("%s"%name) child.sendline("shiproutestaticsummary") child.expect("%s"%name) child.sendline("shenvironmenttemperature") foriinrange(10): index=child.expect(["(?i)More--","%s"%name]) if(index==0): child.send("") else: child.sendline("shvpc") break foriinrange(10): index=child.expect(["(?i)More--","%s"%name]) if(index==0): child.send("") else: child.sendline("shlogginglast30") break foriinrange(10): index=child.expect(["(?i)More--","%s"%name]) if(index==0): child.send("") else: child.sendline("exit") sys.exit()11_12DMZ-NE40E.py#华为NE40E交互脚本
#!/usr/bin/envpython importpexpect importsys importdatetime d1=datetime.datetime.now() d3=d1+datetime.timedelta(days=-1) tdy=d3.strftime('%b%d') today=datetime.date.today().strftime('%Y%m%d') tt=tdy.split() ifint(tt[-1])<10: tdy=tdy.replace('0','') ip=str(sys.argv[1]) passwd=str(sys.argv[2]) child=pexpect.spawn('ssh用户名@%s'%ip) IP=['ip1','ip2'] ifip==IP[0]: txt='11DMZ-NE40E-1.txt' name='' elifip==IP[1]: txt='12DMZ-NE40E-2.txt' name=' ' else: print"IPInputError!" sys.exit() fout=file('/usr/sh/shell/linux/xunjian/'+today+'/'+txt,'w') child.logfile=fout child.expect('(?i)ssword:') child.sendline("%s"%passwd) child.expect("(?i)N]:") child.sendline("n") child.expect("%s"%name) child.sendline("disdevice|exNormal") child.expect("%s"%name) child.sendline("disversion|inNE40E-X8uptime") child.expect("%s"%name) child.sendline("dir") index=child.expect(["(?i)----More----","%s"%name]) if(index==0): child.send("") index=child.expect(["(?i)----More----","%s"%name]) if(index==0): child.send("") else: child.sendline("dismemory-usage") else: child.sendline("dismemory-usage") child.expect("%s"%name) child.sendline("disintbrief|inup") child.expect("%s"%name) child.sendline("disiprouting-tableprotocolstatic") child.expect("%s"%name) child.sendline("distemperature") foriinrange(40): index=child.expect(["(?i)----More----","%s"%name]) if(index==0): child.send("") else: child.sendline("disalarmall") break child.expect("%s"%name) child.sendline("dislogbuffer|in%s"%tdy) foriinrange(30): index=child.expect(["(?i)----More----","%s"%name]) if(index==0): child.send("") else: child.sendline("q") break 13_16-RD5412_6420.py#RadwareRD5412交互脚本,只要掌握一个,其他都是套路
#!/usr/bin/envpython importpexpect importsys importdatetime d1=datetime.datetime.now() d3=d1+datetime.timedelta(days=-1) tdy=d3.strftime('%b%d') today=datetime.date.today().strftime('%Y%m%d') tt=tdy.split() ifint(tt[-1])<10: tdy=tdy.replace('0','') ip=str(sys.argv[1]) passwd=str(sys.argv[2]) child=pexpect.spawn('ssh还是用户名@%s'%ip) IP=['ip1','ip2','ip3','ip4'] ifip==IP[0]: txt='13DMZ-RD5412-1.txt' elifip==IP[1]: txt='14DMZ-RD5412-2.txt' elifip==IP[2]: txt='15SM-RD6420-1.txt' elifip==IP[3]: txt='16SM-RD6420-2.txt' else: print"IPInputError!" sys.exit() name='StandaloneADC(?i)' fout=file('/usr/sh/shell/linux/xunjian/'+today+'/'+txt,'w') child.logfile=fout child.expect('(?i)ssword:') child.sendline("%s"%passwd) ifip==IP[3]: child.expect("(?i)y]:") child.sendline("y") child.expect("%s"%name) child.sendline("/i/sys/general") child.expect("%s"%name) child.sendline("/i/sys/ps") child.expect("%s"%name) child.sendline("/i/sys/fan") child.expect("%s"%name) child.sendline("/i/link") index=child.expect(["Pressqtoquit,anyotherkeytocontinue","%s"%name]) if(index==0): child.send("") index=child.expect(["Pressqtoquit,anyotherkeytocontinue","%s"%name]) if(index==0): child.send("") else: child.sendline("/i/sys/capacityslb") else: child.sendline("/i/sys/capacityslb") index=child.expect(["Pressqtoquit,anyotherkeytocontinue","%s"%name]) if(index==0): child.send("") index=child.expect(["Pressqtoquit,anyotherkeytocontinue","%s"%name]) if(index==0): child.send("") index=child.expect(["Pressqtoquit,anyotherkeytocontinue","%s"%name]) if(index==0): child.send("") else: child.sendline("/stats/mp/cpu") else: child.sendline("/stats/mp/cpu") else: child.sendline("/stats/mp/cpu") child.expect("%s"%name) child.sendline("/stats/mp/mem") child.expect("%s"%name) child.sendline("/i/sys/temp") child.expect("%s"%name) child.sendline("/i/l3/vrrp") child.expect("%s"%name) child.sendline("/i/sys/log") foriinrange(50): index=child.expect(["Pressqtoquit,anyotherkeytocontinue","%s"%name]) if(index==0): child.send("") else: child.sendline("exit") break #index=child.expect(["(?i)n]:","%s"%name]) #if(index==0): ifip==IP[3]: child.expect("(?i)n]:") child.sendline("y") #else: #pass child.expect("(?i)n]:") child.sendline("n")3、编写邮件脚本
mail.py
#!/usr/bin/python #-*-coding:utf-8-*- fromemail.headerimportHeader importsmtplib importemail.MIMEMultipart#importMIMEMultipart importemail.MIMEText#importMIMEText importemail.MIMEBase#importMIMEBase importos.path importsys importmimetypes importemail.MIMEImage#importMIMEImage importdatetime tday=datetime.date.today().strftime('%Y/%m/%d') #命令mail.py<1:发送方(回复地址)10000@qq.com><2:发送地址,多个以;隔开><3:发送文件> From="%s<*@139.com>"%Header("XXX","utf-8") ReplyTo=sys.argv[1] To=sys.argv[2] file_name=sys.argv[3]#附件名 file_name1=sys.argv[4] server=smtplib.SMTP("smtp.139.com",25) server.login("user@139.com","password")#仅smtp服务器需要验证时 #构造MIMEMultipart对象做为根容器 main_msg=email.MIMEMultipart.MIMEMultipart() #构造MIMEText对象做为邮件显示内容并附加到根容器 text_msg=email.MIMEText.MIMEText("message内容正文",_charset="utf-8") main_msg.attach(text_msg) #构造MIMEBase对象做为文件附件内容并附加到根容器 ctype,encoding=mimetypes.guess_type(file_name) ifctypeisNoneorencodingisnotNone: ctype='application/octet-stream' maintype,subtype=ctype.split('/',1) file_msg=email.MIMEImage.MIMEImage(open(file_name,'rb').read(),subtype) file_msg1=email.MIMEImage.MIMEImage(open(file_name1,'rb').read(),subtype) ##设置附件头 basename=os.path.basename(file_name) file_msg.add_header('Content-Disposition','attachment',filename=basename)#修改邮件头 main_msg.attach(file_msg) basename1=os.path.basename(file_name1) file_msg1.add_header('Content-Disposition','attachment',filename=basename1)#修改邮件头 main_msg.attach(file_msg1) #设置根容器属性 main_msg['From']=From main_msg['Reply-to']=ReplyTo #main_msg['To']=To main_msg['Subject']=u"[每日巡检]%s邮件标题"%tday main_msg['Date']=email.Utils.formatdate() #main_msg['Bcc']=To #得到格式化后的完整文本 fullText=main_msg.as_string() #用smtp发送邮件 try: server.sendmail(From,To.split(';'),fullText) finally: server.quit()mail_excel_error.py#报错通知邮件:excel不存在
#!/usr/bin/envpython #-*-coding:utf-8-*- #importsys #reload(sys) importsmtplib,string,datetime,xlrd tday=datetime.date.today().strftime('%Y/%m/%d') HOST="smtp.139.com" SUBJECT="[每日巡检]%s哈哈哈"%tday TO="*.com" FROM="*@139.com" text="excelnocunzai" BODY=string.join(( "FROM:%s"%FROM, "To:%s"%TO, "Subject:%s"%SUBJECT, "", text ),"\r\n") server=smtplib.SMTP() server.connect(HOST,"25") server.starttls() server.login(FROM,"密码") server.sendmail(FROM,[TO],BODY) server.quit()mail_zip_error.py#邮件告警:巡检历史记录压缩文档不存在
#!/usr/bin/envpython #-*-coding:utf-8-*- #importsys #reload(sys) importsmtplib,string,datetime,xlrd tday=datetime.date.today().strftime('%Y/%m/%d') HOST="smtp.139.com" SUBJECT="[每日巡检]%s嘻嘻嘻"%tday TO="asdas.com" FROM="***@139.com" text="zipnocunzai" BODY=string.join(( "FROM:%s"%FROM, "To:%s"%TO, "Subject:%s"%SUBJECT, "", text ),"\r\n") server=smtplib.SMTP() server.connect(HOST,"25") server.starttls() server.login(FROM,"PASSWORD") server.sendmail(FROM,[TO],BODY) server.quit()4、数据处理
wangluo_xunjian.py#根据巡检内容制表
#!/usr/bin/envpython #-*-coding:utf-8-*- #importsys #reload(sys) importxlsxwriter,os,datetime defcmd(sname,fname):#该函数判断巡检命令行所在输出文件位置 i=1 f=open(fname) line_hang_list=[] forlineinf: ifline.find(sname)==0: line_hang_list.append(i) i+=1 f.close returnline_hang_list defcmd1(sname,fname):#同上 i=1 f=open(fname) line_hang_list=[] forlineinf: ifsnameinline: line_hang_list.append(i) i+=1 f.close returnline_hang_list tday=datetime.date.today().strftime('%Y.%m.%d') today=datetime.date.today().strftime('%Y%m%d') workbook=xlsxwriter.Workbook(u"/usr/sh/shell/linux/xunjian/%s/网络设备巡检-%s.xlsx"%(today,tday),{'strings_to_numbers':True}) file_01='/usr/sh/shell/linux/xunjian/'+str(today)+'/01DMZ-E8000E.txt' file_02_1='/usr/sh/shell/linux/xunjian/'+str(today)+'/03SM-M9006.txt' file_02_2='/usr/sh/shell/linux/xunjian/'+str(today)+'/02DMZ-M9006.txt' file_03='/usr/sh/shell/linux/xunjian/'+str(today)+'/04IN-FG3950B.txt' #新建sheet worksheet0=workbook.add_worksheet(u"防火墙") worksheet1=workbook.add_worksheet(u"交换机") worksheet2=workbook.add_worksheet(u"路由器") worksheet3=workbook.add_worksheet(u"负载") #设置单元格格式(居中,颜色,边框,合并,列宽,列隐藏等) colour='#660099' format_title=workbook.add_format() format_title.set_border(1) format_title.set_bottom(2) format_title.set_bold(1) format_title.set_font_color('white') format_title.set_bg_color(colour) format_title.set_align('center') format_title.set_valign('vcenter') format_nr=workbook.add_format() format_nr.set_border(1) format_nr.set_bottom(2) format_nr.set_align('center') format_nr.set_valign('vcenter') format_nrr=workbook.add_format() format_nrr.set_border(1) format_nrr.set_valign('vcenter') format_nrr.set_text_wrap() format_bottom=workbook.add_format() format_bottom.set_border(1) format_bottom.set_bottom(2) format_bottom.set_valign('vcenter') format_bottom.set_text_wrap() format_rt=workbook.add_format() format_rt.set_border(1) format_rt.set_right(2) format_rt.set_valign('left') format_rt.set_text_wrap() format_right=workbook.add_format() format_right.set_border(1) format_right.set_right(2) format_right.set_bottom(2) format_right.set_valign('vcenter') format_right.set_text_wrap() format_red=workbook.add_format() format_red.set_font_color('red') format_red.set_border(1) format_red.set_right(2) format_red.set_valign('vcenter') format_rd=workbook.add_format() format_rd.set_font_color('red') format_rd.set_border(1) format_rd.set_right(2) format_rd.set_bottom(2) format_rd.set_valign('vcenter') #填写相关固定单元格内容 firewall_title=[u'设备名称',u'设备类型',u'IP地址',u'检查项',u'命令',u'说明',u'检查结果'] firewall_jc=[u'设备状态',u'运行时长',u'运行温度',u'Flash状态',u'CPU使用率',u'内存使用率',u'冗余组状态',u'session数目',u'路由条数',u'端口状态',u'策略条数',u'告警',u'日志',u'板卡状态',u'运行时长',u'运行温度',u'Flash状态',u'CPU使用率',u'内存使用率',u'堆叠状态',u'冗余组状态',u'session数目',u'路由条数',u'端口状态',u'策略条数',u'告警',u'日志',u'板卡状态',u'运行时长',u'运行温度',u'Flash状态',u'CPU使用率',u'内存使用率',u'堆叠状态',u'冗余组状态',u'session数目',u'路由条数',u'端口状态',u'策略条数',u'告警',u'日志',u'运行时长',u'CPU使用率(BOMC看)',u'内存使用率',u'网络流量',u'session数目',u'新建session速率',u'接口状态',u'冗余组状态',u'路由条数',u'日志',u'策略条数',u'告警'] firewall_cmd=['disdevice|exNormal','disversion','distemperature','dir',u'在BOMC看','dismemory-usage','dishrpstate','disfirewallsessiontable','disiprouting-tableprotocolstatic','disintbrief(dislogbuffer|inDOWN)','disacl3004(3004-3007)','disalarmall','dislogbuffer|in[data]','disdevice|exNormal','disversion|inuptime','disenvironment','dir|intotal',u'在BOMC看','dismemory','disirflink','disredundancygroup','dissessionstatisticssummary','disiprouting-tableprotocolstatic','disintbrief(dislogbuffer|inDOWN)','disobject-policyip','disalarm','dislogbuffer|in[month]','disdevice|exNormal','disversion|inuptime','disenvironment','dir|intotal',u'在BOMC看','dismemory','disirflink','disredundancygroup','dissessionstatisticssummary','disiprouting-tableprotocolstatic','disintbrief(dislogbuffer|inDOWN)','disaclall','disalarm','dislogbuffer|in[month]','getsysperformancestatus','','','','diagnosesyssessionstat','',u'网页登录查看',u'网页登录查看','getrouteinforoutingtablestatic',u'网页登录查看',u'网页登录查看',u'网页登录查看'] firewall_sm=[u'填写Status是Abnormal的项',u'填写已运行天数,小时数',u'填写温度范围',u'填写total和free的flash大小',u'填写CPU使用率峰值和平均值',u'填写内存使用率',u'填写本机和邻居的角色,看有无发生主备切换',u'填写链接总数',u'填写路由数目',u'填写状态为UP的端口数目',u'填写策略数目',u'填写告警内容,无告警则填写“无告警”',u'填写异常日志,无异常则填写“正常”',u'填写State为Absent,且Type不为NONE的项',u'填写已运行天数,小时数',u'填写温度范围',u'填写total和free的flash大小',u'填写CPU使用率峰值和平均值',u'填写内存使用率范围',u'填写Status不是UP的项',u'填写Status,看有无发生主备切换',u'填写链接总数',u'填写路由数目',u'填写状态为UP的端口数目',u'填写策略数目(所有rule的总数)',u'填写告警内容,无告警则填写“无告警”',u'填写异常日志,无异常则填写“正常”',u'填写State为Absent,且Type不为NONE的项',u'填写已运行天数,小时数',u'填写温度范围',u'填写total和free的flash大小',u'填写CPU使用率峰值和平均值',u'填写内存使用率范围',u'填写Status不是UP的项',u'填写Status,看有无发生主备切换',u'填写链接总数',u'填写路由数目',u'填写状态为UP的端口数目',u'填写策略数目(acl3001+3002的总条目数)',u'填写告警内容,无告警则填写“无告警”',u'填写异常日志,无异常则填写“正常”',u'填写已运行天数,小时数',u'填写CPU使用率峰值和平均值',u'填写内存使用率',u'填写30分钟内平均带宽占用(kbps)',u'填写session_count值',u'填写setup_rate值',u'填写启用状态的接口数目',u'填写冗余状态',u'填写路由数目',u'填写异常日志,无异常则填写“正常”',u'填写策略数目',u'填写告警内容,无告警则填写“无告警”'] switch_title=[u'设备名称',u'设备类型',u'IP地址',u'检查项',u'命令',u'说明',u'检查结果'] switch_jc=[u'设备状态',u'运行时长',u'Flash状态',u'CPU使用率',u'内存使用率',u'接口状态',u'VRRP状态',u'MAC地址条目数',u'ARP条目数',u'路由条目数',u'运行温度',u'告警',u'日志'] switch_jc1=[u'设备状态',u'运行时长',u'Flash状态',u'CPU使用率',u'内存使用率',u'堆叠状态',u'接口状态',u'MAC地址条目数',u'ARP条目数',u'路由条目数',u'运行温度',u'告警',u'日志'] switch_jc2=[u'设备状态',u'运行时长',u'Flash状态',u'CPU使用率',u'内存使用率',u'堆叠状态',u'接口状态',u'MAC地址条目数',u'ARP条目数',u'运行温度',u'告警',u'日志'] switch_cmd=['disdevice','disversion|inQuidway','dir','discpu-usage','dismemory-usage','disintbrief(dislogbuffer|inIF_STATE)','disvrrpbrief','dismac-addresstotal-number','disarpstatisticsall','disiprouting-tableprotocolstatic','distemperatureall','disalarmall','dislogbuffer|in[date]'] switch_cmmd=['disdevice|exNormal','disversion|inH3CS12508','dir',u'在BOMC看','dismemory','disirflink','disintbrief(dislogbufferreverse|inUPDOWN)','dismac-addresscount','disarpallcount','disiprouting-tablevpn-instanceDmz/Insideprotocolstatic','disenvironment','disalarm','dislogbufferreverse|in[date]'] switch_cmd1=['disdevice|exNormal','disversion|inH3CS12508','dir',u'在BOMC看','dismemory','disintbrief(dislogbufferreverse|inUPDOWN)','disvrrp','dismac-addresscount','disarpallcount','disiprouting-tableprotocolstatic','disenvironment','disalarm','dislogbufferreverse|in[date]'] switch_cmd2=['disdevice|exNormal','disversion|inH3CS12508','dir',u'在BOMC看','dismemory','disirflink','disintbrief(dislogbufferreverse|inUPDOWN)','dismac-addresscount','disarpallcount','disenvironment','disalarm','dislogbufferreverse|in[date]'] switch_sm=[u'查看电源、风扇以及板卡状态,填写异常项',u'填写已运行天数,小时数',u'填写total和free的flash大小',u'填写CPU使用率',u'填写内存使用率',u'填写状态为UP的端口数目',u'查看VRRP主备状态',u'填写总的mac-address条目数',u'填写动态和静态ARP条目数',u'填写路由数目',u'填写温度范围',u'填写告警内容,无告警则填写“无告警”',u'填写异常日志,无异常则填写“正常”'] switch_ssm=[u'填写状态异常的项',u'填写已运行天数,小时数',u'填写total和free的flash大小',u'填写CPU使用率峰值和平均值',u'填写内存使用率',u'填写Status不是UP的项',u'填写状态为UP的端口数目',u'填写总的mac-address条目数',u'填写总的ARP条目数',u'填写路由数目(Dmz和Inside路由总和)',u'填写温度范围',u'填写设备告警,无则填写“无告警”',u'填写异常日志,无异常则填写“正常”'] switch_sm1=[u'填写状态异常的项',u'填写已运行天数,小时数',u'填写total和free的flash大小',u'填写CPU使用率峰值和平均值',u'填写内存使用率',u'填写状态为UP的端口数目',u'查看VRRP主备状态',u'填写总的mac-address条目数',u'填写总的ARP条目数',u'填写路由数目',u'填写温度范围',u'填写设备告警,无则填写“无告警”',u'填写异常日志,无异常则填写“正>常”'] switch_sm2=[u'填写状态异常的项',u'填写已运行天数,小时数',u'填写total和free的flash大小',u'填写CPU使用率峰值和平均值',u'填写内存使用率',u'填写Status不是UP的项',u'填写状态为UP的端口数目',u'填写总的mac-address条目数',u'填写总的ARP条目数',u'填写温度范围',u'填写设备告警,无则填写“无告警”',u'填写异常日志,无异常则填写“正>常”'] route_title=[u'设备名称',u'设备类型',u'IP地址',u'检查项',u'命令',u'说明',u'检查结果'] route_jc=[u'设备状态',u'运行时长',u'Flash状态',u'CPU使用率',u'内存使用率',u'接口状态',u'路由条数',u'运行温度',u'告警',u'日志'] route_cmd=['disdevice|exNormal','disversion|inNE40E-X8uptime','dir',u'在BOMC看','dismemory-usage','disintbrief(dislogbuffer|inIF_STATE)','disiprouting-tableprotocolstatic','distemperature','disalarmall','dislogbuffer|in[date]'] route_sm=[u'填写Status不是“Normal”的项',u'填写已运行天数,小时数',u'填写total和free的flash大小',u'填写CPU使用率峰值和平均值',u'填写内存使用率',u'填写状态为UP的端口数目',u'填写路由数目',u'填写温度范围',u'填写告警内容,无告警则填写“无告警”',u'填写异常日志,无异常则填写“正常”'] fuzai_title=[u'设备名称',u'设备类型',u'IP地址',u'检查项',u'命令',u'说明',u'检查结果'] fuzai_jc=[u'运行时长',u'电源状态',u'风扇状态',u'端口状态',u'各表项数值',u'CPU使用率',u'内存使用率',u'硬件温度',u'冗余状态',u'日志'] fuzai_cmd=['/i/sys/general','/i/sys/ps','/i/sys/fan','/i/link','/i/sys/capacityslb','/stats/mp/cpu','/stats/mp/mem','/i/sys/temp','/i/l3/vrrp','/i/sys/log'] fuzai_sm=[u'填写已运行天数,小时数',u'填写电源状态',u'填写风扇状态',u'填写Link处于UP状态的端口数',u'填写realservers/servergroups/virtualservers/filters当前值',u'填写CPU使用率',u'填写内存使用率',u'填写温度',u'填写VRRP状态,"master"或者"backup"',u'填写异常日志,无异常则填写“正常”'] newsmswitch_title=[u'设备状态',u'运行时长',u'Flash状态',u'CPU使用率',u'内存使用率',u'接口状态',u'HSRP状态',u'MAC地址条目数',u'ARP条目数',u'路由条目数',u'运行温度',u'VPC状态',u'日志'] newsmswitch_cmd=['shhardware|inok','shversion|inuptime','dir',u'在BOMC看',u'在BOMC看','shintbrief(shintbrief|inup)','shhsrpbrief','shmacaddress-tablecount','shiparp|innumber','shiproutestaticsummary','shenvironmenttemperature','shvpc','shlogginglast30'] newsmswitch_sm=[u'填写状态为OK的模块数',u'填写已运行天数,小时数',u'填写total和free的flash大小',u'填写CPU使用率峰值和平均值',u'填写内存使用率',u'填写状态为UP的端口数目',u'查看HSRP状态(Activelocal则正常)',u'填写总的mac-address条目数',u'填写总的ARP条目数',u'填写路由数目',u'填写CurTemp范围',u'查看VPC状态是否正常',u'查看日志,无异常则填写"正常"'] #ip我就隐藏掉啦,虽然也没什么意思 host={"DMZ-E8000E":[u'防火墙',"ip1"],"DMZ-M9006":[u'防火墙','ip2'],"SM-M9006":[u'防火墙','ip3'],"IN-FG3950B":[u'防火墙',"ip4"],"DMZ-S9306-1":[u'交换机',"ip5"],"DMZ-S9306-2":[u'交换机',"ip6"],"DMZ-S12508":[u'交换机',"ip7"],"IN-S12508":[u'交换机',"ip8"],"SM-S12508-1":[u'交换机',"ip9"],"SM-S12508-2":[u'交换机',"ip10"],"DMZ-NE40E-1":[u'路由器',"ip11"],"DMZ-NE40E-2":[u'路由器',"ip12"],"DMZ-RD5412-1":[u'负载',"ip13"],"DMZ-RD5412-2":[u'负载',"ip14"],"SM-RD6420-1":[u'负载',"ip15"],"SM-RD6420-2":[u'负载',"ip16"],"SM-N7K-1":[u"交换机","ip17"],"SM-N7K-2":[u"交换机","ip18"]} #开始填写固定单元格内容 worksheet0.write_row('A1',firewall_title,format_title) worksheet0.merge_range('A2:A14','DMZ-E8000E',format_nr) worksheet0.merge_range('B2:B14',host["DMZ-E8000E"][0],format_nr) worksheet0.merge_range('C2:C14',host["DMZ-E8000E"][1],format_nr) worksheet0.merge_range('A15:A28','DMZ-M9006',format_nr) worksheet0.merge_range('B15:B28',host["DMZ-M9006"][0],format_nr) worksheet0.merge_range('C15:C28',host["DMZ-M9006"][1],format_nr) worksheet0.merge_range('A29:A42','SM-M9006',format_nr) worksheet0.merge_range('B29:B42',host["SM-M9006"][0],format_nr) worksheet0.merge_range('C29:C42',host["SM-M9006"][1],format_nr) worksheet0.merge_range('A43:A54','IN-FG3950B',format_nr) worksheet0.merge_range('B43:B54',host["IN-FG3950B"][0],format_nr) worksheet0.merge_range('C43:C54',host["IN-FG3950B"][1],format_nr) worksheet0.merge_range('E43:E46','getsysperformancestatus',format_nrr) worksheet0.merge_range('E47:E48','diagnosesyssessionstat',format_nrr) worksheet0.write_column('D2',firewall_jc,format_nrr) worksheet0.write_column('E2',firewall_cmd,format_nrr) worksheet0.write_column('F2',firewall_sm,format_nrr) worksheet0.write('D14',u'日志',format_bottom) worksheet0.write('E14','dislogbuffer|in[data]',format_bottom) worksheet0.write('F14',u'填写异常日志,无异常则填写“正常”',format_bottom) worksheet0.write('D28',u'日志',format_bottom) worksheet0.write('E28','dislogbufferreverse|in[month]',format_bottom) worksheet0.write('F28',u'填写异常日志,无异常则填写“正常”',format_bottom) worksheet0.write('D42',u'日志',format_bottom) worksheet0.write('E42','dislogbufferreverse|in[month]',format_bottom) worksheet0.write('F42',u'填写异常日志,无异常则填写“正常”',format_bottom) worksheet0.write('D54',u'告警',format_bottom) worksheet0.write('E54',u'网页登录查看',format_bottom) worksheet0.write('F54',u'填写告警内容,无告警则填写“无告警”',format_bottom) worksheet0.set_row(0,30) worksheet0.set_column('B:B',15,None,{'hidden':1}) worksheet0.set_column('E:F',40,None,{'hidden':1}) worksheet0.set_column('A:A',15) worksheet0.set_column('C:D',15) worksheet0.set_column('G:G',40) worksheet1.write_row('A1',switch_title,format_title) worksheet1.merge_range('A2:A14','DMZ-S9306-1',format_nr) worksheet1.merge_range('B2:B14',host["DMZ-S9306-1"][0],format_nr) worksheet1.merge_range('C2:C14',host["DMZ-S9306-1"][1],format_nr) worksheet1.merge_range('A15:A27','DMZ-S9306-2',format_nr) worksheet1.merge_range('B15:B27',host["DMZ-S9306-2"][0],format_nr) worksheet1.merge_range('C15:C27',host["DMZ-S9306-2"][1],format_nr) worksheet1.merge_range('A28:A40','DMZ-S12508',format_nr) worksheet1.merge_range('B28:B40',host["DMZ-S12508"][0],format_nr) worksheet1.merge_range('C28:C40',host["DMZ-S12508"][1],format_nr) worksheet1.merge_range('A41:A52','IN-S12508',format_nr) worksheet1.merge_range('B41:B52',host["IN-S12508"][0],format_nr) worksheet1.merge_range('C41:C52',host["IN-S12508"][1],format_nr) worksheet1.merge_range('A53:A65','SM-N7K-1',format_nr) worksheet1.merge_range('B53:B65',host["SM-N7K-1"][0],format_nr) worksheet1.merge_range('C53:C65',host["SM-N7K-1"][1],format_nr) worksheet1.merge_range('A66:A78','SM-N7K-2',format_nr) worksheet1.merge_range('B66:B78',host["SM-N7K-2"][0],format_nr) worksheet1.merge_range('C66:C78',host["SM-N7K-2"][1],format_nr) worksheet1.write_column('D2',switch_jc,format_nrr) worksheet1.write_column('D15',switch_jc,format_nrr) worksheet1.write_column('D28',switch_jc1,format_nrr) worksheet1.write_column('D41',switch_jc2,format_nrr) worksheet1.write_column('D53',newsmswitch_title,format_nrr) worksheet1.write_column('D66',newsmswitch_title,format_nrr) worksheet1.write_column('E2',switch_cmd,format_nrr) worksheet1.write_column('E15',switch_cmd,format_nrr) worksheet1.write_column('E28',switch_cmmd,format_nrr) worksheet1.write_column('E41',switch_cmd2,format_nrr) worksheet1.write_column('E53',newsmswitch_cmd,format_nrr) worksheet1.write_column('E66',newsmswitch_cmd,format_nrr) worksheet1.write_column('F2',switch_sm,format_nrr) worksheet1.write_column('F15',switch_sm,format_nrr) worksheet1.write_column('F28',switch_ssm,format_nrr) worksheet1.write_column('F41',switch_sm2,format_nrr) worksheet1.write_column('F53',newsmswitch_sm,format_nrr) worksheet1.write_column('F66',newsmswitch_sm,format_nrr) worksheet1.set_row(0,30) worksheet1.set_column('B:B',15,None,{'hidden':1}) worksheet1.set_column('E:F',40,None,{'hidden':1}) worksheet1.set_column('A:A',15) worksheet1.set_column('C:D',15) worksheet1.set_column('G:G',40) worksheet2.write_row('A1',route_title,format_title) worksheet2.merge_range('A2:A11','DMZ-NE40E-1',format_nr) worksheet2.merge_range('B2:B11',host["DMZ-NE40E-1"][0],format_nr) worksheet2.merge_range('C2:C11',host["DMZ-NE40E-1"][1],format_nr) worksheet2.merge_range('A12:A21','DMZ-NE40E-2',format_nr) worksheet2.merge_range('B12:B21',host["DMZ-NE40E-2"][0],format_nr) worksheet2.merge_range('C12:C21',host["DMZ-NE40E-2"][1],format_nr) worksheet2.write_column('D2',route_jc,format_nrr) worksheet2.write_column('D12',route_jc,format_nrr) worksheet2.write_column('E2',route_cmd,format_nrr) worksheet2.write_column('E12',route_cmd,format_nrr) worksheet2.write_column('F2',route_sm,format_nrr) worksheet2.write_column('F12',route_sm,format_nrr) worksheet2.set_row(0,30) worksheet2.set_column('B:B',15,None,{'hidden':1}) worksheet2.set_column('E:F',40,None,{'hidden':1}) worksheet2.set_column('A:A',15) worksheet2.set_column('C:D',15) worksheet2.set_column('G:G',40) worksheet3.write_row('A1',fuzai_title,format_title) worksheet3.merge_range('A2:A11','DMZ-RD5412-1',format_nr) worksheet3.merge_range('B2:B11',host["DMZ-RD5412-1"][0],format_nr) worksheet3.merge_range('C2:C11',host["DMZ-RD5412-1"][1],format_nr) worksheet3.merge_range('A12:A21','DMZ-RD5412-2',format_nr) worksheet3.merge_range('B12:B21',host["DMZ-RD5412-2"][0],format_nr) worksheet3.merge_range('C12:C21',host["DMZ-RD5412-2"][1],format_nr) worksheet3.merge_range('A22:A31','SM-RD6420-1',format_nr) worksheet3.merge_range('B22:B31',host["SM-RD6420-1"][0],format_nr) worksheet3.merge_range('C22:C31',host["SM-RD6420-1"][1],format_nr) worksheet3.merge_range('A32:A41','SM-RD6420-2',format_nr) worksheet3.merge_range('B32:B41',host["SM-RD6420-2"][0],format_nr) worksheet3.merge_range('C32:C41',host["SM-RD6420-2"][1],format_nr) worksheet3.write_column('D2',fuzai_jc,format_nrr) worksheet3.write_column('D12',fuzai_jc,format_nrr) worksheet3.write_column('D22',fuzai_jc,format_nrr) worksheet3.write_column('D32',fuzai_jc,format_nrr) worksheet3.write_column('E2',fuzai_cmd,format_nrr) worksheet3.write_column('E12',fuzai_cmd,format_nrr) worksheet3.write_column('E22',fuzai_cmd,format_nrr) worksheet3.write_column('E32',fuzai_cmd,format_nrr) worksheet3.write_column('F2',fuzai_sm,format_nrr) worksheet3.write_column('F12',fuzai_sm,format_nrr) worksheet3.write_column('F22',fuzai_sm,format_nrr) worksheet3.write_column('F32',fuzai_sm,format_nrr) worksheet3.set_row(0,30) worksheet3.set_column('B:B',15,None,{'hidden':1}) worksheet3.set_column('E:F',40,None,{'hidden':1}) worksheet3.set_column('A:A',15) worksheet3.set_column('C:D',15) worksheet3.set_column('G:G',40) jcx=[u'日志','dislogbuffer|in[date]',u'填写异常日志,无异常则填写“正常”'] jcx1=[u'日志','dislogbufferreverse|in[date]',u'填写异常日志,无异常则填写“正常”'] jcx2=[u'日志','shlogginglast30',u'查看日志,无异常则填写“正常”'] fuzai_jcx=[u'日志','/i/sys/log',u'填写异常日志,无异常则填写“正常”'] worksheet1.write_row('D14',jcx,format_bottom) worksheet1.write_row('D27',jcx,format_bottom) worksheet1.write_row('D40',jcx,format_bottom) worksheet1.write_row('D52',jcx1,format_bottom) worksheet1.write_row('D65',jcx2,format_bottom) worksheet1.write_row('D78',jcx2,format_bottom) worksheet2.write_row('D11',jcx,format_bottom) worksheet2.write_row('D21',jcx,format_bottom) worksheet3.write_row('D11',fuzai_jcx,format_bottom) worksheet3.write_row('D21',fuzai_jcx,format_bottom) worksheet3.write_row('D31',fuzai_jcx,format_bottom) worksheet3.write_row('D41',fuzai_jcx,format_bottom) #这边开始根据之前与设备交互所得到的数据文件内容来填格子了。 #------------------------------------------------ #----------firewall_ip1---------------- #------------------------------------------------ try: hang=1 temp=[] hang_list=cmd("HRP_M",file_01) rules=[] g=0 withopen(file_01)asf: foreach_lineinf: num=each_line.split() ifhang>int(hang_list[1])andhang int(hang_list[2])andhang int(hang_list[3])andhang int(hang_list[4])andhang int(hang_list[5])andhang int(hang_list[6])andhang int(hang_list[7])andhang int(hang_list[8])andhang int(hang_list[9])andhang int(hang_list[10])andhang int(hang_list[14])andhang int(hang_list[15])andhang ",file_02_2) temp=[] rules=0 mem=[] g=0 all=0 n=0 level=0 q=0 status=0 type=0 withopen(file_02_2)asf: foreach_lineinf: num=each_line.split() ifhang>int(hang_list[0])andhang int(hang_list[1])andhang int(hang_list[2])andhang int(hang_list[3])andhang int(hang_list[4])andhang int(hang_list[5])andhang int(hang_list[6])andhang int(hang_list[7])andhang int(hang_list[8])andhang int(hang_list[9])andhang =4andnum[1]=='UP': all+=1 ifhang>int(hang_list[10])andhang int(hang_list[12])andhang 5: ifnum[3]!='INFO': level=1 ifhang>int(hang_list[13])andhang ",file_02_1) temp=[] rules=[] mem=[] g=0 all=0 n=0 level=0 q=0 status=0 type=0 withopen(file_02_1)asf: foreach_lineinf: num=each_line.split() ifhang>int(hang_list[0])andhang int(hang_list[1])andhang int(hang_list[2])andhang int(hang_list[3])andhang int(hang_list[4])andhang int(hang_list[5])andhang int(hang_list[6])andhang int(hang_list[7])andhang int(hang_list[8])andhang int(hang_list[9])andhang =4andnum[1]=='UP': all+=1 ifhang>int(hang_list[10])andhang int(hang_list[12])andhang 5: ifnum[3]!='INFO': level=1 ifhang>int(hang_list[13])andhang int(hang_list[0])andhang int(hang_list[1])andhang int(hang_list[2])andhang =6: g+=1 hang+=1 worksheet0.write('G51',g,format_rt) worksheet0.write('G44',None,format_rt) worksheet0.write('G49',None,format_rt) worksheet0.write('G50',None,format_rt) worksheet0.write('G52',None,format_rt) worksheet0.write('G53',None,format_rt) worksheet0.write('G54',None,format_right) exceptIOErrorasreason: print"04IN-FG3950B.py"+str(reason) #------------------------------------------------ #------------switch_ip5---------------- #------------switch_ip6---------------- #------------------------------------------------ try: foriinrange(2): hang=1 alarm=0 state=0 status=0 alm=0 temp_list=[] index={0:list(range(2,15)),1:list(range(15,28))} file='/usr/sh/shell/linux/xunjian/'+str(today)+'/0'+str(i+5)+'DMZ-S9306-'+str(i+1)+'.txt' hang_list=cmd(' '%(i+1),file) withopen(file)asf: foreach_lineinf: num=each_line.split() ifhang>int(hang_list[1])andhang int(hang_list[2])andhang int(hang_list[3])andhang int(hang_list[4])andhang int(hang_list[5])andhang int(hang_list[6])andhang =6andnum[1]=='up': state+=1 ifhang>int(hang_list[7])andhang int(hang_list[8])andhang int(hang_list[9])andhang int(hang_list[10])andhang int(hang_list[11])andhang =6andnum[-5].isdigit(): temp=num[-1].split('.') temp_list.append(temp[0]) ifhang>int(hang_list[12])andhang int(hang_list[13])andhang '] state=[] foriinrange(1): hang=1 file='/usr/sh/shell/linux/xunjian/'+str(today)+'/'+fi_list[i] hang_list=cmd(fi_name[i],file) brd_status=['Master','Slave','Absent'] brd=0 link=0 Master=0 Backup=0 count=[] temp=[] alarm=0 status=0 index={0:list(range(28,41))} withopen(file)asf: foreach_lineinf: num=each_line.split() ifhang>int(hang_list[1])andhang int(hang_list[2])andhang int(hang_list[3])andhang int(hang_list[4])andhang int(hang_list[5])andhang int(hang_list[6])andhang =2andnum[1]=='UP': link+=1 #ifnum[0]=='----'andnum[5]=='UP': #link+=1 ifhang>int(hang_list[7])andhang int(hang_list[8])andhang int(hang_list[9])andhang int(hang_list[11])andhang int(hang_list[12])andhang =8: ifnum[3].isdigit(): temp.append(num[3]) ifnum[0]=='----'andnum[1]=='More': temp.append(num[7]) ifhang>int(hang_list[13])andhang int(hang_list[14])andhang