Python 네트워크 장치 순찰 스 크 립 트 의 인 스 턴 스 설명

1.기본 정보
우리 회 사 는 이전에 인공 순찰 검 사 를 사 용 했 지만 어떻게 대량의 네트워크 설 비 를 가지 고 있 습 니까?순찰 검 사 는 오전 내 내(손 이 빠 르 면)시간 을 낭비 하고 생명 을 낭비 합 니 다.
그 동안 마침 Python 을 배우 고 있 었 기 때문에 두 손 을 놓 으 려 고 했 습 니 다.
자,대본 이 길 고 좌절 되 었 으 니 인내심 이 있 으 면 보 세 요.
순찰 이 필요 한 설 비 는 다음 과 같다.
장치 목록
설비 모델
방화벽
화 웨 이 E8000E
H3C M9006
비 탑 FG 3950 B
교환기
화 웨 이 S9306
H3C S12508
Cisco N7K
공유 기
화 웨 이 NE40E
부하
Radware RD5412
Radware RD6420
2.데이터 수집 및 파일 쓰기
\#관련 설비 순찰 명령 은 소개 하지 않 겠 습 니 다...
01DMZ-E8000E.py\#화 웨 이 E8000E 대화 형 스 크 립 트

#!/usr/bin/env python
import pexpect
import sys
import datetime
 
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()
if int(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("dis device | ex Normal")
child.expect("(?i)E8000E-1>")
child.sendline("dis version")
index = child.expect(["(?i)---- More ----","(?i)E8000E-1>"])
if ( index == 0 ):
 child.send("a")
child.expect("(?i)E8000E-1>")
child.sendline("dis temperature")
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("dis memory-usage")
child.expect("(?i)E8000E-1>")
child.sendline("dis hrp state")
child.expect("(?i)E8000E-1>")
child.sendline("dis firewall session table")
index = child.expect(["(?i)---- More ----","(?i)E8000E-1>"])
if ( index == 0 ):
 child.send("a")
child.expect("(?i)E8000E-1>")
child.sendline("dis ip routing-table protocol static")
child.expect("(?i)E8000E-1>")
child.sendline("dis int brief | in up")
child.expect("(?i)E8000E-1>")
child.sendline("dis acl 3004")
index = child.expect(["(?i)---- More ----","(?i)E8000E-1>"])
if ( index == 0 ):
 child.send("a")
child.expect("(?i)E8000E-1>")
child.sendline("dis acl 3005")
index = child.expect(["(?i)---- More ----","(?i)E8000E-1>"])
if ( index == 0 ):
 child.send("a")
child.expect("(?i)E8000E-1>")
child.sendline("dis acl 3006")
index = child.expect(["(?i)---- More ----","(?i)E8000E-1>"])
if ( index == 0 ):
 child.send("a")
child.expect("(?i)E8000E-1>")
child.sendline("dis acl 3007")
index = child.expect(["(?i)---- More ----","(?i)E8000E-1>"])
if ( index == 0 ):
 child.send("a")
child.expect("(?i)E8000E-1>")
child.sendline("dis alarm all")
child.expect("(?i)E8000E-1>")
child.sendline("dis logbuffer | in %s"%tdy)
for i in range(20):
 index = child.expect(["(?i)---- More ----","(?i)E8000E-1>"])
 if ( index == 0 ):
 child.send(" ")
 else:
 child.sendline("q")
 break
02_03-M9006.py\#H3C M9006 대화 형 스 크 립 트

#!/usr/bin/env python
import pexpect
import sys
import datetime
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])
 
 
if ip == '  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("dis device | ex Normal")
child.expect("M9006>")
child.sendline("dis version | in uptime")
child.expect("M9006>")
child.sendline("dis environment")
for i in range(10):
 index = child.expect(["(?i)---- More ----","M9006>"])
 if ( index == 0 ):
 child.send(" ")
 else:
 child.sendline("dir | in total")
 break
child.expect("M9006>")
child.sendline("dis memory")
for i in range(10):
 index = child.expect(["(?i)---- More ----","M9006>"])
 if ( index == 0 ):
 child.send(" ")
 else:
 child.sendline("dis irf link")
 break
child.expect("M9006>")
child.sendline("dis redundancy group")
child.expect("---- More ----")
child.send('a')
child.expect("M9006>")
child.sendline("dis session statistics summary")
child.expect("M9006>")
child.sendline("dis ip routing-table protocol static")
child.expect("M9006>")
child.sendline("dis int brief | in UP")
for i in range(10):
 index = child.expect(["(?i)---- More ----","M9006>"])
 if ( index == 0 ):
 child.send(" ")
 else:
 break
if ip == '  ip':
 child.sendline("dis acl 3001")
 for i in range(10):
 index = child.expect(["(?i)---- More ----","M9006>"])
 if ( index == 0 ):
 child.send(" ")
 else:
 child.sendline("dis acl 3002")
 child.expect("M9006>")
 child.sendline("dis alarm")
 break
else:
 child.sendline("dis object-policy ip")
 for i in range(20):
 index = child.expect(["(?i)---- More ----","M9006>"])
 if ( index == 0 ):
 child.send(" ")
 else:
 child.sendline("dis alarm")
 break
child.expect("M9006>")
child.sendline("dis logbuffer reverse | 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-FG3950 B.py\#비 탑 FG3950 B 상호작용 스 크 립 트

#!/usr/bin/env python
import pexpect
import sys
import datetime
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("get sys performance status")
for i in range(5):
 index = child.expect(["(?i)--More--","W-IN-FG3950-1 #"])
 if ( index == 0 ):
 child.send(" ")
 else:
 child.sendline("diagnose sys session stat")
 break
child.expect('W-IN-FG3950-1 #')
child.sendline("get route info routing-table static")
child.expect('--More--')
child.send(' ')
child.expect('W-IN-FG3950-1 #')
child.sendline("exit")
05_06DMZ-S9306.py\#화 웨 이 S9306 인 터 랙 션 스 크 립 트

#!/usr/bin/env python
import pexpect
import sys
import datetime
 
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()
if int(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)
 
if ip == '  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('<JSYD-WX-12580-DMZ-9306')
child.sendline("su")
child.expect("(?i)assword:")
child.sendline("%s"%password)
child.expect("<JSYD-WX-12580-DMZ-9306")
child.sendline("dis device")
child.expect("<JSYD-WX-12580-DMZ-9306")
child.sendline("dis version | in Quidway")
child.expect("<JSYD-WX-12580-DMZ-9306")
child.sendline("dir")
child.expect("<JSYD-WX-12580-DMZ-9306")
child.sendline("dis cpu-usage")
index = child.expect(["(?i)---- More ----","<JSYD-WX-12580-DMZ-9306(?i)"])
if ( index == 0 ):
 child.send("a")
child.expect("<JSYD-WX-12580-DMZ-9306")
child.sendline("dis memory-usage")
child.expect("<JSYD-WX-12580-DMZ-9306")
child.sendline("dis int brief | in up")
child.expect("<JSYD-WX-12580-DMZ-9306")
child.sendline("dis vrrp brief")
child.expect("<JSYD-WX-12580-DMZ-9306")
child.sendline("dis mac-address total-number")
child.expect("<JSYD-WX-12580-DMZ-9306")
child.sendline("dis arp statistics all")
child.expect("<JSYD-WX-12580-DMZ-9306")
child.sendline("dis ip routing-table protocol static")
child.expect("<JSYD-WX-12580-DMZ-9306")
child.sendline("dis temperature all")
child.expect("<JSYD-WX-12580-DMZ-9306")
child.sendline("dis alarm all")
child.expect("<JSYD-WX-12580-DMZ-9306")
child.sendline("dis logbuffer | in %s"%tdy)
for i in range(50):
 index = child.expect(["(?i)---- More ----","<JSYD-WX-12580-DMZ-9306(?i)"])
 if ( index == 0 ):
 child.send(" ")
 else:
 child.sendline("q")
 break
07_08-S12508.py\#H3C S12508 대화 형 스 크 립 트

#!/usr/bin/env python
import pexpect
import sys
import datetime
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()
if int(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']
 
if ip == IP[0]:
 txt='07DMZ-S12508.txt'
 name='<W-DMZ-G1G2-12508>'
else:
 txt='08IN-S12508.txt'
 name='<W-IN-G7G8-12508>'
 
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("dis device | ex Normal")
child.expect("%s"%name)
child.sendline("dis version | in H3C S12508")
child.expect("%s"%name)
child.sendline("dir")
child.expect("%s"%name)
child.sendline("dis memory")
child.expect("%s"%name)
child.sendline("dis irf link")
for i in range(10):
 index = child.expect(["(?i)---- More ----","%s"%name])
 if ( index == 0 ):
 child.send(" ")
 else:
 child.sendline("dis int brief | in UP")
 break
for i in range(20):
 index = child.expect(["(?i)---- More ----","%s"%name])
 if ( index == 0 ):
 child.send(" ")
 else:
 child.sendline("dis mac-address count")
 break
child.expect("%s"%name)
child.sendline("dis arp all count")
if ip == "    ":
 child.expect("%s"%name)
 child.sendline("dis ip routing-table vpn-instance Dmz protocol static")
 for i in range(20):
 index = child.expect(["(?i)---- More ----","%s"%name])
 if ( index == 0 ):
 child.send(" ")
 else:
 child.sendline("dis ip routing-table vpn-instance Inside protocol static")
 for i in range(20):
 index = child.expect(["(?i)---- More ----","%s"%name])
 if ( index == 0 ):
  child.send(" ")
 else:
  child.sendline(" ")
  break
 break
child.expect("%s"%name)
child.sendline("dis environment")
for i in range(50):
 index = child.expect(["(?i)---- More ----","%s"%name])
 if ( index == 0 ):
 child.send(" ")
 else:
 child.sendline("dis alarm")
 break
child.expect("%s"%name)
child.sendline("dis logbuffer | in %s"%tdy)
 
for i in range(50):
 index = child.expect(["(?i)---- More ----","%s"%name])
 if ( index == 0 ):
 child.send(" ")
 else:
 child.sendline("q")
 sys.exit()
09_10SM-N7K.py\#Cisco N7K 인 터 랙 션 스 크 립 트

#!/usr/bin/env python
import pexpect
import sys
import datetime
today=datetime.date.today().strftime('%Y%m%d')
 
ip=str(sys.argv[1])
passwd=str(sys.argv[2])
 
child=pexpect.spawn('telnet %s'%ip)
 
 
if ip == '  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("sh hardware | in ok")
child.expect("%s"%name)
child.sendline("sh version | in uptime")
child.expect("%s"%name)
child.sendline("dir")
child.expect("%s"%name)
child.sendline("sh int brief | in up")
for i in range(10):
 index = child.expect(["(?i)More--","%s"%name])
 if ( index == 0 ):
 child.send(" ")
 else:
 child.sendline("sh hsrp brief")
 break
child.expect("%s"%name)
child.sendline("sh mac address-table count")
child.expect("%s"%name)
child.sendline("sh ip arp | in number")
child.expect("%s"%name)
child.sendline("sh ip route static summary")
child.expect("%s"%name)
child.sendline("sh environment temperature")
for i in range(10):
 index = child.expect(["(?i)More--","%s"%name])
 if ( index == 0 ):
 child.send(" ")
 else:
 child.sendline("sh vpc")
 break
for i in range(10):
 index = child.expect(["(?i)More--","%s"%name])
 if ( index == 0 ):
 child.send(" ")
 else:
 child.sendline("sh logging last 30")
 break
for i in range(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/env python
import pexpect
import sys
import datetime
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()
if int(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']
 
if ip == IP[0]:
 txt='11DMZ-NE40E-1.txt'
 name='<W-SM-E11-NE40E-01>'
elif ip == IP[1]:
 txt='12DMZ-NE40E-2.txt'
 name='<W-SM-E12-NE40E-02>'
else:
 print "IP Input Error!"
 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("dis device | ex Normal")
child.expect("%s"%name)
child.sendline("dis version | in NE40E-X8 uptime")
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("dis memory-usage")
else:
 child.sendline("dis memory-usage")
child.expect("%s"%name)
child.sendline("dis int brief | in up")
child.expect("%s"%name)
child.sendline("dis ip routing-table protocol static")
child.expect("%s"%name)
child.sendline("dis temperature")
for i in range(40):
 index = child.expect(["(?i)---- More ----","%s"%name])
 if ( index == 0 ):
 child.send(" ")
 else:
 child.sendline("dis alarm all")
 break
child.expect("%s"%name)
child.sendline("dis logbuffer | in %s"%tdy)
for i in range(30):
 index = child.expect(["(?i)---- More ----","%s"%name])
 if ( index == 0 ):
 child.send(" ")
 else:
 child.sendline("q")
 break
13_16-RD5412_6420.py\#Radware RD 5412 인 터 랙 션 스 크 립 트,하나만 파악 하면 나머지 는 모두 세트 입 니 다.

#!/usr/bin/env python
import pexpect
import sys
import datetime
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()
if int(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']
 
if ip == IP[0]:
 txt='13DMZ-RD5412-1.txt'
elif ip == IP[1]:
 txt='14DMZ-RD5412-2.txt'
elif ip == IP[2]:
 txt='15SM-RD6420-1.txt'
elif ip == IP[3]:
 txt='16SM-RD6420-2.txt'
else:
 print "IP Input Error!"
 sys.exit()
name='Standalone ADC(?i)'
 
fout=file('/usr/sh/shell/linux/xunjian/'+today+'/'+txt,'w')
child.logfile = fout
child.expect('(?i)ssword:')
child.sendline("%s"%passwd)
if ip == 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(["Press q to quit, any other key to continue","%s"%name])
if ( index == 0 ):
 child.send(" ")
 index = child.expect(["Press q to quit, any other key to continue","%s"%name])
 if ( index == 0 ):
 child.send(" ")
 else:
 child.sendline("/i/sys/capacity slb")
else:
 child.sendline("/i/sys/capacity slb")
index = child.expect(["Press q to quit, any other key to continue","%s"%name])
if ( index == 0 ):
 child.send(" ")
 index = child.expect(["Press q to quit, any other key to continue","%s"%name])
 if ( index == 0 ):
 child.send(" ")
 index = child.expect(["Press q to quit, any other key to continue","%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")
for i in range(50):
 index = child.expect(["Press q to quit, any other key to continue","%s"%name])
 if ( index == 0 ):
 child.send(" ")
 else:
 child.sendline("exit")
 break
#index = child.expect(["(?i)n]:","%s"%name])
#if ( index == 0 ):
if ip == 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 -*-
from email.header import Header
import smtplib 
import email.MIMEMultipart# import MIMEMultipart 
import email.MIMEText# import MIMEText 
import email.MIMEBase# import MIMEBase 
import os.path 
import sys 
import mimetypes 
import email.MIMEImage# import MIMEImage 
import datetime
 
 
tday=datetime.date.today().strftime('%Y/%m/%d')
#   mail.py <1:   (    )[email protected]> <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("[email protected]","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) 
if ctype is None or encoding is not None: 
 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\#오류 알림 메 일:엑셀 이 존재 하지 않 습 니 다.

#!/usr/bin/env python
# -*- coding:utf-8 -*-
#import sys
#reload(sys)
import smtplib,string,datetime,xlrd
 
tday=datetime.date.today().strftime('%Y/%m/%d')
HOST="smtp.139.com"
SUBJECT="[    ] %s   "%tday
TO="*.com"
FROM="*@139.com"
 
text="excel no cunzai"
 
BODY=string.join((
 "FROM: %s" % FROM,
 "To: %s" % TO,
 "Subject: %s" % SUBJECT,
 "",
 text
 ), "\r
") 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/env python
# -*- coding:utf-8 -*-
#import sys
#reload(sys)
import smtplib,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="zip no cunzai"
 
BODY=string.join((
 "FROM: %s" % FROM,
 "To: %s" % TO,
 "Subject: %s" % SUBJECT,
 "",
 text
 ), "\r
") 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/env python
# -*- coding:utf-8 -*-
#import sys
#reload(sys)
import xlsxwriter,os,datetime
 
def cmd(sname,fname):  #                   
 i=1
 f=open(fname)
 line_hang_list=[]
 for line in f:
 if line.find(sname) == 0:
 line_hang_list.append(i)
 i+=1
 f.close
 return line_hang_list
 
def cmd1(sname,fname): #   
 i=1
 f=open(fname)
 line_hang_list=[]
 for line in f:
 if sname in line:
 line_hang_list.append(i)
 i+=1
 f.close
 return line_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=['dis device | ex Normal','dis version','dis temperature','dir',u' BOMC ','dis memory-usage','dis hrp state','dis firewall session table','dis ip routing-table protocol static','dis int brief (dis logbuffer | in DOWN)','dis acl 3004 (3004-3007)','dis alarm all','dis logbuffer | in [data]','dis device | ex Normal','dis version | in uptime','dis environment','dir | in total',u' BOMC ','dis memory','dis irf link','dis redundancy group','dis session statistics summary','dis ip routing-table protocol static','dis int brief (dis logbuffer | in DOWN)','dis object-policy ip','dis alarm','dis logbuffer | in [month]','dis device | ex Normal','dis version | in uptime','dis environment','dir | in total',u' BOMC ','dis memory','dis irf link','dis redundancy group','dis session statistics summary','dis ip routing-table protocol static','dis int brief (dis logbuffer | in DOWN)','dis acl all','dis alarm','dis logbuffer | in [month]','get sys performance status','','','','diagnose sys session stat','',u'      ',u'      ','get route info routing table static',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'      (acl 3001+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=['dis device','dis version | in Quidway','dir','dis cpu-usage','dis memory-usage','dis int brief (dis logbuffer | in IF_STATE)','dis vrrp brief','dis mac-address total-number','dis arp statistics all','dis ip routing-table protocol static','dis temperature all','dis alarm all','dis logbuffer | in [date]']
 
switch_cmmd=['dis device | ex Normal','dis version | in H3C S12508','dir',u' BOMC ','dis memory','dis irf link','dis int brief (dis logbuffer reverse | in UPDOWN)','dis mac-address count','dis arp all count','dis ip routing-table vpn-instance Dmz/Inside protocol static','dis environment','dis alarm','dis logbuffer reverse | in [date]']
 
switch_cmd1=['dis device | ex Normal','dis version | in H3C S12508','dir',u' BOMC ','dis memory','dis int brief (dis logbuffer reverse | in UPDOWN)','dis vrrp','dis mac-address count','dis arp all count','dis ip routing-table protocol static','dis environment','dis alarm','dis logbuffer reverse | in [date]']
 
switch_cmd2=['dis device | ex Normal','dis version | in H3C S12508','dir',u' BOMC ','dis memory','dis irf link','dis int brief (dis logbuffer reverse | in UPDOWN)','dis mac-address count','dis arp all count','dis environment','dis alarm','dis logbuffer reverse | 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=['dis device | ex Normal','dis version | in NE40E-X8 uptime','dir',u' BOMC ','dis memory-usage','dis int brief (dis logbuffer | in IF_STATE)','dis ip routing-table protocol static','dis temperature','dis alarm all','dis logbuffer | 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/capacity slb','/stats/mp/cpu','/stats/mp/mem','/i/sys/temp','/i/l3/vrrp','/i/sys/log']
 
fuzai_sm=[u'       ,   ',u'      ',u'      ',u'  Link  UP      ',u'  real servers/server groups/virtual servers/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=['sh hardware | in ok','sh version | in uptime','dir',u' BOMC ',u' BOMC ','sh int brief (sh int brief | in up)','sh hsrp brief','sh mac address-table count','sh ip arp | in number','sh ip route static summary','sh environment temperature','sh vpc','sh logging last 30']
 
newsmswitch_sm=[u'     OK    ',u'       ,   ',u'  total free flash  ',u'  CPU         ',u'       ',u'     UP     ',u'  HSRP  (Active local   )',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','get sys performance status',format_nrr)
worksheet0.merge_range('E47:E48','diagnose sys session stat',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','dis logbuffer | in [data]',format_bottom)
worksheet0.write('F14',u'      ,      “  ”',format_bottom)
worksheet0.write('D28',u'  ',format_bottom)
worksheet0.write('E28','dis logbuffer reverse | in [month]',format_bottom)
worksheet0.write('F28',u'      ,      “  ”',format_bottom)
worksheet0.write('D42',u'  ',format_bottom)
worksheet0.write('E42','dis logbuffer reverse | 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'  ','dis logbuffer | in [date]',u'      ,      “  ”']
jcx1=[u'  ','dis logbuffer reverse | in [date]',u'      ,      “  ”']
jcx2=[u'  ','sh logging last 30',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<JSYD-WX-12580-DMZ-E8000E-1>",file_01)
 rules=[]
 g=0
 with open(file_01) as f:
 for each_line in f:
  num=each_line.split()
  if hang > int(hang_list[1]) and hang < int(hang_list[2]):
  if int(hang_list[2])-int(hang_list[1]) == 6:
  worksheet0.write('G2',u'  ',format_rt)
  else:
  worksheet0.write('G2','ERROR',format_red)
  if hang > int(hang_list[2]) and hang < int(hang_list[3]):
  if num!=[]:
  if num[0] == 'HUAWEI':
   worksheet0.write('G3',u'%s ,%s  '%(num[4],num[6]),format_rt)
  if hang > int(hang_list[3]) and hang < int(hang_list[4]):
  if num!=[]:
  if len(num) == 11:
   temp.append(num[-1])
  if hang > int(hang_list[4]) and hang < int(hang_list[5]):
  if num!=[]:
  if ',' in num[0]:
   total=num[0].replace(',','')+' KB '+num[3].replace(',','')+' KB)'
   worksheet0.write('G5',total,format_rt)
  if hang > int(hang_list[5]) and hang < int(hang_list[6]):
  if num!=[]:
  if num[0] == 'Memory':
   worksheet0.write('G7',num[-1],format_rt)
  if hang > int(hang_list[6]) and hang < int(hang_list[7]):
  if num!=[]:
  if num[0] == 'Role:':
   if num[1] == 'active,' and num[-1] == 'standby':
   worksheet0.write('G8',u'  ',format_rt)
   else:
   worksheet0.write('G8',u' ',format_red)
  if hang > int(hang_list[7]) and hang < int(hang_list[8]):
  if num!=[]:
  if num[0] == 'Current':
   worksheet0.write('G9',str(num[-1]),format_rt)
  if hang > int(hang_list[8]) and hang < int(hang_list[9]):
  if num!=[]:
  if num[0] == 'Destinations' and len(num) == 10:
   worksheet0.write('G10',str(num[2]),format_rt)
  if hang > int(hang_list[9]) and hang < int(hang_list[10]):
  if num!=[]:
  if len(num) == 7:
   if num[1] == 'up':
   g+=1
  if hang > int(hang_list[10]) and hang < int(hang_list[14]):
  if num!=[]:
  if num[0] == 'Advanced':
   rules.append(num[3])
  if hang > int(hang_list[14]) and hang < int(hang_list[15]):
  if int(hang_list[-2])-int(hang_list[-3]) == 8:
  worksheet0.write('G13',u'   ',format_rt)
  else:
  worksheet0.write('G13',u'   ',format_red)
  if hang > int(hang_list[15]) and hang < int(hang_list[16]):
  pass
  hang = hang + 1
 temp.sort()
 worksheet0.write('G4',u'%s℃-%s℃'%(temp[0],temp[-1]),format_rt)
 worksheet0.write('G6',None,format_rt)
 worksheet0.write('G11',g,format_rt)
 worksheet0.write('G12','%s+%s+%s+%s=%d'%(rules[0],rules[1],rules[2],rules[3],int(rules[0])+int(rules[1])+int(rules[2])+int(rules[3])),format_rt)
 worksheet0.write('G14',u'  ',format_right)
except IOError as reason:
 print "01DMZ-E8000E.py "+str(reason)
 
 
 
#------------------------------------------------
#----------firewall_iP2----------------
#------------------------------------------------
try:
 hang=1
 state=dict()
 hang_list=cmd("<W-12580-M9006>",file_02_2)
 temp=[]
 rules=0
 mem=[]
 g=0
 all=0
 n=0
 level=0
 q=0
 status=0
 type=0
 with open(file_02_2) as f:
 for each_line in f:
  num=each_line.split()
  if hang > int(hang_list[0]) and hang < int(hang_list[1]):
  if num!=[]:
  if num[0].isdigit() and len(num) == 7:
   if num[3] == 'Absent':
   if num[2] != 'NONE':
   type=1
  if hang > int(hang_list[1]) and hang < int(hang_list[2]):
  if num!=[]:
  if len(num) == 13:
   worksheet0.write('G16',u'%d ,%s  '%(int(num[5])*7+int(num[7]),num[9]),format_rt)
  if hang > int(hang_list[2]) and hang < int(hang_list[3]):
  if num!=[]:
  if len(num) == 9:
   temp.append(num[4])
  if hang > int(hang_list[3]) and hang < int(hang_list[4]):
  if num!=[]:
  if len(num) == 6:
   total='%s KB %s KB)'%(num[0],num[3])
   worksheet0.write('G18',total,format_rt)
  if hang > int(hang_list[4]) and hang < int(hang_list[5]):
  if num!=[]:
  if len(num) == 8:
   if num[-1] != 'KB:':
   result='%.1f%%'%(100-float(num[-1].split('%')[0]))
   mem.append(result)
  if hang > int(hang_list[5]) and hang < int(hang_list[6]):
  if num!=[]:
  if 'GigabitEthernet' in num[1]:
   if num[2] != 'UP':
   status+=1
  if 'GigabitEthernet' in num[0]:
   if num[1] != 'UP':
   status+=1
  if hang > int(hang_list[6]) and hang < int(hang_list[7]):
  if num!=[]:
  if num[0].isdigit() and len(num) == 5:
   if num[3] != 'Primary' and num[3] != 'Secondary':
   q=1
  if hang > int(hang_list[7]) and hang < int(hang_list[8]):
  if num!=[]:
  if num[0].isdigit() and len(num) == 9:
   g+=1
  if hang > int(hang_list[8]) and hang < int(hang_list[9]):
  if num!=[]:
  if num[0] == 'Summary':
   state[n]=num[3]
   n+=1
  if hang > int(hang_list[9]) and hang < int(hang_list[10]):
  if num!=[]:
  if len(num) >= 4 and num[1] == 'UP':
   all+=1
  if hang > int(hang_list[10]) and hang < int(hang_list[12]):
  if num!=[]:
  if num[0] == 'rule':
   rules+=1
  if hang > int(hang_list[12]) and hang < int(hang_list[13]):
  if num!=[]:
  if num[0].isdigit() and len(num) >5:
   if num[3] != 'INFO':
   level=1
  if hang > int(hang_list[13]) and hang < int(hang_list[14]):
  pass
  hang+=1
 temp.sort()
 mem.sort()
 if type == 0:
  worksheet0.write('G15',u'  ',format_rt)
 else:
  worksheet0.write('G15','ERROR',format_red)
 worksheet0.write('G17',u'%s℃-%s℃'%(temp[0],temp[-1]),format_rt)
 worksheet0.write('G19',None,format_rt)
 worksheet0.write('G20','%s-%s'%(mem[0],mem[-1]),format_rt)
 if status == 0:
  worksheet0.write('G21',u'  ',format_rt)
 else:
  worksheet0.write('G21',status,format_rt)
 if q == 0:
  worksheet0.write('G22',u'  ',format_rt)
 else:
  worksheet0.write('G22',u' ',format_red)
 worksheet0.write('G23',g,format_rt)
 worksheet0.write('G24',state[0],format_rt)
 worksheet0.write('G25',all,format_rt)
 worksheet0.write('G26','%d'%rules,format_rt)
 if level == 1:
  worksheet0.write('G27','ERROR',format_red)
 else:
  worksheet0.write('G27',u'   ',format_rt)
 worksheet0.write('G28',u'  ',format_right)
except IOError as reason:
 print "02DMZ-M9006.py "+str(reason)
 
 
 
 
 
#------------------------------------------------
#----------firewall_ip3----------------
#------------------------------------------------
try:
 hang=1
 state=dict()
 hang_list=cmd("<W-SM-M9006>",file_02_1)
 temp=[]
 rules=[]
 mem=[]
 g=0
 all=0
 n=0
 level=0
 q=0
 status=0
 type=0
 with open(file_02_1) as f:
 for each_line in f:
  num=each_line.split()
  if hang > int(hang_list[0]) and hang < int(hang_list[1]):
  if num!=[]:
  if num[0].isdigit() and len(num) == 7:
   if num[3] == 'Absent':
   if num[2] != 'NONE':
   type=1
  if hang > int(hang_list[1]) and hang < int(hang_list[2]):
  if num!=[]:
  if len(num) == 13:
   worksheet0.write('G30',u'%d ,%s  '%(int(num[5])*7+int(num[7]),num[9]),format_rt)
  if hang > int(hang_list[2]) and hang < int(hang_list[3]):
  if num!=[]:
  if len(num) == 9:
   temp.append(num[4])
  if hang > int(hang_list[3]) and hang < int(hang_list[4]):
  if num!=[]:
  if len(num) == 6:
   total='%s KB %s KB)'%(num[0],num[3])
   worksheet0.write('G32',total,format_rt)
  if hang > int(hang_list[4]) and hang < int(hang_list[5]):
  if num!=[]:
  if len(num) == 8:
   if num[-1] != 'KB:':
   result='%.1f%%'%(100-float(num[-1].split('%')[0]))
   mem.append(result) 
  if hang > int(hang_list[5]) and hang < int(hang_list[6]):
  if num!=[]:
  if 'GigabitEthernet' in num[1]:
   if num[2] != 'UP':
   status=1
  if 'GigabitEthernet' in num[0]:
   if num[1] != 'UP':
   status=1
  if hang > int(hang_list[6]) and hang < int(hang_list[7]):
  if num!=[]:
  if num[0].isdigit() and len(num) == 5:
   if num[3] != 'Primary' and num[3] != 'Secondary':
   q=1
  if hang > int(hang_list[7]) and hang < int(hang_list[8]):
  if num!=[]:
  if num[0].isdigit() and len(num) == 9:
   g+=1
  if hang > int(hang_list[8]) and hang < int(hang_list[9]):
  if num!=[]:
  if num[0] == 'Summary':
   state[n]=num[3]
   n+=1
  if hang > int(hang_list[9]) and hang < int(hang_list[10]):
  if num!=[]:
  if len(num) >= 4 and num[1] == 'UP':
   all+=1
  if hang > int(hang_list[10]) and hang < int(hang_list[12]):
  if num!=[]:
  if num[0] == 'Advanced':
   rules.append(num[5])
  if hang > int(hang_list[12]) and hang < int(hang_list[13]):
  if num!=[]:
  if num[0].isdigit() and len(num) >5:
   if num[3] != 'INFO':
   level=1
  if hang > int(hang_list[13]) and hang < int(hang_list[14]):
  pass 
  hang+=1
 temp.sort()
 mem.sort()
 if type == 0:
  worksheet0.write('G29',u'  ',format_rt)
 else:
  worksheet0.write('G29','ERROR',format_red)
 worksheet0.write('G31',u'%s℃-%s℃'%(temp[0],temp[-1]),format_rt)
 worksheet0.write('G33',None,format_rt)
 worksheet0.write('G34','%s-%s'%(mem[0],mem[-1]),format_rt)
 if status == 0:
  worksheet0.write('G35',u'  ',format_rt)
 else:
  worksheet0.write('G35','ERROR',format_red)
 if q == 0:
  worksheet0.write('G36',u'  ',format_rt)
 else:
  worksheet0.write('G36',u' ',format_red)
 worksheet0.write('G37',g,format_rt)
 worksheet0.write('G38',state[0],format_rt)
 worksheet0.write('G39',all,format_rt)
 worksheet0.write('G40','%s+%s=%d'%(rules[0],rules[1],int(rules[0])+int(rules[1])),format_rt)
 if level == 1:
  worksheet0.write('G41','ERROR',format_red)
 else:
  worksheet0.write('G41',u'   ',format_rt)
 worksheet0.write('G42',u'  ',format_right)
except IOError as reason:
 print "03SM-M9006.py "+str(reason)
 
 
#------------------------------------------------
#----------firewall_ip4----------------
#------------------------------------------------
 
try:
 hang=1
 g=0
 hang_list=cmd("W-IN-FG3950-1 #",file_03)
 with open(file_03) as f:
 for each_line in f:
  num=each_line.split()
  if hang > int(hang_list[0]) and hang < int(hang_list[1]):
  if num!=[]:
  if num[0] == 'Memory':
   worksheet0.write('G45',num[2],format_rt)
  if len(num) == 8 and num[1] == 'Uptime:':
   worksheet0.write('G43',u'%s ,%s  '%(num[2],num[4]),format_rt)
  if num[0] == 'Average':
   if num[1] == 'network':
   worksheet0.write('G46',num[-5],format_rt)
  if hang > int(hang_list[1]) and hang < int(hang_list[2]):
  if num!=[]:
  if num[0] == "misc":
   session_count=num[2].split('=')
   setup_rate=num[3].split('=')
   worksheet0.write('G47',session_count[-1],format_rt)
   worksheet0.write('G48',setup_rate[-1],format_rt)
  if hang > int(hang_list[2]) and hang < int(hang_list[3]):
  if num!=[]:
  if 'S' in num[0] and len(num) >= 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)
except IOError as reason:
 print "04IN-FG3950B.py "+str(reason)
 
#------------------------------------------------
#------------switch_ip5----------------
#------------switch_ip6----------------
#------------------------------------------------
try:
 for i in range(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('<JSYD-WX-12580-DMZ-9306-%d>'%(i+1),file)
 with open(file) as f:
  for each_line in f:
  num=each_line.split()
  if hang > int(hang_list[1]) and hang < int(hang_list[2]):
  if num!=[]:
   if len(num) == 8 and num[1] == '-':
   if num[-2] != 'Normal':
   alarm=1
  if hang > int(hang_list[2]) and hang < int(hang_list[3]):
  if num!=[]:
   if num[0] == 'Quidway':
   worksheet1.write('G'+str(index[i][1]),u'%d , %s  '%(int(num[7])*7+int(num[9]),num[11]),format_rt)
  if hang > int(hang_list[3]) and hang < int(hang_list[4]):
  if num!=[]:
   if len(num) == 6 and num[1] == 'KB':
   mem=num[0].split(',')
   free=num[3].split(',')
   worksheet1.write('G'+str(index[i][2]),'%s KB %s KB)'%(mem[0]+mem[1],free[0]+free[1]),format_rt)
  if hang > int(hang_list[4]) and hang < int(hang_list[5]):
  if num!=[]:
   if len(num) == 6 and num[4] == 'Max:':
   worksheet1.write('G'+str(index[i][3]),num[3],format_rt)
  if hang > int(hang_list[5]) and hang < int(hang_list[6]):
  if num!=[]:
   if len(num) == 5 and num[0] == 'Memory':
   worksheet1.write('G'+str(index[i][4]),num[-1],format_rt)
  if hang > int(hang_list[6]) and hang < int(hang_list[7]):
  if num!=[]:
   if len(num) >=6 and num[1] == 'up':
   state+=1
  if hang > int(hang_list[7]) and hang < int(hang_list[8]):
  if num!=[]:
   if num[0].isdigit() and len(num) == 5:
   if i == 0 and num[1] != 'Master':
   status=1
   if i == 1 and num[1] != 'Backup':
   status=1
  if hang > int(hang_list[8]) and hang < int(hang_list[9]):
  if num!=[]:
   if num[0] == 'Total':
   worksheet1.write('G'+str(index[i][7]),num[-1],format_rt)
  if hang > int(hang_list[9]) and hang < int(hang_list[10]):
  if num!=[]:
   if num[0] == 'Dynamic:':
   worksheet1.write('G'+str(index[i][8]),num[1],format_rt)
  if hang > int(hang_list[10]) and hang < int(hang_list[11]):
  if num!=[]:
   if num[0] == 'Destinations' and len(num) == 10:
   worksheet1.write('G'+str(index[i][9]),num[2],format_rt)
  if hang > int(hang_list[11]) and hang < int(hang_list[12]):
  if num!=[]:
   if len(num) >= 6 and num[-5].isdigit():
   temp=num[-1].split('.')
   temp_list.append(temp[0])
  if hang > int(hang_list[12]) and hang < int(hang_list[13]):
  if num!=[]:
   if len(num) == 2 and num[0] == 'NO' and num[1] == 'alarm':
   alm = 1
  if hang > int(hang_list[13]) and hang < int(hang_list[14]):
  if num!=[]:
   pass
  hang+=1
  temp_list.sort()
  if alarm == 0:
  worksheet1.write('G'+str(index[i][0]),u'  ',format_rt)
  else:
  worksheet1.write('G'+str(index[i][0]),'ERROR',format_red)
  worksheet1.write('G'+str(index[i][5]),state,format_rt)
  if i == 0:
  if status == 0:
  worksheet1.write('G'+str(index[i][6]),'Master',format_rt)
  else:
  worksheet1.write('G'+str(index[i][6]),'No Master',format_red)
  else:
  if status == 0:
  worksheet1.write('G'+str(index[i][6]),'Backup',format_rt)
  else:
  worksheet1.write('G'+str(index[i][6]),'No Backup',format_red)
  worksheet1.write('G'+str(index[i][10]),u'%s℃-%s℃'%(temp_list[0],temp_list[-1]),format_rt)
  if alm == 1:
  worksheet1.write('G'+str(index[i][11]),u'   ',format_rt)
  else:
  worksheet1.write('G'+str(index[i][11]),u'   ',format_red)
  worksheet1.write('G'+str(index[i][12]),u'  ',format_right)
  
except IOError as reason:
 print "05_06DMZ-S9306.py "+str(reason)
 
#------------------------------------------------
#------------switch_ip7----------------
#------------switch_ip8----------------
#------------------------------------------------
 
try:
 fi_list=['07DMZ-S12508.txt']
 fi_name=['<W-DMZ-G1G2-12508>']
 state=[]
 for i in range(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))}
 with open(file) as f:
  for each_line in f:
  num=each_line.split()
  if hang > int(hang_list[1]) and hang < int(hang_list[2]):
  if num!=[]:
   if num[0].isdigit() and len(num) == 4:
   if num[2] not in brd_status:
   brd=1
  if hang > int(hang_list[2]) and hang < int(hang_list[3]):
  if num!=[]:
   if len(num) == 12:
   worksheet1.write('G'+str(index[i][1]),u'%d , %s  '%(int(num[4])*7+int(num[6]),num[8]),format_rt)
  if hang > int(hang_list[3]) and hang < int(hang_list[4]):
  if num!=[]:
   if len(num) == 6 and num[1] == 'KB':
   worksheet1.write('G'+str(index[i][2]),'%s KB %s KB)'%(num[0],num[3]),format_rt)
  if hang > int(hang_list[4]) and hang < int(hang_list[5]):
  if num!=[]:
   if num[0] == 'Used':
   worksheet1.write('G'+str(index[i][4]),num[-1],format_rt)
  if hang > int(hang_list[5]) and hang < int(hang_list[6]):
  if num!=[]:
   if 'GigabitEthernet' in num[1]:
   if num[2] != 'UP':
   status+=1
   if 'GigabitEthernet' in num[0]:
   if num[1] != 'UP':
   status+=1 
  if hang > int(hang_list[6]) and hang < int(hang_list[7]):
  if num!=[]:
   if len(num) >=2 and num[1] == 'UP':
   link+=1
   #if num[0] == '----' and num[5] == 'UP':
   # link+=1
  if hang > int(hang_list[7]) and hang < int(hang_list[8]):
  if num!=[]:
   if num[0].isdigit():
   worksheet1.write('G'+str(index[i][7]),num[0],format_rt)
  if hang > int(hang_list[8]) and hang < int(hang_list[9]):
  if num!=[]:
   if num[0] == 'Total' and num[-1].isdigit():
   worksheet1.write('G'+str(index[i][8]),num[-1],format_rt)
  if hang > int(hang_list[9]) and hang < int(hang_list[11]):
  if num!=[]:
   if num[0] == 'Summary' and num[-1].isdigit():
   count.append(num[-1])
  if hang > int(hang_list[11]) and hang < int(hang_list[12]):
  pass
  if hang > int(hang_list[12]) and hang < int(hang_list[13]):
  if num!=[]:
   if len(num) >= 8:
   if num[3].isdigit():
   temp.append(num[3])
   if num[0] == '----' and num[1] == 'More':
   temp.append(num[7])
  if hang > int(hang_list[13]) and hang < int(hang_list[14]):
  if num!=[]:
   if num[0] == 'No' and num[1] == 'alarm':
   alarm=1
  if hang > int(hang_list[14]) and hang < int(hang_list[15]):
  if num!=[]:
   pass
  hang+=1
  temp.sort()
  if brd == 0:
  worksheet1.write('G'+str(index[i][0]),u'  ',format_rt)
  else:
  worksheet1.write('G'+str(index[i][0]),'ERROR',format_red)
  if status == 0:
  worksheet1.write('G'+str(index[i][5]),u'  ',format_rt)
  else:
  worksheet1.write('G'+str(index[i][5]),status,format_rt)
  worksheet1.write('G'+str(index[i][3]),None,format_rt)
  worksheet1.write('G'+str(index[i][6]),link,format_rt)
  worksheet1.write('G'+str(index[i][9]),int(count[1])+int(count[-2]),format_rt)
  worksheet1.write('G'+str(index[i][10]),u'%s℃-%s℃'%(temp[0],temp[-1]),format_rt)
  if alarm == 1:
  worksheet1.write('G'+str(index[i][11]),u'   ',format_rt)
  else:
  worksheet1.write('G'+str(index[i][11]),'Error',format_red)
  worksheet1.write('G'+str(index[i][12]),u'  ',format_right)
except IOError as reason:
 print "07_08-S12508-01.py"+str(reason)
 
 
try:
 fi_list=['08IN-S12508.txt']
 fi_name=['<W-IN-G7G8-12508>']
 state=[]
 for i in range(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(41,53))}
 with open(file) as f:
  for each_line in f:
  num=each_line.split()
  if hang > int(hang_list[1]) and hang < int(hang_list[2]):
  if num!=[]:
   if num[0].isdigit() and len(num) == 4:
   if num[2] not in brd_status:
   brd=1
  if hang > int(hang_list[2]) and hang < int(hang_list[3]):
  if num!=[]:
   if len(num) == 12:
   worksheet1.write('G'+str(index[i][1]),u'%d , %s  '%(int(num[4])*7+int(num[6]),num[8]),format_rt)
  if hang > int(hang_list[3]) and hang < int(hang_list[4]):
  if num!=[]:
   if len(num) == 6 and num[1] == 'KB':
   worksheet1.write('G'+str(index[i][2]),'%s KB %s KB)'%(num[0],num[3]),format_rt)
  if hang > int(hang_list[4]) and hang < int(hang_list[5]):
  if num!=[]:
   if num[0] == 'Used':
   worksheet1.write('G'+str(index[i][4]),num[-1],format_rt)
  if hang > int(hang_list[5]) and hang < int(hang_list[6]):
  if num!=[]:
   if 'GigabitEthernet' in num[1]:
   if num[2] != 'UP':
   status+=1
   if 'GigabitEthernet' in num[0]:
   if num[1] != 'UP':
   status+=1
  if hang > int(hang_list[6]) and hang < int(hang_list[7]):
  if num!=[]:
   if len(num) >=2 and num[1] == 'UP':
   link+=1
   #if num[0] == '----' and num[5] == 'UP':
   # link+=1
  if hang > int(hang_list[7]) and hang < int(hang_list[8]):
  if num!=[]:
   if num[0].isdigit():
   worksheet1.write('G'+str(index[i][7]),num[0],format_rt)
  if hang > int(hang_list[8]) and hang < int(hang_list[9]):
  if num!=[]:
   if num[0] == 'Total' and num[-1].isdigit():
   worksheet1.write('G'+str(index[i][8]),num[-1],format_rt)
  if hang > int(hang_list[9]) and hang < int(hang_list[10]):
  if num!=[]:
   if len(num) >= 8:
   if num[3].isdigit():
   temp.append(num[3])
   if num[0] == '----' and num[1] == 'More':
   temp.append(num[7])
  if hang > int(hang_list[10]) and hang < int(hang_list[11]):
  if num!=[]:
   if num[0] == 'No' and num[1] == 'alarm':
   alarm=1
  if hang > int(hang_list[11]) and hang < int(hang_list[12]):
  if num!=[]:
   pass
  hang+=1
  temp.sort()
  if brd == 0:
  worksheet1.write('G'+str(index[i][0]),u'  ',format_rt)
  else:
  worksheet1.write('G'+str(index[i][0]),'ERROR',format_red)
  if status == 0:
  worksheet1.write('G'+str(index[i][5]),u'  ',format_rt)
  else:
  worksheet1.write('G'+str(index[i][5]),status,format_rt)
  worksheet1.write('G'+str(index[i][3]),None,format_rt)
  worksheet1.write('G'+str(index[i][6]),link,format_rt)
  worksheet1.write('G'+str(index[i][9]),u'%s℃-%s℃'%(temp[0],temp[-1]),format_rt)
  if alarm == 1:
  worksheet1.write('G'+str(index[i][10]),u'   ',format_rt)
  else:
  worksheet1.write('G'+str(index[i][10]),'Error',format_red)
  worksheet1.write('G'+str(index[i][11]),u'  ',format_right)
except IOError as reason:
 print "07_08-S12508-02.py"+str(reason)
 
 
 
#------------------------------------------------
#------------switch_ip9----------------
#------------switch_ip10----------------
#------------------------------------------------
 
try:
 fi_list=['09SM-N7K-1.txt','10SM-N7K-2.txt']
 fi_name=['W-SM-N7K-1#','W-SM-N7K-2#']
 state=[]
 for i in range(2):
 hang=1
 file='/usr/sh/shell/linux/xunjian/'+str(today)+'/'+fi_list[i]
 hang_list=cmd1(fi_name[i],file)
 index={0:list(range(53,66)),1:list(range(66,79))}
 count1 = 0
 count2 = 0
 count3 = 0
 temp = []
 with open(file) as f:
  for each_line in f:
  num=each_line.split()
  if hang > int(hang_list[0]) and hang < int(hang_list[1]):
  if num!=[]:
   if num[1] == 'ok':
   count1 +=1
  if hang > int(hang_list[1]) and hang < int(hang_list[2]):
  if num!=[]:
   if num[0] == 'Kernel':
   uptime = u'%s ,%s  '%(num[3],num[5])
  if hang > int(hang_list[2]) and hang < int(hang_list[3]):
  if num!=[]:
   if len(num) == 3:
   if num[-1] == 'free':
   free = num[0]
   if num[-1] == 'total':
   total = num[0]
  if hang > int(hang_list[3]) and hang < int(hang_list[4]):
  if num!=[]:
   if len(num) >= 3:
   if num[2] == 'up' or num[4] == 'up' or num[5] == 'up':
   count2 +=1
  if hang > int(hang_list[4]) and hang < int(hang_list[5]):
  if num!=[]:
   pass
  if hang > int(hang_list[5]) and hang < int(hang_list[6]):
  if num!=[]:
   if num[-1].isdigit():
   count3 += int(num[-1])
  if hang > int(hang_list[6]) and hang < int(hang_list[7]):
  if num!=[]:
   if num[-1].isdigit():
   worksheet1.write('G'+str(index[i][8]),num[-1],format_rt) 
  if hang > int(hang_list[7]) and hang < int(hang_list[8]):
  if num!=[]:
   if len(num) == 5 and num[-1].isdigit():
   worksheet1.write('G'+str(index[i][9]),num[-1],format_rt)
  if hang > int(hang_list[8]) and hang < int(hang_list[9]):
  if num!=[]:
   if len(num) >= 6 and num[-2].isdigit():
   temp.append(num[-2])
  if hang > int(hang_list[9]) and hang < int(hang_list[10]):
  if num!=[]:
   if len(num) >=4 and num[0].isdigit():
   status = num[2]
  if hang > int(hang_list[10]) and hang < int(hang_list[11]):
  if num!=[]:
   pass
  hang+=1
  temp.sort()
  worksheet1.write('G'+str(index[i][0]),count1,format_rt) 
  worksheet1.write('G'+str(index[i][1]),uptime,format_rt)
  worksheet1.write('G'+str(index[i][2]),'%s KB (%s KB)'%(total,free),format_rt)
  worksheet1.write('G'+str(index[i][3]),None,format_rt)
  worksheet1.write('G'+str(index[i][4]),None,format_rt)
  worksheet1.write('G'+str(index[i][5]),count2,format_rt)
  worksheet1.write('G'+str(index[i][6]),None,format_rt)
  worksheet1.write('G'+str(index[i][7]),count3,format_rt)
  worksheet1.write('G'+str(index[i][10]),u'%s℃-%s℃'%(temp[0],temp[-1]),format_rt)
  if status == 'up':
  worksheet1.write('G'+str(index[i][11]),u'  ',format_rt)
  else:
  worksheet1.write('G'+str(index[i][11]),u'   ',format_red)
  worksheet1.write('G'+str(index[i][12]),u'  ',format_right)
except Exception as reason:
 print "09_10SM-N7K.py "+str(reason)
 
 
#------------------------------------------------
#------------route_ip11----------------
#------------route_ip12----------------
#------------------------------------------------
 
try:
 fi_list=['11DMZ-NE40E-1.txt','12DMZ-NE40E-2.txt']
 fi_name=['<W-SM-E11-NE40E-01>','<W-SM-E12-NE40E-02>']
 device=['dis','NE40E-X8\'s','Slot','-']
 status=0
 for i in range(2):
 hang=1
 phy=0
 temp=[]
 alarm=0
 index={0:list(range(2,12)),1:list(range(12,22))}
 file='/usr/sh/shell/linux/xunjian/'+str(today)+'/'+fi_list[i]
 hang_list=cmd(fi_name[i],file)
 with open(file) as f:
  for each_line in f:
  num=each_line.split()
  if hang > int(hang_list[0]) and hang < int(hang_list[1]):
  if num!=[]:
   if num[0] not in device:
   status=1
  if hang > int(hang_list[1]) and hang < int(hang_list[2]):
  if num!=[]:
   if num[0] == 'HUAWEI':
   worksheet2.write('G'+str(index[i][1]),u'%s ,%s  '%(num[4],num[6]),format_rt)
  if hang > int(hang_list[2]) and hang < int(hang_list[3]):
  if num!=[]:
   if ',' in num[0]:
   total=num[0].replace(',','')+' KB '+num[3].replace(',','')+' KB)'
   worksheet2.write('G'+str(index[i][2]),total,format_rt)
  if hang > int(hang_list[3]) and hang < int(hang_list[4]):
  if num!=[]:
   if num[0] == 'Memory' and len(num) == 5:
   worksheet2.write('G'+str(index[i][4]),num[-1],format_rt)
  if hang > int(hang_list[4]) and hang < int(hang_list[5]):
  if num!=[]:
   if len(num) == 7 and num[1] == 'up':
   phy+=1
  if hang > int(hang_list[5]) and hang < int(hang_list[6]):
  if num!=[]:
   if num[0] == 'Destinations' and len(num) == 10:
   worksheet2.write('G'+str(index[i][6]),num[2],format_rt)
  if hang > int(hang_list[6]) and hang < int(hang_list[7]):
  if num!=[]:
   if len(num) >= 7 and num[-1].isdigit():
   temp.append(num[-1])
  if hang > int(hang_list[7]) and hang < int(hang_list[8]):
  if num!=[]:
   if num[0] == 'NO' and num[1] == 'alarm':
   alarm=1
  if hang > int(hang_list[8]) and hang < int(hang_list[9]):
  if num!=[]:
   pass
  hang+=1
  temp.sort()
  if status == 0:
  worksheet2.write('G'+str(index[i][0]),u'  ',format_rt) 
  else:
  worksheet2.write('G'+str(index[i][0]),'Error',format_red)
  worksheet2.write('G'+str(index[i][3]),None,format_rt)
  worksheet2.write('G'+str(index[i][5]),phy,format_rt)
  worksheet2.write('G'+str(index[i][7]),u'%s℃-%s℃'%(temp[0],temp[-1]),format_rt)
  if alarm == 1:
  worksheet2.write('G'+str(index[i][8]),u'   ',format_rt)
  else:
  worksheet2.write('G'+str(index[i][8]),'Error',format_red)
  worksheet2.write('G'+str(index[i][9]),u'  ',format_right)
except IOError as reason:
 print "11_12.py "+str(reason)
 
 
#------------------------------------------------
#------------fuzai_ip13-----------------
#------------fuzai_ip14-----------------
#------------fuzai_ip15-----------------
#------------fuzai_ip16-----------------
#------------------------------------------------
try:
 fi_list=['13DMZ-RD5412-1.txt','14DMZ-RD5412-2.txt','15SM-RD6420-1.txt','16SM-RD6420-2.txt']
 fi_name='>> '
 state=[]
 for i in range(4):
 hang=1
 status=0
 link=0
 temp=[]
 Master=0
 Backup=0
 index={0:list(range(2,12)),1:list(range(12,22)),2:list(range(22,32)),3:list(range(32,42))}
 file='/usr/sh/shell/linux/xunjian/'+str(today)+'/'+fi_list[i]
 hang_list=cmd(fi_name,file)
 with open(file) as f:
  for each_line in f:
  num=each_line.split()
  if hang > int(hang_list[0]) and hang < int(hang_list[1]):
  if num!=[]:
   if num[0] == 'Switch':
   worksheet3.write('G'+str(index[i][0]),u'%s ,%s '%(num[3],num[5]),format_rt) 
  if hang > int(hang_list[1]) and hang < int(hang_list[2]):
  if num!=[]:
   if num[0] == 'Dual':
   if num[-1] == "OK":
   worksheet3.write('G'+str(index[i][1]),u'  ',format_rt)
   else:
   worksheet3.write('G'+str(index[i][1]),'Error',format_red)
  if hang > int(hang_list[2]) and hang < int(hang_list[3]):
  if num!=[]:
   if num[0].isdigit() and len(num) == 3:
   if num[-1] != 'Operational':
   status=1
  if hang > int(hang_list[3]) and hang < int(hang_list[4]):
  if num!=[]:
   if num[0].isdigit() and len(num) == 7:
   if num[-1] == 'up':
   link+=1
  if hang > int(hang_list[4]) and hang < int(hang_list[5]):
  if num!=[]:
   if num[0] == 'Real' and num[1] == 'Servers' and len(num) == 4:
   Real_Servers=num[-1].split('(')[-1].split(')')[0]
   if num[0] == 'Server' and num[1] == 'Groups' and len(num) == 4:
   Server_Groups=num[-1]
   if num[0] == 'Virtual' and num[1] == 'Servers' and len(num) == 4:
   Virtual_Servers=num[-1].split('(')[-1].split(')')[0]
   if num[0] == 'Filters' and len(num) == 3:
   Filters=num[-1].split('(')[-1].split(')')[0]
  if hang > int(hang_list[5]) and hang < int(hang_list[6]):
  if num!=[]:
   if num[0] == 'cpuUtil1Second:':
   worksheet3.write('G'+str(index[i][5]),num[-1],format_rt)
  if hang > int(hang_list[6]) and hang < int(hang_list[7]):
  if num!=[]:
   if num[0] == 'Total:':
   Total=int(num[-2])
   if num[0] == 'Free:':
   Free=int(num[-2])
  if hang > int(hang_list[7]) and hang < int(hang_list[8]):
  if num!=[]:
   if num[0] == 'Sensor' and len(num) == 6:
   temp.append(num[3]) 
  if hang > int(hang_list[8]) and hang < int(hang_list[9]):
  if num!=[]:
   if len(num) == 10:
   if num[-1] == 'master':
   Master+=1
   if num[-1] == 'backup':
   Backup+=1
  if hang > int(hang_list[9]) and hang < int(hang_list[10]):
  if num!=[]:
   pass
  hang+=1
  state.append(Master)
  state.append(Backup)
  if status == 0:
  worksheet3.write('G'+str(index[i][2]),u'  ',format_rt)
  else:
  worksheet3.write('G'+str(index[i][2]),'Error',format_red)
  worksheet3.write('G'+str(index[i][3]),link,format_rt)
  worksheet3.write('G'+str(index[i][4]),'%s/%s/%s/%s'%(Real_Servers,Server_Groups,Virtual_Servers,Filters),format_rt)
  worksheet3.write('G'+str(index[i][6]),'%.2f%%'%(float(Total-Free)/Total*100),format_rt)
  worksheet3.write('G'+str(index[i][7]),temp[0],format_rt)
  worksheet3.write('G'+str(index[i][9]),u'  ',format_right)
 if state[0] == state[3]:
 worksheet3.write('G10','master',format_rt)
 worksheet3.write('G20','backup',format_rt)
 else:
 worksheet3.write('G10','Error',format_red)
 worksheet3.write('G20','Error',format_red)
 if state[4] == state[-1]:
 worksheet3.write('G30','master',format_rt)
 worksheet3.write('G40','backup',format_rt)
 else:
 worksheet3.write('G30','Error',format_red)
 worksheet3.write('G40','Error',format_red)
  
except IOError as reason:
 print "13_16-RD5412-6420.py"+str(reason)
 
workbook.close()
5.총 스 크 립 트 입구
wlxj.sh\#전체 스 크 립 트 입구

#!/bin/bash
#-----------    --------------------
dir=/usr/sh/shell/linux/xunjian/python_shell
dir1=/usr/sh/shell/linux/xunjian
if [ ! -d $dir1/$(date '+%Y%m%d') ];then
 mkdir -p $dir1/$(date '+%Y%m%d')
fi
 
 
_shell()
{
pass='       1'
password='       2'
ps1='        3'
 
 
/usr/bin/python $dir/01DMZ-E8000E.py 'ip1' $pass $password
/usr/bin/python $dir/02_03-M9006.py 'ip2' $pass $password
/usr/bin/python $dir/02_03-M9006.py 'ip3' $pass $password
/usr/bin/python $dir/04IN-FG3950B.py 'ip4' $password
 
/usr/bin/python $dir/05_06DMZ-S9306.py 'ip5' $pass $password
/usr/bin/python $dir/05_06DMZ-S9306.py 'ip6' $pass $password
/usr/bin/python $dir/07_08-S12508.py 'ip7' $pass $password
/usr/bin/python $dir/07_08-S12508.py 'ip8' $pass $password
/usr/bin/python $dir/09_10SM-N7K.py 'ip9' $ps1
/usr/bin/python $dir/09_10SM-N7K.py 'ip10' $ps1
 
/usr/bin/python $dir/11_12DMZ-NE40E.py 'ip11' $password
/usr/bin/python $dir/11_12DMZ-NE40E.py 'ip12' $password
 
/usr/bin/python $dir/13_16-RD5412_6420.py 'ip13' $password
/usr/bin/python $dir/13_16-RD5412_6420.py 'ip14' $password
/usr/bin/python $dir/13_16-RD5412_6420.py 'ip15' $password
/usr/bin/python $dir/13_16-RD5412_6420.py 'ip16' $password
 
}
 
 
aa=`ls -l $dir1/$(date '+%Y%m%d') | wc -l`
Year=$(date '+%Y')
Month=$(date '+%m')
Day=$(date '+%d')
 
if [ $Month -lt 10 ];then
 Month=`echo $Month | sed 's/0//g'`
fi
 
if [ $Day -lt 10 ];then
 Day=`echo $Day | sed 's/0//g'`
fi
tday=$(date '+%Y.%m.%d')
new_tday="$Year.$Month.$Day"
zip_tday="$Month.$Day"
 
_shell
#      ,            ,     
cp -a $dir1/$(date '+%Y%m%d')/02DMZ-M9006.txt $dir1/$(date '+%Y%m%d')/02DMZ-M9006.txt.bak
cat $dir1/$(date '+%Y%m%d')/02DMZ-M9006.txt.bak | tr -s "\r
" "
" > $dir1/$(date '+%Y%m%d')/02DMZ-M9006.txt cp -a $dir1/$(date '+%Y%m%d')/03SM-M9006.txt $dir1/$(date '+%Y%m%d')/03SM-M9006.txt.bak cat $dir1/$(date '+%Y%m%d')/03SM-M9006.txt.bak | tr -s "\r
" "
" > $dir1/$(date '+%Y%m%d')/03SM-M9006.txt # excel /usr/bin/python $dir/wangluo_xunjian.py > /dev/null 2>&1 if [ -f $dir1/$(date '+%Y%m%d')/ -$tday.xlsx ];then sed -i 's/Cmcc.*$//g' $dir1/$(date '+%Y%m%d')/*.txt zip -qj $dir1/$(date '+%Y%m%d')/$zip_tday.zip $dir1/$(date '+%Y%m%d')/*.txt >/dev/null if [ $? -ne 0 ];then /usr/bin/python $dir/mail_zip_error.py >/dev/null 2>&1 else mv $dir1/$(date '+%Y%m%d')/ -$tday.xlsx $dir1/$(date '+%Y%m%d')/ -$new_tday.xlsx /usr/bin/python $dir/mail.py [email protected] " , " "$dir1/$(date '+%Y%m%d')/ -$new_tday.xlsx" "$dir1/$(date '+%Y%m%d')/$zip_tday.zip" fi else /usr/bin/python $dir/mail_excel_error.py >/dev/null 2>&1 fi
6、정시 퀘 스 트 가입
제 가 정 했 어 요.매일 오전 9 시.
7.완제품 도



이 파 이 썬 네트워크 장치 순찰 스 크 립 트 에 대한 인 스 턴 스 설명 은 바로 편집장 이 여러분 에 게 공유 한 모든 내용 입 니 다.참고 하 시기 바 랍 니 다.여러분 들 도 저 희 를 많이 사랑 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기