1
2
3
4
5
6
7
8
9
10
11 from operator import itemgetter
12 from Products import Zuul
13 from zope.component import getUtilitiesFor
14 from Products.ZenModel.interfaces import IAction
15 from Products.ZenUtils.Ext import DirectRouter
16 from Products.ZenUtils.extdirect.router import DirectResponse
17 from Products.Zuul.decorators import serviceConnectionError
18 from zenoss.protocols.protobufs.zep_pb2 import RULE_TYPE_JYTHON
19 from Products.ZenMessaging.audit import audit
20
21 import logging
22
23 log = logging.getLogger('zen.triggers');
26 """
27 Router for Triggers UI section under Events.
28 """
29
31 return Zuul.getFacade('triggers', self)
32
33 @serviceConnectionError
36
37 @serviceConnectionError
40
41 @serviceConnectionError
43 data = self._getFacade().addTrigger(newId)
44 audit('UI.Trigger.Add', newId)
45 return DirectResponse.succeed(data=data)
46
47 @serviceConnectionError
49 updated_count = self._getFacade().removeTrigger(uuid)
50 audit('UI.Trigger.Remove', uuid)
51 msg = "Trigger removed successfully. {count} {noun} {verb} updated.".format(
52 count = updated_count,
53 noun = 'notification' if updated_count == 1 else 'notifications',
54 verb = 'was' if updated_count == 1 else 'were'
55 )
56 return DirectResponse.succeed(msg=msg, data=None)
57
58 @serviceConnectionError
61
62 @serviceConnectionError
64 data['rule']['api_version'] = 1
65 data['rule']['type'] = RULE_TYPE_JYTHON
66 triggerUid = data['uuid']
67 response = self._getFacade().updateTrigger(**data)
68 audit('UI.Trigger.Edit', triggerUid, data_=data)
69 return DirectResponse.succeed(msg="Trigger updated successfully.", data=response)
70
71 @serviceConnectionError
73 try:
74 response = self._getFacade().parseFilter(source)
75 return DirectResponse.succeed(data=response)
76 except Exception, e:
77 log.exception(e)
78 return DirectResponse.exception(e,
79 'Error parsing filter source. Please check your syntax.')
80
81
82
83 @serviceConnectionError
87
88 @serviceConnectionError
90 response = self._getFacade().addNotification(newId, action)
91 audit('UI.Notification.Add', newId)
92 return DirectResponse.succeed(data=Zuul.marshal(response))
93
94 @serviceConnectionError
96 response = self._getFacade().removeNotification(uid)
97 audit('UI.Notification.Remove', uid)
98 return DirectResponse.succeed(msg="Notification removed successfully.", data=response)
99
100 @serviceConnectionError
102 utils = getUtilitiesFor(IAction)
103 actionTypes = sorted((dict(id=id, name=util.name) for id, util in utils), key=itemgetter('id'))
104 log.debug('notification action types are: %s' % actionTypes)
105 return DirectResponse.succeed(data=actionTypes)
106
107 @serviceConnectionError
111
112 @serviceConnectionError
114 notificationUid = data['uid']
115 response = self._getFacade().updateNotification(**data)
116 audit('UI.Notification.Edit', notificationUid, data_=data)
117 return DirectResponse.succeed(msg="Notification updated successfully.", data=Zuul.marshal(response))
118
119 @serviceConnectionError
123
124
125 @serviceConnectionError
127 response = self._getFacade().getWindows(uid)
128 return DirectResponse.succeed(data=Zuul.marshal(response))
129
130 @serviceConnectionError
132 response = self._getFacade().addWindow(contextUid, newId)
133 audit('UI.NotificationWindow.Add', newId, notification=contextUid)
134 return DirectResponse.succeed(data=Zuul.marshal(response))
135
136 @serviceConnectionError
138 response = self._getFacade().removeWindow(uid)
139 audit('UI.NotificationWindow.Remove', uid)
140 return DirectResponse.succeed(data=Zuul.marshal(response))
141
142 @serviceConnectionError
144 response = self._getFacade().getWindow(uid)
145 return DirectResponse.succeed(data=Zuul.marshal(response))
146
147 @serviceConnectionError
149 windowUid = data['uid']
150 response = self._getFacade().updateWindow(data)
151 audit('UI.NotificationWindow.Edit', windowUid, data_=data)
152 return DirectResponse.succeed(data=Zuul.marshal(response))
153