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"
}
Mike Moniz
·1 year agoSo PropertySources are used to add properties to whole devices/resources. So good for items like the firmware, OS version, when the device was added to monitoring, etc.
"Instances" have a specific meaning and are when you have monitoring check (like network interfaces or disk volumes) which would apply multiple times to one device. So for example a switch might look like this:
CPU would be a DataSource without any instances, while Network Interfaces is a DataSource with multiple Instances.
So Interfaces that auto-add themselves would come from the DataSource's AutoDiscovery script. So you likely need to look at the AutoDiscover script for DataSources like "SNMP_Network_Interfaces" to add properties to instances. Note that these properties will start with "auto."