diff --git a/perun/proxy/config_templates/run_probes_cfg.yaml b/perun/proxy/config_templates/run_probes_cfg.yaml new file mode 100644 index 0000000000000000000000000000000000000000..76a48e0387570694fabbe746c13c75a29f26b396 --- /dev/null +++ b/perun/proxy/config_templates/run_probes_cfg.yaml @@ -0,0 +1,16 @@ + +check_mongodb: + path: nagios/check_mongodb.py + runs: + - host: hostname + u: mongoadmin + p: password + A: connect + W: 2 + C: 4 + - host: hostname + u: mongoadmin + p: password + A: connections + W: 70 + C: 80 diff --git a/perun/proxy/utils/run_probes.py b/perun/proxy/utils/run_probes.py new file mode 100644 index 0000000000000000000000000000000000000000..6d4dbbe0bf5d38e9062a3660003e25bb3529a3fe --- /dev/null +++ b/perun/proxy/utils/run_probes.py @@ -0,0 +1,49 @@ +import argparse +import os +import sys +from threading import Thread + +import yaml + + +def parse_args(): + parser = argparse.ArgumentParser( + prog="MonitoringProbes", description="runs monitoring probes defined in config" + ) + parser.add_argument("-c", "--config", required=True, help="Filepath to config") + args = parser.parse_args() + return args.config + + +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(command): + os.system(command) + + +def main(): + config = yaml.safe_load(open_file(parse_args())) + if not config: + return + + for name, options in config.items(): + for args in options.get("runs"): + probe_run_builder = "python " + options["path"] + for arg_name, arg_val in args.items(): + if len(arg_name) == 1: + arg_name = "-" + arg_name + else: + arg_name = "--" + arg_name + probe_run_builder += " " + arg_name + " " + str(arg_val) + Thread(target=run_probe, args=[probe_run_builder]).start() + + +if __name__ == "__main__": + main() diff --git a/setup.py b/setup.py index 6894cb44e31686634e9ba7d9130531d5650e754a..23189aba23e7857915e878c8e1fec3598d585958 100644 --- a/setup.py +++ b/setup.py @@ -13,5 +13,6 @@ setuptools.setup( "asyncssh~=2.13", "docker~=6.0", "beautifulsoup4~=4.12", + "yaml~=6.0", ], )