From e3db4501f6436a822a1c32d71b8f4df62320b89e Mon Sep 17 00:00:00 2001 From: Kindred Date: Wed, 22 Jun 2016 07:13:21 +1000 Subject: [PATCH] Added a check for errors in the puppet run. (#8) --- CHANGELOG.md | 1 + bin/check-puppet-last-run.rb | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a20b51..d0b9a11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang - check-puppet-last-run.rb: if the agent is disabled via lock file, display reason (if available) - Loosened dependency on sensu-plugin from `= 1.2.0` to `~> 1.2.0` - Updated Rubocop to 0.40, applied auto-correct +- Added a check for errors in the puppet run ### Removed - Remove Ruby 1.9.3 support; add Ruby 2.2.0 and 2.3.0 support to test matrix. diff --git a/bin/check-puppet-last-run.rb b/bin/check-puppet-last-run.rb index 1bfea5d..26c4092 100755 --- a/bin/check-puppet-last-run.rb +++ b/bin/check-puppet-last-run.rb @@ -69,6 +69,7 @@ def run begin summary = YAML.load_file(config[:summary_file]) @last_run = summary['time']['last_run'].to_i + @failures = summary['events']['failures'].to_i rescue unknown "Could not process #{config[:summary_file]}" end @@ -82,7 +83,11 @@ def run # fail silently end - if @now - @last_run > config[:crit_age] + if @failures > 0 + @message += " with #{@failures} failures" + end + + if @now - @last_run > config[:crit_age] || @failures > 0 critical @message elsif @now - @last_run > config[:warn_age] warning @message