From 7c88f9410d6120ef7fd76047c9f3bb014aad0ca9 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Tue, 12 Feb 2019 20:48:46 +0100 Subject: Replace timestamps in the log with unix timestamps --- bwlp.config | 2 +- main.py | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/bwlp.config b/bwlp.config index 9a9ce84..af5a214 100644 --- a/bwlp.config +++ b/bwlp.config @@ -12,7 +12,7 @@ ping Backup fileserver Ping bwlp-backup.ruf.uni-freiburg.de ping Ping Fail 0.0.0.1 thrift Thrift SAT 132.230.8.192 9090 SAT thrift Thrift MASTER 132.230.4.16 9090 MASTER -thrift Thrift Timeout 132.230.4.16 9092 MASTER +# thrift Thrift Timeout 132.230.4.16 9092 MASTER thrift Thrift SSL test 132.230.4.16 9091 MASTER ssl/CA.pem ssl/client.crt ssl/client.key ping BAS Ping bas.intra.uni-freiburg.de ping yc 127.0.0.2 diff --git a/main.py b/main.py index 48c21da..4811db2 100755 --- a/main.py +++ b/main.py @@ -1,15 +1,16 @@ #!/usr/bin/python3 +import datetime +import logging +import os +import shutil import subprocess -import urllib.request -import urllib.error +import tftpy import thriftpy from thriftpy.rpc import make_client from thriftpy.transport import TFramedTransportFactory -import shutil -import datetime -import os -import tftpy -import logging +import time +import urllib.error +import urllib.request # Global variables statusList = [] @@ -185,7 +186,8 @@ def getLogEntry(status): def logStatus(status): obj = getLogEntry(status) if (obj is None) or (status.state != obj.state): - date = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + # Save unix timestamps + date = str(int(time.time())) logEntries.append(LogEntry(date, status.service, status.state, status.host, status.msg, status.data)) # Reads the config and executes the calls. @@ -233,7 +235,7 @@ for status in statusList: # Prepare and calculate the time since the server is online / offline obj = getLogEntry(status) now = datetime.datetime.now() - date = datetime.datetime.strptime(obj.date, '%Y-%m-%d %H:%M:%S') + date = datetime.datetime.fromtimestamp(int(obj.date)) time = now - date days = time.days hours = time.seconds // 3600 @@ -262,8 +264,9 @@ cut_amount = 0 if len(logEntries) >= n: cut_amount = len(logEntries) - n for entry in reversed(logEntries[cut_amount:]): + parsed_date = datetime.datetime.fromtimestamp(int(entry.date)).strftime('%Y-%m-%d %H:%M:%S') log += ('
[' - + entry.date + ']
[' + + parsed_date + ']
[' + entry.service + ']
[' + entry.state + ']
[' -- cgit v1.2.3-55-g7522