def check_heartbeat(res):
    """Write/read a random string into the heartbeat file."""
    client = schecks.get_client(opts)
    random_str = str(uuid.uuid4())[:8]

    write = "echo {0} > {1}".format(random_str, PATH)
    stdin, stdout, stderr = client.exec_command('export LC_LANG=C && unset LANG && %s' % write)
    if stderr:
        print "CRITICAL: Unresponsive mount!"
        sys.exit(2)

    read = "cat {0}".format(PATH)
    stdin, stdout, stderr = client.exec_command('export LC_LANG=C && unset LANG && %s' % read)
    if stderr or stdout[0] != random_str:
        print "CRITICAL: Unresponsive mount!"
        sys.exit(2)

    # Everything is OK - set the event
    res.set()
    # Before return, close the client
    client.close()

    return mdraid_healthy, mdraid_recover, mdraid_check, mdraid_sync

###############################################################################

parser = schecks.get_parser()

if __name__ == '__main__':
    # Ok first job : parse args
    opts, args = parser.parse_args()
    
    # Ok now got an object that link to our destination
    client = schecks.get_client(opts)
    
    # Scrape /proc/mdstat and get result and perf data
    healthy, recover, scrub, sync = get_raid_status(client)
    # Format perf data
    perf = "|Recover={0}%;0%;100% Scrub={1}%;0%;100% Sync={2}%;0%;100%".format(recover, scrub, sync)

    if not float(recover) == 100:
        print("WARNING: RAID is recovering " + perf)
        sys.exit(1)
    elif healthy:
        print "OK: RAID is healthy " + perf
        sys.exit(0)
    else:
        print "CRITICAL: RAID is degraded " + perf
        sys.exit(2)
示例#3
0
                              int(nb_sec_write), int(io_time)))

    # Before return, close the client
    client.close()

    return diff, stats


parser = schecks.get_parser()

if __name__ == '__main__':
    # Ok first job : parse args
    opts, args = parser.parse_args()

    # Ok now got an object that link to our destination
    client = schecks.get_client(opts)

    # Do the job
    diff, stats = get_disks_stats(client)

    # Maybe we failed at getting data
    if not stats:
        print "Error : cannot fetch disk stats values from host"
        sys.exit(2)

    # We are putting diff into float so we are sure we will have float everywhere
    diff = float(diff)

    perfdata = []
    for (device, v) in stats.iteritems():
        if len(v) < 2: