57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Read-only health smoke for Tier0/1 service cards."""
|
|
import socket
|
|
import unittest
|
|
import urllib.error
|
|
import urllib.request
|
|
from pathlib import Path
|
|
|
|
CHECKS = {
|
|
"audit": "http://127.0.0.1:9160/health",
|
|
"gitea": "http://192.168.1.140:3000/api/v1/version",
|
|
"authentik": "http://192.168.1.114:9000/-/health/live/",
|
|
"matrix": "http://192.168.1.155:8008/_matrix/client/versions",
|
|
"prism": "http://127.0.0.1:8095/api/health",
|
|
"seerr": "http://192.168.1.121:5055/api/v1/status",
|
|
"hub-core": "http://127.0.0.1:9120/status",
|
|
"n8n": "http://192.168.1.108:5680/healthz",
|
|
}
|
|
|
|
|
|
def http_ok(url):
|
|
try:
|
|
with urllib.request.urlopen(url, timeout=6) as r:
|
|
return 200 <= r.status < 400
|
|
except Exception:
|
|
return False
|
|
|
|
|
|
class ServiceHealth(unittest.TestCase):
|
|
def test_http_cards(self):
|
|
failures = {name: url for name, url in CHECKS.items() if not http_ok(url)}
|
|
self.assertEqual(failures, {})
|
|
|
|
def test_jellyfin_auth(self):
|
|
key = Path("/root/.jellyfin-key").read_text().strip()
|
|
req = urllib.request.Request(
|
|
"http://192.168.1.103:8096/System/Info",
|
|
headers={"Authorization": 'MediaBrowser Token="%s"' % key})
|
|
with urllib.request.urlopen(req, timeout=6) as r:
|
|
self.assertEqual(r.status, 200)
|
|
|
|
def test_postgres_tcp(self):
|
|
s = socket.socket()
|
|
s.settimeout(3)
|
|
s.connect(("192.168.1.151", 5432))
|
|
s.close()
|
|
|
|
def test_nats_tcp(self):
|
|
s = socket.socket()
|
|
s.settimeout(3)
|
|
s.connect(("192.168.1.115", 4222))
|
|
s.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main(verbosity=2)
|