Skip to content
Snippets Groups Projects
Commit 8c5419ee authored by Michele Tartara's avatar Michele Tartara
Browse files

Export the data collected by DRBD in JSON format


Write an intermediate function computing the JSON data before adding them
to the DCReport.

Directly export the data computed by that function (with default parameters)
allowing them to be used (in the future) by the monitoring agent.

Signed-off-by: default avatarMichele Tartara <mtartara@google.com>
Reviewed-by: default avatarBernardo Dal Seno <bdalseno@google.com>
parent 82437b28
No related branches found
No related tags found
No related merge requests found
...@@ -32,6 +32,7 @@ module Ganeti.DataCollectors.Drbd ...@@ -32,6 +32,7 @@ module Ganeti.DataCollectors.Drbd
, dcFormatVersion , dcFormatVersion
, dcCategory , dcCategory
, dcKind , dcKind
, dcData
) where ) where
...@@ -87,6 +88,10 @@ dcCategory = Just DCStorage ...@@ -87,6 +88,10 @@ dcCategory = Just DCStorage
dcKind :: DCKind dcKind :: DCKind
dcKind = DCKStatus dcKind = DCKStatus
-- | The data exported by the data collector, taken from the default location.
dcData :: IO J.JSValue
dcData = buildJsonReport defaultFile Nothing
-- * Command line options -- * Command line options
options :: IO [OptType] options :: IO [OptType]
...@@ -121,21 +126,19 @@ getPairingInfo (Just filename) = do ...@@ -121,21 +126,19 @@ getPairingInfo (Just filename) = do
J.Ok instMinor -> BT.Ok instMinor J.Ok instMinor -> BT.Ok instMinor
J.Error msg -> BT.Bad msg J.Error msg -> BT.Bad msg
-- | This function builds a report with the DRBD status. -- | This function computes the JSON representation of the DRBD status.
buildDRBDReport :: FilePath -> Maybe FilePath -> IO DCReport buildJsonReport :: FilePath -> Maybe FilePath -> IO J.JSValue
buildDRBDReport statusFile pairingFile = do buildJsonReport statusFile pairingFile = do
contents <- contents <-
((E.try $ readFile statusFile) :: IO (Either IOError String)) >>= ((E.try $ readFile statusFile) :: IO (Either IOError String)) >>=
exitIfBad "reading from file" . either (BT.Bad . show) BT.Ok exitIfBad "reading from file" . either (BT.Bad . show) BT.Ok
pairingResult <- getPairingInfo pairingFile pairingResult <- getPairingInfo pairingFile
pairing <- exitIfBad "Can't get pairing info" pairingResult pairing <- exitIfBad "Can't get pairing info" pairingResult
jsonData <- case A.parse (drbdStatusParser pairing) $ pack contents of
case A.parse (drbdStatusParser pairing) $ pack contents of A.Fail unparsedText contexts errorMessage -> exitErr $
A.Fail unparsedText contexts errorMessage -> exitErr $ show (Prelude.take defaultCharNum $ unpack unparsedText) ++ "\n"
show (Prelude.take defaultCharNum $ unpack unparsedText) ++ "\n" ++ show contexts ++ "\n" ++ errorMessage
++ show contexts ++ "\n" ++ errorMessage A.Done _ drbdStatus -> return $ J.showJSON drbdStatus
A.Done _ drbdStatus -> return $ J.showJSON drbdStatus
buildReport dcName dcVersion dcFormatVersion dcCategory dcKind jsonData
-- | Main function. -- | Main function.
main :: Options -> [String] -> IO () main :: Options -> [String] -> IO ()
...@@ -144,5 +147,6 @@ main opts args = do ...@@ -144,5 +147,6 @@ main opts args = do
pairingFile = optDrbdPairing opts pairingFile = optDrbdPairing opts
unless (null args) . exitErr $ "This program takes exactly zero" ++ unless (null args) . exitErr $ "This program takes exactly zero" ++
" arguments, got '" ++ unwords args ++ "'" " arguments, got '" ++ unwords args ++ "'"
report <- buildDRBDReport statusFile pairingFile report <- buildJsonReport statusFile pairingFile >>=
buildReport dcName dcVersion dcFormatVersion dcCategory dcKind
putStrLn $ J.encode report putStrLn $ J.encode report
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment