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,107 @@
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'
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['check']['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 region
56
+ settings['ses']['region'] || 'us-east-1'
57
+ end
58
+
59
+ def handle
60
+ mail_to = build_mail_to_list
61
+ body = <<-BODY.gsub(/^\s+/, '')
62
+ #{@event['check']['output']}
63
+ Host: #{@event['client']['name']}
64
+ Timestamp: #{Time.at(@event['check']['issued'])}
65
+ Address: #{@event['client']['address']}
66
+ Check Name: #{@event['check']['name']}
67
+ Command: #{@event['check']['command']}
68
+ Status: #{@event['check']['status']}
69
+ Occurrences: #{@event['occurrences']}
70
+ BODY
71
+
72
+ subject = if @event['check']['notification'].nil?
73
+ "#{action_to_string} - #{event_name}: #{status_to_string}"
74
+ else
75
+ "#{action_to_string} - #{event_name}: #{@event['check']['notification']}"
76
+ end
77
+
78
+ message = {
79
+ subject: {
80
+ data: subject
81
+ },
82
+ body: {
83
+ text: {
84
+ data: body
85
+ }
86
+ }
87
+ }
88
+
89
+ ses = Aws::SES::Client.new(region: region)
90
+
91
+ begin
92
+ Timeout.timeout(10) do
93
+ ses.send_email(
94
+ source: mail_from,
95
+ destination: {
96
+ to_addresses: mail_to.split(',')
97
+ },
98
+ message: message
99
+ )
100
+
101
+ puts 'mail -- sent alert for ' + event_name + ' to ' + mail_to.to_s
102
+ end
103
+ rescue Timeout::Error
104
+ puts 'mail -- timed out while attempting to ' + @event['action'] + ' an incident -- ' + event_name
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Send notifications to an SNS topic
4
+ #
5
+ # Requires the aws-sdk gem.
6
+ #
7
+ # See README for usage information
8
+ #
9
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
10
+ # for details
11
+
12
+ require 'sensu-handler'
13
+ require 'aws-sdk'
14
+ require 'erubis'
15
+
16
+ class SnsNotifier < Sensu::Handler
17
+ def topic_arn
18
+ settings['sns']['topic_arn']
19
+ end
20
+
21
+ def region
22
+ settings['sns']['region'] || 'us-east-1'
23
+ end
24
+
25
+ def event_name
26
+ "#{@event['client']['name']}/#{@event['check']['name']}"
27
+ end
28
+
29
+ def message
30
+ template = if template_file && File.readable?(template_file)
31
+ File.read(template_file)
32
+ else
33
+ <<-BODY.gsub(/^\s+/, '')
34
+ <%= @event['check']['notification'] || @event['check']['output'] %>
35
+ BODY
36
+ end
37
+ eruby = Erubis::Eruby.new(template)
38
+ eruby.result(binding)
39
+ end
40
+
41
+ def template_file
42
+ settings['sns']['template_file']
43
+ end
44
+
45
+ def handle
46
+ sns = Aws::SNS::Client.new(region: region)
47
+
48
+ subject = if @event['action'].eql?('resolve')
49
+ "RESOLVED - [#{event_name}]"
50
+ else
51
+ "ALERT - [#{event_name}]"
52
+ end
53
+
54
+ options = {
55
+ subject: subject,
56
+ message: "#{subject} - #{message}",
57
+ topic_arn: topic_arn
58
+ }
59
+
60
+ sns.publish(options)
61
+ rescue StandardError => e
62
+ puts "Exception occured in SnsNotifier: #{e.message}", e.backtrace
63
+ end
64
+ end
@@ -0,0 +1,156 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # asg-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
+ #
22
+ #
23
+ # NOTES:
24
+ # Returns latency statistics by default. You can specify any valid ASG metric type, see
25
+ # https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/as-metricscollected.html
26
+ #
27
+ # LICENSE:
28
+ # Peter Hoppe <peter.hoppe.extern@bertelsmann.de>
29
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
30
+ # for details.
31
+ #
32
+
33
+ require 'sensu-plugin/metric/cli'
34
+ require 'aws-sdk'
35
+ require 'sensu-plugins-aws'
36
+ require 'time'
37
+
38
+ class ASGMetrics < Sensu::Plugin::Metric::CLI::Graphite
39
+ include Common
40
+ option :asgname,
41
+ description: 'Name of the Auto Scaling Group',
42
+ short: '-n ASG_NAME',
43
+ long: '--name ASG_NAME'
44
+
45
+ option :scheme,
46
+ description: 'Metric naming scheme, text to prepend to metric',
47
+ short: '-s SCHEME',
48
+ long: '--scheme SCHEME'
49
+
50
+ option :fetch_age,
51
+ description: 'How long ago to fetch metrics for',
52
+ short: '-f AGE',
53
+ long: '--fetch_age',
54
+ default: 60,
55
+ proc: proc(&:to_i)
56
+
57
+ option :metric,
58
+ description: 'Metric to fetch',
59
+ short: '-m METRIC',
60
+ long: '--metric',
61
+ default: 'GroupInServiceInstances'
62
+
63
+ option :statistic,
64
+ description: 'Statistic type',
65
+ short: '-t STATISTIC',
66
+ long: '--statistic',
67
+ default: 'Sum'
68
+
69
+ option :aws_region,
70
+ short: '-r AWS_REGION',
71
+ long: '--aws-region REGION',
72
+ description: 'AWS Region (defaults to us-east-1).',
73
+ default: ENV['AWS_REGION']
74
+
75
+ option :end_time,
76
+ short: '-t T',
77
+ long: '--end-time TIME',
78
+ default: Time.now,
79
+ proc: proc { |a| Time.parse a },
80
+ description: 'CloudWatch metric statistics end time'
81
+
82
+ option :period,
83
+ short: '-p N',
84
+ long: '--period SECONDS',
85
+ default: 60,
86
+ proc: proc(&:to_i),
87
+ description: 'CloudWatch metric statistics period'
88
+
89
+ def cloud_watch
90
+ @cloud_watch = Aws::CloudWatch::Client.new
91
+ end
92
+
93
+ def asg
94
+ @asg = Aws::AutoScaling::Client.new
95
+ end
96
+
97
+ def cloud_watch_metric(metric_name, value, asg_name)
98
+ cloud_watch.get_metric_statistics(
99
+ namespace: 'AWS/AutoScaling',
100
+ metric_name: metric_name,
101
+ dimensions: [
102
+ {
103
+ name: 'AutoScalingGroupName',
104
+ value: asg_name
105
+ }
106
+ ],
107
+ statistics: [value],
108
+ start_time: config[:end_time] - config[:period],
109
+ end_time: config[:end_time],
110
+ period: config[:period]
111
+ )
112
+ end
113
+
114
+ def print_statistics(asg_name, statistics)
115
+ result = {}
116
+ statistics.each do |key, static|
117
+ r = cloud_watch_metric(key, static, asg_name)
118
+ keys =
119
+ if config[:scheme].nil?
120
+ []
121
+ else
122
+ [config[:scheme]]
123
+ end
124
+ keys.concat ['AutoScalingGroup', asg_name.tr(' ', '_'), key, static]
125
+
126
+ result[keys.join('.')] = r[:datapoints].first unless r[:datapoints].first.nil?
127
+ end
128
+ result.each do |key, value|
129
+ output key.downcase.to_s, value[config[:statistic].downcase], value[:timestamp].to_i
130
+ end
131
+ end
132
+
133
+ def run
134
+ statistic = {
135
+ 'GroupMinSize' => config[:statistic],
136
+ 'GroupMaxSize' => config[:statistic],
137
+ 'GroupDesiredCapacity' => config[:statistic],
138
+ 'GroupInServiceInstances' => config[:statistic],
139
+ 'GroupPendingInstances' => config[:statistic],
140
+ 'GroupStandbyInstances' => config[:statistic],
141
+ 'GroupTerminatingInstances' => config[:statistic],
142
+ 'GroupTotalInstances' => config[:statistic]
143
+ }
144
+
145
+ begin
146
+ if config[:asgname].nil?
147
+ asg.describe_auto_scaling_groups.auto_scaling_groups.each do |autoscalinggroup|
148
+ print_statistics(autoscalinggroup.auto_scaling_group_name, statistic)
149
+ end
150
+ else
151
+ print_statistics(config[:asgname], statistic)
152
+ end
153
+ ok
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,101 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # metrics-autoscaling-instance-count
4
+ #
5
+ # DESCRIPTION:
6
+ # Get a count of instances in a given AutoScaling group
7
+ #
8
+ # OUTPUT:
9
+ # metric-data
10
+ #
11
+ # PLATFORMS:
12
+ # Linux
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: aws-sdk-v1
16
+ # gem: sensu-plugin
17
+ #
18
+ # USAGE:
19
+ # #YELLOW
20
+ #
21
+ # NOTES:
22
+ #
23
+ # LICENSE:
24
+ # Copyright 2013 Bashton Ltd http://www.bashton.com/
25
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
26
+ # for details.
27
+ #
28
+
29
+ require 'sensu-plugin/metric/cli'
30
+ require 'aws-sdk'
31
+
32
+ class AutoScalingInstanceCountMetrics < Sensu::Plugin::Metric::CLI::Graphite
33
+ option :groupname,
34
+ description: 'Name of the AutoScaling group',
35
+ short: '-g GROUP_NAME',
36
+ long: '--autoscaling-group GROUP_NAME',
37
+ default: false
38
+
39
+ option :scheme,
40
+ description: 'Metric naming scheme, text to prepend to metric',
41
+ short: '-s SCHEME',
42
+ long: '--scheme SCHEME',
43
+ default: ''
44
+
45
+ option :aws_access_key,
46
+ short: '-a AWS_ACCESS_KEY',
47
+ long: '--aws-access-key AWS_ACCESS_KEY',
48
+ description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY'] or provide it as an option",
49
+ default: ENV['AWS_ACCESS_KEY']
50
+
51
+ option :aws_secret_access_key,
52
+ short: '-k AWS_SECRET_KEY',
53
+ long: '--aws-secret-access-key AWS_SECRET_KEY',
54
+ description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_KEY'] or provide it as an option",
55
+ default: ENV['AWS_SECRET_KEY']
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
+ option :include_name,
64
+ short: '-n',
65
+ long: '--include-name',
66
+ description: "Includes any offending instance's 'Name' tag in the metric output",
67
+ default: false
68
+
69
+ def aws_config
70
+ { access_key_id: config[:aws_access_key],
71
+ secret_access_key: config[:aws_secret_access_key],
72
+ region: config[:aws_region] }
73
+ end
74
+
75
+ def autoscaling_groups
76
+ client = Aws::AutoScaling::Client.new(aws_config)
77
+ client.describe_auto_scaling_groups[:auto_scaling_groups].map(&:auto_scaling_group_name)
78
+ end
79
+
80
+ def run
81
+ begin
82
+ groupnames ||= config[:groupname] ? [config[:groupname]] : autoscaling_groups
83
+ groupnames.each do |g|
84
+ as = Aws::AutoScaling::AutoScalingGroup.new aws_config.merge!(name: g)
85
+ count = as.instances.map(&:lifecycle_state).count('InService')
86
+ scheme_name ||= config[:include_name] ? as.data[:tags].select { |tag| tag[:key] == 'Name' }[0][:value] : g
87
+ graphitepath =
88
+ if config[:scheme] == ''
89
+ "#{scheme_name}.autoscaling.instance_count"
90
+ else
91
+ "#{config[:scheme]}.#{scheme_name}.instance_count"
92
+ end
93
+ output graphitepath, count
94
+ end
95
+ rescue StandardError => e
96
+ puts "Error: exception: #{e}"
97
+ critical
98
+ end
99
+ ok
100
+ end
101
+ end
@@ -0,0 +1,97 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # s3-billing
4
+ #
5
+ # DESCRIPTION:
6
+ # Gets Billing 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-plugins-aws
18
+ #
19
+ # USAGE:
20
+ # metrics-billing.rb
21
+ #
22
+ # NOTES:
23
+ #
24
+ # LICENSE:
25
+ # Copyright (c) 2015, Olivier Bazoud, olivier.bazoud@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 BillingMetrics < Sensu::Plugin::Metric::CLI::Graphite
35
+ include Common
36
+
37
+ option :services_name,
38
+ short: '-S SERVICES_NAME',
39
+ long: '--services-name SERVICES_NAME',
40
+ description: 'The name of the AWS service (http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/billing-metricscollected.html)',
41
+ default: 'AmazonEC2,AWSDataTransfer'
42
+
43
+ option :scheme,
44
+ description: 'Metric naming scheme, text to prepend to metric',
45
+ short: '-s SCHEME',
46
+ long: '--scheme SCHEME',
47
+ default: 'sensu.aws.billing'
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
+ def run
56
+ begin
57
+ cw = Aws::CloudWatch::Client.new(aws_config)
58
+ now = Time.now
59
+ r = cw.get_metric_statistics(
60
+ namespace: 'AWS/Billing',
61
+ metric_name: 'EstimatedCharges',
62
+ dimensions: [
63
+ {
64
+ name: 'Currency',
65
+ value: 'USD'
66
+ }
67
+ ],
68
+ start_time: (now.utc - 6 * 60 * 60).iso8601,
69
+ end_time: now.utc.iso8601,
70
+ period: 6 * 60 * 60,
71
+ statistics: ['Maximum'],
72
+ unit: 'None'
73
+ )
74
+ output "#{config[:scheme]}.total.estimated_charges", r[:datapoints][0].maximum, r[:datapoints][0][:timestamp].to_i unless r[:datapoints][0].nil?
75
+
76
+ config[:services_name].split(',').each do |service_name|
77
+ r = cw.get_metric_statistics(
78
+ namespace: 'AWS/Billing',
79
+ metric_name: 'EstimatedCharges',
80
+ dimensions: [
81
+ { name: 'Currency', value: 'USD' },
82
+ { name: 'ServiceName', value: service_name }
83
+ ],
84
+ start_time: (now.utc - 6 * 60 * 60).iso8601,
85
+ end_time: now.utc.iso8601,
86
+ period: 6 * 60 * 60,
87
+ statistics: ['Maximum'],
88
+ unit: 'None'
89
+ )
90
+ output "#{config[:scheme]}.total.#{service_name}", r[:datapoints][0].maximum, r[:datapoints][0][:timestamp].to_i unless r[:datapoints][0].nil?
91
+ end
92
+ rescue StandardError => e
93
+ critical "Error: exception: #{e}"
94
+ end
95
+ ok
96
+ end
97
+ end