revamp report_note to compare data in ruby instead of SQL which was causing headaches with serialization
git-svn-id: file:///home/svn/framework3/trunk@10432 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
aa1d8e403f
commit
2a58f7433e
|
@ -536,8 +536,8 @@ class DBManager
|
||||||
if addr and not host
|
if addr and not host
|
||||||
host = get_host(:workspace => wspace, :host => addr)
|
host = get_host(:workspace => wspace, :host => addr)
|
||||||
end
|
end
|
||||||
if not opts[:service] and (opts[:port] and opts[:proto])
|
if host and (opts[:port] and opts[:proto])
|
||||||
opts[:service] = get_service(wspace, host, opts[:proto], opts[:port])
|
service = get_service(wspace, host, opts[:proto], opts[:port])
|
||||||
end
|
end
|
||||||
|
|
||||||
if host
|
if host
|
||||||
|
@ -552,38 +552,41 @@ class DBManager
|
||||||
args = []
|
args = []
|
||||||
note = nil
|
note = nil
|
||||||
|
|
||||||
|
conditions = { :ntype => ntype }
|
||||||
|
conditions[:host_id] = host[:id] if host
|
||||||
|
conditions[:service_id] = service[:id] if service
|
||||||
|
|
||||||
|
notes = wspace.notes.find(:all, :conditions => conditions)
|
||||||
|
|
||||||
case mode
|
case mode
|
||||||
when :unique
|
when :unique
|
||||||
method = "find_or_initialize_by_ntype"
|
# Only one note of this type should exist, make a new one if it
|
||||||
args = [ ntype ]
|
# isn't there. If it is, grab it and overwrite its data.
|
||||||
when :unique_data
|
if notes.empty?
|
||||||
method = "find_or_initialize_by_ntype_and_data"
|
note = wspace.notes.new(conditions)
|
||||||
args = [ ntype, data ]
|
else
|
||||||
|
note = notes[0]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Find and update a record by type
|
|
||||||
if(method)
|
|
||||||
if host
|
|
||||||
method << "_and_host_id"
|
|
||||||
args.push(host[:id])
|
|
||||||
end
|
|
||||||
if opts[:service] and opts[:service].kind_of? Service
|
|
||||||
method << "_and_service_id"
|
|
||||||
args.push(opts[:service][:id])
|
|
||||||
end
|
|
||||||
|
|
||||||
note = wspace.notes.send(method, *args)
|
|
||||||
if (note.changed?)
|
|
||||||
note.data = data
|
note.data = data
|
||||||
msfe_import_timestamps(opts,note)
|
when :unique_data
|
||||||
note.save!
|
# Don't make a new Note with the same data as one that already
|
||||||
else
|
# exists for the given: type and (host or service)
|
||||||
note.updated_at = note.created_at
|
notes.each do |n|
|
||||||
msfe_import_timestamps(opts,note)
|
# Compare the deserialized data from the table to the raw
|
||||||
note.save!
|
# data we're looking for. Because of the serialization we
|
||||||
|
# can't do this easily or reliably in SQL.
|
||||||
|
if n.data == data
|
||||||
|
note = n
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not note
|
||||||
|
# We didn't find one with the data we're looking for, make
|
||||||
|
# a new one.
|
||||||
|
note = wspace.notes.new(conditions.merge(:data => data))
|
||||||
end
|
end
|
||||||
# Insert a brand new note record no matter what
|
|
||||||
else
|
else
|
||||||
|
# Otherwise, assume :insert, which means always make a new one
|
||||||
note = wspace.notes.new
|
note = wspace.notes.new
|
||||||
if host
|
if host
|
||||||
note.host_id = host[:id]
|
note.host_id = host[:id]
|
||||||
|
@ -595,9 +598,9 @@ class DBManager
|
||||||
note.critical = crit
|
note.critical = crit
|
||||||
note.ntype = ntype
|
note.ntype = ntype
|
||||||
note.data = data
|
note.data = data
|
||||||
|
end
|
||||||
msfe_import_timestamps(opts,note)
|
msfe_import_timestamps(opts,note)
|
||||||
note.save!
|
note.save!
|
||||||
end
|
|
||||||
|
|
||||||
ret[:note] = note
|
ret[:note] = note
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue