@@ -303,6 +303,8 @@ function load() {
303303
304304 $ url = @parse_url ($ url );
305305
306+ $ routing_instance = $ _CONFIG ['routers ' ][$ router ]['routing-instance ' ];
307+
306308 $ os = $ _CONFIG ['routers ' ][$ router ]['os ' ];
307309
308310 if ($ command == 'graph ' AND isset ($ queries [$ os ][$ protocol ]['bgp ' ]))
@@ -378,47 +380,55 @@ function load() {
378380 if ($ os == 'junos ' )
379381 {
380382 // @see JunOS Routing Table Names (http://www.net-gyver.com/?p=602)
381- $ table = ($ protocol == 'ipv6 ' ) ? 'inet6.0 ' : 'inet.0 ' ;
383+ if ($ routing_instance ){
384+ $ table = ($ protocol == 'ipv6 ' ) ? $ routing_instance .'.inet6.0 ' : $ routing_instance .'.inet.0 ' ;
385+ }else {
386+ $ table = ($ protocol == 'ipv6 ' ) ? 'inet6.0 ' : 'inet.0 ' ;
387+ }
382388
383389 if (preg_match ("/^show bgp n\w*\s+([\d\.A-Fa-f:]+)$/ " , $ exec , $ exec_exp ))
384390 {
385- $ exec = 'show bgp neighbor ' .$ exec_exp [1 ];
391+ if ($ routing_instance ){
392+ $ exec = 'show bgp neighbor instance ' .$ routing_instance .' ' .$ exec_exp [1 ];
393+ }else {
394+ $ exec = 'show bgp neighbor ' .$ exec_exp [1 ];
395+ }
386396 }
387397 else if (preg_match ("/^show bgp n\w*\s+([\d\.A-Fa-f:]+) ro\w*$/ " , $ exec , $ exec_exp ))
388398 {
389- $ exec = 'show route receive-protocol bgp ' .$ exec_exp [1 ];
399+ $ exec = 'show route receive-protocol bgp ' .$ exec_exp [1 ]. " table " . $ table ;
390400 }
391401 else if (preg_match ("/^show bgp neighbors ([\d\.A-Fa-f:]+) routes all$/ " , $ exec , $ exec_exp ))
392402 {
393- $ exec = 'show route receive-protocol bgp ' .$ exec_exp [1 ].' all ' ;
403+ $ exec = 'show route receive-protocol bgp ' .$ exec_exp [1 ].' table ' . $ table . ' all ' ;
394404 }
395405 else if (preg_match ("/^show bgp neighbors ([\d\.A-Fa-f:]+) routes damping suppressed$/ " , $ exec , $ exec_exp ))
396406 {
397- $ exec = 'show route receive-protocol bgp ' .$ exec_exp [1 ].' damping suppressed ' ;
407+ $ exec = 'show route receive-protocol bgp ' .$ exec_exp [1 ].' table ' . $ table . ' damping suppressed ' ;
398408 }
399409 else if (preg_match ("/^show bgp n\w*\s+([\d\.A-Fa-f:]+) advertised-routes ([\d\.A-Fa-f:\/]+)$/ " , $ exec , $ exec_exp ))
400410 {
401- $ exec = 'show route advertising-protocol bgp ' .$ exec_exp [1 ].' ' .$ exec_exp [2 ].' exact detail ' ;
411+ $ exec = 'show route advertising-protocol bgp ' .$ exec_exp [1 ].' ' .$ exec_exp [2 ]. ' table ' . $ table .' exact detail ' ;
402412 }
403413 else if (preg_match ("/^show bgp n\w*\s+([\d\.A-Fa-f:]+) receive-protocol ([\d\.A-Fa-f:\/]+)$/ " , $ exec , $ exec_exp ))
404414 {
405- $ exec = 'show route receive-protocol bgp ' .$ exec_exp [1 ].' ' .$ exec_exp [2 ].' exact detail ' ;
415+ $ exec = 'show route receive-protocol bgp ' .$ exec_exp [1 ].' ' .$ exec_exp [2 ].' table ' . $ table . ' exact detail ' ;
406416 }
407417 else if (preg_match ("/^show bgp n\w*\s+([\d\.A-Fa-f:]+) a[\w\-]*$/ " , $ exec , $ exec_exp ))
408418 {
409- $ exec = 'show route advertising-protocol bgp ' .$ exec_exp [1 ];
419+ $ exec = 'show route advertising-protocol bgp ' .$ exec_exp [1 ]. ' table ' . $ table ;
410420 }
411421 else if (preg_match ("/^show bgp\s+([\d\.A-Fa-f:]+\/\d+)$/ " , $ exec , $ exec_exp ))
412422 {
413- $ exec = 'show route protocol bgp ' .$ exec_exp [1 ].' terse exact ' ;
423+ $ exec = 'show route protocol bgp ' .$ exec_exp [1 ].' table ' . $ table . ' terse exact ' ;
414424 }
415425 else if (preg_match ("/^show bgp\s+([\d\.A-Fa-f:]+)$/ " , $ exec , $ exec_exp ))
416426 {
417427 $ exec = 'show route protocol bgp ' .$ exec_exp [1 ].' table ' .$ table ;
418428 }
419429 else if (preg_match ("/^show bgp\s+([\d\.A-Fa-f:\/]+) exact$/ " , $ exec , $ exec_exp ))
420430 {
421- $ exec = 'show route protocol bgp ' .$ exec_exp [1 ].' exact detail all ' ;
431+ $ exec = 'show route protocol bgp ' .$ exec_exp [1 ].' table ' . $ table . ' exact detail all ' ;
422432 }
423433 else if (preg_match ("/^show bgp re\s+(.*)$/ " , $ exec , $ exec_exp ))
424434 {
@@ -434,8 +444,33 @@ function load() {
434444 $ re = $ re .".* \$" ;
435445 }
436446
437- $ exec = 'show route aspath-regex " ' .str_replace ('_ ' , ' ' , $ re ).'" all ' ;
447+ if ($ routing_instance ){
448+ $ exec = 'show route instance ' .$ routing_instance .' aspath-regex " ' .str_replace ('_ ' , ' ' , $ re ).'" all ' ;
449+ }else {
450+ $ exec = 'show route aspath-regex " ' .str_replace ('_ ' , ' ' , $ re ).'" all ' ;
451+ }
452+ }
453+ else if (preg_match ("/^show bgp summary$/ " , $ exec , $ exec_exp ))
454+ {
455+ if ($ routing_instance ){
456+ $ exec = 'show bgp summary instance ' .$ routing_instance ;
457+ }else {
458+ $ exec = 'show bgp summary ' ;
459+ }
438460 }
461+ else if (preg_match ("/^show route advertising-protocol bgp\s+([\d\.A-Fa-f:\/]+)$/ " , $ exec , $ exec_exp ))
462+ {
463+ $ exec = 'show route advertising-protocol bgp ' .$ exec_exp [1 ].' table ' .$ table ;
464+ }
465+ else if (preg_match ("/^traceroute (ip|ipv6) ([\d\.A-Fa-f:\/]+)$/ " , $ exec , $ exec_exp ))
466+ {
467+ if ($ routing_instance ){
468+ $ exec = 'traceroute ' .$ exec_exp [1 ].' routing-instance ' .$ routing_instance .' ' .$ exec_exp [2 ];
469+ }else {
470+ $ exec = 'traceroute ' .$ exec_exp [1 ].' ' .$ exec_exp [2 ];
471+ }
472+ }
473+
439474 }
440475
441476 if ($ command == 'graph ' )
@@ -1387,7 +1422,7 @@ function ($matches) use ($lastip) {
13871422 return $ output ;
13881423 }
13891424
1390- if ($ exec == ' show bgp summary ' )
1425+ if (preg_match ( " /^ show bgp summary(?:\s+instance\s+[\d\w-]*)?$/ " , $ exec ))
13911426 {
13921427 // JunOS
13931428 if (preg_match ("/^([\dA-Fa-f:][\d\.A-Fa-f:]+)\s+/ " , $ output , $ lastip_exp ))
@@ -1553,7 +1588,7 @@ function ($matches) {
15531588 }
15541589
15551590 // JunOS
1556- if (preg_match ("/^show route advertising-protocol bgp\s+([\d\.A-Fa-f:]+)$/i " , $ exec , $ ip_exp ))
1591+ if (preg_match ("/^show route advertising-protocol bgp\s+([\d\.A-Fa-f:]+)(?:\s+table\s+[\d\w\-\.]*)? $/i " , $ exec , $ ip_exp ))
15571592 {
15581593 $ ip = $ ip_exp [1 ];
15591594
@@ -1760,7 +1795,7 @@ function ($matches) {
17601795 return $ output ;
17611796 }
17621797
1763- if (preg_match ("/^show bgp n\w*\s+([\d\.A-Fa-f:]+)/i " , $ exec , $ ip_exp ))
1798+ if (preg_match ("/^show bgp n\w*\s+(?:instance\s+[\d\w-]*)?\s*( [\d\.A-Fa-f:]+)/i " , $ exec , $ ip_exp ))
17641799 {
17651800 $ ip = $ ip_exp [1 ];
17661801
0 commit comments