From d18c17186b55fcac4977183ee5047da77663add3 Mon Sep 17 00:00:00 2001 From: Marian Gasparovic Date: Thu, 26 Oct 2017 14:05:20 +0200 Subject: [PATCH] Plugin should return also a reason for warning from ceph. Change-Id: Ic8612eb123ec8335a6a867f0775116dba3a68dce Signed-off-by: Marian Gasparovic --- files/nagios/check_ceph_status.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/files/nagios/check_ceph_status.py b/files/nagios/check_ceph_status.py index cb8d1a1a..09ee5f8d 100755 --- a/files/nagios/check_ceph_status.py +++ b/files/nagios/check_ceph_status.py @@ -15,19 +15,28 @@ def check_ceph_status(args): nagios_plugin.check_file_freshness(args.status_file, 3600) with open(args.status_file, "r") as f: lines = f.readlines() - status_data = dict(l.strip().split(' ', 1) for l in lines if len(l) > 1) else: lines = subprocess.check_output(["ceph", "status"]).split('\n') - status_data = dict(l.strip().split(' ', 1) for l in lines if len(l) > 1) + status_data = dict(l.strip().split(' ', 1) for l in lines if len(l) > 1) - if ('health' not in status_data - or 'monmap' not in status_data - or 'osdmap'not in status_data): + if ('health' not in status_data or + 'monmap' not in status_data or + 'osdmap' not in status_data): raise nagios_plugin.UnknownError('UNKNOWN: status data is incomplete') if status_data['health'] != 'HEALTH_OK': - msg = 'CRITICAL: ceph health status: "{}"'.format(status_data['health']) + msg = 'CRITICAL: ceph health status: "{}'.format(status_data['health']) + if (len(status_data['health'].split(' '))) == 1: + a = iter(lines) + for line in a: + if re.search('health', line) is not None: + msg1 = next(a) + msg += " " + msg += msg1.strip() + break + msg += '"' raise nagios_plugin.CriticalError(msg) + osds = re.search("^.*: (\d+) osds: (\d+) up, (\d+) in", status_data['osdmap']) if osds.group(1) > osds.group(2): # not all OSDs are "up" msg = 'CRITICAL: Some OSDs are not up. Total: {}, up: {}'.format(