Skip to content

Commit

Permalink
Merge pull request hsdn#41 from mirackle-spb/master
Browse files Browse the repository at this point in the history
routing-instance selection for juniper routers
  • Loading branch information
justkeepquiet authored Oct 19, 2022
2 parents c6d980a + dd11b6e commit e4d84d3
Showing 1 changed file with 49 additions and 14 deletions.
63 changes: 49 additions & 14 deletions htdocs/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,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']))
Expand Down Expand Up @@ -378,47 +380,55 @@ 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))
{
$exec = 'show route protocol bgp '.$exec_exp[1].' table '.$table;
}
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))
{
Expand All @@ -434,8 +444,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')
Expand Down Expand Up @@ -1387,7 +1422,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))
Expand Down Expand Up @@ -1553,7 +1588,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];

Expand Down Expand Up @@ -1760,7 +1795,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];

Expand Down

0 comments on commit e4d84d3

Please sign in to comment.