diff --git a/cont/idrac/idrac78.py b/cont/idrac/idrac78.py index 26c1c76..301a02c 100644 --- a/cont/idrac/idrac78.py +++ b/cont/idrac/idrac78.py @@ -6,39 +6,25 @@ from typing import Annotated, Final # SNMP 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) -SNMPPRIVKEY: Final[str] = os.getenv("SNMPPRIVKEY", None) -SNMPAUTHKEY: Final[str] = os.getenv("SNMPAUTHKEY", None) -# Right now I'll only use SHA -# SNMPAUTHPROTO: Final[str] = os.getenv("SNMPAUTHPROTO", "SHA") -# SNMPPRIVPROTO: Final[str] = os.getenv("SNMPPRIVPROTO", "SHA") -SNMPORT: Final[int] = int(os.getenv("SNMPORT", 161)) - - -# Check if SNMP ENV are empty -if not SNMPUSER or not SNMPPRIVKEY or not SNMPAUTHKEY: - raise Exception("No SNMP user or/and PrivAuth passed") - - -# SNMP -USMUSRDATA = UsmUserData( - userName=SNMPUSER, - authKey=SNMPAUTHKEY, - privKey=SNMPPRIVKEY, - authProtocol=usmHMACSHAAuthProtocol, - privProtocol=usmAesCfb128Protocol, - ) - - - - - # IDRAC78 get data for snmpPyIDRACData class -async def idrac7_8PoolRemote_v3(remoteIP: str, queueToInsrt: asyncio.Queue): +async def idrac7_8PoolRemote_v3( + remoteIP: str, + queueToInsrt: asyncio.Queue, + SNMPUSER: str, + SNMPAUTHKEY: str, + SNMPPRIVKEY: str, + ROUND_PREC: int = 2, + SNMPORT: int = 161 + ): print("starting work on ", remoteIP) + # SNMPUSRDATA + USMUSRDATA = UsmUserData( + userName=SNMPUSER, + authKey=SNMPAUTHKEY, + privKey=SNMPPRIVKEY, + authProtocol=usmHMACSHAAuthProtocol, + privProtocol=usmAesCfb128Protocol, + ) snmpEngine = SnmpEngine() # 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 if errorIndication: + if errorIndication == "No SNMP response received before timeout": + print(f"Host {remoteIP} timed out.\nContinuing...") + snmpEngine.close_dispatcher() + return 1 print(errorIndication) elif errorStatus: print( @@ -73,17 +63,17 @@ async def idrac7_8PoolRemote_v3(remoteIP: str, queueToInsrt: asyncio.Queue): try: # 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 - 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] - 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] - 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 - 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()) hasCPU2 = any("cpu2" in str(thing).lower() for thing in sensorNamesResults.values()) diff --git a/cont/idrac/idrac9.py b/cont/idrac/idrac9.py index 5ab4f67..da63f5b 100644 --- a/cont/idrac/idrac9.py +++ b/cont/idrac/idrac9.py @@ -10,40 +10,27 @@ from typing import Annotated, Final # SNMP 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) -SNMPPRIVKEY: Final[str] = os.getenv("SNMPPRIVKEY", None) -SNMPAUTHKEY: Final[str] = os.getenv("SNMPAUTHKEY", None) -# Right now I'll only use SHA -# SNMPAUTHPROTO: Final[str] = os.getenv("SNMPAUTHPROTO", "SHA") -# SNMPPRIVPROTO: Final[str] = os.getenv("SNMPPRIVPROTO", "SHA") -SNMPORT: Final[int] = int(os.getenv("SNMPORT", 161)) - - -# Check if SNMP ENV are empty -if not SNMPUSER or not SNMPPRIVKEY or not SNMPAUTHKEY: - raise Exception("No SNMP user or/and PrivAuth passed") - - -# SNMP -USMUSRDATA = UsmUserData( - userName=SNMPUSER, - authKey=SNMPAUTHKEY, - privKey=SNMPPRIVKEY, - authProtocol=usmHMACSHAAuthProtocol, - privProtocol=usmAesCfb128Protocol, - ) - - - - - # IDRAC get data for snmpPyIDRACData class -async def idrac9PoolRemote_v3(remoteIP: str, queueToInsrt: asyncio.Queue): +async def idrac9PoolRemote_v3( + remoteIP: str, + queueToInsrt: asyncio.Queue, + SNMPUSER: str, + SNMPAUTHKEY: str, + SNMPPRIVKEY: str, + ROUND_PREC: int = 2, + SNMPORT: int = 161 + ): print("starting work on ", remoteIP) + # SNMP + USMUSRDATA = UsmUserData( + userName=SNMPUSER, + authKey=SNMPAUTHKEY, + privKey=SNMPPRIVKEY, + authProtocol=usmHMACSHAAuthProtocol, + privProtocol=usmAesCfb128Protocol, + ) + snmpEngine = SnmpEngine() iterator = get_cmd( @@ -80,17 +67,17 @@ async def idrac9PoolRemote_v3(remoteIP: str, queueToInsrt: asyncio.Queue): try: # 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 - 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] - 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] - 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 - 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: print(f"{e}\nContinuing regardless...") return 1