@@ -1,13 +1,12 @@
1−{-# LANGUAGE DataKinds #-}
1+{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE ExtendedDefaultRules #-}
2+{-# LANGUAGE ExtendedDefaultRules #-}
3−{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE OverloadedStrings #-}
4−{-# LANGUAGE TemplateHaskell #-}
4+{-# LANGUAGE TemplateHaskell #-}
5−{-# LANGUAGE TypeFamilies #-}
7{-# OPTIONS_GHC -fno-warn-type-defaults #-}
6{-# OPTIONS_GHC -fno-warn-type-defaults #-}
9−-- Module : Network.PagerDuty.REST.Services
8+-- Module : Network.PagerDuty.Services
10−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
9+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
11-- License : This Source Code Form is subject to the terms of
10-- License : This Source Code Form is subject to the terms of
12-- the Mozilla Public License, v. 2.0.
11-- the Mozilla Public License, v. 2.0.
13-- A copy of the MPL can be found in the LICENSE file or
12-- A copy of the MPL can be found in the LICENSE file or
@@ -24,16 +23,14 @@
24-- When a service is shown inlined in other resources, a deleted service will
23-- When a service is shown inlined in other resources, a deleted service will
25-- have its @html_url@ attribute set to 'Nothing'.
24-- have its @html_url@ attribute set to 'Nothing'.
27−-- /See:/ <http://developer.pagerduty.com/documentation/rest/services>
26+-- See: <http://developer.pagerduty.com/documentation/rest/services>
28−module Network.PagerDuty.REST.Services
27+module Network.PagerDuty.Services
30 -- * List Services
29 -- * List Services
32− , listServices
30+ listServices
33 , lsTimeZone
31 , lsTimeZone
35 -- * Create Service
33 -- * Create Service
37 , createService
34 , createService
39 , csDescription
36 , csDescription
@@ -48,7 +45,6 @@ module Network.PagerDuty.REST.Services
48 , getService
45 , getService
50 -- * Update Service
47 -- * Update Service
52 , updateService
48 , updateService
54 , usEscalationPolicyId
50 , usEscalationPolicyId
@@ -72,6 +68,7 @@ module Network.PagerDuty.REST.Services
72 -- * Types
68 -- * Types
73 , EmailFilterMode (..)
69 , EmailFilterMode (..)
74 , EmailIncidentCreation (..)
70 , EmailIncidentCreation (..)
75 , ServiceStatus (..)
72 , ServiceStatus (..)
76 , ServiceType (..)
73 , ServiceType (..)
77 , SeverityFilter (..)
74 , SeverityFilter (..)
@@ -82,6 +79,15 @@ module Network.PagerDuty.REST.Services
82 , cntResolved
79 , cntResolved
83 , cntTotal
80 , cntTotal
85 , PolicyInfo
91 , PolicyInfo
87 , pinfoName
93 , pinfoName
@@ -106,16 +112,16 @@ module Network.PagerDuty.REST.Services
106 , svcSeverityFilter
112 , svcSeverityFilter
109−import Control.Lens hiding (Empty)
115+import Control.Lens
110−import Data.Aeson.Lens
116+import Data.Aeson.Lens
111−import Data.Text (Text)
117+import Data.ByteString.Builder (Builder)
112−import Data.Time
118+import Data.Text (Text)
113−import Network.HTTP.Types
119+import Network.HTTP.Types
114−import Network.PagerDuty.Internal.TH
120+import Network.PagerDuty.Services.Types
121+import Network.PagerDuty.TH
115−import Network.PagerDuty.Internal.Types
122+import Network.PagerDuty.Types
116−import Network.PagerDuty.REST.Services.EmailFilters
118−default (Path)
124+default (Builder)
120services :: Path
126services :: Path
121services = "services"
127services = "services"
@@ -126,203 +132,37 @@ includes =
126 , ("include[]", Just "email_filters")
132 , ("include[]", Just "email_filters")
129−data IncidentCounts = IncidentCounts
130− { _cntTriggered :: !Int
131− , _cntAcknowledged :: !Int
132− , _cntResolved :: !Int
134− } deriving (Eq, Show)
136−deriveRecord ''IncidentCounts
138−data EmailIncidentCreation
140− -- ^ Open a new incident for each trigger email.
142− -- ^ Open a new incident for each new trigger email subject.
143− | OnlyIfNoOpenIncidents
144− -- ^ Open a new incident only if an open incident does not already exist.
147−deriveNullary ''EmailIncidentCreation
151− -- ^ Accept all incoming email
153− -- ^ Accept email only if it matches ONE OR MORE rules below
155− -- ^ Accept email only if it matches ALL of the rules below
158−deriveNullaryWith hyphenated ''EmailFilterMode
162− -- ^ The service is enabled and has no open incidents.
164− -- ^ The service is enabled and has one or more acknowledged incidents.
166− -- ^ The service is enabled and has one or more triggered incidents.
168− -- ^ The service is under maintenance, no new incidents will be
169− -- triggered during maintenance mode.
171− -- ^ The service is disabled and will not have any new triggered incidents.
174−deriveNullary ''ServiceStatus
187−deriveNullary ''ServiceType
189−data PolicyInfo = PolicyInfo
190− { _pinfoId :: EscalationPolicyId
191− , _pinfoName :: Text
192− } deriving (Eq, Show)
194−deriveRecord ''PolicyInfo
198− -- ^ Incidents are created when an alarm enters the Critical state.
199− | SevCriticalOrWarning
200− -- ^ Incidents are created when an alarm enters the Critical OR Warning states
202− -- ^ SQL Monitor: Incidents are created for alerts of any severity.
204− -- ^ SQL Monitor: Incidents are created for alerts with high severity.
206− -- ^ SQL Monitor: Incidents are created for with high or medium severity
209−deriveNullaryWith (dropped 3 underscored) ''SeverityFilter
211−data Service = Service
212− { _svcId :: ServiceId
214− , _svcDescription :: Text
215− , _svcServiceUrl :: Text
216− , _svcServiceKey :: ServiceKey
217− , _svcAutoResolveTimeout :: Maybe Int
218− , _svcAcknowledgementTimeout :: Maybe Int
219− , _svcCreatedAt :: Date
220− , _svcStatus :: ServiceStatus
221− , _svcLastIncidentTimestamp :: Maybe Date
222− , _svcEmailIncidentCreation :: Maybe EmailIncidentCreation
223− , _svcIncidentCounts :: IncidentCounts
224− , _svcEmailFilterMode :: EmailFilterMode
225− , _svcType :: ServiceType
226− , _svcEscalationPolicy :: Maybe PolicyInfo -- FIXME: extract from inline.
227− , _svcEmailFilters :: Maybe [EmailFilterInfo] -- FIXME: extract from inline.
228− , _svcSeverityFilter :: Maybe SeverityFilter
229− } deriving (Eq, Show)
233−-- | A unique identifier for this service.
234−makeLens "_svcId" ''Service
236−-- | The name of the service.
237−makeLens "_svcName" ''Service
239−-- | The description of the service
240−makeLens "_svcDescription" ''Service
242−-- | Relative URL that corresponds to this service.
243−makeLens "_svcServiceUrl" ''Service
245−-- | For Email services, the serviceKey is the associated email address
247−-- For all other service types, this is the unique key used for API calls.
248−makeLens "_svcServiceKey" ''Service
250−-- | Time in seconds that an incident changes to the Triggered State after
251−-- being Acknowledged. Value is 'Nothing' if the feature is disabled.
252−makeLens "_svcAutoResolveTimeout" ''Service
254−-- | Time in seconds that an incident is automatically resolved if left open for
255−-- that long. Value is 'Nothing' is the feature is disabled.
256−makeLens "_svcAcknowledgementTimeout" ''Service
258−-- | The date/time when this service was created.
259−svcCreatedAt :: Lens' Service UTCTime
260−svcCreatedAt = lens _svcCreatedAt (\s x -> s { _svcCreatedAt = x }) . _D
262−-- | The current state of the Service.
263−makeLens "_svcStatus" ''Service
265−-- | The date/time when the most recent incident was created for this service.
266−svcLastIncidentTimestamp :: Lens' Service (Maybe UTCTime)
267−svcLastIncidentTimestamp =
268− lens _svcLastIncidentTimestamp
269− (\s x -> s { _svcLastIncidentTimestamp = x }) . mapping _D
271−-- | If the service is a Generic Email service, this describes what kind of
272−-- emails create an incident.
273−makeLens "_svcEmailIncidentCreation" ''Service
275−-- | An object with the number of incidents corresponding to these states.
276−makeLens "_svcIncidentCounts" ''Service
278−-- | If the service is a Generic Email service, this describes which types of
279−-- email will generate an incident.
280−makeLens "_svcEmailFilterMode" ''Service
282−-- | The service type.
283−makeLens "_svcType" ''Service
285−-- | An object containing the ID and name of the escalation policy used by this
287−makeLens "_svcEscalationPolicy" ''Service
289−-- | An object containing inline Email Filters.
290−-- Note that only genericEmail services have filters.
291−makeLens "_svcEmailFilters" ''Service
293−-- | Specifies what severity levels will create a new open incident.
294−makeLens "_svcSeverityFilter" ''Service
296newtype ListServices = ListServices
135newtype ListServices = ListServices
297− { _lsTimeZone' :: Maybe TZ
136+ { _lsTimeZone' :: Maybe TimeZone
298 } deriving (Eq, Show)
137 } deriving (Eq, Show)
300instance Paginate ListServices
139instance Paginate ListServices
302−queryRequest ''ListServices
141+deriveJSON ''ListServices
303−
142+makeLenses ''ListServices
304−-- | Time zone in which dates in the result will be rendered.
306−-- /Default:/ account default time zone.
307−lsTimeZone :: Lens' (Request ListServices s r) (Maybe TimeZone)
308−lsTimeZone = upd.lsTimeZone'.mapping _TZ
310-- | List existing services.
144-- | List existing services.
312-- @GET \/services@
146-- @GET \/services@
314−-- /See:/ <http://developer.pagerduty.com/documentation/rest/services/list>
148+-- See: <http://developer.pagerduty.com/documentation/rest/services/list>
315listServices :: Request ListServices s [Service]
149listServices :: Request ListServices s [Service]
316listServices =
150listServices =
317 mk ListServices
151 mk ListServices
318 { _lsTimeZone' = Nothing
152 { _lsTimeZone' = Nothing
319 } & path .~ services
153 } & path .~ services
320− & query .~ includes
154+ & query <>~ includes
321 & unwrap .~ key "escalation_policies"
155 & unwrap .~ key "escalation_policies"
157+-- | Time zone in which dates in the result will be rendered.
159+-- Defaults to account default time zone.
160+lsTimeZone :: Lens' (Request ListServices s r) (Maybe TimeZone)
161+lsTimeZone = upd.lsTimeZone'
323data CreateService = CreateService
163data CreateService = CreateService
324 { _csName' :: Text
164 { _csName' :: Text
325− , _csEscalationPolicyId' :: EscalationPolicyId
165+ , _csEscalationPolicyId' :: PolicyId
326 , _csType' :: !ServiceType
166 , _csType' :: !ServiceType
327 , _csVendorId' :: Maybe VendorId
167 , _csVendorId' :: Maybe VendorId
328 , _csDescription' :: Maybe Text
168 , _csDescription' :: Maybe Text
@@ -331,7 +171,30 @@ data CreateService = CreateService
331 , _csSeverityFilter' :: Maybe SeverityFilter
171 , _csSeverityFilter' :: Maybe SeverityFilter
332 } deriving (Eq, Show)
172 } deriving (Eq, Show)
334−jsonRequest ''CreateService
174+deriveJSON ''CreateService
175+makeLenses ''CreateService
177+-- | Creates a new service.
181+-- See: <http://developer.pagerduty.com/documentation/rest/services/create>
182+createService :: Text
185+ -> Request CreateService s Service
186+createService n p t =
189+ , _csEscalationPolicyId' = p
191+ , _csVendorId' = Nothing
192+ , _csDescription' = Nothing
193+ , _csAcknowledgementTimeout' = Nothing
194+ , _csAutoResolveTimeout' = Nothing
195+ , _csSeverityFilter' = Nothing
196+ } & path .~ services
197+ & unwrap .~ key "service"
336-- | The name of the service.
199-- | The name of the service.
337csName :: Lens' (Request CreateService s r) Text
200csName :: Lens' (Request CreateService s r) Text
@@ -351,19 +214,19 @@ csVendorId :: Lens' (Request CreateService s r) (Maybe VendorId)
351csVendorId = upd.csVendorId'
214csVendorId = upd.csVendorId'
353-- | The id of the escalation policy to be used by this service.
216-- | The id of the escalation policy to be used by this service.
354−csEscalationPolicyId :: Lens' (Request CreateService s r) EscalationPolicyId
217+csEscalationPolicyId :: Lens' (Request CreateService s r) PolicyId
355csEscalationPolicyId = upd.csEscalationPolicyId'
218csEscalationPolicyId = upd.csEscalationPolicyId'
357-- | The duration in seconds before an incidents acknowledged in this service
220-- | The duration in seconds before an incidents acknowledged in this service
358-- become triggered again.
221-- become triggered again.
360−-- /Default:/ 30 minutes.
223+-- Defaults to 30 minutes.
361csAcknowledgementTimeout :: Lens' (Request CreateService s r) (Maybe Int)
224csAcknowledgementTimeout :: Lens' (Request CreateService s r) (Maybe Int)
362csAcknowledgementTimeout = upd.csAcknowledgementTimeout'
225csAcknowledgementTimeout = upd.csAcknowledgementTimeout'
364-- | The duration in seconds before a triggered incident auto-resolves itself.
227-- | The duration in seconds before a triggered incident auto-resolves itself.
366−-- /Default:/ 4 hours.
229+-- Defaults to 4 hours.
367csAutoResolveTimeout :: Lens' (Request CreateService s r) (Maybe Int)
230csAutoResolveTimeout :: Lens' (Request CreateService s r) (Maybe Int)
368csAutoResolveTimeout = upd.csAutoResolveTimeout'
231csAutoResolveTimeout = upd.csAutoResolveTimeout'
@@ -371,33 +234,11 @@ csAutoResolveTimeout = upd.csAutoResolveTimeout'
371csSeverityFilter :: Lens' (Request CreateService s r) (Maybe SeverityFilter)
234csSeverityFilter :: Lens' (Request CreateService s r) (Maybe SeverityFilter)
372csSeverityFilter = upd.csSeverityFilter'
235csSeverityFilter = upd.csSeverityFilter'
374−-- | Creates a new service.
378−-- /See:/ <http://developer.pagerduty.com/documentation/rest/services/create>
379−createService :: Text
380− -> EscalationPolicyId
382− -> Request CreateService s Service
383−createService n p t =
386− , _csEscalationPolicyId' = p
388− , _csVendorId' = Nothing
389− , _csDescription' = Nothing
390− , _csAcknowledgementTimeout' = Nothing
391− , _csAutoResolveTimeout' = Nothing
392− , _csSeverityFilter' = Nothing
393− } & path .~ services
394− & unwrap .~ key "service"
396-- | Get details about an existing service.
237-- | Get details about an existing service.
398-- @GET services\/\:id@
239-- @GET services\/\:id@
400−-- /See:/ <http://developer.pagerduty.com/documentation/rest/services/show>
241+-- See: <http://developer.pagerduty.com/documentation/rest/services/show>
401getService :: ServiceId -> Request Empty s Service
242getService :: ServiceId -> Request Empty s Service
402getService i = empty
243getService i = empty
403 & path .~ services % i
244 & path .~ services % i
@@ -407,13 +248,32 @@ getService i = empty
407data UpdateService = UpdateService
248data UpdateService = UpdateService
408 { _usName' :: Maybe Text
249 { _usName' :: Maybe Text
409 , _usDescription' :: Maybe Text
250 , _usDescription' :: Maybe Text
410− , _usEscalationPolicyId' :: Maybe EscalationPolicyId
251+ , _usEscalationPolicyId' :: Maybe PolicyId
411 , _usAcknowledgementTimeout' :: Maybe Int
252 , _usAcknowledgementTimeout' :: Maybe Int
412 , _usAutoResolveTimeout' :: Maybe Int
253 , _usAutoResolveTimeout' :: Maybe Int
413 , _usSeverityFilter' :: Maybe SeverityFilter
254 , _usSeverityFilter' :: Maybe SeverityFilter
414 } deriving (Eq, Show)
255 } deriving (Eq, Show)
257+deriveJSON ''UpdateService
416−jsonRequest ''UpdateService
258+makeLenses ''UpdateService
260+-- | Update an existing service.
262+-- @PUT services\/\:id@
264+-- See: <http://developer.pagerduty.com/documentation/rest/services/update>
265+updateService :: ServiceId -> Request UpdateService s Service
268+ { _usName' = Nothing
269+ , _usEscalationPolicyId' = Nothing
270+ , _usDescription' = Nothing
271+ , _usAcknowledgementTimeout' = Nothing
272+ , _usAutoResolveTimeout' = Nothing
273+ , _usSeverityFilter' = Nothing
275+ & path .~ services % i
276+ & unwrap .~ key "service"
418-- | The name of the service.
278-- | The name of the service.
419usName :: Lens' (Request UpdateService s r) (Maybe Text)
279usName :: Lens' (Request UpdateService s r) (Maybe Text)
@@ -424,19 +284,19 @@ usDescription :: Lens' (Request UpdateService s r) (Maybe Text)
424usDescription = upd.usDescription'
284usDescription = upd.usDescription'
426-- | The id of the escalation policy to be used by this service.
286-- | The id of the escalation policy to be used by this service.
427−usEscalationPolicyId :: Lens' (Request UpdateService s r) (Maybe EscalationPolicyId)
287+usEscalationPolicyId :: Lens' (Request UpdateService s r) (Maybe PolicyId)
428usEscalationPolicyId = upd.usEscalationPolicyId'
288usEscalationPolicyId = upd.usEscalationPolicyId'
430-- | The duration in seconds before an incidents acknowledged in this service
290-- | The duration in seconds before an incidents acknowledged in this service
431-- become triggered again.
291-- become triggered again.
433−-- /Default:/ 30 minutes.
293+-- Defaults to 30 minutes.
434usAcknowledgementTimeout :: Lens' (Request UpdateService s r) (Maybe Int)
294usAcknowledgementTimeout :: Lens' (Request UpdateService s r) (Maybe Int)
435usAcknowledgementTimeout = upd.usAcknowledgementTimeout'
295usAcknowledgementTimeout = upd.usAcknowledgementTimeout'
437-- | The duration in seconds before a triggered incident auto-resolves itself.
297-- | The duration in seconds before a triggered incident auto-resolves itself.
439−-- /Default:/ 4 hours.
299+-- Defaults to 4 hours.
440usAutoResolveTimeout :: Lens' (Request UpdateService s r) (Maybe Int)
300usAutoResolveTimeout :: Lens' (Request UpdateService s r) (Maybe Int)
441usAutoResolveTimeout = upd.usAutoResolveTimeout'
301usAutoResolveTimeout = upd.usAutoResolveTimeout'
@@ -444,31 +304,13 @@ usAutoResolveTimeout = upd.usAutoResolveTimeout'
444usSeverityFilter :: Lens' (Request UpdateService s r) (Maybe SeverityFilter)
304usSeverityFilter :: Lens' (Request UpdateService s r) (Maybe SeverityFilter)
445usSeverityFilter = upd.usSeverityFilter'
305usSeverityFilter = upd.usSeverityFilter'
447−-- | Update an existing service.
449−-- @PUT services\/\:id@
451−-- /See:/ <http://developer.pagerduty.com/documentation/rest/services/update>
452−updateService :: ServiceId -> Request UpdateService s Service
455− { _usName' = Nothing
456− , _usEscalationPolicyId' = Nothing
457− , _usDescription' = Nothing
458− , _usAcknowledgementTimeout' = Nothing
459− , _usAutoResolveTimeout' = Nothing
460− , _usSeverityFilter' = Nothing
462− & path .~ services % i
463− & unwrap .~ key "service"
465-- | Delete an existing service. Once the service is deleted, it will not be
307-- | Delete an existing service. Once the service is deleted, it will not be
466-- accessible from the web UI and new incidents won't be able to be created
308-- accessible from the web UI and new incidents won't be able to be created
467-- for this service.
309-- for this service.
469-- @DELETE \/services/:id@
311-- @DELETE \/services/:id@
471−-- /See:/ <http://developer.pagerduty.com/documentation/rest/services/delete>
313+-- See: <http://developer.pagerduty.com/documentation/rest/services/delete>
472deleteService :: ServiceId -> Request Empty s Empty
314deleteService :: ServiceId -> Request Empty s Empty
473deleteService i = empty & meth .~ DELETE & path .~ services % i
315deleteService i = empty & meth .~ DELETE & path .~ services % i
@@ -476,14 +318,13 @@ deleteService i = empty & meth .~ DELETE & path .~ services % i
477-- @PUT services\/\:id\/enable@
319-- @PUT services\/\:id\/enable@
479−-- /See:/ <http://developer.pagerduty.com/documentation/rest/services/enable>
321+-- See: <http://developer.pagerduty.com/documentation/rest/services/enable>
480enableService :: RequesterId -> ServiceId -> Request Empty s Empty
322enableService :: RequesterId -> ServiceId -> Request Empty s Empty
482− auth (enableServiceBasic i) & query .~ [("requester_id", r)]
323+enableService r i = auth (enableServiceBasic i) & query .~ [("requester_id", r)]
484-- | A version of 'enableService' which uses HTTP Basic authentication and
325-- | A version of 'enableService' which uses HTTP Basic authentication and
485-- doesn't require a 'RequesterId'.
326-- doesn't require a 'RequesterId'.
486−enableServiceBasic :: ServiceId -> Request Empty 'Basic Empty
327+enableServiceBasic :: ServiceId -> Request Empty Basic Empty
487enableServiceBasic i = empty & meth .~ PUT & path .~ services % i % "enable"
328enableServiceBasic i = empty & meth .~ PUT & path .~ services % i % "enable"
489-- | Disable a service. Once a service is disabled, it will not be able to
330-- | Disable a service. Once a service is disabled, it will not be able to
@@ -491,14 +332,13 @@ enableServiceBasic i = empty & meth .~ PUT & path .~ services % i % "enable"
492-- @PUT services\/\:id\/disable@
333-- @PUT services\/\:id\/disable@
494−-- /See:/ <http://developer.pagerduty.com/documentation/rest/services/disable>
335+-- See: <http://developer.pagerduty.com/documentation/rest/services/disable>
495disableService :: RequesterId -> ServiceId -> Request Empty s Empty
336disableService :: RequesterId -> ServiceId -> Request Empty s Empty
497− auth (disableServiceBasic i) & query .~ [("requester_id", r)]
337+disableService r i = auth (disableServiceBasic i) & query .~ [("requester_id", r)]
499-- | A version of 'disableService' which uses HTTP Basic authentication and
339-- | A version of 'disableService' which uses HTTP Basic authentication and
500-- doesn't require a 'RequesterId'.
340-- doesn't require a 'RequesterId'.
501−disableServiceBasic :: ServiceId -> Request Empty 'Basic Empty
341+disableServiceBasic :: ServiceId -> Request Empty Basic Empty
502disableServiceBasic i = empty & meth .~ PUT & path .~ services % i % "disable"
342disableServiceBasic i = empty & meth .~ PUT & path .~ services % i % "disable"
504-- | Regenerate a new service key for an existing service.
344-- | Regenerate a new service key for an existing service.
@@ -508,6 +348,6 @@ disableServiceBasic i = empty & meth .~ PUT & path .~ services % i % "disable"
509-- @POST services\/\:id\/regenerate_key@
349-- @POST services\/\:id\/regenerate_key@
511−-- /See:/ <http://developer.pagerduty.com/documentation/rest/services/regenerate_key>
351+-- See: <http://developer.pagerduty.com/documentation/rest/services/regenerate_key>
512regenerateKey :: ServiceId -> Request Empty s Service
352regenerateKey :: ServiceId -> Request Empty s Service
513regenerateKey i = empty & meth .~ POST & path .~ services % i % "regenerate_key"
353regenerateKey i = empty & meth .~ POST & path .~ services % i % "regenerate_key"