Revision eb65c915 src/Ganeti/Monitoring/Server.hs

b/src/Ganeti/Monitoring/Server.hs
31 31
  , prepMain
32 32
  ) where
33 33

  
34
import Snap.Core
35
import Snap.Http.Server
36
import Data.Text
37
import qualified Text.JSON as J
38

  
34 39
import Ganeti.Daemon
40
import qualified Ganeti.Constants as C
35 41

  
36 42
-- * Types and constants definitions
37 43

  
......
39 45
type CheckResult = ()
40 46

  
41 47
-- | Type alias for prepMain results.
42
type PrepResult = ()
48
type PrepResult = Config Snap ()
49

  
50
-- | Version of the latest supported http API.
51
latestAPIVersion :: Int
52
latestAPIVersion = 1
53

  
54
-- * Configuration handling
55

  
56
-- | The default configuration for the HTTP server.
57
defaultHttpConf :: Config Snap ()
58
defaultHttpConf =
59
  setAccessLog (ConfigFileLog C.daemonsExtraLogfilesGanetiMondAccess) .
60
  setCompression False .
61
  setErrorLog (ConfigFileLog C.daemonsExtraLogfilesGanetiMondError) $
62
  setVerbose False
63
  emptyConfig
43 64

  
44 65
-- * Helper functions
45 66

  
......
49 70

  
50 71
-- | Prepare function for monitoring agent.
51 72
prepMain :: PrepFn CheckResult PrepResult
52
prepMain _ _ = return ()
73
prepMain opts _ =
74
  return $
75
    setPort (maybe C.defaultMondPort fromIntegral (optPort opts))
76
      defaultHttpConf
77

  
78
-- * Query answers
79

  
80
-- | Reply to the supported API version numbers query.
81
versionQ :: Snap ()
82
versionQ = writeText . pack $ J.encode [latestAPIVersion]
83

  
84
-- | The function implementing the HTTP API of the monitoring agent.
85
-- TODO: Currently it only replies to the API version query: implement all the
86
-- missing features.
87
monitoringApi :: Snap ()
88
monitoringApi =
89
  ifTop versionQ
53 90

  
54 91
-- | Main function.
55 92
main :: MainFn CheckResult PrepResult
56
main _ _ _ =
57
  return ()
93
main _ _ httpConf =
94
  httpServe httpConf monitoringApi

Also available in: Unified diff