Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

prtg

Python module to manage PRTG servers

Prerequisites:

  • bs4 (BeautifulSoup)
  • requests
  • lxml

Tested only on Python 3.5.2 so far. Does work with python 2.7 but not extensively tested.

This is a Python module to facilitate in managing PRTG servers from CLI or for automating changes. It is really useful for scripting changes to prtg objects.

The prtg_api no longer uses a config file. Instead you need to enter your PRTG parameters when initiating the prtg_api class. This change was to allow this to be used in a more flexible way, or to manage multiple PRTG instances, you can still set up a local config file for your parameters if you wish. The parameters for initiating the prtg_api class are:

prtg_api(host,user,passhash,protocol='https',port='443',rootid=0)

Upon initialisation the entire device tree is downloaded and each probe, group, device, sensor and channel is provided as a modifiable object. From the main object (called prtg in example) you can access all objects in the tree using the prtg.allprobes, prtg.allgroups, prtg.alldevices and prtg.allsensors attributes. The channels are not available by default, you must run sensor.get_channels() to the get the child channels of that sensor.

You can also set the root of your sensor tree as a group that is not the root of PRTG. This was added to allow a partial sensortree to be downloaded where your PRTG server may have many objects or to provide access to a user with restricted permissions.

When you are accessing an object further down the tree you only have access to the direct children of that object. This for example will show the devices that are in the 4th group of the allgroups array:

from prtg import prtg_api

prtg = prtg_api('192.168.1.1','prtgadmin','0000000000')

prtg.allgroups[3].devices

Probe and group objects can have groups and devices as children, device objects have sensors as children and sensors can have channels as children.

from prtg import prtg_api

prtg = prtg_api('192.168.1.1','prtgadmin','0000000000')

probeobject = prtg.allprobes[0]
groups = probeobject.groups
devices = probeobject.devices

deviceobject = devices[0]
sensors = deviceobject.sensors

sensorobject = sensors[0]
sensorobject.get_channels()

channel = sensorobject.channels[0]

Current methods and parameters (* = required) on all objects include:

  • rename()
  • pause(duration=0,message='') (pause and resume on a channel will change the parent sensor)
  • resume()
  • clone(newname='',newplaceid='')
  • delete(confirm=True) (you can't delete the root object or channels)
  • refresh()
  • set_property(name*,value*)
  • get_property(name*)
  • set_additional_param(param*) (for custom script sensors)
  • set_interval(interval*)
  • set_host(host*) (ip address or hostname)
  • search_byid(id)
  • add_tags(['tag1','tag2']*,clear_old=False)

To come:

  • move

If you are making small changes such as pause, resume, rename; the local data will update as you go. If you are doing larger changes you should refresh the data after each change. If you refresh the main prtg object it will refresh everything otherwise you can just refresh an object further down the tree to only refresh part of the local data. To refresh an object call the .refresh() method.

The set_property method is very powerful and flexible. You can change anything for an object that you can change in the objects settings tab in the web ui. I will add the more commonly used settings as seperate methods. You can use the get_property method to test the name of the property:

from prtg import prtg_api

prtg = prtg_api('192.168.1.1','prtgadmin','0000000000')
prtg.get_property(name='location')
#returns the location and sets prtg.location to the result.

prtg.set_property(name='location',value='Canada')

There are delays with some actions such as resuming so you should add time delays where appropriate.

example usage:

import time
from prtg import prtg_api

prtg = prtg_api('192.168.1.1','prtgadmin','0000000000')

for device in prtg.alldevices:
  if device.id == "1234":
    deviceobj = device

deviceobj.pause()
deviceobj.clone(newname="cloned device",newplaceid="2468")

time.sleep(10)

prtg.refresh()

for device in prtg.alldevices:
  if device.name = "cloned device":
    device.resume()

The prtg_api class can be used with the root id set as the root group, a probe, or a group. If you wanted to manage a device or sensor and don't want to download the entire sensortree to loop through the results; you can use the prtg_device and prtg_sensor classes. For example:

host = '192.168.1.1'
port = '80'
user = 'prtgadmin'
passhash = '0000000'
protocol = 'http'
deviceid = '2025'

device = prtg_device(host,port,user,passhash,protocol,deviceid)

sensorid = '2123'

sensor = prtg_sensor(host,port,user,passhash,protocol,sensorid)

Release files for prtg 0.1.0.dev0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prtg 0.1.0.dev0
File Size Uploaded
prtg-0.1.0.dev0.tar.gz 5.0 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for prtg 0.1.0.dev0
File Interpreter ABI Platform
prtg-0.1.0.dev0-py3-none-any.whl Python 3 none any Details
prtg-0.1.0.dev0-py2-none-any.whl Python 2 none any Details

Total release size: 14.5 kB

Release files / prtg-0.1.0.dev0.tar.gz

Download URL prtg-0.1.0.dev0.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7b8ef8698e04037cc3ad422d02d91f64e6fe82274799d3b95b005405a24fa4e1
BLAKE2b-256 checksum
How to use checksums
601a52158834f1f82cbef9e1b372bb16e9b9df78342f27e2ecf8c9103decd350
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

Release files / prtg-0.1.0.dev0-py3-none-any.whl

Download URL prtg-0.1.0.dev0-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
41c76b7a7e80b96b3c9db6588576f027b8dbac095ebd74f84d753d141e3fee33
BLAKE2b-256 checksum
How to use checksums
5a77c9ed54bc19ff8413aa536add5d1031b0c6465348934f17dc9aa6a83c040f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

Release files / prtg-0.1.0.dev0-py2-none-any.whl

Download URL prtg-0.1.0.dev0-py2-none-any.whl
Size 4.8 kB
Tags Python 2
SHA-256 checksum
How to use checksums
ce91d8575f85db83b522ff0edd6f9bb59327f3e80d352bb3a3ba6e904002b60f
BLAKE2b-256 checksum
How to use checksums
3c0b1643a1d0eb09e7444063cd7c1b45bd7256dd9873794cafc1eb7434b08b48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.1.0.dev0 This release

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page