Use ltsdb_record.record_observations

This commit is contained in:
Peter J. Holzer 2023-09-20 11:00:39 +02:00
parent 1a0ccb22b7
commit ad04443928
1 changed files with 3 additions and 36 deletions

View File

@ -1,14 +1,11 @@
#!/usr/bin/python3
import argparse
import hmac
import json
import os
import socket
import ssl
import time
import requests
import ltsdb_record
ap = argparse.ArgumentParser()
ap.add_argument("--verbose", action="store_true")
@ -16,9 +13,6 @@ ap.add_argument("hostname")
ap.add_argument("port", type=int, default=443, nargs="?")
args = ap.parse_args()
# It's a bit weird that this works.
myhostname = socket.gethostbyaddr(socket.gethostname())[0]
now = time.time()
report0 = []
@ -49,32 +43,5 @@ report = [
for r in report0
]
for dir in (".", os.environ["HOME"] + "/.config/ltsdb", "/etc/ltsdb"):
try:
with open(dir + "/config.json") as fh:
client_config = json.load(fh)
baseurl = client_config["server"]
break
except FileNotFoundError:
pass
while True:
for r in report:
node = myhostname
timestamp = time.time()
msg = (node + " " + str(timestamp)).encode("UTF-8")
digest = hmac.new(client_config["key"].encode("UTF-8"), msg, "SHA256").hexdigest()
r["auth"] = {
"node": node,
"timestamp": timestamp,
"hmac": digest,
}
#pprint.pp(report)
r = requests.post(baseurl + "report", json=report)
print(r)
if r.status_code == 200:
exit(0)
elif r.status_code == 409:
time.sleep(0.5 + random.random())
continue
else:
exit(1)
success = ltsdb_record.record_observations(report)
exit(1 - success)