Rename ltsdb_report.send_report to ltsdb_record.record_observations

This commit is contained in:
Peter J. Holzer 2023-01-07 13:08:44 +01:00 committed by Peter J. Holzer
parent a83ebfcc99
commit fdf782bc2f
2 changed files with 6 additions and 6 deletions

View File

@ -7,7 +7,7 @@ import time
import requests import requests
def send_report(report): def record_observations(observations):
node = socket.gethostbyaddr(socket.gethostname())[0] node = socket.gethostbyaddr(socket.gethostname())[0]
for dir in (".", os.environ["HOME"] + "/.config/ltsdb", "/etc/ltsdb"): for dir in (".", os.environ["HOME"] + "/.config/ltsdb", "/etc/ltsdb"):
try: try:
@ -18,16 +18,16 @@ def send_report(report):
except FileNotFoundError: except FileNotFoundError:
pass pass
while True: while True:
for r in report: for obs in observations:
timestamp = time.time() timestamp = time.time()
msg = (node + " " + str(timestamp)).encode("UTF-8") msg = (node + " " + str(timestamp)).encode("UTF-8")
digest = hmac.new(client_config["key"].encode("UTF-8"), msg, "SHA256").hexdigest() digest = hmac.new(client_config["key"].encode("UTF-8"), msg, "SHA256").hexdigest()
r["auth"] = { obs["auth"] = {
"node": node, "node": node,
"timestamp": timestamp, "timestamp": timestamp,
"hmac": digest, "hmac": digest,
} }
r = requests.post(baseurl + "report", json=report) r = requests.post(baseurl + "record", json=observations)
print(r) print(r)
if r.status_code == 200: if r.status_code == 200:
return True return True

View File

@ -14,7 +14,7 @@ import urllib.parse
import requests import requests
import ltsdb_report import ltsdb_record
ap = argparse.ArgumentParser() ap = argparse.ArgumentParser()
ap.add_argument("url") ap.add_argument("url")
@ -57,6 +57,6 @@ report = [
for r in report0 for r in report0
] ]
success = ltsdb_report.send_report(report) success = ltsdb_record.record_observations(report)
exit(1 - success) exit(1 - success)