radiosonde 0.0.7 → 0.0.8

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: 94b40282fc9d94f7f6dbeb5f325bc2077c744bbb
4
- data.tar.gz: 72f13e77d30ba5dfcd393444cb8b65cdc6e0e151
3
+ metadata.gz: 18a311529994a7e6c2d904c7bc03e5bea0b8878e
4
+ data.tar.gz: ca993fb584d98096b84100c1ffe9a7d672c1b2ee
5
5
  SHA512:
6
- metadata.gz: 8d5411e4fff69d18bbad868eb411f0bb4e096388e9d5b299122dabea146d2206572f773fd8ba4b08c96bd6498c966995e690c9d74f57b032c242ade7fe7d939a
7
- data.tar.gz: 33d53cc74162e59bebce55d090d1cdcb50d8e1cab3e53e4516366e431bc79e7250ae770e6a722aa13edb6c69f5b4b400e1395196d86344519fb994783f2a6d98
6
+ metadata.gz: 7aca86843cbefaa798a0b78525dd2548c269597ffc6d2a5b80896045fef79f19b788beae4fbeed957b2f090d440f2b8b95fd78c047c0ea6611d3b442e9dffa35
7
+ data.tar.gz: d9353663ffdd3f483f66909ea3beb962f38a1dc75fc29bd0858b6e3e2c862ce6208870664e52890dbe3b52c5939a018cc544e0401ad05e262c84660ca56809e8
data/README.md CHANGED
@@ -81,5 +81,32 @@ alarm "alarm2" do
81
81
  end
82
82
  ```
83
83
 
84
+ ### Use template
85
+
86
+ ```ruby
87
+ template "basic" do
88
+ namespace "AWS/EC2"
89
+ metric_name "CPUUtilization"
90
+ dimensions "InstanceId"=>"i-XXXXXXXX"
91
+ period 300
92
+ statistic :average
93
+ threshold ">=", 50.0
94
+ evaluation_periods 1
95
+ actions_enabled true
96
+ alarm_actions []
97
+ ok_actions []
98
+ insufficient_data_actions [context.sns_topic]
99
+ end
100
+
101
+ alarm "alarm1" do
102
+ include_template "basic", :sns_topic=>"arn:aws:sns:us-east-1:123456789012:my_topic"
103
+ end
104
+
105
+ alarm "alarm2" do
106
+ context.sns_topic = "arn:aws:sns:us-east-1:123456789012:my_topic2"
107
+ include_template "basic"
108
+ end
109
+ ```
110
+
84
111
  ## Similar tools
85
112
  * [Codenize.tools](http://codenize.tools/)
@@ -1,8 +1,10 @@
1
1
  class Radiosonde::DSL::Context::Alarm
2
2
  include Radiosonde::DSL::Validator
3
+ include Radiosonde::TemplateHelper
3
4
 
4
- def initialize(name, &block)
5
+ def initialize(context, name, &block)
5
6
  @error_identifier = "Alarm `#{name}`"
7
+ @context = context.merge(:alarm_name => name)
6
8
  @result = OpenStruct.new(
7
9
  :alarm_name => name,
8
10
  :alarm_actions => [],
@@ -1,5 +1,6 @@
1
1
  class Radiosonde::DSL::Context
2
2
  include Radiosonde::DSL::Validator
3
+ include Radiosonde::TemplateHelper
3
4
 
4
5
  class << self
5
6
  def eval(dsl, path, opts = {})
@@ -16,13 +17,24 @@ class Radiosonde::DSL::Context
16
17
  @options = options
17
18
  @result = OpenStruct.new(:alarms => [])
18
19
  @alarm_names = []
20
+
21
+ @context = Hashie::Mash.new(
22
+ :path => path,
23
+ :options => options,
24
+ :templates => {}
25
+ )
26
+
19
27
  instance_eval(&block)
20
28
  end
21
29
 
22
30
  private
23
31
 
32
+ def template(name, &block)
33
+ @context.templates[name.to_s] = block
34
+ end
35
+
24
36
  def require(file)
25
- alarmfile = File.expand_path(File.join(File.dirname(@path), file))
37
+ alarmfile = (file =~ %r|\A/|) ? file : File.expand_path(File.join(File.dirname(@path), file))
26
38
 
27
39
  if File.exist?(alarmfile)
28
40
  instance_eval(File.read(alarmfile), alarmfile)
@@ -39,7 +51,7 @@ class Radiosonde::DSL::Context
39
51
  not @alarm_names.include?(name)
40
52
  end
41
53
 
42
- @result.alarms << Radiosonde::DSL::Context::Alarm.new(name, &block).result
54
+ @result.alarms << Radiosonde::DSL::Context::Alarm.new(@context, name, &block).result
43
55
  @alarm_names << name
44
56
  end
45
57
  end
@@ -21,7 +21,8 @@ class Radiosonde::Logger < ::Logger
21
21
  message << ": #{log_id}" if log_id
22
22
  message << ' (dry-run)' if @options && @options[:dry_run]
23
23
  logger = (@options && @options[:logger]) || Radiosonde::Logger.instance
24
- logger.send(level, message.send(color))
24
+ message = message.send(color) if color
25
+ logger.send(level, message)
25
26
  end
26
27
  end
27
28
  end
@@ -0,0 +1,18 @@
1
+ module Radiosonde::TemplateHelper
2
+ def include_template(template_name, context = {})
3
+ tmplt = @context.templates[template_name.to_s]
4
+
5
+ unless tmplt
6
+ raise "Template `#{template_name}` is not defined"
7
+ end
8
+
9
+ context_orig = @context
10
+ @context = @context.merge(context)
11
+ instance_eval(&tmplt)
12
+ @context = context_orig
13
+ end
14
+
15
+ def context
16
+ @context
17
+ end
18
+ end
@@ -22,4 +22,18 @@ module Radiosonde::Utils
22
22
  return hash
23
23
  end
24
24
  module_function :collect_to_hash
25
+
26
+ class << self
27
+ def diff(obj1, obj2, options = {})
28
+ diffy = Diffy::Diff.new(
29
+ obj1.pretty_inspect,
30
+ obj2.pretty_inspect,
31
+ :diff => '-u'
32
+ )
33
+
34
+ out = diffy.to_s(options[:color] ? :color : :text).gsub(/\s+\z/m, '')
35
+ out.gsub!(/^/, options[:indent]) if options[:indent]
36
+ out
37
+ end
38
+ end # of class methods
25
39
  end
@@ -1,3 +1,3 @@
1
1
  module Radiosonde
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
@@ -56,7 +56,10 @@ class Radiosonde::Wrapper::Alarm
56
56
 
57
57
  def update(dsl)
58
58
  delta = diff(dsl)
59
- log(:info, 'Update Alarm', :green, "#{self.alarm_name}: #{format_delta(delta)}")
59
+ old_attrs = Hash[delta.map {|k, v| [k, v[:old]] }]
60
+ new_attrs = Hash[delta.map {|k, v| [k, v[:new]] }]
61
+ log(:info, 'Update Alarm', :green)
62
+ log(:info, " #{self.alarm_name}:\n".green + Radiosonde::Utils.diff(old_attrs, new_attrs, :color => @options[:color], :indent => ' '), false)
60
63
 
61
64
  unless @options[:dry_run]
62
65
  opts = self.class.normalize_attrs(dsl)
@@ -91,12 +94,6 @@ class Radiosonde::Wrapper::Alarm
91
94
  return delta
92
95
  end
93
96
 
94
- def format_delta(delta)
95
- delta.map {|name, values|
96
- "#{name}(#{values[:old].inspect} --> #{values[:new].inspect})"
97
- }.join(', ')
98
- end
99
-
100
97
  def normalize(name, value)
101
98
  if [Array, Hash].any? {|c| value.kind_of?(c) }
102
99
  value.sort_by {|i| i.to_s }
data/lib/radiosonde.rb CHANGED
@@ -5,11 +5,15 @@ require 'json'
5
5
  require 'logger'
6
6
  require 'ostruct'
7
7
  require 'singleton'
8
+ require 'pp'
8
9
 
9
10
  require 'aws-sdk-v1'
10
11
  require 'term/ansicolor'
12
+ require 'diffy'
13
+ require 'hashie'
11
14
 
12
15
  require 'radiosonde/logger'
16
+ require 'radiosonde/template_helper'
13
17
  require 'radiosonde/utils'
14
18
  require 'radiosonde/client'
15
19
  require 'radiosonde/dsl'
data/radiosonde.gemspec CHANGED
@@ -19,8 +19,10 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_dependency 'aws-sdk-v1'
22
- spec.add_dependency "json"
23
- spec.add_dependency "term-ansicolor"
22
+ spec.add_dependency 'json'
23
+ spec.add_dependency 'term-ansicolor'
24
+ spec.add_dependency 'diffy'
25
+ spec.add_dependency 'hashie'
24
26
  spec.add_development_dependency 'bundler', '~> 1.5'
25
27
  spec.add_development_dependency 'rake'
26
28
  spec.add_development_dependency 'rspec', '>= 3.0.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radiosonde
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-28 00:00:00.000000000 Z
11
+ date: 2015-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-v1
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: diffy
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: hashie
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: bundler
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -124,6 +152,7 @@ files:
124
152
  - lib/radiosonde/ext/cloud_watch_ext.rb
125
153
  - lib/radiosonde/ext/string_ext.rb
126
154
  - lib/radiosonde/logger.rb
155
+ - lib/radiosonde/template_helper.rb
127
156
  - lib/radiosonde/utils.rb
128
157
  - lib/radiosonde/version.rb
129
158
  - lib/radiosonde/wrapper.rb
@@ -153,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
182
  version: '0'
154
183
  requirements: []
155
184
  rubyforge_project:
156
- rubygems_version: 2.0.14
185
+ rubygems_version: 2.4.8
157
186
  signing_key:
158
187
  specification_version: 4
159
188
  summary: Radiosonde is a tool to manage CloudWatch Alarm.