sensu-plugins-aws 18.5.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: 03f4c916797e5cf5b02b2de9788875d6175008be2bae70c5e7754c8bd083dec9
4
- data.tar.gz: 78837fc4f758fecddb73e209f5e35c6ab1d2c375a21cde662790f9007506edd6
3
+ metadata.gz: '08a495ed02c8b0ce9e71fef7101443deaac2bb54dc8b7e8626019c16133a7a6a'
4
+ data.tar.gz: '012180e71e2b13044af8a0dca92f9ed857a10008c8f97cf7fdd8da5ed4d1f8f3'
5
5
  SHA512:
6
- metadata.gz: a28c21a2826a93d3bd786e4faa6f2bb2e2b646b618790ed59880399cb58c0840ea4703a07a4ece60a9654bcda4ecbf6c05b9699cc19de199dd87f4db5874f499
7
- data.tar.gz: 380301c83eff91985a37f60e3ea52f5ea1717f71b1d83da1017a1a8a1038a1960d5182833f2fcd610cfb4c1ccaf2abce1ec4ff9756a09c97f998927df08f7bd6
6
+ metadata.gz: d55ba1c776ced6216e4d765613b4325420fe1db77fc0ebb33ff0331234848d975515065a83ce7722eb7beaa051ea27a237140415c360c9a5c1e2383efe9262f3
7
+ data.tar.gz: 37b1a9dd624e84b3798714296f6fb1182a91823de932530a586cd1f38a2cdeb36877f7316d4cfaf30188fe82a286cc1ad816f8c1d02ff70155edbcf926c627dc
@@ -4,6 +4,22 @@ This project adheres to [Semantic Versioning](http://semver.org/).
4
4
  This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md)
5
5
 
6
6
  ## [Unreleased]
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
+
7
23
  ## [18.5.0] - 2020-01-28
8
24
  ### Changed
9
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)
@@ -599,7 +615,8 @@ WARNING: This release contains major breaking changes that will impact all user
599
615
  ### Added
600
616
  - initial release
601
617
 
602
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/18.5.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
603
620
  [18.5.0]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/18.4.2...18.5.0
604
621
  [18.4.2]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/18.4.1...18.4.2
605
622
  [18.4.1]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/18.4.0...18.4.1
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,8 +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
23
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
24
26
  #
25
27
  # LICENSE:
26
28
  # Barry Martin <nyxcharon@gmail.com>
@@ -44,6 +46,11 @@ class CheckEbsBurstLimit < Sensu::Plugin::Check::CLI
44
46
  description: 'AWS region, will be overridden by the -s option',
45
47
  default: 'us-east-1'
46
48
 
49
+ option :tag,
50
+ description: 'Add volume TAG value to warn/critical message.',
51
+ short: '-t TAG',
52
+ long: '--tag TAG'
53
+
47
54
  option :critical,
48
55
  description: 'Trigger a critical when ebs burst limit is under VALUE',
49
56
  short: '-c VALUE',
@@ -70,6 +77,11 @@ class CheckEbsBurstLimit < Sensu::Plugin::Check::CLI
70
77
  description: 'String representation of the filter to apply',
71
78
  default: '{}'
72
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
+
73
85
  def run
74
86
  errors = []
75
87
 
@@ -107,13 +119,14 @@ class CheckEbsBurstLimit < Sensu::Plugin::Check::CLI
107
119
  volumes[:volumes].each do |volume|
108
120
  config[:dimensions] = []
109
121
  config[:dimensions] << { name: 'VolumeId', value: volume[:volume_id] }
122
+ volume_tag = config[:tag] ? " (#{volume_tag(volume, config[:tag])})" : ''
110
123
  resp = client.get_metric_statistics(metrics_request(config))
111
124
  unless resp.datapoints.first.nil?
112
125
  if resp.datapoints.first[:average] < config[:critical]
113
- errors << "#{volume[:volume_id]} #{resp.datapoints.first[:average]}"
126
+ errors << "#{volume[:volume_id]}#{volume_tag} #{resp.datapoints.first[:average]}"
114
127
  crit = true
115
128
  elsif config[:warning] && resp.datapoints.first[:average] < config[:warning]
116
- errors << "#{volume[:volume_id]} #{resp.datapoints.first[:average]}"
129
+ errors << "#{volume[:volume_id]}#{volume_tag} #{resp.datapoints.first[:average]}"
117
130
  should_warn = true
118
131
  end
119
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 = {}
@@ -323,9 +323,7 @@ class CheckRDS < Sensu::Plugin::Check::CLI
323
323
  if config[:db_cluster_id]
324
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
@@ -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 = 5
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.5.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: 2020-01-29 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,28 +58,28 @@ 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
83
  - !ruby/object:Gem::Dependency
84
84
  name: nokogiri
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -106,14 +106,14 @@ dependencies:
106
106
  requirements:
107
107
  - - '='
108
108
  - !ruby/object:Gem::Version
109
- version: 1.8.0
109
+ version: 2.1.0
110
110
  type: :runtime
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - '='
115
115
  - !ruby/object:Gem::Version
116
- version: 1.8.0
116
+ version: 2.1.0
117
117
  - !ruby/object:Gem::Dependency
118
118
  name: right_aws
119
119
  requirement: !ruby/object:Gem::Requirement
@@ -176,14 +176,14 @@ dependencies:
176
176
  requirements:
177
177
  - - "~>"
178
178
  - !ruby/object:Gem::Version
179
- version: '12.3'
179
+ version: '13.0'
180
180
  type: :development
181
181
  prerelease: false
182
182
  version_requirements: !ruby/object:Gem::Requirement
183
183
  requirements:
184
184
  - - "~>"
185
185
  - !ruby/object:Gem::Version
186
- version: '12.3'
186
+ version: '13.0'
187
187
  - !ruby/object:Gem::Dependency
188
188
  name: redcarpet
189
189
  requirement: !ruby/object:Gem::Requirement
@@ -264,12 +264,14 @@ executables:
264
264
  - check-rds-events.rb
265
265
  - metrics-rds.rb
266
266
  - check-instances-count.rb
267
+ - check-cloudwatch-alarm-multi.rb
267
268
  - metrics-sqs.rb
268
269
  - check-emr-steps.rb
269
270
  - check-ebs-burst-limit.rb
270
271
  - check-redshift-events.rb
271
272
  - check-instance-health.rb
272
273
  - check-elb-health.rb
274
+ - check-expiring-reservations.rb
273
275
  - handler-ec2_node.rb
274
276
  - check-elb-instances-inservice.rb
275
277
  - check-ec2-cpu_balance.rb
@@ -288,6 +290,7 @@ executables:
288
290
  - check-elasticache-failover.rb
289
291
  - check-ec2-filter.rb
290
292
  - check-elb-sum-requests.rb
293
+ - metrics-reservation-utilization.rb
291
294
  - check-sns-subscriptions.rb
292
295
  - metrics-ses.rb
293
296
  - check-elb-health-fog.rb
@@ -342,6 +345,7 @@ files:
342
345
  - bin/check-beanstalk-health.rb
343
346
  - bin/check-certificate-expiry.rb
344
347
  - bin/check-cloudfront-tag.rb
348
+ - bin/check-cloudwatch-alarm-multi.rb
345
349
  - bin/check-cloudwatch-alarm.rb
346
350
  - bin/check-cloudwatch-alarms.rb
347
351
  - bin/check-cloudwatch-composite-metric.rb
@@ -370,6 +374,7 @@ files:
370
374
  - bin/check-emr-cluster.rb
371
375
  - bin/check-emr-steps.rb
372
376
  - bin/check-eni-status.rb
377
+ - bin/check-expiring-reservations.rb
373
378
  - bin/check-instance-events.rb
374
379
  - bin/check-instance-health.rb
375
380
  - bin/check-instance-reachability.rb
@@ -410,6 +415,7 @@ files:
410
415
  - bin/metrics-elb.rb
411
416
  - bin/metrics-emr-steps.rb
412
417
  - bin/metrics-rds.rb
418
+ - bin/metrics-reservation-utilization.rb
413
419
  - bin/metrics-s3.rb
414
420
  - bin/metrics-ses.rb
415
421
  - bin/metrics-sqs.rb
@@ -444,8 +450,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
444
450
  - !ruby/object:Gem::Version
445
451
  version: '0'
446
452
  requirements: []
447
- rubyforge_project:
448
- rubygems_version: 2.7.7
453
+ rubygems_version: 3.0.8
449
454
  signing_key:
450
455
  specification_version: 4
451
456
  summary: Sensu plugins for working with an AWS environment