From 65e7c46b6e4616127802d21f68b57a98579000e2 Mon Sep 17 00:00:00 2001 From: Mike Gerber Date: Tue, 16 Jun 2015 01:36:57 +0200 Subject: [PATCH] Check for the existence of /usr/bin/systemctl first --- check_systemd_state | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/check_systemd_state b/check_systemd_state index f069095..041b421 100755 --- a/check_systemd_state +++ b/check_systemd_state @@ -2,11 +2,18 @@ # Nagios plugin to check the system state according to systemd. from __future__ import division, print_function +import posixpath import subprocess import sys +systemctl = '/usr/bin/systemctl' + +if not posixpath.exists(systemctl): + print('System WARN: systemctl not found') + sys.exit(1) + try: - state = subprocess.check_output(['systemctl', 'is-system-running']) + state = subprocess.check_output([systemctl, 'is-system-running']) state = state.strip() except subprocess.CalledProcessError as e: state = e.output.strip()