New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


Custom Sensor for PSPING

Votes:

0

Your Vote:

Up

Down

I'm trying to make a custom sensor for PSPING, a TCP ping tool :(https://technet.microsoft.com/en-us/sysinternals/jj729731.aspx)

the output from the commandline is "noisy" so, I created a batch file to try an just get the one value I want

FOR /f "tokens=9" %%G IN ('psping -q google.com:443 ^|find "Average"') do echo %%G

This still gives this output: PsPing v2.01 - PsPing - ping, latency, bandwidth measurement utility Copyright (C) 2012-2014 Mark Russinovich Sysinternals - www.sysinternals.com

100% C:\temp>echo 4.79ms 4.79ms

If I add this as a custom sensor, I get the error : Response not well formed (then the batch file contents)

I'd appreciate any pointers on how to get this working.

C:\temp>

batch-file custom-sensor latency

Created on Mar 25, 2015 2:55:58 AM by  aread (0) 1



Best Answer

Accepted Answer

Votes:

5

Your Vote:

Up

Down

Here is a small (vb.net) code snippet for the PsPing wrapper program

Sub Main()
    Dim p As New Process
   
    '// process details
    With (p.StartInfo)
        .UseShellExecute = False
        .RedirectStandardOutput = True
        .FileName = "c:\temp\psping.exe"
        .Arguments = "-q google.com:443"
        .WindowStyle = ProcessWindowStyle.Hidden
        .CreateNoWindow = True
    End With
   
    '// start the PsPing process and catch the output
    p.Start()
    Dim output() As String = p.StandardOutput.ReadToEnd.Split(Convert.ToChar(10))
    p.WaitForExit()
    
    '// loop through the result finding the 'Average' value
    For Each line As String In output
        Dim parts() As String = line.Split(","c)
        For Each part As String In parts
            If part.Contains("Average") Then
               '// return the found 'Average' value to PRTG
                Console.WriteLine(part.Split("="c)(1).Replace("ms", "").Trim & ":Ok")
                Environment.Exit(0)
            End If
        Next
    Next

    '// 'Average' value not found return an error
    Console.WriteLine("0:Could not find Average part")
    Environment.Exit(2)
End Sub

Created on Mar 25, 2015 11:55:02 AM by  PRTG Tools Family [prtgtoolsfamily.com] (12,885) 3 4



4 Replies

Votes:

0

Your Vote:

Up

Down

As you already mentioned, the PsPing utility writes its copyright message to the console. As a result of this, the copyright message is also part of the 'sensor output' and PRTG raises the error 'Response not well formed'

How can this be fixed?

You can write a separate program that will function as a wrapper for PsPing. This wrapper will need to execute PsPing in a shell and redirect the output to a memory stream.

After reading the data from the stream, the wrapper will need to write the well formatted message to the console, to be picked up by PRTG.

Created on Mar 25, 2015 9:50:01 AM by  PRTG Tools Family [prtgtoolsfamily.com] (12,885) 3 4



Accepted Answer

Votes:

5

Your Vote:

Up

Down

Here is a small (vb.net) code snippet for the PsPing wrapper program

Sub Main()
    Dim p As New Process
   
    '// process details
    With (p.StartInfo)
        .UseShellExecute = False
        .RedirectStandardOutput = True
        .FileName = "c:\temp\psping.exe"
        .Arguments = "-q google.com:443"
        .WindowStyle = ProcessWindowStyle.Hidden
        .CreateNoWindow = True
    End With
   
    '// start the PsPing process and catch the output
    p.Start()
    Dim output() As String = p.StandardOutput.ReadToEnd.Split(Convert.ToChar(10))
    p.WaitForExit()
    
    '// loop through the result finding the 'Average' value
    For Each line As String In output
        Dim parts() As String = line.Split(","c)
        For Each part As String In parts
            If part.Contains("Average") Then
               '// return the found 'Average' value to PRTG
                Console.WriteLine(part.Split("="c)(1).Replace("ms", "").Trim & ":Ok")
                Environment.Exit(0)
            End If
        Next
    Next

    '// 'Average' value not found return an error
    Console.WriteLine("0:Could not find Average part")
    Environment.Exit(2)
End Sub

Created on Mar 25, 2015 11:55:02 AM by  PRTG Tools Family [prtgtoolsfamily.com] (12,885) 3 4



Votes:

0

Your Vote:

Up

Down

Thanks so much for the code

Created on Mar 25, 2015 8:39:26 PM by  aread (0) 1



Votes:

0

Your Vote:

Up

Down

Hello,

Tried your vb snippet but always get this error, when i try to run it:

Microsoft VBScript compilation error: Expected end of statement )" (code: PE132)

Created on Mar 16, 2018 3:52:35 PM by  René Radtke (0)



Please log in or register to enter your reply.


Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.