Class: LogStash::Outputs::Sns

Inherits:
Base
  • Object
show all
Includes:
PluginMixins::AwsConfig::V2
Defined in:
lib/logstash/outputs/sns.rb

Overview

SNS output.

Send events to Amazon’s Simple Notification Service, a hosted pub/sub framework. It supports various subscription types, including email, HTTP/S, SMS, and SQS.

For further documentation about the service see:

http://docs.amazonwebservices.com/sns/latest/api/

This plugin looks for the following fields on events it receives:

* `sns` - If no ARN is found in the configuration file, this will be used as
the ARN to publish.
* `sns_subject` - The subject line that should be used.
Optional. The "%{host}" will be used if `sns_subject` is not present. The subject
will be truncated to 100 characters. If `sns_subject` is set to a non-string value a JSON version of that value will be saved.
* `sns_message` - Optional string of message to be sent. If this is set to a non-string value it will be encoded with the specified `codec`. If this is not set the entire event will be encoded with the codec.
with the @message truncated so that the length of the JSON fits in
`32768` bytes.

Upgrading to 2.0.0

This plugin used to have a ‘format` option for controlling the encoding of messages prior to being sent to SNS. This plugin now uses the logstash standard <<codec,codec>> option for encoding instead. If you want the same ’plain’ format as the v0/1 codec (‘format => “plain”`) use `codec => “s3_plain”`.

Constant Summary collapse

MAX_SUBJECT_SIZE_IN_CHARACTERS =
100
MAX_MESSAGE_SIZE_IN_BYTES =
32768
NO_SUBJECT =
"NO SUBJECT"

Instance Method Summary collapse

Instance Method Details

#receive(event) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/logstash/outputs/sns.rb', line 71

def receive(event)
  

  if (sns_msg = event.get("sns_message"))
    if sns_msg.is_a?(String)
      send_sns_message(event_arn(event), event_subject(event), sns_msg)
    else
      @codec.encode(sns_msg)
    end
  else
    @codec.encode(event)
  end
end

#registerObject



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/logstash/outputs/sns.rb', line 58

def register
  require "aws-sdk-resources"

  @sns = Aws::SNS::Client.new(aws_options_hash)

  publish_boot_message_arn()

  @codec.on_event do |event, encoded|
    send_sns_message(event_arn(event), event_subject(event), encoded)
  end
end