Package ZenEvents :: Module EventFilter
[hide private]
[frames] | no frames]

Source Code for Module ZenEvents.EventFilter

  1  ########################################################################### 
  2  # 
  3  # This program is part of Zenoss Core, an open source monitoring platform. 
  4  # Copyright (C) 2007, Zenoss Inc. 
  5  # 
  6  # This program is free software; you can redistribute it and/or modify it 
  7  # under the terms of the GNU General Public License version 2 as published by 
  8  # the Free Software Foundation. 
  9  # 
 10  # For complete information please visit: http://www.zenoss.com/oss/ 
 11  # 
 12  ########################################################################### 
 13   
 14  from AccessControl import ClassSecurityInfo 
 15  from Globals import InitializeClass 
 16   
17 -class EventFilter(object):
18 "Mix-in for objects that query events" 19 20 where = None 21 formName = 'actionRule' 22 23 security = ClassSecurityInfo() 24
25 - def getQueryElements(self):
26 s = self.genMeta().items() 27 s.sort() 28 result = ['<option/>'] 29 for name, attrType in s: 30 result.append('<option value="%s">%s</option>' % 31 (name, attrType.label)) 32 return '\n'.join(result)
33
35 s = self.genMeta().items() 36 s.sort() 37 result = [] 38 for name, attrType in s: 39 result.append(' %s\n' % attrType.genProperties(name)) 40 result = ['var properties={' + ',\n'.join(result) + '};\n'] 41 result.append((Modes + 'var current = %s \n') % 42 self._whereClauseAsJavaScript()) 43 result.append('initializeFilters(current)\n') 44 return ''.join(result)
45
46 - def genMeta(self):
47 from WhereClause import Text, Select, Compare, Enumerated, DeviceGroup 48 from WhereClause import EventClass 49 from EventManagerBase import EventManagerBase 50 kw = {} 51 def addDevices(name, label, column): 52 devices = self.dmd.getDmdRoot(name).getOrganizerNames() 53 kw[column] = DeviceGroup(label, devices)
54 addDevices('Systems', 'Systems', 'systems') 55 addDevices('Groups', 'Device Groups', 'deviceGroups') 56 esconv = [(b, a) for a, b in EventManagerBase.eventStateConversions] 57 sconv = [(b, a) for a, b in EventManagerBase.severityConversions] 58 pconv = self.getConversions(self.dmd.prodStateConversions) 59 pconv = [(int(b), a) for a, b in pconv] 60 dpconv = self.getConversions(self.dmd.priorityConversions) 61 dpconv = [(int(b), a) for a, b in dpconv] 62 owners = [(n, n) for n in self.dmd.ZenUsers.getAllUserSettingsNames()] 63 eventClasses = [(n, n) for n in self.dmd.Events.getOrganizerNames()] 64 deviceClasses = [(n, n) for n in self.dmd.Devices.getOrganizerNames()] 65 return dict( 66 eventClass=EventClass('Event Class', eventClasses), 67 deviceClass=EventClass('Device Class', deviceClasses), 68 summary=Text("Summary"), 69 location=Text("Location"), 70 prodState=Enumerated("Production State",pconv), 71 severity=Enumerated("Severity",sconv), 72 eventState=Enumerated("Event State",esconv), 73 device=Text("Device"), 74 devicePriority=Enumerated("Device Priority",dpconv), 75 eventClassKey=Text("Event Class Key"), 76 count=Compare("Count"), 77 manager=Text("Manager"), 78 agent=Select("Agent",[(x, x) for x in 79 "zenhub", "zenping", "zensyslog", "zenactions", "zentrap", 80 "zenmodeler", "zenperfsnmp", "zencommand", "zenprocess", "zenwin", 81 "zeneventlog"]), 82 facility=Select("Facility",[ 83 "auth","authpriv","cron","daemon","kern","lpr","mail", 84 "mark","news","security","syslog","user","uucp", 85 "local0","local1","local2","local3","local4", 86 "local05","local6","local7"]), 87 priority=Select("Priority",[ 88 "debug","info","notice","warning","error","critical", 89 "alert","emergency"]), 90 component=Text("Component"), 91 message=Text("Message"), 92 ntevid=Text("ntevid"), 93 ipAddress=Text("IP Address"), 94 ownerId=Select("Owner Id", owners), 95 **kw)
96
97 - def getWhere(self):
98 return self.where
99
100 - def _whereClauseAsJavaScript(self):
101 import WhereClause 102 return WhereClause.toJavaScript(self.genMeta(), self.getWhere())
103 104 Modes = """ 105 var modes = { 106 text:[{text:"contains",value:"~"}, 107 {text:"does not contain",value:"!~"}, 108 {text:"begins with",value:"^"}, 109 {text:"ends with",value:"$"}, 110 {text:"is",value:""}, 111 {text:"is not",value:"!"}], 112 evtClass:[{text:"begins with",value:"^"}, 113 {text:"does not begin with",value:"!^"}, 114 {text:"is",value:""}, 115 {text:"is not",value:"!"}], 116 select:[{text:"is",value:""}, 117 {text:"is not",value:"!"}], 118 compare:[{text:"<",value:"<"}, 119 {text:"<=",value:"<="}, 120 {text:"=",value:"="}, 121 {text:">",value:">"}, 122 {text:">=",value:">="}], 123 cselect:[{text:"<",value:"<"}, 124 {text:"<=",value:"<="}, 125 {text:"=",value:"="}, 126 {text:">",value:">"}, 127 {text:">=",value:">="}]}; 128 """ 129 130 InitializeClass(EventFilter) 131