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}]"
end
IO.popen(command) { |stdin|
Rails.logger.info "Reading stdin: "+stdin.inspect
stdin.each { |line|
result = stdin.read()
result.lines.each { |line|
Rails.logger.info "Reading stdin: "+line.inspect
next if line !~ /^([\d\.]+)\s+([[:xdigit:]:]+)\s/;
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
Mac.find(:all).each { |entry|
mac = entry.mac.downcase
ip = entry.ip
if macs.has_key?(mac)
if macs.has_key?(mac) # if our scan shows this mac
if ! entry.active || ! entry.since
Rails.logger.info "Activating #{mac} at #{ip}" if options[:verbose]
entry.since = Time.now

View File

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