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

View File

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