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