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
/
ArcconfCLI.py
74 lines (58 loc) · 2.03 KB
/
ArcconfCLI.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
74
"""
Server Density Plugin
ArcconfCLI 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 ArcconfCLI(object):
"""
Check the "Status of Logical Device" of the controller using output from
/var/opt/arcconf GETCONFIG 1 LD
"""
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', '/var/opt/arcconf', 'GETCONFIG', '1', 'LD'],
stdout=subprocess.PIPE,
close_fds=True)
output = proc.communicate()[0]
except OSError as exception:
self.checks_logger.error(
'Unable to find /opt/arcconf.'
' Error: {0}'.format(exception.message))
return data
ldn = 'X'
for line in output.split("\n"):
if line.startswith('Logical Device number'):
ldn = line.replace('Logical Device number ', '').replace(' ', '')
if line.startswith(' Status of Logical Device'):
data['logical-device-' + ldn + '-state'] = line.split(':')[1].replace(' ', '')
return data
if __name__ == '__main__':
"""
Standalone test
"""
raw_agent_config = {}
main_checks_logger = logging.getLogger('ArcconfCLI')
main_checks_logger.setLevel(logging.DEBUG)
main_checks_logger.addHandler(logging.StreamHandler(sys.stdout))
megaraid_check = ArcconfCLI({}, 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)