Fetching and parsing backuppc host summary with Python

#!/usr/bin/python
import requests, pprint, pandas  # pip install pandas

url = 'http://backuppc.mycompany.com/backuppc/index.cgi?action=summary'
username = '<USERNAME>';
password = '<PASSWORD>';

def fetchSummary(url, username, password):
    response = requests.get(url, auth = requests.auth.HTTPBasicAuth(username, password))
    tables = pandas.read_html(response.content)

    hosts = {}

    for i,host in enumerate(tables[0][0]):
        if not i == 0:
            hosts.update({
                    host : {
                            'hostname'              : host,
                            'user'                  : tables[0][1][i],
                            'fullBackups'           : tables[0][2][i],
                            'lastFullAge'           : tables[0][3][i],
                            'lastFullSize'          : tables[0][4][i],
                            'lastFullSpeed'         : tables[0][5][i],
                            'incrementalBackups'    : tables[0][6][i],
                            'lastIncrementalAge'    : tables[0][7][i],
                            'lastBackup'            : tables[0][8][i],
                            'state'                 : tables[0][9][i],
                            'xferErrors'            : tables[0][10][i],
                            'lastAttempt'           : tables[0][11][i]
                        }
                })
    return hosts


pprint.pprint(fetchSummary(url, username, password))

Dette indlæg blev udgivet i Backuppc, Python. Bogmærk permalinket.