summaryrefslogtreecommitdiffhomepage
path: root/src/Plugins/Monitors/CoreCommon.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Plugins/Monitors/CoreCommon.hs')
-rw-r--r--src/Plugins/Monitors/CoreCommon.hs14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/Plugins/Monitors/CoreCommon.hs b/src/Plugins/Monitors/CoreCommon.hs
index c7fb7d5..943f491 100644
--- a/src/Plugins/Monitors/CoreCommon.hs
+++ b/src/Plugins/Monitors/CoreCommon.hs
@@ -26,16 +26,18 @@ import Plugins.Monitors.Common
import System.Directory
checkedDataRetrieval :: (Ord a, Num a)
- => String -> [String] -> Maybe (String, String -> Int)
+ => String -> [[String]] -> Maybe (String, String -> Int)
-> (Double -> a) -> (a -> String) -> Monitor String
-checkedDataRetrieval msg path lbl trans fmt = liftM (fromMaybe msg) $
- retrieveData path lbl trans fmt
+checkedDataRetrieval msg paths lbl trans fmt =
+ liftM (fromMaybe msg . listToMaybe . catMaybes) $
+ mapM (\p -> retrieveData p lbl trans fmt) paths
retrieveData :: (Ord a, Num a)
=> [String] -> Maybe (String, String -> Int)
-> (Double -> a) -> (a -> String) -> Monitor (Maybe String)
retrieveData path lbl trans fmt = do
- pairs <- map snd . sortBy (compare `on` fst) <$> (mapM readFiles =<< findFiles path lbl)
+ pairs <- map snd . sortBy (compare `on` fst) <$>
+ (mapM readFiles =<< findFilesAndLabel path lbl)
if null pairs
then return Nothing
else Just <$> ( parseTemplate
@@ -84,9 +86,9 @@ pathComponents = joinComps . drop 2 . intercalate [Space] . map splitParts
-- | Function to find all files matching the given path and possible label file.
-- The path must be absolute (start with a leading slash).
-findFiles :: [String] -> Maybe (String, String -> Int)
+findFilesAndLabel :: [String] -> Maybe (String, String -> Int)
-> Monitor [(String, Either Int (String, String -> Int))]
-findFiles path lbl = catMaybes
+findFilesAndLabel path lbl = catMaybes
<$> ( mapM addLabel . zip [0..] . sort
=<< recFindFiles (pathComponents path) "/"
)