diff --git a/cont/classes.py b/cont/classes.py index ac6d655..2378ffb 100644 --- a/cont/classes.py +++ b/cont/classes.py @@ -99,6 +99,7 @@ class snmpPyIDRACData(): uptimeD: float | None = None cpu2Temp: float | None = None powerDrawPSU2: int | None = None + powerDrawBoard: int | None = None voltagePSU2: int | None = None @@ -107,6 +108,7 @@ class snmpPyIDRACData(): f"{self.hostname}\n" f"PSU1 {self.powerDrawPSU1} Watts\n" f"PSU2 {self.powerDrawPSU2} Watts\n" + f"Board {self.powerDrawBoard} Watts\n" f"PSU1 {self.voltagePSU1} Volts\n" f"PSU2 {self.voltagePSU2} Volts\n" f"Inlet {self.inletTemp} C\n" diff --git a/cont/funct.py b/cont/funct.py index d4b0ebd..83f64e8 100644 --- a/cont/funct.py +++ b/cont/funct.py @@ -263,8 +263,8 @@ async def ciscoPoolRemote(remoteIP: str, queueToInsrt: asyncio.Queue): # return returnObj await queueToInsrt.put(returnDict) -# IDRAC get data for snmpPyIDRACData class -async def idracPoolRemote_v3(remoteIP: str, queueToInsrt: asyncio.Queue): +# IDRAC78 get data for snmpPyIDRACData class +async def idrac7_8PoolRemote_v3(remoteIP: str, queueToInsrt: asyncio.Queue): snmpEngine = SnmpEngine() iterator = get_cmd( @@ -281,17 +281,17 @@ async def idracPoolRemote_v3(remoteIP: str, queueToInsrt: asyncio.Queue): 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 + # 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")), #5 - ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.700.20.1.6.1.2")), #6 - ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.700.20.1.6.1.3")), #7 - ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.4.700.20.1.6.1.4")), #8 + 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")), #9 + ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.2.5.0")), #7 ) errorIndication, errorStatus, errorIndex, varBinds = await iterator @@ -309,8 +309,54 @@ async def idracPoolRemote_v3(remoteIP: str, queueToInsrt: asyncio.Queue): for oid, val in varBinds: print(f"{oid.prettyPrint()} = {val.prettyPrint()}") - # for element in varBinds: - # print(element) + 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()}") + + + voltResult = await walk_column_v3(snmpEngine, remoteIP, ".1.3.6.1.4.1.674.10892.5.4.600.20.1.6.1") + + voltList = [] + for thing in voltResult: + voltList.append(voltResult[thing]) snmpEngine.close_dispatcher() # print(varBinds[1][-1]) @@ -319,27 +365,27 @@ async def idracPoolRemote_v3(remoteIP: str, queueToInsrt: asyncio.Queue): hostname=varBinds[0][-1], # Hostname - powerDrawPSU1=round((int(varBinds[1][-1]) / 10) * (int(varBinds[3][-1]) / 1000), ROUND_PREC), - powerDrawPSU2=round((int(varBinds[2][-1]) / 10) * (int(varBinds[4][-1]) / 1000), ROUND_PREC), + powerDrawPSU1=round((int(varBinds[1][-1]) / 10) * (int(voltList[0]) / 1000), ROUND_PREC), + powerDrawPSU2=round((int(varBinds[2][-1]) / 10) * (int(voltList[1]) / 1000), ROUND_PREC), # PSU1 and PSU2 power draw in Watts - voltagePSU1=round((int(varBinds[3][-1]) / 1000), ROUND_PREC), - voltagePSU2=round((int(varBinds[4][-1]) / 1000), ROUND_PREC), + voltagePSU1=round((int(voltList[0]) / 1000), ROUND_PREC), + voltagePSU2=round((int(voltList[1]) / 1000), ROUND_PREC), # PSU1 and PSU2 voltages - inletTemp=int(varBinds[5][-1] / 10), - exhaustTemp=int(varBinds[6][-1] / 10), + inletTemp=int(varBinds[3][-1] / 10), + exhaustTemp=int(varBinds[4][-1] / 10), # Inlet and Exhaust temp - cpu1Temp=int(varBinds[7][-1] / 10), - cpu2Temp=int(varBinds[8][-1] / 10), + cpu1Temp=int(varBinds[5][-1] / 10), + cpu2Temp=int(varBinds[6][-1] / 10), # CPU1 and CPU2 temp - uptimeS=int(varBinds[9][-1]), + uptimeS=int(varBinds[7][-1]), # seconds - uptimeH=round(((int(varBinds[9][-1]) / 60) / 60), ROUND_PREC), + uptimeH=round(((int(varBinds[7][-1]) / 60) / 60), ROUND_PREC), # seconds->minutes->hours - uptimeD=round((((int(varBinds[9][-1]) / 60) / 60) / 24), ROUND_PREC) + uptimeD=round((((int(varBinds[7][-1]) / 60) / 60) / 24), ROUND_PREC) # seconds->minutes->hours->days ) @@ -352,6 +398,110 @@ async def idracPoolRemote_v3(remoteIP: str, queueToInsrt: asyncio.Queue): await queueToInsrt.put(returnDict) + +# IDRAC get data for snmpPyIDRACData class +async def idrac9PoolRemote_v3(remoteIP: str, queueToInsrt: asyncio.Queue): + snmpEngine = SnmpEngine() + + iterator = 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) 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 + ObjectType(ObjectIdentity(".1.3.6.1.4.1.674.10892.5.2.5.0")), #7 + + # 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, varBinds = await iterator + + if errorIndication: + print(errorIndication) + elif errorStatus: + print( + "{} at {}".format( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex) - 1][0] or "?", + ) + ) + else: + for oid, val in varBinds: + print(f"{oid.prettyPrint()} = {val.prettyPrint()}") + + # .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") + + voltList = [] + for thing in voltResult: + voltList.append(voltResult[thing]) + + snmpEngine.close_dispatcher() + # print(varBinds[1][-1]) + # print(type(varBinds[1][-1])) + returnObj = snmpPyIDRACData( + hostname=varBinds[0][-1], + # Hostname + + powerDrawPSU1=round((int(varBinds[1][-1]) / 10) * (int(voltList[0]) / 1000), ROUND_PREC), + powerDrawPSU2=round((int(varBinds[2][-1]) / 10) * (int(voltList[1]) / 1000), ROUND_PREC), + # PSU1 and PSU2 power draw in Watts + + # Total board power consumption + powerDrawBoard=int(varBinds[8][-1]), + + voltagePSU1=round((int(voltList[0]) / 1000), ROUND_PREC), + voltagePSU2=round((int(voltList[1]) / 1000), ROUND_PREC), + # PSU1 and PSU2 voltages + + inletTemp=int(varBinds[3][-1] / 10), + exhaustTemp=int(varBinds[4][-1] / 10), + # Inlet and Exhaust temp + + cpu1Temp=int(varBinds[5][-1] / 10), + cpu2Temp=int(varBinds[6][-1] / 10), + # CPU1 and CPU2 temp + + uptimeS=int(varBinds[7][-1]), + # seconds + uptimeH=round(((int(varBinds[7][-1]) / 60) / 60), ROUND_PREC), + # seconds->minutes->hours + uptimeD=round((((int(varBinds[7][-1]) / 60) / 60) / 24), ROUND_PREC) + # seconds->minutes->hours->days + ) + + returnDict = { + "source": "IDRAC", + "value": returnObj, + "type": "snmpPyIDRACData" + } + # return returnObj + await queueToInsrt.put(returnDict) + + + + # IDRAC get FAN data async def walk_column_v3(snmpEngine, remoteIP: str, base_oid: str) -> dict: rows = {} diff --git a/cont/main.py b/cont/main.py index f65c960..ad825d9 100644 --- a/cont/main.py +++ b/cont/main.py @@ -10,7 +10,8 @@ from classes import * # Program ENV--------------------------------------- try: - IDRAC_HOST_LIST: Final[list] = os.getenv("IDRAC_HOST_LIST", None).split(";") + IDRAC78_HOST_LIST: Final[list] = os.getenv("IDRAC78_HOST_LIST", None).split(";") + IDRAC9_HOST_LIST: Final[list] = os.getenv("IDRAC9_HOST_LIST", None).split(";") CISCO_HOST_LIST: Final[list] = os.getenv("CISCO_HOST_LIST", None).split(";") except: raise Exception("No IDRAC hosts variable") @@ -19,19 +20,24 @@ except: # Flightchecks------------------------------------------- # if HOST_LIST empty, raise Exception No hosts passed -if not IDRAC_HOST_LIST and not CISCO_HOST_LIST: +if not IDRAC78_HOST_LIST and not CISCO_HOST_LIST and not IDRAC9_HOST_LIST: raise Exception("No hosts passed\nExiting...") # for host in HOST_LIST check if valid IP and create a list with strings -for idracHost in IDRAC_HOST_LIST: +for idrac78Host in IDRAC78_HOST_LIST: try: - ip = str(ipaddress.IPv4Address(idracHost)) + ip = str(ipaddress.IPv4Address(idrac78Host)) except ValueError: - raise Exception(f" IP {ip} for IDRAC devices is invalid.\nExiting...") + raise Exception(f" IP {ip} for IDRAC7/8 devices is invalid.\nExiting...") for ciscoHost in CISCO_HOST_LIST: try: ip = str(ipaddress.IPv4Address(ciscoHost)) except ValueError: raise Exception(f" IP {ip} for Cisco devices is invalid.\nExiting...") +for idrac9Host in IDRAC9_HOST_LIST: + try: + ip = str(ipaddress.IPv4Address(idrac9Host)) + except ValueError: + raise Exception(f" IP {ip} for IDRAC9 devices is invalid.\nExiting...") # Done under "Program ENV" on line ~18 @@ -52,8 +58,10 @@ async def main(): # IDRAC part async with asyncio.TaskGroup() as tg: - for IdracIP in IDRAC_HOST_LIST: - tg.create_task(idracPoolRemote_v3(IdracIP, mainQueue)) + for Idrac78IP in IDRAC78_HOST_LIST: + tg.create_task(idrac7_8PoolRemote_v3(Idrac78IP, mainQueue)) + for Idrac9IP in IDRAC9_HOST_LIST: + tg.create_task(idrac9PoolRemote_v3(Idrac9IP, mainQueue)) # FANS # tg.create_task(idracPoolRemoteFAN_v3(IdracIP, mainQueue)) diff --git a/cont/sqlTables.py b/cont/sqlTables.py index 58fa17f..9402894 100644 --- a/cont/sqlTables.py +++ b/cont/sqlTables.py @@ -11,6 +11,7 @@ idracMeasurement = Table( Column("powerDrawPSU1", Numeric(7, 2)), Column("powerDrawPSU2", Numeric(7, 2)), + Column("powerDrawBoard", Numeric(7, 2)), Column("voltagePSU1", Numeric(7, 2)), Column("voltagePSU2", Numeric(7, 2)),