olgen-god 0.8.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 2
2
+ :patch: 0
3
3
  :major: 0
4
- :minor: 8
4
+ :minor: 9
data/lib/god.rb CHANGED
@@ -38,6 +38,7 @@ require 'god/behaviors/clean_unix_socket'
38
38
  require 'god/behaviors/notify_when_flapping'
39
39
 
40
40
  require 'god/condition'
41
+ require 'god/conditions/condition_helper'
41
42
  require 'god/conditions/ping'
42
43
  require 'god/conditions/process_running'
43
44
  require 'god/conditions/process_exits'
@@ -0,0 +1,23 @@
1
+ module God
2
+ module Conditions
3
+
4
+ module ConditionHelper
5
+
6
+ def timeline_test(res)
7
+ @timeline << res
8
+ history = " - SUCCESS RATE: [#{@timeline.select { |x| x }.size}/#{@timeline.length}]"
9
+ if @timeline.select { |x| x }.size >= self.times[0]
10
+ self.info = " PASSED #{history}"
11
+ return true
12
+ elsif @timeline.select { |x| !x }.size > self.times[1] - self.times[0]
13
+ self.info = " FAILED #{history}"
14
+ return false
15
+ else
16
+ self.info = "history too short: #{history}"
17
+ return nil # do not trigger a transition
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -63,6 +63,7 @@ module God
63
63
  # c.timeout = 10
64
64
  # end
65
65
  class HttpResponseCode < PollCondition
66
+ include ConditionHelper
66
67
  attr_accessor :code_is, # e.g. 500 or '500' or [404, 500] or %w{404 500}
67
68
  :code_is_not, # e.g. 200 or '200' or [200, 302] or %w{200 302}
68
69
  :times, # e.g. 3 or [3, 5]
@@ -70,15 +71,18 @@ module God
70
71
  :port, # e.g. 8080
71
72
  :timeout, # e.g. 60.seconds
72
73
  :path, # e.g. '/'
73
- :headers # e.g. {'Host' => 'myvirtual.mydomain.com'}
74
+ :headers, # e.g. {'Host' => 'myvirtual.mydomain.com'}
75
+ :method, # e.g. :post, :get
76
+ :data # e.g. {:ua=>"Mozilla 3.5"}
74
77
 
75
78
  def initialize
76
79
  super
77
80
  self.port = 80
78
81
  self.path = '/'
79
82
  self.headers = {}
80
- self.times = [1, 1]
83
+ self.times = [3, 5]
81
84
  self.timeout = 60.seconds
85
+ self.method = :get
82
86
  end
83
87
 
84
88
  def prepare
@@ -101,19 +105,29 @@ module God
101
105
  def valid?
102
106
  valid = true
103
107
  valid &= complain("Attribute 'host' must be specified", self) if self.host.nil?
108
+ valid &= complain("Attribute 'method' must be in [:get, :post]", self) if ![:get, :post].include?(self.method)
104
109
  valid &= complain("One (and only one) of attributes 'code_is' and 'code_is_not' must be specified", self) if
105
110
  (self.code_is.nil? && self.code_is_not.nil?) || (self.code_is && self.code_is_not)
106
111
  valid
107
112
  end
108
113
 
114
+
109
115
  def test
110
116
  response = nil
111
-
112
117
  Net::HTTP.start(self.host, self.port) do |http|
113
118
  http.read_timeout = self.timeout
114
- response = http.get(self.path, self.headers)
119
+ if self.method == :get
120
+ response = http.get(self.path, self.headers)
121
+ else self.method == :post
122
+ req = Net::HTTP::Post.new(self.path, self.headers)
123
+ req.set_form_data(self.data, ';') if self.data
124
+ response = http.request(req)
125
+ end
115
126
  end
116
127
 
128
+ # require 'ruby-debug'; debugger
129
+
130
+
117
131
  actual_response_code = response.code.to_i
118
132
  if self.code_is && self.code_is.include?(actual_response_code)
119
133
  pass(actual_response_code)
@@ -139,20 +153,13 @@ module God
139
153
  private
140
154
 
141
155
  def pass(code)
142
- @timeline << true
143
- if @timeline.select { |x| x }.size >= self.times.first
144
- self.info = "http response abnormal #{history(code, true)}"
145
- true
146
- else
147
- self.info = "http response nominal #{history(code, true)}"
148
- false
149
- end
156
+ self.info = "http response 1abnormal #{history(code, true)}"
157
+ return timeline_test(true)
150
158
  end
151
159
 
152
160
  def fail(code)
153
- @timeline << false
154
- self.info = "http response nominal #{history(code, false)}"
155
- false
161
+ self.info = "http response 3nominal #{history(code, false)}"
162
+ return timeline_test(false)
156
163
  end
157
164
 
158
165
  def history(code, passed)
@@ -162,6 +169,21 @@ module God
162
169
  '[' + @history.join(", ") + ']'
163
170
  end
164
171
 
172
+ # def timeline_test(res)
173
+ # @timeline << res
174
+ # history = " - SUCCESS RATE: [#{@timeline.select { |x| x }.size}/#{@timeline.length}]"
175
+ # if @timeline.select { |x| x }.size >= self.times[0]
176
+ # self.info = " PASSED #{history}"
177
+ # return true
178
+ # elsif @timeline.select { |x| !x }.size > self.times[1] - self.times[0]
179
+ # self.info = " FAILED #{history}"
180
+ # return false
181
+ # else
182
+ # self.info = "history too short: #{history}"
183
+ # return nil # do not trigger a transition
184
+ # end
185
+ # end
186
+
165
187
  end
166
188
 
167
189
  end
@@ -2,23 +2,31 @@ module God
2
2
  module Conditions
3
3
 
4
4
  class Lambda < PollCondition
5
- attr_accessor :lambda
5
+ include ConditionHelper
6
+ attr_accessor :lambda, :times
6
7
 
8
+ def initialize
9
+ super
10
+ self.times = [1, 1]
11
+ end
12
+
13
+ def prepare
14
+ if self.times.kind_of?(Integer)
15
+ self.times = [self.times, self.times]
16
+ end
17
+ @timeline = Timeline.new(self.times[1])
18
+ end
19
+
7
20
  def valid?
8
21
  valid = true
9
22
  valid &= complain("Attribute 'lambda' must be specified", self) if self.lambda.nil?
10
23
  valid
11
24
  end
12
25
 
13
- def test
14
- if self.lambda.call()
15
- self.info = "lambda condition was satisfied"
16
- true
17
- else
18
- self.info = "lambda condition was not satisfied"
19
- false
20
- end
26
+ def test
27
+ return timeline_test(self.lambda.call)
21
28
  end
29
+
22
30
  end
23
31
 
24
32
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{olgen-god}
8
- s.version = "0.8.2"
8
+ s.version = "0.9.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tom Preston-Werner, Eugen Martin"]
12
- s.date = %q{2009-11-11}
12
+ s.date = %q{2010-02-22}
13
13
  s.default_executable = %q{god}
14
14
  s.description = %q{Fork of God - God is an easy to configure, easy to extend monitoring framework written in Ruby.}
15
15
  s.email = %q{eugen.martin@madvertise.de}
@@ -51,6 +51,7 @@ Gem::Specification.new do |s|
51
51
  "lib/god/condition.rb",
52
52
  "lib/god/conditions/always.rb",
53
53
  "lib/god/conditions/complex.rb",
54
+ "lib/god/conditions/condition_helper.rb",
54
55
  "lib/god/conditions/cpu_usage.rb",
55
56
  "lib/god/conditions/degrading_lambda.rb",
56
57
  "lib/god/conditions/disk_usage.rb",
@@ -170,7 +171,7 @@ Gem::Specification.new do |s|
170
171
  s.homepage = %q{http://github.com/olgen/god}
171
172
  s.rdoc_options = ["--charset=UTF-8"]
172
173
  s.require_paths = ["lib", "ext"]
173
- s.rubygems_version = %q{1.3.5}
174
+ s.rubygems_version = %q{1.3.6}
174
175
  s.summary = %q{Like god, but olgen!}
175
176
  s.test_files = [
176
177
  "test/configs/child_events/simple_server.rb",
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: olgen-god
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 9
8
+ - 0
9
+ version: 0.9.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Tom Preston-Werner, Eugen Martin
@@ -9,7 +14,7 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-11-11 00:00:00 +01:00
17
+ date: 2010-02-22 00:00:00 +01:00
13
18
  default_executable: god
14
19
  dependencies: []
15
20
 
@@ -54,6 +59,7 @@ files:
54
59
  - lib/god/condition.rb
55
60
  - lib/god/conditions/always.rb
56
61
  - lib/god/conditions/complex.rb
62
+ - lib/god/conditions/condition_helper.rb
57
63
  - lib/god/conditions/cpu_usage.rb
58
64
  - lib/god/conditions/degrading_lambda.rb
59
65
  - lib/god/conditions/disk_usage.rb
@@ -183,18 +189,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
183
189
  requirements:
184
190
  - - ">="
185
191
  - !ruby/object:Gem::Version
192
+ segments:
193
+ - 0
186
194
  version: "0"
187
- version:
188
195
  required_rubygems_version: !ruby/object:Gem::Requirement
189
196
  requirements:
190
197
  - - ">="
191
198
  - !ruby/object:Gem::Version
199
+ segments:
200
+ - 0
192
201
  version: "0"
193
- version:
194
202
  requirements: []
195
203
 
196
204
  rubyforge_project:
197
- rubygems_version: 1.3.5
205
+ rubygems_version: 1.3.6
198
206
  signing_key:
199
207
  specification_version: 3
200
208
  summary: Like god, but olgen!