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

# Source Code for Module Products.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 or (at your
      8  # option) any later version as published by 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
     34 -    def getWhereClauseAsJavaScript(self):
     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", "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              eventKey=Text("Event Key"),
     92              message=Text("Message"),
     93              ntevid=Text("ntevid"),
     94              ipAddress=Text("IP Address"),
     95              ownerId=Select("Owner Id", owners),
     96              **kw)
     97
     98 -    def getWhere(self):
     99          return self.where
    100
    101 -    def _whereClauseAsJavaScript(self):
    102          import WhereClause
    103          return WhereClause.toJavaScript(self.genMeta(), self.getWhere())
    104
    105  Modes = """
    106   var modes = {
    107     text:[{text:"contains",value:"~"},
    108           {text:"does not contain",value:"!~"},
    109           {text:"begins with",value:"^"},
    110           {text:"ends with",value:"$"},
    111           {text:"is",value:""},
    112           {text:"is not",value:"!"}],
    113     evtClass:[{text:"begins with",value:"^"},
    114               {text:"does not begin with",value:"!^"},
    115               {text:"is",value:""},
    116               {text:"is not",value:"!"}],
    117     select:[{text:"is",value:""},
    118             {text:"is not",value:"!"}],
    119     compare:[{text:"<",value:"<"},
    120              {text:"<=",value:"<="},
    121              {text:"=",value:"="},
    122              {text:">",value:">"},
    123              {text:">=",value:">="}],
    124     cselect:[{text:"<",value:"<"},
    125              {text:"<=",value:"<="},
    126              {text:"=",value:"="},
    127              {text:">",value:">"},
    128              {text:">=",value:">="}]};
    129  """
    130
    131  InitializeClass(EventFilter)
    132