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,144 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-emr-cluster
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin checks if a cluster exists.
7
+ #
8
+ # OUTPUT:
9
+ # plain-text
10
+ #
11
+ # PLATFORMS:
12
+ # Linux
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: aws-sdk
16
+ # gem: sensu-plugin
17
+ #
18
+ # USAGE:
19
+ # ./check-emr-cluster.rb --cluster-name MyCluster --aws-region eu-west-1 --use-iam --warning-over 14400 --critical-over 21600
20
+ #
21
+ # NOTES:
22
+ #
23
+ # LICENSE:
24
+ # Copyright (c) 2015, Olivier Bazoud, olivier.bazoud@gmail.com
25
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
26
+ # for details.
27
+ #
28
+
29
+ require 'sensu-plugin/check/cli'
30
+ require 'aws-sdk'
31
+
32
+ class CheckEMRCluster < Sensu::Plugin::Check::CLI
33
+ option :aws_access_key,
34
+ short: '-a AWS_ACCESS_KEY',
35
+ long: '--aws-access-key AWS_ACCESS_KEY',
36
+ description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY'] or provide it as an option",
37
+ default: ENV['AWS_ACCESS_KEY']
38
+
39
+ option :aws_secret_access_key,
40
+ short: '-k AWS_SECRET_KEY',
41
+ long: '--aws-secret-access-key AWS_SECRET_KEY',
42
+ description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_KEY'] or provide it as an option",
43
+ default: ENV['AWS_SECRET_KEY']
44
+
45
+ option :aws_region,
46
+ short: '-r AWS_REGION',
47
+ long: '--aws-region REGION',
48
+ description: 'AWS Region (defaults to us-east-1).',
49
+ default: 'us-east-1'
50
+
51
+ option :use_iam_role,
52
+ short: '-u',
53
+ long: '--use-iam',
54
+ description: 'Use IAM role authenticiation. Instance must have IAM role assigned for this to work'
55
+
56
+ option :cluster_name,
57
+ short: '-b CLUSTER_NAME',
58
+ long: '--cluster-name',
59
+ description: 'The name of the EMR cluster',
60
+ required: true
61
+
62
+ option :warning_over,
63
+ description: 'Warn if cluster\'s age is greater than provided age in seconds',
64
+ short: '-w SECONDS',
65
+ long: '--warning-over SECONDS',
66
+ default: -1,
67
+ proc: proc(&:to_i)
68
+
69
+ option :critical_over,
70
+ description: 'Critical if cluster\'s age is greater than provided age in seconds',
71
+ short: '-c SECONDS',
72
+ long: '--critical-over SECONDS',
73
+ default: -1,
74
+ proc: proc(&:to_i)
75
+
76
+ option :warning_under,
77
+ description: 'Warn if cluster\'s age is lower than provided age in seconds',
78
+ short: '-w SECONDS',
79
+ long: '--warning-under SECONDS',
80
+ default: -1,
81
+ proc: proc(&:to_i)
82
+
83
+ option :critical_under,
84
+ description: 'Critical if cluster\'s age is lower than provided age in seconds',
85
+ short: '-C SECONDS',
86
+ long: '--critical-under SECONDS',
87
+ default: -1,
88
+ proc: proc(&:to_i)
89
+
90
+ def aws_config
91
+ { access_key_id: config[:aws_access_key],
92
+ secret_access_key: config[:aws_secret_access_key],
93
+ region: config[:aws_region] }
94
+ end
95
+
96
+ def humanize(secs)
97
+ [[60, :seconds], [60, :minutes], [24, :hours], [1000, :days]].map do |count, name|
98
+ if secs > 0
99
+ secs, n = secs.divmod(count)
100
+ "#{n.to_i} #{name}"
101
+ end
102
+ end.compact.reverse.join(' ')
103
+ end
104
+
105
+ def run
106
+ aws_config = {}
107
+ if config[:use_iam_role].nil?
108
+ aws_config[:access_key_id] = config[:aws_access_key]
109
+ aws_config[:secret_access_key] = config[:aws_secret_access_key]
110
+ end
111
+
112
+ emr = Aws::EMR::Client.new(aws_config.merge!(region: config[:aws_region]))
113
+ begin
114
+ emr_clusters = emr.list_clusters(created_after: Time.now - 24 * 60 * 60, created_before: Time.now).clusters
115
+ clusters = emr_clusters.select { |c| c.name == config[:cluster_name] }
116
+
117
+ critical "EMR cluster #{config[:cluster_name]} appears #{clusters.size} times" if clusters.size > 1
118
+ critical "EMR cluster #{config[:cluster_name]} not found" if clusters.empty?
119
+
120
+ cluster = clusters.first
121
+ state = cluster.status.state
122
+ if state == 'TERMINATED_WITH_ERRORS'
123
+ critical "EMR cluster #{config[:cluster_name]} state is '#{state}'"
124
+ else
125
+ creation_date_time = cluster.status.timeline.creation_date_time
126
+ end_date_time = cluster.status.timeline.end_date_time || Time.now
127
+ age = end_date_time.to_i - creation_date_time.to_i
128
+ if age >= config[:critical_over]
129
+ critical "EMR cluster #{config[:cluster_name]} - #{humanize(age)} vs. #{humanize(config[:critical_over])}"
130
+ elsif age >= config[:warning_over]
131
+ warning "EMR cluster #{config[:cluster_name]} - #{humanize(age)} vs. #{humanize(config[:warning_over])}"
132
+ elsif age <= config[:critical_under] && state == 'TERMINATED'
133
+ critical "EMR cluster #{config[:cluster_name]} - #{humanize(age)} vs. #{humanize(config[:critical_under])}"
134
+ elsif age <= config[:warning_under] && state == 'TERMINATED'
135
+ warning "EMR cluster #{config[:cluster_name]} - #{humanize(age)} vs. #{humanize(config[:warning_under])}"
136
+ else
137
+ ok "EMR cluster #{config[:cluster_name]} - #{humanize(age)}"
138
+ end
139
+ end
140
+ rescue StandardError => e
141
+ critical "EMR cluster #{config[:cluster_name]} - #{e.message}"
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,90 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-emr-steps
4
+ #
5
+ # DESCRIPTION:
6
+ # Alerts on any failed steps for a cluster in the past 10 minutes.
7
+ #
8
+ # OUTPUT:
9
+ # plain-text
10
+ #
11
+ # DEPENDENCIES:
12
+ # gem: aws-sdk
13
+ # gem: sensu-plugin
14
+ #
15
+ # USAGE:
16
+ # check-emr-steps.rb -r us-west-2 -b 'My Cluster' -t FAILED -c 0
17
+ #
18
+ # This will alert on any failed steps in the past 10 minutes on the latest cluster
19
+ # with the name 'My Cluster'.
20
+ # NOTES:
21
+ #
22
+ # LICENSE:
23
+ # Bryan Absher <bryan.absher@gmail.com>
24
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
25
+ # for details.
26
+
27
+ require 'sensu-plugins-aws'
28
+ require 'sensu-plugin/check/cli'
29
+ require 'aws-sdk'
30
+
31
+ class CheckEMRSteps < Sensu::Plugin::Check::CLI
32
+ include Common
33
+
34
+ option :scheme,
35
+ description: 'Metric naming scheme, text to prepend to metric',
36
+ short: '-s SCHEME',
37
+ long: '--scheme SCHEME',
38
+ default: 'sensu.aws.emr'
39
+
40
+ option :aws_region,
41
+ short: '-r AWS_REGION',
42
+ long: '--aws-region REGION',
43
+ description: 'AWS Region (defaults to us-east-1).',
44
+ default: 'us-east-1'
45
+
46
+ option :cluster_name,
47
+ short: '-b CLUSTER_NAME',
48
+ long: '--cluster-name',
49
+ description: 'The name of the EMR cluster',
50
+ required: true
51
+
52
+ option :status,
53
+ short: '-t STEP_STATUS',
54
+ long: '--step-status',
55
+ description: 'Step status to check, [PENDING RUNNING COMPLETED CANCELLED FAILED INTERRUPTED]',
56
+ default: 'FAILED'
57
+
58
+ option :count,
59
+ short: '-c COUNT',
60
+ long: '--count',
61
+ description: 'Max number of steps with this status.',
62
+ proc: proc(&:to_i),
63
+ default: 0
64
+
65
+ def run
66
+ emr = Aws::EMR::Client.new(aws_config)
67
+ begin
68
+ emr_clusters = emr.list_clusters.clusters
69
+ clusters = emr_clusters.select { |c| c.name == config[:cluster_name] }
70
+ critical "EMR cluster #{config[:cluster_name]} not found" if clusters.empty?
71
+ cluster = clusters.sort_by { |c| c.status.timeline.creation_date_time }.reverse.first
72
+
73
+ steps = emr.list_steps(
74
+ cluster_id: cluster.id,
75
+ step_states: [config[:status]]
76
+ ).steps
77
+
78
+ messages = []
79
+ now = Time.new
80
+ failed = steps.select { |step| now - step.status.timeline.end_date_time < 10 * 60 }
81
+ if failed.size > config[:count]
82
+ failed.each_entry { |step| messages << "Step #{step.id} '#{step.name}' has failed on cluster #{cluster.id} '#{cluster.name}'" }
83
+ if messages.count > 0
84
+ critical("#{messages.count} #{messages.count > 1 ? 'steps have' : 'step has'} failed: #{messages.join(',')}")
85
+ end
86
+ end
87
+ ok
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,110 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-eni-status
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin checks the status of an elastic network interface
7
+ #
8
+ # OUTPUT:
9
+ # plain-text
10
+ #
11
+ # PLATFORMS:
12
+ # Linux
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: aws-sdk-v2
16
+ # gem: sensu-plugin
17
+ #
18
+ # USAGE:
19
+ # check-eni-status -e eni -w in-use -r region
20
+ # check-eni-status -e eni -c available -r region
21
+ #
22
+ # NOTES:
23
+ #
24
+ # LICENSE:
25
+ # Copyright (c) 2013, Damien DURANT <damien.durant@edifixio.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 'sensu-plugins-aws'
32
+ require 'aws-sdk'
33
+
34
+ #
35
+ # Check ENI Status
36
+ #
37
+ class ENIStatus < Sensu::Plugin::Check::CLI
38
+ include Common
39
+
40
+ option :aws_region,
41
+ short: '-r AWS_REGION',
42
+ long: '--aws-region REGION',
43
+ description: 'AWS Region (defaults to us-east-1).',
44
+ default: 'us-east-1'
45
+
46
+ option :eni,
47
+ short: '-e ENI_ID',
48
+ long: '--eni ENI_ID',
49
+ description: 'A comma seperated list of the Elastic Network Interfaces to check',
50
+ default: ''
51
+
52
+ option :warn_status,
53
+ short: '-w STATUS',
54
+ long: '--warn STATUS',
55
+ description: 'ENI status considered to be a warning',
56
+ default: ''
57
+
58
+ option :crit_status,
59
+ short: '-c STATUS',
60
+ long: '--crit STATUS',
61
+ description: 'ENI status considered to be critical',
62
+ default: ''
63
+
64
+ def aws_config
65
+ { access_key_id: config[:aws_access_key],
66
+ secret_access_key: config[:aws_secret_access_key],
67
+ region: config[:aws_region] }
68
+ end
69
+
70
+ def run
71
+ Aws.config.update(aws_config)
72
+ client = Aws::EC2::Client.new
73
+
74
+ if config[:eni].empty?
75
+ critical 'Error, ENI(s) should be specified.'
76
+ end
77
+
78
+ if config[:crit_status].empty?
79
+ if config[:warn_status].empty?
80
+ critical 'Error, either crit_status or warn_status must be specified'
81
+ end
82
+ end
83
+
84
+ warnings = []
85
+ crits = []
86
+
87
+ eni = config[:eni].split(',')
88
+ eni.each do |e|
89
+ status = client.describe_network_interfaces(
90
+ filters: [{ name: 'network-interface-id', values: [e] }]
91
+ )[:network_interfaces].first
92
+
93
+ if status.nil?
94
+ warnings << "No Information found for #{e}"
95
+ elsif config[:crit_status].casecmp(status[:status]).zero?
96
+ crits << "#{e} is #{status[:status]}"
97
+ elsif config[:warn_status].casecmp(status[:status]).zero?
98
+ warnings << "#{e} is #{status[:status]}"
99
+ end
100
+ end
101
+
102
+ if crits.any?
103
+ critical crits.join(', ').to_s
104
+ elsif warnings.any?
105
+ warning warnings.join(', ').to_s
106
+ else
107
+ ok "all interfaces(s): #{eni} are OK"
108
+ end
109
+ end
110
+ 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
+ # 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/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