add refresh_api to jenkinsfile

This commit is contained in:
2026-04-18 16:14:22 -07:00
parent 280066436a
commit 67f3f8440b
12 changed files with 161 additions and 63 deletions

View File

@ -1,8 +1,12 @@
from flask import Flask, jsonify
from flask_apscheduler import APScheduler
import psutil
import os
import requests, json
from subprocess import check_output
app = Flask(__name__)
scheduler = APScheduler()
app.config['JSONIFY_PRETTYPRINT_REGULAR'] = True
# Bits to Bytes etc
@ -38,7 +42,8 @@ def get_crystal_disk_info():
"Power On Count": None,
"Host Writes": None,
"Wear Level Count": None,
"Drive Letter": None
"Drive Letter": None,
"Interface": None
}
for line in lines:
if "Model" in line:
@ -74,6 +79,9 @@ def get_crystal_disk_info():
elif "Disk Size" in line:
if ":" in line:
data["Disk Size"] = line.split(":", 1)[1].strip()
elif "Interface" in line:
if ":" in line:
data["Disk Size"] = line.split(":", 1)[1].strip()
if any(value is not None for value in data.values()):
drives.append(data)
@ -113,5 +121,36 @@ def disk():
def drive_health():
return jsonify(get_crystal_disk_info())
def server_reporter():
base_url="http://172.25.1.18:5001/client_update"
url = f"{base_url}/process"
data_dict = get_crystal_disk_info()
response = requests.post(url, json=data_dict)
# Raise an exception for non2xx status codes
response.raise_for_status()
# Return the JSON payload
return response.json()
if __name__ == '__main__':
# Background Loop Function
# That makes this the service loop
def background_loop():
diskinfo_command = f"{{ storage_api_root }}\\dist\\DiskInfo64.exe /CopyExit"
result = check_output(diskinfo_command, shell=True)
print(result)
server_reporter()
return result
scheduler.add_job(id='background_loop',
func=background_loop,
trigger='interval',
seconds=60)
scheduler.init_app(app)
scheduler.start()
background_loop()
app.run(host='0.0.0.0', port={{ api_service_port }})