sync for dev 033026

This commit is contained in:
2026-03-30 19:59:39 -07:00
parent ba849b150c
commit 36917ffa39
18 changed files with 317 additions and 84 deletions

View File

@ -21,7 +21,8 @@ app_settings = {
"REAL_API_KEY": ''.join(secrets.choice(string.ascii_letters + string.digits) for _ in range(256)),
"disable_local_api": False,
"local_api_address": "http://10.200.27.20:5000/",
"cosmostat_server_ip": "10.200.27.20"
"cosmostat_server_ip": "10.200.27.20",
"api_bind_ip": "192.168.37.1"
}
with open('cosmostat_settings.yaml', 'r') as f:
@ -71,10 +72,7 @@ def service_gateway_ip():
return result
def redis_gateway_ip():
if cosmostat_settings["secure_api"]:
return cosmostat_bind_ip()
else:
return "0.0.0.0"
return cosmostat_bind_ip()
def cosmostat_server_api():
return cosmostat_settings["cosmostat_server_api"]

View File

@ -170,11 +170,10 @@ def get_php_summary():
system_components.append(this_component)
if run_cosmostat_server():
print(cosmostat_client.name)
client_uuid = cosmostat_server.get_uuid_from_hostname(cosmostat_client.name)
print(client_uuid)
data_timestamp = cosmostat_server.get_system(client_uuid)
print(data_timestamp)
log_string = f"Cosmostat Client Name: {cosmostat_client.name} - UUID: {client_uuid}- Timestamp: {data_timestamp}"
log_data(log_output = log_string, log_level = "log_output")
component_age = {
"component_name": "Data Timestamp",
"info_strings": f"Data is {data_timestamp} seconds old"
@ -221,7 +220,10 @@ def create_client():
if not cosmostat_server.check_uuid(payload["uuid"]):
result = run_create_client(payload)
else:
result = {"message": "object already exists, skipping creation"}
result = {
"message": "object already exists, skipping creation",
"system_exists": "True"
}
return jsonify(result), 200
# api to validate Cosmostat Class
@ -280,6 +282,7 @@ def run_update_client(this_client):
return {
"status": update_status,
"client_updated": "True",
"uuid": this_client["uuid"],
"redis_data": this_client,
"timestamp_update": timestamp_update
@ -296,6 +299,7 @@ def run_create_client(this_client):
update_status = f'created client {this_client["short_id"]}'
return {
"status": update_status,
"client_created": "True",
"uuid": this_client["uuid"],
"client_properties": this_client,
"timestamp_update": timestamp_update
@ -372,13 +376,15 @@ def get_client_details():
# Cosmostat Client Reporter
def client_update():
api_url = f"{cosmostat_server_api()}update_client"
print(api_url)
payload = get_client_payload(get_client_redis_data(human_readable = False), "redis_data")
log_data(log_output = f"API Update Called - {api_url}", log_level = "debug_output")
log_data(log_output = "client_update - redis data from local client:", log_level = "noisy_test")
log_data(log_output = payload, log_level = "noisy_test")
# execute API call
result = client_submission_handler(api_url, payload)
client_api_initialize()
if not result or not result.get('client_updated'):
log_data(log_output = f"Client not updated, initializing", log_level = "log_output")
result = client_api_initialize()
return result
# Cosmostat Client Initializer
@ -434,6 +440,7 @@ if __name__ == '__main__':
######################################
### Main Functions
######################################
log_data(log_output = f"Main Function Start", log_level = "log_output")
# instantiate and return the Client System object
def new_cosmos_client():
@ -480,9 +487,13 @@ if __name__ == '__main__':
######################################
# local client System Class Object
log_data(log_output = f"Cosmostat Client Start", log_level = "log_output")
cosmostat_client = new_cosmos_client()
cosmostat_client.update_system_state()
# remote client reporter
if app_settings["cosmostat_server_reporter"] and not app_settings["cosmostat_server"]:
log_data(log_output = f"Initialize Client Reporter", log_level = "log_output")
client_api_initialize()
######################################
@ -491,15 +502,19 @@ if __name__ == '__main__':
cosmostat_server = None
if run_cosmostat_server():
log_data(log_output = f"Cosmostat Server Start", log_level = "log_output")
cosmostat_server = new_cosmostat_server()
this_client = get_client_payload(get_php_summary(), "client_properties")
timestamp_update = cosmostat_server.add_system(system_dictionary = this_client)
# moving this here so all the bits exist
client_update()
######################################
# send initial stats update to redis
######################################
if app_settings["push_redis"] and not app_settings["disable_local_api"]:
log_data(log_output = f"Initial Redis Push", log_level = "log_output")
update_redis_server()
######################################
@ -507,6 +522,7 @@ if __name__ == '__main__':
######################################
if app_settings["run_background"] and not app_settings["disable_local_api"]:
log_data(log_output = f"Background Function Initializing", log_level = "log_output")
log_data(log_output = "Loading flask background subroutine...", log_level = "log_output")
scheduler.add_job(id='background_loop',
@ -523,16 +539,18 @@ if __name__ == '__main__':
######################################
# Flask API
######################################
print(f"gateway: {service_gateway_ip()} - port: {service_api_port()}")
log_data(log_output = f"gateway: {service_gateway_ip()} - port: {service_api_port()}", log_level = "log_output")
if not app_settings["disable_local_api"]:
log_data(log_output = f"Main API Start", log_level = "log_output")
app.run(debug=False, host=service_gateway_ip(), port=service_api_port())
else:
# if local API disabled, phone home if configured
print("Internal API Disabled.")
log_data(log_output = f"Internal API Disabled", log_level = "log_output")
cosmostat_client.update_system_state()
client_update()
while True:
if int(time.time()) % 5 == 0 and not cosmostat_client.check_system_timer():
cosmostat_client.update_system_state()
client_update()
time.sleep(0.5)
cosmostat_client.update_system_state()
client_update()
time.sleep(5)

View File

@ -91,7 +91,8 @@
"Clock Speed"
],
"php_extra" :[
"CPU Model"
"CPU Model",
"Core Count"
]
},
{
@ -236,12 +237,13 @@
"name": "DVD",
"description": "{Device Path} is a DVD or Virtual DVD drive.",
"multi_check": "True",
"device_list": "lsblk -d -o NAME,SIZE | grep sr0| awk '{print $1}'",
"device_list": "lsblk -d -o NAME,SIZE | grep sr0 | awk '{print $1}'",
"properties": {
"Device Name": "echo {this_device}",
"Device Path": "lsblk -d -o NAME,SIZE | grep -v -e 0B -e NAME | awk '{{print \"/dev/\"$1}}' | grep {this_device}",
"Total Capacity": "lsblk -d -o NAME,SIZE | grep {this_device} | awk '{{print $2}}'"
},
"precheck": "lspci | grep sr0 | wc -l",
"metrics": {
"placeholder": ""
}