summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xagent/gluster35
-rw-r--r--checks/gluster134
2 files changed, 169 insertions, 0 deletions
diff --git a/agent/gluster b/agent/gluster
new file mode 100755
index 0000000..e7098cd
--- /dev/null
+++ b/agent/gluster
@@ -0,0 +1,35 @@
+#!/usr/bin/python
+
+from subprocess import check_output
+import xml.etree.ElementTree as ET
+
+print "<<<gluster>>>"
+
+print "[peers]"
+pl_xml = check_output(["gluster", "--mode=script", "--xml", "peer", "status" ])
+pl = ET.fromstring(pl_xml)
+for peer in pl.iter('peer'):
+ p = {}
+ for c in peer.iter():
+ p[c.tag] = c.text
+ print "%s %s %s %s %s" % (p['uuid'], p['hostname'], p['connected'], p['state'], p['stateStr'])
+
+
+vl_xml = check_output(["gluster", "--mode=script", "--xml", "volume", "list" ])
+vl = ET.fromstring(vl_xml)
+for vol in vl.iter('volume'):
+ print "[volstatus:%s]" % vol.text
+ vs_xml = check_output(["gluster", "--mode=script", "--xml", "volume", "status", vol.text, "detail" ])
+ vs = ET.fromstring(vs_xml)
+ for node in vs.iter('node'):
+ n = {}
+ for c in node.iter():
+ n[c.tag] = c.text
+ print "%s %s %s %s %s %s" % (n['peerid'], n['hostname'], n['status'], n['sizeTotal'], n['sizeFree'], n['path'] )
+
+# heal info has no xml output so far... :(
+#
+# print "[heal:%s]" % vol.text
+# hi_xml = check_output(["gluster", "--mode=script", "--xml", "volume", "heal", vol.text, "info" ])
+# hi = ET.fromstring(hi_xml)
+
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',
+}