summaryrefslogtreecommitdiffstats
path: root/roles/nagios_server/files/nagios/plugins/check_ipmi
blob: f85397e1f87de6a0b0164fd9d8342f3e260049dd (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
#!/usr/bin/python
# mmcgrath#redhat.com
# Aug 08 2007
# License: GPL
from optparse import OptionParser
import commands
import sys

parser = OptionParser(version='0.1')
parser.add_option('-t', '--temperature',
                    dest = 'temp',
                    default = False,
                    action = 'store_true',
                    help = 'Check Temperatures')
parser.add_option('-f', '--fans',
                    dest = 'fans',
                    default = False,
                    action = 'store_true',
                    help = 'Check Fans')



(opts, args) = parser.parse_args()

class ipmiValue:
    def __init__(self, param='', value='', status=''):
        self.param = param
        try:
            self.value = (int(value.split(' ')[0], 10) * 9) / 5 + 32
        except ValueError:
            self.value = value
        self.status = status

class ipmi:
    def __init__(self):
        self.rawOutput = commands.getstatusoutput('/usr/bin/ipmitool sdr')[1].split('\n')
        self.sdr = []
        for i in self.rawOutput:
            try:
                param = i.split('|')[0].strip()
                value = i.split('|')[1].strip()
                status = i.split('|')[2].strip()
                self.sdr.append(ipmiValue(param, value, status))
            except IndexError:
                print "ERROR - Invalid output from ipmi tool (is it installed?  /usr/bin/ipmitool)"
                sys.exit(3)

    def temps(self):
        ''' Return Known Temperatures '''
        temps = []
        for i in self.sdr:
            if i.param.find('Temp') != -1 and i.status.find('ns') == -1:
                temps.append(i)
        return temps

    def fans(self):
        ''' Return Known Fan Speeds '''
        temps = []
        for i in self.sdr:
            if i.param.find('FAN') != -1 and i.status.find('ns') == -1:
                temps.append(i)
        return temps

str = False
exitCode = 0
if opts.temp:
    ok=True
    str='Temps (F)'
    i = ipmi()
    for temp in i.temps():    
        str = '%s:%s' % (str, temp.value)
        if temp.status != 'ok':
            ok=temp.status
    if ok:
        str = str + ' OK!'
    else:
        str = str + ' %s' % ok
        exitCode = 2

if opts.fans:
    ok=True
    str='Fans (RPM)'
    i = ipmi()
    for fan in i.fans():    
        str = '%s:%s' % (str, fan.value)
        if fan.status != 'ok':
            ok=fan.status
    if ok:
        str = str + ' OK!'
    else:
        str = str + ' %s' % ok
        exitCode = 2

if str:
    print str
    sys.exit(0)
else:
    print 'Please see -h for help'
    sys.exit(2)