{-# 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.ApplicationInsights.Types.LogPattern
-- 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.ApplicationInsights.Types.LogPattern where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object that defines the log patterns that belongs to a
-- @LogPatternSet@.
--
-- /See:/ 'newLogPattern' smart constructor.
data LogPattern = LogPattern'
  { -- | A regular expression that defines the log pattern. A log pattern can
    -- contain as many as 50 characters, and it cannot be empty. The pattern
    -- must be DFA compatible. Patterns that utilize forward lookahead or
    -- backreference constructions are not supported.
    LogPattern -> Maybe Text
pattern' :: Prelude.Maybe Prelude.Text,
    -- | The name of the log pattern. A log pattern name can contain as many as
    -- 50 characters, and it cannot be empty. The characters can be Unicode
    -- letters, digits, or one of the following symbols: period, dash,
    -- underscore.
    LogPattern -> Maybe Text
patternName :: Prelude.Maybe Prelude.Text,
    -- | The name of the log pattern. A log pattern name can contain as many as
    -- 30 characters, and it cannot be empty. The characters can be Unicode
    -- letters, digits, or one of the following symbols: period, dash,
    -- underscore.
    LogPattern -> Maybe Text
patternSetName :: Prelude.Maybe Prelude.Text,
    -- | Rank of the log pattern. Must be a value between @1@ and @1,000,000@.
    -- The patterns are sorted by rank, so we recommend that you set your
    -- highest priority patterns with the lowest rank. A pattern of rank @1@
    -- will be the first to get matched to a log line. A pattern of rank
    -- @1,000,000@ will be last to get matched. When you configure custom log
    -- patterns from the console, a @Low@ severity pattern translates to a
    -- @750,000@ rank. A @Medium@ severity pattern translates to a @500,000@
    -- rank. And a @High@ severity pattern translates to a @250,000@ rank. Rank
    -- values less than @1@ or greater than @1,000,000@ are reserved for
    -- AWS-provided patterns.
    LogPattern -> Maybe Int
rank :: Prelude.Maybe Prelude.Int
  }
  deriving (LogPattern -> LogPattern -> Bool
(LogPattern -> LogPattern -> Bool)
-> (LogPattern -> LogPattern -> Bool) -> Eq LogPattern
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LogPattern -> LogPattern -> Bool
$c/= :: LogPattern -> LogPattern -> Bool
== :: LogPattern -> LogPattern -> Bool
$c== :: LogPattern -> LogPattern -> Bool
Prelude.Eq, ReadPrec [LogPattern]
ReadPrec LogPattern
Int -> ReadS LogPattern
ReadS [LogPattern]
(Int -> ReadS LogPattern)
-> ReadS [LogPattern]
-> ReadPrec LogPattern
-> ReadPrec [LogPattern]
-> Read LogPattern
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LogPattern]
$creadListPrec :: ReadPrec [LogPattern]
readPrec :: ReadPrec LogPattern
$creadPrec :: ReadPrec LogPattern
readList :: ReadS [LogPattern]
$creadList :: ReadS [LogPattern]
readsPrec :: Int -> ReadS LogPattern
$creadsPrec :: Int -> ReadS LogPattern
Prelude.Read, Int -> LogPattern -> ShowS
[LogPattern] -> ShowS
LogPattern -> String
(Int -> LogPattern -> ShowS)
-> (LogPattern -> String)
-> ([LogPattern] -> ShowS)
-> Show LogPattern
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LogPattern] -> ShowS
$cshowList :: [LogPattern] -> ShowS
show :: LogPattern -> String
$cshow :: LogPattern -> String
showsPrec :: Int -> LogPattern -> ShowS
$cshowsPrec :: Int -> LogPattern -> ShowS
Prelude.Show, (forall x. LogPattern -> Rep LogPattern x)
-> (forall x. Rep LogPattern x -> LogPattern) -> Generic LogPattern
forall x. Rep LogPattern x -> LogPattern
forall x. LogPattern -> Rep LogPattern x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LogPattern x -> LogPattern
$cfrom :: forall x. LogPattern -> Rep LogPattern x
Prelude.Generic)

-- |
-- Create a value of 'LogPattern' 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:
--
-- 'pattern'', 'logPattern_pattern' - A regular expression that defines the log pattern. A log pattern can
-- contain as many as 50 characters, and it cannot be empty. The pattern
-- must be DFA compatible. Patterns that utilize forward lookahead or
-- backreference constructions are not supported.
--
-- 'patternName', 'logPattern_patternName' - The name of the log pattern. A log pattern name can contain as many as
-- 50 characters, and it cannot be empty. The characters can be Unicode
-- letters, digits, or one of the following symbols: period, dash,
-- underscore.
--
-- 'patternSetName', 'logPattern_patternSetName' - The name of the log pattern. A log pattern name can contain as many as
-- 30 characters, and it cannot be empty. The characters can be Unicode
-- letters, digits, or one of the following symbols: period, dash,
-- underscore.
--
-- 'rank', 'logPattern_rank' - Rank of the log pattern. Must be a value between @1@ and @1,000,000@.
-- The patterns are sorted by rank, so we recommend that you set your
-- highest priority patterns with the lowest rank. A pattern of rank @1@
-- will be the first to get matched to a log line. A pattern of rank
-- @1,000,000@ will be last to get matched. When you configure custom log
-- patterns from the console, a @Low@ severity pattern translates to a
-- @750,000@ rank. A @Medium@ severity pattern translates to a @500,000@
-- rank. And a @High@ severity pattern translates to a @250,000@ rank. Rank
-- values less than @1@ or greater than @1,000,000@ are reserved for
-- AWS-provided patterns.
newLogPattern ::
  LogPattern
newLogPattern :: LogPattern
newLogPattern =
  LogPattern' :: Maybe Text -> Maybe Text -> Maybe Text -> Maybe Int -> LogPattern
LogPattern'
    { $sel:pattern':LogPattern' :: Maybe Text
pattern' = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:patternName:LogPattern' :: Maybe Text
patternName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:patternSetName:LogPattern' :: Maybe Text
patternSetName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:rank:LogPattern' :: Maybe Int
rank = Maybe Int
forall a. Maybe a
Prelude.Nothing
    }

-- | A regular expression that defines the log pattern. A log pattern can
-- contain as many as 50 characters, and it cannot be empty. The pattern
-- must be DFA compatible. Patterns that utilize forward lookahead or
-- backreference constructions are not supported.
logPattern_pattern :: Lens.Lens' LogPattern (Prelude.Maybe Prelude.Text)
logPattern_pattern :: (Maybe Text -> f (Maybe Text)) -> LogPattern -> f LogPattern
logPattern_pattern = (LogPattern -> Maybe Text)
-> (LogPattern -> Maybe Text -> LogPattern)
-> Lens LogPattern LogPattern (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LogPattern' {Maybe Text
pattern' :: Maybe Text
$sel:pattern':LogPattern' :: LogPattern -> Maybe Text
pattern'} -> Maybe Text
pattern') (\s :: LogPattern
s@LogPattern' {} Maybe Text
a -> LogPattern
s {$sel:pattern':LogPattern' :: Maybe Text
pattern' = Maybe Text
a} :: LogPattern)

-- | The name of the log pattern. A log pattern name can contain as many as
-- 50 characters, and it cannot be empty. The characters can be Unicode
-- letters, digits, or one of the following symbols: period, dash,
-- underscore.
logPattern_patternName :: Lens.Lens' LogPattern (Prelude.Maybe Prelude.Text)
logPattern_patternName :: (Maybe Text -> f (Maybe Text)) -> LogPattern -> f LogPattern
logPattern_patternName = (LogPattern -> Maybe Text)
-> (LogPattern -> Maybe Text -> LogPattern)
-> Lens LogPattern LogPattern (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LogPattern' {Maybe Text
patternName :: Maybe Text
$sel:patternName:LogPattern' :: LogPattern -> Maybe Text
patternName} -> Maybe Text
patternName) (\s :: LogPattern
s@LogPattern' {} Maybe Text
a -> LogPattern
s {$sel:patternName:LogPattern' :: Maybe Text
patternName = Maybe Text
a} :: LogPattern)

-- | The name of the log pattern. A log pattern name can contain as many as
-- 30 characters, and it cannot be empty. The characters can be Unicode
-- letters, digits, or one of the following symbols: period, dash,
-- underscore.
logPattern_patternSetName :: Lens.Lens' LogPattern (Prelude.Maybe Prelude.Text)
logPattern_patternSetName :: (Maybe Text -> f (Maybe Text)) -> LogPattern -> f LogPattern
logPattern_patternSetName = (LogPattern -> Maybe Text)
-> (LogPattern -> Maybe Text -> LogPattern)
-> Lens LogPattern LogPattern (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LogPattern' {Maybe Text
patternSetName :: Maybe Text
$sel:patternSetName:LogPattern' :: LogPattern -> Maybe Text
patternSetName} -> Maybe Text
patternSetName) (\s :: LogPattern
s@LogPattern' {} Maybe Text
a -> LogPattern
s {$sel:patternSetName:LogPattern' :: Maybe Text
patternSetName = Maybe Text
a} :: LogPattern)

-- | Rank of the log pattern. Must be a value between @1@ and @1,000,000@.
-- The patterns are sorted by rank, so we recommend that you set your
-- highest priority patterns with the lowest rank. A pattern of rank @1@
-- will be the first to get matched to a log line. A pattern of rank
-- @1,000,000@ will be last to get matched. When you configure custom log
-- patterns from the console, a @Low@ severity pattern translates to a
-- @750,000@ rank. A @Medium@ severity pattern translates to a @500,000@
-- rank. And a @High@ severity pattern translates to a @250,000@ rank. Rank
-- values less than @1@ or greater than @1,000,000@ are reserved for
-- AWS-provided patterns.
logPattern_rank :: Lens.Lens' LogPattern (Prelude.Maybe Prelude.Int)
logPattern_rank :: (Maybe Int -> f (Maybe Int)) -> LogPattern -> f LogPattern
logPattern_rank = (LogPattern -> Maybe Int)
-> (LogPattern -> Maybe Int -> LogPattern)
-> Lens LogPattern LogPattern (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LogPattern' {Maybe Int
rank :: Maybe Int
$sel:rank:LogPattern' :: LogPattern -> Maybe Int
rank} -> Maybe Int
rank) (\s :: LogPattern
s@LogPattern' {} Maybe Int
a -> LogPattern
s {$sel:rank:LogPattern' :: Maybe Int
rank = Maybe Int
a} :: LogPattern)

instance Core.FromJSON LogPattern where
  parseJSON :: Value -> Parser LogPattern
parseJSON =
    String
-> (Object -> Parser LogPattern) -> Value -> Parser LogPattern
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"LogPattern"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> Maybe Text -> Maybe Int -> LogPattern
LogPattern'
            (Maybe Text -> Maybe Text -> Maybe Text -> Maybe Int -> LogPattern)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Maybe Text -> Maybe Int -> LogPattern)
forall (f :: * -> *) a b. Functor 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
"Pattern")
            Parser (Maybe Text -> Maybe Text -> Maybe Int -> LogPattern)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Maybe Int -> LogPattern)
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
"PatternName")
            Parser (Maybe Text -> Maybe Int -> LogPattern)
-> Parser (Maybe Text) -> Parser (Maybe Int -> LogPattern)
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
"PatternSetName")
            Parser (Maybe Int -> LogPattern)
-> Parser (Maybe Int) -> Parser LogPattern
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Rank")
      )

instance Prelude.Hashable LogPattern

instance Prelude.NFData LogPattern