|
1 |
{-# LANGUAGE TemplateHaskell #-}
|
|
2 |
|
|
3 |
{-| Implementation of the Ganeti data collector types.
|
|
4 |
|
|
5 |
-}
|
|
6 |
|
|
7 |
{-
|
|
8 |
|
|
9 |
Copyright (C) 2012 Google Inc.
|
|
10 |
|
|
11 |
This program is free software; you can redistribute it and/or modify
|
|
12 |
it under the terms of the GNU General Public License as published by
|
|
13 |
the Free Software Foundation; either version 2 of the License, or
|
|
14 |
(at your option) any later version.
|
|
15 |
|
|
16 |
This program is distributed in the hope that it will be useful, but
|
|
17 |
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
19 |
General Public License for more details.
|
|
20 |
|
|
21 |
You should have received a copy of the GNU General Public License
|
|
22 |
along with this program; if not, write to the Free Software
|
|
23 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
24 |
02110-1301, USA.
|
|
25 |
|
|
26 |
-}
|
|
27 |
|
|
28 |
module Ganeti.DataCollectors.Types
|
|
29 |
( DCReport(..)
|
|
30 |
, buildReport
|
|
31 |
) where
|
|
32 |
|
|
33 |
import Data.Maybe
|
|
34 |
import Text.JSON
|
|
35 |
|
|
36 |
import Ganeti.Constants as C
|
|
37 |
import Ganeti.THH
|
|
38 |
import Ganeti.Utils (getCurrentTime)
|
|
39 |
|
|
40 |
-- | This is the format of the report produced by each data collector.
|
|
41 |
$(buildObject "DCReport" "dcReport"
|
|
42 |
[ simpleField "name" [t| String |]
|
|
43 |
, simpleField "version" [t| String |]
|
|
44 |
, simpleField "format_version" [t| Int |]
|
|
45 |
, simpleField "timestamp" [t| Integer |]
|
|
46 |
, simpleField "data" [t| JSValue |]
|
|
47 |
])
|
|
48 |
|
|
49 |
-- | Utility function for building a report automatically adding the current
|
|
50 |
-- timestamp (rounded up to seconds).
|
|
51 |
-- If the version is not specified, it will be set to the value indicating
|
|
52 |
-- a builtin collector.
|
|
53 |
buildReport :: String -> Maybe String -> Int -> JSValue -> IO DCReport
|
|
54 |
buildReport name version format_version jsonData = do
|
|
55 |
now <- getCurrentTime
|
|
56 |
let timestamp = now * 1000000000 :: Integer
|
|
57 |
ver = fromMaybe C.builtinDataCollectorVersion version
|
|
58 |
return $ DCReport name ver format_version timestamp jsonData
|