{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.CloudWatch.Types.AnomalyDetector
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CloudWatch.Types.AnomalyDetector where

import Amazonka.CloudWatch.Types.AnomalyDetectorConfiguration
import Amazonka.CloudWatch.Types.AnomalyDetectorStateValue
import Amazonka.CloudWatch.Types.Dimension
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An anomaly detection model associated with a particular CloudWatch
-- metric and statistic. You can use the model to display a band of
-- expected normal values when the metric is graphed.
--
-- /See:/ 'newAnomalyDetector' smart constructor.
data AnomalyDetector = AnomalyDetector'
  { -- | The name of the metric associated with the anomaly detection model.
    AnomalyDetector -> Maybe Text
metricName :: Prelude.Maybe Prelude.Text,
    -- | The namespace of the metric associated with the anomaly detection model.
    AnomalyDetector -> Maybe Text
namespace :: Prelude.Maybe Prelude.Text,
    -- | The current status of the anomaly detector\'s training. The possible
    -- values are @TRAINED | PENDING_TRAINING | TRAINED_INSUFFICIENT_DATA@
    AnomalyDetector -> Maybe AnomalyDetectorStateValue
stateValue :: Prelude.Maybe AnomalyDetectorStateValue,
    -- | The statistic associated with the anomaly detection model.
    AnomalyDetector -> Maybe Text
stat :: Prelude.Maybe Prelude.Text,
    -- | The configuration specifies details about how the anomaly detection
    -- model is to be trained, including time ranges to exclude from use for
    -- training the model, and the time zone to use for the metric.
    AnomalyDetector -> Maybe AnomalyDetectorConfiguration
configuration :: Prelude.Maybe AnomalyDetectorConfiguration,
    -- | The metric dimensions associated with the anomaly detection model.
    AnomalyDetector -> Maybe [Dimension]
dimensions :: Prelude.Maybe [Dimension]
  }
  deriving (AnomalyDetector -> AnomalyDetector -> Bool
(AnomalyDetector -> AnomalyDetector -> Bool)
-> (AnomalyDetector -> AnomalyDetector -> Bool)
-> Eq AnomalyDetector
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AnomalyDetector -> AnomalyDetector -> Bool
$c/= :: AnomalyDetector -> AnomalyDetector -> Bool
== :: AnomalyDetector -> AnomalyDetector -> Bool
$c== :: AnomalyDetector -> AnomalyDetector -> Bool
Prelude.Eq, ReadPrec [AnomalyDetector]
ReadPrec AnomalyDetector
Int -> ReadS AnomalyDetector
ReadS [AnomalyDetector]
(Int -> ReadS AnomalyDetector)
-> ReadS [AnomalyDetector]
-> ReadPrec AnomalyDetector
-> ReadPrec [AnomalyDetector]
-> Read AnomalyDetector
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AnomalyDetector]
$creadListPrec :: ReadPrec [AnomalyDetector]
readPrec :: ReadPrec AnomalyDetector
$creadPrec :: ReadPrec AnomalyDetector
readList :: ReadS [AnomalyDetector]
$creadList :: ReadS [AnomalyDetector]
readsPrec :: Int -> ReadS AnomalyDetector
$creadsPrec :: Int -> ReadS AnomalyDetector
Prelude.Read, Int -> AnomalyDetector -> ShowS
[AnomalyDetector] -> ShowS
AnomalyDetector -> String
(Int -> AnomalyDetector -> ShowS)
-> (AnomalyDetector -> String)
-> ([AnomalyDetector] -> ShowS)
-> Show AnomalyDetector
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AnomalyDetector] -> ShowS
$cshowList :: [AnomalyDetector] -> ShowS
show :: AnomalyDetector -> String
$cshow :: AnomalyDetector -> String
showsPrec :: Int -> AnomalyDetector -> ShowS
$cshowsPrec :: Int -> AnomalyDetector -> ShowS
Prelude.Show, (forall x. AnomalyDetector -> Rep AnomalyDetector x)
-> (forall x. Rep AnomalyDetector x -> AnomalyDetector)
-> Generic AnomalyDetector
forall x. Rep AnomalyDetector x -> AnomalyDetector
forall x. AnomalyDetector -> Rep AnomalyDetector x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AnomalyDetector x -> AnomalyDetector
$cfrom :: forall x. AnomalyDetector -> Rep AnomalyDetector x
Prelude.Generic)

-- |
-- Create a value of 'AnomalyDetector' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'metricName', 'anomalyDetector_metricName' - The name of the metric associated with the anomaly detection model.
--
-- 'namespace', 'anomalyDetector_namespace' - The namespace of the metric associated with the anomaly detection model.
--
-- 'stateValue', 'anomalyDetector_stateValue' - The current status of the anomaly detector\'s training. The possible
-- values are @TRAINED | PENDING_TRAINING | TRAINED_INSUFFICIENT_DATA@
--
-- 'stat', 'anomalyDetector_stat' - The statistic associated with the anomaly detection model.
--
-- 'configuration', 'anomalyDetector_configuration' - The configuration specifies details about how the anomaly detection
-- model is to be trained, including time ranges to exclude from use for
-- training the model, and the time zone to use for the metric.
--
-- 'dimensions', 'anomalyDetector_dimensions' - The metric dimensions associated with the anomaly detection model.
newAnomalyDetector ::
  AnomalyDetector
newAnomalyDetector :: AnomalyDetector
newAnomalyDetector =
  AnomalyDetector' :: Maybe Text
-> Maybe Text
-> Maybe AnomalyDetectorStateValue
-> Maybe Text
-> Maybe AnomalyDetectorConfiguration
-> Maybe [Dimension]
-> AnomalyDetector
AnomalyDetector'
    { $sel:metricName:AnomalyDetector' :: Maybe Text
metricName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:namespace:AnomalyDetector' :: Maybe Text
namespace = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:stateValue:AnomalyDetector' :: Maybe AnomalyDetectorStateValue
stateValue = Maybe AnomalyDetectorStateValue
forall a. Maybe a
Prelude.Nothing,
      $sel:stat:AnomalyDetector' :: Maybe Text
stat = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:configuration:AnomalyDetector' :: Maybe AnomalyDetectorConfiguration
configuration = Maybe AnomalyDetectorConfiguration
forall a. Maybe a
Prelude.Nothing,
      $sel:dimensions:AnomalyDetector' :: Maybe [Dimension]
dimensions = Maybe [Dimension]
forall a. Maybe a
Prelude.Nothing
    }

-- | The name of the metric associated with the anomaly detection model.
anomalyDetector_metricName :: Lens.Lens' AnomalyDetector (Prelude.Maybe Prelude.Text)
anomalyDetector_metricName :: (Maybe Text -> f (Maybe Text))
-> AnomalyDetector -> f AnomalyDetector
anomalyDetector_metricName = (AnomalyDetector -> Maybe Text)
-> (AnomalyDetector -> Maybe Text -> AnomalyDetector)
-> Lens AnomalyDetector AnomalyDetector (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AnomalyDetector' {Maybe Text
metricName :: Maybe Text
$sel:metricName:AnomalyDetector' :: AnomalyDetector -> Maybe Text
metricName} -> Maybe Text
metricName) (\s :: AnomalyDetector
s@AnomalyDetector' {} Maybe Text
a -> AnomalyDetector
s {$sel:metricName:AnomalyDetector' :: Maybe Text
metricName = Maybe Text
a} :: AnomalyDetector)

-- | The namespace of the metric associated with the anomaly detection model.
anomalyDetector_namespace :: Lens.Lens' AnomalyDetector (Prelude.Maybe Prelude.Text)
anomalyDetector_namespace :: (Maybe Text -> f (Maybe Text))
-> AnomalyDetector -> f AnomalyDetector
anomalyDetector_namespace = (AnomalyDetector -> Maybe Text)
-> (AnomalyDetector -> Maybe Text -> AnomalyDetector)
-> Lens AnomalyDetector AnomalyDetector (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AnomalyDetector' {Maybe Text
namespace :: Maybe Text
$sel:namespace:AnomalyDetector' :: AnomalyDetector -> Maybe Text
namespace} -> Maybe Text
namespace) (\s :: AnomalyDetector
s@AnomalyDetector' {} Maybe Text
a -> AnomalyDetector
s {$sel:namespace:AnomalyDetector' :: Maybe Text
namespace = Maybe Text
a} :: AnomalyDetector)

-- | The current status of the anomaly detector\'s training. The possible
-- values are @TRAINED | PENDING_TRAINING | TRAINED_INSUFFICIENT_DATA@
anomalyDetector_stateValue :: Lens.Lens' AnomalyDetector (Prelude.Maybe AnomalyDetectorStateValue)
anomalyDetector_stateValue :: (Maybe AnomalyDetectorStateValue
 -> f (Maybe AnomalyDetectorStateValue))
-> AnomalyDetector -> f AnomalyDetector
anomalyDetector_stateValue = (AnomalyDetector -> Maybe AnomalyDetectorStateValue)
-> (AnomalyDetector
    -> Maybe AnomalyDetectorStateValue -> AnomalyDetector)
-> Lens
     AnomalyDetector
     AnomalyDetector
     (Maybe AnomalyDetectorStateValue)
     (Maybe AnomalyDetectorStateValue)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AnomalyDetector' {Maybe AnomalyDetectorStateValue
stateValue :: Maybe AnomalyDetectorStateValue
$sel:stateValue:AnomalyDetector' :: AnomalyDetector -> Maybe AnomalyDetectorStateValue
stateValue} -> Maybe AnomalyDetectorStateValue
stateValue) (\s :: AnomalyDetector
s@AnomalyDetector' {} Maybe AnomalyDetectorStateValue
a -> AnomalyDetector
s {$sel:stateValue:AnomalyDetector' :: Maybe AnomalyDetectorStateValue
stateValue = Maybe AnomalyDetectorStateValue
a} :: AnomalyDetector)

-- | The statistic associated with the anomaly detection model.
anomalyDetector_stat :: Lens.Lens' AnomalyDetector (Prelude.Maybe Prelude.Text)
anomalyDetector_stat :: (Maybe Text -> f (Maybe Text))
-> AnomalyDetector -> f AnomalyDetector
anomalyDetector_stat = (AnomalyDetector -> Maybe Text)
-> (AnomalyDetector -> Maybe Text -> AnomalyDetector)
-> Lens AnomalyDetector AnomalyDetector (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AnomalyDetector' {Maybe Text
stat :: Maybe Text
$sel:stat:AnomalyDetector' :: AnomalyDetector -> Maybe Text
stat} -> Maybe Text
stat) (\s :: AnomalyDetector
s@AnomalyDetector' {} Maybe Text
a -> AnomalyDetector
s {$sel:stat:AnomalyDetector' :: Maybe Text
stat = Maybe Text
a} :: AnomalyDetector)

-- | The configuration specifies details about how the anomaly detection
-- model is to be trained, including time ranges to exclude from use for
-- training the model, and the time zone to use for the metric.
anomalyDetector_configuration :: Lens.Lens' AnomalyDetector (Prelude.Maybe AnomalyDetectorConfiguration)
anomalyDetector_configuration :: (Maybe AnomalyDetectorConfiguration
 -> f (Maybe AnomalyDetectorConfiguration))
-> AnomalyDetector -> f AnomalyDetector
anomalyDetector_configuration = (AnomalyDetector -> Maybe AnomalyDetectorConfiguration)
-> (AnomalyDetector
    -> Maybe AnomalyDetectorConfiguration -> AnomalyDetector)
-> Lens
     AnomalyDetector
     AnomalyDetector
     (Maybe AnomalyDetectorConfiguration)
     (Maybe AnomalyDetectorConfiguration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AnomalyDetector' {Maybe AnomalyDetectorConfiguration
configuration :: Maybe AnomalyDetectorConfiguration
$sel:configuration:AnomalyDetector' :: AnomalyDetector -> Maybe AnomalyDetectorConfiguration
configuration} -> Maybe AnomalyDetectorConfiguration
configuration) (\s :: AnomalyDetector
s@AnomalyDetector' {} Maybe AnomalyDetectorConfiguration
a -> AnomalyDetector
s {$sel:configuration:AnomalyDetector' :: Maybe AnomalyDetectorConfiguration
configuration = Maybe AnomalyDetectorConfiguration
a} :: AnomalyDetector)

-- | The metric dimensions associated with the anomaly detection model.
anomalyDetector_dimensions :: Lens.Lens' AnomalyDetector (Prelude.Maybe [Dimension])
anomalyDetector_dimensions :: (Maybe [Dimension] -> f (Maybe [Dimension]))
-> AnomalyDetector -> f AnomalyDetector
anomalyDetector_dimensions = (AnomalyDetector -> Maybe [Dimension])
-> (AnomalyDetector -> Maybe [Dimension] -> AnomalyDetector)
-> Lens
     AnomalyDetector
     AnomalyDetector
     (Maybe [Dimension])
     (Maybe [Dimension])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AnomalyDetector' {Maybe [Dimension]
dimensions :: Maybe [Dimension]
$sel:dimensions:AnomalyDetector' :: AnomalyDetector -> Maybe [Dimension]
dimensions} -> Maybe [Dimension]
dimensions) (\s :: AnomalyDetector
s@AnomalyDetector' {} Maybe [Dimension]
a -> AnomalyDetector
s {$sel:dimensions:AnomalyDetector' :: Maybe [Dimension]
dimensions = Maybe [Dimension]
a} :: AnomalyDetector) ((Maybe [Dimension] -> f (Maybe [Dimension]))
 -> AnomalyDetector -> f AnomalyDetector)
-> ((Maybe [Dimension] -> f (Maybe [Dimension]))
    -> Maybe [Dimension] -> f (Maybe [Dimension]))
-> (Maybe [Dimension] -> f (Maybe [Dimension]))
-> AnomalyDetector
-> f AnomalyDetector
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Dimension] [Dimension] [Dimension] [Dimension]
-> Iso
     (Maybe [Dimension])
     (Maybe [Dimension])
     (Maybe [Dimension])
     (Maybe [Dimension])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Dimension] [Dimension] [Dimension] [Dimension]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromXML AnomalyDetector where
  parseXML :: [Node] -> Either String AnomalyDetector
parseXML [Node]
x =
    Maybe Text
-> Maybe Text
-> Maybe AnomalyDetectorStateValue
-> Maybe Text
-> Maybe AnomalyDetectorConfiguration
-> Maybe [Dimension]
-> AnomalyDetector
AnomalyDetector'
      (Maybe Text
 -> Maybe Text
 -> Maybe AnomalyDetectorStateValue
 -> Maybe Text
 -> Maybe AnomalyDetectorConfiguration
 -> Maybe [Dimension]
 -> AnomalyDetector)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe Text
      -> Maybe AnomalyDetectorStateValue
      -> Maybe Text
      -> Maybe AnomalyDetectorConfiguration
      -> Maybe [Dimension]
      -> AnomalyDetector)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"MetricName")
      Either
  String
  (Maybe Text
   -> Maybe AnomalyDetectorStateValue
   -> Maybe Text
   -> Maybe AnomalyDetectorConfiguration
   -> Maybe [Dimension]
   -> AnomalyDetector)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe AnomalyDetectorStateValue
      -> Maybe Text
      -> Maybe AnomalyDetectorConfiguration
      -> Maybe [Dimension]
      -> AnomalyDetector)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Namespace")
      Either
  String
  (Maybe AnomalyDetectorStateValue
   -> Maybe Text
   -> Maybe AnomalyDetectorConfiguration
   -> Maybe [Dimension]
   -> AnomalyDetector)
-> Either String (Maybe AnomalyDetectorStateValue)
-> Either
     String
     (Maybe Text
      -> Maybe AnomalyDetectorConfiguration
      -> Maybe [Dimension]
      -> AnomalyDetector)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe AnomalyDetectorStateValue)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"StateValue")
      Either
  String
  (Maybe Text
   -> Maybe AnomalyDetectorConfiguration
   -> Maybe [Dimension]
   -> AnomalyDetector)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe AnomalyDetectorConfiguration
      -> Maybe [Dimension] -> AnomalyDetector)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Stat")
      Either
  String
  (Maybe AnomalyDetectorConfiguration
   -> Maybe [Dimension] -> AnomalyDetector)
-> Either String (Maybe AnomalyDetectorConfiguration)
-> Either String (Maybe [Dimension] -> AnomalyDetector)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node]
-> Text -> Either String (Maybe AnomalyDetectorConfiguration)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Configuration")
      Either String (Maybe [Dimension] -> AnomalyDetector)
-> Either String (Maybe [Dimension])
-> Either String AnomalyDetector
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Dimensions" Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                      Either String [Node]
-> ([Node] -> Either String (Maybe [Dimension]))
-> Either String (Maybe [Dimension])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [Dimension])
-> [Node] -> Either String (Maybe [Dimension])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [Dimension]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"member")
                  )

instance Prelude.Hashable AnomalyDetector

instance Prelude.NFData AnomalyDetector