Package Products :: Package ZenModel :: Module EventView |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenModel.EventView

      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  import logging
     14  log = logging.getLogger("zen.EventView")
     15
     16  from _mysql_exceptions import MySQLError
     17
     18  from AccessControl import ClassSecurityInfo
     19  from Globals import InitializeClass
     20  from zope.interface import Interface, implements
     21
     22  from Products.ZenUtils.FakeRequest import FakeRequest
     23  from Products.ZenUtils.Utils import unused
     24
     25 -class IEventView(Interface):
     26      """
     27      Marker interface for objects which have event views.
     28      """
     29
     30 -class EventView(object):
     31
     32      implements(IEventView)
     33
     34      security = ClassSecurityInfo()
     35
     36 -    def getEventManager(self, table='status'):
     37          """Return the current event manager for this object.
     38          """
     39          if table=='history':
     40              return self.ZenEventHistory
     41          return self.ZenEventManager
     42
     43
     44 -    def getEventHistory(self):
     45          """Return the current event history for this object.
     46          """
     47          return self.ZenEventHistory
     48
     49
     50 -    def getStatus(self, statusclass=None, **kwargs):
     51          """Return the status number for this device of class statClass.
     52          """
     53          try:
     54              return self.getEventManager().getStatusME(self, statusclass=statusclass, **kwargs)
     55          except MySQLError:
     56              log.exception("exception getting status")
     57              return -1
     58
     59
     60 -    def getStatusString(self, statclass, **kwargs):
     61          """Return the status number for this device of class statClass.
     62          """
     63          # used to avoid pychecker complaint about wrong # of args to getStatus
     64          f = self.getStatus
     65          return self.convertStatus(f(statclass, **kwargs))
     66
     67
     68 -    def getEventSummary(self, severity=1, state=1, prodState=None):
     69          """Return an event summary list for this managed entity.
     70          """
     71          return self.getEventManager().getEventSummaryME(self, severity, state, prodState)
     72
     73
     74 -    def getEventOwnerList(self, severity=0, state=1):
     75          """Return list of event owners for this mangaed entity.
     76          """
     77          return self.getEventManager().getEventOwnerListME(self, severity, state)
     78
     79
     80 -    def getStatusImgSrc(self, status):
     81          ''' Return the image source for a status number
     82          '''
     83          return self.getEventManager().getStatusImgSrc(status)
     84
     85
     86 -    def getStatusCssClass(self, status):
     87          """Return the css class for a status number.
     88          """
     89          return self.getEventManager().getStatusCssClass(status)
     90
     91
     92 -    def getEventDetail(self, evid=None, dedupid=None, better=False):
     93          """
     94          Return an EventDetail for an event on this object.
     95          """
     96          evt = self.getEventManager().getEventDetail(evid, dedupid, better)
     97          return evt.__of__(self)
     98
     99
    100 -    def getEventDetailFromStatusOrHistory(self, evid=None,
    101                                              dedupid=None, better=False):
    102          """
    103          Return the event detail for an event within the context of a device
    104          or other device organizer
    105          """
    106          evt = self.getEventManager().getEventDetailFromStatusOrHistory(
    107                                          evid, dedupid, better)
    108          return evt.__of__(self)
    109
    110
    111 -    def convertEventField(self, field, value, default=""):
    112          return self.getEventManager().convertEventField(field, value, default)
    113
    114
    115      security.declareProtected('Manage Events','manage_addLogMessage')
    116 -    def manage_addLogMessage(self, evid=None, message='', REQUEST=None):
    117          """
    118          Add a log message to an event
    119          """
    120          self.getEventManager().manage_addLogMessage(evid, message)
    121          if REQUEST: return self.callZenScreen(REQUEST)
    122
    123
    124      security.declareProtected('Manage Events','manage_deleteEvents')
    125 -    def manage_deleteEvents(self, evids=(), REQUEST=None):
    126          """Delete events form this managed entity.
    127          """
    128          # If we pass REQUEST in to the getEventManager().manage_deleteEvents()
    129          # call we don't get a proper refresh of the event console.  It only
    130          # works if self.callZenScreen() is called from here rather than down
    131          # in the event manager.  I'm not sure why.  Using FakeResult to fetch
    132          # the message seems like best workaround for now.
    133          request = FakeRequest()
    134          self.getEventManager().manage_deleteEvents(evids, request)
    135          if REQUEST:
    136              request.setMessage(REQUEST)
    137              return self.callZenScreen(REQUEST)
    138
    139
    140      security.declareProtected('Manage Events','manage_deleteBatchEvents')
    141 -    def manage_deleteBatchEvents(self, selectstatus='none', goodevids=[],
    142                                      badevids=[], filter='',
    143                                      offset=0, count=50, fields=[],
    144                                      getTotalCount=True,
    145                                      startdate=None, enddate=None,
    146                                      severity=2, state=1, orderby='',
    147                                      REQUEST=None, **kwargs):
    148          """Delete events form this managed entity.
    149          """
    150          unused(count)
    151          evids = self.getEventManager().getEventBatchME(self,
    152                                              selectstatus=selectstatus,
    153                                              goodevids=goodevids,
    154                                              badevids=badevids,
    155                                              filter=filter,
    156                                              offset=offset, fields=fields,
    157                                              getTotalCount=getTotalCount,
    158                                              startdate=startdate,
    159                                              enddate=enddate, severity=severity,
    160                                              state=state, orderby=orderby,
    161                                              **kwargs)
    162          request = FakeRequest()
    163          self.manage_deleteEvents(evids, request)
    164          return request.get('message', '')
    165
    166
    167      security.declareProtected('Manage Events','manage_undeleteEvents')
    168 -    def manage_undeleteEvents(self, evids=(), REQUEST=None):
    169          """Delete events form this managed entity.
    170          """
    171          request = FakeRequest()
    172          self.getEventManager().manage_undeleteEvents(evids, request)
    173          if REQUEST:
    174              request.setMessage(REQUEST)
    175              return self.callZenScreen(REQUEST)
    176
    177
    178      #security.declareProtected('Manage Events','manage_undeleteBatchEvents')
    179 -    def manage_undeleteBatchEvents(self, selectstatus='none', goodevids=[],
    180                                      badevids=[], filter='',
    181                                      offset=0, count=50, fields=[],
    182                                      getTotalCount=True,
    183                                      startdate=None, enddate=None,
    184                                      severity=2, state=1, orderby='',
    185                                      REQUEST=None, **kwargs):
    186          """Delete events form this managed entity.
    187          Only called from event console, so uses FakeRequest to avoid
    188          page rendering.
    189          """
    190          unused(count)
    191          evids = self.getEventHistory().getEventBatchME(self,
    192                                              selectstatus=selectstatus,
    193                                              goodevids=goodevids,
    194                                              badevids=badevids,
    195                                              filter=filter,
    196                                              offset=offset, fields=fields,
    197                                              getTotalCount=getTotalCount,
    198                                              startdate=startdate,
    199                                              enddate=enddate, severity=severity,
    200                                              state=state, orderby=orderby,
    201                                              **kwargs)
    202          request = FakeRequest()
    203          self.manage_undeleteEvents(evids, request)
    204          return request.get('message', '')
    205
    206
    207      security.declareProtected('Manage Events','manage_deleteHeartbeat')
    208 -    def manage_deleteHeartbeat(self, REQUEST=None):
    209          """Delete events form this managed entity.
    210          """
    211          dev = self.device()
    212          if dev:
    213              return self.getEventManager().manage_deleteHeartbeat(dev.id, REQUEST)
    214          if REQUEST:
    215              return self.callZenScreen(REQUEST)
    216
    217
    218      security.declareProtected('Manage Events','manage_ackEvents')
    219 -    def manage_ackEvents(self, evids=(), REQUEST=None):
    220          """Set event state form this managed entity.
    221          """
    222          return self.getEventManager().manage_ackEvents(evids, REQUEST)
    223
    224
    225      security.declareProtected('Manage Events','manage_ackBatchEvents')
    226 -    def manage_ackBatchEvents(self, selectstatus='none', goodevids=[],
    227                                      badevids=[], filter='',
    228                                      offset=0, count=50, fields=[],
    229                                      getTotalCount=True,
    230                                      startdate=None, enddate=None,
    231                                      severity=2, state=1, orderby='',
    232                                      REQUEST=None, **kwargs):
    233          """Delete events form this managed entity.
    234          Only called from event console, so uses FakeRequest to avoid
    235          page rendering.
    236          """
    237          unused(count)
    238          evids = self.getEventManager().getEventBatchME(self,
    239                                              selectstatus=selectstatus,
    240                                              goodevids=goodevids,
    241                                              badevids=badevids,
    242                                              filter=filter,
    243                                              offset=offset, fields=fields,
    244                                              getTotalCount=getTotalCount,
    245                                              startdate=startdate,
    246                                              enddate=enddate, severity=severity,
    247                                              state=state, orderby=orderby,
    248                                              **kwargs)
    249          request = FakeRequest()
    250          self.manage_ackEvents(evids, request)
    251          return request.get('message', '')
    252
    253
    254      security.declareProtected('Manage Events','manage_setEventStates')
    255 -    def manage_setEventStates(self, eventState=None, evids=(), REQUEST=None):
    256          """Set event state form this managed entity.
    257          """
    258          return self.getEventManager().manage_setEventStates(
    259                                                  eventState, evids, REQUEST)
    260
    261
    262      security.declareProtected('Manage Events','manage_createEventMap')
    263 -    def manage_createEventMap(self, eventClass=None, evids=(),
    264                                table='status', REQUEST=None):
    265          """Create an event map from an event or list of events.
    266          """
    267          screen = self.getEventManager(table).manage_createEventMap(
    268                                        eventClass, evids, REQUEST)
    269          if REQUEST:
    270              if screen: return screen
    271              return self.callZenScreen(REQUEST)
    272
    273
    274  InitializeClass(EventView)
    275