Difference between revisions of "Transforms - Nice Interface Events"

From Zenoss Wiki
Jump to: navigation, search
(Rewritten/refactored to be more performant)
 
Line 3: Line 3:
 
Event Class: Perf > Interface
 
Event Class: Perf > Interface
 
<syntaxhighlight lang=python>
 
<syntaxhighlight lang=python>
#Transform interface usage into readable format
+
# Transform interface usage for /Perf/Interface threshold events into readable format
import re
+
 
+
# Check if this actually is on an interface component with a speed attribute
fs_id = device.prepId(evt.component)
+
if getattr(component, 'speed', None) is not None:
for f in device.os.interfaces():
+
 
    if f.id != fs_id: continue
+
  # Extract the percent and utilization from the summary
+
  import re
    # Extract the percent and utilization from the summary
+
  m = re.search("threshold of [^:]+: current value ([\d\.]+)", evt.message)
    m = re.search("threshold of [^:]+: current value ([\d\.]+)", evt.message)
+
  currentusage = (float(m.group(1))) * 8
    if not m: continue
+
 
    currentusage = (float(m.group(1))) * 8
+
  # Convert to a percentage of speed. Like threshold, use default speed of 1e09 if speed attribute is not modelled
    p = (currentusage / f.speed) * 100
+
  p = (currentusage / (component.speed or 1e09)) * 100
    evtKey = evt.eventKey
+
 
 +
  evtKey = evt.eventKey
 
    
 
    
    # Whether Input or Output Traffic
+
  # Whether Input or Output Traffic
    if evtKey == "ifInOctets_ifInOctets|high utilization" or evtKey == "ifHCInOctets_ifHCInOctets|high utilization":
+
  if evtKey == "ifInOctets_ifInOctets|high utilization" or evtKey == "ifHCInOctets_ifHCInOctets|high utilization":
        evtNewKey = "Input"
+
      evtNewKey = "Input"
    elif evtKey == "ifOutOctets_ifOutOctets|high utilization" or evtKey == "ifHCOutOctets_ifHCOutOctets|high utilization":
+
  elif evtKey == "ifOutOctets_ifOutOctets|high utilization" or evtKey == "ifHCOutOctets_ifHCOutOctets|high utilization":
        evtNewKey = "Output"
+
      evtNewKey = "Output"
+
 
    # Check the speed to determine the appropriate conversion
+
  # Change the summary to display input/ouput and correct units
    # Gbps utilization
+
  from Products.ZenUtils.Utils import convToUnits
    if currentusage > 1000000000:
+
  evt.summary = "High Interface " + evtNewKey + " Utilization: Currently %3.0f%% used (%s)" % (p, convToUnits(currentusage,1024,'bps'))
        Usage = currentusage / 1000000000
+
 
        evt.summary = "High Interface " + evtNewKey + " Utilization: Currently %3.0f%% used (%3.2f Gbps)" % (p, Usage)
+
  # Update the message to the summary
        evt.message = evt.summary
+
  evt.message = evt.summary
+
    # Mbps utilization
+
    elif currentusage > 1000000:
+
        Usage = currentusage / 1000000
+
        evt.summary = "High Interface " + evtNewKey + " Utilization: Currently %3.0f%% used (%3.2f Mbps)" % (p, Usage)
+
        evt.message = evt.summary
+
+
    # Kbps utilization
+
    elif currentusage > 1000:
+
        Usage = currentusage / 1000
+
        evt.summary = "High Interface " + evtNewKey + " Utilization: Currently %3.0f%% used (%3.2f Kbps)" % (p, Usage)
+
        evt.message = evt.summary
+
+
    # bps  utilization
+
    elif currentusage < 1000:
+
        Usage = currentusage
+
        evt.summary = "High Interface " + evtNewKey + " Utilization: Currently %3.0f%% used (%3.2f bps)" % (p, Usage)
+
        evt.message = evt.summary
+
    break
+
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Transforms]]
 
[[Category:Transforms]]

Latest revision as of 20:51, 12 January 2017

This converts interface utilization into a percentage and Kb, Mb, Gb, etc. raw amount based on link speed.

Event Class: Perf > Interface

# Transform interface usage for /Perf/Interface threshold events into readable format
 
# Check if this actually is on an interface component with a speed attribute
if getattr(component, 'speed', None) is not None:
 
   # Extract the percent and utilization from the summary
   import re
   m = re.search("threshold of [^:]+: current value ([\d\.]+)", evt.message)
   currentusage = (float(m.group(1))) * 8
 
   # Convert to a percentage of speed. Like threshold, use default speed of 1e09 if speed attribute is not modelled
   p = (currentusage / (component.speed or 1e09)) * 100
 
   evtKey = evt.eventKey
 
   # Whether Input or Output Traffic
   if evtKey == "ifInOctets_ifInOctets|high utilization" or evtKey == "ifHCInOctets_ifHCInOctets|high utilization":
       evtNewKey = "Input"
   elif evtKey == "ifOutOctets_ifOutOctets|high utilization" or evtKey == "ifHCOutOctets_ifHCOutOctets|high utilization":
       evtNewKey = "Output"
 
   # Change the summary to display input/ouput and correct units
   from Products.ZenUtils.Utils import convToUnits
   evt.summary = "High Interface " + evtNewKey + " Utilization: Currently %3.0f%% used (%s)" % (p, convToUnits(currentusage,1024,'bps'))
 
   # Update the message to the summary
   evt.message = evt.summary