From 971af69b7388cf5155bb124246f2a697578cc6e9 Mon Sep 17 00:00:00 2001 From: AJ Christensen Date: Sat, 26 Jul 2008 16:50:48 +1200 Subject: Fixing puppetlast to make it work with 0.24.5 / 0.25. Tidied up some of the code a little --- ext/puppetlast | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) (limited to 'ext') diff --git a/ext/puppetlast b/ext/puppetlast index e8c2ea1a7..c77d1ba73 100755 --- a/ext/puppetlast +++ b/ext/puppetlast @@ -15,26 +15,21 @@ print "puppetlast\n" nodes = {} -yfdir = Puppet.settings.value(:vardir) + "/yaml/facts" - -if yfdir - begin - Dir.chdir(yfdir) do - Dir.glob("*.yaml").each do |yaml| - data = YAML.load_file(yaml) - t = Time.now - age = t - data.version - nodes[data.name] = age.to_i - end - end - - nodes.sort.each do |node,age| - minutes = age / 60 + 0.5 - print minutes.floor.to_s + ' minutes ago: ' + node + "\n" - end - - rescue - print 'error: ' + $! + "\n" - end - +factsdir = Puppet.settings.value(:vardir) + "/yaml/facts" + +begin + Dir.chdir(factsdir) if File.exists?(factsdir) + Dir.glob("*.yaml").each do |yaml| + data = YAML.load_file(yaml) + age = Time.now - data.values[:_timestamp] + nodes[data.name] = age.to_i + end + + nodes.sort.each do |node,age| + minutes = age / 60 + puts minutes.floor.to_s + ' minutes ago: ' + node + end + +rescue + puts 'error: ' + $! end -- cgit From 482489ad21e20ee3275185962f76c6a0c9a88328 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Fri, 1 Aug 2008 06:59:23 +1000 Subject: Revert "Fixing puppetlast to make it work with 0.24.5 / 0.25." This reverts commit 971af69b7388cf5155bb124246f2a697578cc6e9. --- ext/puppetlast | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'ext') diff --git a/ext/puppetlast b/ext/puppetlast index c77d1ba73..e8c2ea1a7 100755 --- a/ext/puppetlast +++ b/ext/puppetlast @@ -15,21 +15,26 @@ print "puppetlast\n" nodes = {} -factsdir = Puppet.settings.value(:vardir) + "/yaml/facts" - -begin - Dir.chdir(factsdir) if File.exists?(factsdir) - Dir.glob("*.yaml").each do |yaml| - data = YAML.load_file(yaml) - age = Time.now - data.values[:_timestamp] - nodes[data.name] = age.to_i - end - - nodes.sort.each do |node,age| - minutes = age / 60 - puts minutes.floor.to_s + ' minutes ago: ' + node - end - -rescue - puts 'error: ' + $! +yfdir = Puppet.settings.value(:vardir) + "/yaml/facts" + +if yfdir + begin + Dir.chdir(yfdir) do + Dir.glob("*.yaml").each do |yaml| + data = YAML.load_file(yaml) + t = Time.now + age = t - data.version + nodes[data.name] = age.to_i + end + end + + nodes.sort.each do |node,age| + minutes = age / 60 + 0.5 + print minutes.floor.to_s + ' minutes ago: ' + node + "\n" + end + + rescue + print 'error: ' + $! + "\n" + end + end -- cgit From c97389d5f6748c05b88f6461b87b4d21a273ab00 Mon Sep 17 00:00:00 2001 From: AJ Christensen Date: Wed, 30 Jul 2008 11:36:43 +1200 Subject: Made puppetlast work on 0.24.5 by using the YAML indirector --- ext/puppetlast | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'ext') diff --git a/ext/puppetlast b/ext/puppetlast index e8c2ea1a7..848fdde6c 100755 --- a/ext/puppetlast +++ b/ext/puppetlast @@ -1,15 +1,14 @@ #!/usr/bin/env ruby +# Puppetlast, a script to output the last check-in time of nodes. Also outputs the cached configuration state, if expired or not. # -# Script to print out when puppet ran successfully last -# AJ Christensen +# AJ "Fujin" Christensen # - require 'puppet' -require 'puppet/defaults' -require 'yaml' Puppet[:config] = "/etc/puppet/puppet.conf" Puppet.parse_config +Puppet[:name] = "puppetmasterd" +Puppet::Node::Facts.terminus_class = :yaml print "puppetlast\n" @@ -37,4 +36,7 @@ if yfdir print 'error: ' + $! + "\n" end +Puppet::Node::Facts.search("*").sort.each do |node| + puts "#{node.name} #{node.expired? ? 'cached expired, ' : ''}checked in #{((Time.now - node.values[:_timestamp]) / 60).floor} minutes ago" end + -- cgit From 2a3d195402900aa31843f7a7ff78026409cf43f5 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Fri, 1 Aug 2008 07:11:21 +1000 Subject: Specs for yaml indirector .search - I'm still learning! Updated, I was calling .base myself instead of the actual string --- ext/puppetlast | 27 --------------------------- 1 file changed, 27 deletions(-) (limited to 'ext') diff --git a/ext/puppetlast b/ext/puppetlast index 848fdde6c..d9b698cfe 100755 --- a/ext/puppetlast +++ b/ext/puppetlast @@ -10,33 +10,6 @@ Puppet.parse_config Puppet[:name] = "puppetmasterd" Puppet::Node::Facts.terminus_class = :yaml -print "puppetlast\n" - -nodes = {} - -yfdir = Puppet.settings.value(:vardir) + "/yaml/facts" - -if yfdir - begin - Dir.chdir(yfdir) do - Dir.glob("*.yaml").each do |yaml| - data = YAML.load_file(yaml) - t = Time.now - age = t - data.version - nodes[data.name] = age.to_i - end - end - - nodes.sort.each do |node,age| - minutes = age / 60 + 0.5 - print minutes.floor.to_s + ' minutes ago: ' + node + "\n" - end - - rescue - print 'error: ' + $! + "\n" - end - Puppet::Node::Facts.search("*").sort.each do |node| puts "#{node.name} #{node.expired? ? 'cached expired, ' : ''}checked in #{((Time.now - node.values[:_timestamp]) / 60).floor} minutes ago" end - -- cgit From d02f95cb608e1ee5d90ac06405e354cbc0000706 Mon Sep 17 00:00:00 2001 From: mh Date: Thu, 3 Jul 2008 12:08:46 +0200 Subject: Fixed #1394 - Added stored configuration clearing script to /ext --- ext/puppetstoredconfigclean.rb | 87 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 ext/puppetstoredconfigclean.rb (limited to 'ext') diff --git a/ext/puppetstoredconfigclean.rb b/ext/puppetstoredconfigclean.rb new file mode 100644 index 000000000..f286df2df --- /dev/null +++ b/ext/puppetstoredconfigclean.rb @@ -0,0 +1,87 @@ +#!/usr/bin/env ruby + +# Script to clean up stored configs for (a) given host(s) +# +# Credits: +# Script was taken from http://reductivelabs.com/trac/puppet/attachment/wiki/UsingStoredConfiguration/kill_node_in_storedconfigs_db.rb +# which haven been initially posted by James Turnbull +# duritong adapted and improved the script a bit. + +require 'getoptlong' +config = '/etc/puppet/puppet.conf' + +def printusage(error_code) + puts "Usage: #{$0} [ list of hostnames as stored in hosts table ]" + puts "\n Options:" + puts "--config " + exit(error_code) +end + +opts = GetoptLong.new( + [ "--config", "-c", GetoptLong::REQUIRED_ARGUMENT ], + [ "--help", "-h", GetoptLong::NO_ARGUMENT ], + [ "--usage", "-u", GetoptLong::NO_ARGUMENT ], + [ "--version", "-v", GetoptLong::NO_ARGUMENT ] +) + +begin + opts.each do |opt, arg| + case opt + when "--config" + config = arg + + when "--help" + printusage(0) + + when "--usage" + printusage(0) + + when "--version" + puts "%s" % Puppet.version + exit + end + end +rescue GetoptLong::InvalidOption => detail + $stderr.puts "Try '#{$0} --help'" + exit(1) +end + +printusage(1) unless ARGV.size > 0 + +require 'puppet/rails' +Puppet[:config] = config +Puppet.parse_config +pm_conf = Puppet.settings.instance_variable_get(:@values)[:puppetmasterd] + +adapter = pm_conf[:dbadapter] +args = {:adapter => adapter, :log_level => pm_conf[:rails_loglevel]} + +case adapter + when "sqlite3": + args[:dbfile] = pm_conf[:dblocation] + when "mysql", "postgresql": + args[:host] = pm_conf[:dbserver] unless pm_conf[:dbserver].to_s.empty? + args[:username] = pm_conf[:dbuser] unless pm_conf[:dbuser].to_s.empty? + args[:password] = pm_conf[:dbpassword] unless pm_conf[:dbpassword].to_s.empty? + args[:database] = pm_conf[:dbname] unless pm_conf[:dbname].to_s.empty? + socket = pm_conf[:dbsocket] + args[:socket] = socket unless socket.to_s.empty? + else + raise ArgumentError, "Invalid db adapter %s" % adapter +end + +args[:database] = "puppet" unless not args[:database].to_s.empty? + +ActiveRecord::Base.establish_connection(args) + +ARGV.each { |hostname| + if @host = Puppet::Rails::Host.find_by_name(hostname.strip) + print "Killing #{hostname}..." + $stdout.flush + @host.destroy + puts "done." + else + puts "Can't find host #{hostname}." + end +} +exit 0 -- cgit