rut 0.0.2

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.
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ results.html
3
+ pkg
4
+ html
data/.rvmrc ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.3" > .rvmrc
9
+ environment_id="ruby-1.9.3-p194@rut"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.13.4 (version)" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
+ else
29
+ # If the environment file has not yet been created, use the RVM CLI to select.
30
+ rvm --create "$environment_id" || {
31
+ echo "Failed to create RVM environment '${environment_id}'."
32
+ return 1
33
+ }
34
+ fi
35
+
36
+ # If you use bundler, this might be useful to you:
37
+ # if [[ -s Gemfile ]] && {
38
+ # ! builtin command -v bundle >/dev/null ||
39
+ # builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
40
+ # }
41
+ # then
42
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
43
+ # gem install bundler
44
+ # fi
45
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
46
+ # then
47
+ # bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
48
+ # fi
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rut.gemspec
4
+ gemspec
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rut (0.0.2)
5
+ methadone (~> 1.2.1)
6
+ snmp (~> 1.1.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ aruba (0.4.11)
12
+ childprocess (>= 0.2.3)
13
+ cucumber (>= 1.1.1)
14
+ ffi (>= 1.0.11)
15
+ rspec (>= 2.7.0)
16
+ builder (3.1.3)
17
+ childprocess (0.3.5)
18
+ ffi (~> 1.0, >= 1.0.6)
19
+ cucumber (1.2.1)
20
+ builder (>= 2.1.2)
21
+ diff-lcs (>= 1.1.3)
22
+ gherkin (~> 2.11.0)
23
+ json (>= 1.4.6)
24
+ diff-lcs (1.1.3)
25
+ ffi (1.1.5)
26
+ gherkin (2.11.2)
27
+ json (>= 1.4.6)
28
+ json (1.7.5)
29
+ methadone (1.2.1)
30
+ bundler
31
+ rake (0.9.2.2)
32
+ rdoc (3.12)
33
+ json (~> 1.4)
34
+ rspec (2.11.0)
35
+ rspec-core (~> 2.11.0)
36
+ rspec-expectations (~> 2.11.0)
37
+ rspec-mocks (~> 2.11.0)
38
+ rspec-core (2.11.1)
39
+ rspec-expectations (2.11.3)
40
+ diff-lcs (~> 1.1.3)
41
+ rspec-mocks (2.11.3)
42
+ snmp (1.1.0)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ aruba
49
+ rake (~> 0.9.2)
50
+ rdoc
51
+ rut!
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Tomas Skogberg
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,34 @@
1
+ # Rut
2
+
3
+ Rut is a CLI script that'll show you your routers uptime.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rut'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rut
18
+
19
+ ## Usage
20
+
21
+ $ rut <router's ip address>
22
+
23
+ Example:
24
+
25
+ $ rut 10.0.1.1
26
+ MyRouter has been up 102 days, 22:00:21.34
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
File without changes
@@ -0,0 +1,36 @@
1
+ require 'bundler'
2
+ require 'rake/clean'
3
+
4
+ require 'rake/testtask'
5
+
6
+ require 'cucumber'
7
+ require 'cucumber/rake/task'
8
+ gem 'rdoc' # we need the installed RDoc gem, not the system one
9
+ require 'rdoc/task'
10
+
11
+ include Rake::DSL
12
+
13
+ Bundler::GemHelper.install_tasks
14
+
15
+
16
+ Rake::TestTask.new do |t|
17
+ t.pattern = 'test/tc_*.rb'
18
+ end
19
+
20
+
21
+ CUKE_RESULTS = 'results.html'
22
+ CLEAN << CUKE_RESULTS
23
+ Cucumber::Rake::Task.new(:features) do |t|
24
+ t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty --no-source -x"
25
+ t.fork = false
26
+ end
27
+
28
+ Rake::RDocTask.new do |rd|
29
+
30
+ rd.main = "README.rdoc"
31
+
32
+ rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
33
+ end
34
+
35
+ task :default => [:test,:features]
36
+
data/bin/rut ADDED
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'methadone'
5
+ require 'rut'
6
+ require 'snmp'
7
+
8
+ class App
9
+ include Methadone::Main
10
+ include Methadone::CLILogging
11
+
12
+ attr_accessor :router_ip
13
+
14
+ main do |router_ip|
15
+ @router_ip = router_ip
16
+
17
+ SNMP::Manager.open(host: @router_ip, retries: 0, mib_modules: ["DISMAN-EVENT-MIB", "SNMPv2-MIB"]) do |manager|
18
+ run_and_handle_exceptions do
19
+ response = manager.get_value(["sysUpTimeInstance" , "sysName.0"])
20
+ days = response[0]
21
+ router_name = response[1].capitalize
22
+ puts "#{router_name} has been up #{days}"
23
+ end
24
+ end
25
+ end
26
+
27
+ # supplemental methods here
28
+
29
+ def self.run_and_handle_exceptions
30
+ begin
31
+ yield
32
+ rescue SNMP::RequestTimeout
33
+ exception_output("Host #{@router_ip} not responding", 1)
34
+ rescue SocketError
35
+ exception_output("#{@router_ip} is an invalid ip address", 2)
36
+ rescue Exception
37
+ exception_output($!.inspect, 99)
38
+ end
39
+ end
40
+
41
+ def self.exception_output(output, code)
42
+ puts output
43
+ exit(code)
44
+ end
45
+
46
+ # Declare command-line interface here
47
+
48
+ description "Shows uptime on your router"
49
+
50
+ # Require an argument
51
+
52
+ arg :router_ip
53
+
54
+ version Rut::VERSION
55
+
56
+ use_log_level_option
57
+
58
+ go!
59
+ end
@@ -0,0 +1,29 @@
1
+ Feature: See router uptime
2
+ In order to see a router's uptime
3
+ I want a one-command that print it
4
+ So I don't have to use a admin program
5
+
6
+ Scenario: App should have a basic UI
7
+ When I get help for "rut"
8
+ Then the exit status should be 0
9
+ And the banner should be present
10
+ And there should be a one line summary of what the app does
11
+ And the banner should include the version
12
+ And the banner should document that this app takes options
13
+ And the banner should document that this app's arguments are:
14
+ |router_ip|which is required|
15
+
16
+ Scenario: Entering valid router ip
17
+ When I run `rut 10.0.1.1`
18
+ Then the exit status should be 0
19
+ And the output from "rut 10.0.1.1" should contain "has been up"
20
+
21
+ Scenario: Entering invalid router ip
22
+ When I run `rut 10.0.1.2`
23
+ Then the exit status should be 1
24
+ And the output from "rut 10.0.1.2" should contain "Host 10.0.1.2 not responding"
25
+
26
+ Scenario: Entering an invalid ip
27
+ When I run `rut invalid`
28
+ Then the exit status should be 2
29
+ And the output from "rut invalid" should contain "invalid is an invalid ip address"
@@ -0,0 +1,3 @@
1
+ Before do
2
+ @aruba_timeout_seconds = 50
3
+ end
@@ -0,0 +1 @@
1
+ # Put your step definitions here
@@ -0,0 +1,16 @@
1
+ require 'aruba/cucumber'
2
+ require 'methadone/cucumber'
3
+
4
+ ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
5
+ LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
6
+
7
+ Before do
8
+ # Using "announce" causes massive warnings on 1.9.2
9
+ @puts = true
10
+ @original_rubylib = ENV['RUBYLIB']
11
+ ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
12
+ end
13
+
14
+ After do
15
+ ENV['RUBYLIB'] = @original_rubylib
16
+ end
@@ -0,0 +1,5 @@
1
+ require "rut/version"
2
+
3
+ module Rut
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,3 @@
1
+ module Rut
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rut/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "rut"
8
+ gem.version = Rut::VERSION
9
+ gem.authors = ["Tomas Skogberg"]
10
+ gem.email = ["tomas.skogberg@gmail.com"]
11
+ gem.summary = "Router Uptime (rut)"
12
+ gem.description = "Rut is a CLI script that'll show you your routers uptime."
13
+ gem.homepage = "https://github.com/tskogberg/rut"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.add_development_dependency('aruba')
20
+ gem.add_development_dependency('rdoc')
21
+ gem.add_development_dependency('rake','~> 0.9.2')
22
+ gem.add_dependency('methadone', '~>1.2.1')
23
+ gem.add_dependency('snmp', '~>1.1.0')
24
+ end
@@ -0,0 +1,7 @@
1
+ require 'test/unit'
2
+
3
+ class TestSomething < Test::Unit::TestCase
4
+ def test_truth
5
+ assert true
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rut
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tomas Skogberg
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: aruba
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rdoc
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.9.2
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.2
62
+ - !ruby/object:Gem::Dependency
63
+ name: methadone
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.2.1
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.2.1
78
+ - !ruby/object:Gem::Dependency
79
+ name: snmp
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.1.0
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.1.0
94
+ description: Rut is a CLI script that'll show you your routers uptime.
95
+ email:
96
+ - tomas.skogberg@gmail.com
97
+ executables:
98
+ - rut
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - .gitignore
103
+ - .rvmrc
104
+ - Gemfile
105
+ - Gemfile.lock
106
+ - LICENSE.txt
107
+ - README.md
108
+ - README.rdoc
109
+ - Rakefile
110
+ - bin/rut
111
+ - features/rut.feature
112
+ - features/step_definitions/rut_stemps.rb
113
+ - features/step_definitions/rut_steps.rb
114
+ - features/support/env.rb
115
+ - lib/rut.rb
116
+ - lib/rut/version.rb
117
+ - rut.gemspec
118
+ - test/tc_something.rb
119
+ homepage: https://github.com/tskogberg/rut
120
+ licenses: []
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 1.8.24
140
+ signing_key:
141
+ specification_version: 3
142
+ summary: Router Uptime (rut)
143
+ test_files:
144
+ - features/rut.feature
145
+ - features/step_definitions/rut_stemps.rb
146
+ - features/step_definitions/rut_steps.rb
147
+ - features/support/env.rb
148
+ - test/tc_something.rb