Class: Monitor::Item
- Inherits:
-
Object
- Object
- Monitor::Item
- Defined in:
- lib/chef_monitor/item.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#organization ⇒ Object
readonly
Returns the value of attribute organization.
-
#path ⇒ Object
Returns the value of attribute path.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #commit(path) ⇒ Object
- #commit_nohook(path) ⇒ Object
- #delete(path) ⇒ Object
- #delete_file(file) ⇒ Object
- #download(path) ⇒ Object
- #get_item_json(object) ⇒ Object
-
#initialize(data) ⇒ Item
constructor
A new instance of Item.
- #view_node_data(node) ⇒ Object
Constructor Details
#initialize(data) ⇒ Item
Returns a new instance of Item.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/chef_monitor/item.rb', line 24 def initialize(data) @path = nil @name = data['name'] @time = data['time'].freeze @user = data['user'].freeze @object = data['object'].freeze @server = data['server'].freeze @action = data['action'].freeze @version = data['version'] unless data['version'].nil? @organization = data['org'].freeze end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
41 42 43 |
# File 'lib/chef_monitor/item.rb', line 41 def action @action end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
37 38 39 |
# File 'lib/chef_monitor/item.rb', line 37 def name @name end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
40 41 42 |
# File 'lib/chef_monitor/item.rb', line 40 def object @object end |
#organization ⇒ Object (readonly)
Returns the value of attribute organization.
43 44 45 |
# File 'lib/chef_monitor/item.rb', line 43 def organization @organization end |
#path ⇒ Object
Returns the value of attribute path.
36 37 38 |
# File 'lib/chef_monitor/item.rb', line 36 def path @path end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
38 39 40 |
# File 'lib/chef_monitor/item.rb', line 38 def time @time end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
39 40 41 |
# File 'lib/chef_monitor/item.rb', line 39 def user @user end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
42 43 44 |
# File 'lib/chef_monitor/item.rb', line 42 def version @version end |
Instance Method Details
#commit(path) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/chef_monitor/item.rb', line 121 def commit(path) current_dir = Dir.pwd commit_dir = File.join(path, @organization) Dir.chdir(commit_dir) @version ? object = [@organization, @object, @name, @version].join('/') : object = [@organization, @object, @name].join('/') text = "User : " + @user + "\nObject : " + object + "\nAction : " + @action + "\nLog Time : " + @time domain = %x(git config hooks.emaildomain) || "acme.com" domain = "@" + domain unless domain[0,1] == "@" username = @user useremail = @user + domain %x(git config hooks.username #{username} ) %x(git config hooks.useremail #{useremail} ) %x(git add .) %x(git commit -am \"#{text}\") Dir.chdir(current_dir) end |
#commit_nohook(path) ⇒ Object
138 139 140 141 142 143 144 145 146 |
# File 'lib/chef_monitor/item.rb', line 138 def commit_nohook(path) current_dir = Dir.pwd commit_dir = File.join(path, @organization) Dir.chdir(commit_dir) %x(git config hooks.exclude true) %x(git add .) %x(git commit -am \"no hook executed on this commit\") Dir.chdir(current_dir) end |
#delete(path) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/chef_monitor/item.rb', line 67 def delete(path) file = nil items = [ path ] items << @organization items << @object if @name filename=@name + ".json" if @object == "cookbooks" (@version.nil? || @version.empty?) ? filename=@name : filename=@name + "-" + @version end if @object == "data" (@version.nil? || @version.empty?) ? filename=@name : filename=@name + "/" + @version + ".json" end items << filename end file = items.join("/") delete_file(file) end |
#delete_file(file) ⇒ Object
89 90 91 92 93 |
# File 'lib/chef_monitor/item.rb', line 89 def delete_file(file) FileUtils.rm_rf(file) Monitor::Log.new("Deleted : " + file, 'INFO') true end |
#download(path) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/chef_monitor/item.rb', line 45 def download(path) if @object == "cookbooks" r = download_cookbook(path) else r = download_object(path) end (@version.nil? || @version.empty?) ? object = [@organization, @object, @name].join('/') : object = [@organization, @object, @name, @version].join('/') if r == true Monitor::Log.new("Downloaded: " + object, 'INFO') return true end if r.respond_to?("message") Monitor::Log.new(r. + ' with object: ' + object , 'ERROR') else Monitor::Log.new('Error while downloading object: ' + object , 'ERROR') end return false end |
#get_item_json(object) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/chef_monitor/item.rb', line 95 def get_item_json(object) begin item = rest.get_rest(object) # item.delete('automatic') if item['automatric'] item = view_node_data(item) if item.class == Chef::Node result = JSON.pretty_generate(item) rescue Exception => e Monitor::Log.new(e. + ' with object: ' + @organization + "/" + object , 'ERROR') return nil end return result end |
#view_node_data(node) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/chef_monitor/item.rb', line 108 def view_node_data(node) result = {} result["name"] = node.name result["chef_environment"] = node.chef_environment result["normal"] = node.normal_attrs result["run_list"] = node.run_list #result["default"] = node.default_attrs #result["override"] = node.override_attrs # result["automatic"] = node.automatic_attrs result end |