sensu-plugins-aws 18.3.0 → 18.6.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
  SHA256:
3
- metadata.gz: bb986d62da220b60b0f2e66794be82bbbf685320d42e7f126d1454e672ee7915
4
- data.tar.gz: 1c3b455fb96f1d194af0a12693fc6ecd127114379eb14bd88352f6aad5bcbc8c
3
+ metadata.gz: '08a495ed02c8b0ce9e71fef7101443deaac2bb54dc8b7e8626019c16133a7a6a'
4
+ data.tar.gz: '012180e71e2b13044af8a0dca92f9ed857a10008c8f97cf7fdd8da5ed4d1f8f3'
5
5
  SHA512:
6
- metadata.gz: b6ebc68a7983287cc91e5411cb70e589500880e9a5181259bcf4b1ee63520d666eb357b286eed8ce91b4953c8671b21cc8b0ecc934ac6575f85b968e51dde279
7
- data.tar.gz: d45fe80f8643a31112732663e58048e0947d2a95883cf9f37d97f19009a9a66ea27a139c616825c87b4e8844ff5196f39f00beac13d8b76df9998addea08527b
6
+ metadata.gz: d55ba1c776ced6216e4d765613b4325420fe1db77fc0ebb33ff0331234848d975515065a83ce7722eb7beaa051ea27a237140415c360c9a5c1e2383efe9262f3
7
+ data.tar.gz: 37b1a9dd624e84b3798714296f6fb1182a91823de932530a586cd1f38a2cdeb36877f7316d4cfaf30188fe82a286cc1ad816f8c1d02ff70155edbcf926c627dc
@@ -5,6 +5,39 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## 18.6.0
9
+ ### Added
10
+ - `check-subnet-ip-consumption.rb` - Added `--warn-only` option (@ChrisCalavera)
11
+ - new `metrics-reservation-utilization.rb`: retrieve metrics about reserved instances usage. (@boutetnico)
12
+ - `check-ebs-burst-limit.rb`: add `--tag`/`-t` option to specify a volume tag to output in status message. (@boutetnico)
13
+ - check-instance-events.rb: re-instate assume-role functionality (@pmiles)
14
+ - new `check-expiring-reservations.rb`: check instance reservations and warn about upcoming expiration. (@boutetnico)
15
+ - check-cloudwatch-alarm-multi.rb: Add check that will raise a critical if one of cloud watch alarms are in given state, and a critical for each alarm in given state. (@stevenayers)
16
+ - `check-cloudwatch-alarms.rb`: `--name-prefix`/`-p` option added to filter alarm names by a prefix. (@boutetnico)
17
+
18
+ ### Fixed
19
+ - `check-sqs-messages.rb`: properly surface false positives when pulling an unsupported metric (@majormoses)
20
+ - - Prevent the retrieval of all db instances when the `db_cluster_id` option is specified and the `db_instance_id` option is not specified
21
+ - updated `.bonsai.yml` to match with other plugins (CentOS6/8 support, etc.) (@nixwiz)
22
+
23
+ ## [18.5.0] - 2020-01-28
24
+ ### Changed
25
+ - `check-trustedadvisor-service-limits.rb`: Trusted Advisor combined Service Limits check ID 'eW7HH0l7J9' scheduled to be disabled on Feb 15 2020. Updated the script to go through every Service Limits checks and look for not 'ok' status. Outcome is the same. (@swibowo)
26
+ - bumped version of `bundler` when installing to match travis, before installing dep ensure we have a required version of bundler for development (@majormoses)
27
+
28
+ ## [18.4.2] - 2019-09-23
29
+ ### Fixed
30
+ - Properly parse `--db-cluster-id` option in `check-rds.rb` (@rwha)
31
+
32
+
33
+ ## [18.4.1] - 2019-08-21
34
+ ### Security
35
+ - force newer version of nokogiri to address CVE-2019-5477 (@majormoses)
36
+
37
+ ## [18.4.0] - 2019-05-08
38
+ ### Added
39
+ - `check-ebs-burst-limit.rb`: `--filter` option added to filter which volume to check. (@boutetnico)
40
+
8
41
  ## [18.3.0] - 2019-05-07
9
42
  ### Added
10
43
  - Travis build automation to generate Sensu Asset tarballs that can be used in conjunction with Sensu provided ruby runtime assets and the Bonsai Asset Index
@@ -582,7 +615,12 @@ WARNING: This release contains major breaking changes that will impact all user
582
615
  ### Added
583
616
  - initial release
584
617
 
585
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/18.3.0...HEAD
618
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/18.6.0...HEAD
619
+ [18.6.0]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/18.5.0...18.6.0
620
+ [18.5.0]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/18.4.2...18.5.0
621
+ [18.4.2]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/18.4.1...18.4.2
622
+ [18.4.1]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/18.4.0...18.4.1
623
+ [18.4.0]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/18.3.0...18.4.0
586
624
  [18.3.0]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/18.2.0...18.3.0
587
625
  [18.2.0]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/18.1.0...18.2.0
588
626
  [18.1.0]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/18.0.0...18.1.0
data/README.md CHANGED
@@ -23,6 +23,8 @@ The Sensu assets packaged from this repository are built against the Sensu Ruby
23
23
 
24
24
  **check-cloudwatch-alarm**
25
25
 
26
+ **check-cloudwatch-alarm-multi**
27
+
26
28
  **check-cloudwatch-alarms**
27
29
 
28
30
  **check-cloudwatch-composite-metric**
@@ -169,6 +171,8 @@ The Sensu assets packaged from this repository are built against the Sensu Ruby
169
171
  * /bin/check-configservice-rules.rb
170
172
  * /bin/check-cloudfront-tag.rb
171
173
  * /bin/check-cloudwatch-alarm.rb
174
+ * /bin/check-cloudwatch-alarm-multi.rb
175
+ * /bin/check-cloudwatch-alarms.rb
172
176
  * /bin/check-cloudwatch-metric.rb
173
177
  * /bin/check-cloudwatch-composite-metric.rb
174
178
  * /bin/check-dynamodb-capacity.rb
@@ -192,6 +196,7 @@ The Sensu assets packaged from this repository are built against the Sensu Ruby
192
196
  * /bin/check-emr-cluster.rb
193
197
  * /bin/check-emr-steps.rb
194
198
  * /bin/check-eni-status.rb
199
+ * /bin/check-expiring-reservations.rb
195
200
  * /bin/check-instance-events.rb
196
201
  * /bin/check-rds-events.rb
197
202
  * /bin/check-rds-pending.rb
@@ -221,6 +226,7 @@ The Sensu assets packaged from this repository are built against the Sensu Ruby
221
226
  * /bin/metrics-elb.rb
222
227
  * /bin/metrics-emr-steps.rb
223
228
  * /bin/metrics-rds.rb
229
+ * /bin/metrics-reservation-utilization.rb
224
230
  * /bin/metrics-s3.rb
225
231
  * /bin/metrics-ses.rb
226
232
  * /bin/metrics-sqs.rb
@@ -0,0 +1,91 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-cloudwatch-alarm-multi
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin raise a critical if one of cloud watch alarms are in given state, and a critical for
7
+ # each alarm in given state.
8
+ #
9
+ # OUTPUT:
10
+ # plain-text
11
+ #
12
+ # PLATFORMS:
13
+ # Linux
14
+ #
15
+ # DEPENDENCIES:
16
+ # gem: aws-sdk
17
+ # gem: sensu-plugin
18
+ #
19
+ # USAGE:
20
+ # ./check-cloudwatch-alarm-multi --exclude-alarms "CPUAlarmLow"
21
+ # ./check-cloudwatch-alarm-multi --region eu-west-1 --exclude-alarms "CPUAlarmLow"
22
+ #
23
+ # NOTES:
24
+ #
25
+ # LICENSE:
26
+ # Copyright (c) 2017, Steven Ayers, sayers@equalexperts.com
27
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
28
+ # for details.
29
+ #
30
+
31
+ require 'sensu-plugin/check/cli'
32
+ require 'sensu-plugins-aws/common'
33
+ require 'aws-sdk'
34
+
35
+ class CloudWatchCheck < Sensu::Plugin::Check::CLI
36
+ include Common
37
+
38
+ option :aws_region,
39
+ short: '-r AWS_REGION',
40
+ long: '--aws-region REGION',
41
+ description: 'AWS Region (defaults to us-east-1).',
42
+ default: 'us-east-1'
43
+
44
+ option :state,
45
+ description: 'State of the alarm',
46
+ short: '-s STATE',
47
+ long: '--state STATE',
48
+ default: 'ALARM'
49
+
50
+ option :exclude_alarms,
51
+ description: 'Exclude alarms',
52
+ short: '-e EXCLUDE_ALARMS',
53
+ long: '--exclude-alarms',
54
+ proc: proc { |a| a.split(',') },
55
+ default: []
56
+
57
+ def run
58
+ client = Aws::CloudWatch::Client.new
59
+ options = { state_value: config[:state] }
60
+ alarms = client.describe_alarms(options).metric_alarms
61
+
62
+ if alarms.empty?
63
+ ok "No alarms in '#{config[:state]}' state"
64
+ end
65
+
66
+ config[:exclude_alarms].each do |x|
67
+ alarms.delete_if { |alarm| alarm.alarm_name.match(x) }
68
+ end
69
+
70
+ alarm_names = alarms.map(&:alarm_name)
71
+
72
+ alarm_names.each do |alarm|
73
+ send_critical("check_cloudwatch_alarm_#{alarm}", "#{alarm} in '#{config[:state]}' state")
74
+ end
75
+
76
+ critical "#{alarms.size} in '#{config[:state]}' state: #{alarm_names.join(',')}" unless alarms.empty?
77
+ rescue StandardError => e
78
+ puts "Error: exception: #{e}"
79
+ critical
80
+ end
81
+
82
+ def sensu_client_socket(msg)
83
+ u = UDPSocket.new
84
+ u.send(msg + "\n", 0, '127.0.0.1', 3030)
85
+ end
86
+
87
+ def send_critical(check_name, msg)
88
+ d = { 'name' => check_name, 'status' => 2, 'output' => msg, 'handlers' => config[:handlers] }
89
+ sensu_client_socket d.to_json
90
+ end
91
+ end
@@ -16,8 +16,9 @@
16
16
  # gem: sensu-plugin
17
17
  #
18
18
  # USAGE:
19
+ # ./check-cloudwatch-alarms --name-prefix "staging"
19
20
  # ./check-cloudwatch-alarms --exclude-alarms "CPUAlarmLow"
20
- # ./check-cloudwatch-alarms --region eu-west-1 --exclude-alarms "CPUAlarmLow"
21
+ # ./check-cloudwatch-alarms --aws-region eu-west-1 --exclude-alarms "CPUAlarmLow"
21
22
  #
22
23
  # NOTES:
23
24
  #
@@ -46,6 +47,12 @@ class CloudWatchCheck < Sensu::Plugin::Check::CLI
46
47
  long: '--state STATE',
47
48
  default: 'ALARM'
48
49
 
50
+ option :name_prefix,
51
+ description: 'Alarm name prefix',
52
+ short: '-p NAME_PREFIX',
53
+ long: '--name-prefix NAME_PREFIX',
54
+ default: ''
55
+
49
56
  option :exclude_alarms,
50
57
  description: 'Exclude alarms',
51
58
  short: '-e EXCLUDE_ALARMS',
@@ -57,6 +64,11 @@ class CloudWatchCheck < Sensu::Plugin::Check::CLI
57
64
  client = Aws::CloudWatch::Client.new
58
65
 
59
66
  options = { state_value: config[:state] }
67
+
68
+ unless config[:name_prefix].empty?
69
+ options[:alarm_name_prefix] = config[:name_prefix]
70
+ end
71
+
60
72
  alarms = client.describe_alarms(options).metric_alarms
61
73
 
62
74
  if alarms.empty?
@@ -19,7 +19,10 @@
19
19
  # USAGE:
20
20
  # ./check-ebs-burst-limit.rb -r ${you_region}
21
21
  # ./check-ebs-burst-limit.rb -r ${you_region} -c 50
22
+ # ./check-ebs-burst-limit.rb -r ${you_region} -c 50 -t Name
22
23
  # ./check-ebs-burst-limit.rb -r ${you_region} -w 50 -c 10
24
+ # ./check-ebs-burst-limit.rb -r ${you_region} -w 50 -c 10 -f "{name:tag-value,values:[infrastructure]}"
25
+ # ./check-ebs-burst-limit.rb -r ${you_region} -w 50 -c 10 -f "{name:tag-value,values:[infrastructure]}" -t Name
23
26
  #
24
27
  # LICENSE:
25
28
  # Barry Martin <nyxcharon@gmail.com>
@@ -29,11 +32,13 @@
29
32
 
30
33
  require 'sensu-plugin/check/cli'
31
34
  require 'sensu-plugins-aws'
35
+ require 'sensu-plugins-aws/filter'
32
36
  require 'aws-sdk'
33
37
  require 'net/http'
34
38
 
35
39
  class CheckEbsBurstLimit < Sensu::Plugin::Check::CLI
36
40
  include CloudwatchCommon
41
+ include Filter
37
42
 
38
43
  option :aws_region,
39
44
  short: '-r R',
@@ -41,6 +46,11 @@ class CheckEbsBurstLimit < Sensu::Plugin::Check::CLI
41
46
  description: 'AWS region, will be overridden by the -s option',
42
47
  default: 'us-east-1'
43
48
 
49
+ option :tag,
50
+ description: 'Add volume TAG value to warn/critical message.',
51
+ short: '-t TAG',
52
+ long: '--tag TAG'
53
+
44
54
  option :critical,
45
55
  description: 'Trigger a critical when ebs burst limit is under VALUE',
46
56
  short: '-c VALUE',
@@ -61,29 +71,38 @@ class CheckEbsBurstLimit < Sensu::Plugin::Check::CLI
61
71
  boolean: true,
62
72
  default: false
63
73
 
74
+ option :filter,
75
+ short: '-f FILTER',
76
+ long: '--filter FILTER',
77
+ description: 'String representation of the filter to apply',
78
+ default: '{}'
79
+
80
+ def volume_tag(volume, tag_name)
81
+ tag = volume.tags.select { |t| t.key == tag_name }.first
82
+ tag.nil? ? '' : tag.value
83
+ end
84
+
64
85
  def run
65
86
  errors = []
66
87
 
88
+ volume_filters = Filter.parse(config[:filter])
89
+
67
90
  # Set the describe-volumes filter depending on whether -s was specified
68
91
  if config[:check_self] == true
69
92
  # Get the region from the availability zone, and override the -r option
70
93
  my_instance_az = Net::HTTP.get(URI.parse('http://169.254.169.254/latest/meta-data/placement/availability-zone'))
71
94
  Aws.config[:region] = my_instance_az.chop
72
95
  my_instance_id = Net::HTTP.get(URI.parse('http://169.254.169.254/latest/meta-data/instance-id'))
73
- volume_filters = [
74
- {
75
- name: 'attachment.instance-id',
76
- values: [my_instance_id]
77
- }
78
- ]
96
+ volume_filters.push(
97
+ name: 'attachment.instance-id',
98
+ values: [my_instance_id]
99
+ )
79
100
  else
80
101
  # The -s option was not specified, look at all volumes which are attached
81
- volume_filters = [
82
- {
83
- name: 'attachment.status',
84
- values: ['attached']
85
- }
86
- ]
102
+ volume_filters.push(
103
+ name: 'attachment.status',
104
+ values: ['attached']
105
+ )
87
106
  end
88
107
 
89
108
  ec2 = Aws::EC2::Client.new
@@ -100,13 +119,14 @@ class CheckEbsBurstLimit < Sensu::Plugin::Check::CLI
100
119
  volumes[:volumes].each do |volume|
101
120
  config[:dimensions] = []
102
121
  config[:dimensions] << { name: 'VolumeId', value: volume[:volume_id] }
122
+ volume_tag = config[:tag] ? " (#{volume_tag(volume, config[:tag])})" : ''
103
123
  resp = client.get_metric_statistics(metrics_request(config))
104
124
  unless resp.datapoints.first.nil?
105
125
  if resp.datapoints.first[:average] < config[:critical]
106
- errors << "#{volume[:volume_id]} #{resp.datapoints.first[:average]}"
126
+ errors << "#{volume[:volume_id]}#{volume_tag} #{resp.datapoints.first[:average]}"
107
127
  crit = true
108
128
  elsif config[:warning] && resp.datapoints.first[:average] < config[:warning]
109
- errors << "#{volume[:volume_id]} #{resp.datapoints.first[:average]}"
129
+ errors << "#{volume[:volume_id]}#{volume_tag} #{resp.datapoints.first[:average]}"
110
130
  should_warn = true
111
131
  end
112
132
  end
@@ -0,0 +1,117 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # expiring-reservations
4
+ #
5
+ # DESCRIPTION:
6
+ # Alert on expiring reservations of an AWS account.
7
+ #
8
+ # OUTPUT:
9
+ # plain-text
10
+ #
11
+ # PLATFORMS:
12
+ # Linux
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: aws-sdk
16
+ # gem: sensu-plugin
17
+ # gem: sensu-plugins-aws
18
+ #
19
+ # USAGE:
20
+ # check-expiring-reservations.rb
21
+ #
22
+ # NOTES:
23
+ #
24
+ # LICENSE:
25
+ # Copyright (c) 2019, Nicolas Boutet amd3002@gmail.com
26
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
27
+ # for details.
28
+ #
29
+
30
+ require 'sensu-plugin/check/cli'
31
+ require 'aws-sdk'
32
+ require 'sensu-plugins-aws'
33
+
34
+ class CheckExpiringReservations < Sensu::Plugin::Check::CLI
35
+ include Common
36
+
37
+ option :reservation_id,
38
+ description: 'Reservation id (defaults to all reservations if omitted)',
39
+ short: '-R RESERVATION_ID',
40
+ long: '--reservation-id RESERVATION_ID',
41
+ default: nil
42
+
43
+ option :offering_class,
44
+ description: 'The offering class of the Reserved Instance (standard or convertible)',
45
+ short: '-o OFFERING_CLASS',
46
+ long: '--offering-class OFFERING_CLASS',
47
+ default: 'standard'
48
+
49
+ option :aws_region,
50
+ short: '-r AWS_REGION',
51
+ long: '--aws-region REGION',
52
+ description: 'AWS Region (defaults to us-east-1).',
53
+ default: 'us-east-1'
54
+
55
+ option :warning,
56
+ short: '-w N',
57
+ long: '--warning VALUE',
58
+ description: 'Issue a warning if a reservation will expire in under VALUE days',
59
+ default: 0,
60
+ proc: proc(&:to_i)
61
+
62
+ option :critical,
63
+ short: '-c N',
64
+ long: '--critical VALUE',
65
+ description: 'Issue a critical if a reservation will expire in under VALUE days',
66
+ default: 1,
67
+ proc: proc(&:to_i)
68
+
69
+ def run
70
+ begin
71
+ client = Aws::EC2::Client.new(aws_config)
72
+
73
+ params = {
74
+ filters: [
75
+ {
76
+ name: 'state',
77
+ values: ['active']
78
+ }
79
+ ],
80
+ offering_class: config[:offering_class]
81
+ }
82
+
83
+ unless config[:reservation_id].nil?
84
+ params[:reserved_instances_ids] = [config[:reservation_id]]
85
+ end
86
+
87
+ reservations = client.describe_reserved_instances(params)
88
+
89
+ warnflag = false
90
+ critflag = false
91
+ reportstring = ''
92
+
93
+ reservations.reserved_instances.each do |reservation|
94
+ time_left = (reservation.end - Time.now).abs.to_i / (24 * 60 * 60)
95
+
96
+ if time_left <= config[:critical]
97
+ critflag = true
98
+ reportstring += " reservation #{reservation.reserved_instances_id} (#{reservation.instance_type} x #{reservation.instance_count}) expires in #{time_left} days;"
99
+ elsif time_left <= config[:warning]
100
+ warnflag = true
101
+ reportstring += " reservation #{reservation.reserved_instances_id} (#{reservation.instance_type} x #{reservation.instance_count}) expires in #{time_left} days;"
102
+ end
103
+ end
104
+
105
+ if critflag
106
+ critical reportstring
107
+ elsif warnflag
108
+ warning reportstring
109
+ else
110
+ ok 'All checked reservations are ok'
111
+ end
112
+ rescue StandardError => e
113
+ critical "Error: exception: #{e}"
114
+ end
115
+ ok
116
+ end
117
+ end
@@ -67,6 +67,11 @@ class CheckInstanceEvents < Sensu::Plugin::Check::CLI
67
67
  description: "Includes any offending instance's 'Name' tag in the check output",
68
68
  default: false
69
69
 
70
+ option :role,
71
+ short: '-R ASSUME_ROLE',
72
+ long: '--assume-role-arn ARN',
73
+ description: 'IAM Role to assume'
74
+
70
75
  def aws_config
71
76
  { access_key_id: config[:aws_access_key],
72
77
  secret_access_key: config[:aws_secret_access_key],
@@ -77,6 +82,23 @@ class CheckInstanceEvents < Sensu::Plugin::Check::CLI
77
82
  Aws.partition('aws').regions.map(&:name)
78
83
  end
79
84
 
85
+ def assume_role
86
+ role_config = aws_config
87
+
88
+ # Delete keys so we can use an IAM role
89
+ role_config.delete(:access_key_id)
90
+ role_config.delete(:secret_access_key)
91
+
92
+ Aws.config[:region] = role_config[:region]
93
+
94
+ role_credentials = Aws::AssumeRoleCredentials.new(
95
+ role_arn: config[:role],
96
+ role_session_name: 'sensu-monitoring'
97
+ )
98
+
99
+ role_config.merge!(credentials: role_credentials)
100
+ end
101
+
80
102
  def run
81
103
  event_instances = []
82
104
  aws_config = {}
@@ -161,7 +161,7 @@ class CheckRDS < Sensu::Plugin::Check::CLI
161
161
 
162
162
  def find_db_cluster_writer(id)
163
163
  wr = rds.describe_db_clusters(db_cluster_identifier: id).db_clusters[0].db_cluster_members.detect(&:is_cluster_writer).db_instance_identifier
164
- unknown 'DB cluster not found.' if cl.nil?
164
+ unknown 'DB cluster not found.' if wr.nil?
165
165
  wr
166
166
  end
167
167
 
@@ -321,11 +321,9 @@ class CheckRDS < Sensu::Plugin::Check::CLI
321
321
  def run
322
322
  instances = []
323
323
  if config[:db_cluster_id]
324
- db_cluster_writer_id = find_db_cluster_writer(db_cluster_id)
324
+ db_cluster_writer_id = find_db_cluster_writer(config[:db_cluster_id])
325
325
  instances << find_db_instance(db_cluster_writer_id)
326
- end
327
-
328
- if config[:db_instance_id].nil? || config[:db_instance_id].empty?
326
+ elsif config[:db_instance_id].nil? || config[:db_instance_id].empty?
329
327
  rds.describe_db_instances[:db_instances].map { |db| instances << db }
330
328
  else
331
329
  instances << find_db_instance(config[:db_instance_id])
@@ -118,7 +118,16 @@ class SQSMsgs < Sensu::Plugin::Check::CLI
118
118
  queues = config[:queues]
119
119
  queues.each do |q|
120
120
  url = sqs.get_queue_by_name(queue_name: q).url
121
- messages = sqs.client.get_queue_attributes(queue_url: url, attribute_names: ['All']).attributes[config[:metric]].to_i
121
+ messages = sqs.client.get_queue_attributes(queue_url: url, attribute_names: ['All'])
122
+ if messages.attributes.key(config[:metric])
123
+ messages = messages.attributes([config[:metric]]).to_i
124
+ else
125
+ failure_msg = <<~MESSAGE
126
+ failed to pull metric #{config[:metric]} on queue: #{q}.
127
+ available attributes: #{messages.attributes}
128
+ MESSAGE
129
+ unknown failure_msg
130
+ end
122
131
 
123
132
  if (config[:crit_under] >= 0 && messages < config[:crit_under]) || (config[:crit_over] >= 0 && messages > config[:crit_over])
124
133
  crits << "#{messages} message(s) in #{q}"
@@ -74,6 +74,13 @@ class CheckSubnetIpConsumption < Sensu::Plugin::Check::CLI
74
74
  default: 0,
75
75
  description: 'Manipulate the verbosity of the alert output. Valid options are 0, 1, and 2 (from least to most verbose). Default is 0.'
76
76
 
77
+ option :warn_only,
78
+ short: '-w',
79
+ long: '--warn-only',
80
+ boolean: true,
81
+ default: false,
82
+ description: 'Warning only'
83
+
77
84
  def iam_client
78
85
  @iam_client ||= Aws::IAM::Client.new
79
86
  end
@@ -218,16 +225,23 @@ class CheckSubnetIpConsumption < Sensu::Plugin::Check::CLI
218
225
 
219
226
  case config[:show_account_alias]
220
227
  when true
221
- critical(alert_prefix_with_alias % { count: alert_msg.length,
222
- alias: account_alias,
223
- region: config[:aws_region],
224
- threshold: config[:alert_threshold],
225
- alerts: alert_msg.join(', ') })
228
+ alert_msg = alert_prefix_with_alias % { count: alert_msg.length,
229
+ alias: account_alias,
230
+ region: config[:aws_region],
231
+ threshold: config[:alert_threshold],
232
+ alerts: alert_msg.join(', ') }
233
+ when false
234
+ alert_msg = alert_prefix % { count: alert_msg.length,
235
+ region: config[:aws_region],
236
+ threshold: config[:alert_threshold],
237
+ alerts: alert_msg.join(', ') }
238
+ end
239
+
240
+ case config[:warn_only]
241
+ when true
242
+ warning(alert_msg)
226
243
  when false
227
- critical(alert_prefix % { count: alert_msg.length,
228
- region: config[:aws_region],
229
- threshold: config[:alert_threshold],
230
- alerts: alert_msg.join(', ') })
244
+ critical(alert_msg)
231
245
  end
232
246
  end
233
247
  end
@@ -45,29 +45,37 @@ class CheckTrustedAdvisorServiceLimits < Sensu::Plugin::Check::CLI
45
45
  description: "ISO 639-1 language code to be used when querying Trusted Advisor API. Only 'en' and 'ja' supported for now",
46
46
  default: 'en'
47
47
 
48
- def run
48
+ def aws_support
49
49
  # The Support endpoint seems to only available in us-east-1 region
50
50
  # http://docs.aws.amazon.com/sdkforruby/api/Aws/Support.html
51
- aws_support = Aws::Support::Client.new(region: 'us-east-1')
51
+ @aws_support ||= Aws::Support::Client.new(region: 'us-east-1')
52
+ end
52
53
 
54
+ def run
53
55
  service_limit_msg = []
54
56
 
55
57
  begin
56
- # service limit check
57
- # Perform a refresh to make sure the API result is not stale.
58
- aws_support.refresh_trusted_advisor_check(check_id: 'eW7HH0l7J9')
59
- sl = aws_support.describe_trusted_advisor_check_result(check_id: 'eW7HH0l7J9', language: config[:aws_language])
58
+ # Get all check IDs with category "service_limits"
59
+ check_ids = []
60
+ aws_support.describe_trusted_advisor_checks(language: config[:aws_language])[:checks].each { |c| check_ids << c.id if c.category == 'service_limits' }
61
+
62
+ # Get all checks that are not "ok"
63
+ checks_not_ok = []
64
+ aws_support.describe_trusted_advisor_check_summaries(check_ids: check_ids)[:summaries].each { |c| checks_not_ok << c.check_id if c.status != 'ok' }
65
+
66
+ checks_not_ok.each do |cno|
67
+ aws_support.describe_trusted_advisor_check_result(language: config[:aws_language], check_id: cno)[:result][:flagged_resources].each do |slr|
68
+ # Data structure will be as follow
69
+ # ["<region>", "<service>", "<description>", "<limit>", "<usage>", "<status>"]
70
+ sl_region, sl_service, sl_description, sl_limit, sl_usage, sl_status = slr[:metadata]
60
71
 
61
- sl[:result][:flagged_resources].each do |slr|
62
- # Data structure will be as follow
63
- # ["<region>", "<service>", "<description>", "<limit>", "<usage>", "<status>"]
64
- sl_region, sl_service, sl_description, sl_limit, sl_usage, sl_status = slr[:metadata]
72
+ next if slr.status == 'ok' || sl_status == 'Green'
65
73
 
66
- next if sl_status == 'Green'
67
- sl_usage = 0 if sl_usage.nil?
74
+ sl_usage = 0 if sl_usage.nil?
68
75
 
69
- sl_msg = "#{sl_service} (#{sl_region}) #{sl_description} #{sl_usage} out of #{sl_limit}"
70
- service_limit_msg.push(sl_msg)
76
+ sl_msg = "#{sl_service} (#{sl_region}) #{sl_description} #{sl_usage} out of #{sl_limit}"
77
+ service_limit_msg.push(sl_msg)
78
+ end
71
79
  end
72
80
  rescue StandardError => e
73
81
  unknown "An error occurred processing AWS TrustedAdvisor API: #{e.message}"
@@ -0,0 +1,84 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # reservation-utilization
4
+ #
5
+ # DESCRIPTION:
6
+ # Gets Reservation Utilization of an AWS account.
7
+ #
8
+ # OUTPUT:
9
+ # metric-data
10
+ #
11
+ # PLATFORMS:
12
+ # Linux
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: aws-sdk
16
+ # gem: sensu-plugin
17
+ # gem: sensu-plugins-aws
18
+ #
19
+ # USAGE:
20
+ # metrics-reservation-utilization.rb
21
+ #
22
+ # NOTES:
23
+ #
24
+ # LICENSE:
25
+ # Copyright (c) 2019, Nicolas Boutet amd3002@gmail.com
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
+ require 'sensu-plugins-aws'
33
+
34
+ class ReservationUtilizationMetrics < Sensu::Plugin::Metric::CLI::Graphite
35
+ include Common
36
+
37
+ option :from,
38
+ short: '-f TIME',
39
+ long: '--from TIME',
40
+ default: Time.now - 2 * 86_400, # start date cannot be after 2 days ago
41
+ proc: proc { |a| Time.parse a },
42
+ description: 'The beginning of the time period that you want the usage and costs for (inclusive).'
43
+
44
+ option :to,
45
+ short: '-t TIME',
46
+ long: '--to TIME',
47
+ default: Time.now,
48
+ proc: proc { |a| Time.parse a },
49
+ description: 'The end of the time period that you want the usage and costs for (exclusive).'
50
+
51
+ option :scheme,
52
+ description: 'Metric naming scheme, text to prepend to metric.',
53
+ short: '-s SCHEME',
54
+ long: '--scheme SCHEME',
55
+ default: 'sensu.aws.reservation_utilization'
56
+
57
+ option :aws_region,
58
+ short: '-r AWS_REGION',
59
+ long: '--aws-region REGION',
60
+ description: 'AWS Region (defaults to us-east-1).',
61
+ default: 'us-east-1'
62
+
63
+ def run
64
+ begin
65
+ client = Aws::CostExplorer::Client.new(aws_config)
66
+
67
+ reservation_utilization = client.get_reservation_utilization(
68
+ time_period: {
69
+ start: config[:from].strftime('%Y-%m-%d'),
70
+ end: config[:to].strftime('%Y-%m-%d')
71
+ }
72
+ )
73
+
74
+ reservation_utilization.utilizations_by_time.each do |time|
75
+ time.total.to_h.each do |key, value|
76
+ output "#{config[:scheme]}.utilizations_by_time.#{key}", value, Time.parse(time.time_period.end).to_i
77
+ end
78
+ end
79
+ rescue StandardError => e
80
+ critical "Error: exception: #{e}"
81
+ end
82
+ ok
83
+ end
84
+ end
@@ -1,7 +1,7 @@
1
1
  module SensuPluginsAWS
2
2
  module Version
3
3
  MAJOR = 18
4
- MINOR = 3
4
+ MINOR = 6
5
5
  PATCH = 0
6
6
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 18.3.0
4
+ version: 18.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu-Plugins and contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-07 00:00:00.000000000 Z
11
+ date: 2021-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-plugin
@@ -58,42 +58,62 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 1.32.0
61
+ version: 2.1.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 1.32.0
68
+ version: 2.1.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: fog-core
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 1.43.0
75
+ version: 1.45.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: 1.43.0
82
+ version: 1.45.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: nokogiri
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 1.10.4
90
+ - - "<"
91
+ - !ruby/object:Gem::Version
92
+ version: '2.0'
93
+ type: :runtime
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 1.10.4
100
+ - - "<"
101
+ - !ruby/object:Gem::Version
102
+ version: '2.0'
83
103
  - !ruby/object:Gem::Dependency
84
104
  name: rest-client
85
105
  requirement: !ruby/object:Gem::Requirement
86
106
  requirements:
87
107
  - - '='
88
108
  - !ruby/object:Gem::Version
89
- version: 1.8.0
109
+ version: 2.1.0
90
110
  type: :runtime
91
111
  prerelease: false
92
112
  version_requirements: !ruby/object:Gem::Requirement
93
113
  requirements:
94
114
  - - '='
95
115
  - !ruby/object:Gem::Version
96
- version: 1.8.0
116
+ version: 2.1.0
97
117
  - !ruby/object:Gem::Dependency
98
118
  name: right_aws
99
119
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +134,14 @@ dependencies:
114
134
  requirements:
115
135
  - - "~>"
116
136
  - !ruby/object:Gem::Version
117
- version: '1.7'
137
+ version: '2.1'
118
138
  type: :development
119
139
  prerelease: false
120
140
  version_requirements: !ruby/object:Gem::Requirement
121
141
  requirements:
122
142
  - - "~>"
123
143
  - !ruby/object:Gem::Version
124
- version: '1.7'
144
+ version: '2.1'
125
145
  - !ruby/object:Gem::Dependency
126
146
  name: github-markup
127
147
  requirement: !ruby/object:Gem::Requirement
@@ -156,14 +176,14 @@ dependencies:
156
176
  requirements:
157
177
  - - "~>"
158
178
  - !ruby/object:Gem::Version
159
- version: '12.3'
179
+ version: '13.0'
160
180
  type: :development
161
181
  prerelease: false
162
182
  version_requirements: !ruby/object:Gem::Requirement
163
183
  requirements:
164
184
  - - "~>"
165
185
  - !ruby/object:Gem::Version
166
- version: '12.3'
186
+ version: '13.0'
167
187
  - !ruby/object:Gem::Dependency
168
188
  name: redcarpet
169
189
  requirement: !ruby/object:Gem::Requirement
@@ -228,86 +248,89 @@ description: |-
228
248
  for EC2, SES, and SNS.
229
249
  email: "<sensu-users@googlegroups.com>"
230
250
  executables:
251
+ - check-reserved-instances.rb
252
+ - check-vpc-nameservers.rb
253
+ - metrics-autoscaling-instance-count.rb
254
+ - check-cloudwatch-alarm.rb
255
+ - check-dynamodb-throttle.rb
231
256
  - check-cloudwatch-alarms.rb
232
- - metrics-cloudfront.rb
233
- - metrics-ses.rb
234
- - check-ebs-burst-limit.rb
235
- - handler-scale-asg-down.rb
236
- - check-s3-bucket-visibility.rb
237
- - check-trustedadvisor-service-limits.rb
238
257
  - check-kms-key.rb
239
- - check-ses-statistics.rb
240
- - check-alb-target-group-health.rb
241
258
  - check-ses-limit.rb
242
- - check-sns-subscriptions.rb
243
- - metrics-waf.rb
244
- - metrics-autoscaling-instance-count.rb
245
259
  - metrics-s3.rb
246
- - check-s3-tag.rb
247
- - check-dynamodb-throttle.rb
248
- - handler-ec2_node.rb
249
- - check-ec2-cpu_balance.rb
250
- - check-beanstalk-health.rb
251
- - metrics-asg.rb
260
+ - handler-sns.rb
261
+ - check-s3-bucket-visibility.rb
262
+ - metrics-cloudfront.rb
263
+ - check-ec2-network.rb
264
+ - check-rds-events.rb
265
+ - metrics-rds.rb
252
266
  - check-instances-count.rb
253
- - check-elb-certs.rb
254
- - check-reserved-instances.rb
267
+ - check-cloudwatch-alarm-multi.rb
268
+ - metrics-sqs.rb
269
+ - check-emr-steps.rb
270
+ - check-ebs-burst-limit.rb
271
+ - check-redshift-events.rb
255
272
  - check-instance-health.rb
256
- - check-ec2-network.rb
257
- - check-efs-metric.rb
258
- - check-sensu-client.rb
259
- - check-emr-cluster.rb
260
- - handler-ses.rb
261
- - check-asg-instances-inservice.rb
273
+ - check-elb-health.rb
274
+ - check-expiring-reservations.rb
275
+ - handler-ec2_node.rb
276
+ - check-elb-instances-inservice.rb
277
+ - check-ec2-cpu_balance.rb
262
278
  - check-sqs-messages.rb
263
279
  - check-rds-pending.rb
264
- - check-cloudwatch-metric.rb
265
- - check-configservice-rules.rb
266
- - check-beanstalk-elb-metric.rb
267
- - check-elb-health.rb
268
- - check-instance-reachability.rb
269
- - check-emr-steps.rb
270
- - check-elasticache-failover.rb
280
+ - check-emr-cluster.rb
271
281
  - check-eip-allocation.rb
272
- - check-s3-object.rb
273
- - check-redshift-events.rb
274
- - check-ecs-service-health.rb
275
- - check-autoscaling-cpucredits.rb
276
- - check-s3-bucket.rb
277
- - check-elb-health-sdk.rb
278
- - check-cloudwatch-alarm.rb
279
- - check-route.rb
280
- - check-ebs-snapshots.rb
281
282
  - metrics-ec2-filter.rb
283
+ - check-ebs-snapshots.rb
284
+ - metrics-waf.rb
285
+ - metrics-billing.rb
286
+ - check-autoscaling-cpucredits.rb
287
+ - metrics-asg.rb
288
+ - check-instance-events.rb
282
289
  - check-route53-domain-expiration.rb
283
- - metrics-rds.rb
284
- - check-dynamodb-capacity.rb
290
+ - check-elasticache-failover.rb
285
291
  - check-ec2-filter.rb
286
- - check-asg-instances-created.rb
287
- - check-eni-status.rb
288
- - metrics-sqs.rb
289
- - check-instance-events.rb
290
- - metrics-elasticache.rb
291
- - check-rds-events.rb
292
- - check-subnet-ip-consumption.rb
293
- - check-elb-nodes.rb
294
292
  - check-elb-sum-requests.rb
293
+ - metrics-reservation-utilization.rb
294
+ - check-sns-subscriptions.rb
295
+ - metrics-ses.rb
295
296
  - check-elb-health-fog.rb
296
- - handler-sns.rb
297
297
  - handler-scale-asg-up.rb
298
- - check-vpc-nameservers.rb
298
+ - check-sensu-client.rb
299
+ - check-elb-nodes.rb
300
+ - check-s3-object.rb
301
+ - check-trustedadvisor-service-limits.rb
302
+ - check-ses-statistics.rb
303
+ - check-cloudwatch-metric.rb
304
+ - check-beanstalk-health.rb
305
+ - check-dynamodb-capacity.rb
306
+ - check-eni-status.rb
307
+ - check-s3-tag.rb
308
+ - check-direct-connect-virtual-interfaces.rb
299
309
  - check-cloudwatch-composite-metric.rb
300
- - check-rds.rb
310
+ - metrics-ec2-count.rb
311
+ - metrics-elasticache.rb
301
312
  - check-cloudfront-tag.rb
302
- - metrics-emr-steps.rb
303
- - check-certificate-expiry.rb
304
- - check-elb-instances-inservice.rb
313
+ - check-alb-target-group-health.rb
314
+ - check-elb-health-sdk.rb
305
315
  - check-elb-latency.rb
306
- - metrics-ec2-count.rb
307
- - metrics-billing.rb
316
+ - check-s3-bucket.rb
317
+ - handler-scale-asg-down.rb
318
+ - check-elb-certs.rb
319
+ - check-efs-metric.rb
308
320
  - check-vpc-vpn.rb
309
- - check-direct-connect-virtual-interfaces.rb
321
+ - check-subnet-ip-consumption.rb
322
+ - check-ecs-service-health.rb
323
+ - check-rds.rb
324
+ - handler-ses.rb
325
+ - check-asg-instances-created.rb
326
+ - check-route.rb
327
+ - check-instance-reachability.rb
328
+ - check-certificate-expiry.rb
329
+ - check-asg-instances-inservice.rb
330
+ - metrics-emr-steps.rb
310
331
  - metrics-elb.rb
332
+ - check-configservice-rules.rb
333
+ - check-beanstalk-elb-metric.rb
311
334
  extensions: []
312
335
  extra_rdoc_files: []
313
336
  files:
@@ -322,6 +345,7 @@ files:
322
345
  - bin/check-beanstalk-health.rb
323
346
  - bin/check-certificate-expiry.rb
324
347
  - bin/check-cloudfront-tag.rb
348
+ - bin/check-cloudwatch-alarm-multi.rb
325
349
  - bin/check-cloudwatch-alarm.rb
326
350
  - bin/check-cloudwatch-alarms.rb
327
351
  - bin/check-cloudwatch-composite-metric.rb
@@ -350,6 +374,7 @@ files:
350
374
  - bin/check-emr-cluster.rb
351
375
  - bin/check-emr-steps.rb
352
376
  - bin/check-eni-status.rb
377
+ - bin/check-expiring-reservations.rb
353
378
  - bin/check-instance-events.rb
354
379
  - bin/check-instance-health.rb
355
380
  - bin/check-instance-reachability.rb
@@ -390,6 +415,7 @@ files:
390
415
  - bin/metrics-elb.rb
391
416
  - bin/metrics-emr-steps.rb
392
417
  - bin/metrics-rds.rb
418
+ - bin/metrics-reservation-utilization.rb
393
419
  - bin/metrics-s3.rb
394
420
  - bin/metrics-ses.rb
395
421
  - bin/metrics-sqs.rb
@@ -424,7 +450,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
424
450
  - !ruby/object:Gem::Version
425
451
  version: '0'
426
452
  requirements: []
427
- rubygems_version: 3.0.3
453
+ rubygems_version: 3.0.8
428
454
  signing_key:
429
455
  specification_version: 4
430
456
  summary: Sensu plugins for working with an AWS environment