Got 3750-X monitoring working

This commit is contained in:
2026-03-17 19:38:27 +01:00
parent c474f9c9c2
commit e66998b826
9 changed files with 424 additions and 132 deletions

View File

@@ -68,4 +68,100 @@ async def fluxIDRACWriter(
return 1
return 0
# return {"STATUS": "succesfully inserted to InfluxDB"}
# return {"STATUS": "succesfully inserted to InfluxDB"}
async def fluxDataWriter(
inpDict: dict
) -> int:
"""
Insert temperature data into InfluxDB
:inputQueue: Asyncio Queue that has what is needed to be sent
"""
# inputQueue have multiple such Dicts
# {
# "source": "IDRAC",
# "value": returnObj,
# "type": "snmpPyIDRACData"
# }
if write_fluxdb_api is None:
return 2
match inpDict["source"]:
case "CISCO":
match inpDict["device"]:
case "3750X":
# Prep InfluxDB data
inflxdb_3750X_Data_To_Send = (
influxdb_client.Point(INFXLUXDB_MEASUEREMENT)
.tag("SOURCE", inpDict["source"])
.tag("DEVICE", inpDict["device"])
.tag("TYPE", inpDict["type"])
.tag("HOSTNAME", inpDict["value"].hostname)
.field("systemStatus", inpDict["value"].systemStatus)
.field("systemTemp", inpDict["value"].systemTemp)
.field("last5SecUsage", inpDict["value"].last5SecUsage)
.field("last1MinUsage", inpDict["value"].last1MinUsage)
.field("last5MinUsage", inpDict["value"].last5MinUsage)
.field("uptimeS", inpDict["value"].uptimeS)
)
try:
write_fluxdb_api.write(bucket=INFLUXBCKT, org=INFLUXORG, record=inflxdb_3750X_Data_To_Send)
except Exception as e:
print(e)
return 1
case "NEXUS":
...
return 0
case _:
print(f"{inpDict['device']} is not supported.\nOnly '3750X' and 'Nexus' are.")
return 1
case "IDRAC":
# Prep InfluxDB data
inflxdb_IDRAC_Data_To_Send = (
influxdb_client.Point(INFXLUXDB_MEASUEREMENT)
.tag("SOURCE", inpDict["source"])
.tag("TYPE", inpDict["type"])
.tag("HOSTNAME", inpDict["value"].hostname)
.field("PowerDrawPSU1", inpDict["value"].powerDrawPSU1)
.field("PowerDrawPSU2", inpDict["value"].powerDrawPSU2)
.field("TotalBoardPower", inpDict["value"].powerDrawBoard)
.field("VoltagePSU1", inpDict["value"].voltagePSU1)
.field("VoltagePSU2", inpDict["value"].voltagePSU2)
.field("InletTemperature", inpDict["value"].inletTemp)
.field("ExhaustTemperature", inpDict["value"].exhaustTemp)
.field("TemperatureCPU1", inpDict["value"].cpu1Temp)
.field("TemperatureCPU2", inpDict["value"].cpu2Temp)
.field("UptimeInSeconds", inpDict["value"].uptimeS)
.field("UptimeInHours", inpDict["value"].uptimeH)
.field("UptimeInDays", inpDict["value"].uptimeD)
)
try:
write_fluxdb_api.write(bucket=INFLUXBCKT, org=INFLUXORG, record=inflxdb_IDRAC_Data_To_Send)
except Exception as e:
print(e)
return 1
case "FANS":
await eng.execute(
# changeMeLater
t1.insert(), [{"name": "some name 1"}, {"name": "some name 2"}]
)
case _:
print(f"No such source of data as {inpDict['source']}")
return 1
return 0
# asyncio.sleep(5)

View File

@@ -3,7 +3,8 @@ from sqlalchemy.ext.asyncio import create_async_engine
from typing import Annotated, Final
from dataclasses import asdict
from models.idracModel import snmpPyIDRACData
from models.sqlTable import idracMeasurement
from models.ciscoModel import C3750XciscoData
from models.sqlTable import idracMeasurement, C3750XMeasurement
# SQL ENV-------------------------------------------
USESQL: Final[int] = int(os.getenv("USESQL", 0))
@@ -27,7 +28,7 @@ else:
engine = None
async def sqlIDRACDataWriter(
async def sqlDataWriter(
inpDict: dict
) -> int:
@@ -44,10 +45,36 @@ async def sqlIDRACDataWriter(
match inpDict["source"]:
case "CISCO":
await eng.execute(
# changeMeLater
t1.insert(), [{"name": "some name 1"}, {"name": "some name 2"}]
)
match inpDict["device"]:
case "3750X":
payload = inpDict["value"] # snmpPyIDRACData
row = asdict(payload)
await eng.execute(
C3750XMeasurement.insert(),
[row]
)
return 0
case "NEXUS":
payload = inpDict["value"] # snmpPyIDRACData
row = asdict(payload)
await eng.execute(
NexusMeasurement.insert(),
[row]
)
return 0
case _:
print(f"{inpDict['device']} is not supported.\nOnly '3750X' and 'Nexus' are.")
return 1
# await eng.execute(
# # changeMeLater
# t1.insert(), [{"name": "some name 1"}, {"name": "some name 2"}]
# )
case "IDRAC":
payload = inpDict["value"] # snmpPyIDRACData
row = asdict(payload)
@@ -73,4 +100,4 @@ async def sqlIDRACDataWriter(
return 0
# asyncio.sleep(5)
# asyncio.sleep(5)

View File

@@ -1,7 +1,7 @@
import asyncio, os
from typing import Annotated, Final
from db.Influx import fluxIDRACWriter
from db.MariaDB import sqlIDRACDataWriter
from db.Influx import fluxDataWriter
from db.MariaDB import sqlDataWriter
USEINFLUX: Final[int] = int(os.getenv("USEINFLUX", 1))
USESQL: Final[int] = int(os.getenv("USESQL", 0))
@@ -15,7 +15,7 @@ async def ALLdbIDRACWriter(inputQueue: asyncio.Queue) -> None:
try:
if USESQL:
sqlResult = await sqlIDRACDataWriter(qu)
sqlResult = await sqlDataWriter(qu)
match sqlResult:
case 1:
print("Wrong source")
@@ -26,7 +26,7 @@ async def ALLdbIDRACWriter(inputQueue: asyncio.Queue) -> None:
case _:
print("Inserted in SQL")
if USEINFLUX:
fluxResult = await fluxIDRACWriter(qu)
fluxResult = await fluxDataWriter(qu)
match fluxResult:
case 1:
print("could not insert")