summaryrefslogtreecommitdiff
path: root/checks/gluster
blob: 64161c13352ba979a02a2f11248bdd0a0327f279 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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 %s',
}

check_info["gluster.vol_status"] = {
    'check_function':            check_gluster_volume_status,
    'inventory_function':        inventory_gluster_volume_status,
    'service_description':       'state of glusterfs volume',
}