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

Factor out function for building report


Instead of building the report as part of the "Main" function, have it
built by its own dedicated function, so that it will be able to export it
directly to the monitoring daemon when needed.

Signed-off-by: default avatarMichele Tartara <mtartara@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent 7660aaf3
No related branches found
No related tags found
No related merge requests found
...@@ -179,15 +179,22 @@ buildStatus domains uptimes inst = do ...@@ -179,15 +179,22 @@ buildStatus domains uptimes inst = do
trail trail
status status
-- | Main function. -- | Build the report of this data collector, containing all the information
main :: Options -> [String] -> IO () -- about the status of the instances.
main opts _ = do buildInstStatusReport :: Maybe String -> Maybe Int -> IO DCReport
curNode <- getHostName buildInstStatusReport srvAddr srvPort = do
let node = fromMaybe curNode $ optNode opts node <- getHostName
answer <- getInstances node (optConfdAddr opts) (optConfdPort opts) answer <- getInstances node srvAddr srvPort
inst <- exitIfBad "Can't get instance info from ConfD" answer inst <- exitIfBad "Can't get instance info from ConfD" answer
domains <- getInferredDomInfo domains <- getInferredDomInfo
uptimes <- getUptimeInfo uptimes <- getUptimeInfo
let primaryInst = fst inst let primaryInst = fst inst
iStatus <- mapM (buildStatus domains uptimes) primaryInst 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
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