{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.EnableInsightRules
-- 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)
--
-- Enables the specified Contributor Insights rules. When rules are
-- enabled, they immediately begin analyzing log data.
module Amazonka.CloudWatch.EnableInsightRules
  ( -- * Creating a Request
    EnableInsightRules (..),
    newEnableInsightRules,

    -- * Request Lenses
    enableInsightRules_ruleNames,

    -- * Destructuring the Response
    EnableInsightRulesResponse (..),
    newEnableInsightRulesResponse,

    -- * Response Lenses
    enableInsightRulesResponse_failures,
    enableInsightRulesResponse_httpStatus,
  )
where

import Amazonka.CloudWatch.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newEnableInsightRules' smart constructor.
data EnableInsightRules = EnableInsightRules'
  { -- | An array of the rule names to enable. If you need to find out the names
    -- of your rules, use
    -- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_DescribeInsightRules.html DescribeInsightRules>.
    EnableInsightRules -> [Text]
ruleNames :: [Prelude.Text]
  }
  deriving (EnableInsightRules -> EnableInsightRules -> Bool
(EnableInsightRules -> EnableInsightRules -> Bool)
-> (EnableInsightRules -> EnableInsightRules -> Bool)
-> Eq EnableInsightRules
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EnableInsightRules -> EnableInsightRules -> Bool
$c/= :: EnableInsightRules -> EnableInsightRules -> Bool
== :: EnableInsightRules -> EnableInsightRules -> Bool
$c== :: EnableInsightRules -> EnableInsightRules -> Bool
Prelude.Eq, ReadPrec [EnableInsightRules]
ReadPrec EnableInsightRules
Int -> ReadS EnableInsightRules
ReadS [EnableInsightRules]
(Int -> ReadS EnableInsightRules)
-> ReadS [EnableInsightRules]
-> ReadPrec EnableInsightRules
-> ReadPrec [EnableInsightRules]
-> Read EnableInsightRules
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EnableInsightRules]
$creadListPrec :: ReadPrec [EnableInsightRules]
readPrec :: ReadPrec EnableInsightRules
$creadPrec :: ReadPrec EnableInsightRules
readList :: ReadS [EnableInsightRules]
$creadList :: ReadS [EnableInsightRules]
readsPrec :: Int -> ReadS EnableInsightRules
$creadsPrec :: Int -> ReadS EnableInsightRules
Prelude.Read, Int -> EnableInsightRules -> ShowS
[EnableInsightRules] -> ShowS
EnableInsightRules -> String
(Int -> EnableInsightRules -> ShowS)
-> (EnableInsightRules -> String)
-> ([EnableInsightRules] -> ShowS)
-> Show EnableInsightRules
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EnableInsightRules] -> ShowS
$cshowList :: [EnableInsightRules] -> ShowS
show :: EnableInsightRules -> String
$cshow :: EnableInsightRules -> String
showsPrec :: Int -> EnableInsightRules -> ShowS
$cshowsPrec :: Int -> EnableInsightRules -> ShowS
Prelude.Show, (forall x. EnableInsightRules -> Rep EnableInsightRules x)
-> (forall x. Rep EnableInsightRules x -> EnableInsightRules)
-> Generic EnableInsightRules
forall x. Rep EnableInsightRules x -> EnableInsightRules
forall x. EnableInsightRules -> Rep EnableInsightRules x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EnableInsightRules x -> EnableInsightRules
$cfrom :: forall x. EnableInsightRules -> Rep EnableInsightRules x
Prelude.Generic)

-- |
-- Create a value of 'EnableInsightRules' 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:
--
-- 'ruleNames', 'enableInsightRules_ruleNames' - An array of the rule names to enable. If you need to find out the names
-- of your rules, use
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_DescribeInsightRules.html DescribeInsightRules>.
newEnableInsightRules ::
  EnableInsightRules
newEnableInsightRules :: EnableInsightRules
newEnableInsightRules =
  EnableInsightRules' :: [Text] -> EnableInsightRules
EnableInsightRules' {$sel:ruleNames:EnableInsightRules' :: [Text]
ruleNames = [Text]
forall a. Monoid a => a
Prelude.mempty}

-- | An array of the rule names to enable. If you need to find out the names
-- of your rules, use
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_DescribeInsightRules.html DescribeInsightRules>.
enableInsightRules_ruleNames :: Lens.Lens' EnableInsightRules [Prelude.Text]
enableInsightRules_ruleNames :: ([Text] -> f [Text]) -> EnableInsightRules -> f EnableInsightRules
enableInsightRules_ruleNames = (EnableInsightRules -> [Text])
-> (EnableInsightRules -> [Text] -> EnableInsightRules)
-> Lens EnableInsightRules EnableInsightRules [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnableInsightRules' {[Text]
ruleNames :: [Text]
$sel:ruleNames:EnableInsightRules' :: EnableInsightRules -> [Text]
ruleNames} -> [Text]
ruleNames) (\s :: EnableInsightRules
s@EnableInsightRules' {} [Text]
a -> EnableInsightRules
s {$sel:ruleNames:EnableInsightRules' :: [Text]
ruleNames = [Text]
a} :: EnableInsightRules) (([Text] -> f [Text])
 -> EnableInsightRules -> f EnableInsightRules)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> EnableInsightRules
-> f EnableInsightRules
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest EnableInsightRules where
  type
    AWSResponse EnableInsightRules =
      EnableInsightRulesResponse
  request :: EnableInsightRules -> Request EnableInsightRules
request = Service -> EnableInsightRules -> Request EnableInsightRules
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy EnableInsightRules
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse EnableInsightRules)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse EnableInsightRules))
-> Logger
-> Service
-> Proxy EnableInsightRules
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse EnableInsightRules)))
forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"EnableInsightRulesResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe [PartialFailure] -> Int -> EnableInsightRulesResponse
EnableInsightRulesResponse'
            (Maybe [PartialFailure] -> Int -> EnableInsightRulesResponse)
-> Either String (Maybe [PartialFailure])
-> Either String (Int -> EnableInsightRulesResponse)
forall (f :: * -> *) a b. Functor 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
"Failures" 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 [PartialFailure]))
-> Either String (Maybe [PartialFailure])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [PartialFailure])
-> [Node] -> Either String (Maybe [PartialFailure])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [PartialFailure]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"member")
                        )
            Either String (Int -> EnableInsightRulesResponse)
-> Either String Int -> Either String EnableInsightRulesResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable EnableInsightRules

instance Prelude.NFData EnableInsightRules

instance Core.ToHeaders EnableInsightRules where
  toHeaders :: EnableInsightRules -> ResponseHeaders
toHeaders = ResponseHeaders -> EnableInsightRules -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Core.ToPath EnableInsightRules where
  toPath :: EnableInsightRules -> ByteString
toPath = ByteString -> EnableInsightRules -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery EnableInsightRules where
  toQuery :: EnableInsightRules -> QueryString
toQuery EnableInsightRules' {[Text]
ruleNames :: [Text]
$sel:ruleNames:EnableInsightRules' :: EnableInsightRules -> [Text]
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"EnableInsightRules" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2010-08-01" :: Prelude.ByteString),
        ByteString
"RuleNames"
          ByteString -> QueryString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: ByteString -> [Text] -> QueryString
forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Core.toQueryList ByteString
"member" [Text]
ruleNames
      ]

-- | /See:/ 'newEnableInsightRulesResponse' smart constructor.
data EnableInsightRulesResponse = EnableInsightRulesResponse'
  { -- | An array listing the rules that could not be enabled. You cannot disable
    -- or enable built-in rules.
    EnableInsightRulesResponse -> Maybe [PartialFailure]
failures :: Prelude.Maybe [PartialFailure],
    -- | The response's http status code.
    EnableInsightRulesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (EnableInsightRulesResponse -> EnableInsightRulesResponse -> Bool
(EnableInsightRulesResponse -> EnableInsightRulesResponse -> Bool)
-> (EnableInsightRulesResponse
    -> EnableInsightRulesResponse -> Bool)
-> Eq EnableInsightRulesResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EnableInsightRulesResponse -> EnableInsightRulesResponse -> Bool
$c/= :: EnableInsightRulesResponse -> EnableInsightRulesResponse -> Bool
== :: EnableInsightRulesResponse -> EnableInsightRulesResponse -> Bool
$c== :: EnableInsightRulesResponse -> EnableInsightRulesResponse -> Bool
Prelude.Eq, ReadPrec [EnableInsightRulesResponse]
ReadPrec EnableInsightRulesResponse
Int -> ReadS EnableInsightRulesResponse
ReadS [EnableInsightRulesResponse]
(Int -> ReadS EnableInsightRulesResponse)
-> ReadS [EnableInsightRulesResponse]
-> ReadPrec EnableInsightRulesResponse
-> ReadPrec [EnableInsightRulesResponse]
-> Read EnableInsightRulesResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EnableInsightRulesResponse]
$creadListPrec :: ReadPrec [EnableInsightRulesResponse]
readPrec :: ReadPrec EnableInsightRulesResponse
$creadPrec :: ReadPrec EnableInsightRulesResponse
readList :: ReadS [EnableInsightRulesResponse]
$creadList :: ReadS [EnableInsightRulesResponse]
readsPrec :: Int -> ReadS EnableInsightRulesResponse
$creadsPrec :: Int -> ReadS EnableInsightRulesResponse
Prelude.Read, Int -> EnableInsightRulesResponse -> ShowS
[EnableInsightRulesResponse] -> ShowS
EnableInsightRulesResponse -> String
(Int -> EnableInsightRulesResponse -> ShowS)
-> (EnableInsightRulesResponse -> String)
-> ([EnableInsightRulesResponse] -> ShowS)
-> Show EnableInsightRulesResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EnableInsightRulesResponse] -> ShowS
$cshowList :: [EnableInsightRulesResponse] -> ShowS
show :: EnableInsightRulesResponse -> String
$cshow :: EnableInsightRulesResponse -> String
showsPrec :: Int -> EnableInsightRulesResponse -> ShowS
$cshowsPrec :: Int -> EnableInsightRulesResponse -> ShowS
Prelude.Show, (forall x.
 EnableInsightRulesResponse -> Rep EnableInsightRulesResponse x)
-> (forall x.
    Rep EnableInsightRulesResponse x -> EnableInsightRulesResponse)
-> Generic EnableInsightRulesResponse
forall x.
Rep EnableInsightRulesResponse x -> EnableInsightRulesResponse
forall x.
EnableInsightRulesResponse -> Rep EnableInsightRulesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep EnableInsightRulesResponse x -> EnableInsightRulesResponse
$cfrom :: forall x.
EnableInsightRulesResponse -> Rep EnableInsightRulesResponse x
Prelude.Generic)

-- |
-- Create a value of 'EnableInsightRulesResponse' 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:
--
-- 'failures', 'enableInsightRulesResponse_failures' - An array listing the rules that could not be enabled. You cannot disable
-- or enable built-in rules.
--
-- 'httpStatus', 'enableInsightRulesResponse_httpStatus' - The response's http status code.
newEnableInsightRulesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  EnableInsightRulesResponse
newEnableInsightRulesResponse :: Int -> EnableInsightRulesResponse
newEnableInsightRulesResponse Int
pHttpStatus_ =
  EnableInsightRulesResponse' :: Maybe [PartialFailure] -> Int -> EnableInsightRulesResponse
EnableInsightRulesResponse'
    { $sel:failures:EnableInsightRulesResponse' :: Maybe [PartialFailure]
failures =
        Maybe [PartialFailure]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:EnableInsightRulesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An array listing the rules that could not be enabled. You cannot disable
-- or enable built-in rules.
enableInsightRulesResponse_failures :: Lens.Lens' EnableInsightRulesResponse (Prelude.Maybe [PartialFailure])
enableInsightRulesResponse_failures :: (Maybe [PartialFailure] -> f (Maybe [PartialFailure]))
-> EnableInsightRulesResponse -> f EnableInsightRulesResponse
enableInsightRulesResponse_failures = (EnableInsightRulesResponse -> Maybe [PartialFailure])
-> (EnableInsightRulesResponse
    -> Maybe [PartialFailure] -> EnableInsightRulesResponse)
-> Lens
     EnableInsightRulesResponse
     EnableInsightRulesResponse
     (Maybe [PartialFailure])
     (Maybe [PartialFailure])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnableInsightRulesResponse' {Maybe [PartialFailure]
failures :: Maybe [PartialFailure]
$sel:failures:EnableInsightRulesResponse' :: EnableInsightRulesResponse -> Maybe [PartialFailure]
failures} -> Maybe [PartialFailure]
failures) (\s :: EnableInsightRulesResponse
s@EnableInsightRulesResponse' {} Maybe [PartialFailure]
a -> EnableInsightRulesResponse
s {$sel:failures:EnableInsightRulesResponse' :: Maybe [PartialFailure]
failures = Maybe [PartialFailure]
a} :: EnableInsightRulesResponse) ((Maybe [PartialFailure] -> f (Maybe [PartialFailure]))
 -> EnableInsightRulesResponse -> f EnableInsightRulesResponse)
-> ((Maybe [PartialFailure] -> f (Maybe [PartialFailure]))
    -> Maybe [PartialFailure] -> f (Maybe [PartialFailure]))
-> (Maybe [PartialFailure] -> f (Maybe [PartialFailure]))
-> EnableInsightRulesResponse
-> f EnableInsightRulesResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [PartialFailure] [PartialFailure] [PartialFailure] [PartialFailure]
-> Iso
     (Maybe [PartialFailure])
     (Maybe [PartialFailure])
     (Maybe [PartialFailure])
     (Maybe [PartialFailure])
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
  [PartialFailure] [PartialFailure] [PartialFailure] [PartialFailure]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The response's http status code.
enableInsightRulesResponse_httpStatus :: Lens.Lens' EnableInsightRulesResponse Prelude.Int
enableInsightRulesResponse_httpStatus :: (Int -> f Int)
-> EnableInsightRulesResponse -> f EnableInsightRulesResponse
enableInsightRulesResponse_httpStatus = (EnableInsightRulesResponse -> Int)
-> (EnableInsightRulesResponse
    -> Int -> EnableInsightRulesResponse)
-> Lens
     EnableInsightRulesResponse EnableInsightRulesResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnableInsightRulesResponse' {Int
httpStatus :: Int
$sel:httpStatus:EnableInsightRulesResponse' :: EnableInsightRulesResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: EnableInsightRulesResponse
s@EnableInsightRulesResponse' {} Int
a -> EnableInsightRulesResponse
s {$sel:httpStatus:EnableInsightRulesResponse' :: Int
httpStatus = Int
a} :: EnableInsightRulesResponse)

instance Prelude.NFData EnableInsightRulesResponse