diff options
author | Victor Näslund <victor@sunet.se> | 2022-11-16 23:43:43 +0100 |
---|---|---|
committer | Victor Näslund <victor@sunet.se> | 2022-11-16 23:43:43 +0100 |
commit | ec715926bb827478f0433e716977af9b0ea835bc (patch) | |
tree | 889291b51f8538700e90855f57bed225d2f68d4c /data/healthcheck.py | |
parent | 45eb98199215ac26e04c02091485b02470e2e46e (diff) |
fixed healthcheck path
Diffstat (limited to 'data/healthcheck.py')
-rw-r--r-- | data/healthcheck.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/data/healthcheck.py b/data/healthcheck.py new file mode 100644 index 0000000..1ccd8f3 --- /dev/null +++ b/data/healthcheck.py @@ -0,0 +1,40 @@ +""" +Send a healthcheck request +""" +import sys +import time +import json + +import requests + +from src.soc_collector.auth import load_api_keys + +def check_collector() -> bool: + """Check our collector using /info + + :return: bool + """ + time.sleep(2) # Prevent race condition with mongodb container healthcheck + + req = requests.get( + "https://localhost:8000/info", + headers={"API-KEY": load_api_keys("./api_keys.txt")[-1]}, + 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) |