# # fluent-plugin-calyptia-monitoring # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require "erb" require "optparse" require "pathname" require "fluent/plugin" require "fluent/env" require "fluent/engine" require "fluent/system_config" require "fluent/config/element" require 'fluent/version' class CalyptiaConfigGenerator def initialize(argv = ARGV) @argv = argv @api_key = nil @endpoint = nil @enable_input_metrics = true @enable_size_metrics = false @enable_get_dump = true @rpc_endpoint = "127.0.0.1:24444" @storage_agent_token_dir = default_storage_dir @fluentd_conf_path = nil @disable_rpc = false prepare_option_parser end def default_storage_dir if Fluent.windows? "C:/path/to/accesible/dir" else "/path/to/accesible/dir" end end def call parse_options! puts dump_configuration_for_calyptia end def dump_configuration_for_calyptia dumped = "" template = template_path("calyptia-conf.erb").read dumped << if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+ ERB.new(template, trim_mode: "-") else ERB.new(template, nil, "-") end.result(binding) dumped end private def prepare_option_parser @parser = OptionParser.new @parser.version = Fluent::VERSION @parser.banner = < e usage(e) end def template_path(name) (Pathname(__dir__) + "../../../templates/#{name}").realpath end end