Created
December 16, 2016 12:53
-
-
Save seidler2547/5ef72e380ccfacde9668d17fec5f201c to your computer and use it in GitHub Desktop.
Munin plugin to monitor/alert about the last Puppet run
This file contains 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
#!/usr/bin/env ruby | |
require 'yaml' | |
require 'puppet' | |
if ARGV[0] == 'config' | |
puts <<END | |
graph_args --base 1000 -l 0 -M | |
graph_vlabel value | |
graph_title Puppet stats | |
graph_category system | |
graph_info This graph shows Puppet statistics | |
graph_order status lastrun runtime res_total res_skipped res_failed res_failed_to_restart res_restarted res_changed res_out_of_sync res_scheduled | |
status.label Status | |
lastrun.label Last Run | |
runtime.label Run Time | |
res_total.label Resources | |
res_skipped.label Skipped | |
res_failed.label Failed | |
res_failed_to_restart.label Failed to Restart | |
res_restarted.label Restarted | |
res_changed.label Changed | |
res_out_of_sync.label Out of Sync | |
res_scheduled.label Scheduled | |
status.warning 1 | |
status.critical 2 | |
lastrun.warning 3600 | |
lastrun.critical 36000 | |
runtime.warning 20 | |
runtime.critical 60 | |
END | |
for i in ['status', 'lastrun', 'runtime', 'res_total'] | |
puts "#{i}.min 0" | |
puts "#{i}.draw LINE2" | |
end | |
for i in ['res_skipped', 'res_restarted', 'res_changed', 'res_out_of_sync'] | |
puts "#{i}.min 0" | |
puts "#{i}.draw AREASTACK" | |
puts "#{i}.warning 1" | |
puts "#{i}.critical 10" | |
end | |
for i in ['res_scheduled'] | |
puts "#{i}.min 0" | |
puts "#{i}.draw AREASTACK" | |
end | |
for i in ['res_failed', 'res_failed_to_restart'] | |
puts "#{i}.min 0" | |
puts "#{i}.draw AREASTACK" | |
puts "#{i}.critical 1" | |
end | |
exit | |
end | |
report = YAML.load_file('/var/lib/puppet/state/last_run_report.yaml') | |
if (report.status == 'unchanged') | |
puts 'status.value 0' | |
elsif (report.status == 'failed') | |
puts 'status.value 2' | |
else | |
puts 'status.value 1' | |
end | |
puts 'lastrun.value %i' % (Time.now.to_i - Time.at(report.time).to_i) | |
if !report.metrics.empty? | |
for met in [ 'total', 'skipped', 'failed', 'failed_to_restart', 'restarted', 'changed', 'out_of_sync', 'scheduled' ] | |
puts "res_#{met}.value #{report.metrics['resources'][met]}" | |
end | |
puts "runtime.value #{report.metrics['time']['total']}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment