{-# 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.ELB.Types.HealthCheck
-- 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.ELB.Types.HealthCheck where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.ELB.Internal
import qualified Amazonka.Prelude as Prelude

-- | Information about a health check.
--
-- /See:/ 'newHealthCheck' smart constructor.
data HealthCheck = HealthCheck'
  { -- | The instance being checked. The protocol is either TCP, HTTP, HTTPS, or
    -- SSL. The range of valid ports is one (1) through 65535.
    --
    -- TCP is the default, specified as a TCP: port pair, for example
    -- \"TCP:5000\". In this case, a health check simply attempts to open a TCP
    -- connection to the instance on the specified port. Failure to connect
    -- within the configured timeout is considered unhealthy.
    --
    -- SSL is also specified as SSL: port pair, for example, SSL:5000.
    --
    -- For HTTP\/HTTPS, you must include a ping path in the string. HTTP is
    -- specified as a HTTP:port;\/;PathToPing; grouping, for example
    -- \"HTTP:80\/weather\/us\/wa\/seattle\". In this case, a HTTP GET request
    -- is issued to the instance on the given port and path. Any answer other
    -- than \"200 OK\" within the timeout period is considered unhealthy.
    --
    -- The total length of the HTTP ping target must be 1024 16-bit Unicode
    -- characters or less.
    HealthCheck -> Text
target :: Prelude.Text,
    -- | The approximate interval, in seconds, between health checks of an
    -- individual instance.
    HealthCheck -> Natural
interval :: Prelude.Natural,
    -- | The amount of time, in seconds, during which no response means a failed
    -- health check.
    --
    -- This value must be less than the @Interval@ value.
    HealthCheck -> Natural
timeout :: Prelude.Natural,
    -- | The number of consecutive health check failures required before moving
    -- the instance to the @Unhealthy@ state.
    HealthCheck -> Natural
unhealthyThreshold :: Prelude.Natural,
    -- | The number of consecutive health checks successes required before moving
    -- the instance to the @Healthy@ state.
    HealthCheck -> Natural
healthyThreshold :: Prelude.Natural
  }
  deriving (HealthCheck -> HealthCheck -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HealthCheck -> HealthCheck -> Bool
$c/= :: HealthCheck -> HealthCheck -> Bool
== :: HealthCheck -> HealthCheck -> Bool
$c== :: HealthCheck -> HealthCheck -> Bool
Prelude.Eq, ReadPrec [HealthCheck]
ReadPrec HealthCheck
Int -> ReadS HealthCheck
ReadS [HealthCheck]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HealthCheck]
$creadListPrec :: ReadPrec [HealthCheck]
readPrec :: ReadPrec HealthCheck
$creadPrec :: ReadPrec HealthCheck
readList :: ReadS [HealthCheck]
$creadList :: ReadS [HealthCheck]
readsPrec :: Int -> ReadS HealthCheck
$creadsPrec :: Int -> ReadS HealthCheck
Prelude.Read, Int -> HealthCheck -> ShowS
[HealthCheck] -> ShowS
HealthCheck -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HealthCheck] -> ShowS
$cshowList :: [HealthCheck] -> ShowS
show :: HealthCheck -> String
$cshow :: HealthCheck -> String
showsPrec :: Int -> HealthCheck -> ShowS
$cshowsPrec :: Int -> HealthCheck -> ShowS
Prelude.Show, forall x. Rep HealthCheck x -> HealthCheck
forall x. HealthCheck -> Rep HealthCheck x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HealthCheck x -> HealthCheck
$cfrom :: forall x. HealthCheck -> Rep HealthCheck x
Prelude.Generic)

-- |
-- Create a value of 'HealthCheck' 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:
--
-- 'target', 'healthCheck_target' - The instance being checked. The protocol is either TCP, HTTP, HTTPS, or
-- SSL. The range of valid ports is one (1) through 65535.
--
-- TCP is the default, specified as a TCP: port pair, for example
-- \"TCP:5000\". In this case, a health check simply attempts to open a TCP
-- connection to the instance on the specified port. Failure to connect
-- within the configured timeout is considered unhealthy.
--
-- SSL is also specified as SSL: port pair, for example, SSL:5000.
--
-- For HTTP\/HTTPS, you must include a ping path in the string. HTTP is
-- specified as a HTTP:port;\/;PathToPing; grouping, for example
-- \"HTTP:80\/weather\/us\/wa\/seattle\". In this case, a HTTP GET request
-- is issued to the instance on the given port and path. Any answer other
-- than \"200 OK\" within the timeout period is considered unhealthy.
--
-- The total length of the HTTP ping target must be 1024 16-bit Unicode
-- characters or less.
--
-- 'interval', 'healthCheck_interval' - The approximate interval, in seconds, between health checks of an
-- individual instance.
--
-- 'timeout', 'healthCheck_timeout' - The amount of time, in seconds, during which no response means a failed
-- health check.
--
-- This value must be less than the @Interval@ value.
--
-- 'unhealthyThreshold', 'healthCheck_unhealthyThreshold' - The number of consecutive health check failures required before moving
-- the instance to the @Unhealthy@ state.
--
-- 'healthyThreshold', 'healthCheck_healthyThreshold' - The number of consecutive health checks successes required before moving
-- the instance to the @Healthy@ state.
newHealthCheck ::
  -- | 'target'
  Prelude.Text ->
  -- | 'interval'
  Prelude.Natural ->
  -- | 'timeout'
  Prelude.Natural ->
  -- | 'unhealthyThreshold'
  Prelude.Natural ->
  -- | 'healthyThreshold'
  Prelude.Natural ->
  HealthCheck
newHealthCheck :: Text -> Natural -> Natural -> Natural -> Natural -> HealthCheck
newHealthCheck
  Text
pTarget_
  Natural
pInterval_
  Natural
pTimeout_
  Natural
pUnhealthyThreshold_
  Natural
pHealthyThreshold_ =
    HealthCheck'
      { $sel:target:HealthCheck' :: Text
target = Text
pTarget_,
        $sel:interval:HealthCheck' :: Natural
interval = Natural
pInterval_,
        $sel:timeout:HealthCheck' :: Natural
timeout = Natural
pTimeout_,
        $sel:unhealthyThreshold:HealthCheck' :: Natural
unhealthyThreshold = Natural
pUnhealthyThreshold_,
        $sel:healthyThreshold:HealthCheck' :: Natural
healthyThreshold = Natural
pHealthyThreshold_
      }

-- | The instance being checked. The protocol is either TCP, HTTP, HTTPS, or
-- SSL. The range of valid ports is one (1) through 65535.
--
-- TCP is the default, specified as a TCP: port pair, for example
-- \"TCP:5000\". In this case, a health check simply attempts to open a TCP
-- connection to the instance on the specified port. Failure to connect
-- within the configured timeout is considered unhealthy.
--
-- SSL is also specified as SSL: port pair, for example, SSL:5000.
--
-- For HTTP\/HTTPS, you must include a ping path in the string. HTTP is
-- specified as a HTTP:port;\/;PathToPing; grouping, for example
-- \"HTTP:80\/weather\/us\/wa\/seattle\". In this case, a HTTP GET request
-- is issued to the instance on the given port and path. Any answer other
-- than \"200 OK\" within the timeout period is considered unhealthy.
--
-- The total length of the HTTP ping target must be 1024 16-bit Unicode
-- characters or less.
healthCheck_target :: Lens.Lens' HealthCheck Prelude.Text
healthCheck_target :: Lens' HealthCheck Text
healthCheck_target = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HealthCheck' {Text
target :: Text
$sel:target:HealthCheck' :: HealthCheck -> Text
target} -> Text
target) (\s :: HealthCheck
s@HealthCheck' {} Text
a -> HealthCheck
s {$sel:target:HealthCheck' :: Text
target = Text
a} :: HealthCheck)

-- | The approximate interval, in seconds, between health checks of an
-- individual instance.
healthCheck_interval :: Lens.Lens' HealthCheck Prelude.Natural
healthCheck_interval :: Lens' HealthCheck Natural
healthCheck_interval = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HealthCheck' {Natural
interval :: Natural
$sel:interval:HealthCheck' :: HealthCheck -> Natural
interval} -> Natural
interval) (\s :: HealthCheck
s@HealthCheck' {} Natural
a -> HealthCheck
s {$sel:interval:HealthCheck' :: Natural
interval = Natural
a} :: HealthCheck)

-- | The amount of time, in seconds, during which no response means a failed
-- health check.
--
-- This value must be less than the @Interval@ value.
healthCheck_timeout :: Lens.Lens' HealthCheck Prelude.Natural
healthCheck_timeout :: Lens' HealthCheck Natural
healthCheck_timeout = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HealthCheck' {Natural
timeout :: Natural
$sel:timeout:HealthCheck' :: HealthCheck -> Natural
timeout} -> Natural
timeout) (\s :: HealthCheck
s@HealthCheck' {} Natural
a -> HealthCheck
s {$sel:timeout:HealthCheck' :: Natural
timeout = Natural
a} :: HealthCheck)

-- | The number of consecutive health check failures required before moving
-- the instance to the @Unhealthy@ state.
healthCheck_unhealthyThreshold :: Lens.Lens' HealthCheck Prelude.Natural
healthCheck_unhealthyThreshold :: Lens' HealthCheck Natural
healthCheck_unhealthyThreshold = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HealthCheck' {Natural
unhealthyThreshold :: Natural
$sel:unhealthyThreshold:HealthCheck' :: HealthCheck -> Natural
unhealthyThreshold} -> Natural
unhealthyThreshold) (\s :: HealthCheck
s@HealthCheck' {} Natural
a -> HealthCheck
s {$sel:unhealthyThreshold:HealthCheck' :: Natural
unhealthyThreshold = Natural
a} :: HealthCheck)

-- | The number of consecutive health checks successes required before moving
-- the instance to the @Healthy@ state.
healthCheck_healthyThreshold :: Lens.Lens' HealthCheck Prelude.Natural
healthCheck_healthyThreshold :: Lens' HealthCheck Natural
healthCheck_healthyThreshold = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HealthCheck' {Natural
healthyThreshold :: Natural
$sel:healthyThreshold:HealthCheck' :: HealthCheck -> Natural
healthyThreshold} -> Natural
healthyThreshold) (\s :: HealthCheck
s@HealthCheck' {} Natural
a -> HealthCheck
s {$sel:healthyThreshold:HealthCheck' :: Natural
healthyThreshold = Natural
a} :: HealthCheck)

instance Data.FromXML HealthCheck where
  parseXML :: [Node] -> Either String HealthCheck
parseXML [Node]
x =
    Text -> Natural -> Natural -> Natural -> Natural -> HealthCheck
HealthCheck'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"Target")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"Interval")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"Timeout")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"UnhealthyThreshold")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"HealthyThreshold")

instance Prelude.Hashable HealthCheck where
  hashWithSalt :: Int -> HealthCheck -> Int
hashWithSalt Int
_salt HealthCheck' {Natural
Text
healthyThreshold :: Natural
unhealthyThreshold :: Natural
timeout :: Natural
interval :: Natural
target :: Text
$sel:healthyThreshold:HealthCheck' :: HealthCheck -> Natural
$sel:unhealthyThreshold:HealthCheck' :: HealthCheck -> Natural
$sel:timeout:HealthCheck' :: HealthCheck -> Natural
$sel:interval:HealthCheck' :: HealthCheck -> Natural
$sel:target:HealthCheck' :: HealthCheck -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
target
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
interval
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
timeout
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
unhealthyThreshold
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
healthyThreshold

instance Prelude.NFData HealthCheck where
  rnf :: HealthCheck -> ()
rnf HealthCheck' {Natural
Text
healthyThreshold :: Natural
unhealthyThreshold :: Natural
timeout :: Natural
interval :: Natural
target :: Text
$sel:healthyThreshold:HealthCheck' :: HealthCheck -> Natural
$sel:unhealthyThreshold:HealthCheck' :: HealthCheck -> Natural
$sel:timeout:HealthCheck' :: HealthCheck -> Natural
$sel:interval:HealthCheck' :: HealthCheck -> Natural
$sel:target:HealthCheck' :: HealthCheck -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
target
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
interval
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
timeout
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
unhealthyThreshold
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
healthyThreshold

instance Data.ToQuery HealthCheck where
  toQuery :: HealthCheck -> QueryString
toQuery HealthCheck' {Natural
Text
healthyThreshold :: Natural
unhealthyThreshold :: Natural
timeout :: Natural
interval :: Natural
target :: Text
$sel:healthyThreshold:HealthCheck' :: HealthCheck -> Natural
$sel:unhealthyThreshold:HealthCheck' :: HealthCheck -> Natural
$sel:timeout:HealthCheck' :: HealthCheck -> Natural
$sel:interval:HealthCheck' :: HealthCheck -> Natural
$sel:target:HealthCheck' :: HealthCheck -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Target" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
target,
        ByteString
"Interval" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Natural
interval,
        ByteString
"Timeout" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Natural
timeout,
        ByteString
"UnhealthyThreshold" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Natural
unhealthyThreshold,
        ByteString
"HealthyThreshold" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Natural
healthyThreshold
      ]