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)
plainMsg = if allok
then "Interfaces are healthy"
else "Unhealthy interfaces: " <> Text.intercalate ", " [iface | (iface, False) <- res]
selectRep $ do
provideRep $ do
content <- siteLayoutMsg MsgMenuHealthInterface $ do content <- siteLayoutMsg MsgMenuHealthInterface $ do
setTitleI MsgMenuHealthInterface setTitleI MsgMenuHealthInterface
[whamlet| [whamlet|
$if allok <div>
Interfaces are healthy. #{plainMsg}
$else <div>
#{badMsg}
^{iltable} ^{iltable}
|] |]
sendResponseStatus (bool internalServerError500 status200 allok) content respond content
provideRep $ do
respond $ RepPlain $ toContent plainMsg
runInterfaceLogTable :: ReqBanInterfaceHealth -> Handler (Bool, Bool, [(Text,Bool)], Widget) runInterfaceLogTable :: ReqBanInterfaceHealth -> Handler (Bool, Bool, [(Text,Bool)], Widget)