diff options
Diffstat (limited to 'checks/gluster')
-rw-r--r-- | checks/gluster | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/checks/gluster b/checks/gluster new file mode 100644 index 0000000..ef3e37f --- /dev/null +++ b/checks/gluster @@ -0,0 +1,134 @@ +import re + +OK = 0 +WARN = 1 +CRIT = 2 +UNKNOWN = 3 + +def get_section(name, info): + secre = re.compile('^\[([^:]+)(:(.*))?\]$') + + results = [] + + found = False + sub = None + lines = [] + for line in info: + m = secre.match(line[0]) + if not found: + if m and m.groups()[0] == name: + sub = m.groups()[2] + found = True + lines = [] + else: + if not m: + lines.append(line) + else: + results.append((sub, lines)) + if m.groups()[0] != name: + found = False + else: + sub = m.groups()[2] + lines = [] + + if found: + results.append((sub, lines)) + + return results + + + + +def inventory_gluster_peers(info): + inventory = [] + + (_, lines) = get_section('peers', info)[0] + for line in lines: + inventory.append((line[0],None)) + + return inventory + + +def check_gluster_peers(item, params, info): + (_, lines) = get_section('peers', info)[0] + for line in lines: + if item == line[0]: + if line[2] == '0': + return (CRIT, "not(!!) connected (%s), state %s (%s)" % (line[1], line[3], " ".join(line[4:]))) + elif line[3] == '3': + return (OK, "connected (%s), state %s (%s)" % (line[1], line[3], " ".join(line[4:]))) + return (CRIT, "connected (%s), state %s(!!) (%s)" % (line[1], line[3], " ".join(line[4:]))) + + return (CRIT, "peer not found!") + + + + +def inventory_gluster_volume_status(info): + inventory = [] + + results = get_section('volstatus', info) + for (vol, lines) in results: + uuids = [] + for line in lines: + uuids.append(line[0]) + + inventory.append((vol, uuids)) + + return inventory + + +def check_gluster_volume_status(item, params, info): + results = get_section('volstatus', info) + for (vol, lines) in results: + if vol == item: + uuids = dict((p, [-1]) for p in params) + for line in lines: + if line[0] in uuids.keys(): + uuids[line[0]][0] += 1 + else: + uuids[line[0]] = [1] + + uuids[line[0]].extend(line[1:]) + + status = OK + message = "%i of %i bricks online" % (len(lines), len(params)) + + for uuid in uuids: + if uuids[uuid][0] > 0: + message += ", found new peer %s(!) - please update inventory" % uuid + status = WARN if WARN > status else status + continue + if uuids[uuid][0] < 0: + message += ", missing peer %s(!)" % uuid + status = WARN if WARN > status else status + continue + + if uuids[uuid][2] != '1': + message += ", status(!) of peer %s" % uuid + status = WARN if WARN > status else status + + p = (float(uuids[uuid][4]) / float(uuids[uuid][3])) * 100.0 + if p < 20.0: + message += ", %s@%s has less then 20%% free space(!)" % (uuids[uuid][5], uuids[uuid][1]) + status = WARN if WARN > status else status + if p < 10.0: + message += ", %s@%s has less then 10%% free space(!!)" % (uuids[uuid][5], uuids[uuid][1]) + status = CRIT if CRIT > status else status + + return (status, message) + + return (UNKNOWN, "volume not found!") + + +check_info["gluster.peers"] = { + 'check_function': check_gluster_peers, + 'inventory_function': inventory_gluster_peers, + 'service_description': 'state of glusterfs peer', +} + +check_info["gluster.vol_status"] = { + 'check_function': check_gluster_volume_status, + 'inventory_function': inventory_gluster_volume_status, + 'service_description': 'state of glusterfs volume', +} |