Difference between revisions of "Transforms - Nice Filesystem Events"

From Zenoss Wiki
Jump to: navigation, search
Line 6: Line 6:
 
import time, re, logging
 
import time, re, logging
  
if evt.DeviceClass.startswith('/Storage/NetApp'):
+
if device and evt.eventKey:
  # 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():
 
     for f in device.os.filesystems():
 
         if f.name() != evt.component and f.id != evt.component: continue
 
         if f.name() != evt.component and f.id != evt.component: continue
+
 
         # Extract the used amount from the event's message
+
         # Extract the used blocks from the event's message
 
         import re
 
         import re
 
         m = re.search("threshold of [^:]+: current value ([\d\.]+)", evt.message)
 
         m = re.search("threshold of [^:]+: current value ([\d\.]+)", evt.message)
         if not m:  
+
         if not m: continue
          evt.summary += ": No threshold re match - check transform"
+
   
          continue
+
+
 
         # Get the total blocks from the model. Adjust by specified offset.
 
         # Get the total blocks from the model. Adjust by specified offset.
 
         totalBlocks = f.totalBlocks * getattr(device, "zFileSystemSizeOffset", 1.0)
 
         totalBlocks = f.totalBlocks * getattr(device, "zFileSystemSizeOffset", 1.0)
         if not totalBlocks:
+
         if not totalBlocks: continue
          evt.summary += ": Couldn't get totalBlocks from model - check transform"
+
          continue
+
 
         evt.totalBlocks = totalBlocks
 
         evt.totalBlocks = totalBlocks
 
         totalBytes = totalBlocks * f.blockSize
 
         totalBytes = totalBlocks * f.blockSize
 
         usedBytes = None
 
         usedBytes = None
+
 
 
         currentValue = float(m.groups()[0])
 
         currentValue = float(m.groups()[0])
 
         evt.currentValue = currentValue
 
         evt.currentValue = currentValue
         if 'usedBlocks' in evt.eventKey or 'disk|' in evt.eventKey:
+
         if 'usedBlocks' in evt.eventKey:
 
             usedBytes = currentValue * f.blockSize
 
             usedBytes = currentValue * f.blockSize
 +
            evt.ifstatement = "usedBlocks in evt.eventKey"
 
         elif 'FreeMegabytes' in evt.eventKey:
 
         elif 'FreeMegabytes' in evt.eventKey:
 
             usedBytes = totalBytes - (currentValue * 1048576)
 
             usedBytes = totalBytes - (currentValue * 1048576)
 +
            evt.ifstatement = "usedBlocks = totalBytes - (current ..."
 
         elif 'availBlocks' in evt.eventKey:
 
         elif 'availBlocks' in evt.eventKey:
 
             usedBytes = totalBytes - (currentValue * 1024)
 
             usedBytes = totalBytes - (currentValue * 1024)
 
         else:
 
         else:
            evt.summary += ": Couldn't calculate usedBytes - check transform"
 
 
             continue
 
             continue
 
         try:
 
         try:
 +
            # Calculate the used percent and amount free.
 +
            usedBlocks = float(m.groups()[0])
 +
            evt.usedBlocks = usedBlocks
 
             p = (usedBytes / totalBytes) * 100
 
             p = (usedBytes / totalBytes) * 100
 
             evt.p = p
 
             evt.p = p
 
             from Products.ZenUtils.Utils import convToUnits
 
             from Products.ZenUtils.Utils import convToUnits
 
             free = convToUnits(totalBytes - usedBytes)
 
             free = convToUnits(totalBytes - usedBytes)
+
 
 
             # Make a nicer summary
 
             # Make a nicer summary
 
             evt.summary = "High Disk Utilization: Currently %3.0f%% used (%s free)" % (p, free)
 
             evt.summary = "High Disk Utilization: Currently %3.0f%% used (%s free)" % (p, free)
 
             evt.message = evt.summary
 
             evt.message = evt.summary
+
       
 
         except ZeroDivisionError, e:
 
         except ZeroDivisionError, e:
 
             # Total size hasn't been calculated
 
             # Total size hasn't been calculated
            evt.summary += ": Couldn't calculate size percentage - check transform"
 
 
             pass
 
             pass
+
 
 
         break
 
         break
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Transforms]]
 
[[Category:Transforms]]

Revision as of 17:41, 6 May 2014

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 device and evt.eventKey:
    for f in device.os.filesystems():
        if f.name() != evt.component and f.id != evt.component: continue
 
        # Extract the used blocks from the event's message
        import re
        m = re.search("threshold of [^:]+: current value ([\d\.]+)", evt.message)
        if not m: continue
 
        # Get the total blocks from the model. Adjust by specified offset.
        totalBlocks = f.totalBlocks * getattr(device, "zFileSystemSizeOffset", 1.0)
        if not totalBlocks: continue
        evt.totalBlocks = totalBlocks
        totalBytes = totalBlocks * f.blockSize
        usedBytes = None
 
        currentValue = float(m.groups()[0])
        evt.currentValue = currentValue
        if 'usedBlocks' in evt.eventKey:
            usedBytes = currentValue * f.blockSize
            evt.ifstatement = "usedBlocks in evt.eventKey"
        elif 'FreeMegabytes' in evt.eventKey:
            usedBytes = totalBytes - (currentValue * 1048576)
            evt.ifstatement = "usedBlocks = totalBytes - (current ..."
        elif 'availBlocks' in evt.eventKey:
            usedBytes = totalBytes - (currentValue * 1024)
        else:
            continue
        try:
            # Calculate the used percent and amount free.
            usedBlocks = float(m.groups()[0])
            evt.usedBlocks = usedBlocks
            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
            pass
 
        break