Package Products :: Package Zuul :: Package routers :: Module eventclasses
[hide private]
[frames] | no frames]

Source Code for Module Products.Zuul.routers.eventclasses

  1  ############################################################################## 
  2  # 
  3  # Copyright (C) Zenoss, Inc. 2012, all rights reserved. 
  4  # 
  5  # This content is made available according to terms specified in 
  6  # License.zenoss under the directory where your Zenoss product is installed. 
  7  # 
  8  ############################################################################## 
  9   
 10  import logging 
 11  log = logging.getLogger("zen.EventClasses") 
 12   
 13  from Products.ZenUtils.Ext import DirectResponse 
 14  from Products import Zuul 
 15  from Products.Zuul.decorators import require, serviceConnectionError 
 16  from Products.Zuul.routers import TreeRouter 
 17  from Products.ZenMessaging.audit import audit 
 18  from collections import Mapping 
19 20 21 -class EventClassesRouter(TreeRouter):
22 """ 23 Event Classes and their instance maps 24 """ 25
26 - def _getFacade(self):
27 return Zuul.getFacade('eventclasses', self.context)
28 29 @serviceConnectionError
30 - def addNewInstance(self, params=None):
31 """ 32 Add new event class mapping for the current context 33 """ 34 facade = self._getFacade() 35 newInstance = facade.addNewInstance(params) 36 audit('UI.EventClasses.AddInstance', params['newName'], data_=params) 37 return DirectResponse.succeed(data=Zuul.marshal(newInstance))
38 39 @require('Manage DMD')
40 - def removeInstance(self, instances):
41 """ 42 remove instance(s) from an event class 43 """ 44 facade = self._getFacade() 45 facade.removeInstance(instances) 46 audit('UI.EventClasses.RemoveInstances', instance=instances) 47 return DirectResponse.succeed()
48 49 @serviceConnectionError 50 @require('Manage DMD')
51 - def editInstance(self, params=None):
52 """ 53 Edit an event class instance 54 """ 55 oldData = self.getInstanceData(params['uid']).data 56 self.testCompileTransform(params.get('transform')) 57 self.testRegex(params['regex'], params['example']) 58 self.testRule(params['rule']) 59 facade = self._getFacade() 60 facade.editInstance(params) 61 62 audit('UI.EventClasses.EditInstance', params['uid'], 63 data_=params, oldData_=oldData) 64 65 return DirectResponse.succeed()
66 67 @serviceConnectionError
68 - def getInstances(self, uid, params=None):
69 """ 70 Returns event class mappings for the current context 71 """ 72 facade = self._getFacade() 73 data = facade.getInstances(uid) 74 75 return DirectResponse( data=Zuul.marshal(data) )
76 77 @serviceConnectionError
78 - def getInstanceData(self, uid):
79 """ 80 return all extra data for instance id 81 """ 82 facade = self._getFacade() 83 data = facade.getInstanceData(uid) 84 return DirectResponse(data=Zuul.marshal(data) )
85
86 - def getSequence(self, uid):
87 """ 88 returns the sequence order of keys for a given instance 89 """ 90 facade = self._getFacade() 91 data = facade.getSequence(uid) 92 return DirectResponse(data=Zuul.marshal(data) )
93 94 @require('Manage DMD')
95 - def resequence(self, uids):
96 """ 97 resequences a list of sequenced instances 98 """ 99 facade = self._getFacade() 100 facade.resequence(uids) 101 audit('UI.EventClasses.Resequence', sequence=uids) 102 return DirectResponse.succeed()
103
104 - def setTransform(self, uid, transform):
105 """ 106 sets the transform for the context 107 """ 108 self.testCompileTransform(transform) 109 facade = self._getFacade() 110 facade.setTransform(uid, transform) 111 if isinstance(transform, Mapping): 112 auditTransform = transform 113 else: 114 auditTransform = {'transform': transform} 115 audit('UI.EventClasses.SetTransform', uid, data_=auditTransform) 116 return DirectResponse.succeed()
117
118 - def getTransform(self, uid):
119 """ 120 returns a transform for the context 121 """ 122 facade = self._getFacade() 123 data = facade.getTransform(uid) 124 return DirectResponse(data=Zuul.marshal(data) )
125
126 - def getTransformTree(self, uid):
127 """ 128 returns a transform for the context with all its inherited transforms 129 """ 130 facade = self._getFacade() 131 data = facade.getTransformTree(uid) 132 return DirectResponse(data=Zuul.marshal(data) )
133
134 - def isTransformEnabled(self, uid):
135 """ 136 Returns True if transform is enabled, False if disabled. 137 """ 138 facade = self._getFacade() 139 data = facade.isTransformEnabled(uid) 140 return DirectResponse(data=Zuul.marshal(data) )
141 142 @require('Manage DMD')
143 - def setTransformEnabled(self, uid, enabled):
144 """ 145 Enables or disables transforms on the given event class. 146 When disabled transforms are enabled again, bad_transform events are cleared. 147 """ 148 facade = self._getFacade() 149 data = facade.setTransformEnabled(uid, enabled) 150 return DirectResponse(data=Zuul.marshal(data) )
151 152 @require('Manage DMD')
153 - def editEventClassDescription(self, uid, description):
154 """ 155 edit the description of a given event class 156 """ 157 facade = self._getFacade() 158 facade.editEventClassDescription(uid, description) 159 audit('UI.EventClasses.EditEventClass', EventClass=uid, Description=description) 160 return DirectResponse.succeed()
161 162 @require('Manage DMD')
163 - def deleteEventClass(self, uid, params=None):
164 """ 165 remove an event class 166 """ 167 facade = self._getFacade() 168 facade.deleteNode(uid) 169 audit('UI.EventClasses.DeleteEventClass', deletedEventClass=uid) 170 return DirectResponse.succeed()
171
172 - def testCompileTransform(self, transform):
173 """ 174 Test our transform by compiling it. 175 """ 176 facade = self._getFacade() 177 facade.testCompileTransform(transform) 178 return DirectResponse.succeed()
179
180 - def testRegex(self, regex, example):
181 """ 182 Test our regex using the example event string. 183 """ 184 facade = self._getFacade() 185 reg = facade.testRegex(regex, example) 186 if reg is True: 187 return DirectResponse.succeed() 188 return DirectResponse.fail(reg)
189
190 - def testRule(self, rule):
191 """ 192 Test our rule by compiling it. 193 """ 194 facade = self._getFacade() 195 facade.testRule(rule) 196 return DirectResponse.succeed()
197 198 @require('Manage DMD')
199 - def moveInstance(self, params):
200 """ 201 move a mapped instance to a different organizer 202 @params['targetUid'] 203 @params['UidsToMove'] 204 """ 205 facade = self._getFacade() 206 for uid in params['UidsToMove']: 207 facade.moveInstance(params['targetUid'], uid) 208 audit('UI.EventClasses.MoveInstance', movedInstances=params['UidsToMove'], target=params['targetUid']) 209 return DirectResponse.succeed()
210 211 @require('Manage DMD')
212 - def moveClassOrganizer(self, params):
213 """ 214 move an event class organizer under a different organizer 215 """ 216 facade = self._getFacade() 217 facade.moveClassOrganizer(params['targetUid'], params['UidsToMove'][0]) 218 audit('UI.EventClasses.MoveOrganizer', movedOrganizer=params['UidsToMove'], target=params['targetUid']) 219 return DirectResponse.succeed()
220
221 - def getEventsCounts(self, uid):
222 """ 223 return all the event counts for this context 224 """ 225 facade = self._getFacade() 226 data = facade.getEventsCounts(uid) 227 return DirectResponse(data=Zuul.marshal(data) )
228