sensu-transport-snssqs-ng 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c92289e5673d6c1523eaff67ba2c13811d224b0b
4
+ data.tar.gz: 53a04fd08f78ec57eea0e4c07c447809bedc1641
5
+ SHA512:
6
+ metadata.gz: dcf918e8f291f21ec353df00d6dc24c76151e7a21fb9e2c12bcf4eca8d53054446439219d81fe7c3cb532b7d70d91772be59c41bd75fb70409f2e2770a8a7693
7
+ data.tar.gz: 1879be3c160435f6724390b10fc1f29cd4c38b06d0ff0c4965f176040f148d9a05f9bf6c5ce9d366290fea74284f10741c99583e449dbff3f482737c17681237
checksums.yaml.gz.sig ADDED
Binary file
@@ -0,0 +1,185 @@
1
+ require 'sensu/transport/base'
2
+ require 'aws-sdk'
3
+ require 'statsd-ruby'
4
+
5
+ module Sensu
6
+ module Transport
7
+ class SNSSQS < Sensu::Transport::Base
8
+ attr_accessor :logger
9
+
10
+ STRING_STR = "String".freeze
11
+ KEEPALIVES_STR = "keepalives".freeze
12
+ PIPE_STR = "pipe".freeze
13
+ TYPE_STR = "type".freeze
14
+
15
+ def initialize
16
+ @connected = false
17
+ @subscribing = false
18
+
19
+ # as of sensu 0.23.0 we need to call succeed when we have
20
+ # successfully connected to SQS.
21
+ #
22
+ # we already have our own logic to maintain the connection to
23
+ # SQS, so we can always say we're connected.
24
+ #
25
+ # See:
26
+ # https://github.com/sensu/sensu/blob/cdc25b29169ef2dcd2e056416eab0e83dbe000bb/CHANGELOG.md#0230---2016-04-04
27
+ succeed()
28
+ end
29
+
30
+ def connected?; @connected; end
31
+
32
+ def connect(settings)
33
+ @settings = settings
34
+ @connected = true
35
+ @results_callback = proc {}
36
+ @keepalives_callback = proc {}
37
+ # Sensu Windows install does not include a valid cert bundle for AWS
38
+ Aws.use_bundled_cert! if Gem.win_platform?
39
+ @sqs = Aws::SQS::Client.new(region: @settings[:region])
40
+ @sns = Aws::SNS::Client.new(region: @settings[:region])
41
+
42
+ # connect to statsd, if necessary
43
+ @statsd = nil
44
+ if !@settings[:statsd_addr].nil? and @settings[:statsd_addr] != ""
45
+ pieces = @settings[:statsd_addr].split(':')
46
+ @statsd = Statsd.new(pieces[0], pieces[1].to_i).tap { |sd|
47
+ sd.namespace = @settings[:statsd_namespace]
48
+ }
49
+ @statsd_sample_rate = @settings[:statsd_sample_rate].to_f
50
+ end
51
+ end
52
+
53
+ def statsd_incr(stat)
54
+ @statsd.increment(stat, @statsd_sample_rate) unless @statsd.nil?
55
+ end
56
+
57
+ def statsd_time(stat)
58
+ # always measure + run the block, but only if @statsd is set
59
+ # do we actually report it.
60
+ start = Time.now
61
+ result = yield
62
+ if !@statsd.nil?
63
+ @statsd.timing(stat, ((Time.now - start) * 1000).round(5), @statsd_sample_rate)
64
+ end
65
+ result
66
+ end
67
+
68
+ # subscribe will begin "subscribing" to the consuming sqs queue.
69
+ #
70
+ # This method is intended for use by the Sensu server; fanout
71
+ # subscriptions initiated by the Sensu client process are
72
+ # treated as a no-op.
73
+ #
74
+ # What this really means is that we will start polling for
75
+ # messages from the SQS queue, and, depending on the message
76
+ # type, it will call the appropriate callback.
77
+ #
78
+ # This assumes that the SQS Queue is consuming "Raw" messages
79
+ # from SNS.
80
+ #
81
+ # "subscribing" means that the "callback" parameter will be
82
+ # called when there is a message for you to consume.
83
+ #
84
+ # "funnel" and "type" parameters are completely ignored.
85
+ def subscribe(type, pipe, funnel = nil, options = {}, &callback)
86
+ if type == :fanout
87
+ self.logger.debug("skipping unsupported fanout subscription type=#{type}, pipe=#{pipe}, funnel=#{funnel}")
88
+ return
89
+ end
90
+
91
+ self.logger.info("subscribing to type=#{type}, pipe=#{pipe}, funnel=#{funnel}")
92
+
93
+ if pipe == KEEPALIVES_STR
94
+ @keepalives_callback = callback
95
+ else
96
+ @results_callback = callback
97
+ end
98
+
99
+ unless @subscribing
100
+ do_all_the_time {
101
+ EM::Iterator.new(receive_messages, 10).each do |msg, iter|
102
+ statsd_time("sqs.#{@settings[:consuming_sqs_queue_url]}.process_timing") {
103
+ if msg.message_attributes[PIPE_STR].string_value == KEEPALIVES_STR
104
+ @keepalives_callback.call(msg, msg.body)
105
+ else
106
+ @results_callback.call(msg, msg.body)
107
+ end
108
+ }
109
+ iter.next
110
+ end
111
+ }
112
+ @subscribing = true
113
+ end
114
+ end
115
+
116
+ # acknowledge will delete the given message from the SQS queue.
117
+ def acknowledge(info, &callback)
118
+ EM.defer {
119
+ @sqs.delete_message(
120
+ queue_url: @settings[:consuming_sqs_queue_url],
121
+ receipt_handle: info.receipt_handle,
122
+ )
123
+ statsd_incr("sqs.#{@settings[:consuming_sqs_queue_url]}.message.deleted")
124
+ callback.call(info) if callback
125
+ }
126
+ end
127
+
128
+ # publish publishes a message to the SNS topic.
129
+ #
130
+ # The type, pipe, and options are transformed into SNS message
131
+ # attributes and included with the message.
132
+ def publish(type, pipe, message, options = {}, &callback)
133
+ attributes = {
134
+ TYPE_STR => str_attr(type),
135
+ PIPE_STR => str_attr(pipe)
136
+ }
137
+ options.each do |k, v|
138
+ attributes[k.to_s] = str_attr(v.to_s)
139
+ end
140
+ EM.defer { send_message(message, attributes, &callback) }
141
+ end
142
+
143
+ private
144
+
145
+ def str_attr(str)
146
+ { :data_type => STRING_STR, :string_value => str }
147
+ end
148
+
149
+ def do_all_the_time(&blk)
150
+ callback = proc {
151
+ do_all_the_time(&blk)
152
+ }
153
+ EM.defer(blk, callback)
154
+ end
155
+
156
+ def send_message(msg, attributes, &callback)
157
+ resp = @sns.publish(
158
+ target_arn: @settings[:publishing_sns_topic_arn],
159
+ message: msg,
160
+ message_attributes: attributes
161
+ )
162
+ statsd_incr("sns.#{@settings[:publishing_sns_topic_arn]}.message.published")
163
+ callback.call({ :response => resp }) if callback
164
+ end
165
+
166
+ PIPE_ARR = [PIPE_STR]
167
+
168
+ # receive_messages returns an array of SQS messages
169
+ # for the consuming queue
170
+ def receive_messages
171
+ begin
172
+ resp = @sqs.receive_message(
173
+ message_attribute_names: PIPE_ARR,
174
+ queue_url: @settings[:consuming_sqs_queue_url],
175
+ wait_time_seconds: @settings[:wait_time_seconds],
176
+ max_number_of_messages: @settings[:max_number_of_messages],
177
+ )
178
+ resp.messages
179
+ rescue Aws::SQS::Errors::ServiceError => e
180
+ self.logger.info(e)
181
+ end
182
+ end
183
+ end
184
+ end
185
+ end
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu-transport-snssqs-ng
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Troy Ready
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDjjCCAnagAwIBAgIBATANBgkqhkiG9w0BAQUFADBGMRgwFgYDVQQDDA90cm95
14
+ LnJlYWR5X2dlbXMxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixk
15
+ ARkWA2NvbTAeFw0xNjExMDgyMzMzMjlaFw0xNzExMDgyMzMzMjlaMEYxGDAWBgNV
16
+ BAMMD3Ryb3kucmVhZHlfZ2VtczEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYK
17
+ CZImiZPyLGQBGRYDY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
18
+ 4HhKJwPlVHMlOaxmv2FBaS/M8u/9mN2v5WWsv0+6P934jzDIYBBKE6oW5eFUg6vM
19
+ wpWOaF4O4mwCRoOCvfGuhg2ufVnDYh3GPIWqE1ziIBx/Y3D5VIQSnAvP4/6yDMuS
20
+ kKTHi3/fJcs/vOs9JiuTb7zkb53TFLlR/g2lX6I8vy0HowJcMYZzKLhEUnnIPG7a
21
+ DPD5Qy67p8rIy/T6AsSCCPdn+mpg1jLHsTsj6DdQxPyM9rtNZRRGvBluZNa4QxYv
22
+ PMj3dSRlO9eEKHayrY24pcOZqus8eyPE64bbOeR6yj34vRMJ2eeu+Pq/YzRxlqmf
23
+ 1dtR7Nm3Uxhmw1/PLWi8eQIDAQABo4GGMIGDMAkGA1UdEwQCMAAwCwYDVR0PBAQD
24
+ AgSwMB0GA1UdDgQWBBTX6fBjssJCph8JWQd+lF31ZWtkLTAkBgNVHREEHTAbgRl0
25
+ cm95LnJlYWR5K2dlbXNAZ21haWwuY29tMCQGA1UdEgQdMBuBGXRyb3kucmVhZHkr
26
+ Z2Vtc0BnbWFpbC5jb20wDQYJKoZIhvcNAQEFBQADggEBADMf8GNVKPmUTX8iirDp
27
+ p4FJtZ5pv614QBSoxutDMTVRPUGluN9dZ/oUNTBvByrm4CJI4vMbZhfIs07L8YdG
28
+ D/u5A5nXD9qlKIi9CtYHIekjsetool2s4tCMTyvNO4CfV/dALT0Vdc3gXIPeC8YZ
29
+ lIT+5GzwvlSX+TXYUq/Q4lDLQHU28j2nC4yFl5rej5akZCjiurJWE8A9P/AiHkgc
30
+ ZHJ4XyeURdy0oA6kjiWzYf4puRodQTDQ2W4uis7aHSkqVrw/SCW5YgFZkEBh72KY
31
+ SDfvq2xI1v+iTmBkyYqft23MKnTcc5jJ5Gh0a11a2zUstWaH1XHelXYCx44ZLCtC
32
+ Q6k=
33
+ -----END CERTIFICATE-----
34
+ date: 2016-11-08 00:00:00.000000000 Z
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: aws-sdk
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ - !ruby/object:Gem::Dependency
51
+ name: eventmachine
52
+ requirement: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ - !ruby/object:Gem::Dependency
65
+ name: statsd-ruby
66
+ requirement: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description:
79
+ email: troy.ready+gems@gmail.com
80
+ executables: []
81
+ extensions: []
82
+ extra_rdoc_files: []
83
+ files:
84
+ - lib/sensu/transport/snssqs.rb
85
+ homepage: https://github.com/troyready/sensu-transport-snssqs-ng
86
+ licenses:
87
+ - Apache-2.0
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.6.7
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Sensu transport over Amazon SNS & SQS
109
+ test_files: []
metadata.gz.sig ADDED
@@ -0,0 +1 @@
1
+ �c7�\JCl�;�rd�/9��f���`M5C�VA��m�I�� ������"f�e(!�-7O��3��Wl��}`�R������]Ffa�O~F�2�{r�njJ!X�`�)Q!*��Wڃ�7�:���P��I�A[�Pxh�p� �xnO�^A�3Uֹ��l��{��eh�,c�o���׿)�C����)��-�  �@B��̄2*�"lH=?��Ո�������v�����1Z7G�'Y[�q!i���Ts��p