tumblr / collins

groovy kind of love
tumblr.github.com/collins
Apache License 2.0
571 stars 99 forks source link

Collins should handle missing vlan-name in LLDP reports #466

Closed byxorna closed 7 years ago

byxorna commented 8 years ago

I had to hack genesis to inject vlan names when the generated LLDP report is missing them (dependent on the kind of switches attached?). It would be nice if Collins handles this automatically, and sets a default vlan name and vlan ID if missing, so it can accept lldp reports from more types of switches.

      log "Generating LLDP report"
      network_report = self.generate_network_report
      log "Validating all network interfaces are listed in LLDP report"
      self.validate_num_interfaces(network_report)

      lldp_xml = Nokogiri::XML(network_report)
      # aristas dont set the vlan name, and collins barfs with:
      # Exception Class: class collins.util.parsers.AttributeNotFoundException Exception Message: Found empty vlan name Message: Exception updating asset
      log "Making sure all reported vlans have names"
      set_missing_vlan_names!(lldp_xml)

and

def self.set_missing_vlan_names!(lldp_xml)
    lldp_xml.css('lldp interface vlan').each do |node|
      if node.content.empty?
        log "VLAN name missing! Setting to default so collins accepts this LLDP report"
        node.content = "pingu"
      end
    end
    lldp_xml
end
defect commented 8 years ago

There is a config parameter called requireVlanName that i think does what you want. It doesn't allow you to set a default VLAN name, but it makes collins accept missing VLAN names in LLDP info.

It's not very well documented though (like, not documented at all). I'll add a section about it to the docs.