diff --git a/configs/models/Juniper.yml b/configs/models/Juniper.yml index ce4d6693..dda957ad 100644 --- a/configs/models/Juniper.yml +++ b/configs/models/Juniper.yml @@ -18,6 +18,39 @@ models: interface_counters: \SwitcherCore\Modules\JuniperSwitch\Counters system: \SwitcherCore\Modules\JuniperSwitch\System # vlans: \SwitcherCore\Modules\JuniperSwitch\VlansDot1q + vlan_list: \SwitcherCore\Modules\JuniperSwitch\VlanList + errors: \SwitcherCore\Modules\JuniperSwitch\Errors + rmon: \SwitcherCore\Modules\JuniperSwitch\Rmon + pvid: \SwitcherCore\Modules\JuniperSwitch\PvidDot1q + # vlans_by_port: \SwitcherCore\Modules\JuniperSwitch\VlanByPorts + interface_descriptions: \SwitcherCore\Modules\JuniperSwitch\Descriptions + interfaces_list: \SwitcherCore\Modules\JuniperSwitch\InterfacesList + ctrl_port_descr: \SwitcherCore\Modules\JuniperSwitch\SetPortDescription + ctrl_port_state: \SwitcherCore\Modules\JuniperSwitch\StatePortControl + console_command: \SwitcherCore\Modules\JuniperSwitch\RawConsoleCommand + multi_console_command: \SwitcherCore\Modules\JuniperSwitch\MultiRawConsoleCommand + lldp_info: \SwitcherCore\Modules\JuniperSwitch\LldpInfo + net_settings: \SwitcherCore\Modules\General\NetSettings + +- name: Juniper JNP204 series + key: juniper_jnp204_series + device_type: L3 + inputs: + - snmp + - console + detect: {description: .*, objid: ^.1.3.6.1.4.1.2636.1.1.1.2.144 } + extra: + console_conn_type: junos + console_commands_after_connect: + - set cli screen-length 0 + modules: + parse_interface: \SwitcherCore\Modules\JuniperSwitch\ParseInterface + # fdb: \SwitcherCore\Modules\JuniperSwitch\Fdb + link_info: \SwitcherCore\Modules\JuniperSwitch\LinkInfo + interface_counters: \SwitcherCore\Modules\JuniperSwitch\Counters + system: \SwitcherCore\Modules\JuniperSwitch\System + # vlans: \SwitcherCore\Modules\JuniperSwitch\VlansDot1q + vlan_list: \SwitcherCore\Modules\JuniperSwitch\VlanList errors: \SwitcherCore\Modules\JuniperSwitch\Errors rmon: \SwitcherCore\Modules\JuniperSwitch\Rmon pvid: \SwitcherCore\Modules\JuniperSwitch\PvidDot1q diff --git a/configs/modules.yml b/configs/modules.yml index 6f3e9472..68e5c4a3 100755 --- a/configs/modules.yml +++ b/configs/modules.yml @@ -46,6 +46,10 @@ - {name: vlan_id, pattern: '^[0-9]{1,4}$', required: no} descr: Vlan list +#Get vlan info from device +- name: vlan_list + descr: Vlan list + #Get vlan info from device by ports - name: vlans_by_port arguments: @@ -238,6 +242,10 @@ - {name: name, pattern: '^[0-9a-zA-Z_-]{1,16}$', required: no} descr: BGP-sessions +- name: bgp_info + descr: BGP information + + #Action Get arp info with filters - name: arp_ping arguments: diff --git a/configs/oids/global.oids.yml b/configs/oids/global.oids.yml index 2fc9da22..2d64397e 100755 --- a/configs/oids/global.oids.yml +++ b/configs/oids/global.oids.yml @@ -82,4 +82,38 @@ - {name: lldp.remPortId, oid: .1.0.8802.1.1.2.1.4.1.1.7} # Идентификатор порта на удаленном устройстве (не ID порта) - {name: ip.netSettings, oid: .1.3.6.1.2.1.4.20.1} - - {name: ip.arpTable, oid: .1.3.6.1.2.1.4.22.1} \ No newline at end of file + - {name: ip.arpTable, oid: .1.3.6.1.2.1.4.22.1} + + - {name: bgp.version, oid: .1.3.6.1.2.1.15.1.0} + - {name: bgp.localAs, oid: .1.3.6.1.2.1.15.2.0} + - {name: bgp.identifier, oid: .1.3.6.1.2.1.15.4.0} + - {name: bgp.peer.identifier, oid: .1.3.6.1.2.1.15.3.1.1} + # Syntax INTEGER {idle(1), +#connect(2), +#active(3), +#opensent(4), +#openconfirm(5), +#established(6) +#} + - {name: bgp.peer.state, oid: .1.3.6.1.2.1.15.3.1.2, values: {1: idle, 2: connect, 3: active, 4: opensent, 5: openconfirm, 6: established}} + - {name: bgp.peer.admin_status, oid: .1.3.6.1.2.1.15.3.1.3, values: {1: disabled, 2: enabled}} + - {name: bgp.peer.negotiated_version, oid: .1.3.6.1.2.1.15.3.1.4} + - {name: bgp.peer.local_addr, oid: .1.3.6.1.2.1.15.3.1.5} + - {name: bgp.peer.local_port, oid: .1.3.6.1.2.1.15.3.1.6} + - {name: bgp.peer.remote_addr, oid: .1.3.6.1.2.1.15.3.1.7} + - {name: bgp.peer.remote_port, oid: .1.3.6.1.2.1.15.3.1.8} + - {name: bgp.peer.remote_as, oid: .1.3.6.1.2.1.15.3.1.9} + - {name: bgp.peer.last_error, oid: .1.3.6.1.2.1.15.3.1.14} + - {name: bgp.peer.established_time, oid: .1.3.6.1.2.1.15.3.1.16} + + - {name: bgp.4path_attr.origin, oid: .1.3.6.1.2.1.15.6.1.4, values: {1: igp, 2: egp, 3: incomplete}} + - {name: bgp.4path_attr.as_path_segment, oid: .1.3.6.1.2.1.15.6.1.5} + - {name: bgp.4path_attr.next_hop, oid: .1.3.6.1.2.1.15.6.1.6} + - {name: bgp.4path_attr.multi_exit_disc, oid: .1.3.6.1.2.1.15.6.1.7} + - {name: bgp.4path_attr.local_pref, oid: .1.3.6.1.2.1.15.6.1.8} + - {name: bgp.4path_attr.atomic_aggregate, oid: .1.3.6.1.2.1.15.6.1.9, 1: specific-route-not-selected, 2: specific-route-selected} + - {name: bgp.4path_attr.aggregator_as, oid: .1.3.6.1.2.1.15.6.1.10} + - {name: bgp.4path_attr.aggregator_addr, oid: .1.3.6.1.2.1.15.6.1.11} + - {name: bgp.4path_attr.calc_local_preg, oid: .1.3.6.1.2.1.15.6.1.12} + - {name: bgp.4path_attr.attr_best, oid: .1.3.6.1.2.1.15.6.1.13, values: {1: 'no', 2: 'yes'}} + - {name: bgp.4path_attr.attr_unknown, oid: .1.3.6.1.2.1.15.6.1.14} \ No newline at end of file diff --git a/configs/oids/juniper.yml b/configs/oids/juniper.yml new file mode 100644 index 00000000..939dccdf --- /dev/null +++ b/configs/oids/juniper.yml @@ -0,0 +1,6 @@ + +- {name: jnx.vlan.name, oid: .1.3.6.1.4.1.2636.3.48.1.3.1.1.2} +- {name: jnx.vlan.tag, oid: .1.3.6.1.4.1.2636.3.48.1.3.1.1.3 } +- {name: jnx.vlan.fdb_id, oid: .1.3.6.1.4.1.2636.3.48.1.3.1.1.5} + + diff --git a/oids b/oids deleted file mode 100644 index f2def69d..00000000 --- a/oids +++ /dev/null @@ -1,35 +0,0 @@ -ZTE -GPON descriptions: .1.3.6.1.4.1.3902.1012.3.28.1.1.3 -EPON descriptions: .1.3.6.1.4.1.3902.1015.1010.1.7.4.1.1 - -268567552 - 1/2/4 - -GPON: -.1.3.6.1.4.1.3902.1012.3.28.1.1.3.268566784.1 = STRING: "11079" -.1.3.6.1.4.1.3902.1012.3.28.1.1.3.268566784.2 = STRING: "2$$10742$$10742" -.1.3.6.1.4.1.3902.1012.3.28.1.1.3.268566784.3 = STRING: "3$$14678$$14678" -.1.3.6.1.4.1.3902.1012.3.28.1.1.3.268566784.4 = STRING: "4$$11057$$11057" -.1.3.6.1.4.1.3902.1012.3.28.1.1.3.268566784.5 = STRING: "5$$82808$$82808" -.1.3.6.1.4.1.3902.1012.3.28.1.1.3.268566784.6 = STRING: "6$$90896$$90896" -.1.3.6.1.4.1.3902.1012.3.28.1.1.3.268566784.7 = STRING: "7$$86116$$86116" -.1.3.6.1.4.1.3902.1012.3.28.1.1.3.268566784.8 = STRING: "8$$86071$$86071" -.1.3.6.1.4.1.3902.1012.3.28.1.1.3.268566784.9 = STRING: "9$$91033$$91033" -.1.3.6.1.4.1.3902.1012.3.28.1.1.3.268567296.1 = STRING: "1$$8244$$8244" -.1.3.6.1.4.1.3902.1012.3.28.1.1.3.268567296.2 = STRING: "41005" -.1.3.6.1.4.1.3902.1012.3.28.1.1.3.268567296.3 = STRING: "3$$8334$$8334" -.1.3.6.1.4.1.3902.1012.3.28.1.1.3.268567296.4 = STRING: "$$$$8255" -.1.3.6.1.4.1.3902.1012.3.28.1.1.3.268567296.5 = STRING: "104308" -.1.3.6.1.4.1.3902.1012.3.28.1.1.3.268567296.6 = STRING: "6$$31576$$31576" - -EPON: -.1.3.6.1.4.1.3902.1015.1010.1.7.4.1.1.805830912 = STRING: "1$$9717$$9717" -.1.3.6.1.4.1.3902.1015.1010.1.7.4.1.1.805831168 = STRING: "2$$9706$$9706" -.1.3.6.1.4.1.3902.1015.1010.1.7.4.1.1.805831424 = STRING: "3$$10113$$10113" -.1.3.6.1.4.1.3902.1015.1010.1.7.4.1.1.805831680 = STRING: "4$$10191$$10191" -.1.3.6.1.4.1.3902.1015.1010.1.7.4.1.1.805831936 = STRING: "5$$9728$$9728" -.1.3.6.1.4.1.3902.1015.1010.1.7.4.1.1.805832192 = STRING: "6$$9841$$9841" -.1.3.6.1.4.1.3902.1015.1010.1.7.4.1.1.805832448 = STRING: "7$$10461$$10461" -.1.3.6.1.4.1.3902.1015.1010.1.7.4.1.1.805832704 = STRING: "8$$15972$$15972" - - - diff --git a/src/Modules/BDcom/MultiRawConsoleCommand.php b/src/Modules/BDcom/MultiRawConsoleCommand.php index 011c0866..246f2bf1 100644 --- a/src/Modules/BDcom/MultiRawConsoleCommand.php +++ b/src/Modules/BDcom/MultiRawConsoleCommand.php @@ -22,6 +22,13 @@ public function run($params = []) if(preg_match('/\<\s*?sleep *?([0-9]{1,3}).*?\>/', $command, $match)) { sleep($match[1]); } + if(preg_match('/^\(.*)$/', $command, $match)) { + $command = $match[1]; + $resp = $this->getModule('console_command')->run(['command' => trim($command)])->getPretty(); + $resp['success'] = true; + $response[] = $resp; + continue; + } $resp = $this->getModule('console_command')->run(['command' => trim($command)])->getPretty(); $response[] = $resp; if(!$resp['success'] && $params['break_on_error'] == 'yes') { diff --git a/src/Modules/CData/FD16xxV3/MultiRawConsoleCommand.php b/src/Modules/CData/FD16xxV3/MultiRawConsoleCommand.php index 15cd0671..36b5d204 100644 --- a/src/Modules/CData/FD16xxV3/MultiRawConsoleCommand.php +++ b/src/Modules/CData/FD16xxV3/MultiRawConsoleCommand.php @@ -22,6 +22,13 @@ public function run($params = []) if(preg_match('/\<\s*?sleep *?([0-9]{1,3}).*?\>/', $command, $match)) { sleep($match[1]); } + if(preg_match('/^\(.*)$/', $command, $match)) { + $command = $match[1]; + $resp = $this->getModule('console_command')->run(['command' => trim($command)])->getPretty(); + $resp['success'] = true; + $response[] = $resp; + continue; + } $resp = $this->getModule('console_command')->run(['command' => trim($command)])->getPretty(); $response[] = $resp; if(!$resp['success'] && $params['break_on_error'] == 'yes') { diff --git a/src/Modules/CData/MultiRawConsoleCommand.php b/src/Modules/CData/MultiRawConsoleCommand.php index 83b11159..529fcd7e 100644 --- a/src/Modules/CData/MultiRawConsoleCommand.php +++ b/src/Modules/CData/MultiRawConsoleCommand.php @@ -22,6 +22,13 @@ public function run($params = []) if(preg_match('/\<\s*?sleep *?([0-9]{1,3}).*?\>/', $command, $match)) { sleep($match[1]); } + if(preg_match('/^\(.*)$/', $command, $match)) { + $command = $match[1]; + $resp = $this->getModule('console_command')->run(['command' => trim($command)])->getPretty(); + $resp['success'] = true; + $response[] = $resp; + continue; + } $resp = $this->getModule('console_command')->run(['command' => trim($command)])->getPretty(); $response[] = $resp; if(!$resp['success'] && $params['break_on_error'] == 'yes') { diff --git a/src/Modules/DellSwitch/InterfacesTrait.php b/src/Modules/DellSwitch/InterfacesTrait.php index 73f53a8c..853934b2 100644 --- a/src/Modules/DellSwitch/InterfacesTrait.php +++ b/src/Modules/DellSwitch/InterfacesTrait.php @@ -58,8 +58,8 @@ trait InterfacesTrait function parseInterface($iface, $parseBy = 'id') { $ifaces = $this->getInterfacesIds(); - if($parseBy == 'id') { - if(!isset($ifaces[$iface])) { + if ($parseBy == 'id') { + if (!isset($ifaces[$iface])) { throw new \Exception("Incorrect interface ID"); } return $ifaces[$iface]; @@ -67,8 +67,8 @@ function parseInterface($iface, $parseBy = 'id') $filtered = array_filter($ifaces, function ($i) use ($iface, $parseBy) { return isset($i[$parseBy]) && $i[$parseBy] == $iface; }); - if(count($filtered) > 0) { - return array_values($filtered)[0]; + if (count($filtered) > 0) { + return array_values($filtered)[0]; } throw new \Exception("Interface with name {$iface} not found"); } @@ -91,7 +91,7 @@ function getInterfacesIds() $responses = []; foreach ($response as $resp) { $name = $this->oids->findOidById($resp->getOid()); - if($resp->getError()) { + if ($resp->getError()) { throw new \Exception("Error walk {$name->getOid()} on device {$this->device->getIp()}"); } $responses[$name->getName()] = $resp->getResponse(); @@ -127,14 +127,10 @@ function getInterfacesIds() ]; } } - try { - foreach ($responses['dot1q.PortIfIndex'] as $r) { - if(isset($ifaces[$r->getValue()])) { - $ifaces[$r->getValue()]['_dot1q_id'] = Helper::getIndexByOid($r->getOid()); - } + foreach ($responses['dot1q.PortIfIndex'] as $r) { + if (isset($ifaces[$r->getValue()])) { + $ifaces[$r->getValue()]['_dot1q_id'] = Helper::getIndexByOid($r->getOid()); } - } catch (\Exception $e) { - } $this->_interfaces = $ifaces; $this->setCache("INTERFACES", $ifaces, 600, true); diff --git a/src/Modules/HuaweiOLT/MultiRawConsoleCommand.php b/src/Modules/HuaweiOLT/MultiRawConsoleCommand.php index 25c09b8f..80b60d7c 100644 --- a/src/Modules/HuaweiOLT/MultiRawConsoleCommand.php +++ b/src/Modules/HuaweiOLT/MultiRawConsoleCommand.php @@ -27,6 +27,13 @@ public function run($params = []) if(preg_match('/\<\s*?sleep *?([0-9]{1,3}).*?\>/', $command, $match)) { sleep($match[1]); } + if(preg_match('/^\(.*)$/', $command, $match)) { + $command = $match[1]; + $resp = $this->getModule('console_command')->run(['command' => trim($command)])->getPretty(); + $resp['success'] = true; + $response[] = $resp; + continue; + } $resp = $this->getModule('console_command')->run(['command' => trim($command)])->getPretty(); $response[] = $resp; if(!$resp['success'] && $params['break_on_error'] == 'yes') { diff --git a/src/Modules/JuniperSwitch/BgpInfo.php b/src/Modules/JuniperSwitch/BgpInfo.php new file mode 100644 index 00000000..2338cc11 --- /dev/null +++ b/src/Modules/JuniperSwitch/BgpInfo.php @@ -0,0 +1,24 @@ +response) { + $pretties = []; + $statuses = []; + $ports = []; + if($this->response['dot1q.FdbStatus']->error()) { + throw new \Exception("Returned error {$this->response['dot1q.FdbStatus']->error()} from {$this->response['dot1q.FdbStatus']->getRaw()->ip}"); + } else { + while ($d = $this->response['dot1q.FdbStatus']->fetchOne()) { + $data = Helper::oid2MacVlan($d->getOid()); + $statuses["{$data['vid']}-{$data['mac']}"] = $d->getParsedValue(); + } + } + if($this->response['dot1q.FdbPort']->error()) { + throw new \Exception("Returned error {$this->response['dot1q.FdbPort']->error()} from {$this->response['dot1q.FdbPort']->getRaw()->ip}"); + } else { + while ($d = $this->response['dot1q.FdbPort']->fetchOne()) { + $data = Helper::oid2MacVlan($d->getOid()); + $ports["{$data['vid']}-{$data['mac']}"] = $d->getValue(); + } + } + foreach ($statuses as $key=>$status) { + list($vlanId, $macAddr) = explode("-", $key); + if(!isset($ports[$key])) { + continue; + } + if(!(int)$ports[$key]) continue; + try { + $pretties[] = [ + 'interface' => $this->getIfaceByDot1q($ports[$key]), + 'vlan_id' => (int)$vlanId, + 'mac_address' => $macAddr, + 'status' => $status, + ]; + } catch (\Throwable $e) {} + } + return $pretties; + } else { + throw new \Exception("No response"); + } + } + + protected function getIfaceByDot1q($ident) { + $filtered = array_filter($this->getInterfacesIds(), function ($iface) use ($ident) { + return $iface['_dot1q_id'] == $ident; + }); + if(count($filtered) > 0) { + return array_values($filtered)[0]; + } + return null; + } } diff --git a/src/Modules/JuniperSwitch/InterfacesTrait.php b/src/Modules/JuniperSwitch/InterfacesTrait.php index 5788fe0a..0ed4bd6d 100644 --- a/src/Modules/JuniperSwitch/InterfacesTrait.php +++ b/src/Modules/JuniperSwitch/InterfacesTrait.php @@ -108,6 +108,7 @@ function getInterfacesIds() } $response = $this->snmp->walk([ Oid::init($this->oids->getOidByName('if.Name')->getOid()), + Oid::init($this->oids->getOidByName('dot1q.PortIfIndex')->getOid()), ]); /** * @var $responses PoollerResponse[] @@ -137,6 +138,7 @@ function getInterfacesIds() '_type' => $m[1], '_sorting' => ((!$shelf ? $shelf + 1 : $shelf) * 100000) + ($slot * 1000) + $port, 'type' => $type, + '_dot1q_id' => null, ]; } } @@ -155,11 +157,17 @@ function getInterfacesIds() '_sorting' => 10000000 + $m[2], '_lacp_ifaces' => null, 'type' => $type, + '_dot1q_id' => null, ]; } } + foreach ($responses['dot1q.PortIfIndex'] as $r) { + if (isset($ifaces[$r->getValue()])) { + $ifaces[$r->getValue()]['_dot1q_id'] = Helper::getIndexByOid($r->getOid()); + } + } $this->_interfaces = $ifaces; $this->setCache("INTERFACES", $ifaces, 600, true); diff --git a/src/Modules/JuniperSwitch/VlanList.php b/src/Modules/JuniperSwitch/VlanList.php new file mode 100644 index 00000000..43250e81 --- /dev/null +++ b/src/Modules/JuniperSwitch/VlanList.php @@ -0,0 +1,73 @@ +getResponseByName('dot1q.VlanStaticForbiddenEgressPorts'); + $untagged = $this->getResponseByName('dot1q.VlanStaticUntaggedPorts'); + $names = $this->getResponseByName('dot1q.VlanStaticName'); + $egress = $this->getResponseByName('dot1q.VlanStaticEgressPorts'); + + if($names->error()) { + throw new IncompleteResponseException($names->error()); + } + if($egress->error()) { + throw new IncompleteResponseException($egress->error()); + } + if($untagged->error()) { + throw new IncompleteResponseException($untagged->error()); + } + if($forbidden->error()) { + throw new IncompleteResponseException($forbidden->error()); + } + + $indexes = []; + foreach ($this->getInterfacesIds() as $iface) { + $indexes[$iface['id']] = $iface; + } + $formater = function ($resp) use ($indexes) { + $dex = Helper::hexToBinStr($resp->getHexValue()); + $ports = []; + for($port = 1; $port < strlen($dex) ; $port++) { + if($dex[$port] == '1' && isset($indexes[$port])) $ports[] = $indexes[$port]; + } + return $ports; + }; + + $response = []; + foreach ($names->fetchAll() as $resp) { + $response[Helper::getIndexByOid($resp->getOid())]['name'] = $resp->getValue(); + $response[Helper::getIndexByOid($resp->getOid())]['id'] = Helper::getIndexByOid($resp->getOid()); + } + + foreach ($egress->fetchAll() as $resp) { + $response[ Helper::getIndexByOid($resp->getOid())]['ports']['egress'] = $formater($resp); + } + + foreach ($untagged->fetchAll() as $resp) { + $response[ Helper::getIndexByOid($resp->getOid())]['ports']['untagged'] = $formater($resp); + } + foreach ($forbidden->fetchAll() as $resp) { + $response[ Helper::getIndexByOid($resp->getOid())]['ports']['forbidden'] = $formater($resp); + } + foreach ($response as $vlan_id => $resp) { + foreach ($resp['ports']['egress'] as $port) { + if(in_array($port, $response[$vlan_id]['ports']['untagged'])) continue; + if(in_array($port, $response[$vlan_id]['ports']['forbidden'])) continue; + $response[$vlan_id]['ports']['tagged'][] = $port; + } + } + return array_values($response); + } +} diff --git a/src/Modules/ZTE/C300Series/MultiRawConsoleCommand.php b/src/Modules/ZTE/C300Series/MultiRawConsoleCommand.php index c630e916..c1323bec 100644 --- a/src/Modules/ZTE/C300Series/MultiRawConsoleCommand.php +++ b/src/Modules/ZTE/C300Series/MultiRawConsoleCommand.php @@ -27,6 +27,13 @@ public function run($params = []) if(preg_match('/\<\s*?sleep *?([0-9]{1,3}).*?\>/', $command, $match)) { sleep($match[1]); } + if(preg_match('/^\(.*)$/', $command, $match)) { + $command = $match[1]; + $resp = $this->getModule('console_command')->run(['command' => trim($command)])->getPretty(); + $resp['success'] = true; + $response[] = $resp; + continue; + } $resp = $this->getModule('console_command')->run(['command' => trim($command)])->getPretty(); $response[] = $resp; if(!$resp['success'] && $params['break_on_error'] == 'yes') { diff --git a/test.php b/test.php new file mode 100644 index 00000000..f170f5af --- /dev/null +++ b/test.php @@ -0,0 +1,18 @@ + VLAN ID: $vlanId" . PHP_EOL; +} \ No newline at end of file