Skip to content

Commit

Permalink
Adding modules
Browse files Browse the repository at this point in the history
  • Loading branch information
meklis committed Dec 9, 2024
1 parent fc87cda commit b0acbbf
Show file tree
Hide file tree
Showing 18 changed files with 347 additions and 48 deletions.
33 changes: 33 additions & 0 deletions configs/models/Juniper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions configs/modules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
36 changes: 35 additions & 1 deletion configs/oids/global.oids.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
- {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}
6 changes: 6 additions & 0 deletions configs/oids/juniper.yml
Original file line number Diff line number Diff line change
@@ -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}


35 changes: 0 additions & 35 deletions oids

This file was deleted.

7 changes: 7 additions & 0 deletions src/Modules/BDcom/MultiRawConsoleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('/^\<f\>(.*)$/', $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') {
Expand Down
7 changes: 7 additions & 0 deletions src/Modules/CData/FD16xxV3/MultiRawConsoleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('/^\<f\>(.*)$/', $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') {
Expand Down
7 changes: 7 additions & 0 deletions src/Modules/CData/MultiRawConsoleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('/^\<f\>(.*)$/', $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') {
Expand Down
20 changes: 8 additions & 12 deletions src/Modules/DellSwitch/InterfacesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ 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];
}
$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");
}
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions src/Modules/HuaweiOLT/MultiRawConsoleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('/^\<f\>(.*)$/', $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') {
Expand Down
24 changes: 24 additions & 0 deletions src/Modules/JuniperSwitch/BgpInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace SwitcherCore\Modules\JuniperSwitch;

use SwitcherCore\Modules\AbstractModule;

class BgpInfo extends AbstractModule
{
public function run($params = [])
{
// TODO: Implement run() method.
}

public function getPretty()
{
// TODO: Implement getPretty() method.
}

public function getPrettyFiltered($filter = [])
{
// TODO: Implement getPrettyFiltered() method.
}

}
24 changes: 24 additions & 0 deletions src/Modules/JuniperSwitch/BgpPeerRoutes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace SwitcherCore\Modules\JuniperSwitch;

use SwitcherCore\Modules\AbstractModule;

class BgpPeerRoutes extends AbstractModule
{
public function run($params = [])
{
// TODO: Implement run() method.
}

public function getPretty()
{
// TODO: Implement getPretty() method.
}

public function getPrettyFiltered($filter = [])
{
// TODO: Implement getPrettyFiltered() method.
}

}
24 changes: 24 additions & 0 deletions src/Modules/JuniperSwitch/BgpPeers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace SwitcherCore\Modules\JuniperSwitch;

use SwitcherCore\Modules\AbstractModule;

class BgpPeers extends AbstractModule
{
public function run($params = [])
{
// TODO: Implement run() method.
}

public function getPretty()
{
// TODO: Implement getPretty() method.
}

public function getPrettyFiltered($filter = [])
{
// TODO: Implement getPrettyFiltered() method.
}

}
51 changes: 51 additions & 0 deletions src/Modules/JuniperSwitch/Fdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,55 @@
class Fdb extends FdbDot1Bridge
{
use InterfacesTrait;
protected function formate() {
if($this->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;
}
}
Loading

0 comments on commit b0acbbf

Please sign in to comment.