From 4218ab4b76e81227364ed008d8d55a8c5f3ed1a0 Mon Sep 17 00:00:00 2001
From: Tomas Janousek <tomi@nomi.cz>
Date: Sat, 3 May 2014 13:30:37 +0200
Subject: CoreCommon: Try several paths in checkedDataRetrieval

---
 src/Plugins/Monitors/CoreCommon.hs | 7 ++++---
 src/Plugins/Monitors/CoreTemp.hs   | 2 +-
 src/Plugins/Monitors/CpuFreq.hs    | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)

(limited to 'src/Plugins/Monitors')

diff --git a/src/Plugins/Monitors/CoreCommon.hs b/src/Plugins/Monitors/CoreCommon.hs
index 5d6efd4..943f491 100644
--- a/src/Plugins/Monitors/CoreCommon.hs
+++ b/src/Plugins/Monitors/CoreCommon.hs
@@ -26,10 +26,11 @@ 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)
diff --git a/src/Plugins/Monitors/CoreTemp.hs b/src/Plugins/Monitors/CoreTemp.hs
index 5109070..eebdc95 100644
--- a/src/Plugins/Monitors/CoreTemp.hs
+++ b/src/Plugins/Monitors/CoreTemp.hs
@@ -41,4 +41,4 @@ runCoreTemp _ = do
        lbl  = Just ("_label", read . (dropWhile (not . isDigit)))
        divisor = 1e3 :: Double
        show' = showDigits (max 0 dn)
-   checkedDataRetrieval failureMessage path lbl (/divisor) show'
+   checkedDataRetrieval failureMessage [path] lbl (/divisor) show'
diff --git a/src/Plugins/Monitors/CpuFreq.hs b/src/Plugins/Monitors/CpuFreq.hs
index 8334d1a..3fe2577 100644
--- a/src/Plugins/Monitors/CpuFreq.hs
+++ b/src/Plugins/Monitors/CpuFreq.hs
@@ -36,4 +36,4 @@ runCpuFreq _ = do
       fmt x | x < 1 = (show (round (x * 1000) :: Integer)) ++ "MHz"
             | otherwise = (show x) ++ "GHz"
   failureMessage <- getConfigValue naString
-  checkedDataRetrieval failureMessage path Nothing (/divisor) fmt
+  checkedDataRetrieval failureMessage [path] Nothing (/divisor) fmt
-- 
cgit v1.2.3