{-# LANGUAGE OverloadedStrings #-}
module Network.Datadog.Monitor
( MonitorSpec(..)
, MonitorType(..)
, MonitorOptions(..)
, getSilencedMonitorScopes
, silenceMonitorScope
, unsilenceMonitorScope
, unsilenceAllMonitorScope
, doesNotifyOnNoMonitorData
, notifyOnNoMonitorData
, noNotifyOnNoMonitorData
, getMonitorTimeout
, setMonitorTimeout
, clearMonitorTimeout
, doesRenotifyMonitor
, renotifyMonitor
, noRenotifyMonitor
, doesNotifyOnAudit
, notifyOnAudit
, noNotifyOnAudit
, Monitor(..)
, MonitorId
, minimalMonitorSpec
, createMonitor
, updateMonitor
, deleteMonitor
, loadMonitor
, loadMonitors
, muteAllMonitors
, unmuteAllMonitors
, HasId'(..)
, HasSpec(..)
, HasType'(..)
, HasQuery(..)
, HasOptions(..)
, HasMessage(..)
, HasName(..)
, HasNotifyNoData(..)
, HasTimeoutH(..)
, HasRenotifyInterval(..)
, HasNoDataTimeframe(..)
, HasSilenced(..)
, AsMonitorType(..)
) where
import Control.Arrow
import Control.Exception
import Control.Lens
import Control.Monad (void)
import Data.Aeson
import qualified Data.HashMap.Strict as Data.HashMap
import Data.List (intercalate)
import Data.Maybe
import qualified Data.Text as T (Text, null)
import Data.Time.Clock
import Data.Time.Clock.POSIX
import Network.HTTP.Types
import Network.Datadog.Internal
getSilencedMonitorScopes :: MonitorOptions -> [(T.Text, Maybe UTCTime)]
getSilencedMonitorScopes :: MonitorOptions -> [(Text, Maybe UTCTime)]
getSilencedMonitorScopes MonitorOptions
opts = ((Text, Maybe Integer) -> (Text, Maybe UTCTime))
-> [(Text, Maybe Integer)] -> [(Text, Maybe UTCTime)]
forall a b. (a -> b) -> [a] -> [b]
map ((Maybe Integer -> Maybe UTCTime)
-> (Text, Maybe Integer) -> (Text, Maybe UTCTime)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second ((Integer -> UTCTime) -> Maybe Integer -> Maybe UTCTime
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (POSIXTime -> UTCTime
posixSecondsToUTCTime (POSIXTime -> UTCTime)
-> (Integer -> POSIXTime) -> Integer -> UTCTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> POSIXTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral))) ([(Text, Maybe Integer)] -> [(Text, Maybe UTCTime)])
-> [(Text, Maybe Integer)] -> [(Text, Maybe UTCTime)]
forall a b. (a -> b) -> a -> b
$ HashMap Text (Maybe Integer) -> [(Text, Maybe Integer)]
forall k v. HashMap k v -> [(k, v)]
Data.HashMap.toList (HashMap Text (Maybe Integer) -> [(Text, Maybe Integer)])
-> HashMap Text (Maybe Integer) -> [(Text, Maybe Integer)]
forall a b. (a -> b) -> a -> b
$ MonitorOptions
opts MonitorOptions
-> Getting
(HashMap Text (Maybe Integer))
MonitorOptions
(HashMap Text (Maybe Integer))
-> HashMap Text (Maybe Integer)
forall s a. s -> Getting a s a -> a
^. Getting
(HashMap Text (Maybe Integer))
MonitorOptions
(HashMap Text (Maybe Integer))
forall s a. HasSilenced s a => Lens' s a
silenced
silenceMonitorScope :: T.Text -> Maybe UTCTime -> MonitorOptions -> MonitorOptions
silenceMonitorScope :: Text -> Maybe UTCTime -> MonitorOptions -> MonitorOptions
silenceMonitorScope Text
scopeName Maybe UTCTime
mtime MonitorOptions
old = MonitorOptions
old MonitorOptions
-> (MonitorOptions -> MonitorOptions) -> MonitorOptions
forall a b. a -> (a -> b) -> b
& (HashMap Text (Maybe Integer)
-> Identity (HashMap Text (Maybe Integer)))
-> MonitorOptions -> Identity MonitorOptions
forall s a. HasSilenced s a => Lens' s a
silenced ((HashMap Text (Maybe Integer)
-> Identity (HashMap Text (Maybe Integer)))
-> MonitorOptions -> Identity MonitorOptions)
-> (HashMap Text (Maybe Integer) -> HashMap Text (Maybe Integer))
-> MonitorOptions
-> MonitorOptions
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ HashMap Text (Maybe Integer) -> HashMap Text (Maybe Integer)
silenceF
where silenceF :: HashMap Text (Maybe Integer) -> HashMap Text (Maybe Integer)
silenceF = Text
-> Maybe Integer
-> HashMap Text (Maybe Integer)
-> HashMap Text (Maybe Integer)
forall k v.
(Eq k, Hashable k) =>
k -> v -> HashMap k v -> HashMap k v
Data.HashMap.insert Text
scopeName ((UTCTime -> Integer) -> Maybe UTCTime -> Maybe Integer
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (POSIXTime -> Integer
forall a b. (RealFrac a, Integral b) => a -> b
floor (POSIXTime -> Integer)
-> (UTCTime -> POSIXTime) -> UTCTime -> Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UTCTime -> POSIXTime
utcTimeToPOSIXSeconds) Maybe UTCTime
mtime)
unsilenceMonitorScope :: T.Text -> MonitorOptions -> MonitorOptions
unsilenceMonitorScope :: Text -> MonitorOptions -> MonitorOptions
unsilenceMonitorScope Text
scopeName MonitorOptions
old = MonitorOptions
old MonitorOptions
-> (MonitorOptions -> MonitorOptions) -> MonitorOptions
forall a b. a -> (a -> b) -> b
& (HashMap Text (Maybe Integer)
-> Identity (HashMap Text (Maybe Integer)))
-> MonitorOptions -> Identity MonitorOptions
forall s a. HasSilenced s a => Lens' s a
silenced ((HashMap Text (Maybe Integer)
-> Identity (HashMap Text (Maybe Integer)))
-> MonitorOptions -> Identity MonitorOptions)
-> (HashMap Text (Maybe Integer) -> HashMap Text (Maybe Integer))
-> MonitorOptions
-> MonitorOptions
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Text
-> HashMap Text (Maybe Integer) -> HashMap Text (Maybe Integer)
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> HashMap k v
Data.HashMap.delete Text
scopeName)
unsilenceAllMonitorScope :: MonitorOptions -> MonitorOptions
unsilenceAllMonitorScope :: MonitorOptions -> MonitorOptions
unsilenceAllMonitorScope = ((HashMap Text (Maybe Integer)
-> Identity (HashMap Text (Maybe Integer)))
-> MonitorOptions -> Identity MonitorOptions)
-> HashMap Text (Maybe Integer) -> MonitorOptions -> MonitorOptions
forall s t a b. ASetter s t a b -> b -> s -> t
set (HashMap Text (Maybe Integer)
-> Identity (HashMap Text (Maybe Integer)))
-> MonitorOptions -> Identity MonitorOptions
forall s a. HasSilenced s a => Lens' s a
silenced HashMap Text (Maybe Integer)
forall k v. HashMap k v
Data.HashMap.empty
doesNotifyOnNoMonitorData :: MonitorOptions -> Maybe NominalDiffTime
doesNotifyOnNoMonitorData :: MonitorOptions -> Maybe POSIXTime
doesNotifyOnNoMonitorData MonitorOptions
opts = if MonitorOptions
opts MonitorOptions -> Getting Bool MonitorOptions Bool -> Bool
forall s a. s -> Getting a s a -> a
^. Getting Bool MonitorOptions Bool
forall s a. HasNotifyNoData s a => Lens' s a
notifyNoData
then POSIXTime -> Maybe POSIXTime
forall a. a -> Maybe a
Just (POSIXTime -> Maybe POSIXTime) -> POSIXTime -> Maybe POSIXTime
forall a b. (a -> b) -> a -> b
$ POSIXTime -> (Integer -> POSIXTime) -> Maybe Integer -> POSIXTime
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (AssertionFailed -> POSIXTime
forall a e. Exception e => e -> a
throw (String -> AssertionFailed
AssertionFailed String
"Datadog Library internal error")) (Integer -> POSIXTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> POSIXTime)
-> (Integer -> Integer) -> Integer -> POSIXTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
*Integer
60)) (Maybe Integer -> POSIXTime) -> Maybe Integer -> POSIXTime
forall a b. (a -> b) -> a -> b
$ MonitorOptions
opts MonitorOptions
-> Getting (Maybe Integer) MonitorOptions (Maybe Integer)
-> Maybe Integer
forall s a. s -> Getting a s a -> a
^. Getting (Maybe Integer) MonitorOptions (Maybe Integer)
forall s a. HasNoDataTimeframe s a => Lens' s a
noDataTimeframe
else Maybe POSIXTime
forall a. Maybe a
Nothing
notifyOnNoMonitorData :: NominalDiffTime -> MonitorOptions -> MonitorOptions
notifyOnNoMonitorData :: POSIXTime -> MonitorOptions -> MonitorOptions
notifyOnNoMonitorData POSIXTime
difftime MonitorOptions
old = MonitorOptions
old MonitorOptions
-> (MonitorOptions -> MonitorOptions) -> MonitorOptions
forall a b. a -> (a -> b) -> b
& (Bool -> Identity Bool)
-> MonitorOptions -> Identity MonitorOptions
forall s a. HasNotifyNoData s a => Lens' s a
notifyNoData ((Bool -> Identity Bool)
-> MonitorOptions -> Identity MonitorOptions)
-> Bool -> MonitorOptions -> MonitorOptions
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Bool
True MonitorOptions
-> (MonitorOptions -> MonitorOptions) -> MonitorOptions
forall a b. a -> (a -> b) -> b
& (Maybe Integer -> Identity (Maybe Integer))
-> MonitorOptions -> Identity MonitorOptions
forall s a. HasNoDataTimeframe s a => Lens' s a
noDataTimeframe ((Maybe Integer -> Identity (Maybe Integer))
-> MonitorOptions -> Identity MonitorOptions)
-> Integer -> MonitorOptions -> MonitorOptions
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Integer
stamp
where stamp :: Integer
stamp = POSIXTime -> Integer
forall a b. (RealFrac a, Integral b) => a -> b
floor (POSIXTime
difftime POSIXTime -> POSIXTime -> POSIXTime
forall a. Fractional a => a -> a -> a
/ POSIXTime
60)
noNotifyOnNoMonitorData :: MonitorOptions -> MonitorOptions
noNotifyOnNoMonitorData :: MonitorOptions -> MonitorOptions
noNotifyOnNoMonitorData MonitorOptions
old = MonitorOptions
old MonitorOptions
-> (MonitorOptions -> MonitorOptions) -> MonitorOptions
forall a b. a -> (a -> b) -> b
& (Bool -> Identity Bool)
-> MonitorOptions -> Identity MonitorOptions
forall s a. HasNotifyNoData s a => Lens' s a
notifyNoData ((Bool -> Identity Bool)
-> MonitorOptions -> Identity MonitorOptions)
-> Bool -> MonitorOptions -> MonitorOptions
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Bool
False MonitorOptions
-> (MonitorOptions -> MonitorOptions) -> MonitorOptions
forall a b. a -> (a -> b) -> b
& (Maybe Integer -> Identity (Maybe Integer))
-> MonitorOptions -> Identity MonitorOptions
forall s a. HasNoDataTimeframe s a => Lens' s a
noDataTimeframe ((Maybe Integer -> Identity (Maybe Integer))
-> MonitorOptions -> Identity MonitorOptions)
-> Maybe Integer -> MonitorOptions -> MonitorOptions
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Maybe Integer
forall a. Maybe a
Nothing
getMonitorTimeout :: MonitorOptions -> Maybe NominalDiffTime
getMonitorTimeout :: MonitorOptions -> Maybe POSIXTime
getMonitorTimeout MonitorOptions
opts = (Integer -> POSIXTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> POSIXTime)
-> (Integer -> Integer) -> Integer -> POSIXTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
*Integer
3600)) (Integer -> POSIXTime) -> Maybe Integer -> Maybe POSIXTime
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (MonitorOptions
opts MonitorOptions
-> Getting (Maybe Integer) MonitorOptions (Maybe Integer)
-> Maybe Integer
forall s a. s -> Getting a s a -> a
^. Getting (Maybe Integer) MonitorOptions (Maybe Integer)
forall s a. HasTimeoutH s a => Lens' s a
timeoutH)
setMonitorTimeout :: NominalDiffTime -> MonitorOptions -> MonitorOptions
setMonitorTimeout :: POSIXTime -> MonitorOptions -> MonitorOptions
setMonitorTimeout POSIXTime
difftime MonitorOptions
old = MonitorOptions
old MonitorOptions
-> (MonitorOptions -> MonitorOptions) -> MonitorOptions
forall a b. a -> (a -> b) -> b
& (Maybe Integer -> Identity (Maybe Integer))
-> MonitorOptions -> Identity MonitorOptions
forall s a. HasTimeoutH s a => Lens' s a
timeoutH ((Maybe Integer -> Identity (Maybe Integer))
-> MonitorOptions -> Identity MonitorOptions)
-> Integer -> MonitorOptions -> MonitorOptions
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Integer
stamp
where stamp :: Integer
stamp = POSIXTime -> Integer
forall a b. (RealFrac a, Integral b) => a -> b
ceiling (POSIXTime
difftime POSIXTime -> POSIXTime -> POSIXTime
forall a. Fractional a => a -> a -> a
/ POSIXTime
3600)
clearMonitorTimeout :: MonitorOptions -> MonitorOptions
clearMonitorTimeout :: MonitorOptions -> MonitorOptions
clearMonitorTimeout = ((Maybe Integer -> Identity (Maybe Integer))
-> MonitorOptions -> Identity MonitorOptions)
-> Maybe Integer -> MonitorOptions -> MonitorOptions
forall s t a b. ASetter s t a b -> b -> s -> t
set (Maybe Integer -> Identity (Maybe Integer))
-> MonitorOptions -> Identity MonitorOptions
forall s a. HasTimeoutH s a => Lens' s a
timeoutH Maybe Integer
forall a. Maybe a
Nothing
doesRenotifyMonitor :: MonitorOptions -> Maybe (NominalDiffTime,Maybe T.Text)
doesRenotifyMonitor :: MonitorOptions -> Maybe (POSIXTime, Maybe Text)
doesRenotifyMonitor MonitorOptions
opts = (\Integer
i -> (Integer -> POSIXTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer
i Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
60), Maybe Text
result)) (Integer -> (POSIXTime, Maybe Text))
-> Maybe Integer -> Maybe (POSIXTime, Maybe Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (MonitorOptions
opts MonitorOptions
-> Getting (Maybe Integer) MonitorOptions (Maybe Integer)
-> Maybe Integer
forall s a. s -> Getting a s a -> a
^. Getting (Maybe Integer) MonitorOptions (Maybe Integer)
forall s a. HasRenotifyInterval s a => Lens' s a
renotifyInterval)
where msg :: Text
msg = MonitorOptions
opts MonitorOptions -> Getting Text MonitorOptions Text -> Text
forall s a. s -> Getting a s a -> a
^. Getting Text MonitorOptions Text
forall s a. HasEscalationMessage s a => Lens' s a
escalationMessage
result :: Maybe Text
result = if Text -> Bool
T.null Text
msg then Maybe Text
forall a. Maybe a
Nothing else Text -> Maybe Text
forall a. a -> Maybe a
Just Text
msg
renotifyMonitor :: NominalDiffTime -> Maybe T.Text -> MonitorOptions -> MonitorOptions
renotifyMonitor :: POSIXTime -> Maybe Text -> MonitorOptions -> MonitorOptions
renotifyMonitor POSIXTime
difftime Maybe Text
mMessage MonitorOptions
old = MonitorOptions
old MonitorOptions
-> (MonitorOptions -> MonitorOptions) -> MonitorOptions
forall a b. a -> (a -> b) -> b
& (Maybe Integer -> Identity (Maybe Integer))
-> MonitorOptions -> Identity MonitorOptions
forall s a. HasRenotifyInterval s a => Lens' s a
renotifyInterval ((Maybe Integer -> Identity (Maybe Integer))
-> MonitorOptions -> Identity MonitorOptions)
-> Integer -> MonitorOptions -> MonitorOptions
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Integer
stamp MonitorOptions
-> (MonitorOptions -> MonitorOptions) -> MonitorOptions
forall a b. a -> (a -> b) -> b
& (Text -> Identity Text)
-> MonitorOptions -> Identity MonitorOptions
forall s a. HasEscalationMessage s a => Lens' s a
escalationMessage ((Text -> Identity Text)
-> MonitorOptions -> Identity MonitorOptions)
-> Text -> MonitorOptions -> MonitorOptions
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Text
msg
where stamp :: Integer
stamp = POSIXTime -> Integer
forall a b. (RealFrac a, Integral b) => a -> b
floor (POSIXTime
difftime POSIXTime -> POSIXTime -> POSIXTime
forall a. Fractional a => a -> a -> a
/ POSIXTime
60)
msg :: Text
msg = Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
"" Maybe Text
mMessage
noRenotifyMonitor :: MonitorOptions -> MonitorOptions
noRenotifyMonitor :: MonitorOptions -> MonitorOptions
noRenotifyMonitor MonitorOptions
old = MonitorOptions
old MonitorOptions
-> (MonitorOptions -> MonitorOptions) -> MonitorOptions
forall a b. a -> (a -> b) -> b
& (Maybe Integer -> Identity (Maybe Integer))
-> MonitorOptions -> Identity MonitorOptions
forall s a. HasRenotifyInterval s a => Lens' s a
renotifyInterval ((Maybe Integer -> Identity (Maybe Integer))
-> MonitorOptions -> Identity MonitorOptions)
-> Maybe Integer -> MonitorOptions -> MonitorOptions
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Maybe Integer
forall a. Maybe a
Nothing MonitorOptions
-> (MonitorOptions -> MonitorOptions) -> MonitorOptions
forall a b. a -> (a -> b) -> b
& (Text -> Identity Text)
-> MonitorOptions -> Identity MonitorOptions
forall s a. HasEscalationMessage s a => Lens' s a
escalationMessage ((Text -> Identity Text)
-> MonitorOptions -> Identity MonitorOptions)
-> Text -> MonitorOptions -> MonitorOptions
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Text
""
doesNotifyOnAudit :: MonitorOptions -> Bool
doesNotifyOnAudit :: MonitorOptions -> Bool
doesNotifyOnAudit = Getting Bool MonitorOptions Bool -> MonitorOptions -> Bool
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting Bool MonitorOptions Bool
forall s a. HasNotifyAudit s a => Lens' s a
notifyAudit
notifyOnAudit :: MonitorOptions -> MonitorOptions
notifyOnAudit :: MonitorOptions -> MonitorOptions
notifyOnAudit = ((Bool -> Identity Bool)
-> MonitorOptions -> Identity MonitorOptions)
-> Bool -> MonitorOptions -> MonitorOptions
forall s t a b. ASetter s t a b -> b -> s -> t
set (Bool -> Identity Bool)
-> MonitorOptions -> Identity MonitorOptions
forall s a. HasNotifyAudit s a => Lens' s a
notifyAudit Bool
True
noNotifyOnAudit :: MonitorOptions -> MonitorOptions
noNotifyOnAudit :: MonitorOptions -> MonitorOptions
noNotifyOnAudit = ((Bool -> Identity Bool)
-> MonitorOptions -> Identity MonitorOptions)
-> Bool -> MonitorOptions -> MonitorOptions
forall s t a b. ASetter s t a b -> b -> s -> t
set (Bool -> Identity Bool)
-> MonitorOptions -> Identity MonitorOptions
forall s a. HasNotifyAudit s a => Lens' s a
notifyAudit Bool
False
minimalMonitorSpec :: MonitorType -> T.Text -> MonitorSpec
minimalMonitorSpec :: MonitorType -> Text -> MonitorSpec
minimalMonitorSpec MonitorType
cmtype Text
cmquery = MonitorSpec :: MonitorType
-> Text
-> Maybe Text
-> Maybe Text
-> MonitorOptions
-> MonitorSpec
MonitorSpec { monitorSpecType' :: MonitorType
monitorSpecType' = MonitorType
cmtype
, monitorSpecQuery :: Text
monitorSpecQuery = Text
cmquery
, monitorSpecName :: Maybe Text
monitorSpecName = Maybe Text
forall a. Maybe a
Nothing
, monitorSpecMessage :: Maybe Text
monitorSpecMessage = Maybe Text
forall a. Maybe a
Nothing
, monitorSpecOptions :: MonitorOptions
monitorSpecOptions = MonitorOptions
defaultMonitorOptions
}
createMonitor :: Environment -> MonitorSpec -> IO Monitor
createMonitor :: Environment -> MonitorSpec -> IO Monitor
createMonitor Environment
env MonitorSpec
monitorspec =
let path :: p
path = p
"monitor"
in Environment
-> String
-> [(String, String)]
-> StdMethod
-> Maybe ByteString
-> IO ByteString
datadogHttp Environment
env String
forall p. IsString p => p
path [] StdMethod
POST (ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just (ByteString -> Maybe ByteString) -> ByteString -> Maybe ByteString
forall a b. (a -> b) -> a -> b
$ MonitorSpec -> ByteString
forall a. ToJSON a => a -> ByteString
encode MonitorSpec
monitorspec) IO ByteString -> (ByteString -> IO Monitor) -> IO Monitor
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
String -> ByteString -> IO Monitor
forall a. FromJSON a => String -> ByteString -> IO a
decodeDatadog String
"createMonitor"
loadMonitor :: Environment -> MonitorId -> IO Monitor
loadMonitor :: Environment -> MonitorId -> IO Monitor
loadMonitor Environment
env MonitorId
monitorId =
let path :: String
path = String
"monitor/" String -> String -> String
forall a. [a] -> [a] -> [a]
++ MonitorId -> String
forall a. Show a => a -> String
show MonitorId
monitorId
in Environment
-> String
-> [(String, String)]
-> StdMethod
-> Maybe ByteString
-> IO ByteString
datadogHttp Environment
env String
path [] StdMethod
GET Maybe ByteString
forall a. Maybe a
Nothing IO ByteString -> (ByteString -> IO Monitor) -> IO Monitor
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
String -> ByteString -> IO Monitor
forall a. FromJSON a => String -> ByteString -> IO a
decodeDatadog String
"loadMonitor"
updateMonitor :: Environment -> MonitorId -> MonitorSpec -> IO Monitor
updateMonitor :: Environment -> MonitorId -> MonitorSpec -> IO Monitor
updateMonitor Environment
env MonitorId
monitorId MonitorSpec
mspec =
let path :: String
path = String
"monitor/" String -> String -> String
forall a. [a] -> [a] -> [a]
++ MonitorId -> String
forall a. Show a => a -> String
show MonitorId
monitorId
in Environment
-> String
-> [(String, String)]
-> StdMethod
-> Maybe ByteString
-> IO ByteString
datadogHttp Environment
env String
path [] StdMethod
PUT (ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just (ByteString -> Maybe ByteString) -> ByteString -> Maybe ByteString
forall a b. (a -> b) -> a -> b
$ MonitorSpec -> ByteString
forall a. ToJSON a => a -> ByteString
encode MonitorSpec
mspec) IO ByteString -> (ByteString -> IO Monitor) -> IO Monitor
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
String -> ByteString -> IO Monitor
forall a. FromJSON a => String -> ByteString -> IO a
decodeDatadog String
"updateMonitor"
deleteMonitor :: Environment -> MonitorId -> IO ()
deleteMonitor :: Environment -> MonitorId -> IO ()
deleteMonitor Environment
env MonitorId
monitorId =
let path :: String
path = String
"monitor/" String -> String -> String
forall a. [a] -> [a] -> [a]
++ MonitorId -> String
forall a. Show a => a -> String
show MonitorId
monitorId
in IO ByteString -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO ByteString -> IO ()) -> IO ByteString -> IO ()
forall a b. (a -> b) -> a -> b
$ Environment
-> String
-> [(String, String)]
-> StdMethod
-> Maybe ByteString
-> IO ByteString
datadogHttp Environment
env String
path [] StdMethod
DELETE Maybe ByteString
forall a. Maybe a
Nothing
loadMonitors :: Environment
-> [Tag]
-> IO [Monitor]
loadMonitors :: Environment -> [Tag] -> IO [Monitor]
loadMonitors Environment
env [Tag]
filterTags =
let path :: p
path = p
"monitor"
q :: [(String, String)]
q = [(String
"tags", String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
"," ((Tag -> String) -> [Tag] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Tag -> String
forall a. Show a => a -> String
show [Tag]
filterTags)) | Bool -> Bool
not ([Tag] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Tag]
filterTags)]
in Environment
-> String
-> [(String, String)]
-> StdMethod
-> Maybe ByteString
-> IO ByteString
datadogHttp Environment
env String
forall p. IsString p => p
path [(String, String)]
q StdMethod
GET Maybe ByteString
forall a. Maybe a
Nothing IO ByteString -> (ByteString -> IO [Monitor]) -> IO [Monitor]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
String -> ByteString -> IO [Monitor]
forall a. FromJSON a => String -> ByteString -> IO a
decodeDatadog String
"loadMonitors"
muteAllMonitors :: Environment -> IO ()
muteAllMonitors :: Environment -> IO ()
muteAllMonitors Environment
env =
let path :: p
path = p
"monitor/mute_all"
in IO ByteString -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO ByteString -> IO ()) -> IO ByteString -> IO ()
forall a b. (a -> b) -> a -> b
$ Environment
-> String
-> [(String, String)]
-> StdMethod
-> Maybe ByteString
-> IO ByteString
datadogHttp Environment
env String
forall p. IsString p => p
path [] StdMethod
POST Maybe ByteString
forall a. Maybe a
Nothing
unmuteAllMonitors :: Environment -> IO ()
unmuteAllMonitors :: Environment -> IO ()
unmuteAllMonitors Environment
env =
let path :: p
path = p
"monitor/unmute_all"
in IO ByteString -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO ByteString -> IO ()) -> IO ByteString -> IO ()
forall a b. (a -> b) -> a -> b
$ Environment
-> String
-> [(String, String)]
-> StdMethod
-> Maybe ByteString
-> IO ByteString
datadogHttp Environment
env String
forall p. IsString p => p
path [] StdMethod
POST Maybe ByteString
forall a. Maybe a
Nothing