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

Groups PRTG API - Python script




So i got an assignment at work to gather data from sensors regarding fiber connections.

I have a .csv file with the list of the number of fibers i want to get SLA from.

I have written a basic python script that pulls the data from PRTG using the csv files with fiber connections/sensors i want data from. And its written to a new csv file and sent to the people that wants this information by email.

The csv file has to 4 columns; name of the fiber - Fiber number - Downtime in % - Downtime in hour/min

This script has been setup with crontab and is run each month that pulls the data from the last month.

In a meeting with some bosses, they wanted a own colum after the name of the fiber called SLA. This colum should just say SLA4 or SLA6 based on the importance of the fiber line. They are mostly interessted in SLA6 stuff, and want and easy method to sort this information.

In PRTG we have groups, but i cant find how to import this into the script. Because im not that familiar with PRTG and was just given this assignment as a one off. See at the bottom for imgurlink that shows PRTG groups.

Snippit of my script, some stuff have been hidden to hide sensitive information

class samband(object): def __init__(self, samband): self.samband = samband

def add_obj_id(self, objid): self.samband['objid'] = objid

def add_device_id(self, device): self.samband['device'] = device

requests.packages.urllib3.disable_warnings(InsecurePlatformWarning) requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

def import_csv_data(filename): data = [] with open(filename, 'r') as f: reader = csv.DictReader(f, delimiter=';') for row in reader: yield row

def get_prtg_data(samband): output = [] print "Location;Sambandsnr;Nedetid;Oppetid i prosent" for i in samband:


prtgUrl = 'HIDE' device = '@sub({0})'.format(i.samband["sambandsnr"]) payload = {'content': 'device', 'columns': 'device,objid', 'username': 'HIDE', 'passhash': 'HIDE', 'filter_device': device, 'filter_sensor': '@sub(ping)'} prtgResponse = requests.get(prtgUrl, params=payload, verify=False,timeout=10) root = etree.XML(prtgResponse.content) for item in root.iter(): if item.tag == 'objid': if item.text != '': i.add_obj_id(item.text) if item.tag =='device': if item.text != '': i.add_device_id(item.text)

prtgUrl = 'HIDE' if 'objid' in i.samband: payload = {'id': i.samband['objid'], 'sdate': '2018-02-01-00-00-00', 'edate': '2018-02-28-23-59-59', 'username': 'HIDE', 'passhash': 'HIDE'} prtgResponse = requests.get(prtgUrl, params=payload, verify=False,timeout=10) root = etree.XML(prtgResponse.content) downtime = '' uptimepercent = '' for item in root.iter(): if item.tag == 'downtime': downtime = item.text.strip() i.samband['downtime'] = downtime if item.tag == 'uptimepercent': uptimepercent = item.text.strip() i.samband['uptimepercent'] = uptimepercent print u'{};{};{};{}'.format(i.samband['device'],i.samband['sambandsnr'],downtime,uptimepercent) else: print u';{};;'.format(i.samband['sambandsnr']) i.samband['uptimepercent'] = '' i.samband['downtime'] = '' output.append(i) return output

sb = [samband(i) for i in import_csv_data("/usr/local/scripts/HIDE.csv")] output = get_prtg_data(sb)

Imgur link to show SLA groups: https://imgur.com/a/sPHpV

api prtg python

Created on Apr 4, 2018 2:40:18 PM

1 Reply



To retrieve data about groups you simply have to switch out the content from 'devices' to 'groups'

At a minimum, you only need the group name (which you can then analyze for the "SLA 6" substring. The following URL would retrieve the Object ID and Group Name of all groups in your system (substitute server address + username/passhash


While the following URL would retrieve only the groups whose name contains "SLA 6"


Created on Apr 5, 2018 5:13:48 AM

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.