Improving logging of macs

This commit is contained in:
Will Bradley 2014-03-12 20:46:24 -07:00
parent 3cd6c59df0
commit d4286e4ddf
2 changed files with 10 additions and 6 deletions

View File

@ -292,18 +292,22 @@ Rails.logger.info "starting scan..."
Rails.logger.info "Running [#{command}]" Rails.logger.info "Running [#{command}]"
end end
IO.popen(command) { |stdin| IO.popen(command) { |stdin|
Rails.logger.info "Reading stdin: "+stdin.inspect result = stdin.read()
stdin.each { |line| result.lines.each { |line|
Rails.logger.info "Reading stdin: "+line.inspect
next if line !~ /^([\d\.]+)\s+([[:xdigit:]:]+)\s/; next if line !~ /^([\d\.]+)\s+([[:xdigit:]:]+)\s/;
macs[($2).downcase] = ($1).downcase; macs[($2).downcase] = ($1).downcase;
} }
Rails.logger.info "STDIN:"+result.lines.count.inspect
@macs = macs.dup # make a copy for output in the view
Rails.logger.info "MACS:"+@macs.inspect
} }
# Scan the existing macs and update each record as necessary # Scan the existing macs and update each record as necessary
Mac.find(:all).each { |entry| Mac.find(:all).each { |entry|
mac = entry.mac.downcase mac = entry.mac.downcase
ip = entry.ip ip = entry.ip
if macs.has_key?(mac) if macs.has_key?(mac) # if our scan shows this mac
if ! entry.active || ! entry.since if ! entry.active || ! entry.since
Rails.logger.info "Activating #{mac} at #{ip}" if options[:verbose] Rails.logger.info "Activating #{mac} at #{ip}" if options[:verbose]
entry.since = Time.now entry.since = Time.now

View File

@ -1,7 +1,7 @@
Scanning... Scanning...
<% if can? :read_details, Mac <% if can? :read_details, Mac
@log.each do |log| %> @macs.each do |key, value| %>
<%= log.mac %> = <%= key %> =
<%= log.ip %><br/> <%= value %><br/>
<% end <% end
end %> end %>