DOCS+FE+BE: cleaner versioning retrieval, ICMP, plugin debug docs

Signed-off-by: jokob-sk <jokob.sk@gmail.com>
This commit is contained in:
jokob-sk
2026-01-28 21:56:20 +11:00
parent e46f556df7
commit ecd0ca89c7
10 changed files with 80 additions and 47 deletions

View File

@@ -13,7 +13,7 @@ INSTALL_PATH = os.getenv("NETALERTX_APP", "/app")
sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"])
from logger import mylog # noqa: E402 [flake8 lint suppression]
from helper import get_setting_value, get_env_setting_value # noqa: E402 [flake8 lint suppression]
from helper import get_setting_value, get_env_setting_value, getBuildTimeStampAndVersion # noqa: E402 [flake8 lint suppression]
from db.db_helper import get_date_from_period # noqa: E402 [flake8 lint suppression]
from app_state import updateState # noqa: E402 [flake8 lint suppression]
@@ -1809,6 +1809,9 @@ def start_server(graphql_port, app_state):
)
thread.start()
# Pass Application "VERSION" into the app_state
buildTimestamp, newBuildVersion = getBuildTimeStampAndVersion()
# Update the state to indicate the server has started
app_state = updateState("Process: Idle", None, None, None, 1)

View File

@@ -42,7 +42,8 @@ class app_state_class:
graphQLServerStarted=0,
processScan=False,
pluginsStates=None,
appVersion=None
appVersion=None,
buildTimestamp=None
):
"""
Initialize the application state, optionally overwriting previous values.
@@ -59,6 +60,7 @@ class app_state_class:
processScan (bool, optional): Initial processScan flag.
pluginsStates (dict, optional): Initial plugin states to merge with previous state.
appVersion (str, optional): Application version.
buildTimestamp (str, optional): ABuild timestamp.
"""
# json file containing the state to communicate with the frontend
stateFile = apiPath + "app_state.json"
@@ -86,6 +88,7 @@ class app_state_class:
self.currentState = previousState.get("currentState", "Init")
self.pluginsStates = previousState.get("pluginsStates", {})
self.appVersion = previousState.get("appVersion", "")
self.buildTimestamp = previousState.get("buildTimestamp", "")
else: # init first time values
self.settingsSaved = 0
self.settingsImported = 0
@@ -97,6 +100,7 @@ class app_state_class:
self.currentState = "Init"
self.pluginsStates = {}
self.appVersion = ""
self.buildTimestamp = ""
# Overwrite with provided parameters if supplied
if settingsSaved is not None:
@@ -127,6 +131,8 @@ class app_state_class:
self.pluginsStates[plugin] = state
if appVersion is not None:
self.appVersion = appVersion
if buildTimestamp is not None:
self.buildTimestamp = buildTimestamp
# check for new version every hour and if currently not running new version
if self.isNewVersion is False and self.isNewVersionChecked + 3600 < int(
timeNow().timestamp()
@@ -154,7 +160,13 @@ class app_state_class:
# Broadcast state change via SSE if available
try:
broadcast_state_update(self.currentState, self.settingsImported, timestamp=self.lastUpdated)
broadcast_state_update(
self.currentState,
self.settingsImported,
timestamp=self.lastUpdated,
appVersion=self.appVersion,
buildTimestamp=self.buildTimestamp
)
except Exception as e:
mylog("none", [f"[app_state] SSE broadcast: {e}"])
@@ -170,7 +182,8 @@ def updateState(newState = None,
graphQLServerStarted = None,
processScan = None,
pluginsStates=None,
appVersion=None):
appVersion=None,
buildTimestamp=None):
"""
Convenience method to create or update the app state.
@@ -183,6 +196,7 @@ def updateState(newState = None,
processScan (bool, optional): Flag indicating if a scan is active.
pluginsStates (dict, optional): Plugin state updates.
appVersion (str, optional): Application version.
buildTimestamp (str, optional): Build timestamp.
Returns:
app_state_class: Updated state object.
@@ -195,7 +209,8 @@ def updateState(newState = None,
graphQLServerStarted,
processScan,
pluginsStates,
appVersion
appVersion,
buildTimestamp
)

View File

@@ -715,7 +715,7 @@ def importConfigs(pm, db, all_plugins):
# settingsImported = None (timestamp),
# showSpinner = False (1/0),
# graphQLServerStarted = 1 (1/0))
updateState("Config imported", conf.lastImportedConfFile, conf.lastImportedConfFile, False, 1, None, None, new_version)
updateState("Config imported", conf.lastImportedConfFile, conf.lastImportedConfFile, False, 1, None, None, new_version, buildTimestamp)
msg = '[Config] Imported new settings config'
mylog('minimal', msg)