1-1

 

 

 

 

 

import xlwt
import sys
import time
import os

# with open('hexin.txt') as  f1:
with open('10.10.45.11.txt') as  f1:
    for i in f1:
        if "POWER" in i:
            power1=i[9:].strip()
            print(power1)
        if "five minutes" in i:
            cpu1=i[70:].strip()
            print(cpu1)
        if "uptime is" in i:
            uptime1=i[26:].strip()
            print(uptime1)
        if "Processor Pool Total" in i:
            mem1=i[24:32].strip()
            mem2=i[42:49].strip()
            print(mem1)
            print(mem2)
            # print(*100)
            mem3=("%.2f%%"%((int(mem2))/(int(mem1))*100))
        if "FAN" in i:
            fan1=i[7:].strip()
            print(fan1)
        if "Console logging:" in i:
            log1=i[38:51].strip()
            print(log1)



workbook = xlwt.Workbook(encoding='utf-8')
#建立第一個巡檢sheet
cisco = workbook.add_sheet('接入設備巡檢')
style = xlwt.XFStyle()
pattern = xlwt.Pattern()
pattern.pattern = xlwt.Pattern.SOLID_PATTERN
pattern.pattern_fore_colour = xlwt.Style.colour_map['red']
style.pattern = pattern
borders = xlwt.Borders()
borders.left = 1
borders.right = 1
borders.top = 1
borders.bottom = 1
style.borders = borders
al = xlwt.Alignment()
al.horz = 0x02
al.vert = 0x01
style.alignment = al
style1 = xlwt.XFStyle()
borders = xlwt.Borders()
borders.left = 1
borders.right = 1
borders.top = 1
borders.bottom = 1

style1.borders = borders
al = xlwt.Alignment()
al.horz = 0x02
al.vert = 0x01
style1.alignment = al

style3 = xlwt.XFStyle()
borders = xlwt.Borders()
borders.left = 1
borders.right = 1
borders.top = 1
borders.bottom = 1
style3.borders = borders
al = xlwt.Alignment()
al.horz = 0x02
al.vert = 0x01
style3.alignment = al

first_col = cisco.col(0)
sec_col = cisco.col(1)
thr_col = cisco.col(2)
for_col = cisco.col(3)
fiv_col = cisco.col(4)
first_col.width = 200 * 25
sec_col.width = 120 * 25
thr_col.width = 120 * 25
for_col.width = 320 * 25
fiv_col.width = 320 * 25

cisco.write(0, 0,'設備名稱',style)
cisco.write(0,1, '管理地址',style)
cisco.write(0,2, '檢查項',style)
cisco.write(0,3, '檢查結果',style)
cisco.write(0,4, '備註',style)

#在excel中填寫設備名和IP地址
cisco.write_merge(1,6,0,0,'SA-10F-IDF1-2901',style3)
cisco.write_merge(1,6,1,1,'10.10.40.101',style3)
cisco.write_merge(1,6,4,4,'大樓一樓',style3)

cisco.write(1,2, '電源狀態',style1)
cisco.write(2,2, 'cpu使用率',style1)
cisco.write(3,2, '運行時間',style1)
cisco.write(4,2, '內存使用率',style1)
cisco.write(5,2, '風扇狀態',style1)
cisco.write(6,2, '日誌條目',style1)
#下面開始填入具體內容
cisco.write(1,3, power1,style3)
cisco.write(2,3, cpu1,style3)
cisco.write(3,3, uptime1,style3)
cisco.write(4,3, mem3,style3)
cisco.write(5,3, fan1,style3)
cisco.write(6,3, log1,style3)


workbook.save('設備巡檢.xls')










# #上面是第一個sheet
# cisco2 = workbook.add_sheet('接入網絡巡檢表')
# style = xlwt.XFStyle()
# pattern = xlwt.Pattern()
# pattern.pattern = xlwt.Pattern.SOLID_PATTERN
# pattern.pattern_fore_colour = xlwt.Style.colour_map['red']
# style.pattern = pattern
# borders = xlwt.Borders()
# borders.left = 1
# borders.right = 1
# borders.top = 1
# borders.bottom = 1
# style.borders = borders
# al = xlwt.Alignment()
# al.horz = 0x02
# al.vert = 0x01
# style.alignment = al
#
# style1 = xlwt.XFStyle()
# borders = xlwt.Borders()
# borders.left = 1
# borders.right = 1
# borders.top = 1
# borders.bottom = 1
# style1.borders = borders
# al = xlwt.Alignment()
# al.horz = 0x02
# al.vert = 0x01
# style1.alignment = al
#
# style3 = xlwt.XFStyle()
# borders = xlwt.Borders()
# borders.left = 1
# borders.right = 1
# borders.top = 1
# borders.bottom = 1
# style3.borders = borders
# al = xlwt.Alignment()
# al.horz = 0x02
# al.vert = 0x01
# style3.alignment = al
#
# first_col = cisco2.col(0)
# sec_col = cisco2.col(1)
# thr_col = cisco2.col(2)
# for_col = cisco2.col(3)
# first_col.width = 200 * 25
# sec_col.width = 120 * 25
# thr_col.width = 120 * 25
# for_col.width = 320 * 25
#
#
# cisco2.write(0, 0,'設備名稱',style)
# cisco2.write(0,1, '管理地址',style)
# cisco2.write(0,2, '檢查項',style)
# cisco2.write(0,3, '檢查結果',style)
# cisco2.write(1,2, '電源狀態',style1)
# cisco2.write(2,2, 'cpu使用率',style1)
# cisco2.write(3,2, '運行時間',style1)
# cisco2.write(4,2, '內存使用率',style1)
# cisco2.write(5,2, '風扇狀態',style1)
# cisco2.write(6,2, '日誌條目',style1)
#
# workbook.save('設備巡檢.xls')
相關文章
相關標籤/搜索