Class: Fluent::AzureLogAnalyticsOutput
- Inherits:
-
BufferedOutput
- Object
- BufferedOutput
- Fluent::AzureLogAnalyticsOutput
- Defined in:
- lib/fluent/plugin/out_azure-loganalytics.rb
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #format(tag, time, record) ⇒ Object
-
#initialize ⇒ AzureLogAnalyticsOutput
constructor
A new instance of AzureLogAnalyticsOutput.
- #shutdown ⇒ Object
- #start ⇒ Object
- #write(chunk) ⇒ Object
Constructor Details
#initialize ⇒ AzureLogAnalyticsOutput
Returns a new instance of AzureLogAnalyticsOutput.
7 8 9 10 11 12 |
# File 'lib/fluent/plugin/out_azure-loganalytics.rb', line 7 def initialize super require 'msgpack' require 'time' require "azure/loganalytics/datacollectorapi/client" end |
Instance Method Details
#configure(conf) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/fluent/plugin/out_azure-loganalytics.rb', line 33 def configure(conf) super raise ConfigError, 'no customer_id' if @customer_id.empty? raise ConfigError, 'no shared_key' if @shared_key.empty? raise ConfigError, 'no log_type' if @log_type.empty? if @add_time_field and @time_field_name.empty? raise ConfigError, 'time_field_name must be set if add_time_field is true' end if @add_tag_field and @tag_field_name.empty? raise ConfigError, 'tag_field_name must be set if add_tag_field is true' end @timef = TimeFormatter.new(@time_format, @localtime) end |
#format(tag, time, record) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/fluent/plugin/out_azure-loganalytics.rb', line 58 def format(tag, time, record) if @add_time_field record[@time_field_name] = @timef.format(time) end if @add_tag_field record[@tag_field_name] = tag end record.to_msgpack end |
#shutdown ⇒ Object
53 54 55 56 |
# File 'lib/fluent/plugin/out_azure-loganalytics.rb', line 53 def shutdown super # destroy end |
#start ⇒ Object
47 48 49 50 51 |
# File 'lib/fluent/plugin/out_azure-loganalytics.rb', line 47 def start super # start @client=Azure::Loganalytics::Datacollectorapi::Client::new(@customer_id,@shared_key) end |
#write(chunk) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/fluent/plugin/out_azure-loganalytics.rb', line 68 def write(chunk) records = [] chunk.msgpack_each { |record| records.push(record) } begin res = @client.post_data(@log_type, records) if not Azure::Loganalytics::Datacollectorapi::Client.is_success(res) $log.fatal "DataCollector API request failure: error code: " + "#{res.code}, data=>" + records.to_json end rescue Exception => ex $log.fatal "Exception occured in posting to DataCollector API: " + "'#{ex}', data=>" + records.to_json end end |