Forum Discussion

Stephen_C's avatar
Stephen_C
Icon for Neophyte rankNeophyte
2 months ago

Ping with custom MTU size?

I have a requirement to ping a device from the collector but using a custom MTU,

Does anyone have any suggestions on the best way to do this? My collectors are all Windows based.

6 Replies

  • 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
    }

     

    • Stuart_Weenig's avatar
      Stuart_Weenig
      Icon for Legend rankLegend

      FYI, you don't need any of those imports. You're not using any of them, so importing them is a waste of CPU cycles.

      • Stephen_C's avatar
        Stephen_C
        Icon for Neophyte rankNeophyte

        Thanks for the tip, I didn't actually know that. 

    • Stuart_Weenig's avatar
      Stuart_Weenig
      Icon for Legend rankLegend

      Great 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?

  • You could do a scripted datasource using powershell that invokes the ping command with the -l argument. I recommend a multi-instance script (not batchscript) datasource with property based discovery.

    Meaning; set a property called ping.targets with a comma separated list of names/IPs you want to ping. Your AppliesTo becomes simply "ping.targets". Your Groovy discovery script would look like this:

    hostProps.get("ping.targets").replaceAll(" ","").tokenize(",").each{
        println(it + "##" + it)
    }
    return 0

    Then your script would look like this:

    $result = ping -l X ##WILDVALUE## # replace X with your desired MTU size
    # do something with $result to get the output to be a number representing what you want to know
    # write it out using Write-Host
    return 0

    I'm not a powershell guy, so i'm not much help with the collection script. You'd need to take the result and manipulate it into one or more datapoints. Each datapoint would be written to the host using "Write-Host datapointname: Y" where datapointname is the name you want to call the datapoint and Y is the numeric value.