summaryrefslogtreecommitdiff
path: root/checks/rhctl
blob: 5a0f46c5fc9d32c3751f926691ff277a1544f69c (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
OK = 0
WARN = 1
CRIT = 2
UNKNOWN = 3

def get_data(info):
   import json
   all = ""
   for line in info:
      all = all + ' '.join(line)
   return json.loads(all)

def inventory_rhctl_status(info):
   try:
     inventory = []
     inventory.append((None,None))
     return inventory
   except Exception, e:
     return []


def check_rhctl_status(item, params, info):
   try:
      data = get_data(info)
      if data['Mood'] == 'awakening':
         return (WARN, 'rhctl is awakening')
      if data['Mood'] == 'happy':
         if data['ActiveServer'] == 'master':
            return (OK, 'rhctl is happy, active server is %s' % data['ActiveServer'])
         else:
            return (WARN, 'rhctl is happy, active server is %s(!)' % data['ActiveServer'])
      if data['Mood'] == 'nervous':
         return (WARN, 'rhctl is nervous(!), active server is %s' % data['ActiveServer'])
      if data['Mood'] == 'sad':
         return (CRIT, 'rhctl is sad(!!), last active server was %s' % data['ActiveServer'])
      return (UNKNOWN, 'rhctl has unknown(!!) mood: %s' % data['Mood'])
   except Exception, e:
      return (UNKNOWN, "rhctl check failed: %s" % e.message)



def inventory_rhctl_server(info):
   try:
     inventory = []
     data = get_data(info)
     for server in data['Server']:
        inventory.append((str(server),None))
     return inventory
   except Exception, e:
     return []


def check_rhctl_server(item, params, info):
   try:
      data = get_data(info)
      if item not in data['Server']:
         return (UNKNOWN, 'server %s is missing(!!) in status report' % item)
      if data['Server'][item]['Health'] == "alive":
         return (OK, 'server %s is alive' % item)
      if data['Server'][item]['Health'] == "dead":
         return (CRIT, 'server %s is dead(!!)' % item)
      return (UNKNOWN, 'server %s health is unknown(!!): %s' % (item, data['Server'][item]['Health']))
   except Exception, e:
      return (UNKNOWN, "rhctl check failed: %s" % e.message)



check_info["rhctl.mood"] = {
    'check_function':            check_rhctl_status,
    'inventory_function':        inventory_rhctl_status,
    'service_description':       'Mood of rhctl',
}

check_info["rhctl.server"] = {
    'check_function':            check_rhctl_server,
    'inventory_function':        inventory_rhctl_server,
    'service_description':       'rhctl state of server %s',
}