39 lines
1023 B
Python
39 lines
1023 B
Python
"""CLI: python -m app.jobs.host_silence_scan"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
import sys
|
|
|
|
from app.database import SessionLocal
|
|
from app.services.host_silence_scan import dispatch_host_silence_notifications, run_host_silence_scan
|
|
|
|
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")
|
|
logger = logging.getLogger("sac.host_silence_scan")
|
|
|
|
|
|
def main() -> int:
|
|
db = SessionLocal()
|
|
try:
|
|
results = run_host_silence_scan(db)
|
|
notified = dispatch_host_silence_notifications(db, results)
|
|
db.commit()
|
|
created = sum(1 for r in results if r.created)
|
|
logger.info(
|
|
"host_silence scan done stale_hosts=%s created=%s notified=%s",
|
|
len(results),
|
|
created,
|
|
notified,
|
|
)
|
|
return 0
|
|
except Exception:
|
|
db.rollback()
|
|
logger.exception("host_silence scan failed")
|
|
return 1
|
|
finally:
|
|
db.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|