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

# Source Code for Module Products.ZenEvents.CustomEventView

      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  import logging
     15  log = logging.getLogger("zen.EventView")
     16
     17  from Globals import DTMLFile, InitializeClass
     18  from AccessControl import ClassSecurityInfo
     19  from Acquisition import aq_parent
     20  from zope.interface import implements
     21
     22  from Products.ZenModel.ZenModelRM import ZenModelRM
     23  from Products.ZenEvents.EventFilter import EventFilter
     24  from Products.ZenModel.EventView import IEventView
     25  from Products.ZenUtils.FakeRequest import FakeRequest
     26
     27  from Products.ZenUtils.Utils import unused
     28
     29 -def manage_addCustomEventView(context, id, REQUEST=None):
     30      """Create an aciton rule"""
     31      ed = CustomEventView(id)
     32      context._setObject(id, ed)
     33      if REQUEST is not None:
     34          REQUEST['RESPONSE'].redirect(context.absolute_url() + '/manage_main')
     35
     36  addCustomEventView = DTMLFile('dtml/addCustomEventView',globals())
     37
     38  __pychecker__='no-argsused no-varargsused'
     39
     40 -class CustomEventView(ZenModelRM, EventFilter):
     41
     42      implements(IEventView)
     43
     44      meta_type = "CustomEventView"
     45
     46      type = "status"
     47      evtypes = ("status", "history")
     48      orderby = ""
     49      where = ""
     50      resultFields = ()
     51
     52      _properties = ZenModelRM._properties + (
     53          {'id':'type', 'type':'selection',
     54              'select_variable':'evtypes', 'mode':'w'},
     55          {'id':'orderby', 'type':'string', 'mode':'w'},
     56          {'id':'where', 'type':'text', 'mode':'w'},
     57          {'id':'resultFields', 'type':'lines', 'mode':'w'},
     58      )
     59
     60      factory_type_information = (
     61          {
     62              'immediate_view' : 'getEventView',
     63              'actions'        :
     64              (
     65                  { 'id'            : 'view'
     66                  , 'name'          : 'View'
     67                  , 'action'        : 'getEventView'
     68                  , 'permissions'   : ("View",)
     69                  },
     70                  { 'id'            : 'edit'
     71                  , 'name'          : 'Edit'
     72                  , 'action'        : 'editEventView'
     73                  , 'permissions'   : ("Change Settings",)
     74                  },
     75              )
     76           },
     77          )
     78
     79      security = ClassSecurityInfo()
     80
     81
     82      security.declareProtected('View', 'zentinelTabs')
     83 -    def zentinelTabs(self, templateName):
     84          """Return a list of hashs that define the screen tabs for this object.
     85          [{'name':'Name','action':'template','selected':False},...]
     86          """
     87          tabs = super(CustomEventView, self).zentinelTabs(templateName)
     88          if templateName.endswith("Events"): tabs[0]['selected']=True
     89          # if we don't have any global roles take away edit tab
     90          if self.hasNoGlobalRoles():
     91              return [tabs[0]]
     92          return tabs
     93
     94
     95 -    def breadCrumbs(self, terminator='dmd'):
     96          """Return the breadcrumb links for this object add CustomViews list.
     97          [('url','id'), ...]
     98          """
     99          crumbs = super(CustomEventView, self).breadCrumbs(terminator)
    100          url = aq_parent(self).absolute_url_path() + "/editEventViews"
    101          crumbs.insert(-1,(url,'Event Views'))
    102          return crumbs
    103
    104
    105 -    def getEventView(self):
    106          """Return the default screen for this custom view.
    107          """
    108          if self.type == "status":
    109              tpl = 'viewEvents'
    110          else:
    111              tpl = 'viewHistoryEvents'
    112          url = '%s/%s' % (self.absolute_url_path(), tpl)
    113          self.REQUEST.response.redirect(url)
    114
    115
    116 -    def getEventManager(self):
    117          """Return the current event manager for this object.
    118          """
    119          if self.type == "status":
    120              return self.ZenEventManager
    121          else:
    122              return self.ZenEventHistory
    123
    124
    125 -    def getResultFields(self):
    126          if self.resultFields:
    127              return self.resultFields
    128          return self.getEventManager().defaultResultFields
    129
    130
    131 -    def getWhere(self):
    132          if self.where:
    133              return self.where
    134          return self.getEventManager().defaultWhere
    135
    136
    137 -    def getOrderBy(self):
    138          if self.orderby:
    139              return self.orderby
    140          return self.getEventManager().defaultOrderby
    141
    142
    143 -    def getEventSummary(self, severity=1, state=1):
    144          """Return the current event summary for this custom view.
    145          """
    146          zem = self.getEventManager()
    147          return zem.getEventSummary(self.getWhere(),severity,state)
    148
    149
    150 -    def getEventList(self, **kwargs):
    151          """Return the current event list for this custom view.
    152          """
    153          zem = self.getEventManager()
    154          return zem.getEventList(self.getResultFields(),
    155                                  self.getWhere(),
    156                                  self.getOrderBy(),
    157                                  **kwargs)
    158      getEventHistoryList = getEventList
    159
    160
    161 -    def getEventDetailFromStatusOrHistory(self, evid=None,
    162                                              dedupid=None, better=False):
    163          """
    164          Return the event detail for an event within the context of a device
    165          or other device organizer
    166          """
    167          evt = self.getEventManager().getEventDetailFromStatusOrHistory(
    168                                          evid, dedupid, better)
    169          return evt.__of__(self)
    170
    171
    172 -    def convertEventField(self, field, value, default=""):
    173          return self.getEventManager().convertEventField(field, value, default)
    174
    175
    176      security.declareProtected('Manage Events','manage_addLogMessage')
    177 -    def manage_addLogMessage(self, evid=None, message='', REQUEST=None):
    178          """
    179          Add a log message to an event
    180          """
    181          self.getEventManager().manage_addLogMessage(evid, message)
    182          if REQUEST: return self.callZenScreen(REQUEST)
    183
    184
    185      security.declareProtected('Manage Events','manage_deleteEvents')
    186 -    def manage_deleteEvents(self, evids=(), REQUEST=None):
    187          """Delete events form this managed entity.
    188          """
    189          # If we pass REQUEST in to the getEventManager().manage_deleteEvents()
    190          # call we don't get a proper refresh of the event console.  It only
    191          # works if self.callZenScreen() is called from here rather than down
    192          # in the event manager.  I'm not sure why.  Using FakeResult to fetch
    193          # the message seems like best workaround for now.
    194          request = FakeRequest()
    195          self.getEventManager().manage_deleteEvents(evids, request)
    196          if REQUEST:
    197              request.setMessage(REQUEST)
    198              return self.callZenScreen(REQUEST)
    199
    200
    201      security.declareProtected('Manage Events','manage_deleteHeartbeat')
    202 -    def manage_deleteHeartbeat(self, REQUEST=None):
    203          """Delete events form this managed entity.
    204          """
    205          dev = self.device()
    206          if dev:
    207              return self.getEventManager().manage_deleteHeartbeat(dev.id, REQUEST)
    208          if REQUEST:
    209              return self.callZenScreen(REQUEST)
    210
    211
    212      security.declareProtected('Manage Events','manage_ackEvents')
    213 -    def manage_ackEvents(self, evids=(), REQUEST=None):
    214          """Set event state form this managed entity.
    215          """
    216          return self.getEventManager().manage_ackEvents(evids, REQUEST)
    217
    218
    219      security.declareProtected('Manage Events','manage_setEventStates')
    220 -    def manage_setEventStates(self, eventState=None, evids=(), REQUEST=None):
    221          """Set event state form this managed entity.
    222          """
    223          return self.getEventManager().manage_setEventStates(
    224                                                  eventState, evids, REQUEST)
    225
    226
    227      security.declareProtected('Manage Events','manage_createEventMap')
    228 -    def manage_createEventMap(self, eventClass=None, evids=(), REQUEST=None):
    229          """Create an event map from an event or list of events.
    230          """
    231          screen = self.getEventManager().manage_createEventMap(
    232                                        eventClass, evids, REQUEST)
    233          if REQUEST:
    234              if screen: return screen
    235              return self.callZenScreen(REQUEST)
    236
    237
    238      security.declareProtected('Change Settings', 'manage_editEventView')
    239 -    def manage_editEventView(self, REQUEST=None):
    240          """Update user settings.
    241          """
    242          import WhereClause
    243          if REQUEST and not REQUEST.form.has_key('where'):
    244              clause = WhereClause.fromFormVariables(self.genMeta(), REQUEST.form)
    245              if clause:
    246                  REQUEST.form['where'] = clause
    247          return self.zmanage_editProperties(REQUEST)
    248
    249
    250      security.declareProtected('Manage Events','manage_deleteBatchEvents')
    251 -    def manage_deleteBatchEvents(self, selectstatus='none', goodevids=[],
    252                                      badevids=[], filter='',
    253                                      offset=0, count=50, fields=[],
    254                                      getTotalCount=True,
    255                                      startdate=None, enddate=None,
    256                                      severity=2, state=1, orderby='',
    257                                      REQUEST=None, **kwargs):
    258          """Delete events form this managed entity.
    259          """
    260          unused(count)
    261          evids = self.getEventManager().getEventBatchME(self.dmd.Events,
    262                                              where=self.getWhere(),
    263                                              selectstatus=selectstatus,
    264                                              goodevids=goodevids,
    265                                              badevids=badevids,
    266                                              filter=filter,
    267                                              offset=offset, fields=fields,
    268                                              getTotalCount=getTotalCount,
    269                                              startdate=startdate,
    270                                              enddate=enddate, severity=severity,
    271                                              state=state, orderby=orderby,
    272                                              **kwargs)
    273          request = FakeRequest()
    274          self.manage_deleteEvents(evids, request)
    275          return request.get('message', '')
    276
    277 -    def manage_undeleteEvents(self, evids=(), REQUEST=None):
    278          """Delete events form this managed entity.
    279          """
    280          request = FakeRequest()
    281          self.getEventManager().manage_undeleteEvents(evids, request)
    282          if REQUEST:
    283              request.setMessage(REQUEST)
    284              return self.callZenScreen(REQUEST)
    285
    286
    287      #security.declareProtected('Manage Events','manage_undeleteBatchEvents')
    288 -    def manage_undeleteBatchEvents(self, selectstatus='none', goodevids=[],
    289                                      badevids=[], filter='',
    290                                      offset=0, count=50, fields=[],
    291                                      getTotalCount=True,
    292                                      startdate=None, enddate=None,
    293                                      severity=2, state=1, orderby='',
    294                                      REQUEST=None, **kwargs):
    295          """Delete events form this managed entity.
    296          Only called from event console, so uses FakeRequest to avoid
    297          page rendering.
    298          """
    299          unused(count)
    300          evids = self.ZenEventHistory.getEventBatchME(self.dmd.Events,
    301                                              where=self.getWhere(),
    302                                              selectstatus=selectstatus,
    303                                              goodevids=goodevids,
    304                                              badevids=badevids,
    305                                              filter=filter,
    306                                              offset=offset, fields=fields,
    307                                              getTotalCount=getTotalCount,
    308                                              startdate=startdate,
    309                                              enddate=enddate, severity=severity,
    310                                              state=state, orderby=orderby,
    311                                              **kwargs)
    312          request = FakeRequest()
    313          self.manage_undeleteEvents(evids, request)
    314          return request.get('message', '')
    315
    316
    317      security.declareProtected('Manage Events','manage_ackBatchEvents')
    318 -    def manage_ackBatchEvents(self, selectstatus='none', goodevids=[],
    319                                      badevids=[], filter='',
    320                                      offset=0, count=50, fields=[],
    321                                      getTotalCount=True,
    322                                      startdate=None, enddate=None,
    323                                      severity=2, state=1, orderby='',
    324                                      REQUEST=None, **kwargs):
    325          """Delete events form this managed entity.
    326          Only called from event console, so uses FakeRequest to avoid
    327          page rendering.
    328          """
    329          unused(count)
    330          evids = self.getEventManager().getEventBatchME(self.dmd.Events,
    331                                              where=self.getWhere(),
    332                                              selectstatus=selectstatus,
    333                                              goodevids=goodevids,
    334                                              badevids=badevids,
    335                                              filter=filter,
    336                                              offset=offset, fields=fields,
    337                                              getTotalCount=getTotalCount,
    338                                              startdate=startdate,
    339                                              enddate=enddate, severity=severity,
    340                                              state=state, orderby=orderby,
    341                                              **kwargs)
    342          request = FakeRequest()
    343          self.manage_ackEvents(evids, request)
    344          return request.get('message', '')
    345
    346
    347  InitializeClass(CustomEventView)
    348