Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Python script that emits disks and mdadm raid devices in a form usable by Zabbix low-level discovery
import json
import subprocess
blockdev_fullpath_macro = "{#BLOCKDEV_FULLPATH}"
blockdev_type_macro = "{#BLOCKDEV_TYPE}"
blockdev_shortname_macro = "{#BLOCKDEV_SHORTNAME}"
output = subprocess.Popen("lsblk -r -io KNAME,TYPE", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True )
result = []
dedupe = {}
device_types = ['disk','raid0','raid5']
for line in output.stdout:
(dev_name, dev_type) = line.rstrip().split()
if any( dt in dev_type for dt in device_types):
dedupe[dev_name] = dev_type
for dev_name in dedupe:
dev_type = dedupe[dev_name]
dev_fullpath = '\/dev\/' + dev_name
row = { blockdev_shortname_macro: dev_name, blockdev_type_macro: dev_type , blockdev_fullpath_macro: dev_fullpath }
data_arr = {"data": result }
print json.dumps(data_arr, indent=2)

This comment has been minimized.

Copy link
Owner Author

evandhoffman commented Oct 16, 2015

See here for more information:

# python
  "data": [
      "{#BLOCKDEV_FULLPATH}": "\\/dev\\/sdm",
      "{#BLOCKDEV_TYPE}": "disk",
      "{#BLOCKDEV_SHORTNAME}": "sdm"
      "{#BLOCKDEV_FULLPATH}": "\\/dev\\/md0",
      "{#BLOCKDEV_TYPE}": "raid0",
      "{#BLOCKDEV_SHORTNAME}": "md0"
      "{#BLOCKDEV_FULLPATH}": "\\/dev\\/sdo",
      "{#BLOCKDEV_TYPE}": "disk",
      "{#BLOCKDEV_SHORTNAME}": "sdo"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.