I fix bugs for tagging
parent
863cbcbddb
commit
708eb42984
|
@ -256,7 +256,8 @@ class Db
|
||||||
addrs << ip
|
addrs << ip
|
||||||
wspace = framework.db.workspace
|
wspace = framework.db.workspace
|
||||||
host = framework.db.get_host(:workspace => wspace, :address => ip)
|
host = framework.db.get_host(:workspace => wspace, :address => ip)
|
||||||
possible_tags = Mdm::Tag.includes(:hosts).where("hosts.workspace_id = ? and tags.name = ?", wspace.id, tag_name).order("tags.id DESC").limit(1)
|
if host
|
||||||
|
possible_tags = Mdm::Tag.includes(:hosts).where("hosts.workspace_id = ? and hosts.address = ? and tags.name = ?", wspace.id, ip, tag_name).order("tags.id DESC").limit(1)
|
||||||
tag = (possible_tags.blank? ? Mdm::Tag.new : possible_tags.first)
|
tag = (possible_tags.blank? ? Mdm::Tag.new : possible_tags.first)
|
||||||
tag.name = tag_name
|
tag.name = tag_name
|
||||||
tag.hosts = [host]
|
tag.hosts = [host]
|
||||||
|
@ -264,9 +265,6 @@ class Db
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_tags(host)
|
|
||||||
Mdm::Tag.includes(:hosts).where("hosts.workspace_id = ? and hosts.address = ?", framework.db.workspace.id, host.address).order("tags.id DESC")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def cmd_hosts(*args)
|
def cmd_hosts(*args)
|
||||||
|
@ -409,9 +407,10 @@ class Db
|
||||||
each_host_range_chunk(host_ranges) do |host_search|
|
each_host_range_chunk(host_ranges) do |host_search|
|
||||||
framework.db.hosts(framework.db.workspace, onlyup, host_search).each do |host|
|
framework.db.hosts(framework.db.workspace, onlyup, host_search).each do |host|
|
||||||
if search_term
|
if search_term
|
||||||
next unless host.attribute_names.any? { |a|
|
next unless (
|
||||||
host[a.intern].to_s.match(search_term) || !find_tags(host).empty?
|
host.attribute_names.any? { |a| host[a.intern].to_s.match(search_term) } or
|
||||||
}
|
!Mdm::Tag.includes(:hosts).where("hosts.workspace_id = ? and hosts.address = ? and tags.name = ?", framework.db.workspace.id, host.address, search_term.source).order("tags.id DESC").empty?
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
columns = col_names.map do |n|
|
columns = col_names.map do |n|
|
||||||
|
@ -424,7 +423,7 @@ class Db
|
||||||
end
|
end
|
||||||
# Otherwise, it's just an attribute
|
# Otherwise, it's just an attribute
|
||||||
elsif n == 'tags'
|
elsif n == 'tags'
|
||||||
found_tags = find_tags(host)
|
found_tags = Mdm::Tag.includes(:hosts).where("hosts.workspace_id = ? and hosts.address = ?", framework.db.workspace.id, host.address).order("tags.id DESC")
|
||||||
tag_names = []
|
tag_names = []
|
||||||
found_tags.each {|t| tag_names << t.name}
|
found_tags.each {|t| tag_names << t.name}
|
||||||
found_tags * ", "
|
found_tags * ", "
|
||||||
|
|
Loading…
Reference in New Issue