What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

http sensor: how to get regex from a string response

Votes:

0

I need to get a numeric value from http get.

Websense makes available a status code from this url: http://<WCG IP address>:8083/health.load Load=2253 Conns=5150 Mbps=6.42 ..how can I get above numeric values with a regex expression and to keep them monitored?

many thanks, Gianluca

get http regex

Created on May 9, 2016 8:17:15 PM



1 Reply

Accepted Answer

Votes:

1

Hey,

I used a Windows Shell script (saved in PRTG custom sensor folder) for downloading the HTTP-Content to local disc and then searched for trigger words to extract the following values and returned them as XML channel. This way you can use the xmlexe-sensor, so you get each of your values back as individual channels.

Here is my vbs (provided "as is" without warrenty and so on, of course):

Option Explicit
Dim wshshell
Dim source, target, text, value, name, output, entry, entries
Set wshshell = CreateObject("WScript.Shell")
target = "C:\PRTGScripts\PRTG_custom_http.html"

source = "http://yoursourceurl"

text = DownloadHTTP(source, target)
entries = split (text, " ")
output = ""
output = output & "<prtg>" & vbcrlf
for each entry in entries
	'here to do some code dividing the channel name and value
	name = mid(text, 1, 5)
	value = mid(text, 5, 4)
	
	output = output & "  <result>" & vbcrlf
	output = output & "    <channel>" & name & "</channel>" & vbcrlf
	output = output & "    <float>1</float>" & vbcrlf
	output = output & "    <unit></unit>" & vbcrlf
	output = output & "    <value>" & value & "</value>" & vbcrlf
	output = output & "  </result>" & vbcrlf
	'wscript.echo entry
next
output = output & "</prtg>"  & vbcrlf

wscript.echo output

function DownloadHTTP(source, target)
	Dim HTTP, fs, datei, x, binary, file
	Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
	If http Is Nothing Then Set http = CreateObject("WinHttp.WinHttpRequest")
	If http Is Nothing Then Set http = CreateObject("MSXML2.ServerXMLHTTP")
	If http Is Nothing Then Set http = CreateObject("Microsoft.XMLHTTP")
	Set fs = WScript.CreateObject("Scripting.FileSystemObject")

	'for using proxy, if nessesary
	http.SetProxy 2, "yourproxyurl:8080"
	HTTP.open "GET", source, False
	HTTP.send
	datei = HTTP.responseBody
	For x = 0 to UBound(datei)
		binary = binary & ChrW(AscW(Chr(AscB(MidB(datei,x+1,1)))))
	Next
	Set file = fs.CreateTextFile(target, True)
	file.Write binary
	file.Close
	'DownloadHTTP = HTTP.StatusText
	DownloadHTTP = binary
End function

Created on May 10, 2016 11:18:14 AM




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.