Did a dynamic check to see what features a server has

This commit is contained in:
2026-03-02 20:03:24 +01:00
parent d3d274b2a1
commit 674eaef47a

View File

@@ -265,9 +265,11 @@ async def ciscoPoolRemote(remoteIP: str, queueToInsrt: asyncio.Queue):
# IDRAC78 get data for snmpPyIDRACData class # 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):
snmpEngine = SnmpEngine()
iterator = get_cmd( snmpEngine = SnmpEngine()
# try CPU2 as CPU1 is always there
mainIterator = get_cmd(
snmpEngine, snmpEngine,
# SNMPv1 = mpModel=0 (SNMPv2c would be mpModel=1) # SNMPv1 = mpModel=0 (SNMPv2c would be mpModel=1)
# CommunityData("public", mpModel=0), # CommunityData("public", mpModel=0),
@@ -276,25 +278,11 @@ async def idrac7_8PoolRemote_v3(remoteIP: str, queueToInsrt: asyncio.Queue):
ContextData(), ContextData(),
# Hostname (sysName.0) # Hostname (sysName.0)
ObjectType(ObjectIdentity(".1.3.6.1.2.1.1.5.0")), #0 ObjectType(ObjectIdentity(".1.3.6.1.2.1.1.5.0")), #0
# PSU1 powerDraw and PSU2 powerDraw (Amps)
ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.600.30.1.6.1.1")), #1
ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.600.30.1.6.1.2")), #2
# (Volts)
# ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.600.20.1.6.1.31")), #3
# ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.600.20.1.6.1.32")), #4
# Get Inlet, Exhaust, CPU1, CPU2
ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.700.20.1.6.1.1")), #3
ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.700.20.1.6.1.2")), #4
ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.700.20.1.6.1.3")), #5
ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.700.20.1.6.1.4")), #6
# Uptime in seconds # Uptime in seconds
ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.2.5.0")), #7 ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.2.5.0")), #1
) )
errorIndication, errorStatus, errorIndex, varBinds = await iterator errorIndication, errorStatus, errorIndex, mainVarBinds = await mainIterator
if errorIndication: if errorIndication:
print(errorIndication) print(errorIndication)
@@ -302,90 +290,127 @@ async def idrac7_8PoolRemote_v3(remoteIP: str, queueToInsrt: asyncio.Queue):
print( print(
"{} at {}".format( "{} at {}".format(
errorStatus.prettyPrint(), errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or "?", errorIndex and mainVarBinds[int(errorIndex) - 1][0] or "?",
) )
) )
else: else:
for oid, val in varBinds: for oid, val in mainVarBinds:
print(f"{oid.prettyPrint()} = {val.prettyPrint()}")
iterator2 = get_cmd(
snmpEngine,
# SNMPv1 = mpModel=0 (SNMPv2c would be mpModel=1)
# CommunityData("public", mpModel=0),
USMUSRDATA,
await UdpTransportTarget.create((remoteIP, SNMPORT)),
ContextData(),
# Hostname (sysName.0)
ObjectType(ObjectIdentity(".1.3.6.1.2.1.1.5.0")), #0
# PSU1 powerDraw and PSU2 powerDraw (Amps)
ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.600.30.1.6.1.1")), #1
ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.600.30.1.6.1.2")), #2
# (Volts)
# ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.600.20.1.6.1.31")), #3
# ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.600.20.1.6.1.32")), #4
# Get Inlet, Exhaust, CPU1, CPU2
ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.700.20.1.6.1.1")), #3
ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.700.20.1.6.1.2")), #4
ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.700.20.1.6.1.3")), #5
ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.700.20.1.6.1.4")), #6
# Uptime in seconds
ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.2.5.0")), #7
)
errorIndication2, errorStatus2, errorIndex2, varBinds2 = await iterator2
if errorIndication2:
print(errorIndication2)
elif errorStatus2:
print(
"{} at {}".format(
errorStatus2.prettyPrint(),
errorIndex2 and varBinds[int(errorIndex2) - 1][0] or "?",
)
)
else:
for oid, val in varBinds2:
print(f"{oid.prettyPrint()} = {val.prettyPrint()}") print(f"{oid.prettyPrint()} = {val.prettyPrint()}")
# 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")
# 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")
# PSU1 voltage, [PSU2 voltage]
# psusVoltResult = await walk_column_v3(snmpEngine, remoteIP, ".1.3.6.1.4.1.674.10892.5.4.600.20.1.6.1")
# In reversed order. PSU1 OID name [PSU2 OID name]
# currentsNamesResults[-1] would be "PS2 Voltage 2" and currentsNamesResults[-2] would be "PS1 Voltage 1" IF two PSUs are installed.
# Otherwise currentsNamesResults[-1] would be "PS1 Voltage 1"
# psusNamesResult = await walk_column_v3(snmpEngine, remoteIP, ".1.3.6.1.4.1.674.10892.5.4.600.20.1.8")
# 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")
# 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")
# .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")
hasExhaust = any("exhaust" in str(thing).lower() for thing in sensorNamesResults.values())
hasCPU2 = any("cpu2" in str(thing).lower() for thing in sensorNamesResults.values())
hasPSU2 = any("ps2" in str(thing).lower() for thing in currentsNamesResults.values())
voltList = [] voltList = []
for thing in voltResult: for thing in voltResult:
voltList.append(voltResult[thing]) voltList.append(voltResult[thing])
snmpEngine.close_dispatcher() snmpEngine.close_dispatcher()
# print(varBinds[1][-1])
# print(type(varBinds[1][-1])) # print("\n")
# print(remoteIP)
# print("\n")
# print(currentsCurrentResults, hasPSU2)
# print("\n")
# print(currentsNamesResults, hasCPU2)
# print("\n")
# print(psusVoltResult)
# print("\n")
# # print(psusNamesResult)
# # print("\n")
# print(sensorNamesResults)
# print("\n")
# print(sensorValuesResults, hasExhaust)
# print("\n")
# PSU2 values and board power
psu2PowerDraw = None
psu2Amperage = None
psu2Voltage = None
if hasPSU2:
psu2PowerDraw = round((int(currentsCurrentResults[2]) / 10) * (int(voltList[1]) / 1000), ROUND_PREC)
psu2Amperage = int(currentsCurrentResults[2]) / 10
psu2Voltage = round((int(voltList[1]) / 1000), ROUND_PREC)
boardPowerDraw = int(currentsCurrentResults[3])
else:
boardPowerDraw = int(currentsCurrentResults[2])
# Exhaustm CPU1 and CPU2 temp
exhaustTemp = None
cpu2Temp = None
if hasExhaust and hasCPU2:
exhaustTemp = int(sensorValuesResults[2]) / 10
cpu1Temp = int(sensorValuesResults[3]) / 10
cpu2Temp = int(sensorValuesResults[4]) / 10
elif hasExhaust and not hasCPU2:
exhaustTemp = int(sensorValuesResults[2]) / 10
cpu1Temp = int(sensorValuesResults[3]) / 10
elif hasCPU2 and not hasExhaust:
cpu1Temp = int(sensorValuesResults[3]) / 10
cpu2Temp = int(sensorValuesResults[4]) / 10
else:
cpu1Temp = int(sensorValuesResults[2]) / 10
# Prepare what to insert
returnObj = snmpPyIDRACData( returnObj = snmpPyIDRACData(
hostname=varBinds[0][-1], hostname=mainVarBinds[0][-1],
# Hostname # Hostname
powerDrawPSU1=round((int(varBinds[1][-1]) / 10) * (int(voltList[0]) / 1000), ROUND_PREC), powerDrawPSU1=round((int(currentsCurrentResults[1]) / 10) * (int(voltList[0]) / 1000), ROUND_PREC),
powerDrawPSU2=round((int(varBinds[2][-1]) / 10) * (int(voltList[1]) / 1000), ROUND_PREC), powerDrawPSU2=psu2PowerDraw,
# PSU1 and PSU2 power draw in Watts # PSU1 and PSU2 power draw in Watts
# board power draw
powerDrawBoard=boardPowerDraw,
voltagePSU1=round((int(voltList[0]) / 1000), ROUND_PREC), voltagePSU1=round((int(voltList[0]) / 1000), ROUND_PREC),
voltagePSU2=round((int(voltList[1]) / 1000), ROUND_PREC), voltagePSU2=psu2Voltage,
# PSU1 and PSU2 voltages # PSU1 and PSU2 voltages
inletTemp=int(varBinds[3][-1] / 10), inletTemp=(int(sensorValuesResults[1]) / 10),
exhaustTemp=int(varBinds[4][-1] / 10), exhaustTemp=exhaustTemp,
# Inlet and Exhaust temp # Inlet and Exhaust temp
cpu1Temp=int(varBinds[5][-1] / 10), cpu1Temp=cpu1Temp,
cpu2Temp=int(varBinds[6][-1] / 10), cpu2Temp=cpu2Temp,
# CPU1 and CPU2 temp # CPU1 and CPU2 temp
uptimeS=int(varBinds[7][-1]), uptimeS=int(mainVarBinds[1][-1]),
# seconds # seconds
uptimeH=round(((int(varBinds[7][-1]) / 60) / 60), ROUND_PREC), uptimeH=round(((int(mainVarBinds[1][-1]) / 60) / 60), ROUND_PREC),
# seconds->minutes->hours # seconds->minutes->hours
uptimeD=round((((int(varBinds[7][-1]) / 60) / 60) / 24), ROUND_PREC) uptimeD=round((((int(mainVarBinds[1][-1]) / 60) / 60) / 24), ROUND_PREC)
# seconds->minutes->hours->days # seconds->minutes->hours->days
) )
@@ -405,37 +430,16 @@ async def idrac9PoolRemote_v3(remoteIP: str, queueToInsrt: asyncio.Queue):
iterator = get_cmd( iterator = get_cmd(
snmpEngine, snmpEngine,
# SNMPv1 = mpModel=0 (SNMPv2c would be mpModel=1)
# CommunityData("public", mpModel=0),
USMUSRDATA, USMUSRDATA,
await UdpTransportTarget.create((remoteIP, SNMPORT)), await UdpTransportTarget.create((remoteIP, SNMPORT)),
ContextData(), ContextData(),
# Hostname (sysName.0) # Hostname (sysName.0)
ObjectType(ObjectIdentity(".1.3.6.1.2.1.1.5.0")), #0 ObjectType(ObjectIdentity(".1.3.6.1.2.1.1.5.0")), #0
# PSU1 powerDraw and PSU2 powerDraw (Amps)
ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.600.30.1.6.1.1")), #1
ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.600.30.1.6.1.2")), #2
# (Volts) nevermid, do not querry
# ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.600.20.1.6.1.33")), #3
# ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.600.20.1.6.1.34")), #4
# Get Inlet, Exhaust, CPU1, CPU2
ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.700.20.1.6.1.3")), #3
ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.700.20.1.6.1.4")), #4
ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.700.20.1.6.1.1")), #5
ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.700.20.1.6.1.2")), #6
# Uptime in seconds # Uptime in seconds
ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.2.5.0")), #7 ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.2.5.0")), #1
# Raw board power draw
ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.600.30.1.6.1.3")), #8
) )
errorIndication, errorStatus, errorIndex, mainVarBinds = await iterator
errorIndication, errorStatus, errorIndex, varBinds = await iterator
if errorIndication: if errorIndication:
print(errorIndication) print(errorIndication)
@@ -443,51 +447,103 @@ async def idrac9PoolRemote_v3(remoteIP: str, queueToInsrt: asyncio.Queue):
print( print(
"{} at {}".format( "{} at {}".format(
errorStatus.prettyPrint(), errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or "?", errorIndex and mainVarBinds[int(errorIndex) - 1][0] or "?",
) )
) )
else: else:
for oid, val in varBinds: for oid, val in mainVarBinds:
print(f"{oid.prettyPrint()} = {val.prettyPrint()}") print(f"{oid.prettyPrint()} = {val.prettyPrint()}")
# 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")
# 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")
# 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")
# 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")
# .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")
snmpEngine.close_dispatcher()
voltList = [] voltList = []
for thing in voltResult: for thing in voltResult:
voltList.append(voltResult[thing]) voltList.append(voltResult[thing])
snmpEngine.close_dispatcher() hasExhaust = any("exhaust" in str(thing).lower() for thing in sensorNamesResults.values())
hasCPU2 = any("cpu2" in str(thing).lower() for thing in sensorNamesResults.values())
hasPSU2 = any("ps2" in str(thing).lower() for thing in currentsNamesResults.values())
# PSU2 values and board power
psu2PowerDraw = None
psu2Amperage = None
psu2Voltage = None
if hasPSU2:
psu2PowerDraw = round((int(currentsCurrentResults[2]) / 10) * (int(voltList[1]) / 1000), ROUND_PREC)
psu2Amperage = int(currentsCurrentResults[2]) / 10
psu2Voltage = round((int(voltList[1]) / 1000), ROUND_PREC)
boardPowerDraw = int(currentsCurrentResults[3])
else:
boardPowerDraw = int(currentsCurrentResults[2])
# Exhaustm CPU1 and CPU2 temp
exhaustTemp = None
inletTemp = None
cpu2Temp = None
if hasExhaust and hasCPU2:
exhaustTemp = int(sensorValuesResults[4]) / 10
inletTemp = int(sensorValuesResults[3]) / 10
cpu2Temp = int(sensorValuesResults[2]) / 10
elif hasExhaust and not hasCPU2:
exhaustTemp = int(sensorValuesResults[3]) / 10
inletTemp = int(sensorValuesResults[2]) / 10
elif hasCPU2 and not hasExhaust:
inletTemp = int(sensorValuesResults[3]) / 10
cpu2Temp = int(sensorValuesResults[2]) / 10
else:
inletTemp = int(sensorValuesResults[2]) / 10
# print(varBinds[1][-1]) # print(varBinds[1][-1])
# print(type(varBinds[1][-1])) # print(type(varBinds[1][-1]))
returnObj = snmpPyIDRACData( returnObj = snmpPyIDRACData(
hostname=varBinds[0][-1], hostname=mainVarBinds[0][-1],
# Hostname # Hostname
powerDrawPSU1=round((int(varBinds[1][-1]) / 10) * (int(voltList[0]) / 1000), ROUND_PREC), powerDrawPSU1=round((int(currentsCurrentResults[1]) / 10) * (int(voltList[0]) / 1000), ROUND_PREC),
powerDrawPSU2=round((int(varBinds[2][-1]) / 10) * (int(voltList[1]) / 1000), ROUND_PREC), powerDrawPSU2=psu2PowerDraw,
# PSU1 and PSU2 power draw in Watts # PSU1 and PSU2 power draw in Watts
# Total board power consumption # board power draw
powerDrawBoard=int(varBinds[8][-1]), powerDrawBoard=boardPowerDraw,
voltagePSU1=round((int(voltList[0]) / 1000), ROUND_PREC), voltagePSU1=round((int(voltList[0]) / 1000), ROUND_PREC),
voltagePSU2=round((int(voltList[1]) / 1000), ROUND_PREC), voltagePSU2=psu2Voltage,
# PSU1 and PSU2 voltages # PSU1 and PSU2 voltages
inletTemp=int(varBinds[3][-1] / 10), inletTemp=inletTemp,
exhaustTemp=int(varBinds[4][-1] / 10), exhaustTemp=exhaustTemp,
# Inlet and Exhaust temp # Inlet and Exhaust temp
cpu1Temp=int(varBinds[5][-1] / 10), cpu1Temp=int(sensorValuesResults[1]) / 10,
cpu2Temp=int(varBinds[6][-1] / 10), cpu2Temp=cpu2Temp,
# CPU1 and CPU2 temp # CPU1 and CPU2 temp
uptimeS=int(varBinds[7][-1]), uptimeS=int(mainVarBinds[1][-1]),
# seconds # seconds
uptimeH=round(((int(varBinds[7][-1]) / 60) / 60), ROUND_PREC), uptimeH=round(((int(mainVarBinds[1][-1]) / 60) / 60), ROUND_PREC),
# seconds->minutes->hours # seconds->minutes->hours
uptimeD=round((((int(varBinds[7][-1]) / 60) / 60) / 24), ROUND_PREC) uptimeD=round((((int(mainVarBinds[1][-1]) / 60) / 60) / 24), ROUND_PREC)
# seconds->minutes->hours->days # seconds->minutes->hours->days
) )