refactor interface-health #208

Merged
jost merged 6 commits from fradrive/health-interfaces into master 2024-02-08 08:59:40 +01:00
Showing only changes of commit 4a843fe30e - Show all commits

View File

@ -68,28 +68,25 @@ matchesUniqueInterfaceHealth (UniqueInterfaceHealth ai as aw) (UniqueInterfaceHe
getHealthInterfaceR :: [Text] -> Handler TypedContent
getHealthInterfaceR (dropWhile (=="force") -> ris) = do -- for backwards compatibility we ignore leading "force"
getHealthInterfaceR (dropWhile (=="force") -> ris) = do -- for backwards compatibility we ignore leading "force"
let interfs = splitInterfaces $ identifyInterfaces ris
(missing, allok, res, iltable) <- runInterfaceLogTable interfs
when missing notFound -- send 404 if any requested interface was not found
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
when missing notFound -- send 404 if any requested interface was not found
let ihstatus = if allok then status200
else internalServerError500
plainMsg = if allok then "Interfaces are healthy."
else "Unhealthy interfaces: " <> Text.intercalate ", " [iface | (iface, False) <- res]
sendResponseStatus ihstatus <=< selectRep $ do
provideRep . siteLayoutMsg MsgMenuHealthInterface $ do
setTitleI MsgMenuHealthInterface
[whamlet|
<div>
#{plainMsg}
<div>
^{iltable}
|]
respond content
|]
provideRep $ do
respond $ RepPlain $ toContent plainMsg
provideRep $ return $ RepPlain $ toContent plainMsg