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

My Powershell scripts takes more than 900 seconds to run and always timeouts, how to get it to work?

Votes:

0

I have a custom Powershell script that takes more than 900 seconds (or takes a long time in general) to complete.

Within PRTG the script times-out with error PE018 because the maximum timeout limit is 900 seconds. How to get my custom script working within PRTG as it is essential to my monitoring?

custom-script-exe custom-sensor pe018 powershell

Created on Jul 21, 2015 9:12:17 AM by  Luciano Lingnau [Paessler]

Last change on Jul 21, 2015 9:36:53 AM by  Luciano Lingnau [Paessler]



1 Reply

Accepted Answer

Votes:

0

Within PRTG, Scripts for custom sensors should normally only query properties/things (Usually Get- Powershell cmdlets) and those operations are usually quick.
You should perform any operations (Normally Set-, Start-, New-, etc cmdlets) outside the Custom Sensor's script.

In case you're just performing query operations and your script still takes a long time to complete (it can happen) there's a way around it:

Instead of running the long script within PRTG, run it from a Windows Scheduled Task, invoke the script in the following way(In most cases NO CHANGE is required to the original script):

powershell.exe C:\mylocation\myscript.ps1 > C:\mylocation\scriptoutput.txt

And then for PRTG, create a new powershell script that you will add using the same custom sensor type as previously with the following code:

Get-Content -LiteralPath "C:\mylocation\scriptoutput.txt"

The actual result is that the lengthy original script will be run as a task and it's original output will be written to a file, the second small script will only read/print the result of the original script.

That way, the execution time within PRTG will be massively improved, the sensor will no longer timeout and the load on the PRTG Probe will also decrease (As it will not keep open probe threads during the sensor's lengthy execution).

It's recommend to use an interval that is similar to the Windows Task's schedule, otherwise you'll repeatedly see the same value within PRTG if the file is queried multiple times before it is updated by the Scheduled Task. If you modify the sample script you can create a "Last Updated" message or channel to guarantee that the result is up-to-date.

Alternatively is is possible to create a File Sensor to warn you in case the output file wasn't updated for some reason, or a Windows Scheduled Task sensor to confirm that the task is indeed running as expected.

Update: If you're willing to modify the script, there's also another way this can be achieved. The script can be modified to actually send the data to PRTG directly instead of writing a file. This can be accomplished by sending the data to an HTTP Push Data Advanced Sensor. The result needs of the actual query should be stored in a variable which can then be sent to the corresponding PRTG Probe/Sensor (with the corresponding key) and the data will show up in the sensor in PRTG.

Created on Jul 21, 2015 9:36:11 AM by  Luciano Lingnau [Paessler]

Last change on Nov 20, 2017 7:51:20 AM by  Luciano Lingnau [Paessler]




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.