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

Add Python Modules

Votes:

0

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://kb.paessler.com/en/topic/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?

google-analytics prtg python python-script-advanced-sensor

Created on Mar 19, 2019 6:39:29 PM



Best Answer

Accepted Answer

Votes:

3

I think we're overthinking this. Using the following approach, I'm able to use modules just fine without the unpack stuff:

  1. Download https://bootstrap.pypa.io/get-pip.py into PRTGs python directory
  2. cd C:\Program Files (x86)\PRTG Network Monitor\python\
  3. python.exe get-pip.py
  4. cd Scripts
  5. 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

Created on Mar 21, 2019 8:41:00 AM by  Stephan Linke [Paessler Support]

Last change on Jul 30, 2020 1:06:48 PM by  Dariusz Gorka [Paessler Support]



9 Replies

Votes:

1

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.

Created on Mar 19, 2019 8:42:51 PM



Votes:

0

Thanks for sharing the actual answer :)


PRTGapi | Feature Requests | WMI Issues | SNMP Issues

Kind regards,
Stephan Linke, Tech Support Team

Created on Mar 20, 2019 8:21:48 AM by  Stephan Linke [Paessler Support]



Votes:

0

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:

  1. Added import at beginning of script for Google API
  2. Downloaded .whl file from https://pypi.org/project/google-api-python-client/#files
  3. Renamed with .zip extension and extracted
  4. Copied all folders/files to \Python34\Lib\site-packages\googleapiclient
  5. specific example imports discovery.py file included within this directory
  6. added line at beginning of sensor_example.py file
  7. from googleapiclient.discovery import build
  8. note: this is the exact format used when testing successfully on locally installed Python version
  9. 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?

Created on Mar 20, 2019 9:22:27 PM

Last change on Mar 21, 2019 8:31:22 AM by  Stephan Linke [Paessler Support]



Accepted Answer

Votes:

3

I think we're overthinking this. Using the following approach, I'm able to use modules just fine without the unpack stuff:

  1. Download https://bootstrap.pypa.io/get-pip.py into PRTGs python directory
  2. cd C:\Program Files (x86)\PRTG Network Monitor\python\
  3. python.exe get-pip.py
  4. cd Scripts
  5. 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

Created on Mar 21, 2019 8:41:00 AM by  Stephan Linke [Paessler Support]

Last change on Jul 30, 2020 1:06:48 PM by  Dariusz Gorka [Paessler Support]



Votes:

0

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:

  1. Initially installed python 2.7 on the PRTG server (didn't realize there was already a custom Python env't)
  2. Made a hardlink to use python command anywhere
  3. ... cd c:\Windows
  4. ... mklink /H python.exe c:\python27\python.exe
  5. Uninstalled python 2.7
  6. Removed hardlink
  1. Made hardlinks for python and python3 to PRTG's \Python34
    1. C:\Windows>mklink /H python.exe "C:\Program Files (x86)\PRTG Network Monitor\Pyt hon34\python.exe"
    2. C:\Windows>mklink /H python3.exe "C:\Program Files (x86)\PRTG Network Monitor\Pyt hon34\python.exe"

Installed pip with following command:

  1. cd C:\Program Files (x86)\PRTG Network Monitor\Python34\
  2. python3.exe get-pip.py
  3. 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

Created on Mar 21, 2019 9:38:57 PM

Last change on Mar 22, 2019 7:05:32 AM by  Stephan Linke [Paessler Support]



Votes:

1

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.

Created on Mar 21, 2019 10:51:28 PM



Votes:

0

Glad to hear it's up and running now :)


PRTGapi | Feature Requests | WMI Issues | SNMP Issues

Kind regards,
Stephan Linke, Tech Support Team

Created on Mar 22, 2019 7:06:24 AM by  Stephan Linke [Paessler Support]



Votes:

0

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".

Created on Nov 18, 2020 11:46:00 AM



Votes:

0

Hello Rein,

Thank you for sharing, this is indeed an easy way to install new packages :)

Kind regards.

Created on Nov 18, 2020 2:25:58 PM by  Florian Lesage [Paessler Support]

Last change on Nov 18, 2020 2:26:20 PM by  Florian Lesage [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.