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

Source Code for Module Products.ZenEvents.EventFilter

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