From 814c5a5b60e08a1a9cec81137bda96c835e4867c Mon Sep 17 00:00:00 2001 From: Claudio Cirelli Date: Tue, 20 Oct 2026 09:37:38 +0200 Subject: [PATCH] easy script to check if all channels are online --- check.py | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 check.py diff --git a/check.py b/check.py new file mode 100755 index 0000000..4e92efc --- /dev/null +++ b/check.py @@ -0,0 +1,71 @@ + +#!/usr/bin/env python3 + +import subprocess +import sys +import yaml + + +def check_channels(filename): + with open(filename, "r") as f: + config = yaml.safe_load(f) + + # Only read actual channel definitions + channels = config["channels"] + + online = 0 + offline = 0 + timeouts = 0 + + print(f"\nChecking {len(channels)} channels...\n") + + for alias, channel in channels.items(): + try: + result = subprocess.run( + ["bs", "avail", channel], + capture_output=True, + text=True, + timeout=15 + ) + + is_online = channel in [ + line.strip() for line in result.stdout.splitlines() + ] + + status = "ONLINE" if is_online else "OFFLINE" + + except subprocess.TimeoutExpired: + status = "TIMEOUT" + is_online = False + + except OSError: + status = "ERROR" + + if status == "ONLINE": + online += 1 + symbol = "✓" + elif status == "OFFLINE": + offline +=1 + symbol = "✗" + elif status == "TIMEOUT": + timeouts +=1 + symbol = "!" + else: + offline +=1 + symbol = "?" + + print (f"{symbol} {alias:<18} {status:<8} {channel}") + + print(f"\nSummary: {online} online, {offline} offline") + + return offline == 0 and timeouts==0 + + +if __name__ == "__main__": + if len(sys.argv) != 2: + print("Usage: check ") + sys.exit(1) + + success = check_channels(sys.argv[1]) + sys.exit(0 if success else 1) +