From b056bb608e2b216adeb57eadc207c6df289fbcda Mon Sep 17 00:00:00 2001 From: rkarlsba Date: Mon, 4 Feb 2019 12:06:24 +0100 Subject: [PATCH] Filter out partitions The original code lists partitions as well as disks - it doesn't make sense to monitor partitions --- lld-disks.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lld-disks.py b/lld-disks.py index 48fd3d6..a42081b 100644 --- a/lld-disks.py +++ b/lld-disks.py @@ -1,12 +1,16 @@ #!/usr/bin/python import os import json +import re if __name__ == "__main__": + # filter out partitions + rx_sd = re.compile('.*[a-z]$') # Iterate over all block devices, but ignore them if they are in the # skippable set skippable = ("sr", "loop", "ram") devices = (device for device in os.listdir("/sys/class/block") - if not any(ignore in device for ignore in skippable)) + if not any(ignore in device for ignore in skippable) + and rx_sd.match(device)) data = [{"{#DEVICENAME}": device} for device in devices] print(json.dumps({"data": data}, indent=4))