Class: Fluent::Plugin::MonitorAgentInput::MonitorServlet
- Inherits:
-
WEBrick::HTTPServlet::AbstractServlet
- Object
- WEBrick::HTTPServlet::AbstractServlet
- Fluent::Plugin::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.
41 42 43 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 41 def initialize(server, agent) @agent = agent end |
Instance Method Details
#build_object(req, res) ⇒ Object
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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 64 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 = {with_config: @agent.include_config, with_retry: @agent.include_retry} if s = qs['debug'] and s[0] opts[:with_debug_info] = true opts[:pretty_json] = true end if ivars = (qs['with_ivars'] || []).first opts[:ivars] = ivars.split(',') end if with_config = get_search_parameter(qs, 'with_config'.freeze) opts[:with_config] = Fluent::Config.bool_value(with_config) end if with_retry = get_search_parameter(qs, 'with_retry'.freeze) opts[:with_retry] = Fluent::Config.bool_value(with_retry) 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
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 45 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
140 141 142 143 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 140 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
145 146 147 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 145 def render_json(obj, opts={}) render_json_error(200, obj, opts) end |
#render_json_error(code, obj, opts = {}) ⇒ Object
149 150 151 152 153 154 155 156 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 149 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 |