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

# Source Code for Module Products.ZenEvents.EventCommand

      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  from AccessControl import ClassSecurityInfo
     15  from Acquisition import aq_parent
     16  from Products.ZenModel.ZenModelRM import ZenModelRM
     17  from Products.ZenModel.Commandable import Commandable
     18  from Products.ZenModel.ZenPackable import ZenPackable
     19  from Products.ZenRelations.RelSchema import *
     20  from Globals import InitializeClass
     21  from EventFilter import EventFilter
     22
     23 -class EventCommand(ZenModelRM, Commandable, EventFilter, ZenPackable):
     24
     25      where = ''
     26      command = ''
     27      clearCommand = ''
     28      enabled = False
     29      delay = 0
     30      repeatTime = 0
     31
     32      _properties = ZenModelRM._properties + (
     33          {'id':'command', 'type':'string', 'mode':'w'},
     34          {'id':'clearCommand', 'type':'string', 'mode':'w'},
     35          {'id':'where', 'type':'string', 'mode':'w'},
     36          {'id':'defaultTimeout', 'type':'int', 'mode':'w'},
     37          {'id':'enabled', 'type':'boolean', 'mode':'w'},
     38          {'id':'delay', 'type':'int', 'mode':'w'},
     39          {'id':'repeatTime', 'type':'int', 'mode':'w'},
     40      )
     41
     42      _relations =  ZenPackable._relations + (
     43          ("eventManager", ToOne(ToManyCont, "Products.ZenEvents.EventManagerBase", "commands")),
     44      )
     45
     46      factory_type_information = (
     47          {
     48              'immediate_view' : 'editEventCommand',
     49              'actions'        :
     50              (
     51                  { 'id'            : 'edit'
     52                  , 'name'          : 'Edit'
     53                  , 'action'        : 'editEventCommand'
     54                  , 'permissions'   : ( "Manage DMD", )
     55                  },
     56              )
     57            },
     58          )
     59
     60      security = ClassSecurityInfo()
     61
     62 -    def getEventFields(self):
     63          return self.eventManager.getFieldList()
     64
     65 -    def getUserid(self):
     66          return ''
     67
     68 -    def breadCrumbs(self, terminator='dmd'):
     69          """Return the breadcrumb links for this object add ActionRules list.
     70          [('url','id'), ...]
     71          """
     72          crumbs = super(EventCommand, self).breadCrumbs(terminator)
     73          url = aq_parent(self).absolute_url_path() + "/listEventCommands"
     74          crumbs.insert(-1,(url,'Event Commands'))
     75          return crumbs
     76
     77
     78 -    def sqlwhere(self):
     79          """Return sql where to select alert_state data for this event.
     80          """
     81          return "userid = '' and rule = '%s'" % (self.id)
     82
     83 -    def _clearAlertState(self):
     84          """Clear state in alert_state before we are deleted.
     85          """
     86          zem = self.dmd.ZenEventManager
     87          conn = zem.connect()
     88          try:
     89              delcmd = "delete from alert_state where %s" % self.sqlwhere()
     90              curs = conn.cursor()
     91              curs.execute(delcmd)
     92          finally: zem.close(conn)
     93
     94
     95      security.declareProtected('Manage EventManager', 'manage_editEventCommand')
     96 -    def manage_editEventCommand(self, REQUEST=None):
     97          "edit the commands run when events match"
     98          import WhereClause
     99          if REQUEST and not REQUEST.form.has_key('where'):
    100              clause = WhereClause.fromFormVariables(self.genMeta(), REQUEST.form)
    101              if clause:
    102                  REQUEST.form['where'] = clause
    103          return self.zmanage_editProperties(REQUEST)
    104
    105
    106  InitializeClass(EventCommand)
    107