26 |
26 |
-}
|
27 |
27 |
|
28 |
28 |
module Ganeti.DataCollectors.Types
|
29 |
|
( DCReport(..)
|
|
29 |
( addStatus
|
30 |
30 |
, DCCategory(..)
|
31 |
31 |
, DCKind(..)
|
|
32 |
, DCReport(..)
|
|
33 |
, DCStatus(..)
|
|
34 |
, DCStatusCode(..)
|
32 |
35 |
, DCVersion(..)
|
33 |
36 |
, buildReport
|
34 |
37 |
) where
|
... | ... | |
49 |
52 |
readJSON =
|
50 |
53 |
error "JSON read instance not implemented for type DCCategory"
|
51 |
54 |
|
|
55 |
-- | The possible status codes of a data collector.
|
|
56 |
data DCStatusCode = DCSCOk -- ^ Everything is OK
|
|
57 |
| DCSCTempBad -- ^ Bad, but being automatically fixed
|
|
58 |
| DCSCUnknown -- ^ Unable to determine the status
|
|
59 |
| DCSCBad -- ^ Bad. External intervention required
|
|
60 |
deriving (Show, Eq, Ord)
|
|
61 |
|
|
62 |
-- | The JSON instance for CollectorStatus.
|
|
63 |
instance JSON DCStatusCode where
|
|
64 |
showJSON DCSCOk = showJSON (0 :: Int)
|
|
65 |
showJSON DCSCTempBad = showJSON (1 :: Int)
|
|
66 |
showJSON DCSCUnknown = showJSON (2 :: Int)
|
|
67 |
showJSON DCSCBad = showJSON (4 :: Int)
|
|
68 |
readJSON = error "JSON read instance not implemented for type DCStatusCode"
|
|
69 |
|
|
70 |
-- | The status of a \"status reporting data collector\".
|
|
71 |
$(buildObject "DCStatus" "dcStatus"
|
|
72 |
[ simpleField "code" [t| DCStatusCode |]
|
|
73 |
, simpleField "message" [t| String |]
|
|
74 |
])
|
|
75 |
|
52 |
76 |
-- | The type representing the kind of the collector.
|
53 |
77 |
data DCKind = DCKPerf -- ^ Performance reporting collector
|
54 |
78 |
| DCKStatus -- ^ Status reporting collector
|
... | ... | |
81 |
105 |
, simpleField "data" [t| JSValue |]
|
82 |
106 |
])
|
83 |
107 |
|
|
108 |
-- | Add the data collector status information to the JSON representation of
|
|
109 |
-- the collector data.
|
|
110 |
addStatus :: DCStatus -> JSValue -> JSValue
|
|
111 |
addStatus dcStatus (JSObject obj) =
|
|
112 |
makeObj $ ("status", showJSON dcStatus) : fromJSObject obj
|
|
113 |
addStatus dcStatus value = makeObj
|
|
114 |
[ ("status", showJSON dcStatus)
|
|
115 |
, ("data", value)
|
|
116 |
]
|
|
117 |
|
84 |
118 |
-- | Utility function for building a report automatically adding the current
|
85 |
119 |
-- timestamp (rounded up to seconds).
|
86 |
120 |
-- If the version is not specified, it will be set to the value indicating
|