Difference between revisions of "Transforms - Nice Interface Events"
From Zenoss Wiki
Crouthamela (Talk | contribs) m |
(Rewritten/refactored to be more performant) |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
This converts interface utilization into a percentage and Kb, Mb, Gb, etc. raw amount based on link speed. | This converts interface utilization into a percentage and Kb, Mb, Gb, etc. raw amount based on link speed. | ||
+ | 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 |
− | + | ||
− | + | # 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 | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
</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