wip
This commit is contained in:
parent
f6aa3b5f0f
commit
23ccf197c4
BIN
__pycache__/app.cpython-313.pyc
Normal file
BIN
__pycache__/app.cpython-313.pyc
Normal file
Binary file not shown.
BIN
__pycache__/grabber.cpython-313.pyc
Normal file
BIN
__pycache__/grabber.cpython-313.pyc
Normal file
Binary file not shown.
16
app.py
16
app.py
@ -1,8 +1,11 @@
|
||||
from fastapi import FastAPI, Request, HTTPException
|
||||
import json
|
||||
from grabber import Grabber
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
ordi1 = Grabber()
|
||||
|
||||
@app.post("/endpoint")
|
||||
async def receive_info(request: Request):
|
||||
# Lire le body brut
|
||||
@ -16,5 +19,16 @@ async def receive_info(request: Request):
|
||||
raise HTTPException(status_code=400, detail="Invalid JSON")
|
||||
|
||||
# Debug
|
||||
print("Infos recues :", data)
|
||||
print("Data grabbed :", data)
|
||||
|
||||
ordi1.hostname = data['HARDWARE']['hostname']
|
||||
ordi1.mb_serial = data['HARDWARE']['mb_serial']
|
||||
|
||||
print(f"Hostname is {ordi1.hostname}")
|
||||
print(f"Motherboard serial is {ordi1.mb_serial}")
|
||||
|
||||
return {"status": "ok"}
|
||||
|
||||
@app.get("/ordi1")
|
||||
async def get_ordi1_info():
|
||||
return ordi1
|
||||
35
grabber.py
Normal file
35
grabber.py
Normal file
@ -0,0 +1,35 @@
|
||||
#!/usr/bin/python3
|
||||
import configparser
|
||||
import requests
|
||||
|
||||
class Grabber():
|
||||
mb_serial = " "
|
||||
cpu_model = " "
|
||||
cpu_id = " "
|
||||
cpu_cores = " "
|
||||
cpu_threads = " "
|
||||
cpu_frequency_min = " "
|
||||
cpu_frequency_cur = " "
|
||||
cpu_frequency_max = " "
|
||||
ram_size = " "
|
||||
ram_slots = " "
|
||||
ram_number = " "
|
||||
|
||||
os = " "
|
||||
arch = " "
|
||||
desktop_env = " "
|
||||
window_manager = " "
|
||||
kernel = " "
|
||||
|
||||
def fetch_summary(self):
|
||||
return
|
||||
def shutdown():
|
||||
return
|
||||
def status(self):
|
||||
return
|
||||
def link_to_user(self,user):
|
||||
return
|
||||
def remove_user_access(self):
|
||||
return
|
||||
def show_users(self):
|
||||
return
|
||||
@ -152,14 +152,14 @@ CPU_ID=$(dmidecode -t processor | grep ID | cut -d: -f2 | sed 's/^ *//' | xargs)
|
||||
CPU_FREQUENCY_MIN=$(lscpu | grep MHz | cut -d: -f2 | sed -n '3p' | tr -s " " | sed 's/\ //' | cut -d, -f1)
|
||||
CPU_FREQUENCY_CUR=$(dmidecode | grep "MHz" | cut -d: -f2 | sed -n '3p' | sed 's/\ //')
|
||||
CPU_FREQUENCY_MAX=$(dmidecode | grep "MHz" | cut -d: -f2 | sed -n '2p' | sed 's/\ //')
|
||||
CPU_CORES_NUMBER=$(inxi | grep core | cut -d' ' -f2 | sed 's/-core//')
|
||||
CPU_THREADS_NUMBER=$(nproc)
|
||||
CPU_CORES=$(inxi | grep core | cut -d' ' -f2 | sed 's/-core//')
|
||||
CPU_THREADS=$(nproc)
|
||||
#---------------------------------
|
||||
|
||||
#------------ RAM ----------------
|
||||
RAM_SIZE=$(lsmem | grep "Total online memory" | cut -d: -f2 | sed 's/\ *//')
|
||||
RAM_NUMBER=$(dmidecode --type memory | grep 'Rank' | wc -l)
|
||||
RAM_SLOTS_NUMBER=$(dmidecode --type memory | grep "Number Of Devices" | cut -d: -f2 | sed 's/\ //')
|
||||
RAM_SLOTS=$(dmidecode --type memory | grep "Number Of Devices" | cut -d: -f2 | sed 's/\ //')
|
||||
#---------------------------------
|
||||
|
||||
#------------ COMPONENTS ---------
|
||||
|
||||
@ -1,71 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
import configparser
|
||||
import requests
|
||||
class ordinateur():
|
||||
mb_serial = " "
|
||||
cpu_model = " "
|
||||
cpu_id = " "
|
||||
cpu_cores_number = " "
|
||||
cpu_threads_number = " "
|
||||
cpu_frequency_min = " "
|
||||
cpu_frequency_cur = " "
|
||||
cpu_frequency_max = " "
|
||||
gpu_model = " "
|
||||
ram_size = " "
|
||||
ram_slots_number = " "
|
||||
ram_number = " "
|
||||
ram_gen = " "
|
||||
|
||||
os = " "
|
||||
arch = " "
|
||||
desktop = " "
|
||||
wm = " "
|
||||
kernel = " "
|
||||
def __init__(self):
|
||||
self.reload()
|
||||
def reload(self):
|
||||
r = requests.get("http://localhost:8000/summary.txt")
|
||||
r.raise_for_status()
|
||||
print(type(r.content.decode("utf-8")))
|
||||
sum = configparser.ConfigParser()
|
||||
sum.read_string(r.content.decode("utf-8"))
|
||||
# sum.read("/opt/grabber/summary.txt")
|
||||
if "MB_SERIAL" in sum['HARDWARE']:
|
||||
self.mb_serial=sum['HARDWARE']['MB_SERIAL']
|
||||
if "CHASSIS_SERIAL" in sum['HARDWARE']:
|
||||
self.chassis_serial=sum['HARDWARE']['CHASSIS_SERIAL']
|
||||
if "CPU" in sum['HARDWARE']:
|
||||
self.cpu=sum['HARDWARE']['CPU']
|
||||
if "CPU_ID" in sum['HARDWARE']:
|
||||
self.cpu_id=sum['HARDWARE']['CPU_ID']
|
||||
if "CPU_CORES_NUMBER" in sum['HARDWARE']:
|
||||
self.cpu_cores_number=sum['HARDWARE']['CPU_CORES_NUMBER']
|
||||
if "CPU_THREADS_NUMBER" in sum['HARDWARE']:
|
||||
self.cpu_threads_number=sum['HARDWARE']['CPU_THREADS_NUMBER']
|
||||
if "CPU_FREQUENCY_MIN" in sum['HARDWARE']:
|
||||
self.cpu_frequency_min=sum['HARDWARE']['CPU_FREQUENCY_MIN']
|
||||
if "CPU_FREQUENCY_CUR" in sum['HARDWARE']:
|
||||
self.cpu_frequency_cur=sum['HARDWARE']['CPU_FREQUENCY_CUR']
|
||||
if "CPU_FREQUENCY_MAX" in sum['HARDWARE']:
|
||||
self.cpu_frequency_max=sum['HARDWARE']['CPU_FREQUENCY_MAX']
|
||||
if "GPU_MODEL" in sum['HARDWARE']:
|
||||
self.gpu_model=sum['HARDWARE']['GPU_MODEL']
|
||||
if "RAM_SLOTS_NUMBER" in sum['HARDWARE']:
|
||||
self.ram_slots_number=sum['HARDWARE']['RAM_SLOTS_NUMBER']
|
||||
if "RAM_NUMBER" in sum['HARDWARE']:
|
||||
self.ram_number=sum['HARDWARE']['RAM_NUMBER']
|
||||
if "RAM_GEN" in sum['HARDWARE']:
|
||||
self.ram_gen=sum['HARDWARE']['RAM_GEN']
|
||||
return
|
||||
def fetch_summary(self):
|
||||
return
|
||||
def shutdown():
|
||||
return
|
||||
def status(self):
|
||||
return
|
||||
def link_to_user(self,user):
|
||||
return
|
||||
def remove_user_access(self):
|
||||
return
|
||||
def show_users(self):
|
||||
return
|
||||
@ -8,3 +8,16 @@ pydantic_core==2.41.5
|
||||
starlette==0.50.0
|
||||
typing-inspection==0.4.2
|
||||
typing_extensions==4.15.0
|
||||
annotated-doc==0.0.4
|
||||
annotated-types==0.7.0
|
||||
anyio==4.12.1
|
||||
click==8.3.1
|
||||
fastapi==0.128.0
|
||||
h11==0.16.0
|
||||
idna==3.11
|
||||
pydantic==2.12.5
|
||||
pydantic_core==2.41.5
|
||||
starlette==0.50.0
|
||||
typing-inspection==0.4.2
|
||||
typing_extensions==4.15.0
|
||||
uvicorn==0.40.0
|
||||
|
||||
Reference in New Issue
Block a user