{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TemplateHaskell #-}
module Network.Datadog.Types where
import Data.ByteString.Char8 (ByteString)
import Data.DList (DList)
import Data.HashMap.Strict (HashMap)
import Data.Semigroup
import Data.Text (Text)
import qualified Data.Text as T
import Data.Int (Int64)
import Data.Time.Clock (UTCTime, NominalDiffTime)
import Data.Time.Clock.POSIX (POSIXTime)
import Network.HTTP.Client (Manager)
newtype Timestamp = Timestamp { fromTimestamp :: NominalDiffTime }
newtype Write = Write { writeApiKey :: ByteString }
data ReadWrite = ReadWrite { readWriteApiKey :: ByteString
, readWriteApplicationKey :: ByteString
}
data DatadogClient a = DatadogClient
{ datadogClientManager :: Manager
, datadogClientKeys :: a
}
data Keys = Keys { apiKey :: String
, appKey :: String
} deriving (Eq)
data Environment = Environment { environmentKeys :: Keys
, environmentApiUrl :: String
, environmentManager :: Manager
}
data Tag = KeyValueTag Text Text
| LabelTag Text
deriving (Eq)
instance Show Tag where
show (KeyValueTag k v) = T.unpack k ++ (':' : T.unpack v)
show (LabelTag t) = T.unpack t
instance Read Tag where
readsPrec _ s = let t = T.pack s
in (\a -> [(a, "")]) $
maybe (LabelTag t) (\i -> uncurry KeyValueTag (T.splitAt i t)) $
T.findIndex (==':') t
data CheckStatus = CheckOk
| CheckWarning
| CheckCritical
| CheckUnknown
deriving (Eq)
data CheckResult = CheckResult { checkResultCheck :: Text
, checkResultHostName :: Text
, checkResultStatus :: CheckStatus
, checkResultTimestamp :: Maybe UTCTime
, checkResultMessage :: Maybe Text
, checkResultTags :: [Tag]
} deriving (Eq)
data DowntimeSpec = DowntimeSpec { downtimeSpecStart :: Maybe UTCTime
, downtimeSpecEnd :: Maybe UTCTime
, downtimeSpecMessage :: Maybe Text
, downtimeSpecScope :: Tag
} deriving (Eq)
type DowntimeId = Int
data Downtime = Downtime { downtimeId' :: DowntimeId
, downtimeSpec :: DowntimeSpec
} deriving (Eq)
data EventPriority = NormalPriority
| LowPriority
deriving (Eq)
instance Show EventPriority where
show NormalPriority = "normal"
show LowPriority = "low"
data AlertType = Error
| Warning
| Info
| Success
deriving (Eq)
instance Show AlertType where
show Error = "error"
show Warning = "warning"
show Info = "info"
show Success = "success"
data SourceType = Nagios
| Hudson
| Jenkins
| User
| MyApps
| Feed
| Chef
| Puppet
| Git
| BitBucket
| Fabric
| Capistrano
deriving (Eq)
instance Show SourceType where
show Nagios = "nagios"
show Hudson = "hudson"
show Jenkins = "jenkins"
show User = "user"
show MyApps = "my apps"
show Feed = "feed"
show Chef = "chef"
show Puppet = "puppet"
show Git = "git"
show BitBucket = "bitbucket"
show Fabric = "fabric"
show Capistrano = "capistrano"
data EventSpec = EventSpec { eventSpecTitle :: Text
, eventSpecText :: Text
, eventSpecDateHappened :: UTCTime
, eventSpecPriority :: EventPriority
, eventSpecHost :: Maybe Text
, eventSpecTags :: [Tag]
, eventSpecAlertType :: AlertType
, eventSpecSourceType :: Maybe SourceType
} deriving (Eq, Show)
type EventId = Int
data Event = Event { eventId' :: EventId
, eventDetails :: EventSpec
} deriving (Eq, Show)
data WrappedEvent = WrappedEvent { wrappedEvent :: Event }
data WrappedEvents = WrappedEvents { wrappedEvents :: [Event] }
newtype Series = Series { fromSeries :: DList Metric }
deriving (Semigroup, Monoid)
data MetricPoints = Gauge [(POSIXTime, Float)]
| Counter [(POSIXTime, Int64)]
data Metric = Metric
{ metricName :: Text
, metricPoints :: MetricPoints
, metricHost :: Maybe Text
, metricTags :: [Text]
}
data MonitorType = MetricAlert
| ServiceCheck
| EventAlert
deriving (Eq)
instance Show MonitorType where
show MetricAlert = "metric alert"
show ServiceCheck = "service check"
show EventAlert = "event alert"
data MonitorOptions = MonitorOptions { monitorOptionsSilenced :: HashMap T.Text (Maybe Integer)
, monitorOptionsNotifyNoData :: Bool
, monitorOptionsNoDataTimeframe :: Maybe Integer
, monitorOptionsTimeoutH :: Maybe Integer
, monitorOptionsRenotifyInterval :: Maybe Integer
, monitorOptionsEscalationMessage :: T.Text
, monitorOptionsNotifyAudit :: Bool
} deriving (Eq)
data MonitorSpec = MonitorSpec { monitorSpecType' :: MonitorType
, monitorSpecQuery :: T.Text
, monitorSpecName :: Maybe T.Text
, monitorSpecMessage :: Maybe T.Text
, monitorSpecOptions :: MonitorOptions
} deriving (Eq)
type MonitorId = Int
data Monitor = Monitor { monitorId' :: MonitorId
, monitorSpec :: MonitorSpec
} deriving (Eq)