chore(health): getHealthInterfaceR responds to mime content type header

This commit is contained in:
Steffen Jost 2024-02-06 10:32:00 +00:00
parent 1464a9a582
commit 42f1a802b5

View File

@ -67,27 +67,30 @@ matchesUniqueInterfaceHealth (UniqueInterfaceHealth ai as aw) (UniqueInterfaceHe
eqOrNothing a b = a == b eqOrNothing a b = a == b
getHealthInterfaceR :: [Text] -> Handler Html getHealthInterfaceR :: [Text] -> Handler TypedContent
getHealthInterfaceR ris = do getHealthInterfaceR (dropWhile (=="force") -> ris) = do -- for backwards compatibility we ignore leading "force"
let (forced, ris') = case ris of let interfs = splitInterfaces $ identifyInterfaces ris
("force":ris0) -> (True , ris0)
_ -> (False, ris )
interfs = splitInterfaces $ identifyInterfaces ris'
(missing, allok, res, iltable) <- runInterfaceLogTable interfs (missing, allok, res, iltable) <- runInterfaceLogTable interfs
let badMsg = "Unhealthy interfaces: " <> Text.intercalate ", " [iface | (iface, False) <- res]
when missing notFound -- send 404 if any requested interface was not found when missing notFound -- send 404 if any requested interface was not found
unless (forced || allok) $ sendResponseStatus internalServerError500 badMsg let respond = sendResponseStatus (bool internalServerError500 status200 allok)
content <- siteLayoutMsg MsgMenuHealthInterface $ do plainMsg = if allok
setTitleI MsgMenuHealthInterface then "Interfaces are healthy"
[whamlet| else "Unhealthy interfaces: " <> Text.intercalate ", " [iface | (iface, False) <- res]
$if allok selectRep $ do
Interfaces are healthy. provideRep $ do
$else content <- siteLayoutMsg MsgMenuHealthInterface $ do
#{badMsg} setTitleI MsgMenuHealthInterface
[whamlet|
<div>
#{plainMsg}
<div>
^{iltable}
|]
respond content
provideRep $ do
respond $ RepPlain $ toContent plainMsg
^{iltable}
|]
sendResponseStatus (bool internalServerError500 status200 allok) content
runInterfaceLogTable :: ReqBanInterfaceHealth -> Handler (Bool, Bool, [(Text,Bool)], Widget) runInterfaceLogTable :: ReqBanInterfaceHealth -> Handler (Bool, Bool, [(Text,Bool)], Widget)