# File lib/fluent/plugin/in_monitor_agent.rb, line 38 def initialize(server, agent) @agent = agent end
# File lib/fluent/plugin/in_monitor_agent.rb, line 61 def build_object(req, res) unless req.path_info == "" return render_json_error(404, "Not found") end # parse ?=query string if req.query_string begin qs = CGI.parse(req.query_string) rescue return render_json_error(400, "Invalid query string") end else qs = Hash.new {|h,k| [] } end # if ?debug=1 is set, set :with_debug_info for get_monitor_info # and :pretty_json for render_json_error opts = {} if s = qs['debug'] and s[0] opts[:with_debug_info] = true opts[:pretty_json] = true end 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_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 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
# File lib/fluent/plugin/in_monitor_agent.rb, line 42 def do_GET(req, res) begin code, header, body = process(req, res) rescue code, header, body = render_json_error(500, { 'message '=> 'Internal Server Error', 'error' => "#{$!}", 'backgrace'=> $!.backtrace, }) end # set response code, header and body res.status = code header.each_pair {|k,v| res[k] = v } res.body = body end
# File lib/fluent/plugin/in_monitor_agent.rb, line 125 def get_search_parameter(qs, param_name) return nil unless qs.has_key?(param_name) qs[param_name].first end
# File lib/fluent/plugin/in_monitor_agent.rb, line 130 def render_json(obj, opts={}) render_json_error(200, obj, opts) end
# File lib/fluent/plugin/in_monitor_agent.rb, line 134 def render_json_error(code, obj, opts={}) if opts[:pretty_json] js = JSON.pretty_generate(obj) else js = obj.to_json end [code, {'Content-Type'=>'application/json'}, js] end