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

exe/script sensor not behaving as expected

Votes:

0

I made a sensor that runs a short powershell script. If I run the script straight from powershell, it works fine...produces either a 2:FAILED or a 0:OK response/output.

But from PRTG, it AWAYS produces a 0:OK no matter what. Can't figure out why. Here's the script below. It queries my server's web page and looks for the phrase *not available* on the page...that determines success or failure. You can skip this top block of code and jump to the bottom. Top portion is to ok the ssl cert. Again, works fine from powershell command line or from powershell ISE, just not PRTG.

add-type @"
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
    public class TrustAllCertsPolicy : ICertificatePolicy {
        public bool CheckValidationResult(
            ServicePoint srvPoint, X509Certificate certificate,
            WebRequest request, int certificateProblem) {
            return true;
        }
    }
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

$link = "https://server01.mycompany.com/web/MG_HLP_001_INQ.jsp"
$result = Invoke-WebRequest -Uri $link
$fullcontent = $result.Content

if ($fullcontent -like '*Not Available*') {
  $exitstatus = "2:FAILED"
  write-host $exitstatus

  exit 2
  }
ELSE {
  $exitstatus = "0:OK"
  write-host $exitstatus

  exit 0
  }

custom-sensor powershell prtg

Created on Jan 5, 2016 8:57:43 PM



1 Reply

Votes:

0

I figured this out myself. I added the parameter -UseBasicParsing I changed the Invoke-WebRequest line to: $result = Invoke-WebRequest -Uri $link -UseBasicParsing

Not 100% sure why that works but it does.

-thanks ME

Created on Jan 6, 2016 9:42:19 PM




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.