Skip to content

Commit

Permalink
for idaholab#415, work in progress on converting devices -> vms
Browse files Browse the repository at this point in the history
  • Loading branch information
mmguero committed Apr 25, 2024
1 parent fad7372 commit faabbcf
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions logstash/ruby/netbox_enrich.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1200,23 +1200,23 @@ def netbox_lookup(
_tags = _tags.filter{|tag| tag[:slug] != @device_tag_manufacturer_unknown[:slug]}
end

# We could have created a device (without mac/OUI) based on hostname, and now only realize that
# We could have created a device (without mac/OUI) based on hostname, and now only realize that
# it's actually a VM. However, a device can't have been autopopulated as a VM and then later
# "become" a device, since the only reason we'd have created it as a VM would be because
# we saw the OUI (from real traffic) in @vm_namesarray in the first place.
_is_vm = _autopopulate_manuf.is_a?(Hash) && (_autopopulate_manuf.fetch(:vm, false) == true)
_is_vm = _was_vm || (_autopopulate_manuf.is_a?(Hash) && (_autopopulate_manuf.fetch(:vm, false) == true)
_device_to_vm = ((_was_vm == false) && (_is_vm == true))

if !_patched_device_data.empty? || _device_to_vm
# we've got changes to make, so do it
_device_written = false

puts('netbox_lookup patching %{name} @ %{site} (%{id}, dev->vm: %{dev2vm}) for "%{tags}" ("%{host}", "%{mac}", "%{oui}"): %{changes}' % {
puts('netbox_lookup patching %{name} @ %{site} (%{id}, VM: %{wasvm}->%{isvm}) ("%{host}", "%{mac}", "%{oui}"): %{changes}' % {
name: ip_key,
site: _previous_device_site,
id: _previous_device_id,
dev2vm: _device_to_vm,
tags: _tags.join('|'),
wasvm: _was_vm,
isvm: _is_vm,
host: _autopopulate_hostname.to_s,
mac: _autopopulate_mac.to_s,
oui: _autopopulate_oui.to_s,
Expand Down Expand Up @@ -1262,11 +1262,10 @@ def netbox_lookup(

# we've made the change to netbox, do a call to lookup_devices to get the formatted/updated data
# (yeah, this is a *little* inefficient, but this should really only happen one extra time per device at most)
if _device_written
_devices = lookup_devices(ip_key, @lookup_site, _lookup_service_port, @netbox_url_base, @netbox_url_suffix, _nb)
end #_device_written
_devices = lookup_devices(ip_key, @lookup_site, _lookup_service_port, @netbox_url_base, @netbox_url_suffix, _nb) if _device_written

end # check _patched_device_data

end # check previous device ID is valid
end # check on previous_result function argument

Expand Down

0 comments on commit faabbcf

Please sign in to comment.