sensu-plugins-aws 0.0.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,10 +13,8 @@
13
13
  # Linux
14
14
  #
15
15
  # DEPENDENCIES:
16
- # gem: aws-sdk
16
+ # gem: aws-sdk-v1
17
17
  # gem: sensu-plugin
18
- # gem: openssl
19
- # gem: net/http
20
18
  #
21
19
  # USAGE:
22
20
  # ./check-ec2-network.rb -r ${you_region} -i ${your_instance_id} --warning-over 1000000 --critical-over 1500000
@@ -40,19 +38,19 @@ class CheckELBCerts < Sensu::Plugin::Check::CLI
40
38
  option :aws_access_key,
41
39
  short: '-a AWS_ACCESS_KEY',
42
40
  long: '--aws-access-key AWS_ACCESS_KEY',
43
- description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY_ID'] or provide it as an option",
44
- default: ENV['AWS_ACCESS_KEY_ID']
41
+ description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY'] or provide it as an option",
42
+ default: ENV['AWS_ACCESS_KEY']
45
43
 
46
44
  option :aws_secret_access_key,
47
- short: '-s AWS_SECRET_ACCESS_KEY',
48
- long: '--aws-secret-access-key AWS_SECRET_ACCESS_KEY',
49
- description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_ACCESS_KEY'] or provide it as an option",
50
- default: ENV['AWS_SECRET_ACCESS_KEY']
45
+ short: '-k AWS_SECRET_KEY',
46
+ long: '--aws-secret-access-key AWS_SECRET_KEY',
47
+ description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_KEY'] or provide it as an option",
48
+ default: ENV['AWS_SECRET_KEY']
51
49
 
52
50
  option :aws_region,
53
51
  short: '-r AWS_REGION',
54
52
  long: '--aws-region REGION',
55
- description: 'AWS Region (such as eu-west-1).',
53
+ description: 'AWS Region (defaults to us-east-1).',
56
54
  default: 'us-east-1'
57
55
 
58
56
  option :warn_under,
@@ -82,11 +80,10 @@ class CheckELBCerts < Sensu::Plugin::Check::CLI
82
80
  end
83
81
 
84
82
  def aws_config
85
- hash = {}
86
- hash.update access_key_id: config[:aws_access_key], secret_access_key: config[:aws_secret_access_key]\
87
- if config[:aws_access_key] && config[:aws_secret_access_key]
88
- hash.update region: config[:aws_region]
89
- hash
83
+ { access_key_id: config[:aws_access_key],
84
+ secret_access_key: config[:aws_secret_access_key],
85
+ region: config[:aws_region]
86
+ }
90
87
  end
91
88
 
92
89
  def run # rubocop:disable all
@@ -15,7 +15,6 @@
15
15
  # DEPENDENCIES:
16
16
  # gem: fog
17
17
  # gem: sensu-plugin
18
- # gem: uri
19
18
  #
20
19
  # USAGE:
21
20
  # ./check-ec2-network.rb -r ${you_region} -i ${your_instance_id} --warning-over 1000000 --critical-over 1500000
@@ -39,16 +38,14 @@ class ELBHealth < Sensu::Plugin::Check::CLI
39
38
  option :aws_access_key,
40
39
  short: '-a AWS_ACCESS_KEY',
41
40
  long: '--aws-access-key AWS_ACCESS_KEY',
42
- description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY_ID'] or provide it as an option",
43
- required: true,
44
- default: ENV['AWS_ACCESS_KEY_ID']
41
+ description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY'] or provide it as an option",
42
+ default: ENV['AWS_ACCESS_KEY']
45
43
 
46
44
  option :aws_secret_access_key,
47
- short: '-s AWS_SECRET_ACCESS_KEY',
48
- long: '--aws-secret-access-key AWS_SECRET_ACCESS_KEY',
49
- description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_ACCESS_KEY'] or provide it as an option",
50
- required: true,
51
- default: ENV['AWS_SECRET_ACCESS_KEY']
45
+ short: '-k AWS_SECRET_KEY',
46
+ long: '--aws-secret-access-key AWS_SECRET_KEY',
47
+ description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_KEY'] or provide it as an option",
48
+ default: ENV['AWS_SECRET_KEY']
52
49
 
53
50
  option :aws_region,
54
51
  short: '-r AWS_REGION',
@@ -84,10 +81,10 @@ class ELBHealth < Sensu::Plugin::Check::CLI
84
81
  end
85
82
 
86
83
  def aws_config
87
- hash = {}
88
- hash.update access_key_id: config[:access_key_id], secret_access_key: config[:secret_access_key] if config[:access_key_id] && config[:secret_access_key]
89
- hash.update region: config[:region]
90
- hash
84
+ { access_key_id: config[:aws_access_key],
85
+ secret_access_key: config[:aws_secret_access_key],
86
+ region: config[:aws_region]
87
+ }
91
88
  end
92
89
 
93
90
  def run
@@ -108,7 +105,7 @@ class ELBHealth < Sensu::Plugin::Check::CLI
108
105
  ok "All instances on ELB #{aws_region}::#{config[:elb_name]} healthy!"
109
106
  else
110
107
  if config[:verbose]
111
- critical "Unhealthy instances detected: #{unhealthy_instances.map { |id, state| '[' + id + '::' + state + ']' }.join(' ') }"
108
+ critical "Unhealthy instances detected: #{unhealthy_instances.map { |id, state| '[' + id + '::' + state + ']' }.join(' ')}"
112
109
  else
113
110
  critical "Detected [#{unhealthy_instances.size}] unhealthy instances"
114
111
  end
@@ -14,9 +14,7 @@
14
14
  # Linux
15
15
  #
16
16
  # DEPENDENCIES:
17
- # gem: aws-sdk
18
- # gem: uri
19
- # gem: net/http
17
+ # gem: aws-sdk-v1
20
18
  # gem: sensu-plugin
21
19
  #
22
20
  # Copyright (c) 2015, Benjamin Kett <bkett@umn.edu>
@@ -33,19 +31,19 @@ class ELBHealth < Sensu::Plugin::Check::CLI
33
31
  option :aws_access_key,
34
32
  short: '-a AWS_ACCESS_KEY',
35
33
  long: '--aws-access-key AWS_ACCESS_KEY',
36
- description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY_ID'] or provide it as an option",
37
- default: ENV['AWS_ACCESS_KEY_ID']
34
+ description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY'] or provide it as an option",
35
+ default: ENV['AWS_ACCESS_KEY']
38
36
 
39
37
  option :aws_secret_access_key,
40
- short: '-s AWS_SECRET_ACCESS_KEY',
41
- long: '--aws-secret-access-key AWS_SECRET_ACCESS_KEY',
42
- description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_ACCESS_KEY'] or provide it as an option",
43
- default: ENV['AWS_SECRET_ACCESS_KEY']
38
+ short: '-k AWS_SECRET_KEY',
39
+ long: '--aws-secret-access-key AWS_SECRET_KEY',
40
+ description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_KEY'] or provide it as an option",
41
+ default: ENV['AWS_SECRET_KEY']
44
42
 
45
43
  option :aws_region,
46
44
  short: '-r AWS_REGION',
47
45
  long: '--aws-region REGION',
48
- description: 'AWS Region (such as eu-west-1).',
46
+ description: 'AWS Region (defaults to us-east-1).',
49
47
  default: 'us-east-1'
50
48
 
51
49
  option :elb_name,
@@ -66,10 +64,10 @@ class ELBHealth < Sensu::Plugin::Check::CLI
66
64
  default: false
67
65
 
68
66
  def aws_config
69
- hash = {}
70
- hash.update access_key_id: config[:access_key_id], secret_access_key: config[:secret_access_key] if config[:access_key_id] && config[:secret_access_key]
71
- hash.update region: config[:aws_region]
72
- hash
67
+ { access_key_id: config[:aws_access_key],
68
+ secret_access_key: config[:aws_secret_access_key],
69
+ region: config[:aws_region]
70
+ }
73
71
  end
74
72
 
75
73
  def elb
@@ -13,7 +13,6 @@
13
13
  #
14
14
  # DEPENDENCIES:
15
15
  # gem: right-aws
16
- # gem: uri
17
16
  # gem: sensu-plugin
18
17
  #
19
18
  # USAGE:
@@ -38,16 +37,14 @@ class ELBHealth < Sensu::Plugin::Check::CLI
38
37
  option :aws_access_key,
39
38
  short: '-a AWS_ACCESS_KEY',
40
39
  long: '--aws-access-key AWS_ACCESS_KEY',
41
- description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY_ID'] or provide it as an option",
42
- required: true,
43
- default: ENV['AWS_ACCESS_KEY_ID']
40
+ description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY'] or provide it as an option",
41
+ default: ENV['AWS_ACCESS_KEY']
44
42
 
45
43
  option :aws_secret_access_key,
46
- short: '-s AWS_SECRET_ACCESS_KEY',
47
- long: '--aws-secret-access-key AWS_SECRET_ACCESS_KEY',
48
- description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_ACCESS_KEY'] or provide it as an option",
49
- required: true,
50
- default: ENV['AWS_SECRET_ACCESS_KEY']
44
+ short: '-k AWS_SECRET_KEY',
45
+ long: '--aws-secret-access-key AWS_SECRET_KEY',
46
+ description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_KEY'] or provide it as an option",
47
+ default: ENV['AWS_SECRET_KEY']
51
48
 
52
49
  option :aws_region,
53
50
  short: '-r AWS_REGION',
@@ -13,7 +13,7 @@
13
13
  # Linux
14
14
  #
15
15
  # DEPENDENCIES:
16
- # gem: aws-sdk
16
+ # gem: aws-sdk-v1
17
17
  # gem: sensu-plugin
18
18
  #
19
19
  # USAGE:
@@ -35,20 +35,23 @@ require 'sensu-plugin/check/cli'
35
35
  require 'aws-sdk-v1'
36
36
 
37
37
  class CheckELBLatency < Sensu::Plugin::Check::CLI
38
- option :access_key_id,
39
- short: '-k N',
40
- long: '--access-key-id ID',
41
- description: 'AWS access key ID'
42
-
43
- option :secret_access_key,
44
- short: '-s N',
45
- long: '--secret-access-key KEY',
46
- description: 'AWS secret access key'
47
-
48
- option :region,
49
- short: '-r R',
50
- long: '--region REGION',
51
- description: 'AWS region'
38
+ option :aws_access_key,
39
+ short: '-a AWS_ACCESS_KEY',
40
+ long: '--aws-access-key AWS_ACCESS_KEY',
41
+ description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY'] or provide it as an option",
42
+ default: ENV['AWS_ACCESS_KEY']
43
+
44
+ option :aws_secret_access_key,
45
+ short: '-k AWS_SECRET_KEY',
46
+ long: '--aws-secret-access-key AWS_SECRET_KEY',
47
+ description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_KEY'] or provide it as an option",
48
+ default: ENV['AWS_SECRET_KEY']
49
+
50
+ option :aws_region,
51
+ short: '-r AWS_REGION',
52
+ long: '--aws-region REGION',
53
+ description: 'AWS Region (defaults to us-east-1).',
54
+ default: 'us-east-1'
52
55
 
53
56
  option :elb_names,
54
57
  short: '-l N',
@@ -85,10 +88,10 @@ class CheckELBLatency < Sensu::Plugin::Check::CLI
85
88
  end
86
89
 
87
90
  def aws_config
88
- hash = {}
89
- hash.update access_key_id: config[:access_key_id], secret_access_key: config[:secret_access_key] if config[:access_key_id] && config[:secret_access_key]
90
- hash.update region: config[:region] if config[:region]
91
- hash
91
+ { access_key_id: config[:aws_access_key],
92
+ secret_access_key: config[:aws_secret_access_key],
93
+ region: config[:aws_region]
94
+ }
92
95
  end
93
96
 
94
97
  def elb
@@ -141,7 +144,7 @@ class CheckELBLatency < Sensu::Plugin::Check::CLI
141
144
  next unless threshold
142
145
  next if metric_value < threshold
143
146
  flag_alert severity,
144
- "; #{elbs.size == 1 ? nil : "#{elb.inspect}'s"} Latency is #{sprintf '%.3f', metric_value} seconds. (expected lower than #{sprintf '%.3f', threshold})" # rubocop:disable all
147
+ "; #{elbs.size == 1 ? nil : "#{elb.inspect}'s"} Latency is #{sprintf '%.3f', metric_value} seconds. (expected lower than #{sprintf '%.3f', threshold})" # rubocop:disable all
145
148
  break
146
149
  end
147
150
  end
@@ -13,7 +13,7 @@
13
13
  # Linux
14
14
  #
15
15
  # DEPENDENCIES:
16
- # gem: aws-sdk
16
+ # gem: aws-sdk-v1
17
17
  # gem: sensu-plugin
18
18
  #
19
19
  # USAGE:
@@ -38,17 +38,19 @@ class CheckELBNodes < Sensu::Plugin::Check::CLI
38
38
  option :aws_access_key,
39
39
  short: '-a AWS_ACCESS_KEY',
40
40
  long: '--aws-access-key AWS_ACCESS_KEY',
41
- description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY_ID'] or provide it as an option"
41
+ description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY'] or provide it as an option",
42
+ default: ENV['AWS_ACCESS_KEY']
42
43
 
43
44
  option :aws_secret_access_key,
44
- short: '-s AWS_SECRET_ACCESS_KEY',
45
- long: '--aws-secret-access-key AWS_SECRET_ACCESS_KEY',
46
- description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_ACCESS_KEY'] or provide it as an option"
45
+ short: '-k AWS_SECRET_KEY',
46
+ long: '--aws-secret-access-key AWS_SECRET_KEY',
47
+ description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_KEY'] or provide it as an option",
48
+ default: ENV['AWS_SECRET_KEY']
47
49
 
48
50
  option :aws_region,
49
51
  short: '-r AWS_REGION',
50
52
  long: '--aws-region REGION',
51
- description: 'AWS Region (such as eu-west-1).',
53
+ description: 'AWS Region (defaults to us-east-1).',
52
54
  default: 'us-east-1'
53
55
 
54
56
  option :load_balancer,
@@ -86,11 +88,10 @@ class CheckELBNodes < Sensu::Plugin::Check::CLI
86
88
  proc: proc(&:to_i)
87
89
 
88
90
  def aws_config
89
- hash = {}
90
- hash.update access_key_id: config[:aws_access_key], secret_access_key: config[:aws_secret_access_key]\
91
- if config[:aws_access_key] && config[:aws_secret_access_key]
92
- hash.update region: config[:aws_region]
93
- hash
91
+ { access_key_id: config[:aws_access_key],
92
+ secret_access_key: config[:aws_secret_access_key],
93
+ region: config[:aws_region]
94
+ }
94
95
  end
95
96
 
96
97
  def run # rubocop:disable all
@@ -12,7 +12,7 @@
12
12
  # Linux
13
13
  #
14
14
  # DEPENDENCIES:
15
- # gem: aws-sdk
15
+ # gem: aws-sdk-v1
16
16
  # gem: sensu-plugin
17
17
  #
18
18
  # USAGE:
@@ -34,20 +34,23 @@ require 'sensu-plugin/check/cli'
34
34
  require 'aws-sdk-v1'
35
35
 
36
36
  class CheckELBSumRequests < Sensu::Plugin::Check::CLI
37
- option :access_key_id,
38
- short: '-k N',
39
- long: '--access-key-id ID',
40
- description: 'AWS access key ID'
41
-
42
- option :secret_access_key,
43
- short: '-s N',
44
- long: '--secret-access-key KEY',
45
- description: 'AWS secret access key'
46
-
47
- option :region,
48
- short: '-r R',
49
- long: '--region REGION',
50
- description: 'AWS region'
37
+ option :aws_access_key,
38
+ short: '-a AWS_ACCESS_KEY',
39
+ long: '--aws-access-key AWS_ACCESS_KEY',
40
+ description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY'] or provide it as an option",
41
+ default: ENV['AWS_ACCESS_KEY']
42
+
43
+ option :aws_secret_access_key,
44
+ short: '-k AWS_SECRET_KEY',
45
+ long: '--aws-secret-access-key AWS_SECRET_KEY',
46
+ description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_KEY'] or provide it as an option",
47
+ default: ENV['AWS_SECRET_KEY']
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'
51
54
 
52
55
  option :elb_names,
53
56
  short: '-l N',
@@ -77,10 +80,10 @@ class CheckELBSumRequests < Sensu::Plugin::Check::CLI
77
80
  end
78
81
 
79
82
  def aws_config
80
- hash = {}
81
- hash.update access_key_id: config[:access_key_id], secret_access_key: config[:secret_access_key] if config[:access_key_id] && config[:secret_access_key]
82
- hash.update region: config[:region] if config[:region]
83
- hash
83
+ { access_key_id: config[:aws_access_key],
84
+ secret_access_key: config[:aws_secret_access_key],
85
+ region: config[:aws_region]
86
+ }
84
87
  end
85
88
 
86
89
  def elb
@@ -13,7 +13,7 @@
13
13
  # Linux
14
14
  #
15
15
  # DEPENDENCIES:
16
- # gem: aws-sdk
16
+ # gem: aws-sdk-v1
17
17
  # gem: sensu-plugin
18
18
  #
19
19
  # USAGE:
@@ -34,8 +34,20 @@ class CheckInstanceEvents < Sensu::Plugin::Check::CLI
34
34
  option :aws_access_key,
35
35
  short: '-a AWS_ACCESS_KEY',
36
36
  long: '--aws-access-key AWS_ACCESS_KEY',
37
- description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY_ID'] or provide it as an option",
38
- default: ENV['AWS_ACCESS_KEY_ID']
37
+ description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY'] or provide it as an option",
38
+ default: ENV['AWS_ACCESS_KEY']
39
+
40
+ option :aws_secret_access_key,
41
+ short: '-k AWS_SECRET_KEY',
42
+ long: '--aws-secret-access-key AWS_SECRET_KEY',
43
+ description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_KEY'] or provide it as an option",
44
+ default: ENV['AWS_SECRET_KEY']
45
+
46
+ option :aws_region,
47
+ short: '-r AWS_REGION',
48
+ long: '--aws-region REGION',
49
+ description: 'AWS Region (defaults to us-east-1).',
50
+ default: 'us-east-1'
39
51
 
40
52
  option :use_iam_role,
41
53
  short: '-u',
@@ -48,24 +60,11 @@ class CheckInstanceEvents < Sensu::Plugin::Check::CLI
48
60
  description: "Includes any offending instance's 'Name' tag in the check output",
49
61
  default: false
50
62
 
51
- option :aws_secret_access_key,
52
- short: '-s AWS_SECRET_ACCESS_KEY',
53
- long: '--aws-secret-access-key AWS_SECRET_ACCESS_KEY',
54
- description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_ACCESS_KEY'] or provide it as an option",
55
- default: ENV['AWS_SECRET_ACCESS_KEY']
56
-
57
- option :aws_region,
58
- short: '-r AWS_REGION',
59
- long: '--aws-region REGION',
60
- description: 'AWS Region (such as eu-west-1).',
61
- default: 'us-east-1'
62
-
63
63
  def aws_config
64
- hash = {}
65
- hash.update access_key_id: config[:aws_access_key], secret_access_key: config[:aws_secret_access_key]\
66
- if config[:aws_access_key] && config[:aws_secret_access_key]
67
- hash.update region: config[:aws_region]
68
- hash
64
+ { access_key_id: config[:aws_access_key],
65
+ secret_access_key: config[:aws_secret_access_key],
66
+ region: config[:aws_region]
67
+ }
69
68
  end
70
69
 
71
70
  def run
@@ -81,22 +80,22 @@ class CheckInstanceEvents < Sensu::Plugin::Check::CLI
81
80
 
82
81
  ec2 = AWS::EC2::Client.new(aws_config.merge!(region: config[:aws_region]))
83
82
  begin
84
- ec2.describe_instance_status[:instance_status_set].each do |i| # rubocop:disable Next
85
- unless i[:events_set].empty?
86
- # Exclude completed reboots since the events API appearently returns these even after they have been completed:
87
- # Example:
88
- # "events_set": [
89
- # {
90
- # "code": "system-reboot",
91
- # "description": "[Completed] Scheduled reboot",
92
- # "not_before": "2015-01-05 12:00:00 UTC",
93
- # "not_after": "2015-01-05 18:00:00 UTC"
94
- # }
95
- # ]
96
- useful_events = i[:events_set].reject { |x| x[:code] == 'system-reboot' && x[:description] =~ /\[Completed\]/ }
97
- unless useful_events.empty?
98
- event_instances << i[:instance_id]
99
- end
83
+ ec2.describe_instance_status[:instance_status_set].each do |i|
84
+ next if i[:events_set].empty?
85
+
86
+ # Exclude completed reboots since the events API appearently returns these even after they have been completed:
87
+ # Example:
88
+ # "events_set": [
89
+ # {
90
+ # "code": "system-reboot",
91
+ # "description": "[Completed] Scheduled reboot",
92
+ # "not_before": "2015-01-05 12:00:00 UTC",
93
+ # "not_after": "2015-01-05 18:00:00 UTC"
94
+ # }
95
+ # ]
96
+ useful_events = i[:events_set].reject { |x| x[:code] == 'system-reboot' && x[:description] =~ /\[Completed\]/ }
97
+ unless useful_events.empty?
98
+ event_instances << i[:instance_id]
100
99
  end
101
100
  end
102
101
  rescue => e