Revision 17ae9cdb src/Ganeti/DataCollectors/InstStatus.hs
b/src/Ganeti/DataCollectors/InstStatus.hs | ||
---|---|---|
30 | 30 |
) where |
31 | 31 |
|
32 | 32 |
|
33 |
import Control.Exception.Base |
|
33 | 34 |
import Data.Maybe |
34 | 35 |
import qualified Data.Map as Map |
35 | 36 |
import Network.BSD (getHostName) |
... | ... | |
44 | 45 |
import Ganeti.DataCollectors.Types |
45 | 46 |
import Ganeti.Hypervisor.Xen |
46 | 47 |
import Ganeti.Hypervisor.Xen.Types |
48 |
import Ganeti.Logging |
|
47 | 49 |
import Ganeti.Objects |
50 |
import Ganeti.Path |
|
51 |
import Ganeti.Types |
|
48 | 52 |
import Ganeti.Utils |
49 | 53 |
|
50 | 54 |
-- * Command line options |
... | ... | |
79 | 83 |
Just (J.Error msg) -> BT.Bad msg |
80 | 84 |
Nothing -> BT.Bad "No answer from the Confd server" |
81 | 85 |
|
86 |
-- | Try to get the reason trail for an instance. In case it is not possible, |
|
87 |
-- log the failure and return an empty list instead. |
|
88 |
getReasonTrail :: String -> IO ReasonTrail |
|
89 |
getReasonTrail instanceName = do |
|
90 |
fileName <- getInstReasonFilename instanceName |
|
91 |
content <- try $ readFile fileName |
|
92 |
case content of |
|
93 |
Left e -> do |
|
94 |
logWarning $ |
|
95 |
"Unable to open the reason trail for instance " ++ instanceName ++ |
|
96 |
" expected at " ++ fileName ++ ": " ++ show (e :: IOException) |
|
97 |
return [] |
|
98 |
Right trailString -> |
|
99 |
case J.decode trailString of |
|
100 |
J.Ok t -> return t |
|
101 |
J.Error msg -> do |
|
102 |
logWarning $ "Unable to parse the reason trail: " ++ msg |
|
103 |
return [] |
|
104 |
|
|
82 | 105 |
-- | Determine the value of the status field for the report of one instance |
83 | 106 |
computeStatusField :: AdminState -> ActualState -> DCStatus |
84 | 107 |
computeStatusField AdminDown actualState = |
... | ... | |
118 | 141 |
else domState dom |
119 | 142 |
_ -> ActualUnknown |
120 | 143 |
status = computeStatusField adminState actualState |
144 |
trail <- getReasonTrail name |
|
121 | 145 |
return $ |
122 | 146 |
InstStatus |
123 | 147 |
name |
... | ... | |
126 | 150 |
actualState |
127 | 151 |
uptime |
128 | 152 |
(instMtime inst) |
153 |
trail |
|
129 | 154 |
status |
130 | 155 |
|
131 | 156 |
-- | Main function. |
Also available in: Unified diff