Skip to content
Snippets Groups Projects
Commit 79cf9595 authored by root's avatar root
Browse files

Updated check_mellanox to Python3 with easysnmp

parent 3c6c73dd
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/python #!/usr/bin/python3
# Author: Devon Merner (dmerner) # Author: Devon Merner (dmerner)
# Date: November 17th, 2016 # Date: November 17th, 2016
...@@ -14,7 +14,8 @@ CRITICAL_TEXT="" ...@@ -14,7 +14,8 @@ CRITICAL_TEXT=""
import sys import sys
import argparse import argparse
import netsnmp from easysnmp import Session
from easysnmp.exceptions import *
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-c", default="public", dest="community", parser.add_argument("-c", default="public", dest="community",
...@@ -38,31 +39,39 @@ parser.add_argument("-fC", default="1000", dest="fancrit", ...@@ -38,31 +39,39 @@ parser.add_argument("-fC", default="1000", dest="fancrit",
help="Fan monitor critical threshold in RPM (returns critical if equivelant or less than this number) Default: 1000") help="Fan monitor critical threshold in RPM (returns critical if equivelant or less than this number) Default: 1000")
options = parser.parse_args() options = parser.parse_args()
args = {
"Version": int(options.version), def snmpGet(oid):
"DestHost": options.host, try:
"Community": options.community return session.get(oid).value
} except EasySNMPNoSuchNameError:
return None
def snmpWalk(oid):
try:
return session.walk(oid)
except EasySNMPNoSuchNameError:
return None
session = Session(hostname=options.host, community=options.community, version=int(options.version))
dataReturned = 0 dataReturned = 0
# Collect fan/temperature sensor data # Collect fan/temperature sensor data
for idx in netsnmp.snmpwalk(netsnmp.Varbind(".1.3.6.1.2.1.99.1.1"), **args): for idx in snmpWalk(".1.3.6.1.2.1.99.1.1"):
idx = idx.value
dataReturned = 1 dataReturned = 1
# Mellanox indexes start with 200 for some reason. # Mellanox indexes start with 200 for some reason.
if not idx.startswith("200"): if not idx.startswith("200"):
continue continue
sensortype, desc, units, value = netsnmp.snmpget( sensortype = snmpGet(".1.3.6.1.2.1.47.1.1.1.1.7." + idx)
netsnmp.Varbind(".1.3.6.1.2.1.47.1.1.1.1.7", idx), desc = snmpGet(".1.3.6.1.2.1.47.1.1.1.1.2." + idx)
netsnmp.Varbind(".1.3.6.1.2.1.47.1.1.1.1.2", idx), units = snmpGet(".1.3.6.1.2.1.99.1.1.1.6." + idx)
netsnmp.Varbind(".1.3.6.1.2.1.99.1.1.1.6", idx), value = snmpGet(".1.3.6.1.2.1.99.1.1.1.4." + idx)
netsnmp.Varbind(".1.3.6.1.2.1.99.1.1.1.4", idx),
**args)
if (sensortype is None): if (sensortype is None):
continue continue
# Convert into actual units if using SNMP v1 # Convert into actual units if using SNMP v1
if (int(options.version) == 1) and sensortype.startswith("Temperature"): if (int(options.version) == 1) and sensortype.startswith("Temperature"):
...@@ -90,13 +99,12 @@ if dataReturned == 0: ...@@ -90,13 +99,12 @@ if dataReturned == 0:
sys.exit(STATE_UNKNOWN) sys.exit(STATE_UNKNOWN)
# Collect power supply information # Collect power supply information
for idx in netsnmp.snmpwalk(netsnmp.Varbind(".1.3.6.1.2.1.47.1.1.1.1.1"), **args): for idx in snmpWalk(".1.3.6.1.2.1.47.1.1.1.1.1"):
idx = idx.value
sensortype, desc, alarm = netsnmp.snmpget( sensorType = snmpGet(".1.3.6.1.2.1.47.1.1.1.1.7." + idx)
netsnmp.Varbind(".1.3.6.1.2.1.47.1.1.1.1.7", idx), desc = snmpGet(".1.3.6.1.2.1.47.1.1.1.1.2." + idx)
netsnmp.Varbind(".1.3.6.1.2.1.47.1.1.1.1.2", idx), alarm = snmpGet(".1.3.6.1.2.1.131.1.1.1.5." + idx)
netsnmp.Varbind(".1.3.6.1.2.1.131.1.1.1.5", idx),
**args)
if sensortype is None: if sensortype is None:
continue continue
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment