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

Source Code for Module 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 manage_beforeDelete(self, item, container):
79 """Clear state in alert_state before we are deleted. 80 """ 81 self._clearAlertState()
82 83
84 - def sqlwhere(self):
85 """Return sql where to select alert_state data for this event. 86 """ 87 return "userid = '' and rule = '%s'" % (self.id)
88
89 - def _clearAlertState(self):
90 """Clear state in alert_state before we are deleted. 91 """ 92 zem = self.dmd.ZenEventManager 93 conn = zem.connect() 94 try: 95 delcmd = "delete from alert_state where %s" % self.sqlwhere() 96 curs = conn.cursor() 97 curs.execute(delcmd) 98 finally: zem.close(conn)
99 100 101 security.declareProtected('Manage EventManager', 'manage_editEventCommand')
102 - def manage_editEventCommand(self, REQUEST=None):
103 "edit the commands run when events match" 104 import WhereClause 105 if REQUEST and not REQUEST.form.has_key('where'): 106 clause = WhereClause.fromFormVariables(self.genMeta(), REQUEST.form) 107 if clause: 108 REQUEST.form['where'] = clause 109 return self.zmanage_editProperties(REQUEST)
110 111 112 InitializeClass(EventCommand) 113