Last active
October 16, 2015 17:39
-
-
Save evandhoffman/b29245c1b38d3e19b531 to your computer and use it in GitHub Desktop.
Python script that emits disks and mdadm raid devices in a form usable by Zabbix low-level discovery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
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 } | |
result.append(row) | |
data_arr = {"data": result } | |
print json.dumps(data_arr, indent=2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See here for more information: https://www.zabbix.com/documentation/2.4/manual/discovery/low_level_discovery