igp 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +34 -0
- data/LICENSE +20 -0
- data/README.rdoc +88 -0
- data/Rakefile +53 -0
- data/bin/igp +16 -0
- data/igp.gemspec +76 -0
- data/init.rb +1 -0
- data/lib/igp.rb +4 -0
- data/lib/igp/base.rb +67 -0
- data/lib/igp/shell.rb +106 -0
- data/lib/igp/version.rb +3 -0
- data/spec/base_spec.rb +59 -0
- data/spec/shell_spec.rb +161 -0
- data/spec/spec_helper.rb +1 -0
- metadata +140 -0
data/CHANGELOG
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.2)
|
5
|
+
getoptions (0.3)
|
6
|
+
git (1.2.5)
|
7
|
+
jeweler (1.5.2)
|
8
|
+
bundler (~> 1.0.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
net-ldap (0.2.2)
|
12
|
+
net-ping (1.5.0)
|
13
|
+
net-ldap (~> 0.2.2)
|
14
|
+
rake (0.8.7)
|
15
|
+
rcov (0.9.9)
|
16
|
+
rspec (2.5.0)
|
17
|
+
rspec-core (~> 2.5.0)
|
18
|
+
rspec-expectations (~> 2.5.0)
|
19
|
+
rspec-mocks (~> 2.5.0)
|
20
|
+
rspec-core (2.5.1)
|
21
|
+
rspec-expectations (2.5.0)
|
22
|
+
diff-lcs (~> 1.1.2)
|
23
|
+
rspec-mocks (2.5.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.0.0)
|
30
|
+
getoptions (~> 0.3)
|
31
|
+
jeweler (~> 1.5.2)
|
32
|
+
net-ping (~> 1.5.0)
|
33
|
+
rcov
|
34
|
+
rspec (> 2.3.0)
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Paul Gallagher, gallagher.paul@gmail.com
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
= igp ... It goes PING!
|
2
|
+
|
3
|
+
igp arrived as an idea to have a simple commmand line utility for testing services supporting a range of common protocols: TCP, HTTP/S, LDAP/S and so on.
|
4
|
+
This is nothing new, but in the past -- when testing a new load balancer for example -- I always reached for a bunch of trusty (and rusty) shell scripts.
|
5
|
+
Wouldn't it be nice if there was a simple tool that had no other dependency than ruby?
|
6
|
+
|
7
|
+
Thankfully, most of the work has already been done by the {net-ping library}[https://github.com/djberg96/net-ping].
|
8
|
+
igp just provides a nice command-line wrapper.
|
9
|
+
|
10
|
+
== How to use it
|
11
|
+
|
12
|
+
Install:
|
13
|
+
|
14
|
+
gem install igp
|
15
|
+
|
16
|
+
Then you are ready to go. To test some common protocols, just provide a suitable URI.
|
17
|
+
Protocols currently supported are: icmp, http, https, ldap, ldaps, tcp, udp.
|
18
|
+
If you don't specify a port in the URI, the default well-known port will be assumed if possible
|
19
|
+
e.g. port 80 for HTTP.
|
20
|
+
|
21
|
+
igp my.server.com
|
22
|
+
# ^ ICMP assumed by default. This is the same as:
|
23
|
+
igp icmp://my.server.com
|
24
|
+
|
25
|
+
igp http://my.insecure.server.com
|
26
|
+
igp http://my.insecure.server-hiding-on-a-funny-port.com:8080/javascripts/all.js
|
27
|
+
|
28
|
+
igp https://my.secure.server.com
|
29
|
+
igp https://my.secure.server-hiding-on-a-funny-port.com:4443
|
30
|
+
|
31
|
+
igp tcp://my.tcp-service.com:9091
|
32
|
+
igp udp://my.tcp-service.com:123
|
33
|
+
|
34
|
+
igp ldap://my.insecure.ldap.server.com
|
35
|
+
igp ldaps://my.secure.ldap.server.com
|
36
|
+
|
37
|
+
Of course, you can use IP addresses too:
|
38
|
+
|
39
|
+
igp tcp://127.0.0.1:22
|
40
|
+
|
41
|
+
== Command-line Options
|
42
|
+
|
43
|
+
=== Interval
|
44
|
+
The default interval between pings is 5 seconds. You can change this with the -i or --interval parameter.
|
45
|
+
|
46
|
+
# set the ping interval to 10 seconds. Note that '=' is optional
|
47
|
+
igp my.server.com -i 10
|
48
|
+
igp my.server.com --interval=10
|
49
|
+
|
50
|
+
=== Limit
|
51
|
+
+igp+ will ping to the end of time if you let it. To limit the number of ping tests, use the -l or --limit parameter.
|
52
|
+
|
53
|
+
# I only want to ping 5 times..
|
54
|
+
igp my.server.com -l 5
|
55
|
+
igp my.server.com --limit=5
|
56
|
+
|
57
|
+
|
58
|
+
== Output format
|
59
|
+
Any messages or warnings are sent to stderr. Actual ping results are written to stdout.
|
60
|
+
|
61
|
+
Ping results are written as a comma-separated record with 4 components:
|
62
|
+
* time of the ping test (UTC/GMT in ISO 8601 / RFC 3339 format)
|
63
|
+
* test success true/false
|
64
|
+
* ping duration in seconds (if the test was a success)
|
65
|
+
* error or exception code (if any)
|
66
|
+
|
67
|
+
# a 'good' ping example:
|
68
|
+
2011-05-07T03:34:08.078Z,true,0.006508,
|
69
|
+
# a 'bad' ping example:
|
70
|
+
2011-05-07T03:31:17.173Z,false,,ping: cannot resolve my.server.com: Unknown host
|
71
|
+
|
72
|
+
|
73
|
+
== Contributing to igp
|
74
|
+
You're welcome to fork/borrow/copy the source. If you come up with any improvements though, I welcome your contributions back even more.
|
75
|
+
|
76
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
77
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
78
|
+
* Fork the project
|
79
|
+
* Start a feature/bugfix branch
|
80
|
+
* Commit and push until you are happy with your contribution
|
81
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
82
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
83
|
+
|
84
|
+
== Copyright
|
85
|
+
|
86
|
+
Copyright (c) 2011 Paul Gallagher. See LICENSE.txt for
|
87
|
+
further details.
|
88
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
$LOAD_PATH << './lib'
|
12
|
+
require 'igp'
|
13
|
+
|
14
|
+
begin
|
15
|
+
require 'jeweler'
|
16
|
+
Jeweler::Tasks.new do |gem|
|
17
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
18
|
+
gem.name = "igp"
|
19
|
+
gem.version = Igp::VERSION
|
20
|
+
gem.homepage = "http://github.com/tardate/igp"
|
21
|
+
gem.license = "MIT"
|
22
|
+
gem.summary = %Q{It goes PING!}
|
23
|
+
gem.description = %Q{command line interface for running longitudinal monitoring for various protocols: HTTP, HTTPS, ICMP and more}
|
24
|
+
gem.email = "gallagher.paul@gmail.com"
|
25
|
+
gem.authors = ["Paul Gallagher"]
|
26
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
27
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
28
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
29
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
30
|
+
end
|
31
|
+
Jeweler::RubygemsDotOrgTasks.new
|
32
|
+
rescue LoadError
|
33
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
require 'rspec'
|
38
|
+
require 'rspec/core/rake_task'
|
39
|
+
RSpec::Core::RakeTask.new do |t|
|
40
|
+
t.rspec_opts = ["-c", "-f progress"]
|
41
|
+
t.pattern = 'spec/**/*_spec.rb'
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
task :default => :spec
|
46
|
+
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "igp #{Igp::VERSION}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/bin/igp
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
3
|
+
|
4
|
+
require 'igp'
|
5
|
+
require 'getoptions'
|
6
|
+
|
7
|
+
begin
|
8
|
+
options = GetOptions.new(Igp::Shell::OPTIONS)
|
9
|
+
Igp::Shell.new(options,ARGV).run
|
10
|
+
rescue Interrupt
|
11
|
+
$stderr.puts ""
|
12
|
+
rescue Exception => e
|
13
|
+
$stderr.puts "That wasn't meant to happen! #{e.message}"
|
14
|
+
Igp::Shell.usage
|
15
|
+
end
|
16
|
+
|
data/igp.gemspec
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{igp}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Paul Gallagher"]
|
12
|
+
s.date = %q{2011-05-07}
|
13
|
+
s.description = %q{command line interface for running longitudinal monitoring for various protocols: HTTP, HTTPS, ICMP and more}
|
14
|
+
s.email = %q{gallagher.paul@gmail.com}
|
15
|
+
s.executables = ["igp"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
"CHANGELOG",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"bin/igp",
|
28
|
+
"igp.gemspec",
|
29
|
+
"init.rb",
|
30
|
+
"lib/igp.rb",
|
31
|
+
"lib/igp/base.rb",
|
32
|
+
"lib/igp/shell.rb",
|
33
|
+
"lib/igp/version.rb",
|
34
|
+
"spec/base_spec.rb",
|
35
|
+
"spec/shell_spec.rb",
|
36
|
+
"spec/spec_helper.rb"
|
37
|
+
]
|
38
|
+
s.homepage = %q{http://github.com/tardate/igp}
|
39
|
+
s.licenses = ["MIT"]
|
40
|
+
s.require_paths = ["lib"]
|
41
|
+
s.rubygems_version = %q{1.7.2}
|
42
|
+
s.summary = %q{It goes PING!}
|
43
|
+
s.test_files = [
|
44
|
+
"spec/base_spec.rb",
|
45
|
+
"spec/shell_spec.rb",
|
46
|
+
"spec/spec_helper.rb"
|
47
|
+
]
|
48
|
+
|
49
|
+
if s.respond_to? :specification_version then
|
50
|
+
s.specification_version = 3
|
51
|
+
|
52
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
53
|
+
s.add_runtime_dependency(%q<net-ping>, ["~> 1.5.0"])
|
54
|
+
s.add_runtime_dependency(%q<getoptions>, ["~> 0.3"])
|
55
|
+
s.add_development_dependency(%q<rspec>, ["> 2.3.0"])
|
56
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
57
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
58
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<net-ping>, ["~> 1.5.0"])
|
61
|
+
s.add_dependency(%q<getoptions>, ["~> 0.3"])
|
62
|
+
s.add_dependency(%q<rspec>, ["> 2.3.0"])
|
63
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
64
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
65
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
66
|
+
end
|
67
|
+
else
|
68
|
+
s.add_dependency(%q<net-ping>, ["~> 1.5.0"])
|
69
|
+
s.add_dependency(%q<getoptions>, ["~> 0.3"])
|
70
|
+
s.add_dependency(%q<rspec>, ["> 2.3.0"])
|
71
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
72
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
73
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'igp'
|
data/lib/igp.rb
ADDED
data/lib/igp/base.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
class Igp::Base
|
2
|
+
|
3
|
+
# holds the parsed options
|
4
|
+
attr_reader :options
|
5
|
+
# the Net::Ping handler for the specific protocol required
|
6
|
+
attr_reader :ping_handler
|
7
|
+
# number of pings to perform (nil => infinite)
|
8
|
+
attr_reader :limit
|
9
|
+
# number of seconds to wait between pings (default = 5)
|
10
|
+
attr_reader :interval
|
11
|
+
|
12
|
+
# expects a configuration hash as +options+ which may contain:
|
13
|
+
# :type => symbol indicating protocol to use (:icmp,:udp,:tcp:http,:https,:ldap,:ldaps)
|
14
|
+
# :limit => number of pings to perform (nil => infinite)
|
15
|
+
# :interval => number of seconds to wait between pings (default = 5)
|
16
|
+
# :url => destination url (required for http/s and ldap/s)
|
17
|
+
# :host => host name or IP address (required for icmp,tcp, and udp)
|
18
|
+
# :port => optionally specify the port for host (else default port is assumed)
|
19
|
+
#
|
20
|
+
def initialize(options = {})
|
21
|
+
@options = options
|
22
|
+
@limit = options[:limit]
|
23
|
+
@interval = options[:interval] || 5
|
24
|
+
case options[:type]
|
25
|
+
when :icmp
|
26
|
+
@ping_handler = Net::Ping::External.new(@options[:host],@options[:port])
|
27
|
+
when :udp
|
28
|
+
@ping_handler = Net::Ping::UDP.new(@options[:host],@options[:port])
|
29
|
+
when :tcp
|
30
|
+
@ping_handler = Net::Ping::TCP.new(@options[:host],@options[:port])
|
31
|
+
when :http, :https
|
32
|
+
@ping_handler = Net::Ping::HTTP.new(@options[:url])
|
33
|
+
when :ldap, :ldaps
|
34
|
+
@ping_handler = Net::Ping::LDAP.new(@options[:url])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# main routine to run a complete ping test
|
39
|
+
def run
|
40
|
+
return unless ping_handler
|
41
|
+
header
|
42
|
+
ping_count=0
|
43
|
+
while (limit.nil? || ping_count < limit) do
|
44
|
+
status = ping_handler.ping?
|
45
|
+
log status,ping_handler.duration,ping_handler.exception
|
46
|
+
ping_count += 1
|
47
|
+
sleep interval if (limit.nil? || ping_count < limit)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
protected
|
52
|
+
|
53
|
+
# prints the header structure to STDERR
|
54
|
+
def header
|
55
|
+
$stderr.puts [
|
56
|
+
'# It goes PING! .. testing',options[:url],
|
57
|
+
(limit ? "#{limit} times - once" : nil),'every',interval,'seconds'
|
58
|
+
].compact.join(' ')
|
59
|
+
end
|
60
|
+
|
61
|
+
# logs ping result to STDOUT
|
62
|
+
# +args+ is an array of values to log
|
63
|
+
def log(*args)
|
64
|
+
$stdout.puts(([Time.now.utc.strftime( "%Y-%m-%dT%H:%M:%S.%LZ" )] + args).join(','))
|
65
|
+
$stdout.flush
|
66
|
+
end
|
67
|
+
end
|
data/lib/igp/shell.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'uri'
|
2
|
+
class Igp::Shell
|
3
|
+
|
4
|
+
# holds the parsed options
|
5
|
+
attr_reader :options
|
6
|
+
# holds the URI object representing the ping target
|
7
|
+
attr_reader :uri
|
8
|
+
|
9
|
+
# initializes the shell with command line argments:
|
10
|
+
#
|
11
|
+
# +options+ is expected to be the hash structure as provided by GetOptions.new(..)
|
12
|
+
#
|
13
|
+
# +args+ is the remaining command line arguments
|
14
|
+
#
|
15
|
+
def initialize(options,args)
|
16
|
+
defaults = {
|
17
|
+
:interval => 1
|
18
|
+
}
|
19
|
+
@options = defaults.merge( (options||{}).each{|k|k} )
|
20
|
+
return unless args.first
|
21
|
+
resolve_addressing args.first
|
22
|
+
normalise_options
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
# decodes the +host+ string to type, host, port and sets the uri
|
28
|
+
def resolve_addressing(host)
|
29
|
+
@uri = URI.parse(host)
|
30
|
+
unless uri.scheme
|
31
|
+
@options[:type] = :icmp
|
32
|
+
@options[:host] = uri.to_s
|
33
|
+
@options[:url] = "#{@options[:type].to_s}://#{@options[:host]}"
|
34
|
+
return
|
35
|
+
end
|
36
|
+
@options[:url] = uri.to_s
|
37
|
+
@options[:type] = uri.scheme.to_sym
|
38
|
+
@options[:port] = uri.port
|
39
|
+
@options[:host] = uri.host
|
40
|
+
end
|
41
|
+
|
42
|
+
# sets defaults where required
|
43
|
+
def normalise_options
|
44
|
+
@options[:interval] = @options[:interval].to_i
|
45
|
+
@options[:limit] = @options[:limit].to_i if @options[:limit]
|
46
|
+
end
|
47
|
+
|
48
|
+
public
|
49
|
+
|
50
|
+
# runs the ping task
|
51
|
+
def run
|
52
|
+
case options[:type]
|
53
|
+
when :icmp,:http,:https,:tcp,:udp,:ldap,:ldaps
|
54
|
+
Igp::Base.new(options).run
|
55
|
+
else
|
56
|
+
usage
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# defines the valid command line options
|
61
|
+
OPTIONS = %w(help verbose interval=i limit=i)
|
62
|
+
|
63
|
+
# prints usage/help information
|
64
|
+
def usage
|
65
|
+
self.class.usage
|
66
|
+
end
|
67
|
+
# prints usage/help information
|
68
|
+
def self.usage
|
69
|
+
$stderr.puts <<-EOS
|
70
|
+
|
71
|
+
It goes PING! v#{Igp::VERSION}
|
72
|
+
===================================
|
73
|
+
|
74
|
+
Usage:
|
75
|
+
igp [options] uri
|
76
|
+
|
77
|
+
Options:
|
78
|
+
-h | --help :shows command help
|
79
|
+
-i= | --interval=seconds (default: 1 second)
|
80
|
+
-l= | --limit=number of tests (default: infinite)
|
81
|
+
|
82
|
+
The uri specifies the protocol, hostname and port.
|
83
|
+
The ICMP protocol is assumed if not specified.
|
84
|
+
The default well-known port is assumed if not specified.
|
85
|
+
|
86
|
+
Examples:
|
87
|
+
|
88
|
+
ICMP ping:
|
89
|
+
igp localhost
|
90
|
+
igp icmp://localhost
|
91
|
+
|
92
|
+
UDP/TCP ping:
|
93
|
+
igp udp://localhost:123
|
94
|
+
igp tcp://localhost:843
|
95
|
+
|
96
|
+
HTTP/S ping:
|
97
|
+
igp http://localhost:8080
|
98
|
+
igp https://localhost:4443
|
99
|
+
|
100
|
+
LDAP/S ping:
|
101
|
+
igp ldap://localhost
|
102
|
+
igp ldaps://localhost:6636
|
103
|
+
|
104
|
+
EOS
|
105
|
+
end
|
106
|
+
end
|
data/lib/igp/version.rb
ADDED
data/spec/base_spec.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'getoptions'
|
3
|
+
|
4
|
+
describe Igp::Base do
|
5
|
+
|
6
|
+
describe "base initialization without options" do
|
7
|
+
before do
|
8
|
+
@base = Igp::Base.new
|
9
|
+
end
|
10
|
+
it "should not set ping_handler" do
|
11
|
+
@base.ping_handler.should be_nil
|
12
|
+
end
|
13
|
+
it "should not set limit" do
|
14
|
+
@base.limit.should be_nil
|
15
|
+
end
|
16
|
+
it "should default interval to 5 sec" do
|
17
|
+
@base.interval.should eql(5)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "ping_handler configuration" do
|
22
|
+
it "should be Net::Ping::External for :icmp" do
|
23
|
+
options = { :type => :icmp, :host => 'localhost', :port => nil}
|
24
|
+
base = Igp::Base.new(options)
|
25
|
+
base.ping_handler.class.should eql(Net::Ping::External)
|
26
|
+
end
|
27
|
+
it "should be Net::Ping::UDP for :tcp" do
|
28
|
+
options = { :type => :udp, :host => 'localhost', :port => 22}
|
29
|
+
base = Igp::Base.new(options)
|
30
|
+
base.ping_handler.should be_a(Net::Ping::UDP)
|
31
|
+
end
|
32
|
+
it "should be Net::Ping::TCP for :tcp" do
|
33
|
+
options = { :type => :tcp, :host => 'localhost', :port => 22}
|
34
|
+
base = Igp::Base.new(options)
|
35
|
+
base.ping_handler.should be_a(Net::Ping::TCP)
|
36
|
+
end
|
37
|
+
it "should be Net::Ping::HTTP for :http" do
|
38
|
+
options = { :type => :http, :url => 'http://localhost'}
|
39
|
+
base = Igp::Base.new(options)
|
40
|
+
base.ping_handler.should be_a(Net::Ping::HTTP)
|
41
|
+
end
|
42
|
+
it "should be Net::Ping::HTTP for :https" do
|
43
|
+
options = { :type => :https, :url => 'https://localhost'}
|
44
|
+
base = Igp::Base.new(options)
|
45
|
+
base.ping_handler.should be_a(Net::Ping::HTTP)
|
46
|
+
end
|
47
|
+
it "should be Net::Ping::LDAP for :ldap" do
|
48
|
+
options = { :type => :ldap, :url => 'ldap://localhost'}
|
49
|
+
base = Igp::Base.new(options)
|
50
|
+
base.ping_handler.should be_a(Net::Ping::LDAP)
|
51
|
+
end
|
52
|
+
it "should be Net::Ping::LDAP for :ldaps" do
|
53
|
+
options = { :type => :ldaps, :url => 'ldaps://localhost'}
|
54
|
+
base = Igp::Base.new(options)
|
55
|
+
base.ping_handler.should be_a(Net::Ping::LDAP)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
data/spec/shell_spec.rb
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'getoptions'
|
3
|
+
|
4
|
+
describe Igp::Shell do
|
5
|
+
|
6
|
+
describe "base configuration" do
|
7
|
+
context 'without destination specified' do
|
8
|
+
before do
|
9
|
+
@options = GetOptions.new(Igp::Shell::OPTIONS, [])
|
10
|
+
end
|
11
|
+
it "should initialize without error" do
|
12
|
+
expect { Igp::Shell.new(@options,[]) }.to_not raise_error
|
13
|
+
end
|
14
|
+
it "should provide help/usage" do
|
15
|
+
Igp::Shell.respond_to?(:usage).should be_true
|
16
|
+
Igp::Shell.new(@options,[]).respond_to?(:usage).should be_true
|
17
|
+
end
|
18
|
+
it "should print usage when run" do
|
19
|
+
shell = Igp::Shell.new(@options,[])
|
20
|
+
shell.should_receive(:usage)
|
21
|
+
shell.run
|
22
|
+
end
|
23
|
+
end
|
24
|
+
context 'with destination specified' do
|
25
|
+
before do
|
26
|
+
@options_server_value = 'example.com'
|
27
|
+
@options = GetOptions.new(Igp::Shell::OPTIONS, [])
|
28
|
+
@shell = Igp::Shell.new(@options,[@options_server_value])
|
29
|
+
end
|
30
|
+
it "should default to 1 second infinte intervals" do
|
31
|
+
@shell.options[:interval].should eql(1)
|
32
|
+
@shell.options[:limit].should be_nil
|
33
|
+
end
|
34
|
+
it "should accept server and default to icmp ping" do
|
35
|
+
@shell.options[:host].should eql(@options_server_value)
|
36
|
+
@shell.options[:type].should eql(:icmp)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "tcp configuration" do
|
42
|
+
before(:each) do
|
43
|
+
@type = :tcp
|
44
|
+
@host = 'localhost'
|
45
|
+
@port = 843
|
46
|
+
@options_server_value = "#{@type.to_s}://#{@host}:#{@port}"
|
47
|
+
@shell = Igp::Shell.new(GetOptions.new(Igp::Shell::OPTIONS, []), [@options_server_value])
|
48
|
+
end
|
49
|
+
it "should support url accessor" do
|
50
|
+
@shell.options[:url].should eql(@options_server_value)
|
51
|
+
end
|
52
|
+
it "should default to tcp ping with url when given server with tcp protocol setting" do
|
53
|
+
@shell.options[:type].should eql(@type)
|
54
|
+
end
|
55
|
+
it "should resolve host/port" do
|
56
|
+
@shell.options[:host].should eql(@host)
|
57
|
+
@shell.options[:port].should eql(@port)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "udp configuration" do
|
62
|
+
before(:each) do
|
63
|
+
@type = :udp
|
64
|
+
@host = 'localhost'
|
65
|
+
@port = 22
|
66
|
+
@options_server_value = "#{@type.to_s}://#{@host}:#{@port}"
|
67
|
+
@shell = Igp::Shell.new(GetOptions.new(Igp::Shell::OPTIONS, []), [@options_server_value])
|
68
|
+
end
|
69
|
+
it "should support url accessor" do
|
70
|
+
@shell.options[:url].should eql(@options_server_value)
|
71
|
+
end
|
72
|
+
it "should default to tcp ping with url when given server with tcp protocol setting" do
|
73
|
+
@shell.options[:type].should eql(@type)
|
74
|
+
end
|
75
|
+
it "should resolve host/port" do
|
76
|
+
@shell.options[:host].should eql(@host)
|
77
|
+
@shell.options[:port].should eql(@port)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "http configuration" do
|
82
|
+
before(:each) do
|
83
|
+
@type = :http
|
84
|
+
@host = 'localhost'
|
85
|
+
@port = 80
|
86
|
+
@options_server_value = "#{@type.to_s}://#{@host}"
|
87
|
+
@shell = Igp::Shell.new(GetOptions.new(Igp::Shell::OPTIONS, []), [@options_server_value])
|
88
|
+
end
|
89
|
+
it "should support url accessor" do
|
90
|
+
@shell.options[:url].should eql(@options_server_value)
|
91
|
+
end
|
92
|
+
it "should default to tcp ping with url when given server with tcp protocol setting" do
|
93
|
+
@shell.options[:type].should eql(@type)
|
94
|
+
end
|
95
|
+
it "should resolve host/port" do
|
96
|
+
@shell.options[:host].should eql(@host)
|
97
|
+
@shell.options[:port].should eql(@port)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "https configuration" do
|
102
|
+
before(:each) do
|
103
|
+
@type = :https
|
104
|
+
@host = 'localhost'
|
105
|
+
@port = 443
|
106
|
+
@options_server_value = "#{@type.to_s}://#{@host}"
|
107
|
+
@shell = Igp::Shell.new(GetOptions.new(Igp::Shell::OPTIONS, []), [@options_server_value])
|
108
|
+
end
|
109
|
+
it "should support url accessor" do
|
110
|
+
@shell.options[:url].should eql(@options_server_value)
|
111
|
+
end
|
112
|
+
it "should default to tcp ping with url when given server with tcp protocol setting" do
|
113
|
+
@shell.options[:type].should eql(@type)
|
114
|
+
end
|
115
|
+
it "should resolve host/port" do
|
116
|
+
@shell.options[:host].should eql(@host)
|
117
|
+
@shell.options[:port].should eql(@port)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "ldap configuration" do
|
122
|
+
before(:each) do
|
123
|
+
@type = :ldap
|
124
|
+
@host = 'localhost'
|
125
|
+
@port = 389
|
126
|
+
@options_server_value = "#{@type.to_s}://#{@host}"
|
127
|
+
@shell = Igp::Shell.new(GetOptions.new(Igp::Shell::OPTIONS, []), [@options_server_value])
|
128
|
+
end
|
129
|
+
it "should support url accessor" do
|
130
|
+
@shell.options[:url].should eql(@options_server_value)
|
131
|
+
end
|
132
|
+
it "should default to tcp ping with url when given server with tcp protocol setting" do
|
133
|
+
@shell.options[:type].should eql(@type)
|
134
|
+
end
|
135
|
+
it "should resolve host/port" do
|
136
|
+
@shell.options[:host].should eql(@host)
|
137
|
+
@shell.options[:port].should eql(@port)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe "ldaps configuration" do
|
142
|
+
before(:each) do
|
143
|
+
@type = :ldaps
|
144
|
+
@host = 'localhost'
|
145
|
+
@port = 636
|
146
|
+
@options_server_value = "#{@type.to_s}://#{@host}"
|
147
|
+
@shell = Igp::Shell.new(GetOptions.new(Igp::Shell::OPTIONS, []), [@options_server_value])
|
148
|
+
end
|
149
|
+
it "should support url accessor" do
|
150
|
+
@shell.options[:url].should eql(@options_server_value)
|
151
|
+
end
|
152
|
+
it "should default to tcp ping with url when given server with tcp protocol setting" do
|
153
|
+
@shell.options[:type].should eql(@type)
|
154
|
+
end
|
155
|
+
it "should resolve host/port" do
|
156
|
+
@shell.options[:host].should eql(@host)
|
157
|
+
@shell.options[:port].should eql(@port)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'igp'
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: igp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Paul Gallagher
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-05-07 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: net-ping
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.5.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: getoptions
|
28
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0.3"
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">"
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 2.3.0
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: bundler
|
50
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.0.0
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: jeweler
|
61
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 1.5.2
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *id005
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rcov
|
72
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *id006
|
81
|
+
description: "command line interface for running longitudinal monitoring for various protocols: HTTP, HTTPS, ICMP and more"
|
82
|
+
email: gallagher.paul@gmail.com
|
83
|
+
executables:
|
84
|
+
- igp
|
85
|
+
extensions: []
|
86
|
+
|
87
|
+
extra_rdoc_files:
|
88
|
+
- LICENSE
|
89
|
+
- README.rdoc
|
90
|
+
files:
|
91
|
+
- CHANGELOG
|
92
|
+
- Gemfile
|
93
|
+
- Gemfile.lock
|
94
|
+
- LICENSE
|
95
|
+
- README.rdoc
|
96
|
+
- Rakefile
|
97
|
+
- bin/igp
|
98
|
+
- igp.gemspec
|
99
|
+
- init.rb
|
100
|
+
- lib/igp.rb
|
101
|
+
- lib/igp/base.rb
|
102
|
+
- lib/igp/shell.rb
|
103
|
+
- lib/igp/version.rb
|
104
|
+
- spec/base_spec.rb
|
105
|
+
- spec/shell_spec.rb
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
homepage: http://github.com/tardate/igp
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
hash: 497536060373054853
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
version: "0"
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: "0"
|
130
|
+
requirements: []
|
131
|
+
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 1.7.2
|
134
|
+
signing_key:
|
135
|
+
specification_version: 3
|
136
|
+
summary: It goes PING!
|
137
|
+
test_files:
|
138
|
+
- spec/base_spec.rb
|
139
|
+
- spec/shell_spec.rb
|
140
|
+
- spec/spec_helper.rb
|