Update app.py
This commit is contained in:
parent
3088272cdb
commit
3fbc331c23
1 changed files with 39 additions and 1 deletions
40
app.py
40
app.py
|
|
@ -2,12 +2,13 @@ import json
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
|
import re
|
||||||
from jinja2 import Template
|
from jinja2 import Template
|
||||||
from flask import Flask, render_template_string, jsonify, url_for, redirect, render_template, request, abort
|
from flask import Flask, render_template_string, jsonify, url_for, redirect, render_template, request, abort
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
from modules.parse import run_bgp_curl_command, run_arp_curl_command, run_neighbors_curl_command, run_interfaces_curl_command, run_bgp_route_curl_command
|
from modules.parse import run_bgp_curl_command, run_arp_curl_command, run_neighbors_curl_command, run_interfaces_curl_command, run_bgp_route_curl_command, run_rpki_cache_connection_curl_command, run_rpki_lookup_curl_command
|
||||||
|
|
||||||
from modules.bgp import parse_bgp_data, generate_bgp_json
|
from modules.bgp import parse_bgp_data, generate_bgp_json
|
||||||
|
|
||||||
|
|
@ -21,6 +22,8 @@ from modules.akvorado import get_widget_data
|
||||||
|
|
||||||
from modules.librenms import get_port_id, fetch_graph_base64
|
from modules.librenms import get_port_id, fetch_graph_base64
|
||||||
|
|
||||||
|
from modules.rpki import parse_rpki_cache_data, parse_rpki_lookup_data
|
||||||
|
|
||||||
from modules.visual_route import generate_visual_route_graph
|
from modules.visual_route import generate_visual_route_graph
|
||||||
|
|
||||||
@app.context_processor
|
@app.context_processor
|
||||||
|
|
@ -101,6 +104,41 @@ def bgp_route_lookup():
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({"error": str(e)}), 500
|
return jsonify({"error": str(e)}), 500
|
||||||
|
|
||||||
|
@app.route('/rpki')
|
||||||
|
def rpki_page():
|
||||||
|
return render_template("rpki.html")
|
||||||
|
|
||||||
|
@app.route('/rpki/status')
|
||||||
|
def rpki_status():
|
||||||
|
try:
|
||||||
|
raw_result = run_rpki_cache_connection_curl_command()
|
||||||
|
parsed_data = parse_rpki_cache_data(raw_result)
|
||||||
|
return jsonify(parsed_data)
|
||||||
|
except Exception as e:
|
||||||
|
return jsonify({"error": str(e)}), 500
|
||||||
|
|
||||||
|
@app.route('/rpki/lookup', methods=['POST'])
|
||||||
|
def rpki_lookup():
|
||||||
|
data = request.json
|
||||||
|
query = data.get('query')
|
||||||
|
|
||||||
|
if not query:
|
||||||
|
return jsonify({"error": "Query is required"}), 400
|
||||||
|
|
||||||
|
try:
|
||||||
|
if re.match(r'^\d+$', query):
|
||||||
|
result = run_rpki_lookup_curl_command("as-number", query)
|
||||||
|
elif '/' in query:
|
||||||
|
result = run_rpki_lookup_curl_command("prefix", query)
|
||||||
|
else:
|
||||||
|
return jsonify({"error": "Invalid query format. Use AS number or prefix."}), 400
|
||||||
|
|
||||||
|
parsed_result = parse_rpki_lookup_data(result)
|
||||||
|
return jsonify(parsed_result)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
return jsonify({"error": str(e)}), 500
|
||||||
|
|
||||||
@app.route('/stats')
|
@app.route('/stats')
|
||||||
def stats_page():
|
def stats_page():
|
||||||
interface_name = os.getenv("LIBRENMS_MAIN_PORT", "dummy")
|
interface_name = os.getenv("LIBRENMS_MAIN_PORT", "dummy")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue