From 82437b280123d50fcab4f63e8ddfb79fdf6f6786 Mon Sep 17 00:00:00 2001 From: Michele Tartara Date: Thu, 14 Mar 2013 13:09:27 +0000 Subject: [PATCH] Add DCStatus data type for the data collectors Also adds the DCStatusCode, part of DCStatus, and the addStatus utility function for adding the "status" field to an already existing JSValue. The design document is updated to have the status codes sorted by increasing seriousness. Signed-off-by: Michele Tartara Reviewed-by: Bernardo Dal Seno --- doc/design-monitoring-agent.rst | 8 ++++---- src/Ganeti/DataCollectors/Types.hs | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/doc/design-monitoring-agent.rst b/doc/design-monitoring-agent.rst index 5f40fea..9957ac2 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 bef28c9..8a119ab 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 -- 1.7.10.4