• 7 December 2024

Some PRTG API samples

Get a passhash code

PRTG supports API, but we need to have a passhash code. It’s a link below that we can get a passhash for our user. Just you should adapt your PRTG.

https://my_prtg_address/api/getpasshash.htm?username?=my_user&password=my_password

It returns a code like 111222333. 111222333 is our passhash. We will use it every API requests instead of using password.

Getting all devices as JSON

If we want results are in JSON format we can call /api/table.json. Our full URL is

https://my_prtg_address/api/table.json?content=devices&output=json&columns=objid,group,device,host&username?=my_user&passhash=111222333

We can get all devices with Python script below

import requests

url = https://my_prtg_address/api/table.json?content=devices&output=json&columns=objid,group,device,host&username?=my_user&passhash=111222333

response = requests.get(url, verify=False)
devices = response.json()["devices"]
for device in devices:
 print(f"Obje ID : {device['objid']}, Device Name:{device['device']}, IP Address : {device['host']}")

Getting all sensors of a device as JSON

Now, our content is sensor and we need to give a device object id as an argument. Our URL is as below.

import requests

url = https://my_prtg_address/api/table.json?content=sensors&output=json&columns=name,type,status&filter_parentid=12345&username?=my_user&passhash=111222333

response = requests.get(url, verify=False)
devices = response.json()["sensors"]
for sensor in sensors:
 print(f"Sensor type : {sensor['type']}, Sensor Name:{sensor['name']}, Status : {sensor['status']}")

Getting all devices in all sub group in a parent group

import json
import requests

url = "https://my_prtg_address/api/table.json?content=groups&output=json&columns=objid,name&filter_parentid=12345&passhash=111222333&username=my_user"

res = requests.get(url, verify=False)
my_dict = json.loads(res.content)
groups = my_dict["groups"]

devices = []

for sub_gr in groups:
	obj_id = sub_gr["objid"]
	url = f"https://my_prtg_address/api/table.json?content=devices&output=json&columns=objid,device,host&filter_parentid={obj_id}&passhash=111222333&username=my_user"
	res = requests.get(url, verify=False)
	my_dict = json.loads(res.content)
	devices.extend(my_dict["devices"])