Hi,
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:
(HERE I PULL OBJID ETC)
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
Add comment