wlc_snmp 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1c01f85ae4e6dc37a6f146713d8644545444ff64
4
+ data.tar.gz: 1b8b573ae2c159508436a82ce55e79f4e13f44a9
5
+ SHA512:
6
+ metadata.gz: cb3fbbe1ed2ce428c7a34ca6284b3eb8f19ed43c8349c048d271a8963ae4da429e1820f04ac21f9e3627ce73161a4b9d8497188ea3f9bc5e6b35ba9c4868bf5d
7
+ data.tar.gz: 12a2c4d55fde83f33bf27338683cfd2bd24f8569ab676f627bcb4ca699f8da1b39dfd51e65881e9e14be17eaac1c17ec5d61f2b274befa14daf809398a49580a
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wlc_snmp.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Sorah Fukumori
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # WlcSnmp: Easy interaction with Cisco WLC via SNMP
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'wlc_snmp'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install wlc_snmp
18
+
19
+ ## Usage
20
+
21
+ ```
22
+ wlc = WlcSnmp::Client.new(host: 'wlc.example.com', community: 'xxx')
23
+
24
+ p wlc.aps
25
+ p wlc.clients
26
+ ```
27
+
28
+ ## Development
29
+
30
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
31
+
32
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sorah/wlc_snmp.
37
+
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
42
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wlc_snmp"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/wlc_snmp.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'wlc_snmp/version'
2
+ require 'wlc_snmp/client'
@@ -0,0 +1,27 @@
1
+ module WlcSnmp
2
+ class Ap
3
+ def initialize(name: , mac_address: nil, ethernet_mac_address: nil, location: nil, operational_status: nil, model: nil, serial: nil, ip_address: nil, type: nil, admin_status: nil)
4
+ @name = name
5
+ @mac_address = mac_address
6
+ @ethernet_mac_address = ethernet_mac_address
7
+ @location = location
8
+ @operational_status = operational_status
9
+ @model = model
10
+ @serial = serial
11
+ @ip_address = ip_address
12
+ @type = type
13
+ @admin_status = admin_status
14
+ end
15
+
16
+ attr_reader :name
17
+ attr_reader :mac_address
18
+ attr_reader :ethernet_mac_address
19
+ attr_reader :location
20
+ attr_reader :operational_status
21
+ attr_reader :model
22
+ attr_reader :serial
23
+ attr_reader :ip_address
24
+ attr_reader :type
25
+ attr_reader :admin_status
26
+ end
27
+ end
@@ -0,0 +1,147 @@
1
+ require 'snmp'
2
+
3
+ require 'wlc_snmp/client_data'
4
+ require 'wlc_snmp/ap'
5
+
6
+ module WlcSnmp
7
+ class Client
8
+ MIB_AIRESPACE_CLIENT_MAC = '1.3.6.1.4.1.14179.2.1.4.1.1'
9
+ MIB_AIRESPACE_CLIENT_IP = '1.3.6.1.4.1.14179.2.1.4.1.2'
10
+
11
+ MIB_AIRESPACE_AP_BASE_MAC = '1.3.6.1.4.1.14179.2.2.1.1.1'
12
+ MIB_AIRESPACE_AP_NAME = '1.3.6.1.4.1.14179.2.2.1.1.3'
13
+ MIB_AIRESPACE_AP_LOCATION = '1.3.6.1.4.1.14179.2.2.1.1.4'
14
+ MIB_AIRESPACE_AP_OPER_STATUS = '1.3.6.1.4.1.14179.2.2.1.1.6'
15
+ MIB_AIRESPACE_AP_MODEL = '1.3.6.1.4.1.14179.2.2.1.1.16'
16
+ MIB_AIRESPACE_AP_SERIAL = '1.3.6.1.4.1.14179.2.2.1.1.17'
17
+ MIB_AIRESPACE_AP_IP = '1.3.6.1.4.1.14179.2.2.1.1.19'
18
+ MIB_AIRESPACE_AP_TYPE = '1.3.6.1.4.1.14179.2.2.1.1.22'
19
+ MIB_AIRESPACE_AP_ETHENRET_MAC = '1.3.6.1.4.1.14179.2.2.1.1.33'
20
+ MIB_AIRESPACE_AP_ADMIN_STATUS = '1.3.6.1.4.1.14179.2.2.1.1.37'
21
+
22
+ MIB_LWAPP_AP_NAME = '1.3.6.1.4.1.9.9.513.1.1.1.1.5'
23
+ MIB_LWAPP_AP_MAC = '1.3.6.1.4.1.9.9.513.1.1.1.1.2'
24
+
25
+ MIB_LWAPP_CLIENT_MAC = '1.3.6.1.4.1.9.9.599.1.3.1.1.1'
26
+ MIB_LWAPP_CLIENT_WLAN_PROFILE = '1.3.6.1.4.1.9.9.599.1.3.1.1.3'
27
+ MIB_LWAPP_CLIENT_PROTOCOL = '1.3.6.1.4.1.9.9.599.1.3.1.1.6'
28
+ MIB_LWAPP_CLIENT_AP_MAC = '1.3.6.1.4.1.9.9.599.1.3.1.1.8'
29
+ MIB_LWAPP_CLIENT_IP = '1.3.6.1.4.1.9.9.599.1.3.1.1.10'
30
+ MIB_LWAPP_CLIENT_UPTIME = '1.3.6.1.4.1.9.9.599.1.3.1.1.15'
31
+ MIB_LWAPP_CLIENT_CURRENT_RATE = '1.3.6.1.4.1.9.9.599.1.3.1.1.17'
32
+ MIB_LWAPP_CLIENT_RATE_SET = '1.3.6.1.4.1.9.9.599.1.3.1.1.18'
33
+ MIB_LWAPP_CLIENT_USER = '1.3.6.1.4.1.9.9.599.1.3.1.1.27'
34
+ MIB_LWAPP_CLIENT_SSID = '1.3.6.1.4.1.9.9.599.1.3.1.1.28'
35
+
36
+ def initialize(host: , port: 161, community: )
37
+ @host = host
38
+ @port = port
39
+ @community = community
40
+ end
41
+
42
+ def aps
43
+ snmp_get_tree(
44
+ mac_address: MIB_AIRESPACE_AP_BASE_MAC,
45
+ name: MIB_AIRESPACE_AP_NAME,
46
+ location: MIB_AIRESPACE_AP_LOCATION,
47
+ operational_status: MIB_AIRESPACE_AP_OPER_STATUS,
48
+ model: MIB_AIRESPACE_AP_MODEL,
49
+ serial: MIB_AIRESPACE_AP_SERIAL,
50
+ ip_address: MIB_AIRESPACE_AP_IP,
51
+ type: MIB_AIRESPACE_AP_TYPE,
52
+ ethernet_mac_address: MIB_AIRESPACE_AP_ETHENRET_MAC,
53
+ admin_status: MIB_AIRESPACE_AP_ADMIN_STATUS,
54
+ ).map do |data|
55
+ Ap.new(
56
+ name: data[:name].to_s,
57
+ mac_address: unpack_mac(data[:mac_address]),
58
+ location: data[:location]&.to_s,
59
+ operational_status: data[:operational_status]&.to_i,
60
+ model: data[:model]&.to_s,
61
+ serial: data[:serial]&.to_s,
62
+ ip_address: data[:ip_address]&.to_s,
63
+ type: data[:ip_address],
64
+ ethernet_mac_address: unpack_mac(data[:ethernet_mac_address]),
65
+ admin_status: data[:admin_status]&.to_i,
66
+ )
67
+ end
68
+ end
69
+
70
+ def clients
71
+ aps = aps().map{ |_| [_.mac_address, _] }.to_h
72
+
73
+ airespace_clients = snmp_get_tree(ip: MIB_AIRESPACE_CLIENT_IP, mac: MIB_AIRESPACE_CLIENT_MAC).map do |data|
74
+ [data[:ip].to_s, unpack_mac(data[:mac])]
75
+ end.to_h
76
+
77
+ snmp_get_tree(
78
+ wlan_profile: MIB_LWAPP_CLIENT_WLAN_PROFILE,
79
+ protocol: MIB_LWAPP_CLIENT_PROTOCOL,
80
+ ap_mac: MIB_LWAPP_CLIENT_AP_MAC,
81
+ ip: MIB_LWAPP_CLIENT_IP,
82
+ uptime: MIB_LWAPP_CLIENT_UPTIME,
83
+ data_rate: MIB_LWAPP_CLIENT_CURRENT_RATE,
84
+ supported_data_rates: MIB_LWAPP_CLIENT_RATE_SET,
85
+ user: MIB_LWAPP_CLIENT_USER,
86
+ ssid: MIB_LWAPP_CLIENT_SSID,
87
+ ).map do |data|
88
+ ip = data[:ip].to_s.unpack("C*").map(&:to_s).join(?.)
89
+ mac = airespace_clients[ip] ? airespace_clients[ip] : nil
90
+ ap_mac = unpack_mac(data[:ap_mac])
91
+
92
+ ClientData.new(
93
+ mac_address: mac,
94
+ ip_address: ip,
95
+ ap: aps[ap_mac],
96
+ wlan_profile: data[:wlan_profile].to_s,
97
+ protocol: data[:protocol].to_i,
98
+ ap_mac: ap_mac,
99
+ uptime: data[:uptime].to_i,
100
+ current_rate: data[:data_rate].to_s,
101
+ supported_data_rates: data[:supported_data_rates].to_s.split(?,),
102
+ user: data[:user]&.to_s,
103
+ ssid: data[:ssid]&.to_s,
104
+ )
105
+ end
106
+ end
107
+
108
+ def snmp
109
+ @snmp ||= SNMP::Manager.new(host: @host, port: @port, community: @community)
110
+ end
111
+
112
+ private
113
+
114
+ def snmp_get_tree(attributes)
115
+ variables = attributes.map do |key, oid|
116
+ [key, snmp_walk(oid).map{|_| [_.name.index(oid).to_s, _] }.to_h]
117
+ end
118
+
119
+ variables.first[1].each_key.map do |index|
120
+ variables.map do |key, vbs|
121
+ [key, vbs[index]&.value]
122
+ end.to_h
123
+ end
124
+ end
125
+
126
+ def snmp_walk(tree)
127
+ vbs = []
128
+ pointer = tree
129
+ begin
130
+ list = snmp.get_bulk(0, 100, [pointer])
131
+ list.varbind_list.each do |vb|
132
+ unless vb.name.subtree_of?(tree)
133
+ pointer = nil
134
+ break
135
+ end
136
+ vbs.push vb
137
+ pointer = vb.name
138
+ end
139
+ end while pointer
140
+ vbs
141
+ end
142
+
143
+ def unpack_mac(mac)
144
+ mac.unpack("C*").map{ |_| _.to_s(16).rjust(2,'0') }.join(?:)
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,29 @@
1
+ module WlcSnmp
2
+ class ClientData
3
+ def initialize(ip_address: , mac_address: nil, wlan_profile: nil, protocol: nil, ap_mac: nil, uptime: nil, current_rate: nil, supported_data_rates: nil, user: nil, ssid: nil, ap: nil)
4
+ @ip_address = ip_address
5
+ @mac_address = mac_address
6
+ @wlan_profile = wlan_profile
7
+ @protocol = protocol
8
+ @ap_mac = ap_mac
9
+ @uptime = uptime
10
+ @current_rate = current_rate
11
+ @supported_data_rates = supported_data_rates
12
+ @user = user
13
+ @ssid = ssid
14
+ @ap = ap
15
+ end
16
+
17
+ attr_reader :ip_address
18
+ attr_reader :mac_address
19
+ attr_reader :wlan_profile
20
+ attr_reader :protocol
21
+ attr_reader :ap_mac
22
+ attr_reader :uptime
23
+ attr_reader :current_rate
24
+ attr_reader :supported_data_rates
25
+ attr_reader :user
26
+ attr_reader :ssid
27
+ attr_reader :ap
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module WlcSnmp
2
+ VERSION = "0.1.0"
3
+ end
data/wlc_snmp.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wlc_snmp/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wlc_snmp"
8
+ spec.version = WlcSnmp::VERSION
9
+ spec.authors = ["Sorah Fukumori"]
10
+ spec.email = ["sorah@cookpad.com"]
11
+
12
+ spec.summary = %q{Wrapper of snmp.gem for easy interacting with Cisco WLC}
13
+ spec.homepage = "https://github.com/sorah/wlc_snmp"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+
27
+ spec.add_dependency "snmp"
28
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wlc_snmp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sorah Fukumori
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: snmp
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - sorah@cookpad.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/wlc_snmp.rb
86
+ - lib/wlc_snmp/ap.rb
87
+ - lib/wlc_snmp/client.rb
88
+ - lib/wlc_snmp/client_data.rb
89
+ - lib/wlc_snmp/version.rb
90
+ - wlc_snmp.gemspec
91
+ homepage: https://github.com/sorah/wlc_snmp
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.6.11
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Wrapper of snmp.gem for easy interacting with Cisco WLC
115
+ test_files: []