Zenoss 事件内容修改正则表达式
因为事件的内容过于复杂,查看不是很方便,且公司短信报警有字数限制。ide
但愿将相似threshold of cpuidle-w exceeded: current value 172.14的事件内容修改成CPU: 56.97% usedui
事件:cpuidle 事件目录 /perf/testorm
代码:对象
import re //导入正则表达式模块blog
m = re.search("threshold of [^:]+: current value ([\d\.]+)", evt.message) //匹配事件内容事件
currentValue = 1 - float(m.groups()[0]) / 4 //匹配对象 因为对象的值是4核CPU值,因此作了个计算ip
evt.summary = "CPU: %3.2f%% used" % currentValue //EVENT面板调用的是evt.summary 赋值。get
evt.message = evt.summary //某些事件也会用到message对象 也赋值吧。it
这只是初步的判断,还能够更深刻根据componet,ip,device来进行判断
代码添加方式:
Events-à Eventsclass -> 须要修改事件信息的目录(/perf/test) -> Transform
贴入代码 : save
友情提醒:
切莫到 http://XXXX:8080/zport/dmd/Events/manage 中进行代码添加。
在zodb库中添加,会出现转换
['import re\n
m = re.search("threshold of [^:]+: current value ([\\d\\.]+)", evt.message)\n
currentValue = 100 - float(m.groups()[0]) / 4\nevt.summary = "CPU: %3.2f%% used" % currentValue\n
evt.message = evt.summary', '']。