Skip to main content
Solved

Inventory device state from Description field

  • September 12, 2023
  • 1 reply
  • 62 views

Lane
Forum|alt.badge.img

I am trying to use the harvest the INVENTORY device state file but target the Description field, but I am unsure on on how to do that so that I can select it. I have the following:

import "External/Juniper-EoS";
foreach device in network.devices
where device.platform.vendor == Vendor.JUNIPER
let outputs=device.outputs
foreach command in outputs.commands
where command.commandType == CommandType.INVENTORY
let platform = device.platform
where isPresent(platform.model)
foreach part in platform.components
where isPresent(part.serialNumber)


select {
 deviceName: device.name,
 model: platform.model,
 part: part.serialNumber,
 violation: if part.partId in juniper_eos then true else false
}

 

Best answer by andrewcarver

Below would help in matching against a list of known end of life HW part numbers within the inventory. In approvedDescriptions [“THIS WILL BE THE LIST TO MATCH AGAINST”];

 

approvedDescriptions = [
  "foo",
  "bar"
];

foreach device in network.devices
where device.platform.vendor == Vendor.JUNIPER
foreach command in device.outputs.commands
where command.commandType == CommandType.INVENTORY
let platform = device.platform
where isPresent(platform.model)
foreach part in platform.components
let serialNumber = part.serialNumber
where isPresent(serialNumber)
foreach configLine in parseConfigBlocks(OS.UNKNOWN, command.response)
let text = configLine.text
where matches(text, "*" + serialNumber + "*")
let description = replaceMatches(text, "*" + serialNumber, "")
select {
  violation: description in approvedDescriptions,
  Device: device.name,
  Model: platform.model,
  "Serial Number": part.serialNumber,
  Description: description
}

 

View original
Did this topic help you find an answer to your question?

1 reply

  • Employee
  • 3 replies
  • Answer
  • September 19, 2023
Below would help in matching against a list of known end of life HW part numbers within the inventory. In approvedDescriptions [“THIS WILL BE THE LIST TO MATCH AGAINST”];

 

approvedDescriptions = [
  "foo",
  "bar"
];

foreach device in network.devices
where device.platform.vendor == Vendor.JUNIPER
foreach command in device.outputs.commands
where command.commandType == CommandType.INVENTORY
let platform = device.platform
where isPresent(platform.model)
foreach part in platform.components
let serialNumber = part.serialNumber
where isPresent(serialNumber)
foreach configLine in parseConfigBlocks(OS.UNKNOWN, command.response)
let text = configLine.text
where matches(text, "*" + serialNumber + "*")
let description = replaceMatches(text, "*" + serialNumber, "")
select {
  violation: description in approvedDescriptions,
  Device: device.name,
  Model: platform.model,
  "Serial Number": part.serialNumber,
  Description: description
}

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings