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

PRTG Network Monitor

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

Free Download

Top Tags


View all Tags

Monitor 1 value, on error send 2nd value

Votes:

0

Your Vote:

Up

Down

I have an HTML page which looks like this: [120] [RandomText]

First value is an integer, and the second value is a string.

I would like to create a sensor, that will send the string itself (let's say by email, but that is not the issue here) if the 1st integer value is greater than X. I tried to create an HTTP Content sensor, but it can only monitors integer/ float, and NOT strings.

Could you please help?

custom-script-exe http integer notification string

Created on Feb 21, 2013 11:19:55 PM by  yoland (0) 1

Last change on Mar 19, 2015 3:39:58 PM by  Martina Wittmann [Paessler Support]



Best Answer

Accepted Answer

Votes:

0

Your Vote:

Up

Down

As a basic script to wrap this problem you can create a powershell-script in your CustomSensors-folder of PRTG with the following Content:

Param([string]$URL,[int]$warnlevel)

$error.clear()
$ActionPreference = "silentlyContinue"
$errorActionPreference = $ActionPreference
$warningActionpreference = $ActionPreference

# create a table to store the information 
$table = New-Object system.Data.DataTable "result"
$col1  = New-Object system.Data.DataColumn channel,string
$col2  = New-Object system.Data.DataColumn value,decimal
$col3  = New-Object system.Data.DataColumn unit,string
$col4  = New-Object system.Data.DataColumn warning,string
    
$table.columns.add($($col1))
$table.columns.add($($col2))
$table.columns.add($($col3))
$table.columns.add($($col4))

# this function produces a well-formated prtg-xml-output out of a given table
function New-Xml
{
	param($RootTag="prtg",$ItemTag="result", $ChildItems="*", $TextTag="OK", $Attributes=$Null)

	Begin {
		$xml = "<$RootTag>`n"
	}
	Process {
		$xml += "  <$ItemTag>`n"
        foreach ($child in $_ | Get-Member -Type *Property $childItems)
        {
            $Name = $child.Name
            if (-not "$($_.$name)" -eq "")  {
                $xml += "    <$Name>$($_.$Name)</$Name>`n"
            }
        }
		$xml += "  </$ItemTag>`n"
	}
	End {
        $xml += "  <text>$TextTag</text>`n" 
		$xml += "</$RootTag>`n"
		$xml
	}
} 

# initialize the webclient
$webclient = New-Object Net.WebClient
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}

# download the page
$response = $webclient.DownloadString($URL)
# for example: $response: "[993][385][0][350][Test]"

# parse the result for 'words' 
$regex = [regex]"\[([^\]]+)\]+"
$valArr = ($response | select-string -allmatches $regex | Select-Object -ExpandProperty matches | Select-Object -ExpandProperty value | ForEach {$_ -replace "\[|\]", ""})
# from the example: $valArr.Length: 5

# iterate through the results without the last value
$valueCount = $valArr.length - 2
for ($i=0; $i -le $valueCount; $i++)
{
    $row = $table.NewRow();
    $index = $i + 1
    $row.channel = "Value $index"
    $row.value = [int]$valArr[$i]
    if ($row.value -gt $warnlevel) { $row.warning = "1"; }
    $row.unit  = "Count"
    $table.Rows.Add($row)
} 

# define the last value as response-text
$resultText = $valArr[-1]

# forward the generated table to xml-generator and store the result as $retval
$retval = $table | New-Xml -ChildItems Channel,Value,Unit,CustomUnit,Warning,Error -TextTag $resultText

# return the result
write-host $retval

exit

Now you can add this script to PRTG as a new CustomSensor 'EXE/Script Advanced'.

As Parameter use the url for the HTML-page and a threshold for triggering a warning-state in the format: "[url] [integer-for-maximum]"

For example, enter as parameters: "http://www.example.org/testing 25"

This sensor returns all values it finds at the given URL as single channels —except for the last value in that row. The last value will not be returned in a sensor channel, but will be used as the sensor's 'last message'.

After that you can define a notification for the 'warning' status and you will be notified with the 'last-message' value.

Kind regards

Created on Feb 22, 2013 1:55:05 PM by  Dieter Loskarn [Paessler Support]

Last change on Feb 26, 2013 9:39:43 AM by  Daniel Zobel [Product Manager]



2 Replies

Votes:

0

Your Vote:

Up

Down

Hi,

as PRTG is designed to process results in graphs it is hard to process string-results as sensor-values.

The only possibility is to use a 'wrapper'-custom-sensor that parses the HTML-Page and returns the value and the string as <value>:<string> pair so that PRTG uses the string as 'Last Message'. This message although appears in the Notification.

Kind regards

Created on Feb 22, 2013 12:03:51 PM by  Dieter Loskarn [Paessler Support]



Accepted Answer

Votes:

0

Your Vote:

Up

Down

As a basic script to wrap this problem you can create a powershell-script in your CustomSensors-folder of PRTG with the following Content:

Param([string]$URL,[int]$warnlevel)

$error.clear()
$ActionPreference = "silentlyContinue"
$errorActionPreference = $ActionPreference
$warningActionpreference = $ActionPreference

# create a table to store the information 
$table = New-Object system.Data.DataTable "result"
$col1  = New-Object system.Data.DataColumn channel,string
$col2  = New-Object system.Data.DataColumn value,decimal
$col3  = New-Object system.Data.DataColumn unit,string
$col4  = New-Object system.Data.DataColumn warning,string
    
$table.columns.add($($col1))
$table.columns.add($($col2))
$table.columns.add($($col3))
$table.columns.add($($col4))

# this function produces a well-formated prtg-xml-output out of a given table
function New-Xml
{
	param($RootTag="prtg",$ItemTag="result", $ChildItems="*", $TextTag="OK", $Attributes=$Null)

	Begin {
		$xml = "<$RootTag>`n"
	}
	Process {
		$xml += "  <$ItemTag>`n"
        foreach ($child in $_ | Get-Member -Type *Property $childItems)
        {
            $Name = $child.Name
            if (-not "$($_.$name)" -eq "")  {
                $xml += "    <$Name>$($_.$Name)</$Name>`n"
            }
        }
		$xml += "  </$ItemTag>`n"
	}
	End {
        $xml += "  <text>$TextTag</text>`n" 
		$xml += "</$RootTag>`n"
		$xml
	}
} 

# initialize the webclient
$webclient = New-Object Net.WebClient
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}

# download the page
$response = $webclient.DownloadString($URL)
# for example: $response: "[993][385][0][350][Test]"

# parse the result for 'words' 
$regex = [regex]"\[([^\]]+)\]+"
$valArr = ($response | select-string -allmatches $regex | Select-Object -ExpandProperty matches | Select-Object -ExpandProperty value | ForEach {$_ -replace "\[|\]", ""})
# from the example: $valArr.Length: 5

# iterate through the results without the last value
$valueCount = $valArr.length - 2
for ($i=0; $i -le $valueCount; $i++)
{
    $row = $table.NewRow();
    $index = $i + 1
    $row.channel = "Value $index"
    $row.value = [int]$valArr[$i]
    if ($row.value -gt $warnlevel) { $row.warning = "1"; }
    $row.unit  = "Count"
    $table.Rows.Add($row)
} 

# define the last value as response-text
$resultText = $valArr[-1]

# forward the generated table to xml-generator and store the result as $retval
$retval = $table | New-Xml -ChildItems Channel,Value,Unit,CustomUnit,Warning,Error -TextTag $resultText

# return the result
write-host $retval

exit

Now you can add this script to PRTG as a new CustomSensor 'EXE/Script Advanced'.

As Parameter use the url for the HTML-page and a threshold for triggering a warning-state in the format: "[url] [integer-for-maximum]"

For example, enter as parameters: "http://www.example.org/testing 25"

This sensor returns all values it finds at the given URL as single channels —except for the last value in that row. The last value will not be returned in a sensor channel, but will be used as the sensor's 'last message'.

After that you can define a notification for the 'warning' status and you will be notified with the 'last-message' value.

Kind regards

Created on Feb 22, 2013 1:55:05 PM by  Dieter Loskarn [Paessler Support]

Last change on Feb 26, 2013 9:39:43 AM by  Daniel Zobel [Product Manager]



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.