{-# 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.Lightsail.Types.InstanceHealthSummary
-- 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.Lightsail.Types.InstanceHealthSummary where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Lightsail.Types.InstanceHealthReason
import Amazonka.Lightsail.Types.InstanceHealthState
import qualified Amazonka.Prelude as Prelude

-- | Describes information about the health of the instance.
--
-- /See:/ 'newInstanceHealthSummary' smart constructor.
data InstanceHealthSummary = InstanceHealthSummary'
  { -- | Describes the overall instance health. Valid values are below.
    InstanceHealthSummary -> Maybe InstanceHealthState
instanceHealth :: Prelude.Maybe InstanceHealthState,
    -- | The name of the Lightsail instance for which you are requesting health
    -- check data.
    InstanceHealthSummary -> Maybe Text
instanceName :: Prelude.Maybe Prelude.Text,
    -- | More information about the instance health. If the @instanceHealth@ is
    -- @healthy@, then an @instanceHealthReason@ value is not provided.
    --
    -- If __@instanceHealth@__ is @initial@, the __@instanceHealthReason@__
    -- value can be one of the following:
    --
    -- -   __@Lb.RegistrationInProgress@__ - The target instance is in the
    --     process of being registered with the load balancer.
    --
    -- -   __@Lb.InitialHealthChecking@__ - The Lightsail load balancer is
    --     still sending the target instance the minimum number of health
    --     checks required to determine its health status.
    --
    -- If __@instanceHealth@__ is @unhealthy@, the __@instanceHealthReason@__
    -- value can be one of the following:
    --
    -- -   __@Instance.ResponseCodeMismatch@__ - The health checks did not
    --     return an expected HTTP code.
    --
    -- -   __@Instance.Timeout@__ - The health check requests timed out.
    --
    -- -   __@Instance.FailedHealthChecks@__ - The health checks failed because
    --     the connection to the target instance timed out, the target instance
    --     response was malformed, or the target instance failed the health
    --     check for an unknown reason.
    --
    -- -   __@Lb.InternalError@__ - The health checks failed due to an internal
    --     error.
    --
    -- If __@instanceHealth@__ is @unused@, the __@instanceHealthReason@__
    -- value can be one of the following:
    --
    -- -   __@Instance.NotRegistered@__ - The target instance is not registered
    --     with the target group.
    --
    -- -   __@Instance.NotInUse@__ - The target group is not used by any load
    --     balancer, or the target instance is in an Availability Zone that is
    --     not enabled for its load balancer.
    --
    -- -   __@Instance.IpUnusable@__ - The target IP address is reserved for
    --     use by a Lightsail load balancer.
    --
    -- -   __@Instance.InvalidState@__ - The target is in the stopped or
    --     terminated state.
    --
    -- If __@instanceHealth@__ is @draining@, the __@instanceHealthReason@__
    -- value can be one of the following:
    --
    -- -   __@Instance.DeregistrationInProgress@__ - The target instance is in
    --     the process of being deregistered and the deregistration delay
    --     period has not expired.
    InstanceHealthSummary -> Maybe InstanceHealthReason
instanceHealthReason :: Prelude.Maybe InstanceHealthReason
  }
  deriving (InstanceHealthSummary -> InstanceHealthSummary -> Bool
(InstanceHealthSummary -> InstanceHealthSummary -> Bool)
-> (InstanceHealthSummary -> InstanceHealthSummary -> Bool)
-> Eq InstanceHealthSummary
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InstanceHealthSummary -> InstanceHealthSummary -> Bool
$c/= :: InstanceHealthSummary -> InstanceHealthSummary -> Bool
== :: InstanceHealthSummary -> InstanceHealthSummary -> Bool
$c== :: InstanceHealthSummary -> InstanceHealthSummary -> Bool
Prelude.Eq, ReadPrec [InstanceHealthSummary]
ReadPrec InstanceHealthSummary
Int -> ReadS InstanceHealthSummary
ReadS [InstanceHealthSummary]
(Int -> ReadS InstanceHealthSummary)
-> ReadS [InstanceHealthSummary]
-> ReadPrec InstanceHealthSummary
-> ReadPrec [InstanceHealthSummary]
-> Read InstanceHealthSummary
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [InstanceHealthSummary]
$creadListPrec :: ReadPrec [InstanceHealthSummary]
readPrec :: ReadPrec InstanceHealthSummary
$creadPrec :: ReadPrec InstanceHealthSummary
readList :: ReadS [InstanceHealthSummary]
$creadList :: ReadS [InstanceHealthSummary]
readsPrec :: Int -> ReadS InstanceHealthSummary
$creadsPrec :: Int -> ReadS InstanceHealthSummary
Prelude.Read, Int -> InstanceHealthSummary -> ShowS
[InstanceHealthSummary] -> ShowS
InstanceHealthSummary -> String
(Int -> InstanceHealthSummary -> ShowS)
-> (InstanceHealthSummary -> String)
-> ([InstanceHealthSummary] -> ShowS)
-> Show InstanceHealthSummary
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InstanceHealthSummary] -> ShowS
$cshowList :: [InstanceHealthSummary] -> ShowS
show :: InstanceHealthSummary -> String
$cshow :: InstanceHealthSummary -> String
showsPrec :: Int -> InstanceHealthSummary -> ShowS
$cshowsPrec :: Int -> InstanceHealthSummary -> ShowS
Prelude.Show, (forall x. InstanceHealthSummary -> Rep InstanceHealthSummary x)
-> (forall x. Rep InstanceHealthSummary x -> InstanceHealthSummary)
-> Generic InstanceHealthSummary
forall x. Rep InstanceHealthSummary x -> InstanceHealthSummary
forall x. InstanceHealthSummary -> Rep InstanceHealthSummary x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InstanceHealthSummary x -> InstanceHealthSummary
$cfrom :: forall x. InstanceHealthSummary -> Rep InstanceHealthSummary x
Prelude.Generic)

-- |
-- Create a value of 'InstanceHealthSummary' 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:
--
-- 'instanceHealth', 'instanceHealthSummary_instanceHealth' - Describes the overall instance health. Valid values are below.
--
-- 'instanceName', 'instanceHealthSummary_instanceName' - The name of the Lightsail instance for which you are requesting health
-- check data.
--
-- 'instanceHealthReason', 'instanceHealthSummary_instanceHealthReason' - More information about the instance health. If the @instanceHealth@ is
-- @healthy@, then an @instanceHealthReason@ value is not provided.
--
-- If __@instanceHealth@__ is @initial@, the __@instanceHealthReason@__
-- value can be one of the following:
--
-- -   __@Lb.RegistrationInProgress@__ - The target instance is in the
--     process of being registered with the load balancer.
--
-- -   __@Lb.InitialHealthChecking@__ - The Lightsail load balancer is
--     still sending the target instance the minimum number of health
--     checks required to determine its health status.
--
-- If __@instanceHealth@__ is @unhealthy@, the __@instanceHealthReason@__
-- value can be one of the following:
--
-- -   __@Instance.ResponseCodeMismatch@__ - The health checks did not
--     return an expected HTTP code.
--
-- -   __@Instance.Timeout@__ - The health check requests timed out.
--
-- -   __@Instance.FailedHealthChecks@__ - The health checks failed because
--     the connection to the target instance timed out, the target instance
--     response was malformed, or the target instance failed the health
--     check for an unknown reason.
--
-- -   __@Lb.InternalError@__ - The health checks failed due to an internal
--     error.
--
-- If __@instanceHealth@__ is @unused@, the __@instanceHealthReason@__
-- value can be one of the following:
--
-- -   __@Instance.NotRegistered@__ - The target instance is not registered
--     with the target group.
--
-- -   __@Instance.NotInUse@__ - The target group is not used by any load
--     balancer, or the target instance is in an Availability Zone that is
--     not enabled for its load balancer.
--
-- -   __@Instance.IpUnusable@__ - The target IP address is reserved for
--     use by a Lightsail load balancer.
--
-- -   __@Instance.InvalidState@__ - The target is in the stopped or
--     terminated state.
--
-- If __@instanceHealth@__ is @draining@, the __@instanceHealthReason@__
-- value can be one of the following:
--
-- -   __@Instance.DeregistrationInProgress@__ - The target instance is in
--     the process of being deregistered and the deregistration delay
--     period has not expired.
newInstanceHealthSummary ::
  InstanceHealthSummary
newInstanceHealthSummary :: InstanceHealthSummary
newInstanceHealthSummary =
  InstanceHealthSummary' :: Maybe InstanceHealthState
-> Maybe Text
-> Maybe InstanceHealthReason
-> InstanceHealthSummary
InstanceHealthSummary'
    { $sel:instanceHealth:InstanceHealthSummary' :: Maybe InstanceHealthState
instanceHealth =
        Maybe InstanceHealthState
forall a. Maybe a
Prelude.Nothing,
      $sel:instanceName:InstanceHealthSummary' :: Maybe Text
instanceName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:instanceHealthReason:InstanceHealthSummary' :: Maybe InstanceHealthReason
instanceHealthReason = Maybe InstanceHealthReason
forall a. Maybe a
Prelude.Nothing
    }

-- | Describes the overall instance health. Valid values are below.
instanceHealthSummary_instanceHealth :: Lens.Lens' InstanceHealthSummary (Prelude.Maybe InstanceHealthState)
instanceHealthSummary_instanceHealth :: (Maybe InstanceHealthState -> f (Maybe InstanceHealthState))
-> InstanceHealthSummary -> f InstanceHealthSummary
instanceHealthSummary_instanceHealth = (InstanceHealthSummary -> Maybe InstanceHealthState)
-> (InstanceHealthSummary
    -> Maybe InstanceHealthState -> InstanceHealthSummary)
-> Lens
     InstanceHealthSummary
     InstanceHealthSummary
     (Maybe InstanceHealthState)
     (Maybe InstanceHealthState)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InstanceHealthSummary' {Maybe InstanceHealthState
instanceHealth :: Maybe InstanceHealthState
$sel:instanceHealth:InstanceHealthSummary' :: InstanceHealthSummary -> Maybe InstanceHealthState
instanceHealth} -> Maybe InstanceHealthState
instanceHealth) (\s :: InstanceHealthSummary
s@InstanceHealthSummary' {} Maybe InstanceHealthState
a -> InstanceHealthSummary
s {$sel:instanceHealth:InstanceHealthSummary' :: Maybe InstanceHealthState
instanceHealth = Maybe InstanceHealthState
a} :: InstanceHealthSummary)

-- | The name of the Lightsail instance for which you are requesting health
-- check data.
instanceHealthSummary_instanceName :: Lens.Lens' InstanceHealthSummary (Prelude.Maybe Prelude.Text)
instanceHealthSummary_instanceName :: (Maybe Text -> f (Maybe Text))
-> InstanceHealthSummary -> f InstanceHealthSummary
instanceHealthSummary_instanceName = (InstanceHealthSummary -> Maybe Text)
-> (InstanceHealthSummary -> Maybe Text -> InstanceHealthSummary)
-> Lens
     InstanceHealthSummary
     InstanceHealthSummary
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InstanceHealthSummary' {Maybe Text
instanceName :: Maybe Text
$sel:instanceName:InstanceHealthSummary' :: InstanceHealthSummary -> Maybe Text
instanceName} -> Maybe Text
instanceName) (\s :: InstanceHealthSummary
s@InstanceHealthSummary' {} Maybe Text
a -> InstanceHealthSummary
s {$sel:instanceName:InstanceHealthSummary' :: Maybe Text
instanceName = Maybe Text
a} :: InstanceHealthSummary)

-- | More information about the instance health. If the @instanceHealth@ is
-- @healthy@, then an @instanceHealthReason@ value is not provided.
--
-- If __@instanceHealth@__ is @initial@, the __@instanceHealthReason@__
-- value can be one of the following:
--
-- -   __@Lb.RegistrationInProgress@__ - The target instance is in the
--     process of being registered with the load balancer.
--
-- -   __@Lb.InitialHealthChecking@__ - The Lightsail load balancer is
--     still sending the target instance the minimum number of health
--     checks required to determine its health status.
--
-- If __@instanceHealth@__ is @unhealthy@, the __@instanceHealthReason@__
-- value can be one of the following:
--
-- -   __@Instance.ResponseCodeMismatch@__ - The health checks did not
--     return an expected HTTP code.
--
-- -   __@Instance.Timeout@__ - The health check requests timed out.
--
-- -   __@Instance.FailedHealthChecks@__ - The health checks failed because
--     the connection to the target instance timed out, the target instance
--     response was malformed, or the target instance failed the health
--     check for an unknown reason.
--
-- -   __@Lb.InternalError@__ - The health checks failed due to an internal
--     error.
--
-- If __@instanceHealth@__ is @unused@, the __@instanceHealthReason@__
-- value can be one of the following:
--
-- -   __@Instance.NotRegistered@__ - The target instance is not registered
--     with the target group.
--
-- -   __@Instance.NotInUse@__ - The target group is not used by any load
--     balancer, or the target instance is in an Availability Zone that is
--     not enabled for its load balancer.
--
-- -   __@Instance.IpUnusable@__ - The target IP address is reserved for
--     use by a Lightsail load balancer.
--
-- -   __@Instance.InvalidState@__ - The target is in the stopped or
--     terminated state.
--
-- If __@instanceHealth@__ is @draining@, the __@instanceHealthReason@__
-- value can be one of the following:
--
-- -   __@Instance.DeregistrationInProgress@__ - The target instance is in
--     the process of being deregistered and the deregistration delay
--     period has not expired.
instanceHealthSummary_instanceHealthReason :: Lens.Lens' InstanceHealthSummary (Prelude.Maybe InstanceHealthReason)
instanceHealthSummary_instanceHealthReason :: (Maybe InstanceHealthReason -> f (Maybe InstanceHealthReason))
-> InstanceHealthSummary -> f InstanceHealthSummary
instanceHealthSummary_instanceHealthReason = (InstanceHealthSummary -> Maybe InstanceHealthReason)
-> (InstanceHealthSummary
    -> Maybe InstanceHealthReason -> InstanceHealthSummary)
-> Lens
     InstanceHealthSummary
     InstanceHealthSummary
     (Maybe InstanceHealthReason)
     (Maybe InstanceHealthReason)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InstanceHealthSummary' {Maybe InstanceHealthReason
instanceHealthReason :: Maybe InstanceHealthReason
$sel:instanceHealthReason:InstanceHealthSummary' :: InstanceHealthSummary -> Maybe InstanceHealthReason
instanceHealthReason} -> Maybe InstanceHealthReason
instanceHealthReason) (\s :: InstanceHealthSummary
s@InstanceHealthSummary' {} Maybe InstanceHealthReason
a -> InstanceHealthSummary
s {$sel:instanceHealthReason:InstanceHealthSummary' :: Maybe InstanceHealthReason
instanceHealthReason = Maybe InstanceHealthReason
a} :: InstanceHealthSummary)

instance Core.FromJSON InstanceHealthSummary where
  parseJSON :: Value -> Parser InstanceHealthSummary
parseJSON =
    String
-> (Object -> Parser InstanceHealthSummary)
-> Value
-> Parser InstanceHealthSummary
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"InstanceHealthSummary"
      ( \Object
x ->
          Maybe InstanceHealthState
-> Maybe Text
-> Maybe InstanceHealthReason
-> InstanceHealthSummary
InstanceHealthSummary'
            (Maybe InstanceHealthState
 -> Maybe Text
 -> Maybe InstanceHealthReason
 -> InstanceHealthSummary)
-> Parser (Maybe InstanceHealthState)
-> Parser
     (Maybe Text -> Maybe InstanceHealthReason -> InstanceHealthSummary)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe InstanceHealthState)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"instanceHealth")
            Parser
  (Maybe Text -> Maybe InstanceHealthReason -> InstanceHealthSummary)
-> Parser (Maybe Text)
-> Parser (Maybe InstanceHealthReason -> InstanceHealthSummary)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"instanceName")
            Parser (Maybe InstanceHealthReason -> InstanceHealthSummary)
-> Parser (Maybe InstanceHealthReason)
-> Parser InstanceHealthSummary
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe InstanceHealthReason)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"instanceHealthReason")
      )

instance Prelude.Hashable InstanceHealthSummary

instance Prelude.NFData InstanceHealthSummary