Permalink
Browse files

Filter displayed charts by giving names of desired interfaces

On the command line after IP, e.g.:
spectacular 192.168.1.1 wlan0 wlan1

server is still transmitting update for all interfaces
  • Loading branch information...
1 parent 447c6f9 commit 5a45eaff57b876e1e9d22ff68b1597bf32a652a9 @dreww dreww committed Mar 30, 2012
Showing with 18 additions and 10 deletions.
  1. +2 −1 README.rdoc
  2. +3 −2 bin/spectacular
  3. +10 −5 lib/spectacular/device.rb
  4. +3 −2 lib/spectacular/server.rb
View
@@ -18,7 +18,8 @@ browser.
$ gem install spectacular
$ spectacular 10.0.1.1
-Open your browser and {click this link}[http://localhost:8080].
+Open your browser and {click this link}[http://localhost:8080]. If you want,
+you can supply the names of interfaces to filter what appears in the browser.
== REQUIREMENTS:
View
@@ -3,8 +3,9 @@
require 'spectacular/server'
router = ARGV.shift
+interfaces = ARGV
-abort "usage:\n#{$0} router_ip" unless router
+abort "usage:\n#{$0} router_ip (interface_name)\noptionally supply one or more interface names to filter output" unless router
name = '[unknown router]'
@@ -17,7 +18,7 @@ end
server = WEBrick::HTTPServer.new :Port => 8080, :OutputBufferSize => 256
server.mount '/', Spectacular::Server::Index, name
-server.mount '/events.json', Spectacular::Server::Events, router
+server.mount '/events.json', Spectacular::Server::Events, router, interfaces
trap('INT') { server.shutdown }
server.start
View
@@ -6,9 +6,10 @@ module Spectacular
class Device
attr_reader :host, :history
- def initialize host, history = 10
+ def initialize host, history = 10, interface_args
@host = host
@history = new_history history
+ @interface_args = interface_args
end
def columns
@@ -17,11 +18,15 @@ def columns
def interfaces
manager = snmp_manager host
- interfaces = []
- manager.walk(['ifDescr']) do |row|
- interfaces << row.first.value.to_s
+ if @interface_args.empty?
+ interfaces = []
+ manager.walk(['ifDescr']) do |row|
+ interfaces << row.first.value.to_s
+ end
+ interfaces
+ else
+ @interface_args
end
- interfaces
ensure
manager.close
end
@@ -24,10 +24,11 @@ def do_GET request, response
class Events < WEBrick::HTTPServlet::AbstractServlet
- def initialize server, router
+ def initialize server, router, interfaces
super server
@router = router
+ @interface_args = interfaces
end
def do_GET request, response
@@ -40,7 +41,7 @@ def do_GET request, response
Thread.new {
begin
- dev = Spectacular::Device.new @router
+ dev = Spectacular::Device.new @router, @interface_args
rw.write "event: interfaces\n"
rw.write "data: #{JSON.dump(dev.interfaces)}\n\n"

0 comments on commit 5a45eaf

Please sign in to comment.