fix: support list-valued threshold_config in hosts table
threshold_config in .hb.yaml can be a list (e.g. [local, zrepl]). The hosts table was treating it as a single string, so the pre-selected value never matched. Normalize to a list in settings.py, switch the select to multiple, and fix the JS to collect all selected options. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -284,7 +284,10 @@ def get_settings_sections(config: dict, threshold_checker=None) -> list:
|
|||||||
"owner": hcfg.get("owner", ""),
|
"owner": hcfg.get("owner", ""),
|
||||||
"managers": hcfg.get("managers", []),
|
"managers": hcfg.get("managers", []),
|
||||||
"monitors": hcfg.get("monitors", []),
|
"monitors": hcfg.get("monitors", []),
|
||||||
"threshold_config": hcfg.get("threshold_config", ""),
|
"threshold_configs": (
|
||||||
|
list(v) if isinstance(v := hcfg.get("threshold_config"), list)
|
||||||
|
else ([v] if v else [])
|
||||||
|
),
|
||||||
"notification_channels": hcfg.get("notification_channels", []),
|
"notification_channels": hcfg.get("notification_channels", []),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -591,10 +591,9 @@
|
|||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<select class="field-input host-tc">
|
<select class="field-input host-tc" multiple size="{{ [all_threshold_configs|length, 4]|min or 2 }}">
|
||||||
<option value="">— none —</option>
|
|
||||||
{% for tc in all_threshold_configs %}
|
{% for tc in all_threshold_configs %}
|
||||||
<option value="{{ tc | e }}" {% if h.threshold_config == tc %}selected{% endif %}>{{ tc | e }}</option>
|
<option value="{{ tc | e }}" {% if tc in h.threshold_configs %}selected{% endif %}>{{ tc | e }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
@@ -981,8 +980,8 @@
|
|||||||
if (managers.length) entry.managers = managers;
|
if (managers.length) entry.managers = managers;
|
||||||
const monitors = [...(row.querySelector('.host-monitors')?.selectedOptions || [])].map(o => o.value);
|
const monitors = [...(row.querySelector('.host-monitors')?.selectedOptions || [])].map(o => o.value);
|
||||||
if (monitors.length) entry.monitors = monitors;
|
if (monitors.length) entry.monitors = monitors;
|
||||||
const tc = row.querySelector('.host-tc').value;
|
const tcs = [...(row.querySelector('.host-tc')?.selectedOptions || [])].map(o => o.value);
|
||||||
if (tc) entry.threshold_config = tc;
|
if (tcs.length) entry.threshold_config = tcs;
|
||||||
const chs = [...(row.querySelector('.host-channels')?.selectedOptions || [])].map(o => o.value);
|
const chs = [...(row.querySelector('.host-channels')?.selectedOptions || [])].map(o => o.value);
|
||||||
if (chs.length) entry.notification_channels = chs;
|
if (chs.length) entry.notification_channels = chs;
|
||||||
return entry;
|
return entry;
|
||||||
@@ -1007,9 +1006,7 @@
|
|||||||
const tbody = document.getElementById('hosts-tbody');
|
const tbody = document.getElementById('hosts-tbody');
|
||||||
const sz = n => Math.min(Math.max(n, 1), 4);
|
const sz = n => Math.min(Math.max(n, 1), 4);
|
||||||
const usersOpts = _allUsers.map(u => `<option value="${escHtml(u)}">${escHtml(u)}</option>`).join('');
|
const usersOpts = _allUsers.map(u => `<option value="${escHtml(u)}">${escHtml(u)}</option>`).join('');
|
||||||
const tcOpts = ['<option value="">— none —</option>'].concat(
|
const tcOpts = _allThresholdConfigs.map(t => `<option value="${escHtml(t)}">${escHtml(t)}</option>`).join('');
|
||||||
_allThresholdConfigs.map(t => `<option value="${escHtml(t)}">${escHtml(t)}</option>`)
|
|
||||||
).join('');
|
|
||||||
const chOpts = _allChannels.map(c => `<option value="${escHtml(c)}">${escHtml(c)}</option>`).join('');
|
const chOpts = _allChannels.map(c => `<option value="${escHtml(c)}">${escHtml(c)}</option>`).join('');
|
||||||
const row = document.createElement('tr');
|
const row = document.createElement('tr');
|
||||||
row.setAttribute('data-new-host', 'true');
|
row.setAttribute('data-new-host', 'true');
|
||||||
@@ -1020,7 +1017,7 @@
|
|||||||
<td><input class="field-input host-owner" placeholder="(none)" style="min-width:90px"></td>
|
<td><input class="field-input host-owner" placeholder="(none)" style="min-width:90px"></td>
|
||||||
<td><select class="field-input host-managers" multiple size="${sz(_allUsers.length)}">${usersOpts}</select></td>
|
<td><select class="field-input host-managers" multiple size="${sz(_allUsers.length)}">${usersOpts}</select></td>
|
||||||
<td><select class="field-input host-monitors" multiple size="${sz(_allUsers.length)}">${usersOpts}</select></td>
|
<td><select class="field-input host-monitors" multiple size="${sz(_allUsers.length)}">${usersOpts}</select></td>
|
||||||
<td><select class="field-input host-tc" size="${sz(_allThresholdConfigs.length)}">${tcOpts}</select></td>
|
<td><select class="field-input host-tc" multiple size="${sz(_allThresholdConfigs.length)}">${tcOpts}</select></td>
|
||||||
<td><select class="field-input host-channels" multiple size="${sz(_allChannels.length)}">${chOpts}</select></td>
|
<td><select class="field-input host-channels" multiple size="${sz(_allChannels.length)}">${chOpts}</select></td>
|
||||||
<td><button class="btn-danger" onclick="this.closest('tr').remove()">✕</button></td>`;
|
<td><button class="btn-danger" onclick="this.closest('tr').remove()">✕</button></td>`;
|
||||||
tbody.appendChild(row);
|
tbody.appendChild(row);
|
||||||
|
|||||||
Reference in New Issue
Block a user