Skip to content

Instantly share code, notes, and snippets.

@kamermans
Last active February 20, 2023 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save kamermans/e83657f8194db6b73defb7b4e2142364 to your computer and use it in GitHub Desktop.
Save kamermans/e83657f8194db6b73defb7b4e2142364 to your computer and use it in GitHub Desktop.
Script to parse storcli (replaced megacli) output for use in monitoring applications like Nagios, Zabbix, etc
#!/usr/bin/env python
#
# Parses the output of storcli:
# storcli /c0 show all J
import sys
import json
output_dir = "."
data = json.load(sys.stdin)
controllers = []
line_output = open(output_dir + "/raid_status.txt", "w")
json_output = open(output_dir + "/raid_status.json", "w")
zabbix_discovery_ctrl = open(output_dir + "/raid_zabbix_discovery_ctrl.json", "w")
zabbix_discovery_vd = open(output_dir + "/raid_zabbix_discovery_vd.json", "w")
zabbix_discovery_pd = open(output_dir + "/raid_zabbix_discovery_pd.json", "w")
zabbix_discovery = {
"ctrl": [],
"vd": [],
"pd": []
}
for ctrl_raw in data["Controllers"]:
ctrl_data = ctrl_raw["Response Data"]
controller = {
"id": ctrl_data["Basics"]["Controller"], # 0
"model": ctrl_data["Basics"]["Model"], # PERC H700 Integrated
"firmware": ctrl_data["Version"]["Firmware Version"], # 2.100.03-4651
"status": ctrl_data["Status"]["Controller Status"], # OK
"memory": ctrl_data["HwCfg"]["On Board Memory Size"], # 512MB
"bbu_status": ctrl_data["BBU_Info"][0]["State"], # Optimal
"bbu_date": ctrl_data["BBU_Info"][0]["MfgDate"], # "2014/10/13"
"vds": [],
"pds": []
}
for prop in ["model", "firmware", "status", "memory", "bbu_status", "bbu_date"]:
line_output.write("ctrl:%i;%s\t%s\n" % (controller["id"], prop, str(controller[prop])))
zabbix_discovery["ctrl"].append({
"{#CTRL}": controller["id"],
"{#MODEL}": controller["model"]
})
for vd_data in ctrl_data["VD LIST"]:
vd = {
"id": "%i/%s" % (controller["id"], vd_data["DG/VD"]), # 0/1/1
"name": vd_data["Name"], # Virtual Disk 1
"type": vd_data["TYPE"], # RAID1
"state": vd_data["State"], # Optl
"size": vd_data["Size"] # 111.25 GB
};
controller["vds"].append(vd)
for prop in ["name", "type", "size", "state"]:
line_output.write("vd:%s;%s\t%s\n" % (vd["id"], prop, str(vd[prop])))
zabbix_discovery["vd"].append({
"{#VD}": vd["id"],
"{#NAME}": "%s %s [%s]" % (vd["size"], vd["type"], vd["name"])
})
for pd_data in ctrl_data["PD LIST"]:
pd = {
"id": "%i/%s" % (controller["id"], pd_data["EID:Slt"]), # 0/32:0
"type": pd_data["Med"], # SSD
"state": pd_data["State"], # Onln
"size": pd_data["Size"], # 111.25 GB
"model": pd_data["Model"] # INTEL SSDSC2BF120A5
}
controller["pds"].append(pd)
for prop in ["type", "state", "size", "model"]:
line_output.write("pd:%s;%s\t%s\n" % (pd["id"], prop, str(pd[prop])))
zabbix_discovery["pd"].append({
"{#PD}": pd["id"],
"{#NAME}": "%s %s [%s]" % (pd["size"], pd["type"], pd["model"])
})
health = {
"vds": len(controller["vds"]),
"bad_vds": sum(v["state"] != "Optl" for v in controller["vds"]),
"pds": len(controller["pds"]),
"bad_pds": sum(p["state"] != "Onln" for p in controller["pds"])
}
controllers.append(controller)
json.dump(controllers, json_output, indent=4, sort_keys=True)
json.dump({"data": zabbix_discovery["ctrl"]}, zabbix_discovery_ctrl, indent=4, sort_keys=True)
json.dump({"data": zabbix_discovery["vd"]}, zabbix_discovery_vd, indent=4, sort_keys=True)
json.dump({"data": zabbix_discovery["pd"]}, zabbix_discovery_pd, indent=4, sort_keys=True)
line_output.close()
json_output.close()
zabbix_discovery_ctrl.close()
zabbix_discovery_vd.close()
zabbix_discovery_pd.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment