diff --git a/htdocs/index.php b/htdocs/index.php index 285f1f1..a0f3017 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -261,6 +261,7 @@ function load() { ( 'bgp' => 'display bgp routing-table %s', 'advertised-routes' => 'display bgp routing-table peer %s advertised-routes', + 'bgp-within' => 'display bgp routing-table community | include %s', 'received-routes' => 'display bgp routing-table peer %s received-routes', 'routes' => 'display bgp routing-table peer %s received-routes active', 'summary' => 'display bgp peer', @@ -370,6 +371,8 @@ function load() { $url = @parse_url($url); + $routing_instance = $_CONFIG['routers'][$router]['routing-instance']; + $os = $_CONFIG['routers'][$router]['os']; if ($command == 'graph' AND isset($queries[$os][$protocol]['bgp'])) @@ -445,39 +448,47 @@ function load() { if ($os == 'junos') { // @see JunOS Routing Table Names (http://www.net-gyver.com/?p=602) - $table = ($protocol == 'ipv6') ? 'inet6.0' : 'inet.0'; + if ($routing_instance){ + $table = ($protocol == 'ipv6') ? $routing_instance.'.inet6.0' : $routing_instance.'.inet.0'; + }else{ + $table = ($protocol == 'ipv6') ? 'inet6.0' : 'inet.0'; + } if (preg_match("/^show bgp n\w*\s+([\d\.A-Fa-f:]+)$/", $exec, $exec_exp)) { - $exec = 'show bgp neighbor '.$exec_exp[1]; + if ($routing_instance){ + $exec = 'show bgp neighbor instance '.$routing_instance.' '.$exec_exp[1]; + }else{ + $exec = 'show bgp neighbor '.$exec_exp[1]; + } } else if (preg_match("/^show bgp n\w*\s+([\d\.A-Fa-f:]+) ro\w*$/", $exec, $exec_exp)) { - $exec = 'show route receive-protocol bgp '.$exec_exp[1]; + $exec = 'show route receive-protocol bgp '.$exec_exp[1]." table ".$table; } else if (preg_match("/^show bgp neighbors ([\d\.A-Fa-f:]+) routes all$/", $exec, $exec_exp)) { - $exec = 'show route receive-protocol bgp '.$exec_exp[1].' all'; + $exec = 'show route receive-protocol bgp '.$exec_exp[1].' table '.$table.' all'; } else if (preg_match("/^show bgp neighbors ([\d\.A-Fa-f:]+) routes damping suppressed$/", $exec, $exec_exp)) { - $exec = 'show route receive-protocol bgp '.$exec_exp[1].' damping suppressed'; + $exec = 'show route receive-protocol bgp '.$exec_exp[1].' table '.$table.' damping suppressed'; } else if (preg_match("/^show bgp n\w*\s+([\d\.A-Fa-f:]+) advertised-routes ([\d\.A-Fa-f:\/]+)$/", $exec, $exec_exp)) { - $exec = 'show route advertising-protocol bgp '.$exec_exp[1].' '.$exec_exp[2].' exact detail'; + $exec = 'show route advertising-protocol bgp '.$exec_exp[1].' '.$exec_exp[2].' table '.$table.' exact detail'; } else if (preg_match("/^show bgp n\w*\s+([\d\.A-Fa-f:]+) receive-protocol ([\d\.A-Fa-f:\/]+)$/", $exec, $exec_exp)) { - $exec = 'show route receive-protocol bgp '.$exec_exp[1].' '.$exec_exp[2].' exact detail'; + $exec = 'show route receive-protocol bgp '.$exec_exp[1].' '.$exec_exp[2].' table '.$table.' exact detail'; } else if (preg_match("/^show bgp n\w*\s+([\d\.A-Fa-f:]+) a[\w\-]*$/", $exec, $exec_exp)) { - $exec = 'show route advertising-protocol bgp '.$exec_exp[1]; + $exec = 'show route advertising-protocol bgp '.$exec_exp[1].' table '.$table; } else if (preg_match("/^show bgp\s+([\d\.A-Fa-f:]+\/\d+)$/", $exec, $exec_exp)) { - $exec = 'show route protocol bgp '.$exec_exp[1].' terse exact'; + $exec = 'show route protocol bgp '.$exec_exp[1].' table '.$table.' terse exact'; } else if (preg_match("/^show bgp\s+([\d\.A-Fa-f:]+)$/", $exec, $exec_exp)) { @@ -485,7 +496,7 @@ function load() { } else if (preg_match("/^show bgp\s+([\d\.A-Fa-f:\/]+) exact$/", $exec, $exec_exp)) { - $exec = 'show route protocol bgp '.$exec_exp[1].' exact detail all'; + $exec = 'show route protocol bgp '.$exec_exp[1].' table '.$table.' exact detail all'; } else if (preg_match("/^show bgp re\s+(.*)$/", $exec, $exec_exp)) { @@ -501,8 +512,33 @@ function load() { $re = $re.".*\$"; } - $exec = 'show route aspath-regex "'.str_replace('_', ' ', $re).'" all'; + if ($routing_instance){ + $exec = 'show route instance '.$routing_instance.' aspath-regex "'.str_replace('_', ' ', $re).'" all'; + }else{ + $exec = 'show route aspath-regex "'.str_replace('_', ' ', $re).'" all'; + } + } + else if (preg_match("/^show bgp summary$/", $exec, $exec_exp)) + { + if ($routing_instance){ + $exec = 'show bgp summary instance '.$routing_instance; + }else{ + $exec = 'show bgp summary'; + } } + else if (preg_match("/^show route advertising-protocol bgp\s+([\d\.A-Fa-f:\/]+)$/", $exec, $exec_exp)) + { + $exec = 'show route advertising-protocol bgp '.$exec_exp[1].' table '.$table; + } + else if (preg_match("/^traceroute (ip|ipv6) ([\d\.A-Fa-f:\/]+)$/", $exec, $exec_exp)) + { + if ($routing_instance){ + $exec = 'traceroute '.$exec_exp[1].' routing-instance '.$routing_instance.' '.$exec_exp[2]; + }else{ + $exec = 'traceroute '.$exec_exp[1].' '.$exec_exp[2]; + } + } + } if ($command == 'graph') @@ -1489,7 +1525,7 @@ function ($matches) use ($lastip) { return $output; } - if ($exec == 'show bgp summary') + if (preg_match("/^show bgp summary(?:\s+instance\s+[\d\w-]*)?$/", $exec)) { // JunOS if (preg_match("/^([\dA-Fa-f:][\d\.A-Fa-f:]+)\s+/", $output, $lastip_exp)) @@ -1655,7 +1691,7 @@ function ($matches) { } // JunOS - if (preg_match("/^show route advertising-protocol bgp\s+([\d\.A-Fa-f:]+)$/i", $exec, $ip_exp)) + if (preg_match("/^show route advertising-protocol bgp\s+([\d\.A-Fa-f:]+)(?:\s+table\s+[\d\w\-\.]*)?$/i", $exec, $ip_exp)) { $ip = $ip_exp[1]; @@ -1862,7 +1898,7 @@ function ($matches) { return $output; } - if (preg_match("/^show bgp n\w*\s+([\d\.A-Fa-f:]+)/i", $exec, $ip_exp)) + if (preg_match("/^show bgp n\w*\s+(?:instance\s+[\d\w-]*)?\s*([\d\.A-Fa-f:]+)/i", $exec, $ip_exp)) { $ip = $ip_exp[1];