Skip to content

Instantly share code, notes, and snippets.

@amosshapira
Last active December 20, 2015 07:58
Show Gist options
  • Save amosshapira/6096804 to your computer and use it in GitHub Desktop.
Save amosshapira/6096804 to your computer and use it in GitHub Desktop.
This script takes a list of names of Puppet report files and extract the names and time stamps of failed resources.
#!/usr/bin/env ruby
require 'yaml'
ARGV.each do |filename|
yaml = YAML.load_file(filename)
hash = yaml.ivars["resource_statuses"]
# The following line will just print the resource reference
# puts hash.keys.sort.select{|resource| hash[resource].ivars["failed"]}
# The following line will also print the resource time stamp, it demonstrates access
# to other fields about the resource in the report.
hash.keys.sort.select{|resource| hash[resource].ivars["failed"]}.each do |resource|
puts "#{hash[resource].ivars["time"]} #{resource}"
end
end
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment