sensu-plugins-aws 2.0.1 → 2.1.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
  SHA1:
3
- metadata.gz: 207ae0c8a468edf766ab233945bee9bb6046b85f
4
- data.tar.gz: 90e1e84ba225762c306219b60b545495c9e2639a
3
+ metadata.gz: 2efbcaa411b6ef7da6f0c0217d3949b8a94ecce0
4
+ data.tar.gz: 908abecb23899de8f95741c7fbc515031ec9d149
5
5
  SHA512:
6
- metadata.gz: 7246d4d4da7a7d74d7121ce334d0e228afc7667a9b6ae98b485f05a0d029308729430d87a6af0da77b4133dd14a993d008ed8bd0394f886930fcdf6b15e34349
7
- data.tar.gz: 7cf1528e5c8126f2e92e30210562ed12f23ac42fadf9384b4eb3acb60d167b894b3e408ae073820ad03d3597178b39696e772db4eaeb7341391a20d9d29bdfec
6
+ metadata.gz: 9735551c5d5a0117dcfab9709ddf7a572cb0ebef73bb079bf0f1e450c81d805dd744a4dbb3454ba51b21e6f7b24d8dc5172452b4ee67b49deb343218c4966ba0
7
+ data.tar.gz: 69fe7444c11198923d7d4ec4f63f03ba3109997eccc62c0a8ed132183a8d8badaac129864cf83f7c973bb59e92409f786a5de754c1036aafdd6b0a5ed63a1493
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -5,6 +5,27 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
5
5
 
6
6
  ## Unreleased
7
7
 
8
+ ## [2.1.0] - 2016-01-15
9
+ ### Added
10
+ - check-elb-health-sdk.rb: add option for warning instead of critical when unhealthy instances are found
11
+ - check-rds.rb: add M4 instances
12
+ - handler-sns.rb: add option to use a template to render body mail
13
+ - check-rds-events.rb: add RDS event message to output
14
+ - Added check-cloudwatch-metric that checks the values of cloudwatch metrics
15
+ - Added check-beanstalk-elb-metric that checks an ELB used in a Beanstalk environment
16
+ - Added check-certificate-expiry that checks the expiration date of certificates loaded into IAM
17
+ - Added test cases for check-certificate-expiry.rb
18
+
19
+ ### Changed
20
+ - handler-ec2_node.rb: Update to new API event naming and simplifying ec2_node_should_be_deleted method and fixing match that will work with any user state defined, also improved docs
21
+ - metrics-elb-full.rb: flush hash in-between iterations
22
+ - check-ses-limit.rb: move to AWS-SDK v2, use common module, return unknown on empty responses
23
+
24
+ ### Fixed
25
+ - metrics-memcached.rb: Fixed default scheme
26
+ - Fix typo in cloudwatch comparison check
27
+
28
+ ## [2.0.1] - 2015-11-03
8
29
  ### Changed
9
30
  - pinned all dependencies
10
31
  - set gemspec to require > `2.0.0`
data/README.md CHANGED
@@ -11,6 +11,10 @@
11
11
 
12
12
  **check-autoscaling-cpucredits.rb**
13
13
 
14
+ **check-beanstalk-elb-metric.rb**
15
+
16
+ **check-certificate-expiry.rb**
17
+
14
18
  **check-cloudwatch-alarm**
15
19
 
16
20
  **check-dynamodb-capacity.rb**
@@ -87,6 +91,8 @@
87
91
  ## Files
88
92
 
89
93
  * /bin/check-autoscaling-cpucredits.rb
94
+ * /bin/check-beanstalk-elb-metric.rb
95
+ * /bin/check-certificate-expiry.rb
90
96
  * /bin/check-cloudwatch-alarm.rb
91
97
  * /bin/check-dynamodb-capacity.rb
92
98
  * /bin/check-dynamodb-throttle.rb
@@ -0,0 +1,123 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-beanstalk-elb-metric
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin finds the desired ELB in a beanstalk environment and queries
7
+ # for the requested cloudwatch metric for that ELB
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-beanstalk-elb-metric -e MyAppEnv -m Latency -c 100
21
+ #
22
+ # NOTES:
23
+ #
24
+ # LICENSE:
25
+ # Andrew Matheny
26
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
27
+ # for details.
28
+ #
29
+
30
+ require 'sensu-plugins-aws/cloudwatch-common'
31
+ require 'sensu-plugin/check/cli'
32
+ require 'aws-sdk'
33
+
34
+ class BeanstalkELBCheck < Sensu::Plugin::Check::CLI
35
+ option :environment,
36
+ description: 'Application environment name',
37
+ short: '-e ENVIRONMENT_NAME',
38
+ long: '--environment ENVIRONMENT_NAME',
39
+ required: true
40
+
41
+ option :elb_idx,
42
+ description: 'Index of ELB. Useful for multiple ELB environments',
43
+ short: '-i ELB_NUM',
44
+ long: '--elb-idx ELB_NUM',
45
+ default: 0,
46
+ proc: proc(&:to_i)
47
+
48
+ option :metric_name,
49
+ description: 'ELB CloudWatch Metric',
50
+ short: '-m METRIC_NAME',
51
+ long: '--metric METRIC_NAME',
52
+ required: true
53
+
54
+ option :period,
55
+ description: 'CloudWatch metric statistics period. Must be a multiple of 60',
56
+ short: '-p N',
57
+ long: '--period SECONDS',
58
+ default: 60,
59
+ proc: proc(&:to_i)
60
+
61
+ option :statistics,
62
+ short: '-s N',
63
+ long: '--statistics NAME',
64
+ default: 'Average',
65
+ description: 'CloudWatch statistics method'
66
+
67
+ option :unit,
68
+ short: '-u UNIT',
69
+ long: '--unit UNIT',
70
+ description: 'CloudWatch metric unit'
71
+
72
+ option :critical,
73
+ description: 'Trigger a critical when value is over VALUE',
74
+ short: '-c VALUE',
75
+ long: '--critical VALUE',
76
+ proc: proc(&:to_f),
77
+ required: true
78
+
79
+ option :warning,
80
+ description: 'Trigger a critical when value is over VALUE',
81
+ short: '-w VALUE',
82
+ long: '--warning VALUE',
83
+ proc: proc(&:to_f)
84
+
85
+ option :compare,
86
+ description: 'Comparision operator for threshold: equal, not, greater, less',
87
+ short: '-o OPERATION',
88
+ long: '--opertor OPERATION',
89
+ default: 'greater'
90
+
91
+ option :no_data_ok,
92
+ short: '-n',
93
+ long: '--allow-no-data',
94
+ description: 'Returns ok if no data is returned from the metric',
95
+ boolean: true,
96
+ default: false
97
+
98
+ include CloudwatchCommon
99
+
100
+ def metric_desc
101
+ @metric_desc ||= "BeanstalkELB/#{config[:environment]}/#{elb_name}/#{config[:metric_name]}"
102
+ end
103
+
104
+ def elb_name
105
+ @elb_name ||= Aws::ElasticBeanstalk::Client.new
106
+ .describe_environment_resources(environment_name: config[:environment])
107
+ .environment_resources
108
+ .load_balancers[config[:elb_idx]]
109
+ .name
110
+ end
111
+
112
+ def run
113
+ new_config = config.clone
114
+ new_config[:namespace] = 'AWS/ELB'
115
+ new_config[:dimensions] = [
116
+ {
117
+ name: 'LoadBalancerName',
118
+ value: elb_name
119
+ }
120
+ ]
121
+ check new_config
122
+ end
123
+ end
@@ -0,0 +1,124 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-certificate-expiry
4
+ #
5
+ # DESCRIPTION:
6
+ # Checks expiration date on certificate. If no certificate is passed it checks
7
+ # all certs in account. Will use default provider if no access key and secret are passed
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-certificate-expiry.rb --server-certificate-name ${cert_name} --warning 45 --critical 30
21
+ #
22
+ # NOTES:
23
+ # Based heavily on Yohei Kawahara's check-ec2-network
24
+ #
25
+ # LICENSE:
26
+ # Zach Bintliff <zbintliff@gmail.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 'aws-sdk'
33
+
34
+ class CheckCertificateExpiry < Sensu::Plugin::Check::CLI
35
+ option :aws_access_key,
36
+ short: '-a AWS_ACCESS_KEY',
37
+ long: '--aws-access-key AWS_ACCESS_KEY',
38
+ description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY'] or provide it as an option. Uses Default Credential if none are passed",
39
+ default: ENV['AWS_ACCESS_KEY']
40
+
41
+ option :aws_secret_access_key,
42
+ short: '-k AWS_SECRET_KEY',
43
+ long: '--aws-secret-access-key AWS_SECRET_KEY',
44
+ description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_KEY'] or provide it as an option. Uses Default Credential if none are passed",
45
+ default: ENV['AWS_SECRET_KEY']
46
+
47
+ option :aws_region,
48
+ short: '-r AWS_REGION',
49
+ long: '--aws-region REGION',
50
+ description: 'AWS Region (defaults to us-east-1).',
51
+ default: 'us-east-1'
52
+
53
+ option :server_certificate_name,
54
+ short: '-n CERTIFICATE_NAME',
55
+ long: '--server-certificate-name CERTIFICATE_NAME',
56
+ description: 'Certificate to check. Checks all if not passed'
57
+
58
+ option :warning,
59
+ short: '-w N',
60
+ long: '--warning VALUE',
61
+ description: 'Issue a warning if the Cert will expire in under VALUE days'
62
+
63
+ option :critical,
64
+ short: '-c N',
65
+ long: '--critical VALUE',
66
+ description: 'Issue a critical if the Cert will expire in under VALUE days',
67
+ default: 0
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
+ }
74
+ end
75
+
76
+ def aws_client(opts = {})
77
+ config = aws_config.merge(opts)
78
+ @aws_client ||= Aws::IAM::Client.new config
79
+ end
80
+
81
+ def get_cert(cert_name)
82
+ aws_client.get_server_certificate(server_certificate_name: cert_name).server_certificate.server_certificate_metadata
83
+ end
84
+
85
+ def check_expiry(cert, reportstring, warnflag, critflag)
86
+ expiration = cert.expiration.gmtime
87
+ current_time = Time.now.gmtime
88
+ time_to_expiry = (expiration - current_time).to_i / (24 * 60 * 60) ## Seconds to days, integer division
89
+
90
+ if time_to_expiry <= config[:critical].to_i
91
+ critflag = true
92
+ if time_to_expiry < 1
93
+ reportstring += " #{cert.server_certificate_name} certificate is expired!"
94
+ else
95
+ reportstring += " #{cert.server_certificate_name} certificate expires in #{time_to_expiry} days;"
96
+ end
97
+ elsif time_to_expiry <= config[:warning].to_i
98
+ warnflag = true
99
+ reportstring += " #{cert.server_certificate_name} certificate expires in #{time_to_expiry} days;"
100
+ end
101
+ [reportstring, warnflag, critflag]
102
+ end
103
+
104
+ def run
105
+ warnflag = false
106
+ critflag = false
107
+ reportstring = ''
108
+ if config[:server_certificate_name].nil?
109
+ aws_client.list_server_certificates.server_certificate_metadata_list.each do |cert|
110
+ reportstring, warnflag, critflag = check_expiry(cert, reportstring, warnflag, critflag)
111
+ end
112
+ else
113
+ reportstring, warnflag, critflag = check_expiry(get_cert(config[:server_certificate_name]), reportstring, warnflag, critflag)
114
+ end
115
+
116
+ if critflag
117
+ critical reportstring
118
+ elsif warnflag
119
+ warning reportstring
120
+ else
121
+ ok 'All checked Certificates are ok'
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,117 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-cloudwatch-metric
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin retrieves the value of a cloudwatch metric and triggers
7
+ # alarms based on the thresholds specified
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-metric -n CPUUtilization -d InstanceId=i-12345678,AvailabilityZone=us-east-1a -c 90
21
+ #
22
+ # NOTES:
23
+ #
24
+ # LICENSE:
25
+ # Andrew Matheny
26
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
27
+ # for details.
28
+ #
29
+
30
+ require 'sensu-plugins-aws/cloudwatch-common'
31
+ require 'sensu-plugin/check/cli'
32
+ require 'aws-sdk'
33
+
34
+ class CloudWatchMetricCheck < Sensu::Plugin::Check::CLI
35
+ option :namespace,
36
+ description: 'CloudWatch namespace for metric',
37
+ short: '-n NAME',
38
+ long: '--namespace NAME',
39
+ default: 'AWS/EC2'
40
+
41
+ option :metric_name,
42
+ description: 'Metric name',
43
+ short: '-m NAME',
44
+ long: '--metric NAME',
45
+ required: true
46
+
47
+ option :dimensions,
48
+ description: 'Comma delimited list of DimName=Value',
49
+ short: '-d DIMENSIONS',
50
+ long: '--dimensions DIMENSIONS',
51
+ proc: proc { |d| CloudWatchMetricCheck.parse_dimensions d },
52
+ default: ''
53
+
54
+ option :period,
55
+ description: 'CloudWatch metric statistics period. Must be a multiple of 60',
56
+ short: '-p N',
57
+ long: '--period SECONDS',
58
+ default: 60,
59
+ proc: proc(&:to_i)
60
+
61
+ option :statistics,
62
+ short: '-s N',
63
+ long: '--statistics NAME',
64
+ default: 'Average',
65
+ description: 'CloudWatch statistics method'
66
+
67
+ option :unit,
68
+ short: '-u UNIT',
69
+ long: '--unit UNIT',
70
+ description: 'CloudWatch metric unit'
71
+
72
+ option :critical,
73
+ description: 'Trigger a critical when value is over VALUE',
74
+ short: '-c VALUE',
75
+ long: '--critical VALUE',
76
+ proc: proc(&:to_f),
77
+ required: true
78
+
79
+ option :warning,
80
+ description: 'Trigger a critical when value is over VALUE',
81
+ short: '-w VALUE',
82
+ long: '--warning VALUE',
83
+ proc: proc(&:to_f)
84
+
85
+ option :compare,
86
+ description: 'Comparision operator for threshold: equal, not, greater, less',
87
+ short: '-o OPERATION',
88
+ long: '--opertor OPERATION',
89
+ default: 'greater'
90
+
91
+ option :no_data_ok,
92
+ short: '-n',
93
+ long: '--allow-no-data',
94
+ description: 'Returns ok if no data is returned from the metric',
95
+ boolean: true,
96
+ default: false
97
+
98
+ include CloudwatchCommon
99
+
100
+ def self.parse_dimensions(dimension_string)
101
+ dimension_string.split(',')
102
+ .collect { |d| d.split '=' }
103
+ .collect { |a| { name: a[0], value: a[1] } }
104
+ end
105
+
106
+ def dimension_string
107
+ config[:dimensions].map { |d| "#{d[:name]}=#{d[:value]}" }.join('&')
108
+ end
109
+
110
+ def metric_desc
111
+ "#{config[:namespace]}-#{config[:metric_name]}(#{dimension_string})"
112
+ end
113
+
114
+ def run
115
+ check config
116
+ end
117
+ end
@@ -1,8 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
3
  # check-elb-health-sdk
4
- # Last Update: 1/22/2015 by bkett
5
- # ===
6
4
  #
7
5
  # DESCRIPTION:
8
6
  # This plugin checks the health of an Amazon Elastic Load Balancer or all ELBs in a given region.
@@ -17,6 +15,11 @@
17
15
  # gem: aws-sdk-v1
18
16
  # gem: sensu-plugin
19
17
  #
18
+ # USAGE:
19
+ # check-elb-health-sdk.rb -r region
20
+ # check-elb-health-sdk.rb -r region -n my-elb
21
+ # check-elb-health-sdk.rb -r region -n my-elb -i instance1,instance2
22
+ #
20
23
  # Copyright (c) 2015, Benjamin Kett <bkett@umn.edu>
21
24
  #
22
25
  # Released under the same terms as Sensu (the MIT license); see LICENSE
@@ -63,6 +66,12 @@ class ELBHealth < Sensu::Plugin::Check::CLI
63
66
  boolean: true,
64
67
  default: false
65
68
 
69
+ option :warn_only,
70
+ short: '-w',
71
+ long: '--warn-only',
72
+ description: 'Warn instead of critical when unhealthy instances are found',
73
+ default: false
74
+
66
75
  def aws_config
67
76
  { access_key_id: config[:aws_access_key],
68
77
  secret_access_key: config[:aws_secret_access_key],
@@ -113,7 +122,11 @@ class ELBHealth < Sensu::Plugin::Check::CLI
113
122
  end
114
123
  end
115
124
  if critical
116
- critical @message
125
+ if config[:warn_only]
126
+ warning @message
127
+ else
128
+ critical @message
129
+ end
117
130
  else
118
131
  ok @message
119
132
  end
@@ -17,11 +17,11 @@
17
17
  # gem: sensu-plugin
18
18
  #
19
19
  # USAGE:
20
- # Warning if any load balancer's latency is over 1 second, critical if over 3 seconds.
21
- # check-elb-latency --warning-over 1 --critical-over 3
20
+ # Warning if the load balancer has 3 or fewer healthy nodes and critical if 2 or fewer
21
+ # check-elb-nodes --warn 3 --crit 2
22
22
  #
23
- # Critical if "app" load balancer's latency is over 5 seconds, maximum of last one hour
24
- # check-elb-latency --elb-names app --critical-over 5 --statistics maximum --period 3600
23
+ # Warning if the load balancer has 50% or less healthy nodes and critical if 25% or less
24
+ # check-elb-nodes --warn_perc 50 --crit_perc 25
25
25
  #
26
26
  # NOTES:
27
27
  #
@@ -64,7 +64,7 @@ class CheckRDSEvents < Sensu::Plugin::Check::CLI
64
64
  if clusters.empty?
65
65
  ok
66
66
  else
67
- critical("Clusters w/ critical events: #{clusters.join(',')}")
67
+ critical("Clusters w/ critical events: #{clusters.join(', ')}")
68
68
  end
69
69
  end
70
70
 
@@ -82,7 +82,8 @@ class CheckRDSEvents < Sensu::Plugin::Check::CLI
82
82
  next if events_record[:events].empty?
83
83
 
84
84
  # if the last event is a start maint event then the cluster is still in maint
85
- maint_clusters.push(cluster_name) if events_record[:events][-1][:message] =~ /has started|is being|off-line|shutdown/
85
+ cluster_name_long = "#{cluster_name} (#{aws_config[:region]}) #{events_record[:events][-1][:message]}"
86
+ maint_clusters.push(cluster_name_long) if events_record[:events][-1][:message] =~ /has started|is being|off-line|shutdown/
86
87
  end
87
88
  rescue => e
88
89
  unknown "An error occurred processing AWS RDS API: #{e.message}"
data/bin/check-rds.rb CHANGED
@@ -172,24 +172,29 @@ class CheckRDS < Sensu::Plugin::Check::CLI
172
172
 
173
173
  def memory_total_bytes(instance_class)
174
174
  memory_total_gigabytes = {
175
- 'db.t1.micro' => 0.615,
175
+ 'db.cr1.8xlarge' => 244.0,
176
176
  'db.m1.small' => 1.7,
177
+ 'db.m1.medium' => 3.75,
178
+ 'db.m1.large' => 7.5,
179
+ 'db.m1.xlarge' => 15.0,
180
+ 'db.m2.xlarge' => 17.1,
181
+ 'db.m2.2xlarge' => 34.2,
182
+ 'db.m2.4xlarge' => 68.4,
177
183
  'db.m3.medium' => 3.75,
178
184
  'db.m3.large' => 7.5,
179
185
  'db.m3.xlarge' => 15.0,
180
186
  'db.m3.2xlarge' => 30.0,
187
+ 'db.m4.large' => 8.0,
188
+ 'db.m4.xlarge' => 16.0,
189
+ 'db.m4.2xlarge' => 32.0,
190
+ 'db.m4.4xlarge' => 64.0,
191
+ 'db.m4.10xlarge' => 160.0,
181
192
  'db.r3.large' => 15.0,
182
193
  'db.r3.xlarge' => 30.5,
183
194
  'db.r3.2xlarge' => 61.0,
184
195
  'db.r3.4xlarge' => 122.0,
185
196
  'db.r3.8xlarge' => 244.0,
186
- 'db.m2.xlarge' => 17.1,
187
- 'db.m2.2xlarge' => 34.2,
188
- 'db.m2.4xlarge' => 68.4,
189
- 'db.cr1.8xlarge' => 244.0,
190
- 'db.m1.medium' => 3.75,
191
- 'db.m1.large' => 7.5,
192
- 'db.m1.xlarge' => 15.0,
197
+ 'db.t1.micro' => 0.615,
193
198
  'db.t2.micro' => 1,
194
199
  'db.t2.small' => 2,
195
200
  'db.t2.medium' => 4,
@@ -16,6 +16,7 @@
16
16
  # DEPENDENCIES:
17
17
  # gem: aws-sdk
18
18
  # gem: sensu-plugin
19
+ # gem: sensu-plugins-aws
19
20
  #
20
21
  # USAGE:
21
22
  # #YELLOW
@@ -29,20 +30,20 @@
29
30
  #
30
31
 
31
32
  require 'sensu-plugin/check/cli'
32
- require 'aws/ses'
33
+ require 'sensu-plugins-aws'
34
+ require 'aws-sdk'
33
35
 
34
36
  class CheckSESLimit < Sensu::Plugin::Check::CLI
37
+ include Common
35
38
  option :aws_access_key,
36
39
  short: '-a AWS_ACCESS_KEY',
37
40
  long: '--aws-access-key AWS_ACCESS_KEY',
38
- description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY'] or provide it as an option",
39
- default: ENV['AWS_ACCESS_KEY']
41
+ description: 'AWS Access Key ID.'
40
42
 
41
43
  option :aws_secret_access_key,
42
44
  short: '-k AWS_SECRET_KEY',
43
45
  long: '--aws-secret-access-key AWS_SECRET_KEY',
44
- description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_KEY'] or provide it as an option",
45
- default: ENV['AWS_SECRET_KEY']
46
+ description: 'AWS Secret Access Key.'
46
47
 
47
48
  option :aws_region,
48
49
  short: '-r AWS_REGION',
@@ -64,33 +65,25 @@ class CheckSESLimit < Sensu::Plugin::Check::CLI
64
65
  default: 90,
65
66
  proc: proc(&:to_i)
66
67
 
67
- def aws_config
68
- { access_key_id: config[:aws_access_key],
69
- secret_access_key: config[:aws_secret_access_key],
70
- region: config[:aws_region]
71
- }
72
- end
73
-
74
68
  def run
75
69
  begin
76
- ses = AWS::SES::Base.new aws_config
77
-
78
- response = ses.quota
79
- rescue AWS::SES::ResponseError => e
80
- critical "An issue occured while communicating with the AWS SES API: #{e.message}"
70
+ ses = Aws::SES::Client.new
71
+ response = ses.get_send_quota
72
+ rescue => e
73
+ unknown "An issue occured while communicating with the AWS SES API: #{e.message}"
81
74
  end
82
75
 
83
- unless response.empty? # rubocop: disable Style/GuardClause
84
- percent = (response.sent_last_24_hours.to_i / response.max_24_hour_send.to_i) * 100
85
- message = "SES sending limit is at #{percent}%"
76
+ unknown 'Empty response from AWS SES API' if response.empty? # Can this happen?
77
+
78
+ percent = (response.sent_last_24_hours.to_i / response.max_24_hour_send.to_i) * 100
79
+ message = "SES sending limit is at #{percent}%"
86
80
 
87
- if config[:crit_percent] > 0 && config[:crit_percent] <= percent
88
- critical message
89
- elsif config[:warn_percent] > 0 && config[:warn_percent] <= percent
90
- warning message
91
- else
92
- ok message
93
- end
81
+ if config[:crit_percent] > 0 && config[:crit_percent] <= percent
82
+ critical message
83
+ elsif config[:warn_percent] > 0 && config[:warn_percent] <= percent
84
+ warning message
85
+ else
86
+ ok message
94
87
  end
95
88
  end
96
89
  end
@@ -1,6 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
3
  # CHANGELOG:
4
+ # * 0.7.0:
5
+ # - Update to new API event naming and simplifying ec2_node_should_be_deleted method and fixing
6
+ # match that will work with any user state defined.
4
7
  # * 0.6.0:
5
8
  # - Fixed ec2_node_should_be_deleted to account for an empty insances array
6
9
  # * 0.5.0:
@@ -32,6 +35,22 @@
32
35
  # to match any state reason `.*` Regardless, eventually a client will be
33
36
  # deleted once AWS stops responding that the instance id exists.
34
37
  #
38
+ # You could specify a ec2_states.json config file for the states like so:
39
+ #
40
+ # {
41
+ # "ec2_node": {
42
+ # "ec2_states": [
43
+ # "terminated",
44
+ # "stopping",
45
+ # "shutting-down",
46
+ # "stopped"
47
+ # ]
48
+ # }
49
+ # }
50
+ #
51
+ # And add that to your /etc/sensu/conf.d directory.
52
+ # If you do not specify any states the handler would not work
53
+ #
35
54
  # NOTE: The implementation for correlating Sensu clients to EC2 instances may
36
55
  # need to be modified to fit your organization. The current implementation
37
56
  # assumes that Sensu clients' names are the same as their instance IDs in EC2.
@@ -81,7 +100,7 @@
81
100
  # "name": "keepalive",
82
101
  # "status": 2
83
102
  # },
84
- # "occurences": "eval: value > 2"
103
+ # "occurrences": "eval: value > 2"
85
104
  # }
86
105
  # }
87
106
  # },
@@ -114,7 +133,10 @@ class Ec2Node < Sensu::Handler
114
133
 
115
134
  def filter; end
116
135
 
136
+ # Method handle
117
137
  def handle
138
+ # Call ec2_node_should_be_deleted method and check for instance state and if valid delete from the sensu API otherwise
139
+ # instance is in invalid state
118
140
  if ec2_node_should_be_deleted?
119
141
  delete_sensu_client!
120
142
  else
@@ -122,23 +144,46 @@ class Ec2Node < Sensu::Handler
122
144
  end
123
145
  end
124
146
 
147
+ # Method to delete client from sensu API
125
148
  def delete_sensu_client!
126
149
  response = api_request(:DELETE, '/clients/' + @event['client']['name']).code
127
150
  deletion_status(response)
128
151
  end
129
152
 
153
+ # Method to check if there is any insance and if instance is in a valid state that could be deleted
130
154
  def ec2_node_should_be_deleted?
155
+ # Defining region for aws SDK object
131
156
  ec2 = Aws::EC2::Client.new(region: region)
132
- states = @event['client']['ec2_states'] || settings['ec2_node']['ec2_states'] || ['shutting-down', 'terminated', 'stopping', 'stopped']
157
+ # Check if attributes or json objects are not defined
158
+ if @event['client']['ec2_states'].nil? && settings['ec2_node']['ec2_states'].nil?
159
+ puts 'ec2_states is not define, please add the attributes or create a json config file with valid states keys'
160
+ else
161
+ # Asigning valid states
162
+ instance_states = @event['client']['ec2_states'] || settings['ec2_node']['ec2_states'] || ['shutting-down', 'terminated', 'stopping', 'stopped']
163
+ end
164
+
133
165
  begin
166
+ # Finding the instance
134
167
  instances = ec2.describe_instances(instance_ids: [@event['client']['name']]).reservations[0]
168
+ # If instance is empty/nil instance id is not valid so client can be deleted
135
169
  if instances.nil? || instances.empty?
136
170
  true
137
171
  else
138
- instance = instances.instances[0]
139
- state_reason = instance.state_reason.nil? ? nil : instance.state_reason.code
140
- state = instance.state.name
141
- states.include?(state) && state_reasons.any? { |reason| Regexp.new(reason) =~ state_reason }
172
+ # Checking for instance state and reason, and if matches any of the user defined or default reasons then
173
+ # method returns True
174
+
175
+ # Returns Instance object
176
+ instance_obj = instances.instances[0]
177
+ # Returns instance state reason in AWS i.e: "Client.UserInitiatedShutdown"
178
+ instance_state_reason = instance_obj.state_reason.code
179
+ # Returns the instance state i.e: "terminated"
180
+ instance_state = instance_obj.state.name
181
+ # Defining the default reasons why an instance could be deleted or not
182
+ instance_default_reasons = %w(Client.UserInitiatedShutdown Server.SpotInstanceTermination Client.InstanceInitiatedShutdown)
183
+ # If user specified a reason use those otherwise use default
184
+ instance_reasons = @event['client']['ec2_state_reasons'] || settings['ec2_node']['ec2_state_reasons'] || instance_default_reasons
185
+ # Return true is instance state and instance reason is valid
186
+ instance_states.include?(instance_state) && instance_reasons.include?(instance_state_reason)
142
187
  end
143
188
  rescue Aws::EC2::Errors::InvalidInstanceIDNotFound
144
189
  true
@@ -160,12 +205,6 @@ class Ec2Node < Sensu::Handler
160
205
  end
161
206
  end
162
207
 
163
- def state_reasons
164
- default_reasons = %w('UserInitiatedShutdown', 'SpotInstanceTermination', 'InstanceInitiatedShutdown')
165
- reasons = @event['client']['ec2_state_reasons'] || settings['ec2_node']['ec2_state_reasons'] || default_reasons
166
- @state_reasons ||= reasons.each { |reason| Regexp.new(reason) }
167
- end
168
-
169
208
  def deletion_status(code)
170
209
  case code
171
210
  when '202'
data/bin/handler-sns.rb CHANGED
@@ -15,6 +15,7 @@
15
15
 
16
16
  require 'sensu-handler'
17
17
  require 'aws-sdk-v1'
18
+ require 'erubis'
18
19
 
19
20
  class SnsNotifier < Sensu::Handler
20
21
  def topic_arn
@@ -43,7 +44,19 @@ class SnsNotifier < Sensu::Handler
43
44
  end
44
45
 
45
46
  def message
46
- @event['check']['notification'] || @event['check']['output']
47
+ if template_file && File.readable?(template_file)
48
+ template = File.read(template_file)
49
+ else
50
+ template = <<-BODY.gsub(/^\s+/, '')
51
+ <%= @event['check']['notification'] || @event['check']['output'] %>
52
+ BODY
53
+ end
54
+ eruby = Erubis::Eruby.new(template)
55
+ eruby.result(binding)
56
+ end
57
+
58
+ def template_file
59
+ settings['sns']['template_file']
47
60
  end
48
61
 
49
62
  def handle
@@ -16,7 +16,8 @@
16
16
  # gem: sensu-plugin
17
17
  #
18
18
  # USAGE:
19
- # #YELLOW
19
+ # elasticache-metrics.rb -n rediscluster -c redis -a key -k secret
20
+ # elasticache-metrics.rb -n memcachedcluster -c memcached -a key -k secret
20
21
  #
21
22
  # NOTES:
22
23
  # Redis: http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/CacheMetrics.Redis.html
@@ -92,7 +93,7 @@ class ElastiCacheMetrics < Sensu::Plugin::Metric::CLI::Graphite
92
93
 
93
94
  def run
94
95
  if config[:scheme] == ''
95
- graphitepath = "#{config[:elasticachename]}.#{config[:metric].downcase}"
96
+ graphitepath = "elasticache.#{config[:cacheclusterid]}"
96
97
  else
97
98
  graphitepath = config[:scheme]
98
99
  end
@@ -116,16 +116,13 @@ class ELBMetrics < Sensu::Plugin::Metric::CLI::Graphite
116
116
  'end_time' => et.iso8601,
117
117
  'period' => 60
118
118
  }
119
-
120
- result = {}
121
-
122
119
  config[:elbname].split(',').each do |elbname|
123
120
  if config[:scheme] == ''
124
121
  graphitepath = "#{elbname}"
125
122
  else
126
123
  graphitepath = "#{config[:scheme]}.#{elbname}"
127
124
  end
128
-
125
+ result = {}
129
126
  statistic_type.each do |key, value|
130
127
  options['metric_name'] = key
131
128
  options['dimensions'][0]['value'] = elbname
@@ -0,0 +1,62 @@
1
+ require 'aws-sdk'
2
+
3
+ module CloudwatchCommon
4
+ def client
5
+ Aws::CloudWatch::Client.new
6
+ end
7
+
8
+ def read_value(resp, stats)
9
+ resp.datapoints.first.send(stats.downcase)
10
+ end
11
+
12
+ def resp_has_no_data(resp, stats)
13
+ resp.datapoints.nil? || resp.datapoints.length == 0 || resp.datapoints.first.nil? || read_value(resp, stats).nil?
14
+ end
15
+
16
+ def compare(value, threshold, compare_method)
17
+ if compare_method == 'greater'
18
+ return value > threshold
19
+ elsif compare_method == 'less'
20
+ return value < threshold
21
+ elsif compare_method == 'not'
22
+ return value != threshold
23
+ else
24
+ return value == threshold
25
+ end
26
+ end
27
+
28
+ def metrics_request(config)
29
+ {
30
+ namespace: config[:namespace],
31
+ metric_name: config[:metric_name],
32
+ dimensions: config[:dimensions],
33
+ start_time: Time.now - config[:period] * 10,
34
+ end_time: Time.now,
35
+ period: config[:period],
36
+ statistics: [config[:statistics]],
37
+ unit: config[:unit]
38
+ }
39
+ end
40
+
41
+ def check(config)
42
+ resp = client.get_metric_statistics(metrics_request(config))
43
+
44
+ no_data = resp_has_no_data(resp, config[:statistics])
45
+ if no_data && config[:no_data_ok]
46
+ ok "#{metric_desc} returned no data but that's ok"
47
+ elsif no_data && !config[:no_data_ok]
48
+ unknown "#{metric_desc} could not be retrieved"
49
+ end
50
+
51
+ value = read_value(resp, config[:statistics])
52
+ base_msg = "#{metric_desc} is #{value}: comparison=#{config[:compare]}"
53
+
54
+ if compare value, config[:critical], config[:compare]
55
+ critical "#{base_msg} threshold=#{config[:critical]}"
56
+ elsif config[:warning] && compare(value, config[:warning], config[:compare])
57
+ warning "#{base_msg} threshold=#{config[:warning]}"
58
+ else
59
+ ok "#{base_msg}, will alarm at #{!config[:warning].nil? ? config[:warning] : config[:critical]}"
60
+ end
61
+ end
62
+ end
@@ -1,8 +1,8 @@
1
1
  module SensuPluginsAWS
2
2
  module Version
3
3
  MAJOR = 2
4
- MINOR = 0
5
- PATCH = 1
4
+ MINOR = 1
5
+ PATCH = 0
6
6
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu-Plugins and contributors
@@ -30,7 +30,7 @@ cert_chain:
30
30
  8sHuVruarogxxKPBzlL2is4EUb6oN/RdpGx2l4254+nyR+abg//Ed27Ym0PkB4lk
31
31
  HP0m8WSjZmFr109pE/sVsM5jtOCvogyujQOjNVGN4gz1wwPr
32
32
  -----END CERTIFICATE-----
33
- date: 2015-11-03 00:00:00.000000000 Z
33
+ date: 2016-01-16 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: aws-sdk
@@ -102,6 +102,20 @@ dependencies:
102
102
  - - '='
103
103
  - !ruby/object:Gem::Version
104
104
  version: 1.2.0
105
+ - !ruby/object:Gem::Dependency
106
+ name: erubis
107
+ requirement: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '='
110
+ - !ruby/object:Gem::Version
111
+ version: 2.7.0
112
+ type: :runtime
113
+ prerelease: false
114
+ version_requirements: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '='
117
+ - !ruby/object:Gem::Version
118
+ version: 2.7.0
105
119
  - !ruby/object:Gem::Dependency
106
120
  name: codeclimate-test-reporter
107
121
  requirement: !ruby/object:Gem::Requirement
@@ -233,7 +247,7 @@ description: |-
233
247
  for monitoring and metrics collection, including:
234
248
  health and metrics for various AWS services, such
235
249
  as EC2, RDS, ELB, and more, as well as handlers
236
- for EC2, SES, and SNS
250
+ for EC2, SES, and SNS.
237
251
  email: "<sensu-users@googlegroups.com>"
238
252
  executables:
239
253
  - metrics-sqs.rb
@@ -246,6 +260,7 @@ executables:
246
260
  - handler-sns.rb
247
261
  - handler-ses.rb
248
262
  - handler-ec2_node.rb
263
+ - check_vpc_vpn.py
249
264
  - check-vpc-vpn.rb
250
265
  - check-vpc-nameservers.rb
251
266
  - check-sqs-messages.rb
@@ -270,7 +285,10 @@ executables:
270
285
  - check-ebs-snapshots.rb
271
286
  - check-dynamodb-throttle.rb
272
287
  - check-dynamodb-capacity.rb
288
+ - check-cloudwatch-metric.rb
273
289
  - check-cloudwatch-alarm.rb
290
+ - check-certificate-expiry.rb
291
+ - check-beanstalk-elb-metric.rb
274
292
  - check-autoscaling-cpucredits.rb
275
293
  extensions: []
276
294
  extra_rdoc_files: []
@@ -279,7 +297,10 @@ files:
279
297
  - LICENSE
280
298
  - README.md
281
299
  - bin/check-autoscaling-cpucredits.rb
300
+ - bin/check-beanstalk-elb-metric.rb
301
+ - bin/check-certificate-expiry.rb
282
302
  - bin/check-cloudwatch-alarm.rb
303
+ - bin/check-cloudwatch-metric.rb
283
304
  - bin/check-dynamodb-capacity.rb
284
305
  - bin/check-dynamodb-throttle.rb
285
306
  - bin/check-ebs-snapshots.rb
@@ -316,6 +337,7 @@ files:
316
337
  - bin/metrics-elb.rb
317
338
  - bin/metrics-sqs.rb
318
339
  - lib/sensu-plugins-aws.rb
340
+ - lib/sensu-plugins-aws/cloudwatch-common.rb
319
341
  - lib/sensu-plugins-aws/common.rb
320
342
  - lib/sensu-plugins-aws/filter.rb
321
343
  - lib/sensu-plugins-aws/version.rb
metadata.gz.sig CHANGED
Binary file