feat: threshold form payload carries per-config owner
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NfPpSpccTWBfZg1FTveyaU
This commit is contained in:
+11
-5
@@ -28,19 +28,25 @@ eventlog = notify_mod.eventlog
|
||||
|
||||
|
||||
def _build_threshold_configs_from_form(form_data: dict) -> dict:
|
||||
"""Convert form-submitted flat threshold data to nested threshold_configs YAML structure.
|
||||
"""Convert form-submitted threshold data to the nested threshold_configs structure.
|
||||
|
||||
Input: {config_name: {metric_path: {warning, critical, operator, hysteresis, enabled, count, display}}}
|
||||
Output: {config_name: {thresholds: {plugin: {metric: {warning, critical, ...}}}}}
|
||||
Input: {config_name: {owner?: str, metrics: {metric_path: {warning, critical, ...}}}}
|
||||
Output: {config_name: {owner?: str, thresholds: {plugin: {metric: {...}}}}}
|
||||
"""
|
||||
result = {}
|
||||
for config_name, metrics in form_data.items():
|
||||
for config_name, cfg in form_data.items():
|
||||
if not isinstance(cfg, dict):
|
||||
continue
|
||||
metrics = cfg.get("metrics")
|
||||
if not isinstance(metrics, dict):
|
||||
continue
|
||||
thresholds = {}
|
||||
for metric_path, values in metrics.items():
|
||||
_insert_threshold_metric(thresholds, metric_path, values)
|
||||
result[config_name] = {"thresholds": thresholds}
|
||||
entry = {"thresholds": thresholds}
|
||||
if cfg.get("owner"):
|
||||
entry["owner"] = cfg["owner"]
|
||||
result[config_name] = entry
|
||||
return result
|
||||
|
||||
|
||||
|
||||
@@ -1556,10 +1556,15 @@
|
||||
|
||||
const cfgsContainer = document.getElementById('thresh-cfgs-' + sectionId);
|
||||
cfgsContainer.querySelectorAll('.thresh-cfg-card').forEach(card => {
|
||||
if (card.dataset.readonly === 'true') return;
|
||||
const configName = card.dataset.configName
|
||||
|| (card.querySelector('.new-config-name')?.value || '').trim();
|
||||
if (!configName) return;
|
||||
configs[configName] = readMetrics(card);
|
||||
const ownerInp = card.querySelector('.thresh-owner');
|
||||
configs[configName] = {
|
||||
owner: ownerInp ? ownerInp.value.trim() : '',
|
||||
metrics: readMetrics(card),
|
||||
};
|
||||
});
|
||||
|
||||
_staged['thresholds'] = configs;
|
||||
|
||||
Reference in New Issue
Block a user