# # Copyright 2022- MahithaB # # 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 "fluent/plugin/output" require_relative 'newrelic_metrics_sender' require_relative 'datadog_metrics_sender' module Fluent module Plugin class JfrogSendMetricsOutput < Fluent::Plugin::Output Fluent::Plugin.register_output("jfrog_send_metrics", self) helpers :timer # `config_param` defines a parameter. # You can refer to a parameter like an instance variable e.g. @port. # `:default` means that the parameter is optional. config_param :target_platform, :string, default: '' config_param :apikey, :string, default: '' config_param :url, :string, default: 'https://metric-api.newrelic.com/metric/v1' config_param :ddtags, :array, default: [] config_param :http_proxy, :string, :default => nil # `configure` is called before `start`. # 'conf' is a `Hash` that includes the configuration parameters. # If the configuration is invalid, raise `Fluent::ConfigError`. def configure(conf) super raise Fluent::ConfigError, 'Must define the vendor to use for getting the metrics.' if @target_platform == '' raise Fluent::ConfigError, 'Must define the apikey to use for authentication.' if @apikey == '' end def process(tag, es) es.each do |time, record| if @target_platform == 'NEWRELIC' vendor = NewRelicMetrics.new(@apikey, @url) vendor.send_metrics(record, @http_proxy) elsif @target_platform == 'DATADOG' vendor = DatadogMetrics.new(@apikey, @url) vendor.send_metrics(@ddtags, record, @http_proxy) end end end end end end