traffic_control 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in traffic_control.gemspec
4
+ gemspec
data/README.textile ADDED
@@ -0,0 +1,43 @@
1
+ h1. Traffic Control
2
+
3
+ Helps you monitor your Airport Extreme traffic.
4
+
5
+ h2. Features
6
+
7
+ Spits out some basic snmp info including:
8
+ * Number of wireless clients
9
+ * Number of dhcp clients
10
+ * Uptime
11
+
12
+ Get network client information including:
13
+ * Mac Address
14
+ * IP Address
15
+ * Time associated
16
+ * Wireless strength
17
+
18
+ h2. Example
19
+
20
+ bc.. airport = TrafficControl::Airport.new "airport.local", "public"
21
+
22
+ puts "There are around #{airport.settings["wirelessNumber"]} folk#{"s" unless airport.settings["wirelessNumber"] == 1} on your wifi"
23
+ puts airport.clients.inspect
24
+
25
+ airport.clients.each do |client, attributes|
26
+ puts "Details for client with MAC address #{client}:"
27
+ attributes.each do |name, details|
28
+ puts "#{name}: #{details}"
29
+ end
30
+ puts "--\n"
31
+ end
32
+
33
+
34
+ h2. Requirements
35
+
36
+ * SNMPwalk
37
+ * Possibly the Airport MIB (see below)
38
+
39
+ h3. Installing the Airport MIB
40
+
41
+ bc. cd /usr/share/snmp/mibs
42
+ sudo curl -L -O http://supportdownload.apple.com/download.info.apple.com/Apple_Support_Area/Apple_Software_Updates/Mac_OS_X/downloads/061-0652.20030619.5ibjt/airport-extreme.mib
43
+ cd ~
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/snmpwalk ADDED
Binary file
@@ -0,0 +1,47 @@
1
+ # Inspired by Andre LaBranche's work at http://dreness.com/bits/tech/airport
2
+ # Send him love at dre at mac dot com
3
+
4
+ module TrafficControl
5
+ class Airport
6
+ attr_accessor :host, :settings, :clients
7
+
8
+ def initialize(host, community = "public")
9
+ @host = host
10
+ @community = community
11
+ @settings = {}
12
+ @clients = []
13
+ end
14
+
15
+ def load_data!
16
+ client_data = {}
17
+
18
+ snmp_results = snmp_parser(snmp_output(@host, @community))
19
+ snmp_results.each do |setting|
20
+ if setting[1] == "0"
21
+ self.settings[setting[0]] = setting[2]
22
+ else
23
+ client_data[setting[1]] ||= []
24
+ client_data[setting.delete(setting[1])] << setting
25
+ end
26
+ end
27
+
28
+ client_data.each { |key, value| self.clients << TrafficControl::Client.new(Hash[value]) }
29
+ end
30
+
31
+ def snmp_output(host, community)
32
+ snmpcmd = "#{SNMPBIN} -m AIRPORT-BASESTATION-3-MIB -Osq -v 2c "
33
+ snmpcmd += "-c \"#{community}\" \"#{host}\" "
34
+ snmpcmd += "SNMPv2-SMI::enterprises.apple.airport"
35
+
36
+ `#{snmpcmd}`
37
+ end
38
+
39
+ def snmp_parser(output)
40
+ output.
41
+ chomp
42
+ .split("\n")
43
+ .collect{ |v| v.split(/\.(.+)/).collect{ |t| t.split(" ") }.flatten }
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,10 @@
1
+ module TrafficControl
2
+ class Client
3
+ attr_accessor :mac, :ip, :client_id, :lease_time
4
+
5
+ def initialize(attributes)
6
+ @mac, @ip, @client_id, @lease_time = attributes["dhcpPhysAddress"], attributes["dhcpIpAddress"], attributes["dhcpClientID"], attributes["dhcpLeaseTime"]
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module TrafficControl
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,8 @@
1
+ require "traffic_control/version"
2
+ require "traffic_control/airport"
3
+ require "traffic_control/client"
4
+
5
+ module TrafficControl
6
+ SNMPBIN = File.dirname(__FILE__) + "../bin/snmpwalk"
7
+ SNMPBIN = "/usr/bin/snmpwalk"
8
+ end
@@ -0,0 +1,28 @@
1
+ require "spec_helper"
2
+
3
+ describe TrafficControl::Airport do
4
+ subject { TrafficControl::Airport.new "airport.local" }
5
+
6
+ context "loading data" do
7
+
8
+ it "should grab teh snmpwalk results and parse them, and create a bunch of clients" do
9
+ subject.stub! :snmp_parser => [["foo", "name", "bar"]], :snmp_output => nil
10
+ subject.load_data!
11
+
12
+ subject.clients.should be_an(Array)
13
+ subject.clients.first.should be_a_kind_of TrafficControl::Client
14
+ end
15
+
16
+ it "should parse the results of an snmpwalk output" do
17
+ mock_output = "foo.0 bar
18
+ foo.0
19
+ foo.\"bar\" \"bar\""
20
+
21
+ subject.snmp_parser(mock_output).should == [
22
+ ["foo", "0", "bar"],
23
+ ["foo", "0"],
24
+ ["foo", "\"bar\"", "\"bar\""],
25
+ ]
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,18 @@
1
+ require "spec_helper"
2
+
3
+ describe TrafficControl::Client do
4
+
5
+ it "should create a client given a hash of data" do
6
+ client = TrafficControl::Client.new({
7
+ "dhcpPhysAddress" => "foo",
8
+ "dhcpIpAddress" => "bar",
9
+ "dhcpClientID" => "\"\"",
10
+ "dhcpLeaseTime" => "1961"
11
+ })
12
+
13
+ client.mac.should == "foo"
14
+ client.ip.should == "bar"
15
+ client.client_id.should == "\"\""
16
+ client.lease_time.should == "1961"
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ $:.unshift '../lib'
2
+
3
+ require "rspec"
4
+ require "traffic_control"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "traffic_control/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "traffic_control"
7
+ s.version = TrafficControl::VERSION
8
+ s.authors = ["Nathan S"]
9
+ s.email = ["nathan@inspire9.com"]
10
+ s.homepage = "http://github.com/nathanscott/traffic_control"
11
+ s.summary = "Helps you monitor your Airport Extreme traffic."
12
+ s.description = "It really helps you monitor your Airport Extreme traffic."
13
+
14
+ s.rubyforge_project = "traffic_control"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: traffic_control
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nathan S
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
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
+ description: It really helps you monitor your Airport Extreme traffic.
31
+ email:
32
+ - nathan@inspire9.com
33
+ executables:
34
+ - snmpwalk
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - README.textile
41
+ - Rakefile
42
+ - bin/snmpwalk
43
+ - lib/traffic_control.rb
44
+ - lib/traffic_control/airport.rb
45
+ - lib/traffic_control/client.rb
46
+ - lib/traffic_control/version.rb
47
+ - spec/models/airport_spec.rb
48
+ - spec/models/client_spec.rb
49
+ - spec/spec_helper.rb
50
+ - traffic_control.gemspec
51
+ homepage: http://github.com/nathanscott/traffic_control
52
+ licenses: []
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ segments:
64
+ - 0
65
+ hash: -3384502027841592073
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ segments:
73
+ - 0
74
+ hash: -3384502027841592073
75
+ requirements: []
76
+ rubyforge_project: traffic_control
77
+ rubygems_version: 1.8.23
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Helps you monitor your Airport Extreme traffic.
81
+ test_files:
82
+ - spec/models/airport_spec.rb
83
+ - spec/models/client_spec.rb
84
+ - spec/spec_helper.rb