def check_nodepool_image_status(warning_threshold, critial_threshold):
    """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
    """
    try:
        image_list_raw = utils.run_command_local('sudo /usr/local/bin/nodepool image-list')
        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 not newest_image_age:
            return 2, 'Error running command, output: ' + image_list_raw

        exit_code = 0
        if newest_image_age > warning_threshold:
            exit_code = 2
        elif newest_image_age > warning_threshold:
            exit_code = 1
        return exit_code, 'Nodepool image age (hours): ' + str(newest_image_age)

    except Exception, e:
        return 2, 'Error checking nodepool images: %s' + str(e)
예제 #2
0
def check_gearman_status(job_name):
    """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
    """
    try:
        gearadmin_status = utils.run_command_local('(echo status ; sleep 0.1) | netcat 127.0.0.1 4730 -w 1')
        if job_name not in gearadmin_status:
            return 2, 'Failed to find job registered with gearman!\nstatus:\n%s' % gearadmin_status
    except Exception, e:
        return 2, 'Failed to check gearman status' + e.message
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, 1 -> warning, or 0 -> OK
    """
    try:
        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:
            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 newest_image_age is None:
            return 2, 'Error running command, output: ' + image_list_raw

        exit_code = 0
        if newest_image_age > critial_threshold:
            exit_code = 2
        elif newest_image_age > warning_threshold:
            exit_code = 1
        return exit_code, 'Nodepool image age (hours): ' + str(newest_image_age)

    except Exception, e:
        return 2, 'Error checking nodepool images: %s' + str(e)