diff options
author | Victor Näslund <victor@sunet.se> | 2022-11-16 19:09:46 +0100 |
---|---|---|
committer | Victor Näslund <victor@sunet.se> | 2022-11-16 19:09:46 +0100 |
commit | 43e87d84b15d12d52a4dcde6e80426cbd17e3d6f (patch) | |
tree | 18cef29b77973053522a67677121789ebe032285 /src/soc_collector/healthcheck.py | |
parent | 4a56b3aae4114db731eff725e2c6292371a9b8ae (diff) |
auth and CLI done
Diffstat (limited to 'src/soc_collector/healthcheck.py')
-rw-r--r-- | src/soc_collector/healthcheck.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/soc_collector/healthcheck.py b/src/soc_collector/healthcheck.py new file mode 100644 index 0000000..e561fa0 --- /dev/null +++ b/src/soc_collector/healthcheck.py @@ -0,0 +1,38 @@ +""" +Send a healthcheck request +""" +import sys +import time +import json + +import requests + + +def check_collector() -> bool: + """Check our collector using /info + + :return: bool + """ + time.sleep(2) # Prevent race condition with redis container healthcheck + + req = requests.get( + "https://localhost:8000/info", + timeout=3, + verify="./collector_root_ca.crt", + ) + + if req.status_code != 200: + return False + + data = json.loads(req.text) + if isinstance(data["Estimated document count"], int) and data["Estimated document count"] >= 0: + return req.status_code == 200 + + return False + + +if __name__ == "__main__": + if sys.argv[1] == "COLLECTOR": + if check_collector(): + sys.exit(0) + sys.exit(1) |