Skip to main content

Python module to manage PRTG servers

Project description

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prtg-0.1.0.dev0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distributions

prtg-0.1.0.dev0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

prtg-0.1.0.dev0-py2-none-any.whl (4.8 kB view details)

Uploaded Python 2

File details

Details for the file prtg-0.1.0.dev0.tar.gz.

File metadata

  • Download URL: prtg-0.1.0.dev0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for prtg-0.1.0.dev0.tar.gz
Algorithm Hash digest
SHA256 7b8ef8698e04037cc3ad422d02d91f64e6fe82274799d3b95b005405a24fa4e1
MD5 3a44c497b78022d6eb3f7201ef2cd066
BLAKE2b-256 601a52158834f1f82cbef9e1b372bb16e9b9df78342f27e2ecf8c9103decd350

See more details on using hashes here.

File details

Details for the file prtg-0.1.0.dev0-py3-none-any.whl.

File metadata

  • Download URL: prtg-0.1.0.dev0-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for prtg-0.1.0.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 41c76b7a7e80b96b3c9db6588576f027b8dbac095ebd74f84d753d141e3fee33
MD5 271c9ab90b30e211162e82c71f4a7f35
BLAKE2b-256 5a77c9ed54bc19ff8413aa536add5d1031b0c6465348934f17dc9aa6a83c040f

See more details on using hashes here.

File details

Details for the file prtg-0.1.0.dev0-py2-none-any.whl.

File metadata

  • Download URL: prtg-0.1.0.dev0-py2-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 2
  • Uploaded using 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

File hashes

Hashes for prtg-0.1.0.dev0-py2-none-any.whl
Algorithm Hash digest
SHA256 ce91d8575f85db83b522ff0edd6f9bb59327f3e80d352bb3a3ba6e904002b60f
MD5 486e2cd7e550e3feb77a7e0c5e269ec3
BLAKE2b-256 3c0b1643a1d0eb09e7444063cd7c1b45bd7256dd9873794cafc1eb7434b08b48

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page