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?
Article Comments
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?
Oct, 2022 - Permalink
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.
Oct, 2022 - Permalink
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
Oct, 2022 - Permalink
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.
Oct, 2022 - Permalink
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
Oct, 2022 - Permalink
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.
Oct, 2022 - Permalink
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
Oct, 2022 - Permalink
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?
Oct, 2022 - Permalink
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
Nov, 2022 - Permalink
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?
Nov, 2022 - Permalink
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
Oct, 2022 - Permalink