git.iko.soy/typeable/pagerduty
on develop help sign in
Adding Reports REST API
commitb60c4401d972cd22e90179f90d03df7c312b0a4e authorBrendan Hay <brendan.g.hay@gmail.com> dateWed 1 Oct 2014, 09:54 (12 years ago) parent17a5c94
1 file changed+135−7
src/Network/PagerDuty/REST/Reports.hs+135−7
src/Network/PagerDuty/REST/Reports.hs+135−7
@@ -1,5 +1,8 @@
1−{-# LANGUAGE OverloadedStrings #-}
2−{-# LANGUAGE TemplateHaskell #-}
1+{-# LANGUAGE ExtendedDefaultRules #-}
2+{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE TemplateHaskell #-}
4+
5+{-# OPTIONS_GHC -fno-warn-type-defaults #-}
36
47-- Module : Network.PagerDuty.REST.Reports
58-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
@@ -11,27 +14,152 @@
1114-- Stability : experimental
1215-- Portability : non-portable (GHC extensions)
1316
14−-- | Access high level reports about alerts and incidents. Useful for creating graphs.
17+-- | Access high level reports about alerts and incidents.
18+-- Useful for creating graphs.
1519module Network.PagerDuty.REST.Reports
1620 (
21+ -- * Alerts Per Time
22+ alertsPerTime
23+
24+ -- * Incidents Per Time
25+ , incidentsPerTime
26+
27+ -- * Types
28+ , Rollup (..)
1729
30+ , AlertReport
31+ , arStart
32+ , arEnd
33+ , arNumberOfAlerts
34+ , arNumberOfPhoneAlerts
35+ , arNumberOfSmsAlerts
36+ , arNumberOfEmailAlerts
37+
38+ , AlertTotals
39+ , atAlerts
40+ , atTotalNumberOfAlerts
41+ , atTotalNumberOfPhoneAlerts
42+ , atTotalNumberOfSmsAlerts
43+ , atTotalNumberOfEmailAlerts
44+ , atTotalNumberOfBillableAlerts
45+
46+ , IncidentReport
47+ , irStart
48+ , irEnd
49+ , irNumberOfIncidents
1850 ) where
1951
52+import Control.Lens
53+import Data.Aeson.Lens
54+import Data.ByteString.Builder (Builder)
55+import Data.Text (Text)
56+import Network.HTTP.Types
57+import Network.PagerDuty.TH
58+import Network.PagerDuty.Types
59+
60+default (Builder)
61+
2062reports :: Path
2163reports = "reports"
2264
65+data Rollup
66+ = Daily
67+ | Weekly
68+ | Monthly
69+ deriving (Eq Show)
70+
71+deriveJSON ''Rollup
72+
73+data Report = Report
74+ { _rSince' :: Date
75+ , _rUntil' :: Date
76+ , _rRollup' :: !Rollup
77+ } deriving (Eq, Show)
78+
79+deriveJSON ''Report
80+makeLenses ''Report
81+
82+data AlertReport
83+ { _arStart :: Date
84+ , _arEnd :: Date
85+ , _arNumberOfAlerts :: !Int
86+ , _arNumberOfPhoneAlerts :: !Int
87+ , _arNumberOfSmsAlerts :: !Int
88+ , _arNumberOfEmailAlerts :: !Int
89+ } deriving (Eq, Show)
90+
91+deriveJSON ''AlertReport
92+makeLenses ''AlertReport
93+
94+data AlertTotals = AlertTotals
95+ { _atAlerts :: [AlertReport]
96+ , _atTotalNumberOfAlerts :: !Int
97+ , _atTotalNumberOfPhoneAlerts :: !Int
98+ , _atTotalNumberOfSmsAlerts :: !Int
99+ , _atTotalNumberOfEmailAlerts :: !Int
100+ , _atTotalNumberOfBillableAlerts :: !Int
101+ } deriving (Eq, Show)
102+
103+deriveJSON ''AlertTotals
104+makeLenses ''AlertTotals
105+
106+data IncidentReport = IncidentReport
107+ { _irStart :: Date
108+ , _irEnd :: Date
109+ , _irNumberOfIncidents :: !Int
110+ } deriving (Eq, Show)
111+
112+deriveJSON ''IncidentReport
113+makeLenses ''IncidentReport
114+
115+-- | Start of the date range over which you want to search. The time element
116+-- is optional.
117+rSince :: Lens' (Request Report s r) Date
118+rSince = upd.rSince'
119+
120+-- | The end of the date range over which you want to search. This should be
121+-- in the same format as since.
122+rUntil :: Lens' (Request Report s r) Date
123+rUntil = upd.rUntil'
124+
125+-- | Specifies the bucket duration for each summation.
126+--
127+-- Defaults to monthly.
128+--
129+-- Example: A time window of two years (based on since and until) with a
130+-- rollup of monthly will result in 24 sets of data points being returned
131+-- (one for each month in the span).
132+rSince :: Lens' (Request Report s r) Rollup
133+rSince = upd.rSince'
134+
23135-- | Get high level statistics about the number of alerts (SMSes, phone calls and
24136-- emails) sent for the desired time period, summed daily, weekly or monthly.
25137--
26138-- @GET \/reports\/alerts_per_time@
27139--
28140-- See: <http://developer.pagerduty.com/documentation/rest/reports/alerts_per_time>
29−alertsPerTime = undefined
141+alertsPerTime :: Date -- ^ 'rSince'
142+ -> Date -- ^ 'rUntil'
143+ -> Request Report s AlertTotals
144+alertsPerTime s u =
145+ mk Report
146+ { _rSince = s
147+ , _rUntil = u
148+ , _rRollup = Monthly
149+ } & path .~ reports % "alerts_per_time"
30150
31−-- | Get high level statistics about the number of incidents created for the desired
32−-- time period, summed daily, weekly or monthly.
151+-- | Get high level statistics about the number of incidents created for the
152+-- desired time period, summed daily, weekly or monthly.
33153--
34154-- @GET \/reports\/incidents_per_time@
35155--
36156-- See: <http://developer.pagerduty.com/documentation/rest/reports/incidents_per_time>
37−incidentsPerTime = undefined
157+incidentsPerTime :: Date -- ^ 'rSince'
158+ -> Date -- ^ 'rUntil'
159+ -> Request Report s [IncidentReport]
160+incidentsPerTime s u =
161+ mk Report
162+ { _rSince = s
163+ , _rUntil = u
164+ , _rRollup = Monthly
165+ } & path .~ reports % "incidents_per_time"