Revision ecb783f0

b/src/Ganeti/Monitoring/Server.hs
35 35
import Control.Monad
36 36
import Snap.Core
37 37
import Snap.Http.Server
38
import Data.ByteString.Char8
38
import Data.ByteString.Char8 hiding (map)
39 39
import qualified Text.JSON as J
40 40

  
41 41
import Ganeti.Daemon
42
import qualified Ganeti.DataCollectors.Drbd as Drbd
43
import Ganeti.DataCollectors.Types
42 44
import qualified Ganeti.Constants as C
43 45

  
44 46
-- * Types and constants definitions
......
53 55
latestAPIVersion :: Int
54 56
latestAPIVersion = 1
55 57

  
58
-- | Type describing a data collector basic information
59
data DataCollector = DataCollector
60
  { dName     :: String           -- ^ Name of the data collector
61
  , dCategory :: Maybe DCCategory -- ^ Category (storage, instance, ecc)
62
                                  --   of the collector
63
  , dKind     :: DCKind           -- ^ Kind (performance or status reporting) of
64
                                  --   the data collector
65
  }
66

  
67
-- | The list of available builtin data collectors.
68
collectors :: [DataCollector]
69
collectors =
70
  [ DataCollector Drbd.dcName Drbd.dcCategory Drbd.dcKind
71
  ]
72

  
73

  
56 74
-- * Configuration handling
57 75

  
58 76
-- | The default configuration for the HTTP server.
......
93 111
       , ("report", reportHandler)
94 112
       ]
95 113

  
114
-- | Get the JSON representation of a data collector to be used in the collector
115
-- list.
116
dcListItem :: DataCollector -> J.JSValue
117
dcListItem dc =
118
  J.JSArray
119
    [ J.showJSON $ dName dc
120
    , maybe J.JSNull J.showJSON $ dCategory dc
121
    , J.showJSON $ dKind dc
122
    ]
123

  
96 124
-- | Handler for returning lists.
97 125
listHandler :: Snap ()
98 126
listHandler =
99
  dir "collectors" $ writeText "TODO: return the list of collectors"
127
  dir "collectors" . writeBS . pack . J.encode $ map dcListItem collectors
100 128

  
101 129
-- | Handler for returning data collector reports.
102 130
reportHandler :: Snap ()

Also available in: Unified diff