diff --git a/perun/proxy/utils/nagios/check_dockers.py b/perun/proxy/utils/nagios/check_dockers.py new file mode 100644 index 0000000000000000000000000000000000000000..e048e8f518dd8bd8c4f82495a10caf84b802110c --- /dev/null +++ b/perun/proxy/utils/nagios/check_dockers.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 + +import argparse + +import docker +from docker.errors import NotFound, APIError + + +def get_docker_states(req_containers): + client = docker.from_env() + containers = {} + for item in req_containers: + try: + container = client.containers.get(item) + containers[container.name] = container.status + except (NotFound, APIError): + containers[item] = "ERROR" + + return containers + + +def get_args(): + """ + Supports the command-line arguments listed below. + """ + parser = argparse.ArgumentParser(description="Check dockers") + parser.add_argument( + "-c", + "--containers", + required=True, + help='list of container names to check in following format: "[cont1, cont2]"', + ) + + return parser.parse_args() + + +def main(): + args = get_args() + containers_list = args.containers.replace(" ", "").strip("[]").split(",") + containers_status = get_docker_states(containers_list) + + status = 0 + status_info = "" + + for container_name in containers_status: + container_status = containers_status[container_name] + if container_status != "running": + status = 2 + status_info += container_name + ": " + container_status + "; " + + print(str(status) + " docker_containers - [" + status_info + "]") + return status + + +if __name__ == "__main__": + exit(main()) diff --git a/perun/proxy/utils/nagios/check_exabgp_propagation.py b/perun/proxy/utils/nagios/check_exabgp_propagation.py new file mode 100644 index 0000000000000000000000000000000000000000..36824e56430ae48bb2de5f73043bc7422ce814b4 --- /dev/null +++ b/perun/proxy/utils/nagios/check_exabgp_propagation.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +from subprocess import run + + +def main(): + result = run( + ["/usr/bin/docker", "exec", "exabgp", "exabgpcli", "show", "adj-rib", "out"], + text=True, + capture_output=True, + ) + exit_code = result.returncode + out = result.stdout + + status = 0 + status_txt = "OK" + + if exit_code != 0 or len(out) == 0: + status = 2 + status_txt = "CRITICAL" + + print(status_txt, end=" ") + + if len(out) != 0: + print("-", end=" ") + print(out) + return status + + +if __name__ == "__main__": + exit(main()) diff --git a/perun/proxy/utils/nagios/check_ldap_syncrepl.py b/perun/proxy/utils/nagios/check_ldap_syncrepl.py new file mode 100644 index 0000000000000000000000000000000000000000..8c4158ab05455a11e06a1289bc982be8edb764f7 --- /dev/null +++ b/perun/proxy/utils/nagios/check_ldap_syncrepl.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python3 + +from check_syncrepl_extended.check_syncrepl_extended import main + +# for program arguments check +# https://gitlab.ics.muni.cz/perun-proxy-aai/python/check_syncrepl_extended + +if __name__ == "__main__": + main() diff --git a/perun/proxy/utils/nagios/webserver_availability.py b/perun/proxy/utils/nagios/webserver_availability.py new file mode 100755 index 0000000000000000000000000000000000000000..cee20e3d2ed7c6c9236df62e3ad313e280d81cf3 --- /dev/null +++ b/perun/proxy/utils/nagios/webserver_availability.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +import argparse + +import requests + + +def get_args(): + """ + Supports the command-line arguments listed below. + """ + parser = argparse.ArgumentParser(description="Check webserver") + parser.add_argument( + "-u", + "--url", + required=True, + help="webserver url", + ) + parser.add_argument("-p", "--port", help="webserver port") + + return parser.parse_args() + + +def main(): + args = get_args() + url = args.url + + if args.port: + url += f":{args.port}" + + status = 2 + status_txt = "ERROR" + + try: + res = requests.get(url, allow_redirects=False) + if res.status_code == 200 or res.status_code == 301: + status = 0 + status_txt = "OK" + except requests.RequestException: + pass + + print(str(status) + " webserver_availability - " + status_txt) + return status + + +if __name__ == "__main__": + exit(main()) diff --git a/setup.py b/setup.py index d640cd68b100573a98b6524e4181bd0dc74c25d4..8dbd2e5990f426ba124a3d9e91416cb28aa10719 100644 --- a/setup.py +++ b/setup.py @@ -15,5 +15,7 @@ setuptools.setup( "beautifulsoup4~=4.12", "requests~=2.31", "ldap3~=2.9.1", + "check_syncrepl_extended @ git+https://gitlab.ics.muni.cz/perun-proxy-aai/" + "python/check_syncrepl_extended.git@main", ], )