{-# 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.IoT.Types.Behavior
-- 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.IoT.Types.Behavior where

import qualified Amazonka.Core as Core
import Amazonka.IoT.Types.BehaviorCriteria
import Amazonka.IoT.Types.MetricDimension
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A Device Defender security profile behavior.
--
-- /See:/ 'newBehavior' smart constructor.
data Behavior = Behavior'
  { -- | Suppresses alerts.
    Behavior -> Maybe Bool
suppressAlerts :: Prelude.Maybe Prelude.Bool,
    -- | The dimension for a metric in your behavior. For example, using a
    -- @TOPIC_FILTER@ dimension, you can narrow down the scope of the metric to
    -- only MQTT topics where the name matches the pattern specified in the
    -- dimension. This can\'t be used with custom metrics.
    Behavior -> Maybe MetricDimension
metricDimension :: Prelude.Maybe MetricDimension,
    -- | What is measured by the behavior.
    Behavior -> Maybe Text
metric :: Prelude.Maybe Prelude.Text,
    -- | The criteria that determine if a device is behaving normally in regard
    -- to the @metric@.
    Behavior -> Maybe BehaviorCriteria
criteria :: Prelude.Maybe BehaviorCriteria,
    -- | The name you\'ve given to the behavior.
    Behavior -> Text
name :: Prelude.Text
  }
  deriving (Behavior -> Behavior -> Bool
(Behavior -> Behavior -> Bool)
-> (Behavior -> Behavior -> Bool) -> Eq Behavior
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Behavior -> Behavior -> Bool
$c/= :: Behavior -> Behavior -> Bool
== :: Behavior -> Behavior -> Bool
$c== :: Behavior -> Behavior -> Bool
Prelude.Eq, ReadPrec [Behavior]
ReadPrec Behavior
Int -> ReadS Behavior
ReadS [Behavior]
(Int -> ReadS Behavior)
-> ReadS [Behavior]
-> ReadPrec Behavior
-> ReadPrec [Behavior]
-> Read Behavior
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Behavior]
$creadListPrec :: ReadPrec [Behavior]
readPrec :: ReadPrec Behavior
$creadPrec :: ReadPrec Behavior
readList :: ReadS [Behavior]
$creadList :: ReadS [Behavior]
readsPrec :: Int -> ReadS Behavior
$creadsPrec :: Int -> ReadS Behavior
Prelude.Read, Int -> Behavior -> ShowS
[Behavior] -> ShowS
Behavior -> String
(Int -> Behavior -> ShowS)
-> (Behavior -> String) -> ([Behavior] -> ShowS) -> Show Behavior
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Behavior] -> ShowS
$cshowList :: [Behavior] -> ShowS
show :: Behavior -> String
$cshow :: Behavior -> String
showsPrec :: Int -> Behavior -> ShowS
$cshowsPrec :: Int -> Behavior -> ShowS
Prelude.Show, (forall x. Behavior -> Rep Behavior x)
-> (forall x. Rep Behavior x -> Behavior) -> Generic Behavior
forall x. Rep Behavior x -> Behavior
forall x. Behavior -> Rep Behavior x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Behavior x -> Behavior
$cfrom :: forall x. Behavior -> Rep Behavior x
Prelude.Generic)

-- |
-- Create a value of 'Behavior' 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:
--
-- 'suppressAlerts', 'behavior_suppressAlerts' - Suppresses alerts.
--
-- 'metricDimension', 'behavior_metricDimension' - The dimension for a metric in your behavior. For example, using a
-- @TOPIC_FILTER@ dimension, you can narrow down the scope of the metric to
-- only MQTT topics where the name matches the pattern specified in the
-- dimension. This can\'t be used with custom metrics.
--
-- 'metric', 'behavior_metric' - What is measured by the behavior.
--
-- 'criteria', 'behavior_criteria' - The criteria that determine if a device is behaving normally in regard
-- to the @metric@.
--
-- 'name', 'behavior_name' - The name you\'ve given to the behavior.
newBehavior ::
  -- | 'name'
  Prelude.Text ->
  Behavior
newBehavior :: Text -> Behavior
newBehavior Text
pName_ =
  Behavior' :: Maybe Bool
-> Maybe MetricDimension
-> Maybe Text
-> Maybe BehaviorCriteria
-> Text
-> Behavior
Behavior'
    { $sel:suppressAlerts:Behavior' :: Maybe Bool
suppressAlerts = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:metricDimension:Behavior' :: Maybe MetricDimension
metricDimension = Maybe MetricDimension
forall a. Maybe a
Prelude.Nothing,
      $sel:metric:Behavior' :: Maybe Text
metric = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:criteria:Behavior' :: Maybe BehaviorCriteria
criteria = Maybe BehaviorCriteria
forall a. Maybe a
Prelude.Nothing,
      $sel:name:Behavior' :: Text
name = Text
pName_
    }

-- | Suppresses alerts.
behavior_suppressAlerts :: Lens.Lens' Behavior (Prelude.Maybe Prelude.Bool)
behavior_suppressAlerts :: (Maybe Bool -> f (Maybe Bool)) -> Behavior -> f Behavior
behavior_suppressAlerts = (Behavior -> Maybe Bool)
-> (Behavior -> Maybe Bool -> Behavior)
-> Lens Behavior Behavior (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Behavior' {Maybe Bool
suppressAlerts :: Maybe Bool
$sel:suppressAlerts:Behavior' :: Behavior -> Maybe Bool
suppressAlerts} -> Maybe Bool
suppressAlerts) (\s :: Behavior
s@Behavior' {} Maybe Bool
a -> Behavior
s {$sel:suppressAlerts:Behavior' :: Maybe Bool
suppressAlerts = Maybe Bool
a} :: Behavior)

-- | The dimension for a metric in your behavior. For example, using a
-- @TOPIC_FILTER@ dimension, you can narrow down the scope of the metric to
-- only MQTT topics where the name matches the pattern specified in the
-- dimension. This can\'t be used with custom metrics.
behavior_metricDimension :: Lens.Lens' Behavior (Prelude.Maybe MetricDimension)
behavior_metricDimension :: (Maybe MetricDimension -> f (Maybe MetricDimension))
-> Behavior -> f Behavior
behavior_metricDimension = (Behavior -> Maybe MetricDimension)
-> (Behavior -> Maybe MetricDimension -> Behavior)
-> Lens
     Behavior Behavior (Maybe MetricDimension) (Maybe MetricDimension)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Behavior' {Maybe MetricDimension
metricDimension :: Maybe MetricDimension
$sel:metricDimension:Behavior' :: Behavior -> Maybe MetricDimension
metricDimension} -> Maybe MetricDimension
metricDimension) (\s :: Behavior
s@Behavior' {} Maybe MetricDimension
a -> Behavior
s {$sel:metricDimension:Behavior' :: Maybe MetricDimension
metricDimension = Maybe MetricDimension
a} :: Behavior)

-- | What is measured by the behavior.
behavior_metric :: Lens.Lens' Behavior (Prelude.Maybe Prelude.Text)
behavior_metric :: (Maybe Text -> f (Maybe Text)) -> Behavior -> f Behavior
behavior_metric = (Behavior -> Maybe Text)
-> (Behavior -> Maybe Text -> Behavior)
-> Lens Behavior Behavior (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Behavior' {Maybe Text
metric :: Maybe Text
$sel:metric:Behavior' :: Behavior -> Maybe Text
metric} -> Maybe Text
metric) (\s :: Behavior
s@Behavior' {} Maybe Text
a -> Behavior
s {$sel:metric:Behavior' :: Maybe Text
metric = Maybe Text
a} :: Behavior)

-- | The criteria that determine if a device is behaving normally in regard
-- to the @metric@.
behavior_criteria :: Lens.Lens' Behavior (Prelude.Maybe BehaviorCriteria)
behavior_criteria :: (Maybe BehaviorCriteria -> f (Maybe BehaviorCriteria))
-> Behavior -> f Behavior
behavior_criteria = (Behavior -> Maybe BehaviorCriteria)
-> (Behavior -> Maybe BehaviorCriteria -> Behavior)
-> Lens
     Behavior Behavior (Maybe BehaviorCriteria) (Maybe BehaviorCriteria)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Behavior' {Maybe BehaviorCriteria
criteria :: Maybe BehaviorCriteria
$sel:criteria:Behavior' :: Behavior -> Maybe BehaviorCriteria
criteria} -> Maybe BehaviorCriteria
criteria) (\s :: Behavior
s@Behavior' {} Maybe BehaviorCriteria
a -> Behavior
s {$sel:criteria:Behavior' :: Maybe BehaviorCriteria
criteria = Maybe BehaviorCriteria
a} :: Behavior)

-- | The name you\'ve given to the behavior.
behavior_name :: Lens.Lens' Behavior Prelude.Text
behavior_name :: (Text -> f Text) -> Behavior -> f Behavior
behavior_name = (Behavior -> Text)
-> (Behavior -> Text -> Behavior)
-> Lens Behavior Behavior Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Behavior' {Text
name :: Text
$sel:name:Behavior' :: Behavior -> Text
name} -> Text
name) (\s :: Behavior
s@Behavior' {} Text
a -> Behavior
s {$sel:name:Behavior' :: Text
name = Text
a} :: Behavior)

instance Core.FromJSON Behavior where
  parseJSON :: Value -> Parser Behavior
parseJSON =
    String -> (Object -> Parser Behavior) -> Value -> Parser Behavior
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Behavior"
      ( \Object
x ->
          Maybe Bool
-> Maybe MetricDimension
-> Maybe Text
-> Maybe BehaviorCriteria
-> Text
-> Behavior
Behavior'
            (Maybe Bool
 -> Maybe MetricDimension
 -> Maybe Text
 -> Maybe BehaviorCriteria
 -> Text
 -> Behavior)
-> Parser (Maybe Bool)
-> Parser
     (Maybe MetricDimension
      -> Maybe Text -> Maybe BehaviorCriteria -> Text -> Behavior)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"suppressAlerts")
            Parser
  (Maybe MetricDimension
   -> Maybe Text -> Maybe BehaviorCriteria -> Text -> Behavior)
-> Parser (Maybe MetricDimension)
-> Parser
     (Maybe Text -> Maybe BehaviorCriteria -> Text -> Behavior)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe MetricDimension)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"metricDimension")
            Parser (Maybe Text -> Maybe BehaviorCriteria -> Text -> Behavior)
-> Parser (Maybe Text)
-> Parser (Maybe BehaviorCriteria -> Text -> Behavior)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"metric")
            Parser (Maybe BehaviorCriteria -> Text -> Behavior)
-> Parser (Maybe BehaviorCriteria) -> Parser (Text -> Behavior)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe BehaviorCriteria)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"criteria")
            Parser (Text -> Behavior) -> Parser Text -> Parser Behavior
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"name")
      )

instance Prelude.Hashable Behavior

instance Prelude.NFData Behavior

instance Core.ToJSON Behavior where
  toJSON :: Behavior -> Value
toJSON Behavior' {Maybe Bool
Maybe Text
Maybe MetricDimension
Maybe BehaviorCriteria
Text
name :: Text
criteria :: Maybe BehaviorCriteria
metric :: Maybe Text
metricDimension :: Maybe MetricDimension
suppressAlerts :: Maybe Bool
$sel:name:Behavior' :: Behavior -> Text
$sel:criteria:Behavior' :: Behavior -> Maybe BehaviorCriteria
$sel:metric:Behavior' :: Behavior -> Maybe Text
$sel:metricDimension:Behavior' :: Behavior -> Maybe MetricDimension
$sel:suppressAlerts:Behavior' :: Behavior -> Maybe Bool
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"suppressAlerts" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
suppressAlerts,
            (Text
"metricDimension" Text -> MetricDimension -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (MetricDimension -> Pair) -> Maybe MetricDimension -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe MetricDimension
metricDimension,
            (Text
"metric" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
metric,
            (Text
"criteria" Text -> BehaviorCriteria -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (BehaviorCriteria -> Pair) -> Maybe BehaviorCriteria -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe BehaviorCriteria
criteria,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name)
          ]
      )