sensu-plugins-aws-boutetnico 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +3 -0
  3. data/LICENSE +22 -0
  4. data/README.md +333 -0
  5. data/bin/check-alb-target-group-health.rb +100 -0
  6. data/bin/check-asg-instances-created.rb +129 -0
  7. data/bin/check-asg-instances-inservice.rb +109 -0
  8. data/bin/check-autoscaling-cpucredits.rb +160 -0
  9. data/bin/check-beanstalk-elb-metric.rb +123 -0
  10. data/bin/check-beanstalk-health.rb +123 -0
  11. data/bin/check-certificate-expiry.rb +123 -0
  12. data/bin/check-cloudfront-tag.rb +70 -0
  13. data/bin/check-cloudwatch-alarm.rb +102 -0
  14. data/bin/check-cloudwatch-alarms.rb +89 -0
  15. data/bin/check-cloudwatch-composite-metric.rb +199 -0
  16. data/bin/check-cloudwatch-metric.rb +123 -0
  17. data/bin/check-configservice-rules.rb +76 -0
  18. data/bin/check-direct-connect-virtual-interfaces.rb +84 -0
  19. data/bin/check-dynamodb-capacity.rb +194 -0
  20. data/bin/check-dynamodb-throttle.rb +188 -0
  21. data/bin/check-ebs-burst-limit.rb +143 -0
  22. data/bin/check-ebs-snapshots.rb +104 -0
  23. data/bin/check-ec2-cpu_balance.rb +139 -0
  24. data/bin/check-ec2-filter.rb +190 -0
  25. data/bin/check-ec2-network.rb +133 -0
  26. data/bin/check-ecs-service-health.rb +155 -0
  27. data/bin/check-efs-metric.rb +145 -0
  28. data/bin/check-eip-allocation.rb +64 -0
  29. data/bin/check-elasticache-failover.rb +113 -0
  30. data/bin/check-elb-certs.rb +132 -0
  31. data/bin/check-elb-health-fog.rb +114 -0
  32. data/bin/check-elb-health-sdk.rb +176 -0
  33. data/bin/check-elb-health.rb +116 -0
  34. data/bin/check-elb-instances-inservice.rb +103 -0
  35. data/bin/check-elb-latency.rb +166 -0
  36. data/bin/check-elb-nodes.rb +133 -0
  37. data/bin/check-elb-sum-requests.rb +157 -0
  38. data/bin/check-emr-cluster.rb +144 -0
  39. data/bin/check-emr-steps.rb +90 -0
  40. data/bin/check-eni-status.rb +110 -0
  41. data/bin/check-expiring-reservations.rb +117 -0
  42. data/bin/check-instance-events.rb +154 -0
  43. data/bin/check-instance-health.rb +108 -0
  44. data/bin/check-instance-reachability.rb +107 -0
  45. data/bin/check-instances-count.rb +94 -0
  46. data/bin/check-kms-key.rb +73 -0
  47. data/bin/check-rds-events.rb +141 -0
  48. data/bin/check-rds-pending.rb +91 -0
  49. data/bin/check-rds.rb +382 -0
  50. data/bin/check-redshift-events.rb +108 -0
  51. data/bin/check-reserved-instances.rb +80 -0
  52. data/bin/check-route.rb +122 -0
  53. data/bin/check-route53-domain-expiration.rb +78 -0
  54. data/bin/check-s3-bucket-visibility.rb +176 -0
  55. data/bin/check-s3-bucket.rb +86 -0
  56. data/bin/check-s3-object.rb +205 -0
  57. data/bin/check-s3-tag.rb +70 -0
  58. data/bin/check-sensu-client.rb +184 -0
  59. data/bin/check-ses-limit.rb +89 -0
  60. data/bin/check-ses-statistics.rb +149 -0
  61. data/bin/check-sns-subscriptions.rb +52 -0
  62. data/bin/check-sqs-messages.rb +168 -0
  63. data/bin/check-subnet-ip-consumption.rb +234 -0
  64. data/bin/check-trustedadvisor-service-limits.rb +90 -0
  65. data/bin/check-vpc-nameservers.rb +87 -0
  66. data/bin/check-vpc-vpn.rb +98 -0
  67. data/bin/handler-ec2_node.rb +241 -0
  68. data/bin/handler-scale-asg-down.rb +131 -0
  69. data/bin/handler-scale-asg-up.rb +131 -0
  70. data/bin/handler-ses.rb +107 -0
  71. data/bin/handler-sns.rb +64 -0
  72. data/bin/metrics-asg.rb +156 -0
  73. data/bin/metrics-autoscaling-instance-count.rb +101 -0
  74. data/bin/metrics-billing.rb +97 -0
  75. data/bin/metrics-cloudfront.rb +159 -0
  76. data/bin/metrics-ec2-count.rb +137 -0
  77. data/bin/metrics-ec2-filter.rb +97 -0
  78. data/bin/metrics-elasticache.rb +166 -0
  79. data/bin/metrics-elb.rb +169 -0
  80. data/bin/metrics-emr-steps.rb +82 -0
  81. data/bin/metrics-rds.rb +153 -0
  82. data/bin/metrics-reservation-utilization.rb +84 -0
  83. data/bin/metrics-s3.rb +107 -0
  84. data/bin/metrics-ses.rb +62 -0
  85. data/bin/metrics-sqs.rb +98 -0
  86. data/bin/metrics-waf.rb +111 -0
  87. data/lib/sensu-plugins-aws.rb +4 -0
  88. data/lib/sensu-plugins-aws/cloudwatch-common.rb +92 -0
  89. data/lib/sensu-plugins-aws/common.rb +35 -0
  90. data/lib/sensu-plugins-aws/filter.rb +47 -0
  91. data/lib/sensu-plugins-aws/version.rb +8 -0
  92. metadata +456 -0
@@ -0,0 +1,169 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # elb-metrics
4
+ #
5
+ # DESCRIPTION:
6
+ # Gets latency metrics from CloudWatch and puts them in Graphite for longer term storage
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-plugin-aws
18
+ # gem: time
19
+ #
20
+ # USAGE:
21
+ # #YELLOW
22
+ #
23
+ # NOTES:
24
+ # Returns latency statistics by default. You can specify any valid ELB metric type, see
25
+ # http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/CW_Support_For_AWS.html#elb-metricscollected
26
+ #
27
+ # By default fetches statistics from one minute ago. You may need to fetch further back than this;
28
+ # high traffic ELBs can sometimes experience statistic delays of up to 10 minutes. If you experience this,
29
+ # raising a ticket with AWS support should get the problem resolved.
30
+ # As a workaround you can use eg -f 300 to fetch data from 5 minutes ago.
31
+ #
32
+ # LICENSE:
33
+ # Copyright 2013 Bashton Ltd http://www.bashton.com/
34
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
35
+ # for details.
36
+ # Updated by Peter Hoppe <peter.hoppe.extern@bertelsmann.de> 09.11.2016
37
+ # Using aws sdk version 2
38
+
39
+ require 'sensu-plugin/metric/cli'
40
+ require 'aws-sdk'
41
+ require 'sensu-plugins-aws'
42
+ require 'time'
43
+
44
+ class ELBMetrics < Sensu::Plugin::Metric::CLI::Graphite
45
+ include Common
46
+ option :elbname,
47
+ description: 'Name of the Elastic Load Balancer',
48
+ short: '-n ELB_NAME',
49
+ long: '--name ELB_NAME'
50
+
51
+ option :scheme,
52
+ description: 'Metric naming scheme, text to prepend to metric',
53
+ short: '-s SCHEME',
54
+ long: '--scheme SCHEME',
55
+ default: 'elb'
56
+
57
+ option :fetch_age,
58
+ description: 'How long ago to fetch metrics for',
59
+ short: '-f AGE',
60
+ long: '--fetch_age',
61
+ default: 60,
62
+ proc: proc(&:to_i)
63
+
64
+ option :statistic,
65
+ description: 'Statistics type',
66
+ short: '-t STATISTIC',
67
+ long: '--statistic',
68
+ default: ''
69
+
70
+ option :aws_region,
71
+ short: '-r AWS_REGION',
72
+ long: '--aws-region REGION',
73
+ description: 'AWS Region (defaults to us-east-1).',
74
+ default: ENV['AWS_REGION']
75
+
76
+ option :end_time,
77
+ short: '-t T',
78
+ long: '--end-time TIME',
79
+ default: Time.now,
80
+ proc: proc { |a| Time.parse a },
81
+ description: 'CloudWatch metric statistics end time'
82
+
83
+ option :period,
84
+ short: '-p N',
85
+ long: '--period SECONDS',
86
+ default: 60,
87
+ proc: proc(&:to_i),
88
+ description: 'CloudWatch metric statistics period'
89
+
90
+ def cloud_watch
91
+ @cloud_watch = Aws::CloudWatch::Client.new
92
+ end
93
+
94
+ def loadbalancer
95
+ @loadbalancer = Aws::ElasticLoadBalancing::Client.new
96
+ end
97
+
98
+ def cloud_watch_metric(metric_name, value, load_balancer_name)
99
+ cloud_watch.get_metric_statistics(
100
+ namespace: 'AWS/ELB',
101
+ metric_name: metric_name,
102
+ dimensions: [
103
+ {
104
+ name: 'LoadBalancerName',
105
+ value: load_balancer_name
106
+ }
107
+ ],
108
+ statistics: [value],
109
+ start_time: config[:end_time] - config[:fetch_age] - config[:period],
110
+ end_time: config[:end_time] - config[:fetch_age],
111
+ period: config[:period]
112
+ )
113
+ end
114
+
115
+ def print_statistics(load_balancer_name, statistics)
116
+ result = {}
117
+ static_value = {}
118
+ statistics.each do |key, static|
119
+ r = cloud_watch_metric(key, static, load_balancer_name)
120
+ keys = if config[:scheme] == ''
121
+ []
122
+ else
123
+ [config[:scheme]]
124
+ end
125
+ keys.concat [load_balancer_name, key, static]
126
+ metric_key = keys.join('.')
127
+
128
+ static_value[metric_key] = static
129
+ result[metric_key] = r[:datapoints][0] unless r[:datapoints][0].nil?
130
+ end
131
+ result.each do |key, value|
132
+ output key.downcase.to_s, value[static_value[key].downcase], value[:timestamp].to_i
133
+ end
134
+ end
135
+
136
+ def run
137
+ if config[:statistic] == ''
138
+ default_statistic_per_metric = {
139
+ 'Latency' => 'Average',
140
+ 'RequestCount' => 'Sum',
141
+ 'UnHealthyHostCount' => 'Average',
142
+ 'HealthyHostCount' => 'Average',
143
+ 'HTTPCode_Backend_2XX' => 'Sum',
144
+ 'HTTPCode_Backend_3XX' => 'Sum',
145
+ 'HTTPCode_Backend_4XX' => 'Sum',
146
+ 'HTTPCode_Backend_5XX' => 'Sum',
147
+ 'HTTPCode_ELB_4XX' => 'Sum',
148
+ 'HTTPCode_ELB_5XX' => 'Sum',
149
+ 'BackendConnectionErrors' => 'Sum',
150
+ 'SurgeQueueLength' => 'Maximum',
151
+ 'SpilloverCount' => 'Sum'
152
+ }
153
+ statistic = default_statistic_per_metric
154
+ else
155
+ statistic = config[:statistic]
156
+ end
157
+
158
+ begin
159
+ if config[:elbname].nil?
160
+ loadbalancer.describe_load_balancers.load_balancer_descriptions.each do |elb|
161
+ print_statistics(elb.load_balancer_name, statistic)
162
+ end
163
+ else
164
+ print_statistics(config[:elbname], statistic)
165
+ end
166
+ ok
167
+ end
168
+ end
169
+ end
@@ -0,0 +1,82 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # metrics-emr-steps
4
+ #
5
+ # DESCRIPTION:
6
+ # Lists steps in EMR cluster queue with their status.
7
+ #
8
+ # OUTPUT:
9
+ # plain-text
10
+ #
11
+ #
12
+ # DEPENDENCIES:
13
+ # gem: aws-sdk
14
+ # gem: sensu-plugin
15
+ #
16
+ # USAGE:
17
+ # metric-emr-steps.rb -r us-west-2 -b 'prod lateral train'
18
+ #
19
+ # This will list out the counts for each step status for the entire history of the cluster.
20
+ #
21
+ # NOTES:
22
+ #
23
+ # LICENSE:
24
+ # Bryan Absher <bryan.absher@gmail.com>
25
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
26
+ # for details.
27
+
28
+ require 'sensu-plugins-aws'
29
+ require 'sensu-plugin/metric/cli'
30
+ require 'aws-sdk'
31
+
32
+ class EMRStepMetrics < Sensu::Plugin::Metric::CLI::Graphite
33
+ include Common
34
+
35
+ option :scheme,
36
+ description: 'Metric naming scheme, text to prepend to metric',
37
+ short: '-s SCHEME',
38
+ long: '--scheme SCHEME',
39
+ default: 'sensu.aws.emr'
40
+
41
+ option :aws_region,
42
+ short: '-r AWS_REGION',
43
+ long: '--aws-region REGION',
44
+ description: 'AWS Region (defaults to us-east-1).',
45
+ default: 'us-east-1'
46
+
47
+ option :cluster_name,
48
+ short: '-b CLUSTER_NAME',
49
+ long: '--cluster-name',
50
+ description: 'The name of the EMR cluster',
51
+ required: true
52
+
53
+ def count(steps, status)
54
+ steps.count { |step| step.status.state == status }
55
+ end
56
+
57
+ STATUS = %w[PENDING RUNNING COMPLETED CANCELLED FAILED INTERRUPTED].freeze
58
+
59
+ def cluster_steps(emr, cluster_id, data)
60
+ steps = emr.list_steps(
61
+ cluster_id: cluster_id
62
+ ).steps
63
+ STATUS.each_entry { |s| data[s] += count(steps, s) }
64
+ end
65
+
66
+ def run
67
+ emr = Aws::EMR::Client.new(aws_config)
68
+ begin
69
+ emr_clusters = emr.list_clusters.clusters
70
+ clusters = emr_clusters.select { |c| c.name == config[:cluster_name] }
71
+ critical "EMR cluster #{config[:cluster_name]} not found" if clusters.empty?
72
+ cluster = clusters.sort_by { |c| c.status.timeline.creation_date_time }.reverse.first
73
+ data = {}
74
+ STATUS.each_entry { |status| data[status] = 0 }
75
+ cluster_steps(emr, cluster.id, data)
76
+ safe_name = config[:cluster_name].tr(' ', '_')
77
+ output config[:scheme] + '.' + safe_name + '.id.' + cluster.id
78
+ STATUS.each_entry { |status| output config[:scheme] + '.' + safe_name + '.step.' + status, data[status] }
79
+ end
80
+ ok
81
+ end
82
+ end
@@ -0,0 +1,153 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # rds-metrics
4
+ #
5
+ # DESCRIPTION:
6
+ # Gets RDS metrics from CloudWatch and puts them in Graphite for longer term storage
7
+ #
8
+ # OUTPUT:
9
+ # metric-data
10
+ #
11
+ # PLATFORMS:
12
+ # Linux
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: sensu-plugin
16
+ #
17
+ # USAGE:
18
+ # rds-metrics --aws-region eu-west-1
19
+ # rds-metrics --aws-region eu-west-1 --name sr2x8pbti0eon1
20
+ #
21
+ # NOTES:
22
+ # Returns all RDS statistics for all RDS instances in this account unless you specify --name
23
+ #
24
+ # LICENSE:
25
+ # Peter Hoppe <peter.hoppe.extern@bertelsmann.de>
26
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
27
+ # for details.
28
+ #
29
+
30
+ require 'sensu-plugins-aws'
31
+ require 'sensu-plugin/metric/cli'
32
+ require 'aws-sdk'
33
+ require 'time'
34
+
35
+ class RDSMetrics < Sensu::Plugin::Metric::CLI::Graphite
36
+ include Common
37
+ option :scheme,
38
+ description: 'Metric naming scheme, text to prepend to metric',
39
+ short: '-s SCHEME',
40
+ long: '--scheme SCHEME'
41
+
42
+ option :aws_region,
43
+ short: '-r AWS_REGION',
44
+ long: '--aws-region REGION',
45
+ description: 'AWS Region (defaults to us-east-1).',
46
+ default: ENV['AWS_REGION']
47
+
48
+ option :db_instance_id,
49
+ short: '-i N',
50
+ long: '--db-instance-id NAME',
51
+ description: 'DB instance identifier'
52
+
53
+ option :end_time,
54
+ short: '-t T',
55
+ long: '--end-time TIME',
56
+ default: Time.now,
57
+ proc: proc { |a| Time.parse a },
58
+ description: 'CloudWatch metric statistics end time'
59
+
60
+ option :fetch_age,
61
+ description: 'How long ago to fetch metrics from',
62
+ short: '-f AGE',
63
+ long: '--fetch-age',
64
+ default: 0,
65
+ proc: proc(&:to_i)
66
+
67
+ option :period,
68
+ short: '-p N',
69
+ long: '--period SECONDS',
70
+ default: 60,
71
+ proc: proc(&:to_i),
72
+ description: 'CloudWatch metric statistics period'
73
+
74
+ option :statistics,
75
+ short: '-S N',
76
+ long: '--statistics NAME',
77
+ default: :average,
78
+ proc: proc { |a| a.downcase.intern },
79
+ description: 'CloudWatch statistics method'
80
+
81
+ def rds
82
+ @rds = Aws::RDS::Client.new
83
+ end
84
+
85
+ def cloud_watch
86
+ @cloud_watch = Aws::CloudWatch::Client.new
87
+ end
88
+
89
+ def find_db_instance(id)
90
+ db = rds.describe_db_instances.db_instances.detect { |db_instance| db_instance.db_instance_identifier == id }
91
+ unknown 'DB instance not found.' if db.nil?
92
+ db
93
+ end
94
+
95
+ def cloud_watch_metric(metric_name, value)
96
+ cloud_watch.get_metric_statistics(
97
+ namespace: 'AWS/RDS',
98
+ metric_name: metric_name,
99
+ dimensions: [
100
+ {
101
+ name: 'DBInstanceIdentifier',
102
+ value: value
103
+ }
104
+ ],
105
+ start_time: config[:end_time] - config[:fetch_age] - config[:period],
106
+ end_time: config[:end_time] - config[:fetch_age],
107
+ statistics: [config[:statistics].to_s.capitalize],
108
+ period: config[:period]
109
+ )
110
+ end
111
+
112
+ def run
113
+ statistic_type = {
114
+ 'CPUUtilization' => 'Average',
115
+ 'DatabaseConnections' => 'Average',
116
+ 'FreeStorageSpace' => 'Average',
117
+ 'ReadIOPS' => 'Average',
118
+ 'ReadLatency' => 'Average',
119
+ 'ReadThroughput' => 'Average',
120
+ 'WriteIOPS' => 'Average',
121
+ 'WriteLatency' => 'Average',
122
+ 'WriteThroughput' => 'Average',
123
+ 'ReplicaLag' => 'Average',
124
+ 'SwapUsage' => 'Average',
125
+ 'BinLogDiskUsage' => 'Average',
126
+ 'DiskQueueDepth' => 'Average'
127
+ }
128
+
129
+ @db_instance = find_db_instance config[:db_instance_id]
130
+ @message = "#{config[:db_instance_id]}: "
131
+
132
+ result = {}
133
+
134
+ rdsname = @db_instance.db_instance_identifier
135
+ full_scheme =
136
+ if config[:scheme].nil?
137
+ rdsname
138
+ else
139
+ config[:scheme] + '.' + rdsname
140
+ end
141
+
142
+ statistic_type.each_key do |key, _value|
143
+ r = cloud_watch_metric key, rdsname
144
+ result[full_scheme + '.' + key] = r[:datapoints][0] unless r[:datapoints][0].nil?
145
+ end
146
+ unless result.nil?
147
+ result.each do |key, value|
148
+ output key.downcase.to_s, value.average, value[:timestamp].to_i
149
+ end
150
+ end
151
+ exit
152
+ end
153
+ 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