IsHealthyAgg 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2008-12-17
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,10 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/is_healthy_agg.rb
6
+ bin/monitor_config.yml
7
+ lib/config_loader.rb
8
+ lib/page_scrape.rb
9
+ test/test_config_loader.rb
10
+ test/test_page_scrape.rb
@@ -0,0 +1,51 @@
1
+ = IsHealthyAgg
2
+
3
+ * http://rubyforge.org/projects/uwruby/
4
+ * http://uwruby.rubyforge.org/is_healthy_agg/
5
+
6
+ == DESCRIPTION:
7
+
8
+ Monitors multiple URLs for a configured string. Expects to find the string on at least one of the instances. If the required string isn't found on any monitored instance, it will report as error. Generates an HTML file for display with another web server.
9
+
10
+ == FEATURES/PROBLEMS:
11
+
12
+ * Monitors N URLs for a configured string
13
+ * Expects to find the search string on at least one URL
14
+ * Configuration managed through YAML config file
15
+
16
+ == SYNOPSIS:
17
+ Run the following from the command line:
18
+
19
+ is_healthy_agg
20
+
21
+ == REQUIREMENTS:
22
+
23
+
24
+ == INSTALL:
25
+
26
+ * sudo gem install is_healthy_agg
27
+
28
+ == LICENSE:
29
+
30
+ The MIT License
31
+
32
+ Copyright (c) 2008 Trent Rau
33
+
34
+ Permission is hereby granted, free of charge, to any person obtaining
35
+ a copy of this software and associated documentation files (the
36
+ 'Software'), to deal in the Software without restriction, including
37
+ without limitation the rights to use, copy, modify, merge, publish,
38
+ distribute, sublicense, and/or sell copies of the Software, and to
39
+ permit persons to whom the Software is furnished to do so, subject to
40
+ the following conditions:
41
+
42
+ The above copyright notice and this permission notice shall be
43
+ included in all copies or substantial portions of the Software.
44
+
45
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
46
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
47
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
48
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
49
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
50
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
51
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,12 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './bin/is_healthy_agg.rb'
6
+
7
+ Hoe.new('IsHealthyAgg', IsHealthyAgg::VERSION) do |p|
8
+ p.rubyforge_name = 'uwruby' # if different than lowercase project name
9
+ p.developer('Trent Rau', 'rautrr@yahoo.com')
10
+ end
11
+
12
+ # vim: syntax=Ruby
@@ -0,0 +1,39 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ $: << '../lib'
4
+
5
+ require 'yaml'
6
+ require 'lib/config_loader'
7
+ require 'lib/page_scrape'
8
+
9
+ class IsHealthyAgg
10
+ VERSION = '0.0.1'
11
+
12
+ def self.run
13
+ config_file = YAML::load(File.open("./monitor_config.yml", "r"))
14
+
15
+ config = ConfigLoader.new config_file.to_yaml
16
+
17
+ found = false
18
+
19
+ config.servers do |l|
20
+ url = l[:url]
21
+ search_string = l[:search_term]
22
+
23
+ mon = PageScrape.new url, search_string
24
+
25
+ found = true if mon.search_result
26
+ end
27
+
28
+ output_file = File.open("monitors.txt", "w")
29
+
30
+ if found then
31
+ output_file << "Tests Failed: 0"
32
+ else
33
+ output_file << "Tests Failed: 1"
34
+ end
35
+ end
36
+
37
+ end
38
+
39
+ IsHealthyAgg.run if __FILE__ == $0
@@ -0,0 +1,6 @@
1
+ ---
2
+ - :url: http://www.google.com
3
+ :search_term: omnicron
4
+ - :url: http://www.google.com
5
+ :search_term: a
6
+
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby -w
2
+
3
+ require 'yaml'
4
+
5
+ class ConfigLoader
6
+ attr_accessor :config_params
7
+
8
+ def initialize(config_string)
9
+ @config_params = YAML::load(config_string)
10
+ end
11
+
12
+ #Treat servers like each. I would have used
13
+ #the name each, but I wanted to give the user
14
+ #some idea of what information they should be getting.
15
+
16
+ def servers
17
+ server_list = @config_params
18
+
19
+ server_list.each do |i|
20
+ yield i
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,33 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ require 'open-uri'
4
+
5
+ class PageScrape
6
+ attr_accessor :uri, :search_string
7
+ attr_reader :search_result
8
+
9
+ def initialize(uri, search_string)
10
+ #Returning nil instead of raising works
11
+ #for this class' intended purpose.
12
+ #Bad URIs are expected, so we're not
13
+ #concerned about finding one.
14
+
15
+ begin
16
+ @uri = URI.parse(uri).read
17
+ rescue
18
+ @uri = ""
19
+ end
20
+
21
+ @search_string = search_string
22
+ self.scrape
23
+ end
24
+
25
+ def scrape(uri = @uri, search_string = @search_string)
26
+ #Set @search_result to nil each time you scrape
27
+ #otherwise it will always return true, even if you
28
+ #re-scrape
29
+
30
+ @search_result = nil
31
+ @search_result = true if uri.match(search_string)
32
+ end
33
+ end
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby -w
2
+
3
+ $: << 'lib'
4
+ $: << 'bin'
5
+
6
+ require 'test/unit'
7
+ require 'config_loader'
8
+ require 'yaml'
9
+
10
+ class TestConfigLoader < Test::Unit::TestCase
11
+ def setup
12
+ #Config file mock-up
13
+ config_obj = [{:url => 'http://server1', :search_term => 'fail'},
14
+ {:url => 'http://server2', :search_term => 'pass'}]
15
+
16
+ @config = ConfigLoader.new config_obj.to_yaml
17
+ end
18
+
19
+ #I'm not really sure how to test a method that
20
+ #is essentially an implementation of each
21
+
22
+ def test_servers
23
+ @config.servers do |l|
24
+ assert_match(/server?/, l[:url])
25
+ assert_match(/pass|fail/, l[:search_term])
26
+ end
27
+ end
28
+
29
+ def test_config_load_from_file
30
+ #config_obj = File.open("bin/monitor_config.yml", "r")
31
+
32
+ config_obj = YAML::load(File.open("bin/monitor_config.yml", "r"))
33
+
34
+ config_from_file = ConfigLoader.new config_obj.to_yaml
35
+
36
+ config_from_file.servers do |l|
37
+ assert_match(/google/, l[:url])
38
+ assert_match(/a|omnicron/, l[:search_term])
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby -w
2
+
3
+ $: << 'lib'
4
+
5
+ require 'test/unit'
6
+ require 'page_scrape'
7
+ require 'open-uri'
8
+
9
+ class TestPageScrape < Test::Unit::TestCase
10
+ def setup
11
+ #This would normally be used to search a URI,
12
+ #but this allows me to test using a string instead
13
+
14
+ @mon = PageScrape.new "", "test"
15
+ @string = "This is my test string"
16
+ @mon.uri = @string
17
+
18
+ #You need to re-scrape after changing the search_string
19
+ #or URI
20
+
21
+ @mon.scrape
22
+ end
23
+
24
+ def test_search
25
+ assert_equal true, @mon.search_result
26
+ end
27
+
28
+ def test_not_found
29
+ #Override search_string and re-scrape
30
+
31
+ @mon.search_string = "horses"
32
+ @mon.scrape
33
+
34
+ assert_equal nil, @mon.search_result
35
+ end
36
+
37
+ def test_scrape_bad_uri
38
+ #I could have overridden and re-scraped, but
39
+ #I wanted to illustrate how it would be used
40
+ #under normal circumstances
41
+
42
+ baduri = PageScrape.new "localhost", "horses"
43
+
44
+ assert_equal nil, baduri.search_result
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: IsHealthyAgg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Trent Rau
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-24 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.8.2
24
+ version:
25
+ description: Monitors multiple URLs for a configured string. Expects to find the string on at least one of the instances. If the required string isn't found on any monitored instance, it will report as error. Generates an HTML file for display with another web server.
26
+ email:
27
+ - rautrr@yahoo.com
28
+ executables:
29
+ - is_healthy_agg.rb
30
+ - monitor_config.yml
31
+ extensions: []
32
+
33
+ extra_rdoc_files:
34
+ - History.txt
35
+ - Manifest.txt
36
+ - README.txt
37
+ files:
38
+ - History.txt
39
+ - Manifest.txt
40
+ - README.txt
41
+ - Rakefile
42
+ - bin/is_healthy_agg.rb
43
+ - bin/monitor_config.yml
44
+ - lib/config_loader.rb
45
+ - lib/page_scrape.rb
46
+ - test/test_config_loader.rb
47
+ - test/test_page_scrape.rb
48
+ has_rdoc: true
49
+ homepage: http://rubyforge.org/projects/uwruby/
50
+ post_install_message:
51
+ rdoc_options:
52
+ - --main
53
+ - README.txt
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ requirements: []
69
+
70
+ rubyforge_project: uwruby
71
+ rubygems_version: 1.3.1
72
+ signing_key:
73
+ specification_version: 2
74
+ summary: Monitors multiple URLs for a configured string
75
+ test_files:
76
+ - test/test_config_loader.rb
77
+ - test/test_page_scrape.rb