This repository has been archived by the owner on May 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StorCLI.py
73 lines (56 loc) · 1.91 KB
/
StorCLI.py
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
"""
Server Density Plugin
StorCLI (MegaRAID) monitor
Inspired by https://github.com/serverdensity/sd-agent-plugins/tree/master/MegaRAID
Version: 1.0.0
"""
import json
import logging
import platform
import sys
import subprocess
import time
class StorCLI(object):
"""
Check the "Hlth" of the controller using output from
/opt/MegaRAID/storcli/storcli64 show J
"""
def __init__(self, agent_config, checks_logger, raw_config):
self.agent_config = agent_config
self.checks_logger = checks_logger
self.raw_config = raw_config
self.version = platform.python_version_tuple()
def run(self):
data = {}
try:
proc = subprocess.Popen(
['sudo', '/opt/MegaRAID/storcli/storcli64', 'show', 'J'],
stdout=subprocess.PIPE,
close_fds=True)
output = proc.communicate()[0]
except OSError as exception:
self.checks_logger.error(
'Unable to find /opt/MegaRAID/storcli/storcli64.'
' Error: {0}'.format(exception.message))
return data
outputJson = json.loads(output)
for ctl in outputJson['Controllers']:
for stat in ctl['Response Data']['System Overview']:
data['Ctl-' + str(stat['Ctl']) + '-Hlth'] = stat['Hlth']
return data
if __name__ == '__main__':
"""
Standalone test
"""
raw_agent_config = {}
main_checks_logger = logging.getLogger('StorCLI')
main_checks_logger.setLevel(logging.DEBUG)
main_checks_logger.addHandler(logging.StreamHandler(sys.stdout))
megaraid_check = StorCLI({}, main_checks_logger, raw_agent_config)
while True:
try:
print json.dumps(megaraid_check.run(), indent=4, sort_keys=True)
except:
main_checks_logger.exception("Unhandled exception")
finally:
time.sleep(60)