Compare commits
5 Commits
b074b9d633
...
886f7bbd19
| Author | SHA1 | Date | |
|---|---|---|---|
| 886f7bbd19 | |||
| f7d28b31b8 | |||
| 912ce9c10e | |||
| 943954ed9d | |||
| 1936976312 |
@@ -24,6 +24,7 @@ RUN python3 -m venv pyvenv && \
|
||||
COPY ./main.py /app/snmpython/
|
||||
COPY ./funct.py /app/snmpython/
|
||||
COPY ./classes.py /app/snmpython/
|
||||
COPY ./sqlTables.py /app/snmpython/
|
||||
# COPY ../code/MIBs/ /app/snmpython/MIBs
|
||||
|
||||
# COPY ./entrypoint.sh /entrypoint.sh
|
||||
|
||||
@@ -92,6 +92,7 @@ class snmpPyIDRACData():
|
||||
inletTemp: float
|
||||
exhaustTemp: float
|
||||
cpu1Temp: float
|
||||
uptimeS: int
|
||||
uptimeH: float
|
||||
|
||||
# optional fields
|
||||
@@ -125,6 +126,7 @@ class snmpPyCiscoData():
|
||||
inletTemp: float
|
||||
exhaustTemp: float
|
||||
cpu1Temp: float
|
||||
uptimeS: int
|
||||
uptimeH: float
|
||||
|
||||
# optional fields
|
||||
@@ -145,6 +147,7 @@ class snmpPyCiscoData():
|
||||
f"Exhaust {self.exhaustTemp} C\n"
|
||||
f"CPU1 {self.cpu1Temp} C\n"
|
||||
f"CPU2 {self.cpu2Temp} C\n"
|
||||
f"Uptime {self.uptimeS} Seconds\n"
|
||||
f"Uptime {self.uptimeH} Hours\n"
|
||||
f"Uptime {self.uptimeD} Days"
|
||||
)
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import influxdb_client, sqlalchemy, random, os, asyncio
|
||||
# from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
# from sqlalchemy import create_engine, exc # , Column, Integer, String, Numeric
|
||||
# from sqlalchemy.ext.declarative import declarative_base
|
||||
# from sqlalchemy.orm import sessionmaker
|
||||
from dataclasses import asdict
|
||||
|
||||
from sqlalchemy.ext.asyncio import create_async_engine
|
||||
from sqlTables import *
|
||||
|
||||
from classes import *
|
||||
from typing import Annotated, Final
|
||||
@@ -103,10 +102,14 @@ async def sqlDataWriter(
|
||||
t1.insert(), [{"name": "some name 1"}, {"name": "some name 2"}]
|
||||
)
|
||||
case "IDRAC":
|
||||
payload = inpDict["value"] # snmpPyIDRACData
|
||||
row = asdict(payload)
|
||||
|
||||
await eng.execute(
|
||||
# changeMeLater
|
||||
t1.insert(), [{"name": "some name 1"}, {"name": "some name 2"}]
|
||||
idracMeasurement.insert(),
|
||||
[row]
|
||||
)
|
||||
return 0
|
||||
case "FANS":
|
||||
await eng.execute(
|
||||
# changeMeLater
|
||||
@@ -146,15 +149,21 @@ async def fluxWriter(
|
||||
|
||||
# Prep InfluxDB data
|
||||
inflxdb_Data_To_Send = (
|
||||
influxdb_client.Point(f"{INFXLUXDB_MEASUEREMENT}")
|
||||
.tag("PLACE", inpayload.name)
|
||||
.tag("TEMP", sensorIDinp)
|
||||
.tag("TEMP", whatTheSensor)
|
||||
.field("TEMP", inpayload.temp)
|
||||
.field("TEMP", inpayload.humid)
|
||||
.field("TEMP", inpayload.hicc)
|
||||
.field("TEMP", inpayload.presss)
|
||||
.field("TEMP", inpayload.alttd)
|
||||
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("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:
|
||||
@@ -252,7 +261,7 @@ async def ciscoPoolRemote(remoteIP: str, queueToInsrt: asyncio.Queue):
|
||||
"type": "snmpPyCiscoData"
|
||||
}
|
||||
# return returnObj
|
||||
queueToInsrt.put(returnDict)
|
||||
await queueToInsrt.put(returnDict)
|
||||
|
||||
# IDRAC get data for snmpPyIDRACData class
|
||||
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),
|
||||
# CPU1 and CPU2 temp
|
||||
|
||||
uptimeS=int(varBinds[9][-1]),
|
||||
# seconds
|
||||
uptimeH=round(((int(varBinds[9][-1]) / 60) / 60), ROUND_PREC),
|
||||
# seconds->minutes->hours
|
||||
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"
|
||||
}
|
||||
# return returnObj
|
||||
queueToInsrt.put(returnDict)
|
||||
await queueToInsrt.put(returnDict)
|
||||
|
||||
|
||||
# IDRAC get FAN data
|
||||
@@ -388,3 +399,5 @@ async def idracPoolRemoteFAN_v3(remoteIP: str, queueToInsrt: asyncio.Queue) -> d
|
||||
"value": out,
|
||||
"type": "Dict"
|
||||
}
|
||||
|
||||
await queueToInsrt.put(returnDict)
|
||||
37
cont/main.py
37
cont/main.py
@@ -9,8 +9,11 @@ from funct import *
|
||||
from classes import *
|
||||
|
||||
# Program ENV---------------------------------------
|
||||
IDRAC_HOST_LIST: Final[list] = os.getenv("IDRAC_HOST_LIST").split(";")
|
||||
CISCO_HOST_LIST: Final[list] = os.getenv("CISCO_HOST_LIST").split(";")
|
||||
try:
|
||||
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()
|
||||
# ciscoQueue = asyncio.Queue()
|
||||
# fanQueue = asyncio.Queue()
|
||||
mainQueue(maxsize=225)
|
||||
mainQueue = asyncio.Queue(maxsize=225)
|
||||
|
||||
asyncio.create_task(ALLdbWriter(mainQueue))
|
||||
|
||||
while True:
|
||||
tasks = []
|
||||
|
||||
# IDRAC part
|
||||
async with asyncio.TaskGroup() as tg:
|
||||
for IdracIP in IDRAC_HOST_LIST:
|
||||
tasks.append(tg.create_task(idracPoolRemote_v3(IdracIP, mainQueue)))
|
||||
# tasks.append(tg.create_task(idracPoolRemoteFAN_v3(IdracIP, mainQueue)))
|
||||
|
||||
|
||||
# for CiscoIP in CISCO_HOST_LIST:
|
||||
# tasks.append(tg.create_task(ciscoPoolRemote(CiscoIP, mainQueue)))
|
||||
tg.create_task(idracPoolRemote_v3(IdracIP, mainQueue))
|
||||
# FANS
|
||||
# tg.create_task(idracPoolRemoteFAN_v3(IdracIP, mainQueue))
|
||||
|
||||
sleep(20)
|
||||
# CISCO devices
|
||||
# for CiscoIP in CISCO_HOST_LIST:
|
||||
# tg.create_task(ciscoPoolRemote(CiscoIP, mainQueue))
|
||||
|
||||
await asyncio.sleep(20)
|
||||
|
||||
|
||||
|
||||
@@ -75,10 +81,13 @@ async def main():
|
||||
# print("End of code")
|
||||
|
||||
if __name__ == "__main__":
|
||||
# qu = asyncio.Queue()
|
||||
# asyncio.run(idracPoolRemote_v3("192.168.20.7", qu))
|
||||
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
task = loop.create_task(main())
|
||||
asyncio.run(main())
|
||||
|
||||
# loop = asyncio.get_event_loop()
|
||||
# task = loop.create_task(main())
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
# mysql-connector-python==9.2.0
|
||||
PyMySQL==1.1.1
|
||||
sqlmodel==0.0.24
|
||||
sqlalchemy[asyncio]
|
||||
pydantic==2.10.6
|
||||
pydantic_core==2.27.2
|
||||
PyMySQL==1.1.2
|
||||
sqlmodel==0.0.37
|
||||
sqlalchemy[asyncio]==2.0.47
|
||||
asyncmy==0.2.11
|
||||
pydantic==2.12.5
|
||||
pydantic_core==2.41.5
|
||||
annotated-types==0.7.0
|
||||
typing==3.7.4.3
|
||||
pysnmp==7.1.22
|
||||
cryptography==46.0.5
|
||||
# requests==2.32.3
|
||||
influxdb-client==1.49.0
|
||||
# requests==2.32.5
|
||||
influxdb-client==1.50.0
|
||||
# influxdb3-python==0.18.0
|
||||
25
cont/sqlTables.py
Normal file
25
cont/sqlTables.py
Normal 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)),
|
||||
)
|
||||
29
tables.sql
29
tables.sql
@@ -25,21 +25,24 @@ SET NAMES utf8mb4;
|
||||
|
||||
|
||||
-- New universal table type
|
||||
CREATE TABLE idracHOSTNAMECHANGEME (
|
||||
CREATE TABLE IDRACmeasurement (
|
||||
id MEDIUMINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
time_stamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
hostname TEXT(30),
|
||||
powerDrawPSU1 FLOAT,
|
||||
powerDrawPSU2 FLOAT NULL,
|
||||
voltagePSU1 TINYINT(100),
|
||||
voltagePSU2 TINYINT(100) NULL,
|
||||
inletTemp FLOAT,
|
||||
exhaustTemp FLOAT,
|
||||
cpu1Temp FLOAT,
|
||||
cpu2Temp FLOAT NULL,
|
||||
uptimeH INT ,
|
||||
uptimeD FLOAT NULL
|
||||
time_stamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
hostname VARCHAR(64) NOT NULL,
|
||||
powerDrawPSU1 DECIMAL(7,2),
|
||||
powerDrawPSU2 DECIMAL(7,2) NULL,
|
||||
voltagePSU1 DECIMAL(7,2),
|
||||
voltagePSU2 DECIMAL(7,2) NULL,
|
||||
inletTemp DECIMAL(5,2),
|
||||
exhaustTemp DECIMAL(5,2),
|
||||
cpu1Temp DECIMAL(5,2),
|
||||
cpu2Temp DECIMAL(5,2) NULL,
|
||||
uptimeS BIGINT,
|
||||
uptimeH DECIMAL(8,3),
|
||||
uptimeD DECIMAL(8,3) NULL,
|
||||
|
||||
INDEX idx_time (time_stamp),
|
||||
INDEX idx_host_time (hostname, time_stamp)
|
||||
);
|
||||
|
||||
CREATE TABLE fansHOSTNAMEHERE (
|
||||
|
||||
Reference in New Issue
Block a user