root / src / Ganeti / Monitoring / Server.hs @ eb65c915
History | View | Annotate | Download (2.4 kB)
1 | 13cc7b84 | Michele Tartara | {-# LANGUAGE OverloadedStrings #-} |
---|---|---|---|
2 | 13cc7b84 | Michele Tartara | |
3 | 13cc7b84 | Michele Tartara | {-| Implementation of the Ganeti confd server functionality. |
4 | 13cc7b84 | Michele Tartara | |
5 | 13cc7b84 | Michele Tartara | -} |
6 | 13cc7b84 | Michele Tartara | |
7 | 13cc7b84 | Michele Tartara | {- |
8 | 13cc7b84 | Michele Tartara | |
9 | 13cc7b84 | Michele Tartara | Copyright (C) 2013 Google Inc. |
10 | 13cc7b84 | Michele Tartara | |
11 | 13cc7b84 | Michele Tartara | This program is free software; you can redistribute it and/or modify |
12 | 13cc7b84 | Michele Tartara | it under the terms of the GNU General Public License as published by |
13 | 13cc7b84 | Michele Tartara | the Free Software Foundation; either version 2 of the License, or |
14 | 13cc7b84 | Michele Tartara | (at your option) any later version. |
15 | 13cc7b84 | Michele Tartara | |
16 | 13cc7b84 | Michele Tartara | This program is distributed in the hope that it will be useful, but |
17 | 13cc7b84 | Michele Tartara | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | 13cc7b84 | Michele Tartara | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
19 | 13cc7b84 | Michele Tartara | General Public License for more details. |
20 | 13cc7b84 | Michele Tartara | |
21 | 13cc7b84 | Michele Tartara | You should have received a copy of the GNU General Public License |
22 | 13cc7b84 | Michele Tartara | along with this program; if not, write to the Free Software |
23 | 13cc7b84 | Michele Tartara | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
24 | 13cc7b84 | Michele Tartara | 02110-1301, USA. |
25 | 13cc7b84 | Michele Tartara | |
26 | 13cc7b84 | Michele Tartara | -} |
27 | 13cc7b84 | Michele Tartara | |
28 | 13cc7b84 | Michele Tartara | module Ganeti.Monitoring.Server |
29 | 13cc7b84 | Michele Tartara | ( main |
30 | 13cc7b84 | Michele Tartara | , checkMain |
31 | 13cc7b84 | Michele Tartara | , prepMain |
32 | 13cc7b84 | Michele Tartara | ) where |
33 | 13cc7b84 | Michele Tartara | |
34 | eb65c915 | Michele Tartara | import Snap.Core |
35 | eb65c915 | Michele Tartara | import Snap.Http.Server |
36 | eb65c915 | Michele Tartara | import Data.Text |
37 | eb65c915 | Michele Tartara | import qualified Text.JSON as J |
38 | eb65c915 | Michele Tartara | |
39 | 13cc7b84 | Michele Tartara | import Ganeti.Daemon |
40 | eb65c915 | Michele Tartara | import qualified Ganeti.Constants as C |
41 | 13cc7b84 | Michele Tartara | |
42 | 13cc7b84 | Michele Tartara | -- * Types and constants definitions |
43 | 13cc7b84 | Michele Tartara | |
44 | 13cc7b84 | Michele Tartara | -- | Type alias for checkMain results. |
45 | 13cc7b84 | Michele Tartara | type CheckResult = () |
46 | 13cc7b84 | Michele Tartara | |
47 | 13cc7b84 | Michele Tartara | -- | Type alias for prepMain results. |
48 | eb65c915 | Michele Tartara | type PrepResult = Config Snap () |
49 | eb65c915 | Michele Tartara | |
50 | eb65c915 | Michele Tartara | -- | Version of the latest supported http API. |
51 | eb65c915 | Michele Tartara | latestAPIVersion :: Int |
52 | eb65c915 | Michele Tartara | latestAPIVersion = 1 |
53 | eb65c915 | Michele Tartara | |
54 | eb65c915 | Michele Tartara | -- * Configuration handling |
55 | eb65c915 | Michele Tartara | |
56 | eb65c915 | Michele Tartara | -- | The default configuration for the HTTP server. |
57 | eb65c915 | Michele Tartara | defaultHttpConf :: Config Snap () |
58 | eb65c915 | Michele Tartara | defaultHttpConf = |
59 | eb65c915 | Michele Tartara | setAccessLog (ConfigFileLog C.daemonsExtraLogfilesGanetiMondAccess) . |
60 | eb65c915 | Michele Tartara | setCompression False . |
61 | eb65c915 | Michele Tartara | setErrorLog (ConfigFileLog C.daemonsExtraLogfilesGanetiMondError) $ |
62 | eb65c915 | Michele Tartara | setVerbose False |
63 | eb65c915 | Michele Tartara | emptyConfig |
64 | 13cc7b84 | Michele Tartara | |
65 | 13cc7b84 | Michele Tartara | -- * Helper functions |
66 | 13cc7b84 | Michele Tartara | |
67 | 13cc7b84 | Michele Tartara | -- | Check function for the monitoring agent. |
68 | 13cc7b84 | Michele Tartara | checkMain :: CheckFn CheckResult |
69 | 13cc7b84 | Michele Tartara | checkMain _ = return $ Right () |
70 | 13cc7b84 | Michele Tartara | |
71 | 13cc7b84 | Michele Tartara | -- | Prepare function for monitoring agent. |
72 | 13cc7b84 | Michele Tartara | prepMain :: PrepFn CheckResult PrepResult |
73 | eb65c915 | Michele Tartara | prepMain opts _ = |
74 | eb65c915 | Michele Tartara | return $ |
75 | eb65c915 | Michele Tartara | setPort (maybe C.defaultMondPort fromIntegral (optPort opts)) |
76 | eb65c915 | Michele Tartara | defaultHttpConf |
77 | eb65c915 | Michele Tartara | |
78 | eb65c915 | Michele Tartara | -- * Query answers |
79 | eb65c915 | Michele Tartara | |
80 | eb65c915 | Michele Tartara | -- | Reply to the supported API version numbers query. |
81 | eb65c915 | Michele Tartara | versionQ :: Snap () |
82 | eb65c915 | Michele Tartara | versionQ = writeText . pack $ J.encode [latestAPIVersion] |
83 | eb65c915 | Michele Tartara | |
84 | eb65c915 | Michele Tartara | -- | The function implementing the HTTP API of the monitoring agent. |
85 | eb65c915 | Michele Tartara | -- TODO: Currently it only replies to the API version query: implement all the |
86 | eb65c915 | Michele Tartara | -- missing features. |
87 | eb65c915 | Michele Tartara | monitoringApi :: Snap () |
88 | eb65c915 | Michele Tartara | monitoringApi = |
89 | eb65c915 | Michele Tartara | ifTop versionQ |
90 | 13cc7b84 | Michele Tartara | |
91 | 13cc7b84 | Michele Tartara | -- | Main function. |
92 | 13cc7b84 | Michele Tartara | main :: MainFn CheckResult PrepResult |
93 | eb65c915 | Michele Tartara | main _ _ httpConf = |
94 | eb65c915 | Michele Tartara | httpServe httpConf monitoringApi |