cosmostat python comment enrichment

This commit is contained in:
2026-03-29 10:38:07 -07:00
parent 9646ee92fd
commit 6453a839a9
14 changed files with 95 additions and 791 deletions

View File

@ -1,16 +1,21 @@
#######################################################################
### app.py
### cosmostat service handler
#######################################################################
from flask import Flask, jsonify, request, Response
from flask_apscheduler import APScheduler
from typing import Dict, Union
import json, time, redis, yaml
import base64, hashlib
import secrets, string
import requests
from requests import RequestException, Response
from Components import *
# Import Cosmos Settings
from Cosmos_Settings import *
# System and Component Classes
from Components import *
# Cosmostat server Classes
from Cosmostat import *
# declare flask apps
@ -373,11 +378,11 @@ def client_update():
log_data(log_output = payload, log_level = "noisy_test")
# execute API call
result = client_submission_handler(api_url, payload)
client_initialize()
client_api_initialize()
return result
# Cosmostat Client Initializer
def client_initialize():
def client_api_initialize():
api_url = f"{cosmostat_server_api()}create_client"
# generate payload
payload = get_client_payload(get_php_summary(), "client_properties")
@ -446,34 +451,39 @@ if __name__ == '__main__':
# Background Loop Function
def background_loop():
# Update all data on the System object unless this is the server
if cosmostat_client.check_system_timer() and not run_cosmostat_server():
# Update all data on the local System object
if cosmostat_client.check_system_timer() or run_cosmostat_server():
cosmostat_client.update_system_state()
# publish to redis if the web dashboard is active locally
if app_settings["push_redis"] and not app_settings["disable_local_api"]:
update_redis_server()
# report data to the server if configured
if run_cosmostat_reporter():
if int(time.time()) % 5 == 0 and not cosmostat_client.check_system_timer():
cosmostat_client.update_system_state()
client_update()
# if this is the server, do this stuff
if run_cosmostat_server():
# update the client state since that was skipped
cosmostat_client.update_system_state()
this_client = get_client_payload(get_client_redis_data(human_readable = False), "redis_data")
if app_settings["noisy_test"]:
print(this_client)
run_update_client(this_client)
# purge stale client systems
cosmostat_server.purge_stale_hostnames()
# report the server's own client object to itself
run_update_client(get_client_payload(get_client_redis_data(human_readable = False), "redis_data"))
log_data(log_output = f"{this_client}", log_level = "noisy_test")
time.sleep(0.5)
######################################
# instantiate client
# instantiate client
######################################
# local client System Class Object
cosmostat_client = new_cosmos_client()
# remote client reporter
if app_settings["cosmostat_server_reporter"] and not app_settings["cosmostat_server"]:
client_initialize()
client_api_initialize()
######################################
# instantiate server
@ -517,6 +527,7 @@ if __name__ == '__main__':
if not app_settings["disable_local_api"]:
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.")
while True:
if int(time.time()) % 5 == 0 and not cosmostat_client.check_system_timer():