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 - value not saved

Votes:

0

Hi,

I have a simple script with following code

$files=get-childitem "C:\Temp\test" | where {$_.extension -ne ".txt" -and $_.PSIsContainer -ne "True"}

$numberfiles=$files.count

 if ($numberfiles -gt "4")    
    {
    write-host "$numberfiles":"$numberfiles files found"
    exit 2
	}

elseif ($numberfiles -gt "0") 
	{
      write-host "$numberfiles":"$numberfiles files found"
      exit 1
	}

else {write-host "no files found"
	exit 0
	}

Basically:

  • no files in directory: exit code 0, green, OK.
  • more than 0 files but less or equal than 4 files in directory: exit code 1, yellow, warning.
  • more than 4 files in directory: exit code 2, red, critical.

This all works, but for some reason, PRTG does not keep the value when exit code 2 is used. Only when exit code 0 or 1 is used, it keeps the value.

Screenshot: https://imgur.com/a/RMTFGER

Any ideas why this might happen?

code exe-script-sensor script

Created on Jul 9, 2019 7:05:31 AM



2 Replies

Accepted Answer

Votes:

1

Hi there,

As the exit codes 2-4 are considered as errors you don't get the value. The best way in your case would be to not use any exit code (only 0) and to define a limit in the "Value"-channel that triggers a warning/error. There you can also define a warning/error message.

Best regards.

Created on Jul 9, 2019 7:34:48 AM by  Dariusz Gorka [Paessler Support]



Votes:

0

Hi Dariusz,

Works like a charm, thanks so much!

Created on Jul 9, 2019 7:45:34 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.