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

PowerShell script notification

Votes:

0

Hi, I have the following script that checks the windows host file and returns a value based on the lines in the host file. For example, if a host file has an entry in it (that not remarked or 127.0.0.1) it will return an entry number. so if the host file has 1 entry in it the script will out put value 1, and if no entry it will not output any value. The script:

$counter = 0

foreach ($record in Select-String -pattern "^#","^127.0.0.1" -Path C:\Windows\System32\drivers\etc\hosts -NotMatch ) 
{
	if ($record.Line.length -gt 8) 
	{
		$counter = $counter + 1
	}
}
if ($counter -ne 0) {
Write-Host $counter
}

Now, I want to run this script on multiple servers that I monitor and trigger an alert if it returns a value.

Can anyone please help?

Thanks in advance.

notifications powershell windows

Created on Sep 27, 2016 12:20:19 PM

Last change on Sep 27, 2016 12:25:21 PM by  Luciano Lingnau [Paessler]



3 Replies

Votes:

0

Dear Rotem187

To use this script as custom Exe/Script sensor, please expand the output with adding a sensor message. The output format is

value:message

for example

write-host 1:Ok

To alert based on the return value, you can open the sensor's setting tab and add a threshold trigger. As an alternative, you can change the sensor status by using limits for the result channel, and add a state trigger.

There is a third option to change the sensor status: By using an exit code ("errorlevel") of 1 to change the sensor status to waring, or 2, 3, 4 to mark different alarm reasons. Please find the documentation in the PRTG webinterface, menu Setup | PRTG API, tab "Custom Sensors".

Created on Sep 28, 2016 2:18:04 PM by  Arne Seifert [Paessler Support]



Votes:

0

Hi, Thanks for the reply. How do i get PRTG to run this script on a remote computer? I created exe/script on a device but it's keeps returning the vales of the PRTG server and not the remote server that the sensor is on.

Thanks

Created on Sep 28, 2016 2:36:31 PM



Votes:

0

Dear Rotem187

That is correct, scripts are run locally. This prevents a PRTG user to spread possibly harmful scripts to other computers.

You can either expand your script to run a remote powershell, or install a PRTG remote probe on that computer and copy the script into that remote probe (in the same folder as on the core server.) Then create the sensor on the remote probe, and it is run there.

Created on Sep 28, 2016 7:02:46 PM by  Arne Seifert [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.