Transforms - Nice Filesystem Events
From Zenoss Wiki
This is the approved revision of this page, as well as being the most recent.
Output provides a nice percentage with raw amount free.
Event Class: Perf > Filesystem
# Converts file system events into a prettier message with percentage and raw values import time, re, logging if evt.DeviceClass.startswith('/Storage/NetApp'): # Extract the used % from the event's message import re m = re.search("threshold of [^:]+: current value ([\d\.]+)", evt.message) if m: currentValue = float(m.groups()[0]) evt.currentValue = currentValue # Make a nicer summary evt.summary = "High Disk Utilization: Currently %3.0f%% used" % (currentValue) evt.message = evt.summary elif device and evt.eventKey: for f in device.os.filesystems(): if f.name() != evt.component and f.id != evt.component: continue # Extract the used amount from the event's message import re m = re.search("threshold of [^:]+: current value ([\d\.]+)", evt.message) if not m: evt.summary += ": No threshold re match - check transform" continue # Get the total blocks from the model. Adjust by specified offset. totalBlocks = f.totalBlocks * getattr(device, "zFileSystemSizeOffset", 1.0) if not totalBlocks: evt.summary += ": Couldn't get totalBlocks from model - check transform" continue evt.totalBlocks = totalBlocks totalBytes = totalBlocks * f.blockSize usedBytes = None currentValue = float(m.groups()[0]) evt.currentValue = currentValue if 'usedBlocks' in evt.eventKey or 'disk|' in evt.eventKey: usedBytes = currentValue * f.blockSize elif 'FreeMegabytes' in evt.eventKey: usedBytes = totalBytes - (currentValue * 1048576) elif 'availBlocks' in evt.eventKey: usedBytes = totalBytes - (currentValue * 1024) else: evt.summary += ": Couldn't calculate usedBytes - check transform" continue try: p = (usedBytes / totalBytes) * 100 evt.p = p from Products.ZenUtils.Utils import convToUnits free = convToUnits(totalBytes - usedBytes) # Make a nicer summary evt.summary = "High Disk Utilization: Currently %3.0f%% used (%s free)" % (p, free) evt.message = evt.summary except ZeroDivisionError, e: # Total size hasn't been calculated evt.summary += ": Couldn't calculate size percentage - check transform" pass break