update: link status feature is available on Juniper
authorxornet <founder.sl@gmail.com>
Tue, 13 May 2014 11:31:07 +0000 (15:31 +0400)
committerAlexey Andriyanov <alan@al-an.info>
Wed, 14 May 2014 18:26:16 +0000 (22:26 +0400)
ChangeLog
wwwroot/inc/deviceconfig.php
wwwroot/inc/remote.php

index 79b5710..52ac4a4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,7 @@
        update: syncdomain.php now provides some new CLI options and better lockfile handling
        update: new {$client_x.x.x.x} auto tag containing client's IP
        update: explicitly require PHP version 5.3.0 or newer
+       update: link status feature is available on Juniper
 0.20.8
        bugfix: syntax error in functions.php when using PHP prior to 5.3.0 (#1195)
        bugfix: properly format comment text for locations and racks
index 5186369..96f4797 100644 (file)
@@ -1755,6 +1755,9 @@ show configuration interfaces
                        $ret .= "show lldp neighbors\n";
                        $ret .= "# object_id=$dummy_object_id";
                        break;
+               case 'getportstatus':
+                       $ret .= "show interfaces terse\n";
+                       break;
                default:
                        throw new InvalidArgException ('opcode', $cmd['opcode']);
                }
@@ -3004,6 +3007,39 @@ function ros11ReadInterfaceStatus ($text)
        return $ret;
 }
 
+function jun10ReadInterfaceStatus ($input)
+{
+       $result = array();
+       $state = 'headerSearch';
+       foreach (explode ("\n", $input) as $line)
+       {
+               $line = trim ($line);
+               switch ($state)
+               {
+                       case 'headerSearch':
+                               if (preg_match('/^Interface\s+Admin\s+Link\s+Proto\s+Local\s+Remote/i', $line))
+                                       $state = 'readPort';
+                               break;
+                       case 'readPort':
+                               if (preg_match('/^{/', $line) || preg_match('/^\S+>/', $line))
+                                       break 2;
+                               $field_list = preg_split('/\s+/', $line);
+                               if (count ($field_list) < 3)
+                                       continue;
+                               $portname = $field_list[0];
+                               $admin_status = ($field_list[1] == 'up' || $field_list[1] == 'down') ? $field_list[1] : 'disabled';
+                               $link_status = ($field_list[2] == 'up' || $field_list[2] == 'down') ? $field_list[2] : 'disabled';
+
+                               $result[$portname] = array
+                               (
+                                       'status' => $link_status,
+                               );
+                               break;
+               }
+       }
+       return $result;
+}
+
 function maclist_sort ($a, $b)
 {
        if ($a['vid'] == $b['vid'])
index fd4fc30..fe5d47c 100644 (file)
@@ -71,6 +71,7 @@ $breedfunc = array
        'jun10-xlatepushq-main'    => 'jun10TranslatePushQueue',
        'jun10-getallconf-main'    => 'jun10SpotConfigText',
        'jun10-getlldpstatus-main' => 'jun10ReadLLDPStatus',
+       'jun10-getportstatus-main' => 'jun10ReadInterfaceStatus',
        'ftos8-xlatepushq-main'    => 'ftos8TranslatePushQueue',
        'ftos8-getlldpstatus-main' => 'ftos8ReadLLDPStatus',
        'ftos8-getmaclist-main'    => 'ftos8ReadMacList',