Skip to content
Snippets Groups Projects
Commit 423b2dd5 authored by Michele Tartara's avatar Michele Tartara
Browse files

Add monitoring HTTP API structure


Add all the supported commands to the API.
The actual response is still to be implemented.

Signed-off-by: default avatarMichele Tartara <mtartara@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent eb65c915
No related branches found
No related tags found
No related merge requests found
......@@ -31,9 +31,11 @@ module Ganeti.Monitoring.Server
, prepMain
) where
import Control.Applicative
import Control.Monad
import Snap.Core
import Snap.Http.Server
import Data.Text
import Data.ByteString.Char8
import qualified Text.JSON as J
import Ganeti.Daemon
......@@ -79,16 +81,53 @@ prepMain opts _ =
-- | Reply to the supported API version numbers query.
versionQ :: Snap ()
versionQ = writeText . pack $ J.encode [latestAPIVersion]
versionQ = writeBS . pack $ J.encode [latestAPIVersion]
-- | Version 1 of the monitoring HTTP API.
version1Api :: Snap ()
version1Api =
let returnNull = writeBS . pack $ J.encode J.JSNull :: Snap ()
in ifTop returnNull <|>
route
[ ("list", listHandler)
, ("report", reportHandler)
]
-- | Handler for returning lists.
listHandler :: Snap ()
listHandler =
dir "collectors" $ writeText "TODO: return the list of collectors"
-- | Handler for returning data collector reports.
reportHandler :: Snap ()
reportHandler =
route
[ ("all", allReports)
, (":category/:collector", oneReport)
]
-- | Return the report of all the available collectors
allReports :: Snap ()
allReports = writeText "TODO: return the reports of all the collectors"
-- | Return the report of one collector
oneReport :: Snap ()
oneReport = do
category <- fmap (maybe mzero unpack) $ getParam "category"
collector <- fmap (maybe mzero unpack) $ getParam "collector"
writeBS . pack $
"TODO: return the report for collector " ++ category
++ "/" ++ collector
-- | The function implementing the HTTP API of the monitoring agent.
-- TODO: Currently it only replies to the API version query: implement all the
-- missing features.
monitoringApi :: Snap ()
monitoringApi =
ifTop versionQ
ifTop versionQ <|>
dir "1" version1Api
-- | Main function.
main :: MainFn CheckResult PrepResult
main _ _ httpConf =
httpServe httpConf monitoringApi
httpServe httpConf $ method GET monitoringApi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment