zoukankan      html  css  js  c++  java
  • 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')
  • 相关阅读:
    property函数
    robotframework常见问题解决汇总
    python 基本的序列和映射规则
    robot framework -记录错误
    python 函数部分
    python-文件操作
    网络检测,版本更新
    应用FMDB进行数据存储
    xcode5 各区域快捷键大全
    全国第七届大学生计算机设计大赛
  • 原文地址:https://www.cnblogs.com/xiaomai-rhce/p/11836439.html
Copyright © 2011-2022 走看看