knife-lastrun 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # knife-lastlog
2
+
3
+ A plugin for Chef::Knife which displays node metadata about the last chef run.
4
+
5
+ ## Usage
6
+
7
+ Supply a role name to get a dump of its hierarchy, pass -i for the roles that also include it
8
+
9
+ ```
10
+ % knife node lastrun jgoulah.vm.mydomain.com
11
+ Status success
12
+ Elapsed Time 74.198614
13
+ Start Time 2012-02-22 00:39:04 +0000
14
+ End Time 2012-02-22 00:40:18 +0000
15
+
16
+ Recipe Action Resource Type Resource
17
+ bigdata::default run bash check for bashrc
18
+
19
+ Backtrace none
20
+ Exception none
21
+ Formatted Exception none
22
+ ```
23
+
24
+ ## Installation
25
+
26
+ #### Gem install
27
+
28
+ knife-lastrun is available on rubygems.org - if you have that source in your gemrc, you can simply use:
29
+
30
+ gem install knife-lastrun
31
+
32
+ #### Configure the Handler
33
+
34
+ in /etc/chef/client.rb
35
+
36
+ ```
37
+ require "/var/chef/handlers/lastrun_update.rb"
38
+ report_handlers << LastRunUpdateHandler.new
39
+ ```
40
+
41
+
42
+
43
+ #### Script install
44
+
45
+ Copy the knife-lastrun script from lib/chef/knife/lastrun.rb to your ~/.chef/plugins/knife directory.
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "knife-lastrun/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'knife-lastrun'
7
+ s.version = Knife::NodeLastrun::VERSION
8
+ s.date = '2012-02-21'
9
+ s.summary = "A plugin for Chef::Knife which displays node metadata about the last chef run."
10
+ s.description = s.summary
11
+ s.authors = ["John Goulah"]
12
+ s.email = ["jgoulah@gmail.com"]
13
+ s.homepage = "https://github.com/jgoulah/knife-lastrun"
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+ end
@@ -0,0 +1,71 @@
1
+ require 'chef/knife'
2
+ require 'highline'
3
+
4
+ module GoulahPlugins
5
+ class NodeLastrun < Chef::Knife
6
+
7
+ banner "knife node lastrun NODE"
8
+
9
+ def h
10
+ @highline ||= HighLine.new
11
+ end
12
+
13
+ def run
14
+ unless @node_name = name_args[0]
15
+ ui.error "You need to specify a node"
16
+ exit 1
17
+ end
18
+
19
+ node = Chef::Node.load(@node_name)
20
+ if node.nil?
21
+ ui.msg "Could not find a node named #{@node_name}"
22
+ exit 1
23
+ end
24
+
25
+ unless node[:lastrun]
26
+ ui.msg "no information found for last run on #{@node_name}"
27
+ exit
28
+ end
29
+
30
+ # time
31
+ time_entries = [ h.color('Status', :bold),
32
+ h.color('Elapsed Time', :bold),
33
+ h.color('Start Time', :bold),
34
+ h.color('End Time', :bold) ]
35
+
36
+ time_entries << node[:lastrun][:status]
37
+ [:elapsed, :start, :end].each do |time|
38
+ time_entries << node[:lastrun][:runtimes][time].to_s
39
+ end
40
+ ui.msg h.list(time_entries, :columns_down, 2)
41
+ ui.msg "\n"
42
+
43
+ # updated resources
44
+ log_entries = [ h.color('Recipe', :bold),
45
+ h.color('Action', :bold),
46
+ h.color('Resource Type', :bold),
47
+ h.color('Resource', :bold) ]
48
+
49
+ node[:lastrun][:updated_resources].each do |log_entry|
50
+ log_entries << "#{log_entry[:cookbook_name]}::#{log_entry[:recipe_name]}"
51
+ [:action, :resource_type, :resource].each do |entry|
52
+ log_entries << log_entry[entry].to_s
53
+ end
54
+ end
55
+
56
+ ui.msg h.list(log_entries, :columns_across, 4)
57
+ ui.msg "\n"
58
+
59
+ # debug stuff
60
+ debug_entries = [ h.color('Backtrace', :bold),
61
+ h.color('Exception', :bold),
62
+ h.color('Formatted Exception', :bold) ]
63
+ [:backtrace, :exception, :formatted_exception].each do |msg|
64
+ debug_entries << (node[:lastrun][:debug][msg] ? node[:lastrun][:debug][msg].to_s : "none")
65
+ end
66
+ ui.msg h.list(debug_entries, :columns_down, 2)
67
+ ui.msg "\n"
68
+
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,5 @@
1
+ module Knife
2
+ module NodeLastrun
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,38 @@
1
+ require 'chef/log'
2
+
3
+ class LastRunUpdateHandler < Chef::Handler
4
+
5
+ def report
6
+ node[:lastrun] = {}
7
+
8
+ node[:lastrun][:status] = run_status.success? ? "success" : "failed"
9
+
10
+ node[:lastrun][:runtimes] = {}
11
+ node[:lastrun][:runtimes][:elapsed] = run_status.elapsed_time
12
+ node[:lastrun][:runtimes][:start] = run_status.start_time
13
+ node[:lastrun][:runtimes][:end] = run_status.end_time
14
+
15
+ node[:lastrun][:debug] = {}
16
+ node[:lastrun][:debug][:backtrace] = run_status.backtrace
17
+ node[:lastrun][:debug][:exception] = run_status.exception
18
+ node[:lastrun][:debug][:formatted_exception] = run_status.formatted_exception
19
+
20
+ node[:lastrun][:updated_resources] = []
21
+ run_status.updated_resources.each do |resource|
22
+ m = "recipe[#{resource.cookbook_name}::#{resource.recipe_name}] ran '#{resource.action}' on #{resource.resource_name} '#{resource.name}'"
23
+ Chef::Log.debug(m)
24
+
25
+ node[:lastrun][:updated_resources].insert(0, {
26
+ :cookbook_name => resource.cookbook_name,
27
+ :recipe_name => resource.recipe_name,
28
+ :action => resource.action,
29
+ :resource => resource.name,
30
+ :resource_type => resource.resource_name
31
+ })
32
+
33
+ end
34
+
35
+ # Save entries to node
36
+ node.save
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knife-lastrun
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - John Goulah
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-02-21 00:00:00 +00:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: A plugin for Chef::Knife which displays node metadata about the last chef run.
22
+ email:
23
+ - jgoulah@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - README.md
32
+ - knife-lastrun.gemspec
33
+ - lib/chef/knife/lastrun.rb
34
+ - lib/knife-lastrun/version.rb
35
+ - lib/lastrun_update.rb
36
+ has_rdoc: true
37
+ homepage: https://github.com/jgoulah/knife-lastrun
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options: []
42
+
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ requirements: []
62
+
63
+ rubyforge_project:
64
+ rubygems_version: 1.3.7
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: A plugin for Chef::Knife which displays node metadata about the last chef run.
68
+ test_files: []
69
+