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

Add global status field to the instance status collector


The global status is computed from the statuses of the single instances.

The output json format is adapted to include this piece of information, as
prescribed by the design document.

Signed-off-by: default avatarMichele Tartara <mtartara@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent dd69cd3c
No related branches found
No related tags found
No related merge requests found
......@@ -36,6 +36,7 @@ module Ganeti.DataCollectors.InstStatus
import Control.Exception.Base
import Data.List
import Data.Maybe
import qualified Data.Map as Map
import Network.BSD (getHostName)
......@@ -179,6 +180,17 @@ buildStatus domains uptimes inst = do
trail
status
-- | Compute the status code and message, given the current DRBD data
-- The final state will have the code corresponding to the worst code of
-- all the devices, and the error message given from the concatenation of the
-- non-empty error messages.
computeGlobalStatus :: [InstStatus] -> DCStatus
computeGlobalStatus instStatusList =
let dcstatuses = map iStatStatus instStatusList
statuses = map (\s -> (dcStatusCode s, dcStatusMessage s)) dcstatuses
(code, strList) = foldr mergeStatuses (DCSCOk, [""]) statuses
in DCStatus code $ intercalate "\n" strList
-- | Build the report of this data collector, containing all the information
-- about the status of the instances.
buildInstStatusReport :: Maybe String -> Maybe Int -> IO DCReport
......@@ -190,7 +202,8 @@ buildInstStatusReport srvAddr srvPort = do
uptimes <- getUptimeInfo
let primaryInst = fst inst
iStatus <- mapM (buildStatus domains uptimes) primaryInst
let jsonReport = J.showJSON iStatus
let globalStatus = computeGlobalStatus iStatus
jsonReport = J.showJSON $ ReportData iStatus globalStatus
buildReport dcName dcVersion dcFormatVersion dcCategory dcKind jsonReport
-- | Main function.
......
......@@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
module Ganeti.DataCollectors.InstStatusTypes
( InstStatus(..)
, ReportData(..)
) where
......@@ -47,3 +48,8 @@ $(buildObject "InstStatus" "iStat"
, simpleField "state_reason" [t| ReasonTrail |]
, simpleField "status" [t| DCStatus |]
])
$(buildObject "ReportData" "rData"
[ simpleField "instances" [t| [InstStatus] |]
, simpleField "status" [t| DCStatus |]
])
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