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

feat: script to execute multiple monitoring probes

parent 7adcf9ea
No related branches found
No related tags found
1 merge request!33feat: script to execute multiple monitoring probes
Pipeline #283711 passed
# ProxyIdP scripts # Perun proxy utils
## Scripts ## 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 ### separate_ssp_script.py
- Script for remove all logs from test accounts from SimpleSAMLlogs - Script for remove all logs from test accounts from SimpleSAMLlogs
......
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
#!/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)
...@@ -15,6 +15,7 @@ setuptools.setup( ...@@ -15,6 +15,7 @@ setuptools.setup(
"beautifulsoup4~=4.12", "beautifulsoup4~=4.12",
"requests~=2.31", "requests~=2.31",
"ldap3~=2.9.1", "ldap3~=2.9.1",
"PyYAML~=6.0",
"check_syncrepl_extended @ git+https://gitlab.ics.muni.cz/perun-proxy-aai/" "check_syncrepl_extended @ git+https://gitlab.ics.muni.cz/perun-proxy-aai/"
"python/check_syncrepl_extended.git@main", "python/check_syncrepl_extended.git@main",
"check_nginx_status @ git+https://gitlab.ics.muni.cz/perun-proxy-aai/" "check_nginx_status @ git+https://gitlab.ics.muni.cz/perun-proxy-aai/"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment