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

Converted check_geist_pdu to Python3 with easysnmp

parent 79cf9595
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/python
#!/usr/bin/python3
# Author: Devon Merner (dmerner)
# Date: July 16th, 2021
......@@ -23,7 +23,8 @@ PERFDATA = ""
import sys
import argparse
import netsnmp
from easysnmp import Session
from easysnmp.exceptions import *
# OIDs
firmwareTree="SNMPv2-MIB::sysObjectID.0"
......@@ -70,13 +71,22 @@ parser.add_argument("host", default="localhost", nargs="?", help="Agent to retri
parser.add_argument("-d", action="store_true", dest="debug", help="Print debug information")
options = parser.parse_args()
args = {
"Version": int(options.version),
"DestHost": options.host,
"Community": options.community
}
firmwareTreeRoot = netsnmp.snmpget(netsnmp.Varbind(firmwareTree), **args)[0]
def snmpGet(oid):
try:
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))
firmwareTreeRoot = snmpGet(firmwareTree)
if firmwareTreeRoot is None:
print("UNKNOWN - PDU did not respond (network timeout). |")
sys.exit(STATE_UNKNOWN)
......@@ -84,17 +94,17 @@ elif ".3.6.1.4.1.21239.2" in str(firmwareTreeRoot):
if options.debug:
print("PDU is running V3 firmware")
productTitle=netsnmp.snmpget(netsnmp.Varbind(v3_productTitle), **args)[0]
productVersion=netsnmp.snmpget(netsnmp.Varbind(v3_productVersion), **args)[0]
productTitle=snmpGet(v3_productTitle)
productVersion=snmpGet(v3_productVersion)
OUTPUT_TEXT += " [" + str(productTitle) + " v" + str(productVersion) + "]"
for circuit, oids in v3_power.iteritems():
for circuit, oids in v3_power.items():
if options.debug:
print("Circuit " + circuit)
for key, oid in oids.iteritems():
value = netsnmp.snmpget(netsnmp.Varbind(oid), **args)[0]
for key, oid in oids.items():
value = snmpGet(oid)
if "Amp" in key:
value = float(value) / 10
......
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