amphibian 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -2,3 +2,9 @@
2
2
 
3
3
  * 1 major enhancement:
4
4
  * Initial release
5
+
6
+ == 0.0.2 2009-06-28
7
+
8
+ * 2 major enhancements:
9
+ * adding 'check_balancer_members' executable
10
+ * fixing output of 'BalancerManager#enabled_hosts' and 'BalancerManager#disabled_hosts'
data/Manifest.txt CHANGED
@@ -3,6 +3,7 @@ Manifest.txt
3
3
  PostInstall.txt
4
4
  README.rdoc
5
5
  Rakefile
6
+ bin/check_balancer_members
6
7
  lib/amphibian.rb
7
8
  lib/amphibian/balancerManagerDocument.rb
8
9
  lib/amphibian/runner.rb
data/README.rdoc CHANGED
@@ -4,17 +4,37 @@
4
4
 
5
5
  Amphibian is a ruby library for accessing and interacting with an Apache mod_proxy_balancer via the web GUI created by the balancer_manager directive.
6
6
 
7
+ Amhpbian works by scraping the balancer-manager page, and sending get requests with appropriate query strings to the balancer manager in order to enable and disable hosts.
8
+
7
9
  == FEATURES/PROBLEMS:
8
10
 
9
- * TODO
11
+ Allows you to access the different balancers and members on the Apache mod_proxy_balancer balancer-manager handler page.
12
+
13
+ Also, investigating controlling the load balancer via the web page, but use at your own risk.
14
+
10
15
 
11
16
  == SYNOPSIS:
12
17
 
13
- * TODO
18
+ nick-stielaus-computer-3:amphibian nick$ irb
19
+ >> require 'amphibian'
20
+ => true
21
+ >> a = "http://example.com/balancer-manager"
22
+ => "http://example.com/balancer-manager"
23
+ >> amp = Amphibian::BalancerManager.new(a)
24
+ >> amp.hosts
25
+ => ["http://127.0.0.1:10000", "http://127.0.0.1:10001", "http://127.0.0.1:10002"]
26
+ >> amp.enabled_hosts
27
+ => ["http://127.0.0.1:10001", "http://127.0.0.1:10002"]
28
+ >> amp.disabled_hosts
29
+ => ["http://127.0.0.1:10000"]
30
+ >> amp.hosts_with_status
31
+ => {"http://127.0.0.1:10000"=>"Dis", "http://127.0.0.1:10001"=>"Ok", "http://127.0.0.1:10002"=>"Ok"}
32
+
14
33
 
15
34
  == REQUIREMENTS:
16
35
 
17
- * TODO
36
+ * Ruby stuff
37
+ * Apache, mod_proxy, mod_proxy_balancer, and an accessible balancer-manager page.
18
38
 
19
39
  == INSTALL:
20
40
 
data/Rakefile CHANGED
@@ -9,6 +9,8 @@ $hoe = Hoe.new('amphibian', Amphibian::VERSION) do |p|
9
9
  p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
10
10
  p.post_install_message = 'PostInstall.txt'
11
11
  p.rubyforge_name = p.name
12
+ p.bin_files = ["bin/check_balancer_members"]
13
+
12
14
  # p.extra_deps = [
13
15
  # ['activesupport','>= 2.0.2'],
14
16
  # ]
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'amphibian'
5
+
6
+ options = {:dry_run => false, :test_page => '/', :test_regex => nil}
7
+
8
+ OptionParser.new do |opts|
9
+ opts.banner = "Usage: #{File.basename($0)}"
10
+
11
+ opts.on("-h", "--help", "Displays this help info") do
12
+ puts opts
13
+ exit 0
14
+ end
15
+
16
+ opts.on("-d", "--dry-run", "Prints and logs, but does not change balancer manager.") do |d|
17
+ options[:dry_run] = d
18
+ end
19
+
20
+ opts.on("-b", "--balancer-manager URL", "The URL of the balancer-manager to use.") do |b|
21
+ options[:balancer_manager_url] = b
22
+ end
23
+
24
+ opts.on("-p", "--test-page PAGE", "The page to test with the heartbeat, i.e. '/pages/heartbeat'.") do |p|
25
+ options[:test_page] = p
26
+ end
27
+
28
+ opts.on("-r", "--test-regex REGEX", "The regex to run against the test page that verify's the page is loading correctly.") do |r|
29
+ options[:test_regex] = r
30
+ end
31
+
32
+ # TODO: Version
33
+ # opts.on_tail("--version", "Show version") do
34
+ # puts Amphibian::Version.join('.')
35
+ # exit
36
+ # end
37
+
38
+ begin
39
+ opts.parse!(ARGV)
40
+ rescue OptionParser::ParseError => e
41
+ warn e.message
42
+ puts opts
43
+ exit 1
44
+ end
45
+ end
46
+
47
+ # Arg checking...
48
+ abort "You must specify the URL of the balancer-manager to use." if options[:balancer_manager_url].nil?
49
+
50
+ # Instanciate and check!
51
+ amp = Amphibian::Runner.new(options[:balancer_manager_url], options[:test_page], options[:test_regex], options[:dry_run])
52
+ amp.do_check
53
+
54
+
data/lib/amphibian.rb CHANGED
@@ -16,5 +16,5 @@ require 'amphibian/balancerManagerDocument'
16
16
 
17
17
 
18
18
  module Amphibian
19
- VERSION = '0.0.1'
19
+ VERSION = '0.0.2'
20
20
  end
@@ -30,17 +30,23 @@ module Amphibian
30
30
  @hosts ||= (get_doc/'a').select{|a_tag| a_tag.inner_text =~ /^http:/}.map{|a_tag| a_tag.inner_text}
31
31
  end
32
32
 
33
+ # Get an array of hosts that are in 'Ok' state
34
+ #---
33
35
  # TODO: Optionally force refresh
36
+ #+++
34
37
  def enabled_hosts
35
38
  hosts_array = []
36
- hosts_with_status.select{|host,state| state == 'Ok'}.each{|host| hosts_array << host}
39
+ hosts_with_status.select{|host,state| state == 'Ok'}.each{|host, state| hosts_array << host}
37
40
  hosts_array
38
41
  end
39
42
 
43
+ # Get an array of hosts that are not in 'Ok' state
44
+ #---
40
45
  # TODO: Optionally force refresh
46
+ #+++
41
47
  def disabled_hosts
42
48
  hosts_array = []
43
- hosts_with_status.select{|host,state| state != 'Ok'}.each{|host| hosts_array << host}
49
+ hosts_with_status.select{|host,state| state != 'Ok'}.each{|host, state| hosts_array << host}
44
50
  hosts_array
45
51
  end
46
52
 
@@ -93,7 +99,7 @@ private
93
99
  end
94
100
  end
95
101
 
96
- def log_error(error)
102
+ def log_error(error = "")
97
103
  puts "ERROR: #{error}"
98
104
  end
99
105
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amphibian
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Stielau
@@ -32,11 +32,11 @@ dependencies:
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.8.0
34
34
  version:
35
- description: Amphibian is a ruby library for accessing and interacting with an Apache mod_proxy_balancer via the web GUI created by the balancer_manager directive.
35
+ description: Amphibian is a ruby library for accessing and interacting with an Apache mod_proxy_balancer via the web GUI created by the balancer_manager directive. Amhpbian works by scraping the balancer-manager page, and sending get requests with appropriate query strings to the balancer manager in order to enable and disable hosts.
36
36
  email:
37
37
  - nick.stielau@gmail.com
38
- executables: []
39
-
38
+ executables:
39
+ - check_balancer_members
40
40
  extensions: []
41
41
 
42
42
  extra_rdoc_files:
@@ -50,6 +50,7 @@ files:
50
50
  - PostInstall.txt
51
51
  - README.rdoc
52
52
  - Rakefile
53
+ - bin/check_balancer_members
53
54
  - lib/amphibian.rb
54
55
  - lib/amphibian/balancerManagerDocument.rb
55
56
  - lib/amphibian/runner.rb
@@ -84,7 +85,7 @@ rubyforge_project: amphibian
84
85
  rubygems_version: 1.3.1
85
86
  signing_key:
86
87
  specification_version: 2
87
- summary: Amphibian is a ruby library for accessing and interacting with an Apache mod_proxy_balancer via the web GUI created by the balancer_manager directive.
88
+ summary: Amphibian is a ruby library for accessing and interacting with an Apache mod_proxy_balancer via the web GUI created by the balancer_manager directive
88
89
  test_files:
89
90
  - test/test_amphibian.rb
90
91
  - test/test_helper.rb