I've written a custom python script to pull data from the Google Analytics Realtime Reporting API. The existing PRTG sensor for Google Analytics leverages the Core API so this won't work in this case (I've tested).
It has been noted in another KB post (https://helpdesk.paessler.com/en/support/solutions/articles/77005-prtg-paepy-package-and-other-python-packages) ... "PRTG uses its own Python runtime ("C:\Program Files (x86)\PRTG Network Monitor\Python34"). Please make sure that you add all needed modules in the appropriate subfolder ("..\Python34\Lib\site-packages\") in order to enable PRTG to load them."
I'm looking to add the Google API Client Module to PRTG https://pypi.org/project/google-api-python-client/#files
I'm familiar with the process of installing packages to a Python installation via pip etc. But, it appears to use the PRTG python runtime I need to add the packages manually. How can I do this?
Article Comments
Thanks for sharing the actual answer :)
PRTGapi |
Feature Requests |
WMI Issues |
SNMP Issues
Kind regards,
Stephan Linke, Tech Support Team
Mar, 2019 - Permalink
GOOD NEWS
- I was able to download the package file(s), see links above. And they both are listed as usable by Python3.
- I was able to rename from .whl to .zip and extract to get python files.
CHALLENGES
- I copied the extracted folders/files to the ..\Python34\Lib\site-packages directory
- When I attempt to import them within python script, it "breaks" the Python Script Advanced sensor
MORE INFO ON SENSOR ERROR ISSUE CONFIG
Step 1:
To test I added a Python Script Advanced sensor and selected the sensor_example that came with installation
... Result = worked and reporting as expected
Step 2:
- Added import at beginning of script for Google API
- Downloaded .whl file from https://pypi.org/project/google-api-python-client/#files
- Renamed with .zip extension and extracted
- Copied all folders/files to \Python34\Lib\site-packages\googleapiclient
- specific example imports discovery.py file included within this directory
- added line at beginning of sensor_example.py file
- from googleapiclient.discovery import build
- note: this is the exact format used when testing successfully on locally installed Python version
- Result = sensor initially reports channels have "No data", then moves to Warning, then Error/Down status ....... Message: "XML Structural error in xml file, 2 open items. - JSON: The returned JSON does not match the expected structure (Invalid JSON.). (code: PE231)"
QUESTION
What would cause the sensor to error out by adding an import statement, yet not even calling anything from that package?
Mar, 2019 - Permalink
I think we're overthinking this. Using the following approach, I'm able to use modules just fine without the unpack stuff:
- Download https://bootstrap.pypa.io/get-pip.py into PRTGs python directory
- cd C:\Program Files (x86)\PRTG Network Monitor\python\
- python.exe get-pip.py
- cd Scripts
- pip install google-api-python-client
Then import it just like a normal module and work with it. I'm doing the same with a FINTS module in a Sensor to check the bank account :)
PRTGapi |
Feature Requests |
WMI Issues |
SNMP Issues
Kind regards,
Stephan Linke, Tech Support Team
Mar, 2019 - Permalink
And I was able to successfully install pip per the instructions provided via the KB. But, now when trying to use pip to install a module, or even do anything with python it crashes.
Now, to be fully transparent on what steps I've taken:
- Initially installed python 2.7 on the PRTG server (didn't realize there was already a custom Python env't)
- Made a hardlink to use python command anywhere
- ... cd c:\Windows
- ... mklink /H python.exe c:\python27\python.exe
- Uninstalled python 2.7
- Removed hardlink
- Made hardlinks for python and python3 to PRTG's \Python34
- C:\Windows>mklink /H python.exe "C:\Program Files (x86)\PRTG Network Monitor\Pyt hon34\python.exe"
- C:\Windows>mklink /H python3.exe "C:\Program Files (x86)\PRTG Network Monitor\Pyt hon34\python.exe"
Installed pip with following command:
- cd C:\Program Files (x86)\PRTG Network Monitor\Python34\
- python3.exe get-pip.py
- Successfully installed pip
Attempted to install module with following:
.\pip install google-api-python-client
And here is where I get the message "python.exe has stopped working"
Here is the output of message details:
Problem signature:
Problem Event Name: APPCRASH
Application Name: python.exe
Application Version: 0.0.0.0
Application Timestamp: 5432f851
Fault Module Name: python34.dll
Fault Module Version: 6.3.9600.18895
Fault Module Timestamp: 5a4b127e
Exception Code: c0000135
Exception Offset: 0009d4e2
OS Version: 6.3.9600.2.0.0.272.7
Locale ID: 1033
Additional Information 1: 1abe
Additional Information 2: 1abee00edb3fc1158f9ad6f44f0f6be8
Additional Information 3: 1abe
Additional Information 4: 1abee00edb3fc1158f9ad6f44f0f6be8
Mar, 2019 - Permalink
FIXED: Successfully able to install modules with pip now.
ACTIONS: Removed the hardlinks ... both python.exe and python3.exe (i.e. deleted these files from C:\Windows)
Recreated hardlink for python.exe only ... C:\Windows>mklink /H python.exe "C:\Program Files (x86)\PRTG Network Monitor\Pyt hon34\python.exe"
Reinstalled pip using python.exe, whereas prior installed with python3.exe ... python get-pip.py --ignore-installed
And then was able to successfully run pip to install google api module.
Mar, 2019 - Permalink
Glad to hear it's up and running now :)
PRTGapi |
Feature Requests |
WMI Issues |
SNMP Issues
Kind regards,
Stephan Linke, Tech Support Team
Mar, 2019 - Permalink
I found a solution which for me was even easier. I just use my favorite IDE (PyCharm) and create a new project when asked to choose a an interpreter I choose "C:\Program Files (x86)\PRTG Network Monitor\python\python.exe".
Now when I add a module to my project it installs this module in "C:\Program Files (x86)\PRTG Network Monitor\python\Lib\site-packages".
Nov, 2020 - Permalink
Hello Rein,
Thank you for sharing, this is indeed an easy way to install new packages :)
Kind regards.
Nov, 2020 - Permalink
I found that packages can be downloaded in .whl (wheel) format. Renaming this file with a .zip extension I was able to extract and get what I needed.
For example: https://pypi.org/project/google-api-python-client/#files https://pypi.org/project/google-auth/#files
I then was able to copy the folders into the PRTG python directory.
Mar, 2019 - Permalink