From ecb783f05e03533a546b1893ccc314882c518c03 Mon Sep 17 00:00:00 2001 From: Michele Tartara <mtartara@google.com> Date: Fri, 15 Mar 2013 17:40:12 +0000 Subject: [PATCH] Implement the "list collectors" API in monitoring Implement the handler for outputting the list of collectors (name, category, kind) in JSON format. Signed-off-by: Michele Tartara <mtartara@google.com> Reviewed-by: Helga Velroyen <helgav@google.com> --- src/Ganeti/Monitoring/Server.hs | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/Ganeti/Monitoring/Server.hs b/src/Ganeti/Monitoring/Server.hs index fc9174e95..9c31fa06f 100644 --- a/src/Ganeti/Monitoring/Server.hs +++ b/src/Ganeti/Monitoring/Server.hs @@ -35,10 +35,12 @@ import Control.Applicative import Control.Monad import Snap.Core import Snap.Http.Server -import Data.ByteString.Char8 +import Data.ByteString.Char8 hiding (map) import qualified Text.JSON as J import Ganeti.Daemon +import qualified Ganeti.DataCollectors.Drbd as Drbd +import Ganeti.DataCollectors.Types import qualified Ganeti.Constants as C -- * Types and constants definitions @@ -53,6 +55,22 @@ type PrepResult = Config Snap () latestAPIVersion :: Int latestAPIVersion = 1 +-- | Type describing a data collector basic information +data DataCollector = DataCollector + { dName :: String -- ^ Name of the data collector + , dCategory :: Maybe DCCategory -- ^ Category (storage, instance, ecc) + -- of the collector + , dKind :: DCKind -- ^ Kind (performance or status reporting) of + -- the data collector + } + +-- | The list of available builtin data collectors. +collectors :: [DataCollector] +collectors = + [ DataCollector Drbd.dcName Drbd.dcCategory Drbd.dcKind + ] + + -- * Configuration handling -- | The default configuration for the HTTP server. @@ -93,10 +111,20 @@ version1Api = , ("report", reportHandler) ] +-- | Get the JSON representation of a data collector to be used in the collector +-- list. +dcListItem :: DataCollector -> J.JSValue +dcListItem dc = + J.JSArray + [ J.showJSON $ dName dc + , maybe J.JSNull J.showJSON $ dCategory dc + , J.showJSON $ dKind dc + ] + -- | Handler for returning lists. listHandler :: Snap () listHandler = - dir "collectors" $ writeText "TODO: return the list of collectors" + dir "collectors" . writeBS . pack . J.encode $ map dcListItem collectors -- | Handler for returning data collector reports. reportHandler :: Snap () -- GitLab