igp 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/workflows/ruby.yml +34 -0
- data/.gitignore +56 -0
- data/.rubocop.yml +35 -0
- data/.rubocop_todo.yml +86 -0
- data/CHANGELOG +13 -0
- data/Gemfile +2 -10
- data/Guardfile +16 -0
- data/README.rdoc +2 -0
- data/Rakefile +11 -46
- data/bin/igp +3 -4
- data/igp.gemspec +28 -71
- data/lib/igp/base.rb +40 -26
- data/lib/igp/shell.rb +38 -34
- data/lib/igp/version.rb +1 -1
- data/spec/base_spec.rb +45 -38
- data/spec/format_spec.rb +46 -0
- data/spec/shell_spec.rb +93 -94
- data/spec/spec_helper.rb +13 -0
- metadata +152 -96
- data/Gemfile.lock +0 -34
- data/init.rb +0 -1
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 07b9c7b783789ada3d21617353f4470d5145856e2f555454e7f09e37de0ef5c9
|
4
|
+
data.tar.gz: e733c5f176d331afebfd2b4ff57546555767febc77d514961c6383a88706146a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 720507197bc6f4325574027108b77474053dd64c832d0462611214e74875608eb6c2f025d2d5eff53d4ae867e39697dc8cbdbaf48f7918f0bd728650d103f466
|
7
|
+
data.tar.gz: dc0e4f4da5bae955da232efe4353fc62286e49073f431f38c0fad0e4b1c34b428d54d01608a0eabc448feab509418a86af027f1b9c386d41c2db5cb0f82065d5
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ '*' ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ main ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
strategy:
|
21
|
+
matrix:
|
22
|
+
ruby-version: ['2.7', '3.0']
|
23
|
+
|
24
|
+
steps:
|
25
|
+
- uses: actions/checkout@v2
|
26
|
+
- name: Set up Ruby
|
27
|
+
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
28
|
+
with:
|
29
|
+
ruby-version: ${{ matrix.ruby-version }}
|
30
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
31
|
+
- name: Install dependencies
|
32
|
+
run: bundle install
|
33
|
+
- name: Run tests
|
34
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
## Documentation cache and generated files:
|
2
|
+
/.yardoc/
|
3
|
+
/_yardoc/
|
4
|
+
/doc/
|
5
|
+
/rdoc/
|
6
|
+
|
7
|
+
## Environment normalization:
|
8
|
+
/.bundle/
|
9
|
+
/vendor/bundle
|
10
|
+
/lib/bundler/man/
|
11
|
+
|
12
|
+
# for a library or gem, you might want to ignore these files since the code is
|
13
|
+
# intended to run in multiple environments; otherwise, check them in:
|
14
|
+
Gemfile.lock
|
15
|
+
.ruby-version
|
16
|
+
.ruby-gemset
|
17
|
+
|
18
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
19
|
+
.rvmrc
|
20
|
+
|
21
|
+
# rcov generated
|
22
|
+
coverage
|
23
|
+
|
24
|
+
# jeweler generated
|
25
|
+
pkg
|
26
|
+
|
27
|
+
# logs
|
28
|
+
log
|
29
|
+
*.log
|
30
|
+
|
31
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
32
|
+
#
|
33
|
+
# * Create a file at ~/.gitignore
|
34
|
+
# * Include files you want ignored
|
35
|
+
# * Run: git config --global core.excludesfile ~/.gitignore
|
36
|
+
#
|
37
|
+
# After doing this, these files will be ignored in all your git projects,
|
38
|
+
# saving you from having to 'pollute' every project you touch with them
|
39
|
+
#
|
40
|
+
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
41
|
+
#
|
42
|
+
# For MacOS:
|
43
|
+
#
|
44
|
+
#.DS_Store
|
45
|
+
#
|
46
|
+
# For TextMate
|
47
|
+
#*.tmproj
|
48
|
+
#tmtags
|
49
|
+
#
|
50
|
+
# For emacs:
|
51
|
+
#*~
|
52
|
+
#\#*
|
53
|
+
#.\#*
|
54
|
+
#
|
55
|
+
# For vim:
|
56
|
+
#*.swp
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
NewCops: enable
|
5
|
+
|
6
|
+
Layout/CommentIndentation:
|
7
|
+
Exclude:
|
8
|
+
- 'lib/igp/base.rb'
|
9
|
+
|
10
|
+
# Offense count: 1
|
11
|
+
# Configuration parameters: CheckForMethodsWithNoSideEffects.
|
12
|
+
Lint/Void:
|
13
|
+
Exclude:
|
14
|
+
- 'lib/igp/shell.rb'
|
15
|
+
|
16
|
+
# Offense count: 3
|
17
|
+
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
|
18
|
+
Metrics/AbcSize:
|
19
|
+
Max: 29
|
20
|
+
|
21
|
+
# Offense count: 5
|
22
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
|
23
|
+
# IgnoredMethods: refine
|
24
|
+
Metrics/BlockLength:
|
25
|
+
Max: 148
|
26
|
+
|
27
|
+
# Offense count: 1
|
28
|
+
# Configuration parameters: IgnoredMethods.
|
29
|
+
Metrics/CyclomaticComplexity:
|
30
|
+
Max: 8
|
31
|
+
|
32
|
+
# Offense count: 3
|
33
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
|
34
|
+
Metrics/MethodLength:
|
35
|
+
Max: 16
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2022-03-01 12:54:50 UTC using RuboCop version 1.25.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
# Configuration parameters: Include.
|
11
|
+
# Include: **/*.gemspec
|
12
|
+
Gemspec/RequiredRubyVersion:
|
13
|
+
Exclude:
|
14
|
+
- 'igp.gemspec'
|
15
|
+
|
16
|
+
# Offense count: 1
|
17
|
+
Lint/RescueException:
|
18
|
+
Exclude:
|
19
|
+
- 'bin/igp'
|
20
|
+
|
21
|
+
# Offense count: 1
|
22
|
+
# Configuration parameters: ForbiddenDelimiters.
|
23
|
+
# ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
|
24
|
+
Naming/HeredocDelimiterNaming:
|
25
|
+
Exclude:
|
26
|
+
- 'lib/igp/shell.rb'
|
27
|
+
|
28
|
+
# Offense count: 2
|
29
|
+
Security/Eval:
|
30
|
+
Exclude:
|
31
|
+
- 'spec/spec_helper.rb'
|
32
|
+
|
33
|
+
# Offense count: 2
|
34
|
+
# Cop supports --auto-correct.
|
35
|
+
# Configuration parameters: EnforcedStyle.
|
36
|
+
# SupportedStyles: nested, compact
|
37
|
+
Style/ClassAndModuleChildren:
|
38
|
+
Exclude:
|
39
|
+
- 'lib/igp/base.rb'
|
40
|
+
- 'lib/igp/shell.rb'
|
41
|
+
|
42
|
+
# Offense count: 1
|
43
|
+
# Cop supports --auto-correct.
|
44
|
+
Style/Encoding:
|
45
|
+
Exclude:
|
46
|
+
- 'igp.gemspec'
|
47
|
+
|
48
|
+
# Offense count: 2
|
49
|
+
# Cop supports --auto-correct.
|
50
|
+
Style/EvalWithLocation:
|
51
|
+
Exclude:
|
52
|
+
- 'spec/spec_helper.rb'
|
53
|
+
|
54
|
+
# Offense count: 1
|
55
|
+
# Cop supports --auto-correct.
|
56
|
+
Style/ExpandPathArguments:
|
57
|
+
Exclude:
|
58
|
+
- 'igp.gemspec'
|
59
|
+
|
60
|
+
# Offense count: 13
|
61
|
+
# Cop supports --auto-correct.
|
62
|
+
# Configuration parameters: EnforcedStyle.
|
63
|
+
# SupportedStyles: always, always_true, never
|
64
|
+
Style/FrozenStringLiteralComment:
|
65
|
+
Exclude:
|
66
|
+
- 'Gemfile'
|
67
|
+
- 'Guardfile'
|
68
|
+
- 'Rakefile'
|
69
|
+
- 'bin/igp'
|
70
|
+
- 'igp.gemspec'
|
71
|
+
- 'lib/igp.rb'
|
72
|
+
- 'lib/igp/base.rb'
|
73
|
+
- 'lib/igp/shell.rb'
|
74
|
+
- 'lib/igp/version.rb'
|
75
|
+
- 'spec/base_spec.rb'
|
76
|
+
- 'spec/format_spec.rb'
|
77
|
+
- 'spec/shell_spec.rb'
|
78
|
+
- 'spec/spec_helper.rb'
|
79
|
+
|
80
|
+
# Offense count: 4
|
81
|
+
# Cop supports --auto-correct.
|
82
|
+
Style/StderrPuts:
|
83
|
+
Exclude:
|
84
|
+
- 'bin/igp'
|
85
|
+
- 'lib/igp/base.rb'
|
86
|
+
- 'lib/igp/shell.rb'
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
Version 0.0.3 Release: 7th May 2011
|
2
|
+
==================================================
|
3
|
+
* more ruby 1.8.7 compatibility fixes:
|
4
|
+
- suppress net-ping error on ^C
|
5
|
+
- requires rubygems (allows bin/igp to run when not already installed as a gem)
|
6
|
+
- don't lazy-evaluate GetOptions hash values
|
7
|
+
|
8
|
+
Version 0.0.2 Release: 7th May 2011
|
9
|
+
==================================================
|
10
|
+
* properly handle time format in 1.8 and 1.9 ruby
|
11
|
+
the things we forget - 1.8 didn't have strftime milliseconds format option
|
12
|
+
* refactor output formatting to make it more testable
|
13
|
+
|
1
14
|
Version 0.0.1 Release: 7th May 2011
|
2
15
|
==================================================
|
3
16
|
* Initial packaging and release
|
data/Gemfile
CHANGED
@@ -1,11 +1,3 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
|
4
|
-
gem 'getoptions', '~> 0.3'
|
5
|
-
|
6
|
-
group :development do
|
7
|
-
gem 'rspec', '> 2.3.0', :require => 'spec'
|
8
|
-
gem 'bundler', '~> 1.0.0'
|
9
|
-
gem 'jeweler', '~> 1.5.2'
|
10
|
-
gem 'rcov', '>= 0'
|
11
|
-
end
|
3
|
+
gemspec
|
data/Guardfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
2
|
+
require 'guard/rspec/dsl'
|
3
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
4
|
+
|
5
|
+
# Feel free to open issues for suggestions and improvements
|
6
|
+
|
7
|
+
# RSpec files
|
8
|
+
rspec = dsl.rspec
|
9
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
10
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
11
|
+
watch(rspec.spec_files)
|
12
|
+
|
13
|
+
# Ruby files
|
14
|
+
ruby = dsl.ruby
|
15
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
16
|
+
end
|
data/README.rdoc
CHANGED
@@ -64,6 +64,8 @@ Ping results are written as a comma-separated record with 4 components:
|
|
64
64
|
* ping duration in seconds (if the test was a success)
|
65
65
|
* error or exception code (if any)
|
66
66
|
|
67
|
+
Examples:
|
68
|
+
|
67
69
|
# a 'good' ping example:
|
68
70
|
2011-05-07T03:34:08.078Z,true,0.006508,
|
69
71
|
# a 'bad' ping example:
|
data/Rakefile
CHANGED
@@ -1,53 +1,18 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
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'
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
13
3
|
|
14
|
-
|
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
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
35
5
|
|
6
|
+
task default: :spec
|
36
7
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
t.rspec_opts = ["-c", "-f progress"]
|
41
|
-
t.pattern = 'spec/**/*_spec.rb'
|
8
|
+
desc 'Open an irb session preloaded with this library'
|
9
|
+
task :console do
|
10
|
+
sh 'irb -rubygems -I lib -r cancannible.rb'
|
42
11
|
end
|
43
12
|
|
13
|
+
require 'rdoc/task'
|
44
14
|
|
45
|
-
|
46
|
-
|
47
|
-
|
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')
|
15
|
+
RDoc::Task.new do |rdoc|
|
16
|
+
rdoc.main = 'README.rdoc'
|
17
|
+
rdoc.rdoc_files.include('README.rdoc', 'lib /*.rb')
|
53
18
|
end
|
data/bin/igp
CHANGED
@@ -6,11 +6,10 @@ require 'getoptions'
|
|
6
6
|
|
7
7
|
begin
|
8
8
|
options = GetOptions.new(Igp::Shell::OPTIONS)
|
9
|
-
Igp::Shell.new(options,ARGV).run
|
10
|
-
rescue Interrupt
|
11
|
-
$stderr.puts
|
9
|
+
Igp::Shell.new(options, ARGV).run
|
10
|
+
rescue Interrupt, NoMethodError
|
11
|
+
$stderr.puts ''
|
12
12
|
rescue Exception => e
|
13
13
|
$stderr.puts "That wasn't meant to happen! #{e.message}"
|
14
14
|
Igp::Shell.usage
|
15
15
|
end
|
16
|
-
|
data/igp.gemspec
CHANGED
@@ -1,76 +1,33 @@
|
|
1
|
-
#
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# coding: utf-8
|
5
2
|
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'igp/version'
|
9
6
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
]
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'igp'
|
9
|
+
spec.version = Igp::VERSION
|
10
|
+
spec.authors = ['Paul Gallagher']
|
11
|
+
spec.email = ['gallagher.paul@gmail.com']
|
12
|
+
spec.summary = 'It goes PING!'
|
13
|
+
spec.description = 'Simple command-line server monitoring with a range of protocols: ICMP, TCP, UDP, HTTP/S, LDAP/S'
|
14
|
+
spec.homepage = 'https://github.com/tardate/igp'
|
15
|
+
spec.license = 'MIT'
|
48
16
|
|
49
|
-
|
50
|
-
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ['lib']
|
51
21
|
|
52
|
-
|
53
|
-
|
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
|
22
|
+
spec.add_runtime_dependency 'getoptions', '~> 0.3'
|
23
|
+
spec.add_runtime_dependency 'net-ping', '~> 2.0.8'
|
76
24
|
|
25
|
+
spec.add_development_dependency 'bundler'
|
26
|
+
spec.add_development_dependency 'guard-rspec'
|
27
|
+
spec.add_development_dependency 'rake'
|
28
|
+
spec.add_development_dependency 'rb-fsevent'
|
29
|
+
spec.add_development_dependency 'rdoc'
|
30
|
+
spec.add_development_dependency 'rspec'
|
31
|
+
spec.add_development_dependency 'rubocop'
|
32
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
33
|
+
end
|
data/lib/igp/base.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
# main class that runs the ping task
|
1
2
|
class Igp::Base
|
2
|
-
|
3
3
|
# holds the parsed options
|
4
4
|
attr_reader :options
|
5
|
+
# the output formatter
|
6
|
+
attr_reader :formatter
|
5
7
|
# the Net::Ping handler for the specific protocol required
|
6
8
|
attr_reader :ping_handler
|
7
9
|
# number of pings to perform (nil => infinite)
|
@@ -18,50 +20,62 @@ class Igp::Base
|
|
18
20
|
# :port => optionally specify the port for host (else default port is assumed)
|
19
21
|
#
|
20
22
|
def initialize(options = {})
|
23
|
+
@formatter = Format.new
|
21
24
|
@options = options
|
22
25
|
@limit = options[:limit]
|
23
26
|
@interval = options[:interval] || 5
|
24
27
|
case options[:type]
|
25
28
|
when :icmp
|
26
|
-
@ping_handler = Net::Ping::External.new(@options[:host]
|
29
|
+
@ping_handler = Net::Ping::External.new(@options[:host], @options[:port])
|
27
30
|
when :udp
|
28
|
-
@ping_handler = Net::Ping::UDP.new(@options[:host]
|
31
|
+
@ping_handler = Net::Ping::UDP.new(@options[:host], @options[:port])
|
29
32
|
when :tcp
|
30
|
-
@ping_handler = Net::Ping::TCP.new(@options[:host]
|
33
|
+
@ping_handler = Net::Ping::TCP.new(@options[:host], @options[:port])
|
31
34
|
when :http, :https
|
32
35
|
@ping_handler = Net::Ping::HTTP.new(@options[:url])
|
33
|
-
|
34
|
-
|
36
|
+
# TODO: LDAP was retired from net-ping. to add back in one way or another
|
37
|
+
# when :ldap, :ldaps
|
38
|
+
# @ping_handler = Net::Ping::LDAP.new(@options[:url])
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
38
42
|
# main routine to run a complete ping test
|
39
43
|
def run
|
40
|
-
return unless ping_handler
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
+
return unless ping_handler && formatter
|
45
|
+
|
46
|
+
formatter.header(
|
47
|
+
'# It goes PING! .. testing', options[:url],
|
48
|
+
(limit ? "#{limit} times - once" : nil),
|
49
|
+
'every', interval, 'seconds'
|
50
|
+
)
|
51
|
+
ping_count = 0
|
52
|
+
while limit.nil? || ping_count < limit
|
44
53
|
status = ping_handler.ping?
|
45
|
-
log
|
54
|
+
formatter.log(status, formatter.duration(ping_handler.duration), ping_handler.exception)
|
46
55
|
ping_count += 1
|
47
|
-
sleep interval if
|
56
|
+
sleep interval if limit.nil? || ping_count < limit
|
48
57
|
end
|
49
58
|
end
|
50
59
|
|
51
|
-
|
60
|
+
# handle output formating tasks
|
61
|
+
class Format
|
62
|
+
TIME_FORMAT = '%Y-%m-%dT%H:%M:%S.%LZ'.freeze
|
52
63
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
(limit ? "#{limit} times - once" : nil),'every',interval,'seconds'
|
58
|
-
].compact.join(' ')
|
59
|
-
end
|
64
|
+
# prints the header structure to STDERR
|
65
|
+
def header(*args)
|
66
|
+
$stderr.puts(args.compact.join(' '))
|
67
|
+
end
|
60
68
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
69
|
+
# logs ping result to STDOUT
|
70
|
+
# +args+ is an array of values to log
|
71
|
+
def log(*args)
|
72
|
+
$stdout.puts(([Time.now.utc.strftime(TIME_FORMAT)] + args).join(','))
|
73
|
+
$stdout.flush
|
74
|
+
end
|
75
|
+
|
76
|
+
# formats the duration for output. nil duration remains nil
|
77
|
+
def duration(duration)
|
78
|
+
format('%.6f', duration) if duration
|
79
|
+
end
|
66
80
|
end
|
67
|
-
end
|
81
|
+
end
|