Use config data for probe, fixup errors.
This commit is contained in:
parent
cd7de07460
commit
bc403b7c8b
|
@ -26,32 +26,38 @@ def api_login(config):
|
|||
"password": config["api_user_password"],
|
||||
},
|
||||
)
|
||||
logged.append(True)
|
||||
|
||||
if login_r.ok:
|
||||
logged.append(session)
|
||||
logger.info("Logged")
|
||||
else: # pragma: no cover
|
||||
logger.info("Login error")
|
||||
err = f'{login_r.reason}: {login_r.text} for "{config["api_user_login"]}" on "{config["api_login_url"]}'
|
||||
logger.info("Login error {err}")
|
||||
raise ValueError(err)
|
||||
|
||||
return login_r
|
||||
|
||||
|
||||
def api_fetch(config):
|
||||
def api_fetch(conf):
|
||||
breakpoint()
|
||||
if not logged:
|
||||
api_login()
|
||||
api_login(conf)
|
||||
apiurl = conf['api_status_url']
|
||||
fetched = session.get("%s/status" % apiurl)
|
||||
return fetched
|
||||
|
||||
|
||||
def api_forward(config):
|
||||
post_url = ""
|
||||
assert post_url
|
||||
for post_url in forward_urls:
|
||||
res = session.post(post_url, json=data)
|
||||
print(res.ok)
|
||||
print(res.json())
|
||||
def api_forward(config, data):
|
||||
post_url = f'{config["forward_api_address"]}/sonde/conf{"identifiant_sonde"}'
|
||||
breakpoint()
|
||||
res = session.post(post_url, json=data)
|
||||
print(res.ok)
|
||||
print(res.json())
|
||||
return res
|
||||
|
||||
|
||||
def forward_api_error(message=""):
|
||||
def forward_api_error(conf,message=""):
|
||||
breakpoint()
|
||||
forward_urls = [
|
||||
# "https://papi.silib.re/sonde/test/error/",
|
||||
"http://localhost:8000/sonde/838266b2-fc3a-4430-95e8-f7f0d0fc9871/error/",
|
||||
|
@ -78,17 +84,20 @@ def main(
|
|||
pattern="relais_*"
|
||||
):
|
||||
loopcount = itertools.count().__next__
|
||||
config = read_config(kind="relais", pattern=pattern)
|
||||
assert len(config) == 1
|
||||
config = config[0]
|
||||
login(config)
|
||||
conf = config.read_config(kind="relais", pattern=pattern)
|
||||
assert len(conf) == 1
|
||||
conf = conf[0]
|
||||
try:
|
||||
login(conf)
|
||||
except Exception as E:
|
||||
forward_error(conf,str(E))
|
||||
while loopcount() < maxloop:
|
||||
try:
|
||||
current = fetch(config).json()
|
||||
current = fetch(conf).json()
|
||||
except Exception as E:
|
||||
forward_error(str(E))
|
||||
forward_error(conf,str(E))
|
||||
else:
|
||||
forward(current)
|
||||
forward(confconf,current)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in New Issue