mirror of
https://github.com/sileht/bird-lg.git
synced 2024-11-26 00:34:42 +01:00
Handle error correctly
This commit is contained in:
parent
6311df95e8
commit
298b1459fa
51
lg.py
51
lg.py
|
@ -122,8 +122,10 @@ def bird_proxy(host, proto, service, query):
|
||||||
|
|
||||||
port = app.config["PROXY"].get(host, "")
|
port = app.config["PROXY"].get(host, "")
|
||||||
|
|
||||||
if not port or not path:
|
if not port:
|
||||||
return False, "Host/Proto not allowed"
|
return False, 'Host "%s" invalid' % host
|
||||||
|
elif not path:
|
||||||
|
return False, 'Proto "%s" invalid' % proto
|
||||||
else:
|
else:
|
||||||
url = "http://%s.%s:%d/%s?q=%s" % (host, app.config["DOMAIN"], port, path, quote(query))
|
url = "http://%s.%s:%d/%s?q=%s" % (host, app.config["DOMAIN"], port, path, quote(query))
|
||||||
try:
|
try:
|
||||||
|
@ -218,7 +220,15 @@ def summary(hosts, proto="ipv4"):
|
||||||
for host in hosts.split("+"):
|
for host in hosts.split("+"):
|
||||||
ret, res = bird_command(host, proto, command)
|
ret, res = bird_command(host, proto, command)
|
||||||
res = res.split("\n")
|
res = res.split("\n")
|
||||||
if len(res) > 1:
|
|
||||||
|
if ret is False:
|
||||||
|
errors.append("%s" % res)
|
||||||
|
continue
|
||||||
|
|
||||||
|
if len(res) <= 1:
|
||||||
|
errors.append("%s: bird command failed with error, %s" % (host, "\n".join(res)))
|
||||||
|
continue
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
for line in res[1:]:
|
for line in res[1:]:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
|
@ -230,8 +240,6 @@ def summary(hosts, proto="ipv4"):
|
||||||
app.logger.warning("couldn't parse: %s", line)
|
app.logger.warning("couldn't parse: %s", line)
|
||||||
|
|
||||||
summary[host] = data
|
summary[host] = data
|
||||||
else:
|
|
||||||
errors.append("%s: bird command failed with error, %s" % (host, "\n".join(res)))
|
|
||||||
|
|
||||||
return render_template('summary.html', summary=summary, command=command, errors=errors)
|
return render_template('summary.html', summary=summary, command=command, errors=errors)
|
||||||
|
|
||||||
|
@ -251,10 +259,16 @@ def detail(hosts, proto):
|
||||||
for host in hosts.split("+"):
|
for host in hosts.split("+"):
|
||||||
ret, res = bird_command(host, proto, command)
|
ret, res = bird_command(host, proto, command)
|
||||||
res = res.split("\n")
|
res = res.split("\n")
|
||||||
if len(res) > 1:
|
|
||||||
detail[host] = {"status": res[1], "description": add_links(res[2:])}
|
if ret is False:
|
||||||
else:
|
errors.append("%s" % res)
|
||||||
|
continue
|
||||||
|
|
||||||
|
if len(res) <= 1:
|
||||||
errors.append("%s: bird command failed with error, %s" % (host, "\n".join(res)))
|
errors.append("%s: bird command failed with error, %s" % (host, "\n".join(res)))
|
||||||
|
continue
|
||||||
|
|
||||||
|
detail[host] = {"status": res[1], "description": add_links(res[2:])}
|
||||||
|
|
||||||
return render_template('detail.html', detail=detail, command=command, errors=errors)
|
return render_template('detail.html', detail=detail, command=command, errors=errors)
|
||||||
|
|
||||||
|
@ -279,11 +293,17 @@ def traceroute(hosts, proto):
|
||||||
except:
|
except:
|
||||||
return error_page("%s is unresolvable or invalid for %s" % (q, proto))
|
return error_page("%s is unresolvable or invalid for %s" % (q, proto))
|
||||||
|
|
||||||
|
errors = []
|
||||||
infos = {}
|
infos = {}
|
||||||
for host in hosts.split("+"):
|
for host in hosts.split("+"):
|
||||||
status, resultat = bird_proxy(host, proto, "traceroute", q)
|
status, resultat = bird_proxy(host, proto, "traceroute", q)
|
||||||
|
if status is False:
|
||||||
|
errors.append("%s" % resultat)
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
infos[host] = add_links(resultat)
|
infos[host] = add_links(resultat)
|
||||||
return render_template('traceroute.html', infos=infos)
|
return render_template('traceroute.html', infos=infos, errors=errors)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/adv/<hosts>/<proto>")
|
@app.route("/adv/<hosts>/<proto>")
|
||||||
|
@ -563,15 +583,20 @@ def show_route(request_type, hosts, proto):
|
||||||
errors = []
|
errors = []
|
||||||
for host in hosts.split("+"):
|
for host in hosts.split("+"):
|
||||||
ret, res = bird_command(host, proto, command)
|
ret, res = bird_command(host, proto, command)
|
||||||
|
|
||||||
res = res.split("\n")
|
res = res.split("\n")
|
||||||
if len(res) > 1:
|
|
||||||
|
if ret is False:
|
||||||
|
errors.append("%s" % res)
|
||||||
|
continue
|
||||||
|
|
||||||
|
if len(res) <= 1:
|
||||||
|
errors.append("%s: bird command failed with error, %s" % (host, "\n".join(res)))
|
||||||
|
continue
|
||||||
|
|
||||||
if bgpmap:
|
if bgpmap:
|
||||||
detail[host] = build_as_tree_from_raw_bird_ouput(host, proto, res)
|
detail[host] = build_as_tree_from_raw_bird_ouput(host, proto, res)
|
||||||
else:
|
else:
|
||||||
detail[host] = add_links(res)
|
detail[host] = add_links(res)
|
||||||
else:
|
|
||||||
errors.append("%s: bird command failed with error, %s" % (host, "\n".join(res)))
|
|
||||||
|
|
||||||
if bgpmap:
|
if bgpmap:
|
||||||
detail = json.dumps(detail)
|
detail = json.dumps(detail)
|
||||||
|
|
Loading…
Reference in a new issue