{-# 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.SetAlarmState
-- 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)
--
-- Temporarily sets the state of an alarm for testing purposes. When the
-- updated state differs from the previous value, the action configured for
-- the appropriate state is invoked. For example, if your alarm is
-- configured to send an Amazon SNS message when an alarm is triggered,
-- temporarily changing the alarm state to @ALARM@ sends an SNS message.
--
-- Metric alarms returns to their actual state quickly, often within
-- seconds. Because the metric alarm state change happens quickly, it is
-- typically only visible in the alarm\'s __History__ tab in the Amazon
-- CloudWatch console or through
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_DescribeAlarmHistory.html DescribeAlarmHistory>.
--
-- If you use @SetAlarmState@ on a composite alarm, the composite alarm is
-- not guaranteed to return to its actual state. It returns to its actual
-- state only once any of its children alarms change state. It is also
-- reevaluated if you update its configuration.
--
-- If an alarm triggers EC2 Auto Scaling policies or application Auto
-- Scaling policies, you must include information in the @StateReasonData@
-- parameter to enable the policy to take the correct action.
module Amazonka.CloudWatch.SetAlarmState
  ( -- * Creating a Request
    SetAlarmState (..),
    newSetAlarmState,

    -- * Request Lenses
    setAlarmState_stateReasonData,
    setAlarmState_alarmName,
    setAlarmState_stateValue,
    setAlarmState_stateReason,

    -- * Destructuring the Response
    SetAlarmStateResponse (..),
    newSetAlarmStateResponse,
  )
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:/ 'newSetAlarmState' smart constructor.
data SetAlarmState = SetAlarmState'
  { -- | The reason that this alarm is set to this specific state, in JSON
    -- format.
    --
    -- For SNS or EC2 alarm actions, this is just informational. But for EC2
    -- Auto Scaling or application Auto Scaling alarm actions, the Auto Scaling
    -- policy uses the information in this field to take the correct action.
    SetAlarmState -> Maybe Text
stateReasonData :: Prelude.Maybe Prelude.Text,
    -- | The name of the alarm.
    SetAlarmState -> Text
alarmName :: Prelude.Text,
    -- | The value of the state.
    SetAlarmState -> StateValue
stateValue :: StateValue,
    -- | The reason that this alarm is set to this specific state, in text
    -- format.
    SetAlarmState -> Text
stateReason :: Prelude.Text
  }
  deriving (SetAlarmState -> SetAlarmState -> Bool
(SetAlarmState -> SetAlarmState -> Bool)
-> (SetAlarmState -> SetAlarmState -> Bool) -> Eq SetAlarmState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SetAlarmState -> SetAlarmState -> Bool
$c/= :: SetAlarmState -> SetAlarmState -> Bool
== :: SetAlarmState -> SetAlarmState -> Bool
$c== :: SetAlarmState -> SetAlarmState -> Bool
Prelude.Eq, ReadPrec [SetAlarmState]
ReadPrec SetAlarmState
Int -> ReadS SetAlarmState
ReadS [SetAlarmState]
(Int -> ReadS SetAlarmState)
-> ReadS [SetAlarmState]
-> ReadPrec SetAlarmState
-> ReadPrec [SetAlarmState]
-> Read SetAlarmState
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SetAlarmState]
$creadListPrec :: ReadPrec [SetAlarmState]
readPrec :: ReadPrec SetAlarmState
$creadPrec :: ReadPrec SetAlarmState
readList :: ReadS [SetAlarmState]
$creadList :: ReadS [SetAlarmState]
readsPrec :: Int -> ReadS SetAlarmState
$creadsPrec :: Int -> ReadS SetAlarmState
Prelude.Read, Int -> SetAlarmState -> ShowS
[SetAlarmState] -> ShowS
SetAlarmState -> String
(Int -> SetAlarmState -> ShowS)
-> (SetAlarmState -> String)
-> ([SetAlarmState] -> ShowS)
-> Show SetAlarmState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SetAlarmState] -> ShowS
$cshowList :: [SetAlarmState] -> ShowS
show :: SetAlarmState -> String
$cshow :: SetAlarmState -> String
showsPrec :: Int -> SetAlarmState -> ShowS
$cshowsPrec :: Int -> SetAlarmState -> ShowS
Prelude.Show, (forall x. SetAlarmState -> Rep SetAlarmState x)
-> (forall x. Rep SetAlarmState x -> SetAlarmState)
-> Generic SetAlarmState
forall x. Rep SetAlarmState x -> SetAlarmState
forall x. SetAlarmState -> Rep SetAlarmState x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SetAlarmState x -> SetAlarmState
$cfrom :: forall x. SetAlarmState -> Rep SetAlarmState x
Prelude.Generic)

-- |
-- Create a value of 'SetAlarmState' 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:
--
-- 'stateReasonData', 'setAlarmState_stateReasonData' - The reason that this alarm is set to this specific state, in JSON
-- format.
--
-- For SNS or EC2 alarm actions, this is just informational. But for EC2
-- Auto Scaling or application Auto Scaling alarm actions, the Auto Scaling
-- policy uses the information in this field to take the correct action.
--
-- 'alarmName', 'setAlarmState_alarmName' - The name of the alarm.
--
-- 'stateValue', 'setAlarmState_stateValue' - The value of the state.
--
-- 'stateReason', 'setAlarmState_stateReason' - The reason that this alarm is set to this specific state, in text
-- format.
newSetAlarmState ::
  -- | 'alarmName'
  Prelude.Text ->
  -- | 'stateValue'
  StateValue ->
  -- | 'stateReason'
  Prelude.Text ->
  SetAlarmState
newSetAlarmState :: Text -> StateValue -> Text -> SetAlarmState
newSetAlarmState
  Text
pAlarmName_
  StateValue
pStateValue_
  Text
pStateReason_ =
    SetAlarmState' :: Maybe Text -> Text -> StateValue -> Text -> SetAlarmState
SetAlarmState'
      { $sel:stateReasonData:SetAlarmState' :: Maybe Text
stateReasonData = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:alarmName:SetAlarmState' :: Text
alarmName = Text
pAlarmName_,
        $sel:stateValue:SetAlarmState' :: StateValue
stateValue = StateValue
pStateValue_,
        $sel:stateReason:SetAlarmState' :: Text
stateReason = Text
pStateReason_
      }

-- | The reason that this alarm is set to this specific state, in JSON
-- format.
--
-- For SNS or EC2 alarm actions, this is just informational. But for EC2
-- Auto Scaling or application Auto Scaling alarm actions, the Auto Scaling
-- policy uses the information in this field to take the correct action.
setAlarmState_stateReasonData :: Lens.Lens' SetAlarmState (Prelude.Maybe Prelude.Text)
setAlarmState_stateReasonData :: (Maybe Text -> f (Maybe Text)) -> SetAlarmState -> f SetAlarmState
setAlarmState_stateReasonData = (SetAlarmState -> Maybe Text)
-> (SetAlarmState -> Maybe Text -> SetAlarmState)
-> Lens SetAlarmState SetAlarmState (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SetAlarmState' {Maybe Text
stateReasonData :: Maybe Text
$sel:stateReasonData:SetAlarmState' :: SetAlarmState -> Maybe Text
stateReasonData} -> Maybe Text
stateReasonData) (\s :: SetAlarmState
s@SetAlarmState' {} Maybe Text
a -> SetAlarmState
s {$sel:stateReasonData:SetAlarmState' :: Maybe Text
stateReasonData = Maybe Text
a} :: SetAlarmState)

-- | The name of the alarm.
setAlarmState_alarmName :: Lens.Lens' SetAlarmState Prelude.Text
setAlarmState_alarmName :: (Text -> f Text) -> SetAlarmState -> f SetAlarmState
setAlarmState_alarmName = (SetAlarmState -> Text)
-> (SetAlarmState -> Text -> SetAlarmState)
-> Lens SetAlarmState SetAlarmState Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SetAlarmState' {Text
alarmName :: Text
$sel:alarmName:SetAlarmState' :: SetAlarmState -> Text
alarmName} -> Text
alarmName) (\s :: SetAlarmState
s@SetAlarmState' {} Text
a -> SetAlarmState
s {$sel:alarmName:SetAlarmState' :: Text
alarmName = Text
a} :: SetAlarmState)

-- | The value of the state.
setAlarmState_stateValue :: Lens.Lens' SetAlarmState StateValue
setAlarmState_stateValue :: (StateValue -> f StateValue) -> SetAlarmState -> f SetAlarmState
setAlarmState_stateValue = (SetAlarmState -> StateValue)
-> (SetAlarmState -> StateValue -> SetAlarmState)
-> Lens SetAlarmState SetAlarmState StateValue StateValue
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SetAlarmState' {StateValue
stateValue :: StateValue
$sel:stateValue:SetAlarmState' :: SetAlarmState -> StateValue
stateValue} -> StateValue
stateValue) (\s :: SetAlarmState
s@SetAlarmState' {} StateValue
a -> SetAlarmState
s {$sel:stateValue:SetAlarmState' :: StateValue
stateValue = StateValue
a} :: SetAlarmState)

-- | The reason that this alarm is set to this specific state, in text
-- format.
setAlarmState_stateReason :: Lens.Lens' SetAlarmState Prelude.Text
setAlarmState_stateReason :: (Text -> f Text) -> SetAlarmState -> f SetAlarmState
setAlarmState_stateReason = (SetAlarmState -> Text)
-> (SetAlarmState -> Text -> SetAlarmState)
-> Lens SetAlarmState SetAlarmState Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SetAlarmState' {Text
stateReason :: Text
$sel:stateReason:SetAlarmState' :: SetAlarmState -> Text
stateReason} -> Text
stateReason) (\s :: SetAlarmState
s@SetAlarmState' {} Text
a -> SetAlarmState
s {$sel:stateReason:SetAlarmState' :: Text
stateReason = Text
a} :: SetAlarmState)

instance Core.AWSRequest SetAlarmState where
  type
    AWSResponse SetAlarmState =
      SetAlarmStateResponse
  request :: SetAlarmState -> Request SetAlarmState
request = Service -> SetAlarmState -> Request SetAlarmState
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy SetAlarmState
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse SetAlarmState)))
response =
    AWSResponse SetAlarmState
-> Logger
-> Service
-> Proxy SetAlarmState
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse SetAlarmState)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse SetAlarmState
SetAlarmStateResponse
SetAlarmStateResponse'

instance Prelude.Hashable SetAlarmState

instance Prelude.NFData SetAlarmState

instance Core.ToHeaders SetAlarmState where
  toHeaders :: SetAlarmState -> [Header]
toHeaders = [Header] -> SetAlarmState -> [Header]
forall a b. a -> b -> a
Prelude.const [Header]
forall a. Monoid a => a
Prelude.mempty

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

instance Core.ToQuery SetAlarmState where
  toQuery :: SetAlarmState -> QueryString
toQuery SetAlarmState' {Maybe Text
Text
StateValue
stateReason :: Text
stateValue :: StateValue
alarmName :: Text
stateReasonData :: Maybe Text
$sel:stateReason:SetAlarmState' :: SetAlarmState -> Text
$sel:stateValue:SetAlarmState' :: SetAlarmState -> StateValue
$sel:alarmName:SetAlarmState' :: SetAlarmState -> Text
$sel:stateReasonData:SetAlarmState' :: SetAlarmState -> Maybe 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
"SetAlarmState" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2010-08-01" :: Prelude.ByteString),
        ByteString
"StateReasonData" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
stateReasonData,
        ByteString
"AlarmName" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
alarmName,
        ByteString
"StateValue" ByteString -> StateValue -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: StateValue
stateValue,
        ByteString
"StateReason" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
stateReason
      ]

-- | /See:/ 'newSetAlarmStateResponse' smart constructor.
data SetAlarmStateResponse = SetAlarmStateResponse'
  {
  }
  deriving (SetAlarmStateResponse -> SetAlarmStateResponse -> Bool
(SetAlarmStateResponse -> SetAlarmStateResponse -> Bool)
-> (SetAlarmStateResponse -> SetAlarmStateResponse -> Bool)
-> Eq SetAlarmStateResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SetAlarmStateResponse -> SetAlarmStateResponse -> Bool
$c/= :: SetAlarmStateResponse -> SetAlarmStateResponse -> Bool
== :: SetAlarmStateResponse -> SetAlarmStateResponse -> Bool
$c== :: SetAlarmStateResponse -> SetAlarmStateResponse -> Bool
Prelude.Eq, ReadPrec [SetAlarmStateResponse]
ReadPrec SetAlarmStateResponse
Int -> ReadS SetAlarmStateResponse
ReadS [SetAlarmStateResponse]
(Int -> ReadS SetAlarmStateResponse)
-> ReadS [SetAlarmStateResponse]
-> ReadPrec SetAlarmStateResponse
-> ReadPrec [SetAlarmStateResponse]
-> Read SetAlarmStateResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SetAlarmStateResponse]
$creadListPrec :: ReadPrec [SetAlarmStateResponse]
readPrec :: ReadPrec SetAlarmStateResponse
$creadPrec :: ReadPrec SetAlarmStateResponse
readList :: ReadS [SetAlarmStateResponse]
$creadList :: ReadS [SetAlarmStateResponse]
readsPrec :: Int -> ReadS SetAlarmStateResponse
$creadsPrec :: Int -> ReadS SetAlarmStateResponse
Prelude.Read, Int -> SetAlarmStateResponse -> ShowS
[SetAlarmStateResponse] -> ShowS
SetAlarmStateResponse -> String
(Int -> SetAlarmStateResponse -> ShowS)
-> (SetAlarmStateResponse -> String)
-> ([SetAlarmStateResponse] -> ShowS)
-> Show SetAlarmStateResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SetAlarmStateResponse] -> ShowS
$cshowList :: [SetAlarmStateResponse] -> ShowS
show :: SetAlarmStateResponse -> String
$cshow :: SetAlarmStateResponse -> String
showsPrec :: Int -> SetAlarmStateResponse -> ShowS
$cshowsPrec :: Int -> SetAlarmStateResponse -> ShowS
Prelude.Show, (forall x. SetAlarmStateResponse -> Rep SetAlarmStateResponse x)
-> (forall x. Rep SetAlarmStateResponse x -> SetAlarmStateResponse)
-> Generic SetAlarmStateResponse
forall x. Rep SetAlarmStateResponse x -> SetAlarmStateResponse
forall x. SetAlarmStateResponse -> Rep SetAlarmStateResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SetAlarmStateResponse x -> SetAlarmStateResponse
$cfrom :: forall x. SetAlarmStateResponse -> Rep SetAlarmStateResponse x
Prelude.Generic)

-- |
-- Create a value of 'SetAlarmStateResponse' 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.
newSetAlarmStateResponse ::
  SetAlarmStateResponse
newSetAlarmStateResponse :: SetAlarmStateResponse
newSetAlarmStateResponse = SetAlarmStateResponse
SetAlarmStateResponse'

instance Prelude.NFData SetAlarmStateResponse