- Yodeck API poller (every 10 min, paginated, 310 players) - SQLite persistence (players + activity logs) - SNMP v2c agent via net-snmp pass_persist - Zabbix API auto host creation/update (6.0+) - Flask web dashboard with live player status and log - Docker deployment with persistent volume - dev_server.py for local testing without Docker Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
import logging
|
|
from apscheduler.schedulers.background import BackgroundScheduler
|
|
from app import database as db
|
|
from app import yodeck as yd
|
|
from app.zabbix import sync_to_zabbix
|
|
from app.config import YODECK_POLL_INTERVAL_MINUTES
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
def poll_yodeck():
|
|
log.info("Polling Yodeck API …")
|
|
try:
|
|
players = yd.get_all_screens()
|
|
for p in players:
|
|
db.upsert_player(p)
|
|
msg = f"Fetched {len(players)} players from Yodeck API"
|
|
db.add_log('yodeck_fetch', msg, {'count': len(players)})
|
|
log.info(msg)
|
|
# Sync host list to Zabbix after a successful fetch
|
|
sync_to_zabbix(players, db.add_log)
|
|
except Exception as exc:
|
|
msg = f"Yodeck poll failed: {exc}"
|
|
db.add_log('error', msg)
|
|
log.error(msg)
|
|
|
|
|
|
def start_scheduler():
|
|
scheduler = BackgroundScheduler(daemon=True)
|
|
scheduler.add_job(
|
|
poll_yodeck,
|
|
'interval',
|
|
minutes=YODECK_POLL_INTERVAL_MINUTES,
|
|
id='yodeck_poll',
|
|
)
|
|
scheduler.start()
|
|
log.info("Scheduler started — Yodeck poll every %d minutes", YODECK_POLL_INTERVAL_MINUTES)
|
|
# Run an initial poll immediately so the DB is populated at startup
|
|
poll_yodeck()
|
|
return scheduler
|