1 Reply Latest reply on Feb 14, 2018 3:51 AM by Duncan Grisby

    Use of countUnique to filter out 'None' values

    Jon Trotter

      Looking to filter out the None values for a list, but unsure if the options seen in the documentation will do this and definitely not sure how to use the option.


      search Host

      ORDER BY name, #DeviceWithInterface:DeviceInterface:InterfaceOfDevice:NetworkInterface.#EdgeClient:NetworkLink:EdgeDevice:NetworkInterface.#InterfaceOfDevice:DeviceInterface:DeviceWithInterface:NetworkDevice.name

      SHOW name as 'Hostname',   single(sorted(#DeviceWithInterface:DeviceInterface:InterfaceOfDevice:NetworkInterface.#EdgeClient:NetworkLink:EdgeDevice:NetworkInterface.#InterfaceOfDevice:DeviceInterface:DeviceWithInterface:NetworkDevice.name)) as 'ND Name',  single(sorted(#DeviceWithInterface:DeviceInterface:InterfaceOfDevice:NetworkInterface.__interface_id)) as 'Interface Name'

      PROCESSWITH countUnique(1)


      This provides a list of host-to-network device relationships in a manner, but using single will in some cases pull the first value, which can be a None, effectively null. Not sure if the countUnique functionality of ignore_none applies, but I have been unsuccessful applying it. I've tried setting it multiple ways, all yield search errors. The documentation doesn't provide an example of how it is used, so can someone provide some direction as to how the options for countUnique can be used?


      Actually, as I read it again I realize it won't filter, just count....which should be obvious with the name. Is there a better way to filter out None values in a list? to get just the ones that are unique?

        • 1. Re: Use of countUnique to filter out 'None' values
          Duncan Grisby

          countUnique is not what you need at all.


          The reason you get the None values is that the first hop of traversals finds all the NetworkInterfaces for the host, then then next hop finds the connected switch NetworkInterface for each one. Not all the Host interfaces have a link to a switch interface, so for those that don't, you get None. You then have a final hop from switch NetworkInterface to the switch NetworkDevice, but that is also None of course if there is no switch NetworkInterface.


          In BMC Discovery 11.2, you can use a new feature of the search language to filter the data the way you want:


          search Host

          with (traverse DeviceWithInterface:DeviceInterface:InterfaceOfDevice:NetworkInterface as ni where #ndni

             traverse EdgeClient:NetworkLink:EdgeDevice:NetworkInterface as ndni

             traverse InterfaceOfDevice:DeviceInterface:DeviceWithInterface:NetworkDevice as nd)

          order by name

          show name, single(#ni.__interface_id) as "Host Interface", single(#nd.name) as "ND Name"


          What that does is the same traversals as your key expressions, giving them names along the way. The first hop to all the Host's NetworkInterfaces is filtered to only include ones that have a relationship to a switch NetworkInterface.

          2 of 2 people found this helpful