diff options
author | Jannik Schönartz | 2019-02-12 20:48:46 +0100 |
---|---|---|
committer | Jannik Schönartz | 2019-02-12 20:48:46 +0100 |
commit | 7c88f9410d6120ef7fd76047c9f3bb014aad0ca9 (patch) | |
tree | 53f0fdc15e256bc570ab262916c8c5de7060a4f5 | |
parent | Add thrift ssl support, more error handling (diff) | |
download | bwlp-monitoring-7c88f9410d6120ef7fd76047c9f3bb014aad0ca9.tar.gz bwlp-monitoring-7c88f9410d6120ef7fd76047c9f3bb014aad0ca9.tar.xz bwlp-monitoring-7c88f9410d6120ef7fd76047c9f3bb014aad0ca9.zip |
Replace timestamps in the log with unix timestamps
-rw-r--r-- | bwlp.config | 2 | ||||
-rwxr-xr-x | 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 @@ -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 += ('<div class="log_item"><div class="log_item_part time"><div class="content_item_part_title">[' - + entry.date + ']</div></div><div class="log_item_part service"><div class="content_item_part_title">[' + + parsed_date + ']</div></div><div class="log_item_part service"><div class="content_item_part_title">[' + entry.service + ']</div></div><div class="log_item_part ' + entry.state + '"><div class="content_item_part_title">[' + entry.state + ']</div></div><div class="log_item_part"><div class="content_item_part_title">[' |