awspec 0.18.0 → 0.18.1

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: 6db22930c102c95bc37c65c8324aa7554e74aa5b
4
- data.tar.gz: 34a00b15b832de7d042b68e1564c96750f4a6fc8
3
+ metadata.gz: 7b87cfb8b272ff03a8e80f31c85b578e884156b1
4
+ data.tar.gz: 4e98b6f864ee384c35c8e2a15f28d1362710d4d2
5
5
  SHA512:
6
- metadata.gz: 4fbcef8b5ccf42f73b20b667f535419f7a6c02352378e19486e5f23daa3861612de8a9f8c25d6f280d03cd08f2602784a3f2f1d6b27fa444451dad2af85895f8
7
- data.tar.gz: 0de1236f9099647af9840c4313989b885b464bb052163d2e1d6b559a3db1ff1dd9e2f10b6b15e0a1919c917cdbb3130d022fef1cb51891130cabf94cf47a02e8
6
+ metadata.gz: 40d3944ed0f68234739927d07852017014eac9b21299a78a1ca000e0622d75b19f41639930b73577b640713e023c544d18d7e52f543ecddce5550d65e12670cc
7
+ data.tar.gz: 3ce27c40dac0a0369afb7c460f42ef1c56472bd8092e75d094d1dfd3c25f383a037d3e6eeae51ff285be659e8e6982ff9991b8e71a7521a532004ed8f5e6c795
@@ -16,16 +16,30 @@ module Awspec
16
16
  end
17
17
  end
18
18
 
19
+ types_for_generate_all = %w(
20
+ iam_policy cloudwatch_alarm
21
+ )
22
+
19
23
  desc 'route53_hosted_zone [example.com.]', 'Generate route53_hosted_zone spec from Domain name'
20
24
  def route53_hosted_zone(hosted_zone)
21
25
  load_secrets
22
26
  puts Awspec::Generator::Spec::Route53HostedZone.new.generate_by_domain_name(hosted_zone)
23
27
  end
24
28
 
25
- desc 'iam_policy', 'Generate attached iam_policy spec'
26
- def iam_policy
27
- load_secrets
28
- puts Awspec::Generator::Spec::IamPolicy.new.generate_all
29
+ types_for_generate_all = %w(
30
+ iam_policy cloudwatch_alarm
31
+ )
32
+
33
+ types_for_generate_all.each do |type|
34
+ if type == 'iam_policy'
35
+ desc 'iam_policy', 'Generate attached iam_policy spec'
36
+ else
37
+ desc type, "Generate #{type} spec"
38
+ end
39
+ define_method type do
40
+ load_secrets
41
+ eval "puts Awspec::Generator::Spec::#{type.camelize}.new.generate_all"
42
+ end
29
43
  end
30
44
 
31
45
  no_commands do
@@ -8,6 +8,7 @@ require 'awspec/generator/spec/security_group'
8
8
  require 'awspec/generator/spec/route53_hosted_zone'
9
9
  require 'awspec/generator/spec/elb'
10
10
  require 'awspec/generator/spec/iam_policy'
11
+ require 'awspec/generator/spec/cloudwatch_alarm'
11
12
 
12
13
  # Doc
13
14
  require 'awspec/generator/doc/type'
@@ -0,0 +1,40 @@
1
+ module Awspec::Generator
2
+ module Spec
3
+ class CloudwatchAlarm
4
+ include Awspec::Helper::Finder
5
+ def generate_all
6
+ alarms = select_all_cloudwatch_alarms
7
+ alarms.empty? && fail('Not Found alarm')
8
+ ERB.new(alarm_spec_template, nil, '-').result(binding).chomp
9
+ end
10
+
11
+ def alarm_spec_template
12
+ template = <<-'EOF'
13
+ <% alarms.each do |alarm| %>
14
+ describe cloudwatch_alarm('<%= alarm.alarm_name %>') do
15
+ it { should exist }
16
+ <%- alarm.ok_actions.each do |action| -%>
17
+ it { should have_ok_action('<%= action %>') }
18
+ <%- end -%>
19
+ <%- alarm.alarm_actions.each do |action| -%>
20
+ it { should have_alarm_action('<%= action %>') }
21
+ <%- end -%>
22
+ <%- alarm.insufficient_data_actions.each do |action| -%>
23
+ it { should have_insufficient_data_action('<%= action %>') }
24
+ <%- end -%>
25
+ it { should belong_to_metric('<%= alarm.metric_name %>').namespace('<%= alarm.namespace %>') }
26
+ its(:state_value) { should eq '<%= alarm.state_value %>' }
27
+ its(:statistic) { should eq '<%= alarm.statistic %>' }
28
+ its(:period) { should eq <%= alarm.period %> }
29
+ its(:unit) { should eq '<%= alarm.unit %>' }
30
+ its(:evaluation_periods) { should eq <%= alarm.evaluation_periods %> }
31
+ its(:threshold) { should eq <%= alarm.threshold %> }
32
+ its(:comparison_operator) { should eq '<%= alarm.comparison_operator %>' }
33
+ end
34
+ <% end %>
35
+ EOF
36
+ template
37
+ end
38
+ end
39
+ end
40
+ end
@@ -12,6 +12,18 @@ module Awspec::Helper
12
12
  alarm[:alarm_arn] == id
13
13
  end
14
14
  end
15
+
16
+ def select_all_cloudwatch_alarms
17
+ selected = []
18
+ res = @cloudwatch_client.describe_alarms
19
+
20
+ loop do
21
+ selected += res.metric_alarms
22
+ (res.next_page? && res = res.next_page) || break
23
+ end
24
+
25
+ selected
26
+ end
15
27
  end
16
28
  end
17
29
  end
@@ -28,7 +28,7 @@ Aws.config[:cloudwatch] = {
28
28
  }
29
29
  ],
30
30
  period: 300,
31
- unit: nil,
31
+ unit: 'Seconds',
32
32
  evaluation_periods: 1,
33
33
  threshold: 5.0,
34
34
  comparison_operator: 'LessThanOrEqualToThreshold'
@@ -1,3 +1,3 @@
1
1
  module Awspec
2
- VERSION = '0.18.0'
2
+ VERSION = '0.18.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.18.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - k1LoW
@@ -196,6 +196,7 @@ files:
196
196
  - lib/awspec/generator/doc/type/ses_identity.rb
197
197
  - lib/awspec/generator/doc/type/subnet.rb
198
198
  - lib/awspec/generator/doc/type/vpc.rb
199
+ - lib/awspec/generator/spec/cloudwatch_alarm.rb
199
200
  - lib/awspec/generator/spec/ec2.rb
200
201
  - lib/awspec/generator/spec/elb.rb
201
202
  - lib/awspec/generator/spec/iam_policy.rb