Revision 79731e21

b/src/Ganeti/DataCollectors/InstStatus.hs
36 36

  
37 37

  
38 38
import Control.Exception.Base
39
import Data.List
39 40
import Data.Maybe
40 41
import qualified Data.Map as Map
41 42
import Network.BSD (getHostName)
......
179 180
      trail
180 181
      status
181 182

  
183
-- | Compute the status code and message, given the current DRBD data
184
-- The final state will have the code corresponding to the worst code of
185
-- all the devices, and the error message given from the concatenation of the
186
-- non-empty error messages.
187
computeGlobalStatus :: [InstStatus] -> DCStatus
188
computeGlobalStatus instStatusList =
189
  let dcstatuses = map iStatStatus instStatusList
190
      statuses = map (\s -> (dcStatusCode s, dcStatusMessage s)) dcstatuses
191
      (code, strList) = foldr mergeStatuses (DCSCOk, [""]) statuses
192
  in DCStatus code $ intercalate "\n" strList
193

  
182 194
-- | Build the report of this data collector, containing all the information
183 195
-- about the status of the instances.
184 196
buildInstStatusReport :: Maybe String -> Maybe Int -> IO DCReport
......
190 202
  uptimes <- getUptimeInfo
191 203
  let primaryInst =  fst inst
192 204
  iStatus <- mapM (buildStatus domains uptimes) primaryInst
193
  let jsonReport = J.showJSON iStatus
205
  let globalStatus = computeGlobalStatus iStatus
206
      jsonReport = J.showJSON $ ReportData iStatus globalStatus
194 207
  buildReport dcName dcVersion dcFormatVersion dcCategory dcKind jsonReport
195 208

  
196 209
-- | Main function.
b/src/Ganeti/DataCollectors/InstStatusTypes.hs
26 26

  
27 27
module Ganeti.DataCollectors.InstStatusTypes
28 28
  ( InstStatus(..)
29
  , ReportData(..)
29 30
  ) where
30 31

  
31 32

  
......
47 48
  , simpleField "state_reason" [t| ReasonTrail |]
48 49
  , simpleField "status"       [t| DCStatus |]
49 50
  ])
51

  
52
$(buildObject "ReportData" "rData"
53
  [ simpleField "instances" [t| [InstStatus] |]
54
  , simpleField "status"    [t| DCStatus |]
55
  ])

Also available in: Unified diff