From bafcf422b9ca096a8569b8c653d7950a9d242e01 Mon Sep 17 00:00:00 2001 From: Cyberes Date: Fri, 21 Apr 2023 23:54:17 -0600 Subject: [PATCH] check_federation_tester, make stuff executable --- check_federation.py | 0 check_federation_tester.py | 50 ++++++++++++++++++++++++++++++++++ check_matrix_synapse.py | 0 check_media_cdn.py | 0 check_monitor_bot.py | 0 check_monitor_bot.sh | 4 --- check_pve/check_pve.py | 0 check_redis.py | 0 icinga2kuma.py | 0 matrix-host-notification.py | 0 matrix-service-notification.py | 0 test-federation.sh | 9 ------ test-media-cdn.sh | 8 ------ 13 files changed, 50 insertions(+), 21 deletions(-) mode change 100644 => 100755 check_federation.py create mode 100755 check_federation_tester.py mode change 100644 => 100755 check_matrix_synapse.py mode change 100644 => 100755 check_media_cdn.py mode change 100644 => 100755 check_monitor_bot.py delete mode 100644 check_monitor_bot.sh mode change 100644 => 100755 check_pve/check_pve.py mode change 100644 => 100755 check_redis.py mode change 100644 => 100755 icinga2kuma.py mode change 100644 => 100755 matrix-host-notification.py mode change 100644 => 100755 matrix-service-notification.py delete mode 100644 test-federation.sh delete mode 100644 test-media-cdn.sh diff --git a/check_federation.py b/check_federation.py old mode 100644 new mode 100755 diff --git a/check_federation_tester.py b/check_federation_tester.py new file mode 100755 index 0000000..fbf65ae --- /dev/null +++ b/check_federation_tester.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 +import argparse +import sys +import traceback + +import requests + +import checker.nagios as nagios + +parser = argparse.ArgumentParser(description='Test federation between two homeservers.') +parser.add_argument('--endpoint', required=True, help='Endpoint to parse. See fed.mau.dev or federationtester.matrix.org') +parser.add_argument('--timeout', type=float, default=90, help='Request timeout limit.') +parser.add_argument('--warn', type=float, default=2.0, help='Manually set warn level.') +parser.add_argument('--crit', type=float, default=2.5, help='Manually set critical level.') +args = parser.parse_args() + + +def main() -> None: + r = requests.get(args.endpoint, timeout=args.timeout) + if not r.status_code: + print(f'UNKNOWN: tester endpoint failed with status code {r.status_code}\n', r.text) + sys.exit(nagios.UNKNOWN) + + r_json = r.json() + if r_json.get('FederationOK'): + print('OK: federation tester reported success.') + print(f"Version: {r_json.get('Version', {}).get('name')}/{r_json.get('Version', {}).get('version')}") + print('WellKnown:', r_json.get('WellKnownResult', {}).get('m.server')) + nagios_output = nagios.OK + else: + print('CRITICAL: federation tester reported failure.') + print('Server Version:', r_json.get('m.server')) + print('WellKnown:', r_json.get('WellKnownResult', {}).get('m.server')) + print('WellKnown Result:', r_json.get('WellKnownResult', {}).get('result')) + print('DNS Result:', r_json.get('DNSResult', {}).get('SRVError', {}).get('Message', {})) + print('Version:', r_json.get('Version', {}).get('error')) + print('Connection Report:', r_json.get('ConnectionReports')) + print('Connection Errors:', r_json.get('ConnectionErrors')) + nagios_output = nagios.CRITICAL + + sys.exit(nagios_output) + + +if __name__ == "__main__": + try: + main() + except Exception as e: + print(f"UNKNOWN: exception\n{e}") + print(traceback.format_exc()) + sys.exit(nagios.UNKNOWN) diff --git a/check_matrix_synapse.py b/check_matrix_synapse.py old mode 100644 new mode 100755 diff --git a/check_media_cdn.py b/check_media_cdn.py old mode 100644 new mode 100755 diff --git a/check_monitor_bot.py b/check_monitor_bot.py old mode 100644 new mode 100755 diff --git a/check_monitor_bot.sh b/check_monitor_bot.sh deleted file mode 100644 index 7c74037..0000000 --- a/check_monitor_bot.sh +++ /dev/null @@ -1,4 +0,0 @@ -python3 Matrix\ Synapse/check_monitor_bot.py \ - --metrics-endpoint "https://matrix.your-hs.com/matrix-monitor-bot/" \ - --domain your-hs.com \ - --ignore canarymod.net catgirl.cloud diff --git a/check_pve/check_pve.py b/check_pve/check_pve.py old mode 100644 new mode 100755 diff --git a/check_redis.py b/check_redis.py old mode 100644 new mode 100755 diff --git a/icinga2kuma.py b/icinga2kuma.py old mode 100644 new mode 100755 diff --git a/matrix-host-notification.py b/matrix-host-notification.py old mode 100644 new mode 100755 diff --git a/matrix-service-notification.py b/matrix-service-notification.py old mode 100644 new mode 100755 diff --git a/test-federation.sh b/test-federation.sh deleted file mode 100644 index 8a5138c..0000000 --- a/test-federation.sh +++ /dev/null @@ -1,9 +0,0 @@ -python3 Matrix\ Synapse/check_federation.py \ - --bot1-user '@bot1:your-hs.com' \ - --bot1-pw password1234 \ - --bot1-hs https://matrix.your-hs.com \ - --bot1-auth-file /opt/custom-nagios-checks/auth-fed-test-bot1.json \ - --bot2-user '@bot2:matrix.org' \ - --bot2-pw password1234 \ - --bot2-hs https://matrix-federation.matrix.org \ - --bot2-auth-file /opt/custom-nagios-checks/auth-fed-test-bot2.json diff --git a/test-media-cdn.sh b/test-media-cdn.sh deleted file mode 100644 index 2c7b901..0000000 --- a/test-media-cdn.sh +++ /dev/null @@ -1,8 +0,0 @@ -python3 Matrix\ Synapse/check_media_cdn.py \ - --user '@bot1:your-hs.com' \ - --pw password1234 \ - --hs https://matrix.your-hs.com \ - --room '!banana:your-hs.com' \ - --auth-file ./auth-cdn.json \ - --media-cdn-domain matrix-media-cdn.your-hs.com \ - --admin-endpoint https://172.0.2.118