zoukankan      html  css  js  c++  java
  • zabbix 硬盘状态收集,制作表格

    将zabbix首页复制到a文件里,这里主要是用到首页里 最近出现的问题 的信息

    # -*- coding:utf-8 -*-
    import time
    import os
    from openpyxl import Workbook
    from openpyxl import load_workbook
    
    #获取状态信息
    def zabbixdisk():
        ip=os.popen("grep 'DiskHealthy' a | grep -Eo '([0-9]{1,3}.){3}[0-9]{1,3}' |sort -t'.' -k1,1nr -k2,2nr -k3,3nr -k4,4nr|uniq").read().split('
    ')
        
      #一个端口重复一次,避免由于异常导致错过正常端口
      zabbixport=['10050','10050'] data=[] #遍历服务器ip for i in ip: if i == '': continue name=os.popen("grep -w '%s' a | awk '{print $1}'|uniq"%i).read().replace(' ',"") num=0 healthy=0 disk=[] status=[] errore=[] #遍历端口 while len(zabbixport) > num: healthy=os.popen("/usr/local/zabbix/bin/zabbix_get -s%s -p%s -k'disk.healthy'"%(i,zabbixport[num])).read() num=num + 1 if num == len(zabbixport) and healthy == "" : errore.append(i) break elif healthy != "" : num=len(zabbixport)+1 #将状态信息分类 for ii in healthy.split(' '): htmp=[] for iii in ii.split(' '): if "/dev" in iii : disk.append(iii) else: htmp.append(iii) status.append(' '.join(htmp)) data.append([i,name,'%s'%' '.join(disk).rstrip(" "),"%s"%' '.join(status).rstrip(" ")]) return data,ip,' '.join(errore) #获取时间 def newdate(sj): ISOTIMEFORMAT='%Y-%m-%d %X' if sj == 'Obtain': timedate=time.strftime(ISOTIMEFORMAT, time.localtime()) return timedate else: timedate=time.strftime(ISOTIMEFORMAT,time.localtime(sj.st_mtime)) return timedate #写入表格 def exsl(data): name="sample-%s.xlsx"%newdate('Obtain').replace(' ','').replace(':','') wb = Workbook() # grab the active worksheet ws = wb.active # Data can be assigned directly to cells ws['A1'] = 'IP' ws['B1'] = 'HostName' ws['C1'] = 'Disk' ws['D1'] = 'status' for i in data: # Rows can also be appended ws.append([i[0], i[1], i[2], i[3] ]) # Save the file wb.save("/tmp/%s"%name) return "/tmp/%s"%name data,ip,error =zabbixdisk() print "The number of servers that have detected a total hard disk: %s"%(len(ip)-1) print "ZABBIX access to the number of: %s"%len(data) if len(ip)-1 > len(data): print "The following IP failed to succeed: %s"%error print exsl(data)
  • 相关阅读:
    Tomcat给我的java.lang.OutOfMemoryError: PermGen
    解决:dubbo找不到dubbo.xsd报错
    html li css选中状态切换
    JavaScript jQuery 中定义数组与操作及jquery数组操作 http://www.jb51.net/article/76601.htm
    Hibernate中多对多的annotation的写法(中间表可以有多个字段)
    @OneToMany、@ManyToOne以及@ManyToMany讲解
    mysql中char,varchar与text类型的区别和选用
    MYSQL数据库设计规范与原则
    使用fastJSON解析HashMap中的数据
    python测试开发django-29.发送html格式邮件
  • 原文地址:https://www.cnblogs.com/cainiaoit/p/8579733.html
Copyright © 2011-2022 走看看