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

Web Scraping Python

Votes:

0

Hi guys,

I did a web scraping with Python, to collect metrics from a host that are only accessible by a website. I would like to show these metrics in PRTG, through the custom sensor Python script. It's possible? I tried to do it and I get an error, that the output is not compatible with the expected JSON. I used the same formatting as the Python example sensor.

This script of mine has a dependency on an application that will allow access to a web browser, and it needs to be in the same folder as the script. Can I add it to the same folder as the Python scripts in PRTG? Or could it be in another?

json- python web-scraping

Created on Oct 6, 2022 5:27:51 PM

Last change on Oct 11, 2022 1:34:54 PM by  Chan Siau Hen [Paessler Technical Support]



11 Replies

Votes:

0

Hello there,

Thanks for the KB post. The python script has to be placed inside \python subfolder of the PRTG program directory, for the sensor to read the PRTG syntax.

If your python script is 'directory' sensitive and no way you can tweak the script itself, what you can do is run the script with Python install in the server (not the one that comes with PRTG).

To make it display the result in our sensor, you need to use EXE Script or EXE Script Advanced sensor. You need a simple batch script to trigger your python script. This batch script is should be stored in the \Custom Sensors\EXE subfolder as per the manual.


@echo off
python c:\xxxx\xx.py %1 %2


So basically, the sensor is reading the expected PRTG syntax from the batch file output.

This is the only workaround I can think of, for now.


With kind regards,
Chan Siau Hen
Technical Support Team, Paessler AG

Created on Oct 11, 2022 1:57:55 PM by  Chan Siau Hen [Paessler Technical Support]

Last change on Oct 12, 2022 6:07:03 AM by  Chan Siau Hen [Paessler Technical Support]



Votes:

0

Okay, I'll try this way. One more question, I ran my Python script through CMD from the \python folder in the PRTG directory, and it worked perfectly. Could it be that PRTG doesn't accept some libraries from my script? For example, I use Beautifulsoup and Selenium. If so, is there any way to integrate them into PRTG's Python interpreter?

Created on Oct 13, 2022 7:51:39 PM



Votes:

0

Hello man, I made a batch file script as you informed and it worked a part. I'm getting a PE132 error, saying that the response is not formatted correctly. Below is the batch file:

@echo off python xxxx.py

What would be the correct way to format it? My script only returns floating point numbers.

Created on Oct 17, 2022 4:39:06 PM



Votes:

0

Hi there,

Thanks for the feedback.

Could you please let me know which sensor you are using? Besides this, do you know what output is the batch script producing? Maybe you can send the output to a text file and share it with me.


With kind regards,
Chan Siau Hen
Technical Support Team, Paessler AG

Created on Oct 24, 2022 4:34:22 AM by  Chan Siau Hen [Paessler Technical Support]

Last change on Oct 25, 2022 4:08:05 PM by  Chan Siau Hen [Paessler Technical Support]



Votes:

0

Hey,

I managed to get the output to be formatted the right way. However, the output of my script is still not shown on my sensor. I'm using the advanced script that returns a integer numeric.

{

@echo off python xxxx.py %1 echo %1:OK

}

My Python script returns an integer, say 112, this value is located inside a variable in the script, and I use the print command to print this value. From what I understand, this value should be passed as an argument to %1 and this way I would be able to show it in my sensor.

Created on Oct 24, 2022 11:22:59 AM



Votes:

0

Hi there,

You do not need to include any 'return format' syntax in the batch file. The syntax should be in the python script. Please remove echo %1:OK. The return format for the Advanced EXE sensor can be found here

The batch file should just look like this.

@echo off
python c:\xxxx\xx.py


With kind regards,
Chan Siau Hen
Technical Support Team, Paessler AG

Created on Oct 25, 2022 4:07:46 PM by  Chan Siau Hen [Paessler Technical Support]



Votes:

0

Hello guys,

See, I put that return syntax because I was trying to do it through the EXE sensor that returns a number. From the advanced EXE sensor, I'm also not getting success. This sensor must return an XML or JSON, correct? Running my Python script through a batch file, it will show the value 112, how would I pass this value into the XML? I'm not asking how to format the XML, I'd just like to know how to get the output of my script into the XML structure.

Created on Oct 25, 2022 5:00:58 PM



Votes:

0

Hi there,

If you see only 112, it means you didn't include the expected PRTG format in the python script.

To get the output to the XML structure, please refer to this -> https://www.paessler.com/manuals/prtg/custom_sensors

I have put the same link in my last reply. Hope this help.

----
With kind regards,
Chan Siau Hen
Technical Support Team, Paessler AG

Created on Oct 29, 2022 11:17:11 AM by  Chan Siau Hen [Paessler Technical Support]



Votes:

0

My Python script apparently doesn't run in PRTG, as I said before. I use libraries like BeautifulSoup and Selenium, does PRTG support them? If not, I'm trying to run it through the custom script and I'm not able to throw my script's output into these sensors. That's all, I know how to format the standard output in XML and JSON, but I'm just not able to transfer the data from my script into a custom structure, understand?

Created on Oct 31, 2022 12:11:11 PM



Votes:

0

Hello there,

I understand your request. I already told you in this thread, "run the script with Python install in the server (not the one that comes with PRTG)." I am not sure how to convey this message more clearly.

This workaround is definitely out-of-scope our support scope. I was trying to provide the extra mile to help but unfortunately, it didn't work out here. I am really sorry for that.

I hope maybe other readers could provide some input here.


With kind regards,
Chan Siau Hen
Technical Support Team, Paessler AG

Created on Nov 2, 2022 1:44:05 PM by  Chan Siau Hen [Paessler Technical Support]

Last change on Nov 2, 2022 1:44:34 PM by  Chan Siau Hen [Paessler Technical Support]



Votes:

0

Hello,

I did as you said. I put the JSON formatting inside my Python script, and I'm running this script through a batch file. But my PRTG tells me the response is not formatted correctly as the "python" command is not recognized as an internal command, operable program or batch file. I know this error is common when python installation is not pointing to system environment variables. However, I already made this note, the "python" command is seen by my entire system, only PRTG points out this error when it tried to run my script through it. Is there some other kind of permission I need to do?

Created on Nov 14, 2022 8:01:49 PM




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.