Skip to content

Instantly share code, notes, and snippets.

@tanema
Last active August 29, 2015 14:13
Show Gist options
  • Save tanema/22febb85012e562983e5 to your computer and use it in GitHub Desktop.
Save tanema/22febb85012e562983e5 to your computer and use it in GitHub Desktop.
irchelp1
require 'csv'
puts "[unifi.rb] Grabbing data from UniFi Controller"
result = <<-eos
NAME MAC AP CHAN RSSI RX TX
GARETH-LAPTOP 9c:2a:70:c9:c3:37 SR_Wifi 1 44 72 72
android-ac059065c685d5be 90:18:7c:2f:bd:40 SR_Wifi 1 33 1 72
Joes-iPhone a8:88:08:66:7e:ed SR_Wifi 1 32 24 72
sr-dash-01 90:4c:e5:b3:3a:69 SR_Wifi 1 28 52 58
android-1be24885e86c9fb1 80:57:19:03:08:5f SR_Wifi 1 21 6 52
eos
staffcsv = <<-eos
name,mac
Gareth,9c:2a:70:c9:c3:38
Joe,a8:88:08:66:7e:ed
eos
puts "[unifi.rb] Got data, parsing..."
puts
clients = CSV.parse(result, {:headers => true, :header_converters => :symbol, :converters => :all, :col_sep => "\s"})
staff = CSV.parse(staffcsv, {:headers => true, :header_converters => :symbol, :converters => :all})
#map the matches and flatten it so it is a single dimensional array
staff.flat_map do |member|
#filter clients to only those that match this mac
clients.select do |client|
client[:mac] == member[:mac]
end
end.each do |member|
#output the name
p member[:name]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment