diff options
author | Lukas Metzger | 2020-06-11 16:52:33 +0200 |
---|---|---|
committer | Lukas Metzger | 2020-06-11 16:52:33 +0200 |
commit | 5239b63f45cb5d8b175c263d0a25d0d70aa652bd (patch) | |
tree | ebc617fc4cb15afd4e28b5a3642c86511a1f961c /import | |
parent | Added total aggregation (diff) | |
download | bwlp-statistics-5239b63f45cb5d8b175c263d0a25d0d70aa652bd.tar.gz bwlp-statistics-5239b63f45cb5d8b175c263d0a25d0d70aa652bd.tar.xz bwlp-statistics-5239b63f45cb5d8b175c263d0a25d0d70aa652bd.zip |
Fixed import for old and broken formats
Diffstat (limited to 'import')
-rw-r--r-- | import/import.py | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/import/import.py b/import/import.py index 542637d..1e29451 100644 --- a/import/import.py +++ b/import/import.py @@ -29,7 +29,7 @@ try: cursor.execute('INSERT INTO reports(date,ip,version) VALUES(%s, %s, %s)',( date, ip, - data['version'] + data.get('version', 'Unknown') )) except pymysql.err.IntegrityError: print('Report is already in database!') @@ -38,16 +38,17 @@ cursor.execute('SELECT LAST_INSERT_ID() as id') reportId = cursor.fetchone()['id'] # Add server information to database -cursor.execute('INSERT INTO server(report, cpuCount, cpuModel, uptime, memTotal, memFree, swapTotal, swapUsed) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)',( - reportId, - data['server']['cpuCount'], - data['server']['cpuModel'], - data['server']['uptime'], - data['server']['memTotal'], - data['server']['memFree'], - data['server']['swapTotal'], - data['server']['swapUsed'] - )) +if 'server' in data: + cursor.execute('INSERT INTO server(report, cpuCount, cpuModel, uptime, memTotal, memFree, swapTotal, swapUsed) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)',( + reportId, + data['server']['cpuCount'], + data['server']['cpuModel'], + data['server']['uptime'], + data['server']['memTotal'], + data['server']['memFree'], + data['server']['swapTotal'], + data['server']['swapUsed'] + )) # Loop timeframes for i in [7, 30, 90]: @@ -110,22 +111,23 @@ for i in [7, 30, 90]: )) # Add dozmode - cursor.execute("""INSERT INTO dozmod(report, days, vms_total, vms_new, vms_updated, vms_valid, lectures_total, - lectures_new, lectures_updated, lectures_valid, users_total, users_organizations) - VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""",( - reportId, - i, - default(data[iStr]['dozmod']['vms']['total'], 0), - default(data[iStr]['dozmod']['vms']['new'], 0), - default(data[iStr]['dozmod']['vms']['updated'], 0), - default(data[iStr]['dozmod']['vms']['valid'], 0), - default(data[iStr]['dozmod']['lectures']['total'], 0), - default(data[iStr]['dozmod']['lectures']['new'], 0), - default(data[iStr]['dozmod']['lectures']['updated'], 0), - default(data[iStr]['dozmod']['lectures']['valid'], 0), - default(data[iStr]['dozmod']['users']['total'], 0), - default(data[iStr]['dozmod']['users']['organizations'], 0) - )) + if data[iStr]['dozmod'].get('disabled', False) != True: + cursor.execute("""INSERT INTO dozmod(report, days, vms_total, vms_new, vms_updated, vms_valid, lectures_total, + lectures_new, lectures_updated, lectures_valid, users_total, users_organizations) + VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""",( + reportId, + i, + default(data[iStr]['dozmod']['vms']['total'], 0), + default(data[iStr]['dozmod']['vms']['new'], 0), + default(data[iStr]['dozmod']['vms']['updated'], 0), + default(data[iStr]['dozmod']['vms']['valid'], 0), + default(data[iStr]['dozmod']['lectures']['total'], 0), + default(data[iStr]['dozmod']['lectures']['new'], 0), + default(data[iStr]['dozmod']['lectures']['updated'], 0), + default(data[iStr]['dozmod']['lectures']['valid'], 0), + default(data[iStr]['dozmod']['users']['total'], 0), + default(data[iStr]['dozmod']['users']['organizations'], 0) + )) # Add machines for item in data[iStr]['machines']['location']: |