Forum Discussion
Stephen_C
Neophyte
Thanks. I managed to get the following together which seems to work. I want to use it to monitor some remote devices. Thanks for the assistance!
import com.santaba.agent.groovyapi.expect.Expect;
import com.santaba.agent.groovyapi.snmp.Snmp;
import com.santaba.agent.groovyapi.http.*;
import com.santaba.agent.groovyapi.jmx.*;
import org.xbill.DNS.*;
import com.jcraft.jsch.JSch;
import com.santaba.agent.util.Settings;
hostname = hostProps.get("system.hostname")
//hostname = "www.google.com"
mymtu = hostProps.get("custom.ping.mtu")?.toInteger() ?: 1472
pingargs = '-n 4 -f -l $mymtu'
timeout = 15000 // timeout in milliseconds
try {
def command_output = "ping ${hostname} ${pingargs}".execute().text
//command_output = command_output.toString()
//println command_output
packetsSent = (((command_output.findAll(~/(?<=Sent = )\d+/)).toString()).replaceAll(/\[(\d+)\]/, '$1')).toInteger()
packetsReceived = (((command_output.findAll(~/(?<=Received = )\d+/)).toString()).replaceAll(/\[(\d+)\]/, '$1')).toInteger()
packetsLost = (((command_output.findAll(~/(?<=Lost = )\d+/)).toString()).replaceAll(/\[(\d+)\]/, '$1')).toInteger()
roundtripMinimum = (((command_output.findAll(~/(?<=Minimum = )\d+/)).toString()).replaceAll(/\[(\d+)\]/, '$1')).toInteger()
roundtripMaximum = (((command_output.findAll(~/(?<=Maximum = )\d+/)).toString()).replaceAll(/\[(\d+)\]/, '$1')).toInteger()
roundtripAverage = (((command_output.findAll(~/(?<=Average = )\d+/)).toString()).replaceAll(/\[(\d+)\]/, '$1')).toInteger()
println 'packetsSent=' + packetsSent
println 'packetsReceived=' + packetsReceived
println 'packetsLost=' + packetsLost
println 'roundtripMinimum=' + roundtripMinimum
println 'roundtripMaximum=' + roundtripMaximum
println 'roundtripAverage=' + roundtripAverage
return 0
}
catch (Exception e) {
println "Unexpected Exception : " + e
return 1
}
Anonymous
8 months agoGreat that it's in Groovy. Makes it cross platform usable. I see now that you meant pinging devices that are already in LM (i thought you meant pinging devices outside LM). Looks like you should be able to use "custom.ping.mtu" as your AppliesTo. Is that what you're doing?
Related Content
- 9 months ago
- 2 years ago