Compare commits

..

5 Commits

Author SHA1 Message Date
886f7bbd19 Updated some modules and added async sql 2026-02-28 22:58:13 +01:00
f7d28b31b8 Collecting IDRAC stats works.
Data is being inserted to both InfluxDB and mariadb
2026-02-28 22:57:11 +01:00
912ce9c10e Copy sqlTable file to the container 2026-02-28 22:56:53 +01:00
943954ed9d Added a SQL table for use in SQLwriter 2026-02-28 22:56:37 +01:00
1936976312 Updated table for SQL 2026-02-28 22:56:25 +01:00
8 changed files with 106 additions and 51 deletions

View File

@@ -24,6 +24,7 @@ RUN python3 -m venv pyvenv && \
COPY ./main.py /app/snmpython/ COPY ./main.py /app/snmpython/
COPY ./funct.py /app/snmpython/ COPY ./funct.py /app/snmpython/
COPY ./classes.py /app/snmpython/ COPY ./classes.py /app/snmpython/
COPY ./sqlTables.py /app/snmpython/
# COPY ../code/MIBs/ /app/snmpython/MIBs # COPY ../code/MIBs/ /app/snmpython/MIBs
# COPY ./entrypoint.sh /entrypoint.sh # COPY ./entrypoint.sh /entrypoint.sh

View File

@@ -92,6 +92,7 @@ class snmpPyIDRACData():
inletTemp: float inletTemp: float
exhaustTemp: float exhaustTemp: float
cpu1Temp: float cpu1Temp: float
uptimeS: int
uptimeH: float uptimeH: float
# optional fields # optional fields
@@ -125,6 +126,7 @@ class snmpPyCiscoData():
inletTemp: float inletTemp: float
exhaustTemp: float exhaustTemp: float
cpu1Temp: float cpu1Temp: float
uptimeS: int
uptimeH: float uptimeH: float
# optional fields # optional fields
@@ -145,6 +147,7 @@ class snmpPyCiscoData():
f"Exhaust {self.exhaustTemp} C\n" f"Exhaust {self.exhaustTemp} C\n"
f"CPU1 {self.cpu1Temp} C\n" f"CPU1 {self.cpu1Temp} C\n"
f"CPU2 {self.cpu2Temp} C\n" f"CPU2 {self.cpu2Temp} C\n"
f"Uptime {self.uptimeS} Seconds\n"
f"Uptime {self.uptimeH} Hours\n" f"Uptime {self.uptimeH} Hours\n"
f"Uptime {self.uptimeD} Days" f"Uptime {self.uptimeD} Days"
) )

View File

@@ -1,9 +1,8 @@
import influxdb_client, sqlalchemy, random, os, asyncio import influxdb_client, sqlalchemy, random, os, asyncio
# from sqlmodel import Field, Session, SQLModel, create_engine, select from dataclasses import asdict
# from sqlalchemy import create_engine, exc # , Column, Integer, String, Numeric
# from sqlalchemy.ext.declarative import declarative_base
# from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.asyncio import create_async_engine from sqlalchemy.ext.asyncio import create_async_engine
from sqlTables import *
from classes import * from classes import *
from typing import Annotated, Final from typing import Annotated, Final
@@ -103,10 +102,14 @@ async def sqlDataWriter(
t1.insert(), [{"name": "some name 1"}, {"name": "some name 2"}] t1.insert(), [{"name": "some name 1"}, {"name": "some name 2"}]
) )
case "IDRAC": case "IDRAC":
payload = inpDict["value"] # snmpPyIDRACData
row = asdict(payload)
await eng.execute( await eng.execute(
# changeMeLater idracMeasurement.insert(),
t1.insert(), [{"name": "some name 1"}, {"name": "some name 2"}] [row]
) )
return 0
case "FANS": case "FANS":
await eng.execute( await eng.execute(
# changeMeLater # changeMeLater
@@ -146,15 +149,21 @@ async def fluxWriter(
# Prep InfluxDB data # Prep InfluxDB data
inflxdb_Data_To_Send = ( inflxdb_Data_To_Send = (
influxdb_client.Point(f"{INFXLUXDB_MEASUEREMENT}") influxdb_client.Point(INFXLUXDB_MEASUEREMENT)
.tag("PLACE", inpayload.name) .tag("SOURCE", inpDict["source"])
.tag("TEMP", sensorIDinp) .tag("TYPE", inpDict["type"])
.tag("TEMP", whatTheSensor) .tag("HOSTNAME", inpDict["value"].hostname)
.field("TEMP", inpayload.temp) .field("PowerDrawPSU1", inpDict["value"].powerDrawPSU1)
.field("TEMP", inpayload.humid) .field("PowerDrawPSU2", inpDict["value"].powerDrawPSU2)
.field("TEMP", inpayload.hicc) .field("VoltagePSU1", inpDict["value"].voltagePSU1)
.field("TEMP", inpayload.presss) .field("VoltagePSU2", inpDict["value"].voltagePSU2)
.field("TEMP", inpayload.alttd) .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: try:
@@ -252,7 +261,7 @@ async def ciscoPoolRemote(remoteIP: str, queueToInsrt: asyncio.Queue):
"type": "snmpPyCiscoData" "type": "snmpPyCiscoData"
} }
# return returnObj # return returnObj
queueToInsrt.put(returnDict) await queueToInsrt.put(returnDict)
# IDRAC get data for snmpPyIDRACData class # IDRAC get data for snmpPyIDRACData class
async def idracPoolRemote_v3(remoteIP: str, queueToInsrt: asyncio.Queue): async def idracPoolRemote_v3(remoteIP: str, queueToInsrt: asyncio.Queue):
@@ -326,6 +335,8 @@ async def idracPoolRemote_v3(remoteIP: str, queueToInsrt: asyncio.Queue):
cpu2Temp=int(varBinds[8][-1] / 10), cpu2Temp=int(varBinds[8][-1] / 10),
# CPU1 and CPU2 temp # CPU1 and CPU2 temp
uptimeS=int(varBinds[9][-1]),
# seconds
uptimeH=round(((int(varBinds[9][-1]) / 60) / 60), ROUND_PREC), uptimeH=round(((int(varBinds[9][-1]) / 60) / 60), ROUND_PREC),
# seconds->minutes->hours # seconds->minutes->hours
uptimeD=round((((int(varBinds[9][-1]) / 60) / 60) / 24), ROUND_PREC) uptimeD=round((((int(varBinds[9][-1]) / 60) / 60) / 24), ROUND_PREC)
@@ -338,7 +349,7 @@ async def idracPoolRemote_v3(remoteIP: str, queueToInsrt: asyncio.Queue):
"type": "snmpPyIDRACData" "type": "snmpPyIDRACData"
} }
# return returnObj # return returnObj
queueToInsrt.put(returnDict) await queueToInsrt.put(returnDict)
# IDRAC get FAN data # IDRAC get FAN data
@@ -388,3 +399,5 @@ async def idracPoolRemoteFAN_v3(remoteIP: str, queueToInsrt: asyncio.Queue) -> d
"value": out, "value": out,
"type": "Dict" "type": "Dict"
} }
await queueToInsrt.put(returnDict)

View File

@@ -9,8 +9,11 @@ from funct import *
from classes import * from classes import *
# Program ENV--------------------------------------- # Program ENV---------------------------------------
IDRAC_HOST_LIST: Final[list] = os.getenv("IDRAC_HOST_LIST").split(";") try:
CISCO_HOST_LIST: Final[list] = os.getenv("CISCO_HOST_LIST").split(";") IDRAC_HOST_LIST: Final[list] = os.getenv("IDRAC_HOST_LIST", None).split(";")
CISCO_HOST_LIST: Final[list] = os.getenv("CISCO_HOST_LIST", None).split(";")
except:
raise Exception("No IDRAC hosts variable")
@@ -41,21 +44,24 @@ async def main():
# idracQueue = asyncio.Queue() # idracQueue = asyncio.Queue()
# ciscoQueue = asyncio.Queue() # ciscoQueue = asyncio.Queue()
# fanQueue = asyncio.Queue() # fanQueue = asyncio.Queue()
mainQueue(maxsize=225) mainQueue = asyncio.Queue(maxsize=225)
asyncio.create_task(ALLdbWriter(mainQueue))
while True: while True:
tasks = []
# IDRAC part # IDRAC part
async with asyncio.TaskGroup() as tg: async with asyncio.TaskGroup() as tg:
for IdracIP in IDRAC_HOST_LIST: for IdracIP in IDRAC_HOST_LIST:
tasks.append(tg.create_task(idracPoolRemote_v3(IdracIP, mainQueue))) tg.create_task(idracPoolRemote_v3(IdracIP, mainQueue))
# tasks.append(tg.create_task(idracPoolRemoteFAN_v3(IdracIP, mainQueue))) # FANS
# tg.create_task(idracPoolRemoteFAN_v3(IdracIP, mainQueue))
# CISCO devices
# for CiscoIP in CISCO_HOST_LIST: # for CiscoIP in CISCO_HOST_LIST:
# tasks.append(tg.create_task(ciscoPoolRemote(CiscoIP, mainQueue))) # tg.create_task(ciscoPoolRemote(CiscoIP, mainQueue))
sleep(20) await asyncio.sleep(20)
@@ -75,10 +81,13 @@ async def main():
# print("End of code") # print("End of code")
if __name__ == "__main__": if __name__ == "__main__":
# qu = asyncio.Queue()
# asyncio.run(idracPoolRemote_v3("192.168.20.7", qu))
asyncio.run(main())
loop = asyncio.get_event_loop() # loop = asyncio.get_event_loop()
task = loop.create_task(main()) # task = loop.create_task(main())

View File

@@ -1,13 +1,14 @@
# mysql-connector-python==9.2.0 # mysql-connector-python==9.2.0
PyMySQL==1.1.1 PyMySQL==1.1.2
sqlmodel==0.0.24 sqlmodel==0.0.37
sqlalchemy[asyncio] sqlalchemy[asyncio]==2.0.47
pydantic==2.10.6 asyncmy==0.2.11
pydantic_core==2.27.2 pydantic==2.12.5
pydantic_core==2.41.5
annotated-types==0.7.0 annotated-types==0.7.0
typing==3.7.4.3 typing==3.7.4.3
pysnmp==7.1.22 pysnmp==7.1.22
cryptography==46.0.5 cryptography==46.0.5
# requests==2.32.3 # requests==2.32.5
influxdb-client==1.49.0 influxdb-client==1.50.0
# influxdb3-python==0.18.0 # influxdb3-python==0.18.0

View File

25
cont/sqlTables.py Normal file
View File

@@ -0,0 +1,25 @@
from sqlalchemy import Table, Column, MetaData, Integer, String, TIMESTAMP, BigInteger, Numeric, text
metadata = MetaData()
idracMeasurement = Table(
"IDRACmeasurement",
metadata,
Column("id", Integer, primary_key=True, autoincrement=True),
Column("time_stamp", TIMESTAMP, server_default=text("CURRENT_TIMESTAMP"), nullable=False),
Column("hostname", String(64), nullable=False),
Column("powerDrawPSU1", Numeric(7, 2)),
Column("powerDrawPSU2", Numeric(7, 2)),
Column("voltagePSU1", Numeric(7, 2)),
Column("voltagePSU2", Numeric(7, 2)),
Column("inletTemp", Numeric(5, 2)),
Column("exhaustTemp", Numeric(5, 2)),
Column("cpu1Temp", Numeric(5, 2)),
Column("cpu2Temp", Numeric(5, 2)),
Column("uptimeS", BigInteger),
Column("uptimeH", Numeric(8, 3)),
Column("uptimeD", Numeric(8, 3)),
)

View File

@@ -25,21 +25,24 @@ SET NAMES utf8mb4;
-- New universal table type -- New universal table type
CREATE TABLE idracHOSTNAMECHANGEME ( CREATE TABLE IDRACmeasurement (
id MEDIUMINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, id MEDIUMINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
time_stamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, time_stamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
hostname TEXT(30), hostname VARCHAR(64) NOT NULL,
powerDrawPSU1 FLOAT, powerDrawPSU1 DECIMAL(7,2),
powerDrawPSU2 FLOAT NULL, powerDrawPSU2 DECIMAL(7,2) NULL,
voltagePSU1 TINYINT(100), voltagePSU1 DECIMAL(7,2),
voltagePSU2 TINYINT(100) NULL, voltagePSU2 DECIMAL(7,2) NULL,
inletTemp FLOAT, inletTemp DECIMAL(5,2),
exhaustTemp FLOAT, exhaustTemp DECIMAL(5,2),
cpu1Temp FLOAT, cpu1Temp DECIMAL(5,2),
cpu2Temp FLOAT NULL, cpu2Temp DECIMAL(5,2) NULL,
uptimeH INT , uptimeS BIGINT,
uptimeD FLOAT NULL uptimeH DECIMAL(8,3),
uptimeD DECIMAL(8,3) NULL,
INDEX idx_time (time_stamp),
INDEX idx_host_time (hostname, time_stamp)
); );
CREATE TABLE fansHOSTNAMEHERE ( CREATE TABLE fansHOSTNAMEHERE (