TECHZEN Zenoss User Community ARCHIVE  

Zenoss 4.2.5 - updating component property from a trap event class mapping trans ...

Subject: Zenoss 4.2.5 - updating component property from a trap event class mapping transform
Author: Pheripheral Pheripheral
Posted: 2019-01-28 12:47

Hi,

I've previously successfully had a transform on an event class mapping transform update a device property when the trap arrives.
For example, a trap indicating that the device outputSource has changed value will update the outputSource property on the device object in the database.  This works ok with a transform along the lines of :


if device.outputSource != sourceFromEvent:
    @transact
    def updateDb():
        device.outputSource=sourceFromEvent
    updateDb()

However, I'm now attempting to do a very similar task but instead of updating a device property i want to update a component property of one of many components of a devices (e.g. a device contains several sensors and the trap is indicating that one of the sensors has been activated).

My first issue is that I need to map the trap to the specific component on the device and I think I've succeeded in doing this by reading the mib specific field that tells me what sensor component it is and setting this as the evt.component, as follows:

evt.component=evt.mibSpecificEventFieldSensorName

this field exactly matches the title given to the component during modelling and this seems to successfully map to the component as my trap event appears on the component in zenoss and the component field in the trap event details is a working hyperlink to the component on the device. So far so good i thought.

however, my issue arises once i try and update a property on the component in a similar way to as i did for device, as follows:

if component.sensorValue!= valueFromEvent:
    @transact
    def updateDb():
        component.sensorValue=valueFromEvent
    updateDb()

This fails with errors in the zeneventd.log file

Problem on line 3: AttributeError: 'NoneType' object has no attribute 'sensorValue'
if component.sensorValue != valueFromEvent

This is where i'm stuck.
I've used very similar code in an event class transform triggered from a threshold on snmp polling. This used the exact same component.sensorValue type line to successfully set properties on components.

So i think it must be something to do with the fact that i'm setting the component of the event in my transform, rather than zenoss setting it when it triggers the event from the threshold etc... but I can't work out how to achieve the same thing in my trap triggered event class mapping for components.

Any help appreciated as i'm sure it must be achievable!

Thanks
Dafydd


------------------------------
Pheripheral Pheripheral
------------------------------


Subject: RE: Zenoss 4.2.5 - updating component property from a trap event class mapping transform
Author: Pheripheral Pheripheral
Posted: 2019-01-29 05:58

Update

I've made this work (amazing what a nights sleep can do ...)

I'm now grabbing the list of components from the device object and looping through to match a component against the one the trap is raised on and then updating that component.

# set component from trap event attribute
evt.component=evt.mibSpecificEventFieldSensorName

SENSOR_ACTIVE = 1

# find matching sensor from device sensors
for sensor in device.sensors():
    if sensor.title == evt.component:
        # if the status changed then update sensor Component
        if sensor.sensorValue != SENSOR_ACTIVE:
            @transact
            def updateDb():
                sensor.sensorValue=SENSOR_ACTIVE
            updateDb()

This works and sets my property on the component.

If anyone knows of a way to grab this without looping the components do let me know, but in the meantime this works and as i'm only expecting around 4 or 5 components on the device it shouldn't east computing resources.

------------------------------
Pheripheral Pheripheral
------------------------------


Subject: RE: Zenoss 4.2.5 - updating component property from a trap event class mapping transform
Author: Ryan Matte
Posted: 2019-02-21 11:21

The reason you were running in to the error you were seeing is because an event without a component was hitting your transform and you weren't checking for the existence of component before proceeding with the rest of your code.  A simple "if component:" at the top of that code would have fixed that.

------------------------------
Ryan Matte
------------------------------


< Previous
Monitor change of datapoint
  Next
Unable to add a Hub or Collector
>