Update app.py
This commit is contained in:
parent
adcce69cdf
commit
65d3f839e6
1 changed files with 30 additions and 12 deletions
42
app.py
42
app.py
|
|
@ -8,28 +8,17 @@ from flask import Flask, render_template_string, jsonify, url_for, redirect, ren
|
|||
|
||||
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, run_rpki_cache_connection_curl_command, run_rpki_lookup_curl_command, run_bgp_neighbor_detail_curl_command, run_bfd_peers_curl_command, run_bfd_peer_detail_curl_command, run_bgp_dampeningv4_curl_command, run_bgp_dampeningv6_curl_command,run_firewall_ipv4_curl_command, run_firewall_ipv6_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, run_bgp_neighbor_detail_curl_command, run_bfd_peers_curl_command, run_bfd_peer_detail_curl_command, run_bgp_dampeningv4_curl_command, run_bgp_dampeningv6_curl_command,run_firewall_ipv4_curl_command, run_firewall_ipv6_curl_command, run_bgp_reset_command, run_bgp_shutdown_command, run_bgp_enable_command
|
||||
from modules.bgp import parse_bgp_data, generate_bgp_json
|
||||
|
||||
from modules.arp import parse_arp_data, generate_arp_json
|
||||
|
||||
from modules.neighbors import parse_neighbors_data, generate_neighbors_json
|
||||
|
||||
from modules.interfaces import parse_interface_data
|
||||
|
||||
from modules.akvorado import get_widget_data
|
||||
|
||||
from modules.librenms import get_port_id, fetch_graph_base64
|
||||
|
||||
from modules.rpki import parse_rpki_cache_data, parse_rpki_lookup_data
|
||||
|
||||
from modules.bfd import parse_bfd_peers_data
|
||||
|
||||
from modules.bgp_dampening import parse_dampened_data, generate_dampened_json
|
||||
|
||||
from modules.firewall import parse_firewall_data
|
||||
|
||||
from modules.visual_route import generate_visual_route_graph
|
||||
|
||||
@app.context_processor
|
||||
|
|
@ -65,6 +54,35 @@ def bgp_json():
|
|||
|
||||
return jsonify(generate_bgp_json(ipv4_info, ipv4_peers, ipv6_info, ipv6_peers, bfd_peers))
|
||||
|
||||
@app.route('/bgp/action', methods=['POST'])
|
||||
def bgp_action():
|
||||
data = request.json
|
||||
action = data.get('action')
|
||||
neighbor_ip = data.get('neighbor_ip')
|
||||
|
||||
if not action or not neighbor_ip:
|
||||
return jsonify({"success": False, "error": "Missing action or neighbor_ip"}), 400
|
||||
|
||||
try:
|
||||
if action == 'hard_reset':
|
||||
result = run_bgp_reset_command(neighbor_ip, soft=False)
|
||||
elif action == 'soft_reset':
|
||||
result = run_bgp_reset_command(neighbor_ip, soft=True)
|
||||
elif action == 'shutdown':
|
||||
result = run_bgp_shutdown_command(neighbor_ip)
|
||||
elif action == 'enable':
|
||||
result = run_bgp_enable_command(neighbor_ip)
|
||||
else:
|
||||
return jsonify({"success": False, "error": "Invalid action"}), 400
|
||||
|
||||
if result.get("success"):
|
||||
return jsonify({"success": True, "message": f"Action '{action}' for neighbor {neighbor_ip} successful.", "details": result.get("data")})
|
||||
else:
|
||||
return jsonify({"success": False, "error": f"Action '{action}' failed.", "details": result.get("error")}), 500
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({"success": False, "error": str(e)}), 500
|
||||
|
||||
@app.route("/bgp/dampened")
|
||||
def bgp_dampened_page():
|
||||
return render_template("bgp_dampened.html")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue