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

import qualified Amazonka.Core as Core
import Amazonka.ELB.Internal
import qualified Amazonka.Lens as Lens
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
(HealthCheck -> HealthCheck -> Bool)
-> (HealthCheck -> HealthCheck -> Bool) -> Eq HealthCheck
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]
(Int -> ReadS HealthCheck)
-> ReadS [HealthCheck]
-> ReadPrec HealthCheck
-> ReadPrec [HealthCheck]
-> Read 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
(Int -> HealthCheck -> ShowS)
-> (HealthCheck -> String)
-> ([HealthCheck] -> ShowS)
-> Show HealthCheck
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. HealthCheck -> Rep HealthCheck x)
-> (forall x. Rep HealthCheck x -> HealthCheck)
-> Generic HealthCheck
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' :: Text -> Natural -> Natural -> Natural -> Natural -> HealthCheck
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 :: (Text -> f Text) -> HealthCheck -> f HealthCheck
healthCheck_target = (HealthCheck -> Text)
-> (HealthCheck -> Text -> HealthCheck)
-> Lens HealthCheck HealthCheck Text Text
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 :: (Natural -> f Natural) -> HealthCheck -> f HealthCheck
healthCheck_interval = (HealthCheck -> Natural)
-> (HealthCheck -> Natural -> HealthCheck)
-> Lens HealthCheck HealthCheck Natural Natural
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 :: (Natural -> f Natural) -> HealthCheck -> f HealthCheck
healthCheck_timeout = (HealthCheck -> Natural)
-> (HealthCheck -> Natural -> HealthCheck)
-> Lens HealthCheck HealthCheck Natural Natural
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 :: (Natural -> f Natural) -> HealthCheck -> f HealthCheck
healthCheck_unhealthyThreshold = (HealthCheck -> Natural)
-> (HealthCheck -> Natural -> HealthCheck)
-> Lens HealthCheck HealthCheck Natural Natural
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 :: (Natural -> f Natural) -> HealthCheck -> f HealthCheck
healthCheck_healthyThreshold = (HealthCheck -> Natural)
-> (HealthCheck -> Natural -> HealthCheck)
-> Lens HealthCheck HealthCheck Natural Natural
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 Core.FromXML HealthCheck where
  parseXML :: [Node] -> Either String HealthCheck
parseXML [Node]
x =
    Text -> Natural -> Natural -> Natural -> Natural -> HealthCheck
HealthCheck'
      (Text -> Natural -> Natural -> Natural -> Natural -> HealthCheck)
-> Either String Text
-> Either
     String (Natural -> Natural -> Natural -> Natural -> HealthCheck)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Target")
      Either
  String (Natural -> Natural -> Natural -> Natural -> HealthCheck)
-> Either String Natural
-> Either String (Natural -> Natural -> Natural -> HealthCheck)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Natural
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Interval")
      Either String (Natural -> Natural -> Natural -> HealthCheck)
-> Either String Natural
-> Either String (Natural -> Natural -> HealthCheck)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Natural
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Timeout")
      Either String (Natural -> Natural -> HealthCheck)
-> Either String Natural -> Either String (Natural -> HealthCheck)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Natural
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"UnhealthyThreshold")
      Either String (Natural -> HealthCheck)
-> Either String Natural -> Either String HealthCheck
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Natural
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"HealthyThreshold")

instance Prelude.Hashable HealthCheck

instance Prelude.NFData HealthCheck

instance Core.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
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Target" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
target,
        ByteString
"Interval" ByteString -> Natural -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Natural
interval,
        ByteString
"Timeout" ByteString -> Natural -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Natural
timeout,
        ByteString
"UnhealthyThreshold" ByteString -> Natural -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Natural
unhealthyThreshold,
        ByteString
"HealthyThreshold" ByteString -> Natural -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Natural
healthyThreshold
      ]