module Network.PagerDuty.REST.Reports
(
alertsPerTime
, incidentsPerTime
, Report
, rSince
, rUntil
, rRollup
, Rollup (..)
, AlertReport
, arStart
, arEnd
, arNumberOfAlerts
, arNumberOfPhoneAlerts
, arNumberOfSmsAlerts
, arNumberOfEmailAlerts
, AlertTotals
, atAlerts
, atTotalNumberOfAlerts
, atTotalNumberOfPhoneAlerts
, atTotalNumberOfSmsAlerts
, atTotalNumberOfEmailAlerts
, atTotalNumberOfBillableAlerts
, IncidentReport
, irStart
, irEnd
, irNumberOfIncidents
) where
import Control.Lens
import Data.Aeson.Lens
import Data.Time
import Network.PagerDuty.Internal.TH
import Network.PagerDuty.Internal.Types
default (Path)
reports :: Path
reports = "reports"
data Rollup
= Daily
| Weekly
| Monthly
deriving (Eq, Show)
deriveNullary ''Rollup
data Report = Report
{ _rSince' :: Date
, _rUntil' :: Date
, _rRollup' :: !Rollup
} deriving (Eq, Show)
queryRequest ''Report
rSince :: Lens' (Request Report s b) UTCTime
rSince = upd.rSince'._D
rUntil :: Lens' (Request Report s b) UTCTime
rUntil = upd.rUntil'._D
rRollup :: Lens' (Request Report s b) Rollup
rRollup = upd.rRollup'
data AlertReport = AlertReport
{ _arStart :: Date
, _arEnd :: Date
, _arNumberOfAlerts :: !Int
, _arNumberOfPhoneAlerts :: !Int
, _arNumberOfSmsAlerts :: !Int
, _arNumberOfEmailAlerts :: !Int
} deriving (Eq, Show)
deriveJSON ''AlertReport
arStart :: Lens' AlertReport UTCTime
arStart = lens _arStart (\r x -> r { _arStart = x }) ._D
arEnd :: Lens' AlertReport UTCTime
arEnd = lens _arEnd (\r x -> r { _arEnd = x }) ._D
makeLens "_arNumberOfAlerts" ''AlertReport
makeLens "_arNumberOfPhoneAlerts" ''AlertReport
makeLens "_arNumberOfSmsAlerts" ''AlertReport
makeLens "_arNumberOfEmailAlerts" ''AlertReport
data AlertTotals = AlertTotals
{ _atAlerts :: [AlertReport]
, _atTotalNumberOfAlerts :: !Int
, _atTotalNumberOfPhoneAlerts :: !Int
, _atTotalNumberOfSmsAlerts :: !Int
, _atTotalNumberOfEmailAlerts :: !Int
, _atTotalNumberOfBillableAlerts :: !Int
} deriving (Eq, Show)
deriveRecord ''AlertTotals
alertsPerTime :: UTCTime
-> UTCTime
-> Request Report s AlertTotals
alertsPerTime s u =
mk Report
{ _rSince' = D s
, _rUntil' = D u
, _rRollup' = Monthly
} & path .~ reports % "alerts_per_time"
data IncidentReport = IncidentReport
{ _irStart :: Date
, _irEnd :: Date
, _irNumberOfIncidents :: !Int
} deriving (Eq, Show)
deriveJSON ''IncidentReport
irStart :: Lens' IncidentReport UTCTime
irStart = lens _irStart (\r x -> r { _irStart = x }) . _D
irEnd :: Lens' IncidentReport UTCTime
irEnd = lens _irEnd (\r x -> r { _irEnd = x }) . _D
makeLens "_irNumberOfIncidents" ''IncidentReport
incidentsPerTime :: UTCTime
-> UTCTime
-> Request Report s [IncidentReport]
incidentsPerTime s u =
mk Report
{ _rSince' = D s
, _rUntil' = D u
, _rRollup' = Monthly
} & path .~ reports % "incidents_per_time"
& unwrap .~ key "incidents"