summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--import/import.py56
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']: