User Tools

Site Tools


scripts:zenoss_transforms:jnxpowersupplyfailure.trap
jnxPowerSupplyFailure.trap
# Written by Thomas York
# Generates an event for Juniper power supply changes
# This transform also properly ties to the Power Supply component provided by the Juniper ZenPack
 
# Imports
from transaction import commit
 
# Store PSU description name
str_descr = getattr(evt.details, "jnxContentsDescr", None)
 
# Iterate over the PSUs to find a match
for obj_psus in d.hw.powersupplies():
 
 # Check to see if the PSU string in Zenoss matches the trap. If so, assocate them!
 if obj_psus.powerSupplyDescr == str_descr:
  evt.component = obj_psus.getId()
 
  # Find state of PSU
  # https://support.ipmonitor.com/mibs/JUNIPER-MIB/item.aspx?id=jnxPowerSupplyFailure
  int_state = getattr(evt.details, "jnxOperatingState", None)
 
  # Check to see if int_state is populated
  if int_state is not None:
   int_state = int(int_state)
 
   # Convert int_state to human readable status
   # Also, we're updating the state of the power supply object by hand to reflect the trap information
   # This state doesn't get locked in. It can/will be updated by another trap or during modeling/collection
   if int_state == 2 :
    # Running state
    evt.summary = 'PSU %s' % (str_descr) + ', changed state to RUNNING'
    evt.severity = 0
    obj_psus.powerSupplyState = 'Running'
    commit()
   elif int_state == 6 :
    # Down state
    evt.severity = 5
    evt.summary = 'PSU %s' % (str_descr) + ', changed state to DOWN'
    obj_psus.powerSupplyState = 'Down'
    commit()
   else:
    # Unknown/undocumented state
    evt.severity = 5
    evt.summary = 'PSU %s' % (str_descr) + ', changed state to UNKNOWN (state %s' % (int_state) + ')'
/usr/local/www/vhost/www.fuhell.com/data/pages/scripts/zenoss_transforms/jnxpowersupplyfailure.trap.txt · Last modified: 2015/02/11 20:29 by Thomas York