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', '']。