Revision f0e4b2a4 src/Ganeti/DataCollectors/Types.hs

b/src/Ganeti/DataCollectors/Types.hs
27 27

  
28 28
module Ganeti.DataCollectors.Types
29 29
  ( DCReport(..)
30
  , DCCategory(..)
30 31
  , DCVersion(..)
31 32
  , buildReport
32 33
  ) where
......
37 38
import Ganeti.THH
38 39
import Ganeti.Utils (getCurrentTime)
39 40

  
41
-- | The possible classes a data collector can belong to.
42
data DCCategory = DCInstance | DCStorage | DCDaemon | DCHypervisor
43
  deriving (Show, Eq)
44

  
45
-- | The JSON instance for DCCategory.
46
instance JSON DCCategory where
47
  showJSON = showJSON . show
48
  readJSON =
49
    error "JSON read instance not implemented for type DCCategory"
50

  
40 51
-- | Type representing the version number of a data collector.
41 52
data DCVersion = DCVerBuiltin | DCVersion String deriving (Show, Eq)
42 53

  
......
52 63
  , simpleField "version"        [t| DCVersion |]
53 64
  , simpleField "format_version" [t| Int |]
54 65
  , simpleField "timestamp"      [t| Integer |]
66
  , optionalNullSerField $
67
      simpleField "category"     [t| DCCategory |]
55 68
  , simpleField "data"           [t| JSValue |]
56 69
  ])
57 70

  
......
59 72
-- timestamp (rounded up to seconds).
60 73
-- If the version is not specified, it will be set to the value indicating
61 74
-- a builtin collector.
62
buildReport :: String -> DCVersion -> Int -> JSValue -> IO DCReport
63
buildReport name version format_version jsonData = do
75
buildReport :: String -> DCVersion -> Int -> Maybe DCCategory -> JSValue
76
            -> IO DCReport
77
buildReport name version format_version category jsonData = do
64 78
  now <- getCurrentTime
65 79
  let timestamp = now * 1000000000 :: Integer
66
  return $ DCReport name version format_version timestamp jsonData
80
  return $ DCReport name version format_version timestamp category jsonData

Also available in: Unified diff