class LogStash::Outputs::Application_insights::Notification
Public Class Methods
new( tuple )
click to toggle source
Calls superclass method
LogStash::Outputs::Application_insights::Blob::new
# File lib/logstash/outputs/application_insights/notification.rb, line 24 def initialize ( tuple ) # super first parameter must be nil. blob first parameter is channel, otherwise it will pass storage_account_name as channel super( tuple ) end
Public Instance Methods
notify()
click to toggle source
must return whether notification was successful or failed
# File lib/logstash/outputs/application_insights/notification.rb, line 30 def notify @action = :notify @recoverable = [ :notify_failed_blob_not_accessible, :io_failure, :service_unavailable, :notification_process_down ] @force_client = true # to enable get a client even if all storage_accounts marked dead @info = "#{@action} #{@storage_account_name}/#{@container_name}/#{@blob_name}, events: #{@uploaded_events_count}, size: #{@uploaded_bytesize}, blocks: #{@uploaded_block_numbers}, delay: #{Time.now.utc - @oldest_event_time}" success = storage_io_block { submit } if success Telemetry.instance.track_event { { :name => "notified", :properties => context_to_table_entity } } state_table_update else notify_retry_later end success end
Private Instance Methods
create_payload()
click to toggle source
# File lib/logstash/outputs/application_insights/notification.rb, line 70 def create_payload notification_hash = { :data => { :baseType => DATA_BASE_TYPE, :baseData => { :ver => BASE_DATA_REQUIRED_VERSION, :blobSasUri => @blob_sas_url.to_s, :sourceName => @table_id, :sourceVersion => @configuration[:notification_version].to_s } }, :ver => @configuration[:notification_version], :name => REQUEST_NAME, :time => Time.now.utc.iso8601, :iKey => @instrumentation_key } notification_hash.to_json end
notify_retry_later()
click to toggle source
# File lib/logstash/outputs/application_insights/notification.rb, line 99 def notify_retry_later if :notify_failed_blob_not_accessible == @recovery @sub_state = @recovery @storage_recovery.recover_later( context_to_tuple, :notify, @storage_account_name ) elsif :invalid_instrumentation_key == @recovery || :invalid_table_id == @recovery @sub_state = @recovery Channels.instance.channel( @instrumentation_key, @table_id ).recover_later_notification( context_to_tuple ) else if :notify_failed_blob_not_accessible == @sub_state @storage_recovery.recover_later( context_to_tuple, :notify, @storage_account_name ) elsif :invalid_instrumentation_key == @sub_state || :invalid_table_id == @sub_state Channels.instance.channel( @instrumentation_key, @table_id ).recover_later_notification( context_to_tuple ) else @notification_recovery.recover_later( context_to_tuple ) end end end
post_notification( http_client, body )
click to toggle source
# File lib/logstash/outputs/application_insights/notification.rb, line 90 def post_notification ( http_client, body ) request = Azure::Core::Http::HttpRequest.new( :post, @configuration[:application_insights_endpoint], { :body => body, :client => http_client } ) request.headers['Content-Type'] = 'application/json; charset=utf-8' request.headers['Accept'] = 'application/json' @logger.debug { "send notification : \n endpoint: #{@configuration[:application_insights_endpoint]}\n body : #{body}" } response = request.call end
set_blob_sas_url()
click to toggle source
# File lib/logstash/outputs/application_insights/notification.rb, line 60 def set_blob_sas_url blob_url ="https://#{@storage_account_name}.blob.#{@configuration[:azure_storage_host_suffix]}/#{@container_name}/#{@blob_name}" options_and_constrains = {:permissions => "r", :resource => "b", :expiry => ( Time.now.utc + @configuration[:blob_access_expiry_time] ).iso8601 } # breaking change after azure-storage 0.10.1 # @blob_sas_url = @client.storage_auth_sas.signed_uri( URI( blob_url ), options_and_constrains ) use_account_sas = false @blob_sas_url = @client.storage_auth_sas.signed_uri( URI( blob_url ), use_account_sas, options_and_constrains ) end
submit()
click to toggle source
# File lib/logstash/outputs/application_insights/notification.rb, line 47 def submit set_blob_sas_url @logger.debug { "blob_sas_url: #{@blob_sas_url}" } payload = create_payload @logger.debug { "notification payload: #{payload}" } # assume that exceptions can be raised due to this method: post_notification( @client.notifyClient, payload ) unless @configuration[:disable_notification] @log_state = :notified end