gpt4 book ai didi

python - 如何在 Zenoss 映射中导入 DMD?

转载 作者:行者123 更新时间:2023-11-29 13:47:58 24 4
gpt4 key购买 nike

我有 Solaris 10 + Zenoss 2.7.0,如果没有 Oracle 许可证,我无法升级它,因此我尝试寻找解决方法,这就是我请求您帮助的原因。

对于过去 5 分钟内收到的来自同一设备的任何事件,我需要防止事件移动到历史表中,然后如果计数超过 5,则删除事件。

这就是我尝试做的(映射放置在 /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'

我在 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)

最佳答案

从脚本中完全删除 dmd,它已在执行事件转换期间在 locals() 中定义。不需要自己定义,就像evt已经定义了一样。

要亲自查看,请定义以下一行事件转换,然后使用事件控制台添加按钮为刚刚为其创建转换的事件类添加新事件,以快速测试:

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

您应该会看到事件摘要中出现 True,这意味着 dmd 已定义并可供使用:)

关于python - 如何在 Zenoss 映射中导入 DMD?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17126119/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com