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' : 'editEventView',
     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, REQUEST=None):
     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, REQUEST)
     88          if self._selectedTabName(templateName, REQUEST).endswith("Events"):
     89              tabs[0]['selected']=True
     90          # if we don't have any global roles take away edit tab
     91          if self.hasNoGlobalRoles():
     92              return [tabs[0]]
     93          return tabs
     94
     95
     96 -    def breadCrumbs(self, terminator='dmd'):
     97          """Return the breadcrumb links for this object add CustomViews list.
     98          [('url','id'), ...]
     99          """
    100          crumbs = super(CustomEventView, self).breadCrumbs(terminator)
    101          url = aq_parent(self).absolute_url_path() + "/editEventViews"
    102          crumbs.insert(-1,(url,'Event Views'))
    103          return crumbs
    104
    105
    106 -    def getEventViewURL(self):
    107          """Return the url for the default screen for this custom view.
    108          """
    109          tpl = 'viewEvents' if self.type == "status" else 'viewHistoryEvents'
    110          return '%s/%s' % (self.absolute_url_path(), tpl)
    111
    112
    113 -    def getEventView(self):
    114          """Return the default screen for this custom view.
    115          """
    116          self.REQUEST.response.redirect(self.getEventViewURL())
    117
    118
    119 -    def getEventPill(self, number=5):
    120          """
    121          Get the event pill for this event view.
    122          """
    123          from Products.ZenEvents.browser.EventPillsAndSummaries import getEventPill
    124          return getEventPill(self.getEventManager(), self.getWhere(), number,
    125                              url=self.getEventViewURL())
    126
    127
    128 -    def getEventManager(self):
    129          """Return the current event manager for this object.
    130          """
    131          if self.type == "status":
    132              return self.ZenEventManager
    133          else:
    134              return self.ZenEventHistory
    135
    136
    137 -    def getResultFields(self):
    138          if self.resultFields:
    139              return self.resultFields
    140          return self.getEventManager().defaultResultFields
    141
    142
    143 -    def getWhere(self):
    144          if self.where:
    145              return self.where
    146          return self.getEventManager().defaultWhere
    147
    148
    149 -    def getOrderBy(self):
    150          if self.orderby:
    151              return self.orderby
    152          return self.getEventManager().defaultOrderby
    153
    154
    155 -    def getEventSummary(self, severity=1, state=1):
    156          """Return the current event summary for this custom view.
    157          """
    158          zem = self.getEventManager()
    159          return zem.getEventSummary(self.getWhere(),severity,state)
    160
    161
    162 -    def getEventList(self, **kwargs):
    163          """Return the current event list for this custom view.
    164          """
    165          zem = self.getEventManager()
    166          return zem.getEventList(self.getResultFields(),
    167                                  self.getWhere(),
    168                                  self.getOrderBy(),
    169                                  **kwargs)
    170      getEventHistoryList = getEventList
    171
    172
    173 -    def getEventDetailFromStatusOrHistory(self, evid=None,
    174                                              dedupid=None, better=False):
    175          """
    176          Return the event detail for an event within the context of a device
    177          or other device organizer
    178          """
    179          evt = self.getEventManager().getEventDetailFromStatusOrHistory(
    180                                          evid, dedupid, better)
    181          return evt.__of__(self)
    182
    183
    184 -    def convertEventField(self, field, value, default=""):
    185          return self.getEventManager().convertEventField(field, value, default)
    186
    187
    188      security.declareProtected('Manage Events','manage_addLogMessage')
    189 -    def manage_addLogMessage(self, evid=None, message='', REQUEST=None):
    190          """
    191          Add a log message to an event
    192          """
    193          self.getEventManager().manage_addLogMessage(evid, message)
    194          if REQUEST: return self.callZenScreen(REQUEST)
    195
    196
    197      security.declareProtected('Manage Events','manage_deleteEvents')
    198 -    def manage_deleteEvents(self, evids=(), REQUEST=None):
    199          """Delete events form this managed entity.
    200          """
    201          # If we pass REQUEST in to the getEventManager().manage_deleteEvents()
    202          # call we don't get a proper refresh of the event console.  It only
    203          # works if self.callZenScreen() is called from here rather than down
    204          # in the event manager.  I'm not sure why.  Using FakeResult to fetch
    205          # the message seems like best workaround for now.
    206          request = FakeRequest()
    207          self.getEventManager().manage_deleteEvents(evids, request)
    208          if REQUEST:
    209              request.setMessage(REQUEST)
    210              return self.callZenScreen(REQUEST)
    211
    212
    213      security.declareProtected('Manage Events','manage_deleteHeartbeat')
    214 -    def manage_deleteHeartbeat(self, REQUEST=None):
    215          """Delete events form this managed entity.
    216          """
    217          dev = self.device()
    218          if dev:
    219              return self.getEventManager().manage_deleteHeartbeat(dev.id, REQUEST)
    220          if REQUEST:
    221              return self.callZenScreen(REQUEST)
    222
    223
    224      security.declareProtected('Manage Events','manage_ackEvents')
    225 -    def manage_ackEvents(self, evids=(), REQUEST=None):
    226          """Set event state form this managed entity.
    227          """
    228          return self.getEventManager().manage_ackEvents(evids, REQUEST)
    229
    230
    231      security.declareProtected('Manage Events','manage_setEventStates')
    232 -    def manage_setEventStates(self, eventState=None, evids=(), REQUEST=None):
    233          """Set event state form this managed entity.
    234          """
    235          return self.getEventManager().manage_setEventStates(
    236                                                  eventState, evids, REQUEST)
    237
    238
    239      security.declareProtected('Manage Events','manage_createEventMap')
    240 -    def manage_createEventMap(self, eventClass=None, evids=(), REQUEST=None):
    241          """Create an event map from an event or list of events.
    242          """
    243          screen = self.getEventManager().manage_createEventMap(
    244                                        eventClass, evids, REQUEST)
    245          if REQUEST:
    246              if screen: return screen
    247              return self.callZenScreen(REQUEST)
    248
    249
    250      security.declareProtected('Change Settings', 'manage_editEventView')
    251 -    def manage_editEventView(self, REQUEST=None):
    252          """Update user settings.
    253          """
    254          import WhereClause
    255          if REQUEST and not REQUEST.form.has_key('where'):
    256              clause = WhereClause.fromFormVariables(self.genMeta(), REQUEST.form)
    257              if clause:
    258                  REQUEST.form['where'] = clause
    259          return self.zmanage_editProperties(REQUEST)
    260
    261
    262      security.declareProtected('Manage Events','manage_deleteBatchEvents')
    263 -    def manage_deleteBatchEvents(self, selectstatus='none', goodevids=[],
    264                                      badevids=[], filter='',
    265                                      offset=0, count=50, fields=[],
    266                                      getTotalCount=True,
    267                                      startdate=None, enddate=None,
    268                                      severity=2, state=1, orderby='',
    269                                      REQUEST=None, **kwargs):
    270          """Delete events form this managed entity.
    271          """
    272          unused(count)
    273          evids = self.getEventManager().getEventBatchME(self.dmd.Events,
    274                                              where=self.getWhere(),
    275                                              selectstatus=selectstatus,
    276                                              goodevids=goodevids,
    277                                              badevids=badevids,
    278                                              filter=filter,
    279                                              offset=offset, fields=fields,
    280                                              getTotalCount=getTotalCount,
    281                                              startdate=startdate,
    282                                              enddate=enddate, severity=severity,
    283                                              state=state, orderby=orderby,
    284                                              **kwargs)
    285          request = FakeRequest()
    286          self.manage_deleteEvents(evids, request)
    287          return request.get('message', '')
    288
    289 -    def manage_undeleteEvents(self, evids=(), REQUEST=None):
    290          """Delete events form this managed entity.
    291          """
    292          request = FakeRequest()
    293          self.getEventManager().manage_undeleteEvents(evids, request)
    294          if REQUEST:
    295              request.setMessage(REQUEST)
    296              return self.callZenScreen(REQUEST)
    297
    298
    299      #security.declareProtected('Manage Events','manage_undeleteBatchEvents')
    300 -    def manage_undeleteBatchEvents(self, selectstatus='none', goodevids=[],
    301                                      badevids=[], filter='',
    302                                      offset=0, count=50, fields=[],
    303                                      getTotalCount=True,
    304                                      startdate=None, enddate=None,
    305                                      severity=2, state=1, orderby='',
    306                                      REQUEST=None, **kwargs):
    307          """Delete events form this managed entity.
    308          Only called from event console, so uses FakeRequest to avoid
    309          page rendering.
    310          """
    311          unused(count)
    312          evids = self.ZenEventHistory.getEventBatchME(self.dmd.Events,
    313                                              where=self.getWhere(),
    314                                              selectstatus=selectstatus,
    315                                              goodevids=goodevids,
    316                                              badevids=badevids,
    317                                              filter=filter,
    318                                              offset=offset, fields=fields,
    319                                              getTotalCount=getTotalCount,
    320                                              startdate=startdate,
    321                                              enddate=enddate, severity=severity,
    322                                              state=state, orderby=orderby,
    323                                              **kwargs)
    324          request = FakeRequest()
    325          self.manage_undeleteEvents(evids, request)
    326          return request.get('message', '')
    327
    328
    329      security.declareProtected('Manage Events','manage_ackBatchEvents')
    330 -    def manage_ackBatchEvents(self, selectstatus='none', goodevids=[],
    331                                      badevids=[], filter='',
    332                                      offset=0, count=50, fields=[],
    333                                      getTotalCount=True,
    334                                      startdate=None, enddate=None,
    335                                      severity=2, state=1, orderby='',
    336                                      REQUEST=None, **kwargs):
    337          """Delete events form this managed entity.
    338          Only called from event console, so uses FakeRequest to avoid
    339          page rendering.
    340          """
    341          unused(count)
    342          evids = self.getEventManager().getEventBatchME(self.dmd.Events,
    343                                              where=self.getWhere(),
    344                                              selectstatus=selectstatus,
    345                                              goodevids=goodevids,
    346                                              badevids=badevids,
    347                                              filter=filter,
    348                                              offset=offset, fields=fields,
    349                                              getTotalCount=getTotalCount,
    350                                              startdate=startdate,
    351                                              enddate=enddate, severity=severity,
    352                                              state=state, orderby=orderby,
    353                                              **kwargs)
    354          request = FakeRequest()
    355          self.manage_ackEvents(evids, request)
    356          return request.get('message', '')
    357
    358
    359  InitializeClass(CustomEventView)
    360