rut 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rut (0.0.2)
4
+ rut (0.0.3)
5
5
  methadone (~> 1.2.1)
6
6
  snmp (~> 1.1.0)
7
7
 
data/bin/rut CHANGED
@@ -3,57 +3,5 @@
3
3
  require 'optparse'
4
4
  require 'methadone'
5
5
  require 'rut'
6
- require 'snmp'
7
6
 
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
7
+ Rut::App.new
@@ -3,7 +3,7 @@ Feature: See router uptime
3
3
  I want a one-command that print it
4
4
  So I don't have to use a admin program
5
5
 
6
- Scenario: App should have a basic UI
6
+ Scenario: App should have a basic UI
7
7
  When I get help for "rut"
8
8
  Then the exit status should be 0
9
9
  And the banner should be present
@@ -13,10 +13,10 @@ Feature: See router uptime
13
13
  And the banner should document that this app's arguments are:
14
14
  |router_ip|which is required|
15
15
 
16
- Scenario: Entering valid router ip
16
+ Scenario: Entering valid router ip
17
17
  When I run `rut 10.0.1.1`
18
18
  Then the exit status should be 0
19
- And the output from "rut 10.0.1.1" should contain "has been up"
19
+ And the output from "rut 10.0.1.1" should contain "has been up"
20
20
 
21
21
  Scenario: Entering invalid router ip
22
22
  When I run `rut 10.0.1.2`
@@ -24,6 +24,10 @@ Feature: See router uptime
24
24
  And the output from "rut 10.0.1.2" should contain "Host 10.0.1.2 not responding"
25
25
 
26
26
  Scenario: Entering an invalid ip
27
- When I run `rut invalid`
27
+ When I run `rut 999.999.999.999`
28
28
  Then the exit status should be 2
29
- And the output from "rut invalid" should contain "invalid is an invalid ip address"
29
+ And the output from "rut 999.999.999.999" should contain "999.999.999.999 is an invalid ip address"
30
+ Scenario: Entering an invalid input
31
+ When I run `rut something`
32
+ Then the exit status should be 70
33
+ And the output from "rut something" should contain "something is not an IP-address"
data/lib/rut.rb CHANGED
@@ -1,5 +1,59 @@
1
- require "rut/version"
1
+ require 'snmp'
2
+ require 'rut/version'
2
3
 
3
4
  module Rut
4
- # Your code goes here...
5
+ class App
6
+ include Methadone::Main
7
+ include Methadone::CLILogging
8
+
9
+ attr_accessor :router_ip
10
+
11
+ main do |router_ip|
12
+ unless router_ip =~ /\b(?:\d{1,3}\.){3}\d{1,3}\b/
13
+ raise "#{router_ip} is not an IP-address"
14
+ end
15
+
16
+ @router_ip = router_ip
17
+
18
+ SNMP::Manager.open(
19
+ host: @router_ip, retries: 0,
20
+ mib_modules: ["DISMAN-EVENT-MIB", "SNMPv2-MIB"]
21
+ ) do |manager|
22
+ run_and_handle_exceptions do
23
+ response = manager.get_value(["sysUpTimeInstance" , "sysName.0"])
24
+ days = response[0]
25
+ router_name = response[1].capitalize
26
+ puts "#{router_name} has been up #{days}"
27
+ end
28
+ end
29
+ end
30
+
31
+ # supplemental methods here
32
+ def self.run_and_handle_exceptions
33
+ yield
34
+
35
+ rescue SNMP::RequestTimeout
36
+ exception_output("Host #{@router_ip} not responding", 1)
37
+ rescue SocketError
38
+ exception_output("#{@router_ip} is an invalid ip address", 2)
39
+ rescue Exception
40
+ exception_output($!.inspect, 99)
41
+ end
42
+
43
+ def self.exception_output(output, code)
44
+ puts output
45
+ exit(code)
46
+ end
47
+
48
+ # Declare command-line interface here
49
+ description "Shows uptime on your router"
50
+
51
+ # Require an argument
52
+ arg :router_ip, "IP-address to the router"
53
+
54
+ version Rut::VERSION
55
+ use_log_level_option
56
+
57
+ go!
58
+ end
5
59
  end
@@ -1,3 +1,3 @@
1
1
  module Rut
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rut
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-04 00:00:00.000000000 Z
12
+ date: 2013-10-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aruba
@@ -128,12 +128,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
128
  - - ! '>='
129
129
  - !ruby/object:Gem::Version
130
130
  version: '0'
131
+ segments:
132
+ - 0
133
+ hash: -2473147525471622773
131
134
  required_rubygems_version: !ruby/object:Gem::Requirement
132
135
  none: false
133
136
  requirements:
134
137
  - - ! '>='
135
138
  - !ruby/object:Gem::Version
136
139
  version: '0'
140
+ segments:
141
+ - 0
142
+ hash: -2473147525471622773
137
143
  requirements: []
138
144
  rubyforge_project:
139
145
  rubygems_version: 1.8.24