-
-
Save craig-m-unsw/50f937ea8dd76c0bb2b347b235dccfad to your computer and use it in GitHub Desktop.
Nagios/Icinga Puppet run check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/opt/puppetlabs/puppet/bin/ruby | |
| require 'yaml' | |
| require 'puppet' | |
| require 'optparse' | |
| options = { | |
| :lastrun_warn => 3600, | |
| :lastrun_crit => 36000, | |
| :runtime_warn => 25, | |
| :runtime_crit => 60, | |
| } | |
| OptionParser.new do |opt| | |
| opt.banner = "Usage: #{$0} [options]" | |
| opt.on('-l', '--lastrun w,c', Array, 'Time since last Puppet run') { |w| options[:lastrun_warn] = w[0].to_i; options[:lastrun_crit] = w[1].to_i } | |
| opt.on('-r', '--runtime w,c', Array, 'Total Puppet run time') { |w| options[:runtime_warn] = w[0].to_i; options[:runtime_crit] = w[1].to_i } | |
| end.parse! | |
| report = YAML.load_file('/opt/puppetlabs/puppet/cache/state/last_run_report.yaml') | |
| overall = 3; | |
| if (report.status == 'unchanged') | |
| overall = 0 | |
| message = 'No changes' | |
| elsif (report.status == 'failed') | |
| overall = 2 | |
| message = 'Failed resources' | |
| else | |
| overall = 1 | |
| message = 'Changed resources' | |
| end | |
| lastrun = Time.now.to_i - Time.at(report.time).to_i | |
| if (overall < 2) | |
| if (lastrun > options[:lastrun_crit]) | |
| overall = 2 | |
| message << ", Last run: #{lastrun}" | |
| end | |
| if (report.metrics['time']['total'] > options[:runtime_crit]) | |
| overall = 2 | |
| message << ", Total run time: #{report.metrics['time']['total']}" | |
| end | |
| end | |
| if (overall < 1) | |
| if (lastrun > options[:lastrun_warn]) | |
| overall = 1 | |
| message << ", Last run: #{lastrun}" | |
| end | |
| if (report.metrics['time']['total'] > options[:runtime_warn]) | |
| overall = 1 | |
| message << ", Total run time: #{report.metrics['time']['total']}" | |
| end | |
| end | |
| case overall | |
| when 2 | |
| print 'CRITICAL' | |
| when 1 | |
| print 'WARNING' | |
| when 0 | |
| print 'OK' | |
| else | |
| print 'UNKNOWN' | |
| end | |
| print ', %s|lastrun=%i;%i;%i;0; ' % [ message, lastrun, options[:lastrun_warn], options[:lastrun_crit] ] | |
| if !report.metrics.empty? | |
| for met in [ 'total', 'skipped', 'failed', 'failed_to_restart', 'restarted', 'changed', 'out_of_sync', 'scheduled' ] | |
| print "res_#{met}=#{report.metrics['resources'][met]};;;0; " | |
| end | |
| puts "runtime=#{report.metrics['time']['total']}s;#{options[:runtime_warn]};#{options[:runtime_crit]};0; " | |
| end | |
| exit overall |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment