sensu-plugins-aws 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 952cc6ac4588a8609b48d4aee965beb1bbc756bb
4
- data.tar.gz: 54466ee9bf3f405efdcb215498f3111b4f6ec099
3
+ metadata.gz: d1510edf78fde0477592736fb6a25174068aea6f
4
+ data.tar.gz: 3230a421cb5f4f07c7c8697b68500e9de59a480e
5
5
  SHA512:
6
- metadata.gz: 14cfd437258092ca503dab2ed8bbcb97472846184116354cf0cce2919f264d6b45bcb339b72b5ee5ed704ed0092d026550a647b42eea74b3175136f5d43c2ca4
7
- data.tar.gz: 0759bf875abeefdb0629066e460a81c8d02c4d8980cbf72fc0e9180a4fe86950c9b1d58045fcd85229fc3e8f060f95ca46d66173dcbe9a944afdfe730861e464
6
+ metadata.gz: ad8f2bbd6f05d6333383f53d8c0ab50922fad826c73e83c308042bf308c96eaa64f8b9effd80522a28922d201535ef2e0824d70ddfa6220dd8027ce7d2edcb6c
7
+ data.tar.gz: a47164e6147c093b74ac78d41df199ad1cfed09a7643e6e255647cb8c869f6a25b2175103caf96226955c0b2f90422aae7c0c40f34a328a242b7bfb0977a887b
Binary file
data.tar.gz.sig CHANGED
@@ -1,4 +1 @@
1
- %>l{3��EOHD�:�o����QfЦ�j�ZTܝ��q@.�Ibt�#����/����If��CS����1�D<0w!L`�gXM���T�W�hu�����Ow�#�]���
2
- E�0M�G�
3
- �3]�Rk���x�] �2��# ���@+b���ҧ�k����KmI.�Gr�O��R�ЏD�
4
- h}�ʺۇ>�
1
+ �Ɋ;��GN���� *u\V�r�����q�9zq���0� T_ 5�m R��`�`=� %�N�;��Eb��s_���&�"K5�W�,����<�c�]��g��&��^�,�e 1��ٗ� ��� g8���N/Hو1<_�a��m0��c�ؗy%|˫~Uk,��;�SD~J����9k8�qҍ"
@@ -3,6 +3,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).
3
3
 
4
4
  This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
5
5
 
6
+ ## [1.1.0] - 2015-07-24
7
+ ### Added
8
+ - Added new AWS SES handler - handler-ses.rb
9
+ - Add metrics-ec2-filter to store node ids and count matching a given filter
10
+ - Check to alert on unlisted EIPs
11
+
6
12
  ## [1.0.0] - 2015-07-22
7
13
 
8
14
  WARNING: This release contains major breaking changes that will impact all users. The flags used for access key and secret key have been standardized accross all plugins resulting in changed flags for the majority of plugins. The new flags are -a AWS_ACCESS_KEY and -k AWS_SECRET_KEY.
data/README.md CHANGED
@@ -19,6 +19,8 @@
19
19
 
20
20
  **check-ec2-network.rb**
21
21
 
22
+ **check-eip-allocation.rb**
23
+
22
24
  **check-elb-certs.rb**
23
25
 
24
26
  **check-elb-health-fog.rb**
@@ -49,12 +51,16 @@
49
51
 
50
52
  **handler-ec2_node.rb**
51
53
 
54
+ **handler-ses.rb**
55
+
52
56
  **handler-sns.rb**
53
57
 
54
58
  **metrics-autoscaling-instance-count.rb**
55
59
 
56
60
  **metrics-ec2-count.rb**
57
61
 
62
+ **metrics-ec2-filter.rb**
63
+
58
64
  **metrics-elasticache.rb**
59
65
 
60
66
  **metrics-elb-full.rb**
@@ -63,6 +69,7 @@
63
69
 
64
70
  **metrics-sqs.rb**
65
71
 
72
+
66
73
  ## Files
67
74
 
68
75
  * /bin/check-autoscaling-cpucredits.rb
@@ -85,9 +92,11 @@
85
92
  * /bin/check-sqs-messages.rb
86
93
  * /bin/check_vpc_vpn.py
87
94
  * /bin/handler-ec2_node.rb
95
+ * /bin/handler-ses.rb
88
96
  * /bin/handler-sns.rb
89
97
  * /bin/metrics-autoscaling-instance-count.rb
90
98
  * /bin/metrics-ec2-count.rb
99
+ * /bin/metrics-ec2-filter.rb
91
100
  * /bin/metrics-elasticache.rb
92
101
  * /bin/metrics-elb-full.rb
93
102
  * /bin/metrics-elb.rb
@@ -95,19 +104,36 @@
95
104
 
96
105
  ## Usage
97
106
 
107
+ **handler-ses**
108
+ ```
109
+ {
110
+ "ses": {
111
+ "mail_from": "sensu@example.com",
112
+ "mail_to": "monitor@example.com",
113
+ "use_ami_role": true,
114
+ "access_key": "myaccesskey",
115
+ "secret_key": "mysecretkey",
116
+ "region": "us-east-1",
117
+ "subscriptions": {
118
+ "subscription_name": {
119
+ "mail_to": "teamemail@example.com"
120
+ }
121
+ }
122
+ }
123
+ }
124
+ ```
125
+
98
126
  **handler-sns**
99
127
  ```
100
128
  {
101
129
  "sns": {
102
- "topic_arn": "arn:aws:sns:us-east-1:111111111111:topic"
103
- ,"use_ami_role": true
104
- ,"access_key": "MY_KEY"
105
- ,"secret_key": "MY_secret"
130
+ "topic_arn": "arn:aws:sns:us-east-1:111111111111:topic",
131
+ "use_ami_role": true,
132
+ "access_key": "MY_KEY",
133
+ "secret_key": "MY_secret"
106
134
  }
107
135
  }
108
136
  ```
109
137
  ## Installation
110
138
 
111
139
  [Installation and Setup](https://github.com/sensu-plugins/documentation/blob/master/user_docs/installation_instructions.md)
112
-
113
- ## Notes
@@ -0,0 +1,64 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-ebs-snapshots
4
+ #
5
+ # DESCRIPTION:
6
+ # Alert on new eip allocations
7
+ #
8
+ # OUTPUT:
9
+ # plain-text
10
+ #
11
+ # PLATFORMS:
12
+ # Linux
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: aws-sdk
16
+ # gem: sensu-plugin
17
+ #
18
+ # USAGE:
19
+ # ./check-eip-allocation.rb -r ${you_region} -e ${eips_allowed}
20
+ #
21
+ # NOTES:
22
+ #
23
+ # LICENSE:
24
+ # Shane Starcher <shane.starcher@gmail.com>
25
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
26
+ # for details.
27
+ #
28
+
29
+ require 'sensu-plugin/check/cli'
30
+ require 'sensu-plugins-aws'
31
+ require 'aws-sdk'
32
+
33
+ class CheckEipAllocation < Sensu::Plugin::Check::CLI
34
+ include Common
35
+ option :eips_allowed,
36
+ short: '-e EIPS_ALLOWED',
37
+ long: '--eips_allowed eip1,eip2',
38
+ required: true,
39
+ description: 'List of EIPs that are allowed to exist. Comma seperated.'
40
+
41
+ option :aws_region,
42
+ short: '-r R',
43
+ long: '--region REGION',
44
+ description: 'AWS region',
45
+ default: 'us-east-1'
46
+
47
+ def run
48
+ errors = []
49
+ ec2 = Aws::EC2::Client.new
50
+
51
+ eips = ec2.describe_addresses
52
+ eips[:addresses].each do |eip|
53
+ unless config[:eips_allowed].include? eip.public_ip
54
+ errors << eip.public_ip
55
+ end
56
+ end
57
+
58
+ if errors.empty?
59
+ ok
60
+ else
61
+ warning errors.join("\n")
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ #
4
+ # This handler formats alerts as mails and sends them off to a pre-defined recipient.
5
+ #
6
+ # Requires the aws-sdk gem.
7
+ #
8
+ # Setting required in ses.json
9
+ #
10
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
11
+ # for details.
12
+
13
+ require 'sensu-handler'
14
+ require 'aws-sdk-v1'
15
+
16
+ class SESNotifier < Sensu::Handler
17
+ def event_name
18
+ @event['client']['name'] + '/' + @event['check']['name']
19
+ end
20
+
21
+ def action_to_string
22
+ @event['action'].eql?('resolve') ? 'RESOLVED' : 'ALERT'
23
+ end
24
+
25
+ def status_to_string
26
+ case @event['check']['status']
27
+ when 0
28
+ 'OK'
29
+ when 1
30
+ 'WARNING'
31
+ when 2
32
+ 'CRITICAL'
33
+ else
34
+ 'UNKNOWN'
35
+ end
36
+ end
37
+
38
+ def mail_from
39
+ settings['ses']['mail_from'] || ''
40
+ end
41
+
42
+ def build_mail_to_list
43
+ json_config = config[:json_config] || 'ses'
44
+ mail_to = @event['client']['mail_to'] || settings[json_config]['mail_to']
45
+ if settings[json_config].key?('subscriptions')
46
+ @event['check']['subscribers'].each do |sub|
47
+ if settings[json_config]['subscriptions'].key?(sub)
48
+ mail_to << ", #{settings[json_config]['subscriptions'][sub]['mail_to']}"
49
+ end
50
+ end
51
+ end
52
+ mail_to
53
+ end
54
+
55
+ def use_ami_role
56
+ use_ami_role = settings['ses']['use_ami_role']
57
+ use_ami_role.nil? ? true : use_ami_role
58
+ end
59
+
60
+ def aws_access_key
61
+ settings['ses']['access_key'] || ''
62
+ end
63
+
64
+ def aws_access_secret
65
+ settings['ses']['secret_key'] || ''
66
+ end
67
+
68
+ def region
69
+ settings['ses']['region'] || 'us-east-1'
70
+ end
71
+
72
+ def handle
73
+ mail_to = build_mail_to_list
74
+ body = <<-BODY.gsub(/^ {14}/, '')
75
+ #{@event['check']['output']}
76
+ Host: #{@event['client']['name']}
77
+ Timestamp: #{Time.at(@event['check']['issued'])}
78
+ Address: #{@event['client']['address']}
79
+ Check Name: #{@event['check']['name']}
80
+ Command: #{@event['check']['command']}
81
+ Status: #{@event['check']['status']}
82
+ Occurrences: #{@event['occurrences']}
83
+ BODY
84
+
85
+ if @event['check']['notification'].nil?
86
+ subject = "#{action_to_string} - #{event_name}: #{status_to_string}"
87
+ else
88
+ subject = "#{action_to_string} - #{event_name}: #{@event['check']['notification']}"
89
+ end
90
+
91
+ if use_ami_role
92
+ AWS.config(region: region)
93
+ else
94
+ AWS.config(access_key_id: aws_access_key,
95
+ secret_access_key: aws_access_secret,
96
+ region: region)
97
+ end
98
+
99
+ ses = AWS::SimpleEmailService.new
100
+
101
+ begin
102
+ timeout 10 do
103
+ ses.send_email(
104
+ subject: subject,
105
+ from: mail_from,
106
+ to: [mail_to.split(',')],
107
+ body_text: body
108
+ )
109
+
110
+ puts 'mail -- sent alert for ' + event_name + ' to ' + mail_to.to_s
111
+ end
112
+ rescue Timeout::Error
113
+ puts 'mail -- timed out while attempting to ' + @event['action'] + ' an incident -- ' + event_name
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,130 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # metrics-ec2-filter
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin retrieves EC2 instances matching a given filter
7
+ #
8
+ # OUTPUT:
9
+ # plain-text
10
+ #
11
+ # PLATFORMS:
12
+ # Linux
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: aws-sdk
16
+ # gem: sensu-plugin
17
+ #
18
+ # USAGE:
19
+ # ./metrics-ec2-filter.rb -f "{name:tag-value,values:[infrastructure]}"
20
+ # ./metrics-ec2-filter.rb -f "{name:tag-value,values:[infrastructure]} {name:instance-state-name,values:[running]}"
21
+ #
22
+ # NOTES:
23
+ #
24
+ # LICENSE:
25
+ # Justin McCarty
26
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
27
+ # for details.
28
+ #
29
+
30
+ require 'sensu-plugin/metric/cli'
31
+ require 'aws-sdk'
32
+
33
+ class EC2Filter < Sensu::Plugin::Metric::CLI::Graphite
34
+ option :aws_access_key,
35
+ short: '-a AWS_ACCESS_KEY',
36
+ long: '--aws-access-key AWS_ACCESS_KEY',
37
+ description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY'] or provide it as an option",
38
+ default: ENV['AWS_ACCESS_KEY']
39
+
40
+ option :aws_secret_access_key,
41
+ short: '-k AWS_SECRET_KEY',
42
+ long: '--aws-secret-access-key AWS_SECRET_KEY',
43
+ description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_KEY'] or provide it as an option",
44
+ default: ENV['AWS_SECRET_KEY']
45
+
46
+ option :aws_region,
47
+ short: '-r AWS_REGION',
48
+ long: '--aws-region REGION',
49
+ description: 'AWS Region (defaults to us-east-1).',
50
+ default: 'us-east-1'
51
+
52
+ option :name,
53
+ description: 'Filter naming scheme, text to prepend to metric',
54
+ short: '-n NAME',
55
+ long: '--name NAME',
56
+ default: ''
57
+
58
+ option :filter,
59
+ short: '-f FILTER',
60
+ long: '--filter FILTER',
61
+ description: 'String representation of the filter to apply',
62
+ default: '{}'
63
+
64
+ option :scheme,
65
+ description: 'Metric naming scheme, text to prepend to metric',
66
+ short: '-s SCHEME',
67
+ long: '--scheme SCHEME',
68
+ default: 'sensu.aws.ec2'
69
+
70
+ def aws_config
71
+ { access_key_id: config[:aws_access_key],
72
+ secret_access_key: config[:aws_secret_access_key],
73
+ region: config[:aws_region]
74
+ }
75
+ end
76
+
77
+ def convert_filter(input)
78
+ filter = []
79
+ items = input.scan(/{.*?}/)
80
+
81
+ items.each do |item|
82
+ if item.strip.empty?
83
+ fail 'Invalid filter syntax'
84
+ end
85
+
86
+ entry = {}
87
+ name = item.scan(/name:(.*?),/)
88
+ value = item.scan(/values:\[(.*?)\]/)
89
+
90
+ if name.nil? || name.empty? || value.nil? || value.empty?
91
+ fail 'Unable to parse filter entry'
92
+ end
93
+
94
+ entry[:name] = name[0][0].strip
95
+ entry[:values] = value[0][0].split(',')
96
+ filter << entry
97
+ end
98
+ filter
99
+ end
100
+
101
+ def run
102
+ begin
103
+ client = Aws::EC2::Client.new aws_config
104
+
105
+ filter = convert_filter(config[:filter])
106
+
107
+ options = { filters: filter }
108
+
109
+ data = client.describe_instances(options)
110
+
111
+ instance_ids = Set.new
112
+ scheme = config[:scheme]
113
+
114
+ unless config[:name].empty?
115
+ scheme += ".#{config[:name]}"
116
+ end
117
+ data[:reservations].each do |res|
118
+ res[:instances].each do |i|
119
+ instance_ids << i[:instance_id]
120
+ output scheme + ".ids.#{i[:instance_id]}"
121
+ end
122
+ end
123
+ output scheme + ".count.#{instance_ids.count}"
124
+ rescue => e
125
+ puts "Error: exception: #{e}"
126
+ critical
127
+ end
128
+ ok
129
+ end
130
+ end
@@ -5,7 +5,7 @@ module SensuPluginsAWS
5
5
  # This defines the version of the gem
6
6
  module Version
7
7
  MAJOR = 1
8
- MINOR = 0
8
+ MINOR = 1
9
9
  PATCH = 0
10
10
 
11
11
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu-Plugins and contributors
@@ -30,7 +30,7 @@ cert_chain:
30
30
  8sHuVruarogxxKPBzlL2is4EUb6oN/RdpGx2l4254+nyR+abg//Ed27Ym0PkB4lk
31
31
  HP0m8WSjZmFr109pE/sVsM5jtOCvogyujQOjNVGN4gz1wwPr
32
32
  -----END CERTIFICATE-----
33
- date: 2015-07-22 00:00:00.000000000 Z
33
+ date: 2015-07-24 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: sensu-plugin
@@ -235,9 +235,11 @@ executables:
235
235
  - metrics-elb.rb
236
236
  - metrics-elb-full.rb
237
237
  - metrics-elasticache.rb
238
+ - metrics-ec2-filter.rb
238
239
  - metrics-ec2-count.rb
239
240
  - metrics-autoscaling-instance-count.rb
240
241
  - handler-sns.rb
242
+ - handler-ses.rb
241
243
  - handler-ec2_node.rb
242
244
  - check_vpc_vpn.py
243
245
  - check-sqs-messages.rb
@@ -253,6 +255,7 @@ executables:
253
255
  - check-elb-health-sdk.rb
254
256
  - check-elb-health-fog.rb
255
257
  - check-elb-certs.rb
258
+ - check-eip-allocation.rb
256
259
  - check-ec2-network.rb
257
260
  - check-ebs-snapshots.rb
258
261
  - check-dynamodb-throttle.rb
@@ -269,6 +272,7 @@ files:
269
272
  - bin/check-dynamodb-throttle.rb
270
273
  - bin/check-ebs-snapshots.rb
271
274
  - bin/check-ec2-network.rb
275
+ - bin/check-eip-allocation.rb
272
276
  - bin/check-elb-certs.rb
273
277
  - bin/check-elb-health-fog.rb
274
278
  - bin/check-elb-health-sdk.rb
@@ -284,9 +288,11 @@ files:
284
288
  - bin/check-sqs-messages.rb
285
289
  - bin/check_vpc_vpn.py
286
290
  - bin/handler-ec2_node.rb
291
+ - bin/handler-ses.rb
287
292
  - bin/handler-sns.rb
288
293
  - bin/metrics-autoscaling-instance-count.rb
289
294
  - bin/metrics-ec2-count.rb
295
+ - bin/metrics-ec2-filter.rb
290
296
  - bin/metrics-elasticache.rb
291
297
  - bin/metrics-elb-full.rb
292
298
  - bin/metrics-elb.rb
metadata.gz.sig CHANGED
Binary file