From 6c60addfaefd9ce9739c6261ee2a1650356f3c8b Mon Sep 17 00:00:00 2001 From: Sven Velt Date: Wed, 29 Nov 2017 11:56:36 +0100 Subject: [PATCH] Version 1 --- .gitignore | 5 +++++ ssh-wrapper.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 .gitignore create mode 100755 ssh-wrapper.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d1fe9a2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.*sw? +*~ + +*.pyc + diff --git a/ssh-wrapper.py b/ssh-wrapper.py new file mode 100755 index 0000000..80f430e --- /dev/null +++ b/ssh-wrapper.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +import os +import re +import shlex +import subprocess +import sys + +allowed = [ + r'^/usr/bin/lsb_release\s+-d$', + r'^/usr/lib/nagios/plugins/check_disk -w \d+% -c \d+% -p /[/a-z]*$', + r'^/usr/lib/nagios/plugins/check_load -w \d+(,\d+,\d+)? -c \d+(,\d+,\d+)?$', + r'^/usr/lib/nagios/plugins/check_mysql -u [a-z]+ -p [0-9a-zA-Z]+', + r'^/usr/lib/nagios/plugins/check_mysql_health --user(name)?=[a-z]+ --pass(word)?=[0-9a-zA-Z]+ --mode=[a-z-]+$', + ] + +#cmdline = ' '.join(sys.argv[1:]) +cmdline = os.getenv('SSH_ORIGINAL_COMMAND') + +for maybe in allowed: + if re.match(maybe, cmdline): + cmdline = shlex.split(cmdline) + + cmd = subprocess.Popen(cmdline, stdout=subprocess.PIPE) + print cmd.communicate()[0].rstrip() + sys.exit(cmd.returncode) + +print '%s: No command found!' % sys.argv[0] +sys.exit(3) +