awspec 0.14.1 → 0.15.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: c0e8a26293f9797d554ff688944727ff6c2ae71f
4
- data.tar.gz: c2dad23f89b15aa691b869e84facdf976ef9a9cf
3
+ metadata.gz: 246f7601c47ebc923bd6296cdd04cf6ed1a642dd
4
+ data.tar.gz: 7da26f53af5ec2da25187659075122bc79cf93e2
5
5
  SHA512:
6
- metadata.gz: 3e5ea4360f4692d7d7992912baa75654839c339c4a35602472e594104391adca8c1cecd975930383bb9fe4382655c3af58ffac2e2f759d072a4858607dbb147c
7
- data.tar.gz: 5bfa529d72df4e52027e3057c6237709910cbde697d316063a939c46d2610aaa1967cac7981c130eee7ca1a2468fce0b4df3b5aa94b5edd327ae04d62c5f7a57
6
+ metadata.gz: c2bce6300309a639b3f7ae82c2d6a4019026c048552087d90d20eb525dd30cd79793c05c070b60358f1c78cbe79c054bdd33f2e360fbe81d4b97db283a20d67e
7
+ data.tar.gz: 024cc4b227c6abd11740fa7e70de441f0c9e73a3c53dea13559cb7df7cd11a72e68a8d2e2c6cb1f3cd8733e36c5d337178bc3ddd7597710c78adaf45619e9eb6
data/README.md CHANGED
@@ -99,13 +99,14 @@ $ awspec generate ec2 vpc-ab123cde >> spec/ec2_spec.rb
99
99
  - [x] IAM Role (`iam_role`)
100
100
  - [x] IAM Policy (`iam_policy`)
101
101
  - [x] ElastiCache (`elasticache`)
102
- - [x] ElastiCache Cache Parameter Group
102
+ - [x] ElastiCache Cache Parameter Group (`elasticache_cache_parameter_group`)
103
+ - CloudWatch
104
+ - [x] CloudWatch Alarm (`cloudwatch_alarm`)
103
105
 
104
106
  [Resource Types more infomation here](doc/resource_types.md)
105
107
 
106
108
  ### Next..?
107
109
 
108
- - [ ] CloudWatch
109
110
  - ...
110
111
 
111
112
  ## References
@@ -19,6 +19,7 @@
19
19
  | [iam_policy](#iam_policy)
20
20
  | [elasticache](#elasticache)
21
21
  | [elasticache_cache_parameter_group](#elasticache_cache_parameter_group)
22
+ | [cloudwatch_alarm](#cloudwatch_alarm)
22
23
 
23
24
  ## <a name="ec2">ec2</a>
24
25
 
@@ -395,3 +396,20 @@ end
395
396
  ```
396
397
 
397
398
  ### exist
399
+
400
+
401
+ ## <a name="cloudwatch_alarm">cloudwatch_alarm</a>
402
+
403
+ CloudwatchAlarm resource type.
404
+
405
+ ### exist
406
+
407
+ ### have_alarm_action
408
+
409
+ ### have_insufficient_data_action
410
+
411
+ ### have_ok_action
412
+
413
+ ### belong_to_metric
414
+
415
+ #### its(:alarm_name), its(:alarm_arn), its(:alarm_description), its(:alarm_configuration_updated_timestamp), its(:actions_enabled), its(:state_value), its(:state_reason), its(:state_reason_data), its(:state_updated_timestamp), its(:metric_name), its(:namespace), its(:statistic), its(:period), its(:unit), its(:evaluation_periods), its(:threshold), its(:comparison_operator)
@@ -0,0 +1,17 @@
1
+ module Awspec::Generator
2
+ module Doc
3
+ module Type
4
+ class CloudwatchAlarm < Base
5
+ def initialize
6
+ super
7
+ @type_name = 'CloudwatchAlarm'
8
+ @type = Awspec::Type::CloudwatchAlarm.new('my-cloudwatch-alarm')
9
+ @ret = @type.resource
10
+ @matchers = %w(belong_to_metric)
11
+ @ignore_matchers = []
12
+ @describes = []
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -11,6 +11,7 @@ require 'awspec/helper/finder/elb'
11
11
  require 'awspec/helper/finder/lambda'
12
12
  require 'awspec/helper/finder/iam'
13
13
  require 'awspec/helper/finder/elasticache'
14
+ require 'awspec/helper/finder/cloudwatch'
14
15
 
15
16
  module Awspec::Helper
16
17
  module Finder
@@ -27,6 +28,7 @@ module Awspec::Helper
27
28
  include Awspec::Helper::Finder::Lambda
28
29
  include Awspec::Helper::Finder::Iam
29
30
  include Awspec::Helper::Finder::Elasticache
31
+ include Awspec::Helper::Finder::Cloudwatch
30
32
 
31
33
  # rubocop:disable all
32
34
  def initialize(id = nil)
@@ -39,6 +41,7 @@ module Awspec::Helper
39
41
  @lambda_client = Aws::Lambda::Client.new
40
42
  @iam_client = Aws::IAM::Client.new
41
43
  @elasticache_client = Aws::ElastiCache::Client.new
44
+ @cloudwatch_client = Aws::CloudWatch::Client.new
42
45
  end
43
46
  end
44
47
  end
@@ -0,0 +1,17 @@
1
+ module Awspec::Helper
2
+ module Finder
3
+ module Cloudwatch
4
+ def find_cloudwatch_alarm(id)
5
+ res = @cloudwatch_client.describe_alarms({
6
+ alarm_names: [id]
7
+ })
8
+ return res[:metric_alarms].first if res[:metric_alarms].count == 1
9
+
10
+ res = @cloudwatch_client.describe_alarms
11
+ res[:metric_alarms].find do |alarm|
12
+ alarm[:alarm_arn] == id
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -6,6 +6,7 @@ module Awspec
6
6
  vpc s3 route53_hosted_zone auto_scaling_group subnet
7
7
  route_table ebs elb lambda iam_user iam_group iam_role
8
8
  iam_policy elasticache elasticache_cache_parameter_group
9
+ cloudwatch_alarm
9
10
  )
10
11
 
11
12
  TYPES.each do |type|
@@ -23,3 +23,6 @@ require 'awspec/matcher/be_allowed_action'
23
23
  # ElastiCache
24
24
  require 'awspec/matcher/belong_to_replication_group'
25
25
  require 'awspec/matcher/belong_to_cache_subnet_group'
26
+
27
+ # CloudWatch
28
+ require 'awspec/matcher/belong_to_metric'
@@ -0,0 +1,13 @@
1
+ RSpec::Matchers.define :belong_to_metric do |name|
2
+ match do |resource|
3
+ if @namespace
4
+ resource.namespace == @namespace && resource.metric_name == name
5
+ else
6
+ resource.metric_name == name
7
+ end
8
+ end
9
+
10
+ chain :namespace do |namespace|
11
+ @namespace = namespace
12
+ end
13
+ end
@@ -0,0 +1,39 @@
1
+ # rubocop:disable all
2
+ Aws.config[:cloudwatch] = {
3
+ stub_responses: {
4
+ describe_alarms: {
5
+ metric_alarms: [
6
+ {
7
+ alarm_name: 'my-cloudwatch-alarm',
8
+ alarm_arn: 'arn:aws:cloudwatch:ap-northeast-1:1234567890:alarm:my_NumberOfProcesses',
9
+ alarm_description: 'my_NumberOfProcesses',
10
+ alarm_configuration_updated_timestamp: Time.new(2015, 1, 2, 10, 00, 00, '+00:00'),
11
+ actions_enabled: true,
12
+ ok_actions: ['arn:aws:sns:ap-northeast-1:1234567890:sns_alert'],
13
+ alarm_actions: ['arn:aws:sns:ap-northeast-1:1234567890:sns_alert'],
14
+ insufficient_data_actions: ['arn:aws:sns:ap-northeast-1:1234567890:sns_alert'],
15
+ state_value: 'OK',
16
+ state_reason: 'Threshold Crossed: 1 datapoint (53.0) was not less than or equal to the threshold (5.0).',
17
+ state_reason_data:
18
+ '{\'version\':\'1.0\',\'queryDate\':\'2015-04-04T01:06:26.904+0000\',\'startDate\':\'2015-04-04T01:01:00.000+0000\',\'statistic\':\'Average\',\'period\':300,\'recentDatapoints\':[53.0],\'threshold\':5.0}',
19
+ state_updated_timestamp: Time.new(2015, 1, 2, 10, 10, 00, '+00:00'),
20
+ metric_name: 'NumberOfProcesses',
21
+ namespace: 'my-cloudwatch-namespace',
22
+ statistic: 'Average',
23
+ dimensions:
24
+ [
25
+ {
26
+ name: 'name',
27
+ value: 'my-dimension'
28
+ }
29
+ ],
30
+ period: 300,
31
+ unit: nil,
32
+ evaluation_periods: 1,
33
+ threshold: 5.0,
34
+ comparison_operator: 'LessThanOrEqualToThreshold'
35
+ }
36
+ ]
37
+ }
38
+ }
39
+ }
@@ -17,6 +17,10 @@ module Awspec::Type
17
17
  "#{type} '#{@display_name}'"
18
18
  end
19
19
 
20
+ def inspect
21
+ to_s
22
+ end
23
+
20
24
  def exists?
21
25
  @id
22
26
  end
@@ -0,0 +1,21 @@
1
+ module Awspec::Type
2
+ class CloudwatchAlarm < Base
3
+ def initialize(id)
4
+ super
5
+ @resource = find_cloudwatch_alarm(id)
6
+ @id = @resource[:alarm_arn] if @resource
7
+ end
8
+
9
+ def has_ok_action?(name)
10
+ @resource[:ok_actions].include?(name)
11
+ end
12
+
13
+ def has_alarm_action?(name)
14
+ @resource[:alarm_actions].include?(name)
15
+ end
16
+
17
+ def has_insufficient_data_action?(name)
18
+ @resource[:insufficient_data_actions].include?(name)
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module Awspec
2
- VERSION = '0.14.1'
2
+ VERSION = '0.15.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.1
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - k1LoW
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-24 00:00:00.000000000 Z
11
+ date: 2015-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -176,6 +176,7 @@ files:
176
176
  - lib/awspec/generator/doc/type.rb
177
177
  - lib/awspec/generator/doc/type/auto_scaling_group.rb
178
178
  - lib/awspec/generator/doc/type/base.rb
179
+ - lib/awspec/generator/doc/type/cloudwatch_alarm.rb
179
180
  - lib/awspec/generator/doc/type/ebs.rb
180
181
  - lib/awspec/generator/doc/type/ec2.rb
181
182
  - lib/awspec/generator/doc/type/elasticache.rb
@@ -205,6 +206,7 @@ files:
205
206
  - lib/awspec/helper.rb
206
207
  - lib/awspec/helper/finder.rb
207
208
  - lib/awspec/helper/finder/auto_scaling.rb
209
+ - lib/awspec/helper/finder/cloudwatch.rb
208
210
  - lib/awspec/helper/finder/ebs.rb
209
211
  - lib/awspec/helper/finder/ec2.rb
210
212
  - lib/awspec/helper/finder/elasticache.rb
@@ -223,6 +225,7 @@ files:
223
225
  - lib/awspec/matcher/belong_to_cache_subnet_group.rb
224
226
  - lib/awspec/matcher/belong_to_db_subnet_group.rb
225
227
  - lib/awspec/matcher/belong_to_iam_group.rb
228
+ - lib/awspec/matcher/belong_to_metric.rb
226
229
  - lib/awspec/matcher/belong_to_replication_group.rb
227
230
  - lib/awspec/matcher/belong_to_subnet.rb
228
231
  - lib/awspec/matcher/belong_to_vpc.rb
@@ -231,6 +234,7 @@ files:
231
234
  - lib/awspec/setup.rb
232
235
  - lib/awspec/stub.rb
233
236
  - lib/awspec/stub/auto_scaling_group.rb
237
+ - lib/awspec/stub/cloudwatch_alarm.rb
234
238
  - lib/awspec/stub/ebs.rb
235
239
  - lib/awspec/stub/ec2.rb
236
240
  - lib/awspec/stub/elasticache.rb
@@ -252,6 +256,7 @@ files:
252
256
  - lib/awspec/toolbox.rb
253
257
  - lib/awspec/type/auto_scaling_group.rb
254
258
  - lib/awspec/type/base.rb
259
+ - lib/awspec/type/cloudwatch_alarm.rb
255
260
  - lib/awspec/type/ebs.rb
256
261
  - lib/awspec/type/ec2.rb
257
262
  - lib/awspec/type/elasticache.rb