lib/fluent/plugin/in_monitor_agent.rb in fluentd-0.10.57 vs lib/fluent/plugin/in_monitor_agent.rb in fluentd-0.10.58

- old
+ new

@@ -75,38 +75,55 @@ if s = qs['debug'] and s[0] opts[:with_debug_info] = true opts[:pretty_json] = true end - if tags = qs['tag'] and tag = tags[0] + if tag = get_search_parameter(qs, 'tag'.freeze) # ?tag= to search an output plugin by match pattern if obj = @agent.plugin_info_by_tag(tag, opts) list = [obj] else list = [] end - elsif plugin_ids = qs['id'] and plugin_id = plugin_ids[0] - # ?id= to search a plugin by 'id <plugin_id>' config param + elsif plugin_id = get_search_parameter(qs, '@id'.freeze) + # ?@id= to search a plugin by 'id <plugin_id>' config param if obj = @agent.plugin_info_by_id(plugin_id, opts) list = [obj] else list = [] end - elsif types = qs['type'] and type = types[0] - # ?type= to search plugins by 'type <type>' config param - list = @agent.plugins_info_by_type(type, opts) + elsif plugin_id = get_search_parameter(qs, 'id'.freeze) + # Without @ version of ?@id= for backward compatibility + if obj = @agent.plugin_info_by_id(plugin_id, opts) + list = [obj] + else + list = [] + end + elsif plugin_type = get_search_parameter(qs, '@type'.freeze) + # ?@type= to search plugins by 'type <type>' config param + list = @agent.plugins_info_by_type(plugin_type, opts) + + elsif plugin_type = get_search_parameter(qs, 'type'.freeze) + # Without @ version of ?@type= for backward compatibility + list = @agent.plugins_info_by_type(plugin_type, opts) + else # otherwise show all plugins list = @agent.plugins_info_all(opts) end return list, opts end + def get_search_parameter(qs, param_name) + return nil unless qs.has_key?(param_name) + qs[param_name].first + end + def render_json(obj, opts={}) render_json_error(200, obj, opts) end def render_json_error(code, obj, opts={}) @@ -210,17 +227,14 @@ @thread = nil end end MONITOR_INFO = { - 'plugin_id' => 'plugin_id', - 'type' => 'config["type"]', 'output_plugin' => 'is_a?(::Fluent::Output)', 'buffer_queue_length' => '@buffer.queue_size', 'buffer_total_queued_size' => '@buffer.total_queued_chunk_size', 'retry_count' => '@num_errors', - 'config' => 'config', } def all_plugins array = [] @@ -273,11 +287,11 @@ # This method returns an array because # multiple plugins could have the same type def plugins_info_by_type(type, opts={}) array = all_plugins.select {|pe| - pe.config['type'] == type rescue nil + (pe.config['@type'] == type || pe.config['type'] == type) rescue nil } array.map {|pe| get_monitor_info(pe, opts) } end @@ -290,10 +304,16 @@ # get monitor info from the plugin `pe` and return a hash object def get_monitor_info(pe, opts={}) obj = {} + # Common plugin information + obj['plugin_id'] = pe.plugin_id + obj['plugin_category'] = plugin_category(pe) + obj['type'] = pe.config['@type'] || pe.config['type'] + obj['config'] = pe.config + # run MONITOR_INFO in plugins' instance context and store the info to obj MONITOR_INFO.each_pair {|key,code| begin obj[key] = pe.instance_eval(code) rescue @@ -311,9 +331,20 @@ end obj['instance_variables'] = iv end obj + end + + def plugin_category(pe) + case pe + when Fluent::Input + 'input'.freeze + when Fluent::Output + 'output'.freeze + else + 'unknown'.freeze + end end def fluentd_opts @fluentd_opts ||= get_fluentd_opts end