choria-mcorpc-support 2.21.1 → 2.23.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.
- checksums.yaml +4 -4
- data/lib/mcollective.rb +1 -2
- data/lib/mcollective/agent/bolt_tasks.ddl +253 -0
- data/lib/mcollective/agent/bolt_tasks.json +365 -0
- data/lib/mcollective/agent/bolt_tasks.rb +178 -0
- data/lib/mcollective/agent/choria_util.ddl +152 -0
- data/lib/mcollective/agent/choria_util.json +244 -0
- data/lib/mcollective/agent/rpcutil.ddl +8 -4
- data/lib/mcollective/agent/rpcutil.json +333 -0
- data/lib/mcollective/agent/scout.ddl +169 -0
- data/lib/mcollective/agent/scout.json +224 -0
- data/lib/mcollective/agents.rb +7 -6
- data/lib/mcollective/aggregate.rb +4 -4
- data/lib/mcollective/aggregate/average.rb +2 -2
- data/lib/mcollective/aggregate/base.rb +2 -2
- data/lib/mcollective/aggregate/result.rb +3 -3
- data/lib/mcollective/aggregate/result/collection_result.rb +2 -2
- data/lib/mcollective/aggregate/result/numeric_result.rb +2 -2
- data/lib/mcollective/aggregate/sum.rb +2 -2
- data/lib/mcollective/aggregate/summary.rb +3 -4
- data/lib/mcollective/application.rb +57 -21
- data/lib/mcollective/application/choria.rb +189 -0
- data/lib/mcollective/application/completion.rb +6 -6
- data/lib/mcollective/application/facts.rb +11 -11
- data/lib/mcollective/application/federation.rb +237 -0
- data/lib/mcollective/application/find.rb +4 -4
- data/lib/mcollective/application/help.rb +3 -3
- data/lib/mcollective/application/inventory.rb +3 -341
- data/lib/mcollective/application/ping.rb +5 -51
- data/lib/mcollective/application/playbook.rb +207 -0
- data/lib/mcollective/application/plugin.rb +106 -106
- data/lib/mcollective/application/rpc.rb +3 -108
- data/lib/mcollective/application/tasks.rb +425 -0
- data/lib/mcollective/applications.rb +11 -10
- data/lib/mcollective/audit/choria.rb +33 -0
- data/lib/mcollective/cache.rb +2 -4
- data/lib/mcollective/client.rb +11 -10
- data/lib/mcollective/config.rb +21 -34
- data/lib/mcollective/connector/base.rb +2 -1
- data/lib/mcollective/connector/nats.ddl +9 -0
- data/lib/mcollective/connector/nats.rb +450 -0
- data/lib/mcollective/data.rb +8 -3
- data/lib/mcollective/data/agent_data.rb +1 -1
- data/lib/mcollective/data/base.rb +6 -5
- data/lib/mcollective/data/bolt_task_data.ddl +90 -0
- data/lib/mcollective/data/bolt_task_data.rb +32 -0
- data/lib/mcollective/data/collective_data.rb +1 -1
- data/lib/mcollective/data/fact_data.rb +6 -6
- data/lib/mcollective/data/fstat_data.rb +2 -4
- data/lib/mcollective/data/result.rb +7 -2
- data/lib/mcollective/ddl/agentddl.rb +5 -17
- data/lib/mcollective/ddl/base.rb +10 -13
- data/lib/mcollective/discovery.rb +24 -39
- data/lib/mcollective/discovery/choria.ddl +11 -0
- data/lib/mcollective/discovery/choria.rb +223 -0
- data/lib/mcollective/discovery/flatfile.rb +7 -8
- data/lib/mcollective/discovery/mc.rb +2 -2
- data/lib/mcollective/discovery/stdin.rb +17 -18
- data/lib/mcollective/exceptions.rb +13 -0
- data/lib/mcollective/facts/base.rb +9 -9
- data/lib/mcollective/facts/yaml_facts.rb +12 -12
- data/lib/mcollective/generators.rb +3 -3
- data/lib/mcollective/generators/agent_generator.rb +3 -4
- data/lib/mcollective/generators/base.rb +14 -15
- data/lib/mcollective/generators/data_generator.rb +5 -6
- data/lib/mcollective/log.rb +2 -2
- data/lib/mcollective/logger/base.rb +3 -2
- data/lib/mcollective/logger/console_logger.rb +10 -10
- data/lib/mcollective/logger/file_logger.rb +7 -7
- data/lib/mcollective/logger/syslog_logger.rb +11 -15
- data/lib/mcollective/message.rb +8 -39
- data/lib/mcollective/monkey_patches.rb +2 -4
- data/lib/mcollective/optionparser.rb +2 -1
- data/lib/mcollective/pluginmanager.rb +3 -5
- data/lib/mcollective/pluginpackager.rb +1 -3
- data/lib/mcollective/pluginpackager/agent_definition.rb +3 -8
- data/lib/mcollective/pluginpackager/forge_packager.rb +7 -9
- data/lib/mcollective/pluginpackager/standard_definition.rb +1 -2
- data/lib/mcollective/registration/base.rb +18 -16
- data/lib/mcollective/rpc.rb +2 -4
- data/lib/mcollective/rpc/actionrunner.rb +16 -18
- data/lib/mcollective/rpc/agent.rb +26 -43
- data/lib/mcollective/rpc/audit.rb +1 -0
- data/lib/mcollective/rpc/client.rb +67 -85
- data/lib/mcollective/rpc/helpers.rb +55 -62
- data/lib/mcollective/rpc/progress.rb +2 -2
- data/lib/mcollective/rpc/reply.rb +17 -19
- data/lib/mcollective/rpc/request.rb +7 -5
- data/lib/mcollective/rpc/result.rb +6 -8
- data/lib/mcollective/rpc/stats.rb +49 -58
- data/lib/mcollective/security/base.rb +13 -56
- data/lib/mcollective/security/choria.rb +765 -0
- data/lib/mcollective/shell.rb +9 -4
- data/lib/mcollective/signer/base.rb +28 -0
- data/lib/mcollective/signer/choria.rb +185 -0
- data/lib/mcollective/ssl.rb +8 -6
- data/lib/mcollective/util.rb +58 -55
- data/lib/mcollective/util/bolt_support.rb +176 -0
- data/lib/mcollective/util/bolt_support/plan_runner.rb +167 -0
- data/lib/mcollective/util/bolt_support/task_result.rb +94 -0
- data/lib/mcollective/util/bolt_support/task_results.rb +128 -0
- data/lib/mcollective/util/choria.rb +946 -0
- data/lib/mcollective/util/indifferent_hash.rb +12 -0
- data/lib/mcollective/util/natswrapper.rb +242 -0
- data/lib/mcollective/util/playbook.rb +435 -0
- data/lib/mcollective/util/playbook/data_stores.rb +201 -0
- data/lib/mcollective/util/playbook/data_stores/base.rb +99 -0
- data/lib/mcollective/util/playbook/data_stores/consul_data_store.rb +88 -0
- data/lib/mcollective/util/playbook/data_stores/environment_data_store.rb +33 -0
- data/lib/mcollective/util/playbook/data_stores/etcd_data_store.rb +42 -0
- data/lib/mcollective/util/playbook/data_stores/file_data_store.rb +106 -0
- data/lib/mcollective/util/playbook/data_stores/shell_data_store.rb +103 -0
- data/lib/mcollective/util/playbook/inputs.rb +265 -0
- data/lib/mcollective/util/playbook/nodes.rb +207 -0
- data/lib/mcollective/util/playbook/nodes/mcollective_nodes.rb +86 -0
- data/lib/mcollective/util/playbook/nodes/pql_nodes.rb +40 -0
- data/lib/mcollective/util/playbook/nodes/shell_nodes.rb +55 -0
- data/lib/mcollective/util/playbook/nodes/terraform_nodes.rb +65 -0
- data/lib/mcollective/util/playbook/nodes/yaml_nodes.rb +47 -0
- data/lib/mcollective/util/playbook/playbook_logger.rb +47 -0
- data/lib/mcollective/util/playbook/puppet_logger.rb +51 -0
- data/lib/mcollective/util/playbook/report.rb +152 -0
- data/lib/mcollective/util/playbook/task_result.rb +55 -0
- data/lib/mcollective/util/playbook/tasks.rb +196 -0
- data/lib/mcollective/util/playbook/tasks/base.rb +45 -0
- data/lib/mcollective/util/playbook/tasks/graphite_event_task.rb +64 -0
- data/lib/mcollective/util/playbook/tasks/mcollective_task.rb +356 -0
- data/lib/mcollective/util/playbook/tasks/shell_task.rb +93 -0
- data/lib/mcollective/util/playbook/tasks/slack_task.rb +105 -0
- data/lib/mcollective/util/playbook/tasks/webhook_task.rb +136 -0
- data/lib/mcollective/util/playbook/template_util.rb +98 -0
- data/lib/mcollective/util/playbook/uses.rb +169 -0
- data/lib/mcollective/util/tasks_support.rb +751 -0
- data/lib/mcollective/util/tasks_support/cli.rb +260 -0
- data/lib/mcollective/util/tasks_support/default_formatter.rb +138 -0
- data/lib/mcollective/util/tasks_support/json_formatter.rb +108 -0
- data/lib/mcollective/validator.rb +6 -1
- data/lib/mcollective/validator/bolt_task_name_validator.ddl +7 -0
- data/lib/mcollective/validator/bolt_task_name_validator.rb +11 -0
- data/lib/mcollective/validator/length_validator.rb +1 -3
- metadata +65 -6
- data/lib/mcollective/application/describe_filter.rb +0 -87
- data/lib/mcollective/matcher.rb +0 -220
- data/lib/mcollective/matcher/parser.rb +0 -128
- data/lib/mcollective/matcher/scanner.rb +0 -241
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
module MCollective
|
|
2
2
|
module Facts
|
|
3
|
-
require
|
|
3
|
+
require "yaml"
|
|
4
4
|
|
|
5
5
|
# A factsource that reads a hash of facts from a YAML file
|
|
6
6
|
#
|
|
7
7
|
# Multiple files can be specified seperated with a : in the
|
|
8
8
|
# config file, they will be merged with later files overriding
|
|
9
9
|
# earlier ones in the list.
|
|
10
|
-
class Yaml_facts<Base
|
|
10
|
+
class Yaml_facts < Base
|
|
11
11
|
def initialize
|
|
12
12
|
@yaml_file_mtimes = {}
|
|
13
13
|
|
|
@@ -23,15 +23,15 @@ module MCollective
|
|
|
23
23
|
fact_files.each do |file|
|
|
24
24
|
begin
|
|
25
25
|
if File.exist?(file)
|
|
26
|
-
|
|
27
|
-
facts.merge!(YAML.safe_load(File.read(file)))
|
|
28
|
-
|
|
29
|
-
facts.merge!(YAML.load(File.read(file)))
|
|
26
|
+
if YAML.respond_to? :safe_load
|
|
27
|
+
facts.merge!(YAML.safe_load(File.read(file)))
|
|
28
|
+
else
|
|
29
|
+
facts.merge!(YAML.load(File.read(file)))
|
|
30
30
|
end
|
|
31
31
|
else
|
|
32
32
|
raise("Can't find YAML file to load: #{file}")
|
|
33
33
|
end
|
|
34
|
-
rescue Exception => e
|
|
34
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
|
35
35
|
Log.error("Failed to load yaml facts from #{file}: #{e.class}: #{e}")
|
|
36
36
|
end
|
|
37
37
|
end
|
|
@@ -49,13 +49,13 @@ module MCollective
|
|
|
49
49
|
@yaml_file_mtimes[file] ||= File.stat(file).mtime
|
|
50
50
|
mtime = File.stat(file).mtime
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
@yaml_file_mtimes[file] = mtime
|
|
52
|
+
next unless mtime > @yaml_file_mtimes[file]
|
|
54
53
|
|
|
55
|
-
|
|
54
|
+
@yaml_file_mtimes[file] = mtime
|
|
56
55
|
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
Log.debug("Forcing fact reload due to age of #{file}")
|
|
57
|
+
|
|
58
|
+
return true
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
false
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module MCollective
|
|
2
2
|
module Generators
|
|
3
|
-
require "mcollective/generators/base
|
|
4
|
-
require "mcollective/generators/data_generator
|
|
5
|
-
require "mcollective/generators/agent_generator
|
|
3
|
+
require "mcollective/generators/base"
|
|
4
|
+
require "mcollective/generators/data_generator"
|
|
5
|
+
require "mcollective/generators/agent_generator"
|
|
6
6
|
end
|
|
7
7
|
end
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
module MCollective
|
|
2
2
|
module Generators
|
|
3
|
-
class AgentGenerator<Base
|
|
4
|
-
|
|
3
|
+
class AgentGenerator < Base
|
|
5
4
|
attr_accessor :ddl, :content
|
|
6
5
|
|
|
7
|
-
def initialize(plugin_name, actions
|
|
8
|
-
license
|
|
6
|
+
def initialize(plugin_name, actions=[], name=nil, description=nil, author=nil,
|
|
7
|
+
license=nil, version=nil, url=nil, timeout=nil)
|
|
9
8
|
|
|
10
9
|
super(name, description, author, license, version, url, timeout)
|
|
11
10
|
@plugin_name = plugin_name
|
|
@@ -2,6 +2,7 @@ module MCollective
|
|
|
2
2
|
module Generators
|
|
3
3
|
class Base
|
|
4
4
|
attr_accessor :meta, :plugin_name, :mod_name
|
|
5
|
+
|
|
5
6
|
def initialize(name, description, author, license, version, url, timeout)
|
|
6
7
|
@meta = {:name => name,
|
|
7
8
|
:description => description,
|
|
@@ -23,23 +24,21 @@ module MCollective
|
|
|
23
24
|
end
|
|
24
25
|
|
|
25
26
|
def write_plugins
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
puts "Created plugin directory : #{@plugin_name}"
|
|
27
|
+
Dir.mkdir @plugin_name
|
|
28
|
+
dirname = File.join(@plugin_name, @mod_name.downcase)
|
|
29
|
+
Dir.mkdir dirname
|
|
30
|
+
puts "Created plugin directory : #{@plugin_name}"
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
File.open(File.join(dirname, "#{@plugin_name}.ddl"), "w") {|f| f.puts @ddl}
|
|
33
|
+
puts "Created DDL file : #{File.join(dirname, "#{@plugin_name}.ddl")}"
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
end
|
|
35
|
+
File.open(File.join(dirname, "#{@plugin_name}.rb"), "w") {|f| f.puts @plugin}
|
|
36
|
+
puts "Created #{@mod_name} file : #{File.join(dirname, "#{@plugin_name}.rb")}"
|
|
37
|
+
rescue Errno::EEXIST
|
|
38
|
+
raise "cannot generate '#{@plugin_name}' : plugin directory already exists."
|
|
39
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
|
40
|
+
FileUtils.rm_rf(@plugin_name) if File.directory?(@plugin_name)
|
|
41
|
+
raise "cannot generate plugin - #{e}"
|
|
43
42
|
end
|
|
44
43
|
end
|
|
45
44
|
end
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
module MCollective
|
|
2
2
|
module Generators
|
|
3
|
-
class DataGenerator<Base
|
|
4
|
-
|
|
3
|
+
class DataGenerator < Base
|
|
5
4
|
attr_accessor :ddl, :content
|
|
6
5
|
|
|
7
|
-
def initialize(plugin_name, outputs
|
|
8
|
-
license
|
|
6
|
+
def initialize(plugin_name, outputs=[], name=nil, description=nil, author=nil,
|
|
7
|
+
license=nil, version=nil, url=nil, timeout=nil)
|
|
9
8
|
|
|
10
9
|
super(name, description, author, license, version, url, timeout)
|
|
11
10
|
@mod_name = "Data"
|
|
@@ -22,7 +21,7 @@ module MCollective
|
|
|
22
21
|
query_text = "dataquery :description => \"Query information\" do\n"
|
|
23
22
|
query_text += ERB.new(File.read(File.join(File.dirname(__FILE__), "templates", "data_input_snippet.erb"))).result
|
|
24
23
|
|
|
25
|
-
@outputs.each_with_index do |output,i|
|
|
24
|
+
@outputs.each_with_index do |output, i|
|
|
26
25
|
query_text += "%2s%s" % [" ", "output :#{output},\n"]
|
|
27
26
|
query_text += "%9s%s" % [" ", ":description => \"%DESCRIPTION%\",\n"]
|
|
28
27
|
query_text += "%9s%s" % [" ", ":display_as => \"%DESCRIPTION%\"\n"]
|
|
@@ -39,7 +38,7 @@ module MCollective
|
|
|
39
38
|
content_text = "%6s%s" % [" ", "query do |what|\n"]
|
|
40
39
|
|
|
41
40
|
@outputs.each do |output|
|
|
42
|
-
|
|
41
|
+
content_text += "%8s%s" % [" ", "result[:#{output}] = nil\n"]
|
|
43
42
|
end
|
|
44
43
|
content_text += "%6s%s" % [" ", "end\n"]
|
|
45
44
|
|
data/lib/mcollective/log.rb
CHANGED
|
@@ -60,7 +60,7 @@ module MCollective
|
|
|
60
60
|
else
|
|
61
61
|
t = Time.new.strftime("%H:%M:%S")
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
warn "#{t}: #{level}: #{from}: #{msg}"
|
|
64
64
|
end
|
|
65
65
|
end
|
|
66
66
|
|
|
@@ -98,7 +98,7 @@ module MCollective
|
|
|
98
98
|
@logger.start
|
|
99
99
|
rescue Exception => e # rubocop:disable Lint/RescueException
|
|
100
100
|
@configured = false
|
|
101
|
-
|
|
101
|
+
warn "Could not start logger: #{e.class} #{e}"
|
|
102
102
|
end
|
|
103
103
|
|
|
104
104
|
# figures out the filename that called us
|
|
@@ -29,7 +29,7 @@ module MCollective
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
# Sets a new level and record it in @active_level
|
|
32
|
-
def set_level(level)
|
|
32
|
+
def set_level(level) # rubocop:disable Naming/AccessorMethodName
|
|
33
33
|
set_logging_level(level)
|
|
34
34
|
@active_level = level.to_sym
|
|
35
35
|
end
|
|
@@ -47,6 +47,7 @@ module MCollective
|
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
private
|
|
50
|
+
|
|
50
51
|
def map_level(level)
|
|
51
52
|
raise "Logger class do not know how to handle #{level} messages" unless valid_levels.include?(level.to_sym)
|
|
52
53
|
|
|
@@ -54,7 +55,7 @@ module MCollective
|
|
|
54
55
|
end
|
|
55
56
|
|
|
56
57
|
# Gets the next level in the list, cycles down to the firt once it reaches the end
|
|
57
|
-
def get_next_level
|
|
58
|
+
def get_next_level # rubocop:disable Naming/AccessorMethodName
|
|
58
59
|
# if all else fails, always go to debug mode
|
|
59
60
|
nextlvl = :debug
|
|
60
61
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module MCollective
|
|
2
2
|
module Logger
|
|
3
3
|
# Implements a syslog based logger using the standard ruby syslog class
|
|
4
|
-
class Console_logger<Base
|
|
4
|
+
class Console_logger < Base
|
|
5
5
|
def start
|
|
6
6
|
set_level(:info)
|
|
7
7
|
|
|
@@ -9,19 +9,19 @@ module MCollective
|
|
|
9
9
|
set_level(config.loglevel.to_sym) if config.configured
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
def set_logging_level(level)
|
|
12
|
+
def set_logging_level(level) # rubocop:disable Naming/AccessorMethodName
|
|
13
13
|
# nothing to do here, we ignore high levels when we log
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def valid_levels
|
|
17
|
-
{:info
|
|
18
|
-
:warn
|
|
17
|
+
{:info => :info,
|
|
18
|
+
:warn => :warning,
|
|
19
19
|
:debug => :debug,
|
|
20
20
|
:fatal => :crit,
|
|
21
21
|
:error => :err}
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
def log(level, from, msg, normal_output
|
|
24
|
+
def log(level, from, msg, normal_output=$stderr, last_resort_output=$stderr)
|
|
25
25
|
if @known_levels.index(level) >= @known_levels.index(@active_level)
|
|
26
26
|
time = Time.new.strftime("%Y/%m/%d %H:%M:%S")
|
|
27
27
|
|
|
@@ -41,20 +41,20 @@ module MCollective
|
|
|
41
41
|
|
|
42
42
|
colors = {:error => Util.color(:red),
|
|
43
43
|
:fatal => Util.color(:red),
|
|
44
|
-
:warn
|
|
45
|
-
:info
|
|
44
|
+
:warn => Util.color(:yellow),
|
|
45
|
+
:info => Util.color(:green),
|
|
46
46
|
:reset => Util.color(:reset)}
|
|
47
47
|
|
|
48
48
|
if colorize
|
|
49
|
-
|
|
49
|
+
colors[level] || ""
|
|
50
50
|
else
|
|
51
|
-
|
|
51
|
+
""
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
# Helper to return a string in specific color
|
|
56
56
|
def colorize(level, msg)
|
|
57
|
-
"%s%s%s" % [
|
|
57
|
+
"%s%s%s" % [color(level), msg, color(:reset)]
|
|
58
58
|
end
|
|
59
59
|
end
|
|
60
60
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "logger"
|
|
2
2
|
|
|
3
3
|
module MCollective
|
|
4
4
|
module Logger
|
|
@@ -9,7 +9,7 @@ module MCollective
|
|
|
9
9
|
# - config.logfile
|
|
10
10
|
# - config.keeplogs defaults to 2097152
|
|
11
11
|
# - config.max_log_size defaults to 5
|
|
12
|
-
class File_logger<Base
|
|
12
|
+
class File_logger < Base
|
|
13
13
|
def start
|
|
14
14
|
config = Config.instance
|
|
15
15
|
|
|
@@ -19,16 +19,16 @@ module MCollective
|
|
|
19
19
|
set_level(config.loglevel.to_sym)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
def set_logging_level(level)
|
|
22
|
+
def set_logging_level(level) # rubocop:disable Naming/AccessorMethodName
|
|
23
23
|
@logger.level = map_level(level)
|
|
24
|
-
rescue Exception => e
|
|
24
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
|
25
25
|
@logger.level = ::Logger::DEBUG
|
|
26
26
|
log(:error, "", "Could not set logging to #{level} using debug instead: #{e.class} #{e}")
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def valid_levels
|
|
30
|
-
{:info
|
|
31
|
-
:warn
|
|
30
|
+
{:info => ::Logger::INFO,
|
|
31
|
+
:warn => ::Logger::WARN,
|
|
32
32
|
:debug => ::Logger::DEBUG,
|
|
33
33
|
:fatal => ::Logger::FATAL,
|
|
34
34
|
:error => ::Logger::ERROR}
|
|
@@ -39,7 +39,7 @@ module MCollective
|
|
|
39
39
|
rescue
|
|
40
40
|
# if this fails we probably cant show the user output at all,
|
|
41
41
|
# STDERR it as last resort
|
|
42
|
-
|
|
42
|
+
warn("#{level}: #{msg}")
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
def reopen
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
module MCollective
|
|
2
2
|
module Logger
|
|
3
3
|
# Implements a syslog based logger using the standard ruby syslog class
|
|
4
|
-
class Syslog_logger<Base
|
|
5
|
-
require
|
|
4
|
+
class Syslog_logger < Base
|
|
5
|
+
require "syslog"
|
|
6
6
|
|
|
7
7
|
include Syslog::Constants
|
|
8
8
|
|
|
@@ -19,34 +19,30 @@ module MCollective
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def syslog_facility(facility)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
Syslog::LOG_USER
|
|
27
|
-
end
|
|
22
|
+
Syslog.const_get("LOG_#{facility.upcase}")
|
|
23
|
+
rescue NameError
|
|
24
|
+
warn "Invalid syslog facility #{facility} supplied, reverting to USER"
|
|
25
|
+
Syslog::LOG_USER
|
|
28
26
|
end
|
|
29
27
|
|
|
30
|
-
def set_logging_level(level)
|
|
28
|
+
def set_logging_level(level) # rubocop:disable Naming/AccessorMethodName
|
|
31
29
|
# noop
|
|
32
30
|
end
|
|
33
31
|
|
|
34
32
|
def valid_levels
|
|
35
|
-
{:info
|
|
36
|
-
:warn
|
|
33
|
+
{:info => :info,
|
|
34
|
+
:warn => :warning,
|
|
37
35
|
:debug => :debug,
|
|
38
36
|
:fatal => :crit,
|
|
39
37
|
:error => :err}
|
|
40
38
|
end
|
|
41
39
|
|
|
42
40
|
def log(level, from, msg)
|
|
43
|
-
if @known_levels.index(level) >= @known_levels.index(@active_level)
|
|
44
|
-
Syslog.send(map_level(level), "#{from} #{msg}")
|
|
45
|
-
end
|
|
41
|
+
Syslog.send(map_level(level), "#{from} #{msg}") if @known_levels.index(level) >= @known_levels.index(@active_level)
|
|
46
42
|
rescue
|
|
47
43
|
# if this fails we probably cant show the user output at all,
|
|
48
44
|
# STDERR it as last resort
|
|
49
|
-
|
|
45
|
+
warn("#{level}: #{msg}")
|
|
50
46
|
end
|
|
51
47
|
end
|
|
52
48
|
end
|
data/lib/mcollective/message.rb
CHANGED
|
@@ -2,8 +2,7 @@ module MCollective
|
|
|
2
2
|
# container for a message, its headers, agent, collective and other meta data
|
|
3
3
|
class Message
|
|
4
4
|
attr_reader :message, :request, :validated, :msgtime, :payload, :type, :expected_msgid, :reply_to
|
|
5
|
-
attr_accessor :headers, :agent, :collective, :filter
|
|
6
|
-
attr_accessor :requestid, :discovered_hosts, :options, :ttl
|
|
5
|
+
attr_accessor :headers, :agent, :collective, :filter, :requestid, :discovered_hosts, :options, :ttl
|
|
7
6
|
|
|
8
7
|
VALIDTYPES = [:message, :request, :direct_request, :reply].freeze
|
|
9
8
|
|
|
@@ -79,9 +78,7 @@ module MCollective
|
|
|
79
78
|
if type == :direct_request
|
|
80
79
|
raise "Direct requests is not enabled using the direct_addressing config option" unless Config.instance.direct_addressing
|
|
81
80
|
|
|
82
|
-
unless @discovered_hosts && !@discovered_hosts.empty?
|
|
83
|
-
raise "Can only set type to :direct_request if discovered_hosts have been set"
|
|
84
|
-
end
|
|
81
|
+
raise "Can only set type to :direct_request if discovered_hosts have been set" unless @discovered_hosts && !@discovered_hosts.empty?
|
|
85
82
|
|
|
86
83
|
# clear out the filter, custom discovery sources might interpret the filters
|
|
87
84
|
# different than the remote mcollectived and in directed mode really the only
|
|
@@ -109,6 +106,7 @@ module MCollective
|
|
|
109
106
|
# at us.
|
|
110
107
|
def expected_msgid=(msgid)
|
|
111
108
|
raise "Can only store the expected msgid for reply messages" unless @type == :reply
|
|
109
|
+
|
|
112
110
|
@expected_msgid = msgid
|
|
113
111
|
end
|
|
114
112
|
|
|
@@ -132,7 +130,7 @@ module MCollective
|
|
|
132
130
|
|
|
133
131
|
def description
|
|
134
132
|
cid = ""
|
|
135
|
-
cid += payload[:callerid]
|
|
133
|
+
cid += "#{payload[:callerid]}@" if payload.include?(:callerid)
|
|
136
134
|
cid += payload[:senderid]
|
|
137
135
|
|
|
138
136
|
"#{requestid} for agent '#{agent}' in collective '#{collective}' from #{cid}"
|
|
@@ -150,8 +148,6 @@ module MCollective
|
|
|
150
148
|
@requestid = request.payload[:requestid]
|
|
151
149
|
@payload = PluginManager["security_plugin"].encodereply(agent, payload, requestid, request.payload[:callerid])
|
|
152
150
|
when :request, :direct_request
|
|
153
|
-
validate_compound_filter(@filter["compound"]) unless @filter["compound"].empty?
|
|
154
|
-
|
|
155
151
|
@requestid ||= create_reqid
|
|
156
152
|
@payload = PluginManager["security_plugin"].encoderequest(Config.instance.identity, payload, requestid, filter, agent, collective, ttl)
|
|
157
153
|
else
|
|
@@ -159,29 +155,6 @@ module MCollective
|
|
|
159
155
|
end
|
|
160
156
|
end
|
|
161
157
|
|
|
162
|
-
def validate_compound_filter(compound_filter)
|
|
163
|
-
compound_filter.each do |filter|
|
|
164
|
-
filter.each do |statement|
|
|
165
|
-
next unless statement["fstatement"]
|
|
166
|
-
functionname = statement["fstatement"]["name"]
|
|
167
|
-
pluginname = Data.pluginname(functionname)
|
|
168
|
-
value = statement["fstatement"]["value"]
|
|
169
|
-
|
|
170
|
-
ddl = DDL.new(pluginname, :data)
|
|
171
|
-
|
|
172
|
-
# parses numbers and booleans entered as strings into proper
|
|
173
|
-
# types of data so that DDL validation will pass
|
|
174
|
-
statement["fstatement"]["params"] = Data.ddl_transform_input(ddl, statement["fstatement"]["params"])
|
|
175
|
-
|
|
176
|
-
Data.ddl_validate(ddl, statement["fstatement"]["params"])
|
|
177
|
-
|
|
178
|
-
unless value && Data.ddl_has_output?(ddl, value)
|
|
179
|
-
raise(DDLValidationError, "Data plugin '%s()' does not return a '%s' value" % [functionname, value])
|
|
180
|
-
end
|
|
181
|
-
end
|
|
182
|
-
end
|
|
183
|
-
end
|
|
184
|
-
|
|
185
158
|
def decode!
|
|
186
159
|
raise "Cannot decode message type #{type}" unless [:request, :reply].include?(type)
|
|
187
160
|
|
|
@@ -194,15 +167,15 @@ module MCollective
|
|
|
194
167
|
else
|
|
195
168
|
# We're in the client, log and carry on as best we can
|
|
196
169
|
|
|
197
|
-
#
|
|
170
|
+
# NOTE: mc_sender is unverified. The verified identity is in the
|
|
198
171
|
# payload we just failed to decode
|
|
199
172
|
Log.warn("Failed to decode a message from '#{headers['mc_sender']}': #{e}")
|
|
200
173
|
return
|
|
201
174
|
end
|
|
202
175
|
end
|
|
203
176
|
|
|
204
|
-
if type == :request
|
|
205
|
-
raise "callerid in request is not valid, surpressing reply to potentially forged request"
|
|
177
|
+
if type == :request && !PluginManager["security_plugin"].valid_callerid?(payload[:callerid])
|
|
178
|
+
raise "callerid in request is not valid, surpressing reply to potentially forged request"
|
|
206
179
|
end
|
|
207
180
|
|
|
208
181
|
[:collective, :agent, :filter, :requestid, :ttl, :msgtime].each do |prop|
|
|
@@ -216,11 +189,7 @@ module MCollective
|
|
|
216
189
|
|
|
217
190
|
msg_age = Time.now.utc.to_i - msgtime
|
|
218
191
|
|
|
219
|
-
if msg_age > ttl
|
|
220
|
-
PluginManager["global_stats"].ttlexpired
|
|
221
|
-
raise(MsgTTLExpired, "Message #{description} created at #{msgtime} is #{msg_age} seconds old, TTL is #{ttl}. Rejecting message.")
|
|
222
|
-
end
|
|
223
|
-
|
|
192
|
+
raise(MsgTTLExpired, "Message #{description} created at #{msgtime} is #{msg_age} seconds old, TTL is #{ttl}. Rejecting message.") if msg_age > ttl
|
|
224
193
|
raise(NotTargettedAtUs, "Message #{description} does not pass filters. Ignoring message.") unless PluginManager["security_plugin"].validate_filter?(payload[:filter])
|
|
225
194
|
|
|
226
195
|
@validated = true
|