{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.ApplicationInsights.Types.LogPattern where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
    { $sel:pattern':LogPattern' :: Maybe Text
pattern' = forall a. Maybe a
Prelude.Nothing,
      $sel:patternName:LogPattern' :: Maybe Text
patternName = forall a. Maybe a
Prelude.Nothing,
      $sel:patternSetName:LogPattern' :: Maybe Text
patternSetName = forall a. Maybe a
Prelude.Nothing,
      $sel:rank:LogPattern' :: Maybe Int
rank = 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 :: Lens' LogPattern (Maybe Text)
logPattern_pattern = 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 :: Lens' LogPattern (Maybe Text)
logPattern_patternName = 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 :: Lens' LogPattern (Maybe Text)
logPattern_patternSetName = 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 :: Lens' LogPattern (Maybe Int)
logPattern_rank = 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 Data.FromJSON LogPattern where
  parseJSON :: Value -> Parser LogPattern
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"LogPattern"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> Maybe Text -> Maybe Int -> LogPattern
LogPattern'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Pattern")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"PatternName")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"PatternSetName")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Rank")
      )

instance Prelude.Hashable LogPattern where
  hashWithSalt :: Int -> LogPattern -> Int
hashWithSalt Int
_salt LogPattern' {Maybe Int
Maybe Text
rank :: Maybe Int
patternSetName :: Maybe Text
patternName :: Maybe Text
pattern' :: Maybe Text
$sel:rank:LogPattern' :: LogPattern -> Maybe Int
$sel:patternSetName:LogPattern' :: LogPattern -> Maybe Text
$sel:patternName:LogPattern' :: LogPattern -> Maybe Text
$sel:pattern':LogPattern' :: LogPattern -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
pattern'
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
patternName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
patternSetName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
rank

instance Prelude.NFData LogPattern where
  rnf :: LogPattern -> ()
rnf LogPattern' {Maybe Int
Maybe Text
rank :: Maybe Int
patternSetName :: Maybe Text
patternName :: Maybe Text
pattern' :: Maybe Text
$sel:rank:LogPattern' :: LogPattern -> Maybe Int
$sel:patternSetName:LogPattern' :: LogPattern -> Maybe Text
$sel:patternName:LogPattern' :: LogPattern -> Maybe Text
$sel:pattern':LogPattern' :: LogPattern -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
pattern'
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
patternName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
patternSetName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
rank