Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt script to use megacli and make it python3 compatible #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions megacli.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def tobytes(inp):
return inp

def main():
info = subprocess.check_output(['/opt/MegaRAID/MegaCli/MegaCli64', '-AdpAllInfo', '-aAll', '-nolog']).decode('utf-8').splitlines()
pdlist = subprocess.check_output(['/opt/MegaRAID/MegaCli/MegaCli64', '-PdList', '-aAll', '-nolog']).decode('utf-8').splitlines()
info = subprocess.check_output(['megacli', '-AdpAllInfo', '-aAll', '-nolog']).decode('utf-8').splitlines()
pdlist = subprocess.check_output(['megacli', '-PdList', '-aAll', '-nolog']).decode('utf-8').splitlines()
out = {}
adapter = None

Expand All @@ -50,25 +50,25 @@ def main():
]

pat_info = [
{
{
'regex': re.compile('^Adapter\s+#\d+'),
'action': [
'adapter=line.split("#")[1].strip()'
]
},
{
{
'regex': re.compile('^Product\s+Name\s+:'),
'action': [
'out["megacli_controller"]["metrics"].append({ "labels": { "adapter": adapter, "product_name": line.split(":")[1].strip()}, "val": 1})'
]
]
},
{
{
'regex': re.compile('^FW\s+Package\s+Build\s*:'),
'action': [
'out["megacli_controller"]["metrics"].append({ "labels": { "adapter": adapter, "package_build": line.split(":")[1].strip()}, "val": 1 })'
]
},
{
{
'regex': re.compile('^FW\s+Version\s+:'),
'action': [
'out["megacli_controller"]["metrics"].append({ "labels": { "adapter": adapter, "firmware_version": line.split(":")[1].strip()}, "val": 1 })'
Expand Down Expand Up @@ -153,13 +153,13 @@ def main():
]
},
]

enclosure=None
slot=None
position=None
device_id=None
wwn=None

pat_pd = [
{
'regex': re.compile('^Adapter\s+#\d+'),
Expand Down Expand Up @@ -280,11 +280,11 @@ def main():
]
},
]

for m in metrics:
exec(m)

for line in info:
for line in info:
for p in pat_info:
if p['regex'].match(line):
for a in p['action']:
Expand All @@ -299,7 +299,7 @@ def main():
continue

# print json.dumps(out, indent=2, sort_keys=True)
for k,v in out.iteritems():
for k,v in out.items():
print("# HELP " + k + " " + v['help'])
print("# TYPE " + k + " " + v['type'])
for m in v['metrics']:
Expand Down