Added error handling for idrac

This commit is contained in:
2026-03-17 19:09:11 +01:00
parent e06eea68cd
commit c474f9c9c2
2 changed files with 49 additions and 72 deletions

View File

@@ -6,25 +6,19 @@ from typing import Annotated, Final
# SNMP # SNMP
from pysnmp.hlapi.v3arch.asyncio import * from pysnmp.hlapi.v3arch.asyncio import *
# SNMP ENV------------------------------------------- # IDRAC78 get data for snmpPyIDRACData class
ROUND_PREC: Final[int] = int(os.getenv("ROUND_PREC", 2)) async def idrac7_8PoolRemote_v3(
remoteIP: str,
SNMPUSER: Final[str] = os.getenv("SNMPUSER", None) queueToInsrt: asyncio.Queue,
SNMPPRIVKEY: Final[str] = os.getenv("SNMPPRIVKEY", None) SNMPUSER: str,
SNMPAUTHKEY: Final[str] = os.getenv("SNMPAUTHKEY", None) SNMPAUTHKEY: str,
# Right now I'll only use SHA SNMPPRIVKEY: str,
# SNMPAUTHPROTO: Final[str] = os.getenv("SNMPAUTHPROTO", "SHA") ROUND_PREC: int = 2,
# SNMPPRIVPROTO: Final[str] = os.getenv("SNMPPRIVPROTO", "SHA") SNMPORT: int = 161
SNMPORT: Final[int] = int(os.getenv("SNMPORT", 161)) ):
print("starting work on ", remoteIP)
# SNMPUSRDATA
# Check if SNMP ENV are empty USMUSRDATA = UsmUserData(
if not SNMPUSER or not SNMPPRIVKEY or not SNMPAUTHKEY:
raise Exception("No SNMP user or/and PrivAuth passed")
# SNMP
USMUSRDATA = UsmUserData(
userName=SNMPUSER, userName=SNMPUSER,
authKey=SNMPAUTHKEY, authKey=SNMPAUTHKEY,
privKey=SNMPPRIVKEY, privKey=SNMPPRIVKEY,
@@ -32,14 +26,6 @@ USMUSRDATA = UsmUserData(
privProtocol=usmAesCfb128Protocol, privProtocol=usmAesCfb128Protocol,
) )
# IDRAC78 get data for snmpPyIDRACData class
async def idrac7_8PoolRemote_v3(remoteIP: str, queueToInsrt: asyncio.Queue):
print("starting work on ", remoteIP)
snmpEngine = SnmpEngine() snmpEngine = SnmpEngine()
# try CPU2 as CPU1 is always there # try CPU2 as CPU1 is always there
@@ -59,6 +45,10 @@ async def idrac7_8PoolRemote_v3(remoteIP: str, queueToInsrt: asyncio.Queue):
errorIndication, errorStatus, errorIndex, mainVarBinds = await mainIterator errorIndication, errorStatus, errorIndex, mainVarBinds = await mainIterator
if errorIndication: if errorIndication:
if errorIndication == "No SNMP response received before timeout":
print(f"Host {remoteIP} timed out.\nContinuing...")
snmpEngine.close_dispatcher()
return 1
print(errorIndication) print(errorIndication)
elif errorStatus: elif errorStatus:
print( print(
@@ -73,17 +63,17 @@ async def idrac7_8PoolRemote_v3(remoteIP: str, queueToInsrt: asyncio.Queue):
try: try:
# Get PSU1 current, [PSU2 current], total board power draw in watts # Get PSU1 current, [PSU2 current], total board power draw in watts
currentsCurrentResults = await walk_column_v3(snmpEngine, remoteIP, ".1.3.6.1.4.1.674.10892.5.4.600.30.1.6") currentsCurrentResults = await walk_column_v3(snmpEngine, remoteIP, ".1.3.6.1.4.1.674.10892.5.4.600.30.1.6", SNMPUSER, SNMPAUTHKEY, SNMPPRIVKEY)
# PSU1 OID name, [PSU2 OID name], system board power draw # PSU1 OID name, [PSU2 OID name], system board power draw
currentsNamesResults = await walk_column_v3(snmpEngine, remoteIP, ".1.3.6.1.4.1.674.10892.5.4.600.30.1.8") currentsNamesResults = await walk_column_v3(snmpEngine, remoteIP, ".1.3.6.1.4.1.674.10892.5.4.600.30.1.8", SNMPUSER, SNMPAUTHKEY, SNMPPRIVKEY)
# Inlet OID name .1, [Exhaust OID name], CPU1 temp OID name, [CPU2 tempOID name] # Inlet OID name .1, [Exhaust OID name], CPU1 temp OID name, [CPU2 tempOID name]
sensorNamesResults = await walk_column_v3(snmpEngine, remoteIP, ".1.3.6.1.4.1.674.10892.5.4.700.20.1.8") sensorNamesResults = await walk_column_v3(snmpEngine, remoteIP, ".1.3.6.1.4.1.674.10892.5.4.700.20.1.8", SNMPUSER, SNMPAUTHKEY, SNMPPRIVKEY)
# Inlet temp, [Exhaust temp], CPU1 temp, [CPU2 temp] # Inlet temp, [Exhaust temp], CPU1 temp, [CPU2 temp]
sensorValuesResults = await walk_column_v3(snmpEngine, remoteIP, ".1.3.6.1.4.1.674.10892.5.4.700.20.1.6") sensorValuesResults = await walk_column_v3(snmpEngine, remoteIP, ".1.3.6.1.4.1.674.10892.5.4.700.20.1.6", SNMPUSER, SNMPAUTHKEY, SNMPPRIVKEY)
# .1.3.6.1.4.1.674.10892.5.4.600.20.1.6.1 # .1.3.6.1.4.1.674.10892.5.4.600.20.1.6.1
voltResult = await walk_column_v3(snmpEngine, remoteIP, ".1.3.6.1.4.1.674.10892.5.4.600.20.1.6.1") voltResult = await walk_column_v3(snmpEngine, remoteIP, ".1.3.6.1.4.1.674.10892.5.4.600.20.1.6.1", SNMPUSER, SNMPAUTHKEY, SNMPPRIVKEY)
hasExhaust = any("exhaust" in str(thing).lower() for thing in sensorNamesResults.values()) hasExhaust = any("exhaust" in str(thing).lower() for thing in sensorNamesResults.values())
hasCPU2 = any("cpu2" in str(thing).lower() for thing in sensorNamesResults.values()) hasCPU2 = any("cpu2" in str(thing).lower() for thing in sensorNamesResults.values())

View File

@@ -10,25 +10,20 @@ from typing import Annotated, Final
# SNMP # SNMP
from pysnmp.hlapi.v3arch.asyncio import * from pysnmp.hlapi.v3arch.asyncio import *
# SNMP ENV-------------------------------------------
ROUND_PREC: Final[int] = int(os.getenv("ROUND_PREC", 2))
SNMPUSER: Final[str] = os.getenv("SNMPUSER", None) # IDRAC get data for snmpPyIDRACData class
SNMPPRIVKEY: Final[str] = os.getenv("SNMPPRIVKEY", None) async def idrac9PoolRemote_v3(
SNMPAUTHKEY: Final[str] = os.getenv("SNMPAUTHKEY", None) remoteIP: str,
# Right now I'll only use SHA queueToInsrt: asyncio.Queue,
# SNMPAUTHPROTO: Final[str] = os.getenv("SNMPAUTHPROTO", "SHA") SNMPUSER: str,
# SNMPPRIVPROTO: Final[str] = os.getenv("SNMPPRIVPROTO", "SHA") SNMPAUTHKEY: str,
SNMPORT: Final[int] = int(os.getenv("SNMPORT", 161)) SNMPPRIVKEY: str,
ROUND_PREC: int = 2,
SNMPORT: int = 161
# Check if SNMP ENV are empty ):
if not SNMPUSER or not SNMPPRIVKEY or not SNMPAUTHKEY: print("starting work on ", remoteIP)
raise Exception("No SNMP user or/and PrivAuth passed") # SNMP
USMUSRDATA = UsmUserData(
# SNMP
USMUSRDATA = UsmUserData(
userName=SNMPUSER, userName=SNMPUSER,
authKey=SNMPAUTHKEY, authKey=SNMPAUTHKEY,
privKey=SNMPPRIVKEY, privKey=SNMPPRIVKEY,
@@ -36,14 +31,6 @@ USMUSRDATA = UsmUserData(
privProtocol=usmAesCfb128Protocol, privProtocol=usmAesCfb128Protocol,
) )
# IDRAC get data for snmpPyIDRACData class
async def idrac9PoolRemote_v3(remoteIP: str, queueToInsrt: asyncio.Queue):
print("starting work on ", remoteIP)
snmpEngine = SnmpEngine() snmpEngine = SnmpEngine()
iterator = get_cmd( iterator = get_cmd(
@@ -80,17 +67,17 @@ async def idrac9PoolRemote_v3(remoteIP: str, queueToInsrt: asyncio.Queue):
try: try:
# Get PSU1 current, [PSU2 current], total board power draw in watts # Get PSU1 current, [PSU2 current], total board power draw in watts
currentsCurrentResults = await walk_column_v3(snmpEngine, remoteIP, ".1.3.6.1.4.1.674.10892.5.4.600.30.1.6") currentsCurrentResults = await walk_column_v3(snmpEngine, remoteIP, ".1.3.6.1.4.1.674.10892.5.4.600.30.1.6", SNMPUSER, SNMPAUTHKEY, SNMPPRIVKEY)
# PSU1 OID name, [PSU2 OID name], system board power draw # PSU1 OID name, [PSU2 OID name], system board power draw
currentsNamesResults = await walk_column_v3(snmpEngine, remoteIP, ".1.3.6.1.4.1.674.10892.5.4.600.30.1.8") currentsNamesResults = await walk_column_v3(snmpEngine, remoteIP, ".1.3.6.1.4.1.674.10892.5.4.600.30.1.8", SNMPUSER, SNMPAUTHKEY, SNMPPRIVKEY)
# CPU1 OID name .1, [CPU2 OID name], Inlet temp OID name, [Exhaust temp OID name] # CPU1 OID name .1, [CPU2 OID name], Inlet temp OID name, [Exhaust temp OID name]
sensorNamesResults = await walk_column_v3(snmpEngine, remoteIP, ".1.3.6.1.4.1.674.10892.5.4.700.20.1.8") sensorNamesResults = await walk_column_v3(snmpEngine, remoteIP, ".1.3.6.1.4.1.674.10892.5.4.700.20.1.8", SNMPUSER, SNMPAUTHKEY, SNMPPRIVKEY)
# CPU1 temp, [CPU2 temp], Inlet temp, [Exhaust temp] # CPU1 temp, [CPU2 temp], Inlet temp, [Exhaust temp]
sensorValuesResults = await walk_column_v3(snmpEngine, remoteIP, ".1.3.6.1.4.1.674.10892.5.4.700.20.1.6") sensorValuesResults = await walk_column_v3(snmpEngine, remoteIP, ".1.3.6.1.4.1.674.10892.5.4.700.20.1.6", SNMPUSER, SNMPAUTHKEY, SNMPPRIVKEY)
# .1.3.6.1.4.1.674.10892.5.4.600.20.1.6.1 # .1.3.6.1.4.1.674.10892.5.4.600.20.1.6.1
voltResult = await walk_column_v3(snmpEngine, remoteIP, ".1.3.6.1.4.1.674.10892.5.4.600.20.1.6.1") voltResult = await walk_column_v3(snmpEngine, remoteIP, ".1.3.6.1.4.1.674.10892.5.4.600.20.1.6.1", SNMPUSER, SNMPAUTHKEY, SNMPPRIVKEY)
except SNMPTimeoutError as e: except SNMPTimeoutError as e:
print(f"{e}\nContinuing regardless...") print(f"{e}\nContinuing regardless...")
return 1 return 1