Skip to content
Snippets Groups Projects
Commit 21185294 authored by Jan Pavlíček's avatar Jan Pavlíček
Browse files

chore: merge branch 'python-probes' into 'main'

feat: check_exabgp_propagation, check_dockers, webserver_availability, check_syncrepl

See merge request perun-proxy-aai/python/perun-proxy-utils!29
parents b17d9029 5106f365
No related branches found
No related tags found
1 merge request!29feat: check_exabgp_propagation, check_dockers, webserver_availability, check_syncrepl
Pipeline #278608 failed
#!/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())
#!/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())
#!/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()
#!/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())
...@@ -15,5 +15,7 @@ setuptools.setup( ...@@ -15,5 +15,7 @@ setuptools.setup(
"beautifulsoup4~=4.12", "beautifulsoup4~=4.12",
"requests~=2.31", "requests~=2.31",
"ldap3~=2.9.1", "ldap3~=2.9.1",
"check_syncrepl_extended @ git+https://gitlab.ics.muni.cz/perun-proxy-aai/"
"python/check_syncrepl_extended.git@main",
], ],
) )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment