diff --git a/README.md b/README.md index 2cb552107f7237fdecc80895adb5aab9ac07fdb5..a935391d3cd1410fe37fd7f3cde6ee17e75ab32e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,14 @@ -# ProxyIdP scripts +# Perun proxy utils ## Scripts +### run_probes.py + +- script designed to execute multiple monitoring probes +- output is compatible with CheckMK +- it is required to put configuration file to `/etc/run_probes_cfg.yaml` +- for usage run: `./run_probes.py` or `python3 -m perun.proxy.utils.run_probes` + ### separate_ssp_script.py - Script for remove all logs from test accounts from SimpleSAMLlogs diff --git a/config_templates/run_probes_cfg.yaml b/config_templates/run_probes_cfg.yaml new file mode 100644 index 0000000000000000000000000000000000000000..8b5c81ee02ecfdceeb54d1cd54b6b2d6c0fd0b42 --- /dev/null +++ b/config_templates/run_probes_cfg.yaml @@ -0,0 +1,41 @@ +check_mongodb: + # module with checks + module: perun.proxy.utils.nagios.check_mongodb + check_mongodb_shared: &check_mongodb_shared + host: "hostname" + u: "username" + p: "password" + tls: true + tls-ca-file: "/etc/ssl/chain.crt" + tls-cert-key-file: "/etc/ssl/certificate_and_key.pem" + runs: + # check with parameter + check_mongodb_connect: + <<: *check_mongodb_shared + A: connect + W: 2 + C: 4 + check_mongodb_connections: + <<: *check_mongodb_shared + A: connections + W: 70 + C: 80 + check_mongodb_replication_lag: + <<: *check_mongodb_shared + A: replication_lag + W: 15 + C: 30 + check_mongodb_replset_state: + <<: *check_mongodb_shared + A: replset_state + W: 0 + C: 0 + +check_rpc_status: + module: perun.proxy.utils.nagios.check_rpc_status + runs: + check_rpc_status: + u: "username" + p: "password" + d: "domain" + i: 1 diff --git a/perun/proxy/utils/run_probes.py b/perun/proxy/utils/run_probes.py new file mode 100644 index 0000000000000000000000000000000000000000..3599e9bfba1133575c4affc544acdebc6ffbac42 --- /dev/null +++ b/perun/proxy/utils/run_probes.py @@ -0,0 +1,57 @@ +#!/usr/bin/python3 +import re +import subprocess +import sys +from threading import Thread + +import yaml + + +def open_file(filepath): + try: + with open(filepath) as f: + return f.read() + except OSError as e: + print( + f"Cannot open config with path: {filepath}, error: {e.strerror}", + file=sys.stderr, + ) + exit(2) + + +def run_probe(probe_name, command): + result = subprocess.run(command, text=True, capture_output=True) + search = re.search(r" - .*", result.stdout) + if search: + print(f"{result.returncode} {probe_name} {search.group()}") + else: + print(f"{result.returncode} {probe_name} - {result.stdout}") + return result.returncode + + +def main(config_filepath): + config = yaml.safe_load(open_file(config_filepath)) + if not config: + return + + for _, options in config.items(): + module = options["module"] + for name, args in options.get("runs").items(): + command = ["python", "-m", module] + for arg_name, arg_val in args.items(): + if len(arg_name) == 1: + arg_name = "-" + arg_name + else: + arg_name = "--" + arg_name + if arg_val is True: + arg_val = "true" + elif arg_val is False: + arg_val = "false" + command.append(arg_name) + command.append(str(arg_val)) + Thread(target=run_probe, args=[name, command]).start() + + +if __name__ == "__main__": + config_filepath = "/etc/run_probes_cfg.yaml" + main(config_filepath) diff --git a/setup.py b/setup.py index cfb2f03303ef85098b2b4b1b623143e1f6071b9d..9109acc4f31028dd53e965d9d9bcbf2f475de7fb 100644 --- a/setup.py +++ b/setup.py @@ -15,6 +15,7 @@ setuptools.setup( "beautifulsoup4~=4.12", "requests~=2.31", "ldap3~=2.9.1", + "PyYAML~=6.0", "check_syncrepl_extended @ git+https://gitlab.ics.muni.cz/perun-proxy-aai/" "python/check_syncrepl_extended.git@main", "check_nginx_status @ git+https://gitlab.ics.muni.cz/perun-proxy-aai/"