litmus_paper 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.2
4
3
  - 1.9.3
5
4
  - 2.0.0
6
5
  sudo: false
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # LitmusPaper
2
2
 
3
- Backend health tester for HA Services
3
+ Backend health tester for HA Services, or as an agent-check for HAProxy
4
4
 
5
5
  [![Build Status](https://secure.travis-ci.org/braintree/litmus_paper.png)](http://travis-ci.org/braintree/litmus_paper)
6
6
 
@@ -20,7 +20,8 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- TODO: Write usage instructions here
23
+ Use the sample config to run it under unicorn. Or when running it as an
24
+ agent-check for HAProxy use the sample xinetd config.
24
25
 
25
26
  ## Contributing
26
27
 
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'litmus_paper'
5
+ require 'litmus_paper/cli/agent_check'
6
+
7
+ LitmusPaper::CLI::AgentCheck.new.run(ARGV)
@@ -0,0 +1,71 @@
1
+ module LitmusPaper
2
+ module CLI
3
+ class AgentCheck
4
+
5
+ def parse_args(args)
6
+ options = {}
7
+ optparser = OptionParser.new do |opts|
8
+ opts.on("-s", "--service SERVICE", "Service to check") do |s|
9
+ options[:service] = s
10
+ end
11
+ opts.on("-c", "--config CONFIG", "Path to config file") do |c|
12
+ options[:config] = c
13
+ end
14
+ opts.on("-h", "--help", "Help text") do |h|
15
+ options[:help] = h
16
+ end
17
+ end
18
+
19
+ begin
20
+ optparser.parse! args
21
+ rescue OptionParser::InvalidOption => e
22
+ puts e
23
+ puts optparser
24
+ exit 1
25
+ end
26
+
27
+ if options[:help]
28
+ puts optparser
29
+ exit 0
30
+ end
31
+
32
+ if !options.has_key?(:service)
33
+ puts "Error: `-s SERVICE` required"
34
+ puts optparser
35
+ exit 1
36
+ end
37
+ options
38
+ end
39
+
40
+ def output_service_status(service, stdout)
41
+ output = []
42
+ health = LitmusPaper.check_service(service)
43
+ if health.nil?
44
+ output << "failed#NOT_FOUND"
45
+ else
46
+ case health.direction
47
+ when :up, :health
48
+ output << "ready"
49
+ when :down
50
+ output << "drain"
51
+ when :none
52
+ if health.ok?
53
+ output << "ready"
54
+ else
55
+ output << "down"
56
+ end
57
+ end
58
+ output << "#{health.value.to_s}%"
59
+ end
60
+ stdout.printf("%s\r\n", output.join("\t"))
61
+ end
62
+
63
+ def run(args)
64
+ options = parse_args(args)
65
+ LitmusPaper.configure(options[:config])
66
+ output_service_status(options[:service], $stdout)
67
+ end
68
+
69
+ end
70
+ end
71
+ end
@@ -1,3 +1,3 @@
1
1
  module LitmusPaper
2
- VERSION = "0.9.3"
2
+ VERSION = "0.9.4"
3
3
  end
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+ require 'litmus_paper/cli/agent_check'
3
+
4
+ describe LitmusPaper::CLI::AgentCheck do
5
+ before :each do
6
+ LitmusPaper.configure(TEST_CONFIG)
7
+ end
8
+
9
+ def agent_check(service)
10
+ output = StringIO.new
11
+ LitmusPaper::CLI::AgentCheck.new.output_service_status(service, output)
12
+ output.rewind
13
+ output.readline
14
+ end
15
+
16
+ describe "output_service_status" do
17
+ it "returns the forced health value for a healthy service" do
18
+ test_service = LitmusPaper::Service.new('test', [AlwaysAvailableDependency.new], [LitmusPaper::Metric::ConstantMetric.new(100)])
19
+ LitmusPaper.services['test'] = test_service
20
+ LitmusPaper::StatusFile.service_health_file("test").create("Forcing health", 88)
21
+ agent_check("test").should == "ready\t88%\r\n"
22
+ end
23
+
24
+ it "returns the actual health value for an unhealthy service when the measured health is less than the forced value" do
25
+ test_service = LitmusPaper::Service.new('test', [NeverAvailableDependency.new], [LitmusPaper::Metric::ConstantMetric.new(100)])
26
+ LitmusPaper.services['test'] = test_service
27
+ LitmusPaper::StatusFile.service_health_file("test").create("Forcing health", 88)
28
+ agent_check("test").should == "ready\t0%\r\n"
29
+ end
30
+
31
+ it "is 'ready' when the service is passing" do
32
+ test_service = LitmusPaper::Service.new('test', [AlwaysAvailableDependency.new], [LitmusPaper::Metric::ConstantMetric.new(100)])
33
+ LitmusPaper.services['test'] = test_service
34
+ agent_check("test").should == "ready\t100%\r\n"
35
+ end
36
+
37
+ it "is 'down' when the check fails" do
38
+ test_service = LitmusPaper::Service.new('test', [NeverAvailableDependency.new], [LitmusPaper::Metric::ConstantMetric.new(100)])
39
+ LitmusPaper.services['test'] = test_service
40
+ agent_check("test").should == "down\t0%\r\n"
41
+ end
42
+
43
+ it "is 'failed' when the service is unknown" do
44
+ agent_check("unknown").should == "failed#NOT_FOUND\r\n"
45
+ end
46
+
47
+ it "is 'drain' when an up file and down file exists" do
48
+ test_service = LitmusPaper::Service.new('test', [AlwaysAvailableDependency.new], [LitmusPaper::Metric::ConstantMetric.new(100)])
49
+ LitmusPaper.services['test'] = test_service
50
+ LitmusPaper::StatusFile.service_up_file("test").create("Up for testing")
51
+ LitmusPaper::StatusFile.service_down_file("test").create("Down for testing")
52
+ agent_check("test").should == "drain\t0%\r\n"
53
+ end
54
+
55
+ it "is 'drain' when a global down file and up file exists" do
56
+ test_service = LitmusPaper::Service.new('test', [AlwaysAvailableDependency.new], [LitmusPaper::Metric::ConstantMetric.new(100)])
57
+ LitmusPaper.services['test'] = test_service
58
+ LitmusPaper::StatusFile.global_down_file.create("Down for testing")
59
+ LitmusPaper::StatusFile.global_up_file.create("Up for testing")
60
+ agent_check("test").should == "drain\t0%\r\n"
61
+ end
62
+
63
+ it "is 'ready' when an up file exists" do
64
+ test_service = LitmusPaper::Service.new('test', [NeverAvailableDependency.new], [LitmusPaper::Metric::ConstantMetric.new(100)])
65
+ LitmusPaper.services['test'] = test_service
66
+ LitmusPaper::StatusFile.service_up_file("test").create("Up for testing")
67
+ agent_check("test").should == "ready\t100%\r\n"
68
+ end
69
+
70
+ it "is 'drain' when a global down file exists" do
71
+ test_service = LitmusPaper::Service.new('test', [AlwaysAvailableDependency.new], [LitmusPaper::Metric::ConstantMetric.new(100)])
72
+ LitmusPaper.services['test'] = test_service
73
+ LitmusPaper::StatusFile.global_down_file.create("Down for testing")
74
+ agent_check("test").should == "drain\t0%\r\n"
75
+ end
76
+
77
+ it "is 'ready' when a global up file exists" do
78
+ test_service = LitmusPaper::Service.new('test', [NeverAvailableDependency.new], [LitmusPaper::Metric::ConstantMetric.new(100)])
79
+ LitmusPaper.services['test'] = test_service
80
+ LitmusPaper::StatusFile.global_up_file.create("Up for testing")
81
+ agent_check("test").should == "ready\t100%\r\n"
82
+ end
83
+ end
84
+ end
data/xinetd.conf ADDED
@@ -0,0 +1,13 @@
1
+ service internet_health
2
+ {
3
+ disable = no
4
+ socket_type = stream
5
+ protocol = tcp
6
+ port = 9191
7
+ user = agent-check
8
+ wait = no
9
+ server = /usr/bin/litmus-agent-check
10
+ server_args = -s isp
11
+ type = UNLISTED
12
+ instances = 10
13
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: litmus_paper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-03-17 00:00:00.000000000 Z
12
+ date: 2017-03-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
@@ -176,6 +176,7 @@ email:
176
176
  - code@getbraintree.com
177
177
  executables:
178
178
  - litmus
179
+ - litmus-agent-check
179
180
  - litmusctl
180
181
  extensions: []
181
182
  extra_rdoc_files: []
@@ -189,6 +190,7 @@ files:
189
190
  - README.md
190
191
  - Rakefile
191
192
  - bin/litmus
193
+ - bin/litmus-agent-check
192
194
  - bin/litmusctl
193
195
  - config.ru
194
196
  - lib/facts/loadaverage.rb
@@ -199,6 +201,7 @@ files:
199
201
  - lib/litmus_paper/cli/admin/force.rb
200
202
  - lib/litmus_paper/cli/admin/list.rb
201
203
  - lib/litmus_paper/cli/admin/status.rb
204
+ - lib/litmus_paper/cli/agent_check.rb
202
205
  - lib/litmus_paper/cli/server.rb
203
206
  - lib/litmus_paper/configuration.rb
204
207
  - lib/litmus_paper/configuration_file.rb
@@ -222,6 +225,7 @@ files:
222
225
  - litmus_paper.gemspec
223
226
  - spec/litmus_paper/app_spec.rb
224
227
  - spec/litmus_paper/cli/admin_spec.rb
228
+ - spec/litmus_paper/cli/agent_check_spec.rb
225
229
  - spec/litmus_paper/configuration_file_spec.rb
226
230
  - spec/litmus_paper/dependency/file_contents_spec.rb
227
231
  - spec/litmus_paper/dependency/haproxy_backends_spec.rb
@@ -255,6 +259,7 @@ files:
255
259
  - spec/support/test.d.config
256
260
  - spec/support/test.reload.config
257
261
  - spec/support/test.unicorn.config
262
+ - xinetd.conf
258
263
  homepage: https://github.com/braintree/litmus_paper
259
264
  licenses: []
260
265
  post_install_message:
@@ -267,12 +272,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
267
272
  - - ! '>='
268
273
  - !ruby/object:Gem::Version
269
274
  version: '0'
275
+ segments:
276
+ - 0
277
+ hash: 293212437870820872
270
278
  required_rubygems_version: !ruby/object:Gem::Requirement
271
279
  none: false
272
280
  requirements:
273
281
  - - ! '>='
274
282
  - !ruby/object:Gem::Version
275
283
  version: '0'
284
+ segments:
285
+ - 0
286
+ hash: 293212437870820872
276
287
  requirements: []
277
288
  rubyforge_project:
278
289
  rubygems_version: 1.8.23
@@ -282,6 +293,7 @@ summary: Backend health tester for HA Services, partner project of big_brother
282
293
  test_files:
283
294
  - spec/litmus_paper/app_spec.rb
284
295
  - spec/litmus_paper/cli/admin_spec.rb
296
+ - spec/litmus_paper/cli/agent_check_spec.rb
285
297
  - spec/litmus_paper/configuration_file_spec.rb
286
298
  - spec/litmus_paper/dependency/file_contents_spec.rb
287
299
  - spec/litmus_paper/dependency/haproxy_backends_spec.rb