Hi Gary,
Please try the following script in PowerShell first. It should result in:
<prtg>
<result>
<channel>HTTP Status Code</channel>
<value>200</value>
<float>0</float>
<unit>CustomUnit</unit>
<customunit>HTTP</customunit>
</result>
<text>Keyword "Running" found, as expected!</text>
</prtg>
Afterwards just add the Custom Sensor to the following directory on your PRTG Core Server or/and your Remote Probes Server: C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML\. Add a "EXE/Script Advanced Sensor" in PRTG and use the following parameters:
-url "<URL-TO-THE-WEBSITE>" |
-keyword "<KEYWORD TO LOOK FOR (Default: Running)>" |
The script:
# ____ ____ ____________
# / __ \/ __ \/_ __/ ____/
# / /_/ / /_/ / / / / / __
# / ____/ _, _/ / / / /_/ /
#/_/ /_/ |_| /_/ \____/
# NETWORK MONITOR
#-------------------
#(c) 2017 Dariusz Gorka, Paessler AG
#
# Checks certain website for keyword.
#
# Parameter "-url" for the URL of the website
# Parameter "-keyword" for the keyword that has to be available
param(
$url="http://my-computer/test.html",
$keyword="Running"
)
$regex_status = "(<label id=.status. class=.pull-right.*.>)(.*)(</label>\s+</div>\s+<div class=.content-source-statistics.>)"
$site = Invoke-WebRequest -Uri $url -UseBasicParsing
$site_content = $site.Content
$site_statuscode = $site.StatusCode
$site_result = $site_content -match $regex_status
$site_result = $matches[2]
if($site_result -eq $keyword){
$keyword_found = $true
} else {
$keyword_found = $false
}
Write-Host @"
<prtg>
<result>
<channel>HTTP Status Code</channel>
<value>$site_statuscode</value>
<float>0</float>
<unit>CustomUnit</unit>
<customunit>HTTP</customunit>
</result>
"@
if($keyword_found){
Write-Host @"
<text>Keyword "$keyword" found, as expected!</text>
"@
} else {
Write-Host @"
<text>Keyword not found, found "$site_result" instead!</text>
<error>1</error>
"@
}
Write-Host "</prtg>"
Best regards
Add comment