Skip to main content

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
}

 

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 = n
"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
}

 


Reply