class WlcSnmp::Client
Constants
- MIB_AIRESPACE_AP_ADMIN_STATUS
- MIB_AIRESPACE_AP_BASE_MAC
- MIB_AIRESPACE_AP_ETHENRET_MAC
- MIB_AIRESPACE_AP_IP
- MIB_AIRESPACE_AP_LOCATION
- MIB_AIRESPACE_AP_MODEL
- MIB_AIRESPACE_AP_NAME
- MIB_AIRESPACE_AP_OPER_STATUS
- MIB_AIRESPACE_AP_SERIAL
- MIB_AIRESPACE_AP_TYPE
- MIB_AIRESPACE_CLIENT_IP
- MIB_AIRESPACE_CLIENT_MAC
- MIB_LWAPP_AP_MAC
- MIB_LWAPP_AP_NAME
- MIB_LWAPP_CLIENT_AP_MAC
- MIB_LWAPP_CLIENT_CURRENT_RATE
- MIB_LWAPP_CLIENT_IP
- MIB_LWAPP_CLIENT_MAC
- MIB_LWAPP_CLIENT_PROTOCOL
- MIB_LWAPP_CLIENT_RATE_SET
- MIB_LWAPP_CLIENT_SSID
- MIB_LWAPP_CLIENT_UPTIME
- MIB_LWAPP_CLIENT_USER
- MIB_LWAPP_CLIENT_WLAN_PROFILE
Public Class Methods
new(host: , port: 161, community: )
click to toggle source
# File lib/wlc_snmp/client.rb, line 36 def initialize(host: , port: 161, community: ) @host = host @port = port @community = community end
Public Instance Methods
aps()
click to toggle source
# File lib/wlc_snmp/client.rb, line 42 def aps snmp_get_tree( mac_address: MIB_AIRESPACE_AP_BASE_MAC, name: MIB_AIRESPACE_AP_NAME, location: MIB_AIRESPACE_AP_LOCATION, operational_status: MIB_AIRESPACE_AP_OPER_STATUS, model: MIB_AIRESPACE_AP_MODEL, serial: MIB_AIRESPACE_AP_SERIAL, ip_address: MIB_AIRESPACE_AP_IP, type: MIB_AIRESPACE_AP_TYPE, ethernet_mac_address: MIB_AIRESPACE_AP_ETHENRET_MAC, admin_status: MIB_AIRESPACE_AP_ADMIN_STATUS, ).map do |data| Ap.new( name: data[:name].to_s, mac_address: unpack_mac(data[:mac_address]), location: data[:location]&.to_s, operational_status: data[:operational_status]&.to_i, model: data[:model]&.to_s, serial: data[:serial]&.to_s, ip_address: data[:ip_address]&.to_s, type: data[:ip_address], ethernet_mac_address: unpack_mac(data[:ethernet_mac_address]), admin_status: data[:admin_status]&.to_i, ) end end
clients()
click to toggle source
# File lib/wlc_snmp/client.rb, line 70 def clients aps = aps().map{ |_| [_.mac_address, _] }.to_h airespace_clients = snmp_get_tree(ip: MIB_AIRESPACE_CLIENT_IP, mac: MIB_AIRESPACE_CLIENT_MAC).map do |data| [data[:ip].to_s, unpack_mac(data[:mac])] end.to_h snmp_get_tree( wlan_profile: MIB_LWAPP_CLIENT_WLAN_PROFILE, protocol: MIB_LWAPP_CLIENT_PROTOCOL, ap_mac: MIB_LWAPP_CLIENT_AP_MAC, ip: MIB_LWAPP_CLIENT_IP, uptime: MIB_LWAPP_CLIENT_UPTIME, data_rate: MIB_LWAPP_CLIENT_CURRENT_RATE, supported_data_rates: MIB_LWAPP_CLIENT_RATE_SET, user: MIB_LWAPP_CLIENT_USER, ssid: MIB_LWAPP_CLIENT_SSID, ).map do |data| if data[:ip].is_a?(SNMP::IpAddress) ip = data[:ip].to_s else ip = data[:ip].to_s.unpack("C*").map(&:to_s).join(?.) end mac = airespace_clients[ip] ? airespace_clients[ip] : nil ap_mac = unpack_mac(data[:ap_mac]) ClientData.new( mac_address: mac, ip_address: ip, ap: aps[ap_mac], wlan_profile: data[:wlan_profile].to_s, protocol: data[:protocol].to_i, ap_mac: ap_mac, uptime: data[:uptime].to_i, current_rate: data[:data_rate].to_s, supported_data_rates: data[:supported_data_rates].to_s.split(?,), user: data[:user]&.to_s, ssid: data[:ssid]&.to_s, ) end end
snmp()
click to toggle source
# File lib/wlc_snmp/client.rb, line 112 def snmp @snmp ||= SNMP::Manager.new(host: @host, port: @port, community: @community) end
Private Instance Methods
snmp_get_tree(attributes)
click to toggle source
# File lib/wlc_snmp/client.rb, line 118 def snmp_get_tree(attributes) variables = attributes.map do |key, oid| [key, snmp_walk(oid).map{|_| [_.name.index(oid).to_s, _] }.to_h] end variables.first[1].each_key.map do |index| variables.map do |key, vbs| [key, vbs[index]&.value] end.to_h end end
snmp_walk(tree)
click to toggle source
# File lib/wlc_snmp/client.rb, line 130 def snmp_walk(tree) vbs = [] pointer = tree begin list = snmp.get_bulk(0, 100, [pointer]) list.varbind_list.each do |vb| unless vb.name.subtree_of?(tree) pointer = nil break end vbs.push vb pointer = vb.name end end while pointer vbs end
unpack_mac(mac)
click to toggle source
# File lib/wlc_snmp/client.rb, line 147 def unpack_mac(mac) mac.unpack("C*").map{ |_| _.to_s(16).rjust(2,'0') }.join(?:) end