Added error handling for idrac
This commit is contained in:
@@ -6,24 +6,18 @@ 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
|
|
||||||
if not SNMPUSER or not SNMPPRIVKEY or not SNMPAUTHKEY:
|
|
||||||
raise Exception("No SNMP user or/and PrivAuth passed")
|
|
||||||
|
|
||||||
|
|
||||||
# SNMP
|
|
||||||
USMUSRDATA = UsmUserData(
|
USMUSRDATA = UsmUserData(
|
||||||
userName=SNMPUSER,
|
userName=SNMPUSER,
|
||||||
authKey=SNMPAUTHKEY,
|
authKey=SNMPAUTHKEY,
|
||||||
@@ -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())
|
||||||
|
|||||||
@@ -10,23 +10,18 @@ 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)
|
|
||||||
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")
|
|
||||||
|
|
||||||
|
|
||||||
|
# IDRAC get data for snmpPyIDRACData class
|
||||||
|
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
|
# SNMP
|
||||||
USMUSRDATA = UsmUserData(
|
USMUSRDATA = UsmUserData(
|
||||||
userName=SNMPUSER,
|
userName=SNMPUSER,
|
||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user