Nov 17, 2009 3:31 PM
productionState in transform
-
Like (0)
I've got a transform which is giving me headaches; basically, if a certain trap comes in I want to move the device to maintenance mode (so that other traps which might be coming or might have arrived can be appropriately ignored - a time delay would be on the alert notification). Eventually I would also fire a clear event that would move it back to production, but the maintenance event is not working anyway:
zone = getattr(evt, 'mtrapargsInteger', 0)
if zone == 1:
evt.component = "block_jumper"
evt.summary = "Zone #1 Fault - Device in Maintenance"
if dev.productionState == 1000:
dev.setProdState(300)
if zone == 2:
evt.component = "AC8"
evt.summary = "AC8 Common Alarm"
According to applyTransform in $ZENOSS/Products/ZenEvents/EventClassInst.py, 'dev' or 'device' should both map to the device which generated the event, and sure enough the reading of dev.productionState works fine (I tested this by checking for it to be 300, then setting it to Maintenance and verifying that it worked then but not while in Production). So the only part which is failing - and silently, from what I can tell in the logs - is the dev.setProdState(300) call.
I'm currently using 2.5.0, but started trying to make this work while running 2.3.x and upgraded last week in hopes this was a bug that had been fixed.
I dont think you can edit the device from a transform, I dont know if it would be called a bug, its just the way it works
Hmph.. considering the device is presented in the transform, I'd think that if you can't edit it that would be a bug. At the very least, an error saying "you can't do that" would've saved me a few days and some layers of skin on my head from all that scratching :>
I'll file this as a bug report and try to replicate it with an event command in the mean time.
Found it.
Set on the path that I'd have to do this as an event command, I started looking to see how I could from the command line effect the changes needed. And I noticed something in the commands listed which looked familiar - a call to "commit()'. It looked familiar because the EventClassInst.py file lists the objects available to a transform, and one of them is "txnCommit" (mapped to transaction.commit).
Sure enough, adding "txnCommit()" to the block commits the change to the device properly and everything works as originally expected. So if there's any bug here, it's that there should probably be a mention of this necessity in the documentation.
I'd add this to the wiki at least.
--
James Pulver
Information Technology Area Supervisor
LEPP Computer Group
Cornell University
srhuston wrote, On 11/19/2009 12:30 AM:
Found it.
Set on the path that I'd have to do this as an event command, I started looking to see how I could from the command line effect the changes needed. And I noticed something in the commands listed which looked familiar - a call to "commit()'. It looked familiar because the EventClassInst.py file lists the objects available to a transform, and one of them is "txnCommit" (mapped to transaction.commit).
Sure enough, adding "txnCommit()" to the block commits the change to the device properly and everything works as originally expected. So if there's any bug here, it's that there should probably be a mention of this necessity in the documentation.
>
I am confused, did you successfully do this in the transform or from an event command?
Either way could you post the code?
In the transform; the only change to the code was adding the txnCommit():
zone = getattr(evt, 'mtrapargsInteger', 0)
if zone == 1:
evt.component = "block_jumper"
evt.summary = "Zone #1 Fault - Device in Maintenance"
if dev.productionState == 1000:
dev.setProdState(300)
txnCommit()
if zone == 2:
evt.component = "AC8"
evt.summary = "AC8 Common Alarm Fault"
My transform is:
import Globals
from Products.ZenUtils.ZenScriptBase import ZenScriptBase
from transaction import commit
dmd = ZenScriptBase(connect=True).dmd
import re
bsnId = getattr(evt, 'bsnAPName', 'Unknown')
evt.summary = 'Wireless Interface is UP on %s' % (bsnId)
for e in dmd.ZenEventManager.getEventList():
cevt = dmd.ZenEventManager.getEventDetailFromStatusOrHistory(e.evid)
cbsnId = getattr(cevt, 'bsnAPName', 'Unknown')
if re.search('Wireless Interface is DOWN', cevt.summary) and re.match(bsnId, cbsnId):
cevt._action = 'history'
txnCommit()
evt.severity = 0
evt._action = 'history'
It should technically work, but it's not, and the only error in zenhub.log is "error 2" which is colossally unhelpful.
[edit - I replied via email, but my reply came in here as blank...]
On 11/20/09 5:08 PM, Ryan Matte wrote:
import re
bsnId = getattr(evt, 'bsnAPName', 'Unknown')
evt.summary = 'Wireless Interface is UP on %s' % (bsnId)
for e in dmd.ZenEventManager.getEventList():
cevt = dmd.ZenEventManager.getEventDetailFromStatusOrHistory(e.evid)
cbsnId = getattr(cevt, 'bsnAPName', 'Unknown')
if re.search('Wireless Interface is DOWN', cevt.summary) and
re.match(bsnId, cbsnId):
cevt._action = 'history'
txnCommit()
evt.severity = 0
evt._action = 'history'
WOW thats cool worked for me, this opens up a new world, I had no idea this is possible
Thanks!!!
I found the fix. dmd in transforms was fixed in 2.5 but I'm still using 2.4.5. I had to do: "zenpatch 14049" then restart Zenoss.
After that, my transform worked fine without the imports.
Follow Us On Twitter »
|
Latest from the Zenoss Blog » | Community | Products | Services Resources | Customers Partners | About Us | ||
Copyright © 2005-2011 Zenoss, Inc.
|
||||||||