Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checking for errors in last_run_report #43

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md)

## [Unreleased]
- `check-puppet-errors.rb` will now also check for errors in the `last_run_report.yaml` (@elfranne)

## [3.0.0] - 2020-03-24
### Breaking Change
Expand Down
24 changes: 23 additions & 1 deletion bin/check-puppet-errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,20 @@ class PuppetErrors < Sensu::Plugin::Check::CLI
long: '--agent-disabled-file PATH',
default: SensuPluginsPuppet::AGENT_DISABLED_FILE,
description: 'Path to agent disabled lock file'


option :report_file,
short: '-r PATH',
long: '--report-file PATH',
default: SensuPluginsPuppet::REPORT_FILE,
description: 'Location of last_run_report.yaml file'

def run
unless File.exist?(config[:summary_file])
unknown "File #{config[:summary_file]} not found"
end
unless File.exist?(config[:report_file])
unknown "File #{config[:report_file]} not found"
end

begin
summary = YAML.load_file(config[:summary_file])
Expand All @@ -64,6 +73,19 @@ def run
unknown "Could not process #{config[:summary_file]}"
end

begin
%["sudo /usr/bin/head -n 13 #{config[:report_file]}"].split('\n').each { |line|
if line.eql? 'status: failed'
critical 'Last Puppet run reports status: failed'
end
if line.eql? 'transaction_completed: false'
critical 'Last Puppet run reports transaction_completed: false'
end
}
rescue StandardError
unknown "Could not process #{config[:report_file]}"
end

@message = 'Puppet run'

if File.exist?(config[:agent_disabled_file])
Expand Down
1 change: 1 addition & 0 deletions lib/sensu-plugins-puppet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@

module SensuPluginsPuppet
SUMMARY_FILE = "#{Gem.win_platform? ? 'C:/ProgramData/PuppetLabs' : '/opt/puppetlabs'}/puppet/cache/state/last_run_summary.yaml".freeze
REPORT_FILE = "#{Gem.win_platform? ? 'C:/ProgramData/PuppetLabs' : '/opt/puppetlabs'}/puppet/cache/state/last_run_report.yaml".freeze
AGENT_DISABLED_FILE = "#{Gem.win_platform? ? 'C:/ProgramData/PuppetLabs' : '/opt/puppetlabs'}/puppet/cache/state/agent_disabled.lock".freeze
end