Factor out function for building report
[ganeti-local] / src / Ganeti / DataCollectors / InstStatus.hs
index ec8b3ef..3566c57 100644 (file)
@@ -27,6 +27,11 @@ module Ganeti.DataCollectors.InstStatus
   ( main
   , options
   , arguments
+  , dcName
+  , dcVersion
+  , dcFormatVersion
+  , dcCategory
+  , dcKind
   ) where
 
 
@@ -51,6 +56,27 @@ import Ganeti.Path
 import Ganeti.Types
 import Ganeti.Utils
 
+
+-- | The name of this data collector.
+dcName :: String
+dcName = "inst-status-xen"
+
+-- | The version of this data collector.
+dcVersion :: DCVersion
+dcVersion = DCVerBuiltin
+
+-- | The version number for the data format of this data collector.
+dcFormatVersion :: Int
+dcFormatVersion = 1
+
+-- | The category of this data collector.
+dcCategory :: Maybe DCCategory
+dcCategory = Just DCInstance
+
+-- | The kind of this data collector.
+dcKind :: DCKind
+dcKind = DCKStatus
+
 -- * Command line options
 
 options :: IO [OptType]
@@ -153,15 +179,22 @@ buildStatus domains uptimes inst = do
       trail
       status
 
--- | Main function.
-main :: Options -> [String] -> IO ()
-main opts _ = do
-  curNode <- getHostName
-  let node = fromMaybe curNode $ optNode opts
-  answer <- getInstances node (optConfdAddr opts) (optConfdPort opts)
+-- | Build the report of this data collector, containing all the information
+-- about the status of the instances.
+buildInstStatusReport :: Maybe String -> Maybe Int -> IO DCReport
+buildInstStatusReport srvAddr srvPort = do
+  node <- getHostName
+  answer <- getInstances node srvAddr srvPort
   inst <- exitIfBad "Can't get instance info from ConfD" answer
   domains <- getInferredDomInfo
   uptimes <- getUptimeInfo
   let primaryInst =  fst inst
   iStatus <- mapM (buildStatus domains uptimes) primaryInst
-  putStrLn $ J.encode iStatus
+  let jsonReport = J.showJSON iStatus
+  buildReport dcName dcVersion dcFormatVersion dcCategory dcKind jsonReport
+
+-- | Main function.
+main :: Options -> [String] -> IO ()
+main opts _ = do
+  report <- buildInstStatusReport (optConfdAddr opts) (optConfdPort opts)
+  putStrLn $ J.encode report