简体   繁体   English

如何在Zenoss映射中导入DMD?

[英]How do I import DMD in Zenoss mapping?

I have Solaris 10 + Zenoss 2.7.0 and I cannot upgrade it without Oracle licence, so I try to find workaround, that's why I ask for your help. 我有Solaris 10 + Zenoss 2.7.0 ,没有Oracle许可证我无法升级它,所以我尝试寻找解决方法,这就是为什么我寻求您的帮助。

I need to prevent the movement of events into History Table , for any event from the same device recieved during the last 5 minutes and then drop event if the count is more then 5. 对于最近5分钟内收到的来自同一设备的任何事件,我需要防止将事件移入“ 历史记录表” ,如果计数大于5,则丢弃事件。

That's what I try to do (mapping is placed in /Unknown/linkUp ) 那就是我想要做的(映射位于/ Unknown / linkUp中

try:
    import Globals
    import sys
    from Products.ZenUtils.ZenScriptBase import ZenScriptBase
except Exception as error:
    logging.error('ApplyTestZSB. Cannot import ZenScriptBase: %s\n' % error)
    sys.exit(1)

dmd = None

try:
    dmd = ZenScriptBase(connect=True).dmd
except Exception as error:
    logging.error(
        'ApplyTestDMD. Connection to zenoss dmd failed: %s\n' % error)
    sys.exit(1)

ourMessage = str(getattr(evt, "message"))
ourDevice = str(evt.device)
ourLastTime = float(evt.lastTime)
old_elements = 0

if evt.device and evt.component and evt.eventClass and evt.eventKey:
    ourDedupId = '|'.join(
        [evt.device, evt.component, evt.eventClass, evt.eventKey, ''])

for event in dmd.ZenEventManager.getEventList():
    if (event.lastTime > ourLastTime - 301) and \
        ((ourDedupId in str(event.dedupid) and event.severity > 0) or
         (ourMessage == event.message and ourDevice == event.device)):
        old_elements += event.count

if old_elements > 4:
    evt._action = 'drop'

And I have this error in zenhub.log: 我在zenhub.log中有此错误:

2013-06-15 21:21:11 ERROR zen.Events: Error transforming EventClassInst linkUp (1)
2013-06-15 21:21:20 ERROR root: ApplyTestDMD. Connection to zenoss dmd failed: 2

2013-06-15 21:21:20 ERROR zen.Events: Error transforming EventClassInst linkUp (1)
2013-06-15 21:21:24 ERROR root: ApplyTestDMD. Connection to zenoss dmd failed: 2

2013-06-15 21:21:24 ERROR zen.Events: Error transforming EventClassInst linkUp (1)
2013-06-15 21:21:28 ERROR root: ApplyTestDMD. Connection to zenoss dmd failed: 2

2013-06-15 21:21:28 ERROR zen.Events: Error transforming EventClassInst linkUp (1)

Remove dmd entirely from your script, it is already defined in locals() during the execution of your event transform. 从事件脚本中完全删除dmd,它已在执行事件转换期间在locals()中定义。 There is no need to define it yourself, just like evt is already defined. 不需要自己定义它,就像已经定义了evt一样。

To see for yourself, define the following one line event transform, and then use the Event Console add button to add a new event for the Event Class you just created the transform for, to quickly test: 要亲自查看,请定义以下一行事件转换,然后使用“事件控制台”添加按钮为刚刚为其创建转换的事件类添加新事件,以进行快速测试:

evt.summary = str('dmd' in locals()) evt.summary = str(locals()中的'dmd')

You should see a True placed into your event's summary, meaning dmd is already defined, and ready for use :) 您应该在事件的摘要中看到一个True,表示dmd已经定义好,可以使用了:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM