Instance discovery time
Hello,
I was looking to is if anyone has created a module that would add the date and time a new instance is discovered for a module? I'm looking to determine when new interfaces are added to the network interfaces module on devices. I thought about changing the discovery script for that module to add the time but I cant determine where and how to add it so I tried creating a separate property source to do so but no luck. Any advice or insight is welcomed as well.
// Assuming 'instance' refers to the current device instance within the PropertySource context
def instance = context.device // Access the device object from the context, replace this with the actual method to access the device
// Check if the 'discoveryTimestamp' property already exists
def discoveryTimestamp = instance.getDynamicProperty("discoveryTimestamp")
if (discoveryTimestamp == null) {
// If the discovery timestamp doesn't exist, it's a new instance
// Capture the current date and time in a readable format
def currentDate = new Date()
def formattedDate = currentDate.format("yyyy-MM-dd HH:mm:ss")
// Add the discovery timestamp to the instance's dynamic properties
instance.addDynamicProperty("discoveryTimestamp", formattedDate)
// Output the discovery timestamp (This is logged in the script output)
println "New instance discovered at: $formattedDate"
} else {
// If the property exists, it's not a new instance
println "Instance already discovered. Timestamp: $discoveryTimestamp"
}