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

Sensor not working while user logged out

Votes:

0

Hi Guys,

i´ve got an problem regarding an Custom Sensor in Prtg.

I use the following Powershell-Script to get information from an webpage and to trim it to a short output.

the script:

$webpage=Invoke-WebRequest "private ip-address"
$webpage.RawContent | Out-File "C:\Skripte\Tank_S3\webpage_Fuellstand.txt" ASCII -Width 9999
$input_path = "C:\Skripte\Tank_S3\webpage_Fuellstand.txt"
$output_file2 = "C:\Skripte\Tank_S3\Fuellstand.txt"
$regex = '([0-9]{1,2}%)'
$string_fuellstand = Select-String -Path $input_path -Pattern $regex -list | % { $_.Matches } | % { $_.Value }
$string_fuellstand = $string_fuellstand.Remove(2)
$text = $string_fuellstand + ":Wert ermittelt."
$string_fuellstand = $string_fuellstand + ";" + $(get-date).toString('yyyy-MM-dd;HHmmss')
$string_fuellstand >> $output_file2
write-host $text

It works fine as long as an User is logged into the PRTG-Computer.

This is the output while someone is logged in:

80;2017-04-12;103427

If no one is logged in, following output is generated:

;2017-04-12;103915

I´ve already tried to give specific access rights to the sensor. The security is set to use the access data of the parenting device.

I´m now a little bit confused because the script alone works if set in the task scheduler without anyone logged in.

Am I missing some point?

Kind regards,

Daniel

custom-sensor powershell prtg

Created on Apr 12, 2017 9:15:01 AM

Last change on Apr 12, 2017 2:06:04 PM by  Torsten Lindner [Paessler Support]



Best Answer

Accepted Answer

Votes:

0

Hi Luciano,

the webrequest leads to an "open" website in our network. You can log in, but the crucial information that the sensor displays is without credentials.

If i change the account to server-admin i get following error-message: "Dem Client fehlt ein erforderliches Recht. (0x522)".

So i set it back to system-account.

Your hint to track down the problem with the sensor-settings to "write the result to disk" was quite good.

I´m not quite sure how much you will understand if i post the german version:

"Invoke-WebRequest : Der Antwortinhalt kann nicht analysiert werden, da das 
Internet Explorer-Modul nicht verfügbar ist, oder die Konfiguration beim 
ersten Start von Internet Explorer ist nicht abgeschlossen. Geben Sie den 
UseBasicParsing-Parameter an, und wiederholen Sie den Vorgang. "

Essentialy: PRTG cant get anything out of the script because the IE-modul is not available.

I edited my Script and used the -usebasicparsing switch and now everything works fine.

Thank you for your help and happy Easter!

Kind regards Daniel

Created on Apr 13, 2017 12:58:22 PM

Last change on Apr 18, 2017 5:52:26 AM by  Luciano Lingnau [Paessler]



4 Replies

Votes:

0

for some reasons i couldn´t edit my post. So, for better readability:

$webpage=Invoke-WebRequest "private ip-address" 
$webpage.RawContent | Out-File "C:\Skripte\Tank_S3\webpage_Fuellstand.txt" ASCII -Width 9999
$input_path = "C:\Skripte\Tank_S3\webpage_Fuellstand.txt" 
$output_file2 = "C:\Skripte\Tank_S3\Fuellstand.txt" \\ $regex = '([0-9]{1,2}%)' 
$string_fuellstand = Select-String -Path $input_path -Pattern $regex -list | % { $_.Matches } | % { $_.Value } $string_fuellstand = $string_fuellstand.Remove(2)\\ $text = $string_fuellstand + ":Wert ermittelt." 
$string_fuellstand = $string_fuellstand + ";" + $(get-date).toString('yyyy-MM-dd;HHmmss') $string_fuellstand >> $output_file2 
write-host $text

Kind regards,

Daniel

Created on Apr 12, 2017 12:53:56 PM

Last change on Apr 13, 2017 7:25:34 PM by  Felix Saure [Paessler Support]



Votes:

0

Hello Daniel,
thank you for your reply.

The original version in the original post is more than fine. :)

I'm not exactly sure how the logged user could be making a difference. Are any sort of credentials required when you do the Invoke-WebRequest "private ip-address" ?

As for the issue, this does normally have to do with permissions. Keep in mind that the PRTG Probe Service which runs custom sensors uses the LOCAL_SYSTEM account by default. You could use services.msc to change this and specify a different account, does the behavior when running the script change?

Also, when you run the script via a scheduled task, which user account is used to run the script?

Something else you can try to track down the issue is to set the "EXE Result" to "Write EXE result to disk" within the Sensor's settings. Once configured to do so a resulting Text File (Filename: 'Result of Sensor [ID].txt') will be stored under the Logs (Sensors) directory on the next scan of the sensor. This folder's path is by default "C:\ProgramData\Paessler\PRTG Network Monitor" of the probe where the sensor is monitored. This log may tell you more about what happens during the sensor's execution.

Also, on a side note, why do you store the file to disk before processing it further? Have you tried something like this?

$webpage = Invoke-WebRequest -Uri "http://fqdn/url" -UseBasicParsing
$regex = '([0-9]{1,2}%)'
$string_fuellstand = Select-String -InputObject $webpage.RawContent -Pattern $regex -list | % { $_.Matches } | % { $_.Value }
$string_fuellstand = $string_fuellstand.Remove(2)
$text = $string_fuellstand + ":Wert ermittelt."
$string_fuellstand = $string_fuellstand + ";" + $(get-date).toString('yyyy-MM-dd;HHmmss')
write-host $text

Note: I haven't tested the code above as I don't know how the input looks like.

Best Regards,

Created on Apr 13, 2017 11:00:06 AM by  Luciano Lingnau [Paessler]



Accepted Answer

Votes:

0

Hi Luciano,

the webrequest leads to an "open" website in our network. You can log in, but the crucial information that the sensor displays is without credentials.

If i change the account to server-admin i get following error-message: "Dem Client fehlt ein erforderliches Recht. (0x522)".

So i set it back to system-account.

Your hint to track down the problem with the sensor-settings to "write the result to disk" was quite good.

I´m not quite sure how much you will understand if i post the german version:

"Invoke-WebRequest : Der Antwortinhalt kann nicht analysiert werden, da das 
Internet Explorer-Modul nicht verfügbar ist, oder die Konfiguration beim 
ersten Start von Internet Explorer ist nicht abgeschlossen. Geben Sie den 
UseBasicParsing-Parameter an, und wiederholen Sie den Vorgang. "

Essentialy: PRTG cant get anything out of the script because the IE-modul is not available.

I edited my Script and used the -usebasicparsing switch and now everything works fine.

Thank you for your help and happy Easter!

Kind regards Daniel

Created on Apr 13, 2017 12:58:22 PM

Last change on Apr 18, 2017 5:52:26 AM by  Luciano Lingnau [Paessler]



Votes:

0

Hi Luciano,

your hint with "writing exe result to disk" worked. Prtg couldn´t call the IE modul while logged off.
So i used your -usebasicparsing switch.

And now everything works just fine.

Thank you for your help.

Kind regards Daniel

Created on Apr 18, 2017 5:38:44 AM

Last change on Apr 18, 2017 5:52:48 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.