diff --git a/doc/design-monitoring-agent.rst b/doc/design-monitoring-agent.rst index 5f40feaf44e34cd0c76492d4c0e9086e1ced9788..9957ac25553681311ecd610e509dfecd80e2c5e7 100644 --- a/doc/design-monitoring-agent.rst +++ b/doc/design-monitoring-agent.rst @@ -185,14 +185,14 @@ in its ``data`` section, at least the following field: 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. diff --git a/src/Ganeti/DataCollectors/Types.hs b/src/Ganeti/DataCollectors/Types.hs index bef28c98fec31ad5921c41112c6cdd0e0d354102..8a119ab868d4798232c53c3e7c4bbaa4e34b004b 100644 --- a/src/Ganeti/DataCollectors/Types.hs +++ b/src/Ganeti/DataCollectors/Types.hs @@ -26,9 +26,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -} module Ganeti.DataCollectors.Types - ( DCReport(..) + ( addStatus , DCCategory(..) , DCKind(..) + , DCReport(..) + , DCStatus(..) + , DCStatusCode(..) , DCVersion(..) , buildReport ) where @@ -49,6 +52,27 @@ instance JSON DCCategory 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 @@ -81,6 +105,16 @@ $(buildObject "DCReport" "dcReport" , 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