Class: Fluent::MonitorAgentInput::MonitorServlet
- Inherits:
-
WEBrick::HTTPServlet::AbstractServlet
- Object
- WEBrick::HTTPServlet::AbstractServlet
- Fluent::MonitorAgentInput::MonitorServlet
- Defined in:
- lib/fluent/plugin/in_monitor_agent.rb
Direct Known Subclasses
ConfigMonitorServlet, JSONMonitorServlet, LTSVMonitorServlet
Instance Method Summary collapse
- #build_object(req, res) ⇒ Object
- #do_GET(req, res) ⇒ Object
- #get_search_parameter(qs, param_name) ⇒ Object
-
#initialize(server, agent) ⇒ MonitorServlet
constructor
A new instance of MonitorServlet.
- #render_json(obj, opts = {}) ⇒ Object
- #render_json_error(code, obj, opts = {}) ⇒ Object
Constructor Details
#initialize(server, agent) ⇒ MonitorServlet
Returns a new instance of MonitorServlet.
38 39 40 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 38 def initialize(server, agent) @agent = agent end |
Instance Method Details
#build_object(req, res) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# 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 |
#do_GET(req, res) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# 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 |
#get_search_parameter(qs, param_name) ⇒ Object
125 126 127 128 |
# 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 |
#render_json(obj, opts = {}) ⇒ Object
130 131 132 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 130 def render_json(obj, opts={}) render_json_error(200, obj, opts) end |
#render_json_error(code, obj, opts = {}) ⇒ Object
134 135 136 137 138 139 140 141 |
# 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 |