@Stuart Weenig, I rephrased my question as:
Using Groovy 2.4, write the discovery and collection scripts for a multi-instance LogicMonitor DataSource for VMware NSX-T that exposes each IPsec tunnel as a discrete DataSource instance with the following datapoints: tunnel status, tunnel speed, tunnel transmit Bps, tunnel receive Bps, Tunnel throughput Bps, Tunnel Utilization Percentage, Tunnel Packet Loss Percentage, Tunnel Jitter, Tunnel Latency, Tunnel Mean Opinion Score.
Below is the response:
Here's an example of a Groovy 2.4 script for the discovery and collection of a multi-instance LogicMonitor DataSource for VMware NSX-T that exposes each IPsec tunnel as a discrete DataSource instance with the specified datapoints:
Discovery script:
import com.santaba.agent.groovyapi.datasources.*
import com.santaba.agent.groovyapi.execute.*
// Define the credentials to access the NSX-T API
def nsxHost = "${nsxHost}"
def nsxUsername = "${nsxUsername}"
def nsxPassword = "${nsxPassword}"
// Define the API endpoint to retrieve the IPsec tunnels
def endpoint = "/api/v1/ipsec-tunnel"
// Define the datapoints to retrieve for each IPsec tunnel
def datapoints = [
"status",
"speed",
"txBps",
"rxBps",
"throughputBps",
"utilizationPercent",
"packetLossPercent",
"jitter",
"latency",
"meanOpinionScore"
]
// Initialize the LogicMonitor DataSource
def ds = new BasicDataSource("NSX-T IPsec Tunnels")
// Set the custom properties for the DataSource
ds.setMultiInstance(true)
ds.addCustomProperty("nsxHost", nsxHost)
ds.addCustomProperty("nsxUsername", nsxUsername)
ds.addCustomProperty("nsxPassword", nsxPassword)
// Retrieve the list of IPsec tunnels and create a DataSource instance for each tunnel
executeWithApi("nsxt", { api ->
def tunnels = api.get(endpoint)
tunnels.each { tunnel ->
def instanceName = "Tunnel " + tunnel.id
def instance = ds.addInstance(instanceName)
// Set the instance custom properties
instance.addCustomProperty("tunnelId", tunnel.id)
// Add the datapoints to the instance
datapoints.each { datapoint ->
instance.addDatapoint(new SimpleDatapoint(datapoint))
}
}
})
// Save the DataSource
ds.save()
Collection Script:
import com.santaba.agent.groovyapi.datasources.*
import com.santaba.agent.groovyapi.execute.*
import com.santaba.agent.groovyapi.http.*
// Retrieve the custom properties for the DataSource
def nsxHost = "${nsxHost}"
def nsxUsername = "${nsxUsername}"
def nsxPassword = "${nsxPassword}"
// Retrieve the API endpoint for the specified IPsec tunnel
def getEndpoint = { tunnelId ->
"/api/v1/ipsec-tunnel/${tunnelId}"
}
// Retrieve the datapoint values for the specified IPsec tunnel
def getData = { tunnelId ->
def datapoints = [
"status",
"speed",
"txBps",
"rxBps",
"throughputBps",
"utilizationPercent",
"packetLossPercent",
"jitter",
"latency",
"meanOpinionScore"
]
def values = [:]
executeWithApi("nsxt", { api ->
def endpoint = getEndpoint(tunnelId)
def tunnel = api.get(endpoint)
datapoints.each { datapoint ->
values[datapoint] = tunnel[datapoint]
}
})
values
}
// Loop through each IPsec tunnel and collect its datapoints
executeWithApi("nsxt", { api ->
def tunnels = api.get("/api/v1/ipsec-tunnel")
tunnels.each { tunnel ->
def instanceName = "Tunnel " + tunnel.id
def instance = findDataSourceInstance(dsName, instanceName)
if (instance != null