清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
#!/usr/bin/env python #coding:utf-8 """ Author: Edward.Zhou -- <edgeman_03@163.com> Purpose: 监控精密空调DataMate3000状态 Created: 2015年05月02日 """ import unittest import netsnmp import sys import argparse #DataMate3000MIB库 DaTaMate3000MIB = { 'SmartOutput': { 'Temperature': '.1.3.6.1.4.1.13400.2.10.1.2.2.1', #温度 'Humidity': '.1.3.6.1.4.1.13400.2.10.1.2.2.2', #湿度 }, 'BaseStatus': { #'''Status: unknown ( 1 ) , ok ( 2 ) , lostCommunication ( 3 ) , notEstablished ( 4 )''' 'Communication': '.1.3.6.1.4.1.13400.2.10.1.3.1.1', #通信状态 }, 'SmartStatus': { #'''Status: #unknown ( 1 ) , on ( 2 ) , off ( 3 )''' 'UnitOnOff': '.1.3.6.1.4.1.13400.2.10.1.3.2.1', #开关机 'MainFan': '.1.3.6.1.4.1.13400.2.10.1.3.2.2', #风机 'CoolMode': '.1.3.6.1.4.1.13400.2.10.1.3.2.3', #制冷 'HeatMode': '.1.3.6.1.4.1.13400.2.10.1.3.2.4', #加热 'HumidifyMode': '.1.3.6.1.4.1.13400.2.10.1.3.2.5', #加湿 'DehumidifyMode': '.1.3.6.1.4.1.13400.2.10.1.3.2.6', #除湿 'HighPressure': '.1.3.6.1.4.1.13400.2.10.1.3.2.7', #高压告警 'LowPressure': '.1.3.6.1.4.1.13400.2.10.1.3.2.8', #低压告警 'HighTemperature': '.1.3.6.1.4.1.13400.2.10.1.3.2.9', #高温告警 'LowTemperature': '.1.3.6.1.4.1.13400.2.10.1.3.2.10', #低温告警 'HighHumidify': '.1.3.6.1.4.1.13400.2.10.1.3.2.11', #高湿告警 'LowHumidify': '.1.3.6.1.4.1.13400.2.10.1.3.2.12', #低湿告警 'PowerFailure': '.1.3.6.1.4.1.13400.2.10.1.3.2.13', #电源故障告警 'ShortCycle': '.1.3.6.1.4.1.13400.2.10.1.3.2.14', #短周期告警 'CustomAlarm1': '.1.3.6.1.4.1.13400.2.10.1.3.2.15', #自定义告警1 'CustomAlaarm2': '.1.3.6.1.4.1.13400.2.10.1.3.2.16', #自定义告警2 'MainFanServiceRequired': '.1.3.6.1.4.1.13400.2.10.1.3.2.17', #主风机维护请求 'HumidifierServiceRequired': '.1.3.6.1.4.1.13400.2.10.1.3.2.18', #加湿器维护请求 'FilterServiceRequired': '.1.3.6.1.4.1.13400.2.10.1.3.2.19', #过滤网维护请求 'CoilFroze': '.1.3.6.1.4.1.13400.2.10.1.3.2.20', #盘管冻结 'HumidifierFailure': '.1.3.6.1.4.1.13400.2.10.1.3.2.21', #加湿器故障 'SensorBoardFailure': '.1.3.6.1.4.1.13400.2.10.1.3.2.22', #传感器板故障 'DischargeTemperatureFailure': '.1.3.6.1.4.1.13400.2.10.1.3.2.23', #排气温度故障 'PowerLost': '.1.3.6.1.4.1.13400.2.10.1.3.2.24', #电源丢失 'InnerCommFailure': '.1.3.6.1.4.1.13400.2.10.1.3.2.25', #空调通讯状态 }, } #设置返回状态码 ''' ST_OK=0 #正常 ST_WR=1 #错误 ST_CR=2 #严重警告 ST_UK=3 #未知 ''' #采用snmp协议获取相应OID值 def snmpGet(oid, version = 1, community = 'public', host = 'localhost'): try: result = netsnmp.snmpwalk(oid, Version = version, Community = community, DestHost = host) except Exception, err: print err sys.exit() if result: return result[0] else: return None def main(): parser = argparse.ArgumentParser(description='DataMate 3000 status check') parser.add_argument('-i','--host', dest='host', nargs = '?', default= 'localhost', required = False, help='The specified monitoring DataMate 3000 IP or Host') parser.add_argument('-v','--version', dest='version', nargs = '?', default= 1, type = int, required = False, help='The specified snmp version') parser.add_argument('-C','--Community', dest='Community', nargs = '?', default= 'public', required = False, help='The specified snmp community') parser.add_argument('-V','--Variable', dest = 'Variable', nargs = '?', default = 'Temperature', required = True, choices = ['Temperature', 'Humidity'], help = 'The specified check object' ) parser.add_argument('-w', '--warning', dest = 'warning', type = int, nargs = '?', required = True, default = None, help = 'Threshold which will result in a warning status') parser.add_argument('-c', '--critical', dest = 'critical', type = int, nargs = '?', required = True, default = None, help = 'Threshold which will result in a critical status') args = parser.parse_args() #检测环境温度 if args.Variable == 'Temperature': toid = DaTaMate3000MIB['SmartOutput']['Temperature'] _result = snmpGet(toid, args.version, args.Community, args.host) result = float(_result) if (result / 10) < args.warning: print "DataMate 3000 Teamperature is %s ℃,status is ok." % (result / 10) sys.exit(0) elif (result / 10) >= args.warning and (result / 10) <= args.critical: print "DataMate 3000 Teamperature is %s ℃,status is warning." % (result / 10) sys.exit(1) elif (result / 10) >= args.critical: print "DataMate 3000 Teamperature is %s ℃,status is critical." % (result / 10) sys.exit(2) else: print "DataMate 3000 Teamperature is unknown ℃,status is unknown." sys.exit(3) #检测环境湿度 if args.Variable == 'Humidity': hoid = DaTaMate3000MIB['SmartOutput']['Humidity'] _result = snmpGet(hoid, args.version, args.Community, args.host) result = float(_result) if result < args.warning: print "DataMate 3000 Humidity is %s %%RH,status is ok." % result sys.exit(0) elif result >= args.warning and result <= args.critical: print "DataMate 3000 Humidity is %s %%RH,status is warning." % result sys.exit(1) elif result >= args.critical: print "DataMate 3000 Humidity is %s %%RH,status is critical." % result sys.exit(2) else: print "DataMate 3000 Humidity is unknown %%RH,status is unknown." sys.exit(3) if __name__ == '__main__': main()