From fb096c426c01c581b1ec60e90c1cddf3bebe1334 Mon Sep 17 00:00:00 2001 From: Patrick East Date: Sat, 13 Jun 2015 00:07:16 -0700 Subject: [PATCH] Update nagios image check to specify image and use dib. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It now looks at the dib-image-list output and only for a specific image name. It works much better now… Change-Id: I4ea3e92714cdaaea871f643e1131b2470231fd97 --- .../nagios/checks/check_nodepool_image.py | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/monitoring/nagios/checks/check_nodepool_image.py b/monitoring/nagios/checks/check_nodepool_image.py index 97b2c0d..8e430e1 100755 --- a/monitoring/nagios/checks/check_nodepool_image.py +++ b/monitoring/nagios/checks/check_nodepool_image.py @@ -6,31 +6,36 @@ import re import utils -def check_nodepool_image_status(warning_threshold, critial_threshold): +def check_nodepool_image_status(warning_threshold, critial_threshold, image, check_dib): """Returns a tuple of exit code and message string - Exit codes are either 2 -> critical or 0 -> OK - There are no warnings with gearman job checker + Exit codes are either 2 -> critical, 1 -> warning, or 0 -> OK """ try: - image_list_raw = utils.run_command_local('sudo /usr/local/bin/nodepool image-list') + if check_dib: + cmd = 'dib-image-list' + else: + cmd = 'image-list' + image_list_raw = utils.run_command_local('sudo /usr/local/bin/nodepool ' + cmd) image_list_lines = image_list_raw.split('\n') newest_image_age = None for line in image_list_lines: - match = re.search('\|\s+(\w+)\s+\|\s+(\d+\.\d+)\s+\|$', line) - if match: - status = match.group(1) - age = float(match.group(2)) - if status == 'ready': - if (newest_image_age is None) or (age < newest_image_age): - newest_image_age = age + if re.search('\|\s+' + image + '\s+\|', line): + match = re.search('\|\s+(\w+)\s+\|\s+(\d+:\d+:\d+:\d+)\s+\|$', line) + if match: + status = match.group(1) + if status == 'ready': + age_parts = match.group(2).split(':') + age_in_hours = (int(age_parts[0]) * 24) + int(age_parts[1]) + if (newest_image_age is None) or (age_in_hours < newest_image_age): + newest_image_age = age_in_hours - if not newest_image_age: + if newest_image_age is None: return 2, 'Error running command, output: ' + image_list_raw exit_code = 0 - if newest_image_age > warning_threshold: + if newest_image_age > critial_threshold: exit_code = 2 elif newest_image_age > warning_threshold: exit_code = 1 @@ -43,7 +48,9 @@ if __name__ == '__main__': parser = argparse.ArgumentParser(description='Check nodepool image status.') parser.add_argument('-w', required=True, type=int, help='warning threshold for age of the image in hours') parser.add_argument('-c', required=True, type=int, help='critical threshold for age of the image in hours') + parser.add_argument('-i', required=True, type=str, help='name of image') + parser.add_argument('--dib', action='store_true', help='Check dib images.') args = parser.parse_args() - code, message = check_nodepool_image_status(args.w, args.c) + code, message = check_nodepool_image_status(args.w, args.c, args.i, args.dib) print message - exit(code) \ No newline at end of file + exit(code)