packages feed

sensu-run 0.2.0 → 0.3.0

raw patch · 4 files changed

+35/−15 lines, 4 filesdep +unix-compat

Dependencies added: unix-compat

Files

CHANGELOG.md view
@@ -1,5 +1,10 @@ # Revision history for sensu-run +## 0.3.0 -- 2017-07-25++* Add user field to result JSON (#7)+* Handle missing executable properly (#10)+ ## 0.2.0 -- 2017-07-12  * Relax upper version bound for base
README.md view
@@ -48,14 +48,15 @@ {   "name": "check-home-src-size",   "command": "du -s /home/maoe/src",-  "issued": 1496966954,-  "executed": 1496966954,-  "duration": 1.235584,+  "issued": 1500526383,+  "executed": 1500526383,+  "duration": 1.168139,   "status": 0,-  "output": "44567740\t/home/maoe/src\n",+  "output": "55186828\t/home/maoe/src\n",   "handlers": [     "foo"-  ]+  ],+  "user": "maoe" } ``` 
sensu-run.cabal view
@@ -1,5 +1,5 @@ name: sensu-run-version: 0.2.0+version: 0.3.0 synopsis: A tool to send command execution results to Sensu description:   @sensu-run@ is a command line tool to send command execution results to Sensu@@ -17,7 +17,9 @@   CHANGELOG.md   README.md cabal-version: >= 1.10-tested-with: GHC == 8.0.2+tested-with:+  GHC == 8.0.2+  GHC == 8.2.1  executable sensu-run   main-is: sensu-run.hs@@ -35,6 +37,7 @@     , temporary >= 1.1 && < 1.3     , text >= 1.2.2 && < 1.3     , time >= 1.5.0.1 && < 1.9+    , unix-compat < 0.5     , vector >= 0.11 && < 0.13     , wreq >= 0.5.0 && < 0.6   other-modules:
sensu-run.hs view
@@ -32,6 +32,7 @@ import System.FilePath ((</>)) import System.IO.Temp import System.Process+import System.PosixCompat.User (getEffectiveUserName) import qualified Data.ByteString.Lazy as BL import qualified Data.ByteString.Lazy.Char8 as BL8 import qualified Data.Text as T@@ -56,23 +57,28 @@       exitSuccess     RunOptions {..} -> withSystemTempFile "sensu-run.XXX" $ \path hdl -> do       executed <- getCurrentTime-      rawStatus <- bracket+      rawStatus <- try $ bracket         (startProcess cmdspec hdl)         (\ph -> do           terminateProcess ph           killProcessTree ph           waitForProcess ph)         (withTimeout timeout . waitForProcess)+      hClose hdl       exited <- getCurrentTime       rawOutput <- BL.readFile path+      user <- T.pack <$> getEffectiveUserName       let         encoded = encode CheckResult           { command = cmdspec-          , output = TL.decodeUtf8With TE.lenientDecode rawOutput+          , output = case rawStatus of+            Left ioe -> TL.pack $ show (ioe :: IOException)+            Right Nothing -> "timed out"+            Right _ -> TL.decodeUtf8With TE.lenientDecode rawOutput           , status = case rawStatus of-            Nothing -> UNKNOWN-            Just ExitSuccess -> OK-            Just ExitFailure {} -> CRITICAL+            Right (Just ExitSuccess) -> OK+            Right (Just ExitFailure {}) -> CRITICAL+            _ -> UNKNOWN           , duration = diffUTCTime exited executed           , ..           }@@ -82,11 +88,14 @@           ClientSocketInput port -> sendToClientSocketInput port encoded           SensuServer urls -> sendToSensuServer urls encoded       case rawStatus of-        Just ExitSuccess -> exitSuccess-        Nothing -> do+        Left ioe -> do+          hPutStrLn stderr $ show ioe+          exitFailure+        Right (Just ExitSuccess) -> exitSuccess+        Right Nothing -> do           hPutStrLn stderr $ showCmdSpec cmdspec ++ " timed out"           exitFailure-        Just ExitFailure {} -> exitFailure+        Right (Just ExitFailure {}) -> exitFailure  sendToClientSocketInput   :: PortNumber -- ^ Listening port of Sensu client socket@@ -265,6 +274,7 @@   , duration :: NominalDiffTime   , output :: TL.Text   , handlers :: [T.Text]+  , user :: T.Text   }  pattern OK :: ExitCode@@ -294,6 +304,7 @@     , "status" .= statusToInt status     , "output" .= output     , "handlers" .= handlers+    , "user" .= user     ]     where       addOptional key val ps = maybe ps (\val' -> key .= val' : ps) val