Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions configs/models/Dell-switches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ models:
oids:
- ./oids/dell/ems.yml
extra:
console_conn_type: dell
console_conn_type: dell_emc_networking_os
modules:
parse_interface: \SwitcherCore\Modules\DellSwitch\ParseInterface
fdb: \SwitcherCore\Modules\DellSwitch\Fdb
Expand All @@ -111,7 +111,7 @@ models:
multi_console_command: \SwitcherCore\Modules\DellSwitch\MultiRawConsoleCommand
lldp_info: \SwitcherCore\Modules\DellSwitch\LldpInfo
net_settings: \SwitcherCore\Modules\General\NetSettings
arps: \SwitcherCore\Modules\DellSwitch\ArpInfo
arps: \SwitcherCore\Modules\DellSwitch\ArpInfoEMC
bgp_info: \SwitcherCore\Modules\DellSwitch\BgpInfo
bgp_peers: \SwitcherCore\Modules\DellSwitch\BgpPeers
direct_routes: \SwitcherCore\Modules\DellSwitch\DirectRoutes
Expand Down
6 changes: 5 additions & 1 deletion configs/oids/xos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@
- {name: extreme.fdbMacExosFdbVlanIfIndex , oid: .1.3.6.1.4.1.1916.1.16.4.1.2} #.1.3.6.1.4.1.1916.1.16.4.1.2.4.141.56.32.98.186.1000006 = INTEGER: 1000006
- {name: extreme.fdbMacExosFdbPortIfIndex , oid: .1.3.6.1.4.1.1916.1.16.4.1.3} #.1.3.6.1.4.1.1916.1.16.4.1.3.4.141.56.32.98.186.1000006 = INTEGER: 1026
- {name: extreme.fdbMacExosFdbStatus, oid: .1.3.6.1.4.1.1916.1.16.4.1.4, values: {1: OTHER, 2: INVALID, 3: LEARNED, 4: SELF, 5: MGMT}} #.1.3.6.1.4.1.1916.1.16.4.1.4.4.141.56.32.98.186.1000006 = INTEGER: 3
- {name: extreme.vlanIfVlanId, oid: .1.3.6.1.4.1.1916.1.2.1.2.1.10 } # .1.3.6.1.4.1.1916.1.2.1.2.1.10.1000004 = INTEGER: 1
- {name: extreme.vlanIfVlanId, oid: .1.3.6.1.4.1.1916.1.2.1.2.1.10 } # .1.3.6.1.4.1.1916.1.2.1.2.1.10.1000004 = INTEGER: 1

- {name: extreme.vlanIfDescr, oid: .1.3.6.1.4.1.1916.1.2.1.2.1.2 } #vlan name (.1.3.6.1.4.1.1916.1.2.1.2.1.2.1000004 = STRING: "Default")
- {name: extreme.vlanOpaqueTaggedPorts, oid: .1.3.6.1.4.1.1916.1.2.6.1.1.1 } # .1.3.6.1.4.1.1916.1.2.6.1.1.1.1000005.1 = Hex-STRING: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
- {name: extreme.vlanOpaqueUntaggedPorts, oid: .1.3.6.1.4.1.1916.1.2.6.1.1.2 } # .1.3.6.1.4.1.1916.1.2.6.1.1.2.1000005.1 = Hex-STRING: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
78 changes: 43 additions & 35 deletions src/Modules/Arista/ArpInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,55 @@
use SwitcherCore\Modules\AbstractModule;
use SwitcherCore\Modules\Helper;

class ArpInfo extends AbstractModule
{
class ArpInfo extends AbstractModule {
use InterfacesTrait;

public function run($params = [])
{
$oid = $this->oids->getOidByName('ip.arp.macAddr')->getOid();
public function getPrettyFiltered($filter = []) {
return $this->response;
}

$this->response = $this->formatResponse($this->snmp->walk([Oid::init($oid)]));
return $this;
public function getPretty() {
return $this->response;
}

public function getPretty()
{
if ($this->response['ip.arp.macAddr']->error()) {
throw new \SNMPException($this->response['ip.arp.macAddr']->error());
public function run($params = []) {
$cmd = 'show arp';
if(isset($params['vlan_id']) && intval($params['vlan_id']) > 0 && intval($params['vlan_id']) < 4095) {
$cmd .= ' interface vlan' . $params['vlan_id'];
}
$vlanIds = $this->getVlanIdsMap();
$response = [];
foreach ($this->response['ip.arp.macAddr']->fetchAll() as $mac) {
$ip = Helper::getIndexByOid($mac->getOid(), 3) . "." .
Helper::getIndexByOid($mac->getOid(), 2) . "." .
Helper::getIndexByOid($mac->getOid(), 1) . "." .
Helper::getIndexByOid($mac->getOid())
;
$vlanIdIndex = Helper::getIndexByOid($mac->getOid(), 4);

$response[] = [
'mac' => $mac->getHexValue(),
'ip' => $ip,
'vlan_id' => isset($vlanIds[$vlanIdIndex]) ? $vlanIds[$vlanIdIndex] : null,
'interface' => null,
];
if(isset($params['ip']) && preg_match('/^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$/', $params['ip'])) {
$cmd .= ' ' . $params['ip'];
}

return $response;
}

public function getPrettyFiltered($filter = [])
{
return $this->getPretty();
if(isset($params['mac'])) {
$mac = Helper::formatMac3Blocks($params['mac']);
$cmd .= ' mac-address ' . $mac;
}
$cmd .= " | json";

$res = $this->getModule('console_command')->run(['command' => $cmd])->getPrettyFiltered();
if(!$res['success']) throw new \Exception("Error while running command {$cmd}");

$this->response = [];
$res = json_decode($res['output'], true);
if(isset($res['ipV4Neighbors'])) {
foreach($res['ipV4Neighbors'] as $row) {
$vlan_id = null;
if(preg_match('/vlan(\d{1,4})/i', $row['interface'], $m)) {
$vlan_id = $m[1];
}
$iface = null;
if(preg_match('/(Ethernet\d{1,3}\/?\d?\d?\d?|Port\-Channel\d{1,3})/', $row['interface'], $m)) {
$iface = $this->parseInterface($m[1], 'name');
}
$this->response[] = [
'interface' => $iface,
'mac' => Helper::formatMac($row['hwAddress']),
'ip' => $row['address'],
'vlan_id' => $vlan_id,
'_age' => (isset($row['age']) ? $row['age'] : null),
];
}
}
return $this;
}

}
68 changes: 36 additions & 32 deletions src/Modules/DellSwitch/ArpInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,50 @@

namespace SwitcherCore\Modules\DellSwitch;

use SnmpWrapper\Oid;
use SwitcherCore\Modules\AbstractModule;
use SwitcherCore\Modules\Helper;

class ArpInfo extends AbstractModule
{
class ArpInfo extends AbstractModule {
use InterfacesTrait;

public function run($params = [])
{
$oid = $this->oids->getOidByName('ip.arp.macAddr')->getOid();

$this->response = $this->formatResponse($this->snmp->walk([Oid::init($oid)]));
return $this;
}

public function getPretty()
{
if ($this->response['ip.arp.macAddr']->error()) {
throw new \SNMPException($this->response['ip.arp.macAddr']->error());
public function run($params = []) {
$cmd = 'show arp';
if (isset($params['mac'])) {
$mac = Helper::formatMac($params['mac']);
$cmd .= ' macaddress ' . $mac;
} elseif (isset($params['ip']) && preg_match('/^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$/', $params['ip'])) {
$cmd .= ' ip ' . $params['ip'];
} elseif (isset($params['vlan_id']) && intval($params['vlan_id']) > 0 && intval($params['vlan_id']) < 4095) {
$cmd .= ' interface vlan ' . $params['vlan_id'];
}
$vlanIds = $this->getVlanIdsMap();
$response = [];
foreach ($this->response['ip.arp.macAddr']->fetchAll() as $mac) {
$ip = Helper::getIndexByOid($mac->getOid(), 3) . "." .
Helper::getIndexByOid($mac->getOid(), 2) . "." .
Helper::getIndexByOid($mac->getOid(), 1) . "." .
Helper::getIndexByOid($mac->getOid())
;
$vlanIdIndex = Helper::getIndexByOid($mac->getOid(), 4);

$response[] = [
'mac' => $mac->getHexValue(),
'ip' => $ip,
'vlan_id' => isset($vlanIds[$vlanIdIndex]) ? $vlanIds[$vlanIdIndex] : null,
'interface' => null,
];
$res = $this->getModule('console_command')->run(['command' => $cmd])->getPrettyFiltered();
if(!$res['success']) throw new \Exception("Error while running command {$cmd}. output = {$res['output']}");
$exploded = explode("\n", $res['output']);
$this->response = [];
foreach($exploded as $row) {
if(preg_match('/^.*\s(((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4})\s+(\d{1,6}|\-)\s+(([a-f0-9]{2}\:){5}[a-f0-9]{2})\s+(\-|.*)\s+Vl\s(\d{1,4})/i', $row, $m)) {
$iface = null;
if(preg_match('/^Po\s(\d{1,3})$/', trim($m[8]), $mm)) {
$iface = $this->parseInterface('Port-channel ' . $mm[1], 'name');
} elseif(preg_match('/^Te\s(\d\/\d+)$/', trim($m[8]), $mm)) {
$iface = $this->parseInterface('TenGigabitEthernet ' . $mm[1], 'name');
} elseif(preg_match('/^Fo\s(\d\/\d+)$/', trim($m[8]), $mm)) {
$iface = $this->parseInterface('fortyGigE ' . $mm[1], 'name');
}
$this->response[] = [
'interface' => $iface,
'mac' => Helper::formatMac($m[6]),
'ip' => $m[1],
'vlan_id' => $m[9],
'_age' => (($m[5] === '-') ? null : $m[5]),
];
}
}
return $this;
}

return $response;
public function getPretty() {
return $this->response;
}

public function getPrettyFiltered($filter = [])
Expand Down
48 changes: 48 additions & 0 deletions src/Modules/DellSwitch/ArpInfoEMC.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace SwitcherCore\Modules\DellSwitch;

use SwitcherCore\Modules\AbstractModule;
use SwitcherCore\Modules\Helper;

class ArpInfoEMC extends AbstractModule {
use InterfacesTrait;

public function run($params = []) {
$cmd = 'show ip arp';
if (isset($params['mac'])) {
$mac = Helper::formatMac3Blocks($params['mac']);
$cmd .= ' mac-address ' . $mac;
} elseif (isset($params['ip']) && preg_match('/^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$/', $params['ip'])) {
$cmd .= ' ' . $params['ip'];
} elseif (isset($params['vlan_id']) && intval($params['vlan_id']) > 0 && intval($params['vlan_id']) < 4095) {
$cmd .= ' interface vlan' . $params['vlan_id'];
}
$res = $this->getModule('console_command')->run(['command' => $cmd])->getPrettyFiltered();
if(!$res['success']) throw new \Exception("Error while running command {$cmd}. output = {$res['output']}");

$exploded = explode("\n", $res['output']);
$this->response = [];
foreach($exploded as $row) {
if(preg_match('/^(((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4})\s+(([a-f0-9]{2}\:){5}[a-f0-9]{2})\s+vlan(\d{1,4})\s+(port\-channel\d{1,3}|ethernet\d{1,3}\/\d{1,3}\/\d{1,3}\:?\d?\d?\d?)/i', $row, $m)) {
$this->response[] = [
'interface' => $this->parseInterface($m[8], 'name'),
'mac' => Helper::formatMac($m[5]),
'ip' => $m[1],
'vlan_id' => $m[7],
];
}
}
return $this;
}

public function getPretty() {
return $this->response;
}

public function getPrettyFiltered($filter = [])
{
return $this->getPretty();
}

}
28 changes: 24 additions & 4 deletions src/Modules/ExtremeXOS/ArpInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,32 @@ public function run($params = [])
* - {name: mac, pattern: '^[a-fA-F0-9:]{17}|[a-fA-F0-9]{12}$', required: no}
* - {name: status, pattern: '^(disabled|invalid|OK)$', required: no, values: [disabled, invalid, OK]}
*/
$filter_vlan_id = false;
if(isset($params['vlan_id']) && intval($params['vlan_id']) > 0 && intval($params['vlan_id']) < 4097) {
$oids[] = Oid::init($this->oids->getOidByName('extreme.vlanIfDescr')->getOid());
$oids[] = Oid::init($this->oids->getOidByName('extreme.vlanIfVlanId')->getOid());
$res = $this->formatResponse($this->snmp->walk($oids));

foreach($res['extreme.vlanIfDescr']->fetchAll() as $val) {
$vlan_names[Helper::getIndexByOid($val->getOid())] = $val->getValue();
}
foreach($res['extreme.vlanIfVlanId']->fetchAll() as $val) {
$vlan_ids[$val->getValue()] = Helper::getIndexByOid($val->getOid());
}

if(isset($vlan_names[$vlan_ids[$params['vlan_id']]])) {
$filter_vlan_id = $vlan_names[$vlan_ids[$params['vlan_id']]];
}
}

$command = "show iparp";
if(isset($params['ip']) && $params['ip']) {
if($filter_vlan_id) {
$command .= " {$filter_vlan_id}";
} elseif(isset($params['ip']) && $params['ip']) {
$command .= " {$params['ip']}";
}
if(isset($params['mac']) && $params['mac']) {
$command .= " {$params['mac']}";
} elseif(isset($params['mac']) && $params['mac']) {
$mac = Helper::formatMac($params['mac']);
$command .= " {$mac}";
}

$this->response = $this->console->exec($command);
Expand Down
Loading