Add information about what class a data collector is part of,
what is the general status of the report, an optional explicative message.

Also, the DRBD data collector is changed accordingly.

Signed-off-by: Michele Tartara <[email protected]>
---
 src/Ganeti/DataCollectors/Drbd.hs  |  8 ++++---
 src/Ganeti/DataCollectors/Types.hs | 49 +++++++++++++++++++++++++++++---------
 2 files changed, 43 insertions(+), 14 deletions(-)

diff --git a/src/Ganeti/DataCollectors/Drbd.hs 
b/src/Ganeti/DataCollectors/Drbd.hs
index 8f0aeb4..c6b7278 100644
--- a/src/Ganeti/DataCollectors/Drbd.hs
+++ b/src/Ganeti/DataCollectors/Drbd.hs
@@ -105,7 +105,8 @@ getPairingInfo (Just filename) = do
       J.Error msg -> BT.Bad msg
 
 -- | This function builds a report with the DRBD status.
-buildDRBDReport :: FilePath -> Maybe FilePath -> IO DCReport
+buildDRBDReport :: FilePath -> Maybe FilePath
+  -> IO (CollectorStatus, Maybe String, J.JSValue)
 buildDRBDReport statusFile pairingFile = do
   contents <-
     ((E.try $ readFile statusFile) :: IO (Either IOError String)) >>=
@@ -118,7 +119,7 @@ buildDRBDReport statusFile pairingFile = do
         show (Prelude.take defaultCharNum $ unpack unparsedText) ++ "\n"
           ++ show contexts ++ "\n" ++ errorMessage
       A.Done _ drbdStatus -> return $ J.showJSON drbdStatus
-  buildReport dcName Nothing dcFormatVersion jsonData
+  return (DcInfo, Nothing, jsonData)
 
 -- | Main function.
 main :: Options -> [String] -> IO ()
@@ -127,5 +128,6 @@ main opts args = do
       pairingFile = optDrbdPairing opts
   unless (null args) . exitErr $ "This program takes exactly zero" ++
                                   " arguments, got '" ++ unwords args ++ "'"
-  report <- buildDRBDReport statusFile pairingFile
+  report <- buildDRBDReport statusFile pairingFile >>=
+    buildReport dcName Nothing dcFormatVersion Nothing
   putStrLn $ J.encode report
diff --git a/src/Ganeti/DataCollectors/Types.hs 
b/src/Ganeti/DataCollectors/Types.hs
index c423a47..8c48e5d 100644
--- a/src/Ganeti/DataCollectors/Types.hs
+++ b/src/Ganeti/DataCollectors/Types.hs
@@ -27,6 +27,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
 module Ganeti.DataCollectors.Types
   ( DCReport(..)
+  , CollectorClass(..)
+  , CollectorStatus(..)
   , buildReport
   ) where
 
@@ -37,22 +39,47 @@ import Ganeti.Constants as C
 import Ganeti.THH
 import Ganeti.Utils (getCurrentTime)
 
+-- | The possible classes a data collector can belong to.
+data CollectorClass = Instance | Storage | Daemon | Hypervisor
+  deriving (Show, Eq)
+
+-- | The JSON instance for CollectorClass.
+instance JSON CollectorClass where
+  showJSON = showJSON . show
+  readJSON = error "JSON read instance not implemented for type CollectorClass"
+
+-- | The possible statuses of a data collector.
+data CollectorStatus = DcOk | DcBad | DcInfo | DcUnknown deriving (Show, Eq)
+
+-- | The JSON instance for CollectorStatus.
+instance JSON CollectorStatus where
+  showJSON = showJSON . drop 2 . show
+  readJSON = error "JSON read instance not implemented for type 
CollectorStatus"
+
 -- | This is the format of the report produced by each data collector.
 $(buildObject "DCReport" "dcReport"
-  [ simpleField "name"           [t| String |]
-  , simpleField "version"        [t| String |]
-  , simpleField "format_version" [t| Int |]
-  , simpleField "timestamp"      [t| Integer |]
-  , simpleField "data"           [t| JSValue |]
+  [ simpleField "name"          [t| String |]
+  , simpleField "version"       [t| String |]
+  , simpleField "formatVersion" [t| Int |]
+  , simpleField "timestamp"     [t| Integer |]
+  , optionalNullSerField $
+    simpleField "instanceOf"    [t| CollectorClass |]
+  , simpleField "status"        [t| CollectorStatus |]
+  , optionalNullSerField $
+    simpleField "message"       [t| String |]
+  , simpleField "data"          [t| JSValue |]
   ])
 
 -- | 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
 -- a builtin collector.
-buildReport :: String -> Maybe String -> Int -> JSValue -> IO DCReport
-buildReport name version format_version jsonData = do
-  now <- getCurrentTime
-  let timestamp = now * 1000000000 :: Integer
-      ver = fromMaybe C.builtinDataCollectorVersion version
-  return $ DCReport name ver format_version timestamp jsonData
+buildReport :: String -> Maybe String -> Int -> Maybe CollectorClass ->
+  (CollectorStatus, Maybe String, JSValue) -> IO DCReport
+buildReport name version formatVersion instanceOf (status, message,
+  jsonData) = do
+    now <- getCurrentTime
+    let timestamp = now * 1000000000 :: Integer
+        ver = fromMaybe C.builtinDataCollectorVersion version
+    return $ DCReport name ver formatVersion timestamp instanceOf status
+      message jsonData
-- 
1.8.1

-- 
You received this message because you are subscribed to the Google Groups 
"ganeti-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to