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

Custom sensor shows Down regardless of exit code.



Hi. This may sound like a repeated question, but as far as I can tell, I've tried all the suggestions I've found, and I'm still having an issue.

I have a powershell script that, no matter what exit code I return, the sensor shows a warning state immediately after running, then shows an error state. Regardless, I still get the output I want, but I'd like to know what I'm doing wrong in regards to the exit state.

I have the settings set to set placeholders as environment variables, and I pass %device as a parameter.

I also selected "Use Windows credentials of parent device."

When I run the code from the command line or from an ISE, it works fine. No errors.

My code is as follows:

$BeginDate = $null
$LogResults = $null

Try {
   $LogResults = get-wmiobject -class win32_ntlogevent -ComputerName $args[0] -filter "(Type='Error') and (LogFile='Application') and (TimeGenerated >'$BeginDate') and (SourceName <> 'GetEnginefiles')"

   If ($LogResults) {
      $FormattedResult = New-Object System.Text.StringBuilder
      foreach ($Result in $LogResults) {
      Write-Host "1:$FormattedResult"
      exit 1
   } else {
      Write-Host "0:OK"
      exit 0
} Catch {
   Write-Host "2:Error"
   exit 2

custom-sensor exitcode powershell prtg wql

Created on Mar 26, 2013 7:50:33 PM

Last change on Mar 26, 2013 7:57:39 PM by  Konstantin Wolff [Paessler Support]

5 Replies



what is the precise error message you are receiving? What is the output of the script when run manually?
May you additional activate the debug mode of the sensor? That can be done on tab Settings of the same. There set option Result Handling to Write Result to disk. This will create a file called Result of Sensor XXXX.txt in the subfolder Logs (Sensors) of your PRTG Data Directory.
What is the file content?

Created on Mar 26, 2013 8:01:25 PM by  Konstantin Wolff [Paessler Support]



Right now, it says "#01320:", then gives me the output I'm looking for.

I'm not finding a results file, even after changing the result handling.

Created on Mar 26, 2013 8:34:31 PM



The precise path to the output file should by standard be the following

C:\ProgramData\Paessler\PRTG Network Monitor\Logs (Sensors)

Please note that this is a hidden folder
What precise sensor type are you using? The EXE/Script or the EXE/Script Advanced Sensor?

Created on Mar 26, 2013 8:40:37 PM by  Konstantin Wolff [Paessler Support]



It appears that PRTG does not like the long variable I returned as the $FormattedResult. I returned a much shorter, simpler message instead, and it seems to work. I suppose I could write code in the sensor itself that sends me the long output in an email, but just returns a short, generic message to the sensor.

Created on Mar 26, 2013 9:59:15 PM



You are correct, the length of the MESSAGE variable is automatically cut at 255 characters. So it is not possible to return longer messages to PRTG. Sorry. What message is the sensor showing?

Created on Mar 27, 2013 3:01:39 PM by  Konstantin Wolff [Paessler Support]

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.