From 423b2dd5891eae157bd3e1f199e7ee7da80f9976 Mon Sep 17 00:00:00 2001 From: Michele Tartara <mtartara@google.com> Date: Thu, 7 Mar 2013 15:36:48 +0000 Subject: [PATCH] Add monitoring HTTP API structure Add all the supported commands to the API. The actual response is still to be implemented. Signed-off-by: Michele Tartara <mtartara@google.com> Reviewed-by: Guido Trotter <ultrotter@google.com> --- src/Ganeti/Monitoring/Server.hs | 47 ++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/src/Ganeti/Monitoring/Server.hs b/src/Ganeti/Monitoring/Server.hs index 3b141e15c..fc9174e95 100644 --- a/src/Ganeti/Monitoring/Server.hs +++ b/src/Ganeti/Monitoring/Server.hs @@ -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 -- GitLab