There is no need of external intervention.
``2``
- The collector can determine that something is wrong and Ganeti has no
- way to fix it autonomously. External intervention is required.
-
- ``4``
The collector has failed to understand whether the status is good or
bad. Further analysis is required. Interpret this status as a
potentially dangerous situation.
+ ``4``
+ The collector can determine that something is wrong and Ganeti has no
+ way to fix it autonomously. External intervention is required.
+
``message``
A message to better explain the reason of the status.
The exact format of the message string is data collector dependent.
-}
module Ganeti.DataCollectors.Types
- ( DCReport(..)
+ ( addStatus
, DCCategory(..)
, DCKind(..)
+ , DCReport(..)
+ , DCStatus(..)
+ , DCStatusCode(..)
, DCVersion(..)
, buildReport
) where
readJSON =
error "JSON read instance not implemented for type DCCategory"
+-- | The possible status codes of a data collector.
+data DCStatusCode = DCSCOk -- ^ Everything is OK
+ | DCSCTempBad -- ^ Bad, but being automatically fixed
+ | DCSCUnknown -- ^ Unable to determine the status
+ | DCSCBad -- ^ Bad. External intervention required
+ deriving (Show, Eq, Ord)
+
+-- | The JSON instance for CollectorStatus.
+instance JSON DCStatusCode where
+ showJSON DCSCOk = showJSON (0 :: Int)
+ showJSON DCSCTempBad = showJSON (1 :: Int)
+ showJSON DCSCUnknown = showJSON (2 :: Int)
+ showJSON DCSCBad = showJSON (4 :: Int)
+ readJSON = error "JSON read instance not implemented for type DCStatusCode"
+
+-- | The status of a \"status reporting data collector\".
+$(buildObject "DCStatus" "dcStatus"
+ [ simpleField "code" [t| DCStatusCode |]
+ , simpleField "message" [t| String |]
+ ])
+
-- | The type representing the kind of the collector.
data DCKind = DCKPerf -- ^ Performance reporting collector
| DCKStatus -- ^ Status reporting collector
, simpleField "data" [t| JSValue |]
])
+-- | Add the data collector status information to the JSON representation of
+-- the collector data.
+addStatus :: DCStatus -> JSValue -> JSValue
+addStatus dcStatus (JSObject obj) =
+ makeObj $ ("status", showJSON dcStatus) : fromJSObject obj
+addStatus dcStatus value = makeObj
+ [ ("status", showJSON dcStatus)
+ , ("data", value)
+ ]
+
-- | Utility function for building a report automatically adding the current
-- timestamp (rounded up to seconds).
-- If the version is not specified, it will be set to the value indicating