dtk-node-agent 0.5.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +15 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +18 -0
  4. data/README.md +42 -0
  5. data/bin/dtk-node-agent +16 -0
  6. data/dtk-node-agent.gemspec +38 -0
  7. data/lib/config/install.config +12 -0
  8. data/lib/dtk-node-agent/installer.rb +142 -0
  9. data/lib/dtk-node-agent/version.rb +3 -0
  10. data/mcollective_additions/plugins/README.md +1 -0
  11. data/mcollective_additions/plugins/v1.2/agent/discovery.rb +39 -0
  12. data/mcollective_additions/plugins/v1.2/agent/get_log_fragment.ddl +15 -0
  13. data/mcollective_additions/plugins/v1.2/agent/get_log_fragment.rb +79 -0
  14. data/mcollective_additions/plugins/v1.2/agent/git_access.ddl +9 -0
  15. data/mcollective_additions/plugins/v1.2/agent/git_access.rb +79 -0
  16. data/mcollective_additions/plugins/v1.2/agent/netstat.ddl +9 -0
  17. data/mcollective_additions/plugins/v1.2/agent/netstat.rb +34 -0
  18. data/mcollective_additions/plugins/v1.2/agent/puppet_apply.ddl +9 -0
  19. data/mcollective_additions/plugins/v1.2/agent/puppet_apply.rb +630 -0
  20. data/mcollective_additions/plugins/v1.2/agent/rpcutil.ddl +204 -0
  21. data/mcollective_additions/plugins/v1.2/agent/rpcutil.rb +101 -0
  22. data/mcollective_additions/plugins/v1.2/facts/pbuilder_facts.rb +35 -0
  23. data/mcollective_additions/plugins/v2.2/agent/dev_manager.ddl +9 -0
  24. data/mcollective_additions/plugins/v2.2/agent/dev_manager.rb +69 -0
  25. data/mcollective_additions/plugins/v2.2/agent/discovery.rb +39 -0
  26. data/mcollective_additions/plugins/v2.2/agent/dtk_node_agent_git_client.rb +94 -0
  27. data/mcollective_additions/plugins/v2.2/agent/execute_tests.ddl +9 -0
  28. data/mcollective_additions/plugins/v2.2/agent/execute_tests.rb +64 -0
  29. data/mcollective_additions/plugins/v2.2/agent/get_log_fragment.ddl +15 -0
  30. data/mcollective_additions/plugins/v2.2/agent/get_log_fragment.rb +79 -0
  31. data/mcollective_additions/plugins/v2.2/agent/git_access.ddl +9 -0
  32. data/mcollective_additions/plugins/v2.2/agent/git_access.rb +72 -0
  33. data/mcollective_additions/plugins/v2.2/agent/netstat.ddl +9 -0
  34. data/mcollective_additions/plugins/v2.2/agent/netstat.rb +34 -0
  35. data/mcollective_additions/plugins/v2.2/agent/ps.ddl +9 -0
  36. data/mcollective_additions/plugins/v2.2/agent/ps.rb +37 -0
  37. data/mcollective_additions/plugins/v2.2/agent/puppet_apply.ddl +9 -0
  38. data/mcollective_additions/plugins/v2.2/agent/puppet_apply.rb +633 -0
  39. data/mcollective_additions/plugins/v2.2/agent/puppet_cancel.ddl +10 -0
  40. data/mcollective_additions/plugins/v2.2/agent/puppet_cancel.rb +78 -0
  41. data/mcollective_additions/plugins/v2.2/agent/rpcutil.ddl +204 -0
  42. data/mcollective_additions/plugins/v2.2/agent/rpcutil.rb +101 -0
  43. data/mcollective_additions/plugins/v2.2/agent/sync_agent_code.ddl +10 -0
  44. data/mcollective_additions/plugins/v2.2/agent/sync_agent_code.rb +85 -0
  45. data/mcollective_additions/plugins/v2.2/agent/tail.ddl +11 -0
  46. data/mcollective_additions/plugins/v2.2/agent/tail.rb +67 -0
  47. data/mcollective_additions/plugins/v2.2/connector/r8stomp.rb +238 -0
  48. data/mcollective_additions/plugins/v2.2/connector/stomp.rb +349 -0
  49. data/mcollective_additions/plugins/v2.2/connector/stomp_em.rb +191 -0
  50. data/mcollective_additions/plugins/v2.2/facts/pbuilder_facts.rb +35 -0
  51. data/mcollective_additions/plugins/v2.2/security/sshkey.ddl +9 -0
  52. data/mcollective_additions/plugins/v2.2/security/sshkey.rb +362 -0
  53. data/mcollective_additions/server.cfg +22 -0
  54. data/puppet_additions/modules/r8/lib/puppet/type/r8_export_file.rb +53 -0
  55. data/puppet_additions/modules/r8/manifests/export_variable.rb +10 -0
  56. data/puppet_additions/puppet_lib_base/puppet/indirector/catalog/r8_storeconfig_backend.rb +48 -0
  57. data/puppet_additions/puppet_lib_base/puppet/indirector/r8_storeconfig_backend.rb +4 -0
  58. data/puppet_additions/puppet_lib_base/puppet/indirector/resource/r8_storeconfig_backend.rb +72 -0
  59. data/src/etc/init.d/ec2-run-user-data +95 -0
  60. data/src/etc/logrotate.d/mcollective +10 -0
  61. data/src/etc/logrotate.d/puppet +7 -0
  62. metadata +189 -0
@@ -0,0 +1,204 @@
1
+ metadata :name => "rpcutil",
2
+ :description => "General helpful actions that expose stats and internals to SimpleRPC clients",
3
+ :author => "R.I.Pienaar <rip@devco.net>",
4
+ :license => "Apache License, Version 2.0",
5
+ :version => "1.0",
6
+ :url => "http://marionette-collective.org/",
7
+ :timeout => 10
8
+
9
+ action "collective_info", :description => "Info about the main and sub collectives" do
10
+ display :always
11
+
12
+ output :main_collective,
13
+ :description => "The main Collective",
14
+ :display_as => "Main Collective"
15
+
16
+ output :collectives,
17
+ :description => "All Collectives",
18
+ :display_as => "All Collectives"
19
+
20
+ summarize do
21
+ aggregate summary(:collectives)
22
+ end
23
+ end
24
+
25
+ action "inventory", :description => "System Inventory" do
26
+ display :always
27
+
28
+ output :agents,
29
+ :description => "List of agent names",
30
+ :display_as => "Agents"
31
+
32
+ output :facts,
33
+ :description => "List of facts and values",
34
+ :display_as => "Facts"
35
+
36
+ output :classes,
37
+ :description => "List of classes on the system",
38
+ :display_as => "Classes"
39
+
40
+ output :version,
41
+ :description => "MCollective Version",
42
+ :display_as => "Version"
43
+
44
+ output :main_collective,
45
+ :description => "The main Collective",
46
+ :display_as => "Main Collective"
47
+
48
+ output :collectives,
49
+ :description => "All Collectives",
50
+ :display_as => "All Collectives"
51
+
52
+ output :data_plugins,
53
+ :description => "List of data plugin names",
54
+ :display_as => "Data Plugins"
55
+ end
56
+
57
+ action "get_fact", :description => "Retrieve a single fact from the fact store" do
58
+ display :always
59
+
60
+ input :fact,
61
+ :prompt => "The name of the fact",
62
+ :description => "The fact to retrieve",
63
+ :type => :string,
64
+ :validation => '^[\w\-\.]+$',
65
+ :optional => false,
66
+ :maxlength => 40
67
+
68
+ output :fact,
69
+ :description => "The name of the fact being returned",
70
+ :display_as => "Fact"
71
+
72
+ output :value,
73
+ :description => "The value of the fact",
74
+ :display_as => "Value"
75
+
76
+ summarize do
77
+ aggregate summary(:value)
78
+ end
79
+ end
80
+
81
+ action "daemon_stats", :description => "Get statistics from the running daemon" do
82
+ display :always
83
+
84
+ output :threads,
85
+ :description => "List of threads active in the daemon",
86
+ :display_as => "Threads"
87
+
88
+ output :agents,
89
+ :description => "List of agents loaded",
90
+ :display_as => "Agents"
91
+
92
+ output :pid,
93
+ :description => "Process ID of the daemon",
94
+ :display_as => "PID"
95
+
96
+ output :times,
97
+ :description => "Processor time consumed by the daemon",
98
+ :display_as => "Times"
99
+
100
+ output :validated,
101
+ :description => "Messages that passed security validation",
102
+ :display_as => "Security Validated"
103
+
104
+ output :unvalidated,
105
+ :description => "Messages that failed security validation",
106
+ :display_as => "Failed Security"
107
+
108
+ output :passed,
109
+ :description => "Passed filter checks",
110
+ :display_as => "Passed Filter"
111
+
112
+ output :filtered,
113
+ :description => "Didn't pass filter checks",
114
+ :display_as => "Failed Filter"
115
+
116
+ output :starttime,
117
+ :description => "Time the server started",
118
+ :display_as => "Start Time"
119
+
120
+ output :total,
121
+ :description => "Total messages received",
122
+ :display_as => "Total Messages"
123
+
124
+ output :replies,
125
+ :description => "Replies sent back to clients",
126
+ :display_as => "Replies"
127
+
128
+ output :configfile,
129
+ :description => "Config file used to start the daemon",
130
+ :display_as => "Config File"
131
+
132
+ output :version,
133
+ :description => "MCollective Version",
134
+ :display_as => "Version"
135
+
136
+ output :ttlexpired,
137
+ :description => "Messages that did pass TTL checks",
138
+ :display_as => "TTL Expired"
139
+
140
+ summarize do
141
+ aggregate summary(:version)
142
+ aggregate summary(:agents)
143
+ end
144
+ end
145
+
146
+ action "agent_inventory", :description => "Inventory of all agents on the server" do
147
+ display :always
148
+
149
+ output :agents,
150
+ :description => "List of agents on the server",
151
+ :display_as => "Agents"
152
+ end
153
+
154
+ action "get_config_item", :description => "Get the active value of a specific config property" do
155
+ display :always
156
+
157
+ input :item,
158
+ :prompt => "Configuration Item",
159
+ :description => "The item to retrieve from the server",
160
+ :type => :string,
161
+ :validation => '^.+$',
162
+ :optional => false,
163
+ :maxlength => 50
164
+
165
+ output :item,
166
+ :description => "The config property being retrieved",
167
+ :display_as => "Property"
168
+
169
+ output :value,
170
+ :description => "The value that is in use",
171
+ :display_as => "Value"
172
+
173
+ summarize do
174
+ aggregate summary(:value)
175
+ end
176
+ end
177
+
178
+ action "get_data", :description => "Get data from a data plugin" do
179
+ display :always
180
+
181
+ input :source,
182
+ :prompt => "Data Source",
183
+ :description => "The data plugin to retrieve information from",
184
+ :type => :string,
185
+ :validation => '^\w+$',
186
+ :optional => false,
187
+ :maxlength => 50
188
+
189
+ input :query,
190
+ :prompt => "Query",
191
+ :description => "The query argument to supply to the data plugin",
192
+ :type => :string,
193
+ :validation => '^.+$',
194
+ :optional => true,
195
+ :maxlength => 50
196
+ end
197
+
198
+ action "ping", :description => "Responds to requests for PING with PONG" do
199
+ display :always
200
+
201
+ output :pong,
202
+ :description => "The local timestamp",
203
+ :display_as => "Timestamp"
204
+ end
@@ -0,0 +1,101 @@
1
+ module MCollective
2
+ module Agent
3
+ class Rpcutil<RPC::Agent
4
+ # Basic system inventory, same as the basic discovery agent
5
+ action "inventory" do
6
+ reply[:agents] = Agents.agentlist
7
+ reply[:facts] = PluginManager["facts_plugin"].get_facts
8
+ reply[:version] = MCollective.version
9
+ reply[:classes] = []
10
+ reply[:main_collective] = config.main_collective
11
+ reply[:collectives] = config.collectives
12
+ reply[:data_plugins] = PluginManager.grep(/_data$/)
13
+
14
+ cfile = Config.instance.classesfile
15
+ if File.exist?(cfile)
16
+ reply[:classes] = File.readlines(cfile).map {|i| i.chomp}
17
+ end
18
+ end
19
+
20
+ # Retrieve a single fact from the node
21
+ action "get_fact" do
22
+ validate :fact, String
23
+
24
+ reply[:fact] = request[:fact]
25
+ reply[:value] = Facts[request[:fact]]
26
+ end
27
+
28
+ # Get the global stats for this mcollectied
29
+ action "daemon_stats" do
30
+ stats = PluginManager["global_stats"].to_hash
31
+
32
+ reply[:threads] = stats[:threads]
33
+ reply[:agents] = stats[:agents]
34
+ reply[:pid] = stats[:pid]
35
+ reply[:times] = stats[:times]
36
+ reply[:configfile] = Config.instance.configfile
37
+ reply[:version] = MCollective.version
38
+
39
+ reply.data.merge!(stats[:stats])
40
+ end
41
+
42
+ # Builds an inventory of all agents on teh machine
43
+ # including license, version and timeout information
44
+ action "agent_inventory" do
45
+ reply[:agents] = []
46
+
47
+ Agents.agentlist.sort.each do |target_agent|
48
+ agent = PluginManager["#{target_agent}_agent"]
49
+ actions = agent.methods.grep(/_agent/)
50
+
51
+ agent_data = {:agent => target_agent,
52
+ :license => "unknown",
53
+ :timeout => agent.timeout,
54
+ :description => "unknown",
55
+ :name => target_agent,
56
+ :url => "unknown",
57
+ :version => "unknown",
58
+ :author => "unknown"}
59
+
60
+ agent_data.merge!(agent.meta)
61
+
62
+ reply[:agents] << agent_data
63
+ end
64
+ end
65
+
66
+ # Retrieves a single config property that is in effect
67
+ action "get_config_item" do
68
+ validate :item, String
69
+
70
+ reply.fail! "Unknown config property #{request[:item]}" unless config.respond_to?(request[:item])
71
+
72
+ reply[:item] = request[:item]
73
+ reply[:value] = config.send(request[:item])
74
+ end
75
+
76
+ # Responds to PING requests with the local timestamp
77
+ action "ping" do
78
+ reply[:pong] = Time.now.to_i
79
+ end
80
+
81
+ # Returns all configured collectives
82
+ action "collective_info" do
83
+ config = Config.instance
84
+ reply[:main_collective] = config.main_collective
85
+ reply[:collectives] = config.collectives
86
+ end
87
+
88
+ action "get_data" do
89
+ validate :source, String
90
+
91
+ query = Data.ddl_transform_input(Data.ddl(request[:source]), request[:query].to_s)
92
+
93
+ data = Data[ request[:source] ].lookup(query)
94
+
95
+ data.keys.each do |key|
96
+ reply[key] = data[key]
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,35 @@
1
+ require 'open-uri'
2
+ require 'timeout'
3
+ require 'yaml'
4
+
5
+ module MCollective
6
+ module Facts
7
+ # A factsource for pbuilder
8
+ class Pbuilder_facts < Base
9
+
10
+ def load_facts_from_source
11
+ ret = {"pbuilderid" => get_pbuilderid()}
12
+ yaml_file = '/etc/mcollective/facts.yaml'
13
+ if File.exists?(yaml_file)
14
+ yaml_facts = YAML.load_file(yaml_file)
15
+ ret.merge!(yaml_facts)
16
+ end
17
+ ret
18
+ end
19
+
20
+ def get_pbuilderid()
21
+ ret = nil
22
+ begin
23
+ addr = "169.254.169.254"
24
+ wait_sec = 2
25
+ Timeout::timeout(wait_sec) {open("http://#{addr}:80/")}
26
+ ret = OpenURI.open_uri("http://#{addr}/2008-02-01/meta-data/instance-id").read
27
+ rescue Timeout::Error
28
+ rescue
29
+ #TODO: unexpected; write to log what error is
30
+ end
31
+ ret
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,9 @@
1
+ metadata :name => "development manager",
2
+ :description => "Manager which allows manipulation of nodes",
3
+ :author => "Reactor8",
4
+ :license => "",
5
+ :version => "",
6
+ :url => "",
7
+ :timeout => 2
8
+ action "inject_agent", :description => "Injects agent content and restarts mcollective" do
9
+ end
@@ -0,0 +1,69 @@
1
+ require 'base64'
2
+
3
+ module MCollective
4
+ module Agent
5
+ class Dev_manager < RPC::Agent
6
+
7
+ AGENT_MCOLLECTIVE_LOCATION = "#{::MCollective::Config.instance.libdir}/mcollective/agent/"
8
+ @log = Log.instance
9
+
10
+ action "inject_agent" do
11
+ begin
12
+
13
+ ret ||= Response.new()
14
+
15
+ request[:agent_files].each do |k,v|
16
+ if v == :deleted
17
+ File.delete("#{AGENT_MCOLLECTIVE_LOCATION}#{k}")
18
+ next
19
+ end
20
+ content = Base64.decode64(v)
21
+ File.open("#{AGENT_MCOLLECTIVE_LOCATION}#{k}",'w') do |file|
22
+ file << content
23
+ end
24
+ end
25
+ ret.set_status_succeeded!()
26
+
27
+ t1 = Thread.new do
28
+ system("sudo /etc/init.d/mcollective restart")
29
+ end
30
+
31
+ return ret
32
+
33
+ rescue Exception => e
34
+ @log.error e
35
+ ret.set_status_failed!()
36
+ error_info = { :error => { :message => "Error syncing agents: #{e}" } }
37
+ ret.merge!(error_info)
38
+ end
39
+ return ret
40
+ end
41
+ end
42
+ #TODO: this should be common accross Agents
43
+ class Response < Hash
44
+ def initialize(hash={})
45
+ super()
46
+ self.merge!(hash)
47
+ self[:status] = :unknown unless hash.has_key?(:status)
48
+ end
49
+
50
+ def to_hash()
51
+ Hash.new.merge(self)
52
+ end
53
+
54
+ def failed?()
55
+ self[:status] == :failed
56
+ end
57
+
58
+ def set_status_failed!()
59
+ self[:status] = :failed
60
+ end
61
+ def set_status_succeeded!()
62
+ self[:status] = :succeeded
63
+ end
64
+ def set_dynamic_attributes!(dynamic_attributes)
65
+ self[:dynamic_attributes] = dynamic_attributes
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,39 @@
1
+ module MCollective
2
+ module Agent
3
+ # Discovery agent for The Marionette Collective
4
+ #
5
+ # Released under the Apache License, Version 2
6
+ class Discovery
7
+ attr_reader :timeout, :meta
8
+
9
+ def initialize
10
+ config = Config.instance.pluginconf
11
+
12
+ @timeout = 5
13
+ @timeout = config["discovery.timeout"].to_i if config.include?("discovery.timeout")
14
+
15
+ @meta = {:license => "Apache License, Version 2",
16
+ :author => "R.I.Pienaar <rip@devco.net>",
17
+ :timeout => @timeout,
18
+ :name => "Discovery Agent",
19
+ :version => MCollective.version,
20
+ :url => "http://www.marionette-collective.org",
21
+ :description => "MCollective Discovery Agent"}
22
+ end
23
+
24
+ def handlemsg(msg, stomp)
25
+ reply = "unknown request"
26
+
27
+ case msg[:body]
28
+ when "ping"
29
+ reply = "pong"
30
+
31
+ else
32
+ reply = "Unknown Request: #{msg[:body]}"
33
+ end
34
+
35
+ reply
36
+ end
37
+ end
38
+ end
39
+ end