Remove players deleted from Yodeck instead of showing them as offline

Poll loop now deletes DB rows for players no longer returned by the
Yodeck API, and Zabbix sync deletes the corresponding hosts from the
Yodeck Players group. Both actions are reflected in the activity log.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-19 18:02:03 +02:00
parent 31e7b93546
commit ecafc5a48a
3 changed files with 34 additions and 2 deletions

View File

@@ -117,6 +117,9 @@ class ZabbixClient:
def update_host_name(self, hostid, visible_name):
self._call('host.update', {'hostid': hostid, 'name': visible_name})
def delete_hosts(self, hostids):
self._call('host.delete', hostids)
# ------------------------------------------------------------------ templates
def get_template_id(self, name):
@@ -260,10 +263,23 @@ def sync_to_zabbix(players, add_log_fn):
log.warning("Skipped host %s: %s", hostname, exc)
skipped += 1
current_hostnames = {f"yodeck-{p['id']}" for p in players}
stale = [h for h in existing.values() if h['host'] not in current_hostnames]
deleted = 0
for h in stale:
try:
zbx.delete_hosts([h['hostid']])
deleted += 1
log.info("Deleted stale Zabbix host: %s", h['host'])
except Exception as exc:
log.warning("Could not delete host %s: %s", h['host'], exc)
skipped += 1
msg = (f"Zabbix sync complete: {created} created, {updated} updated"
+ (f", {deleted} deleted" if deleted else "")
+ (f", {skipped} skipped" if skipped else "")
+ f" ({len(players)} total)")
add_log_fn('zabbix_sync', msg, {'created': created, 'updated': updated, 'total': len(players)})
add_log_fn('zabbix_sync', msg, {'created': created, 'updated': updated, 'deleted': deleted, 'total': len(players)})
log.info(msg)
except Exception as exc: