Network
banshee/network-collection/network/snmp/
lldp-neighbors
The LLDP neighbors of a switch or a router by SNMP (LLDP-MIB): who is on each port, and an expected neighbor gone.
by banshee1 installation2 versions
// The LLDP neighbors of a switch or a router, by SNMP (LLDP-MIB, IEEE 802.1AB): on each local port, the
// name of the device seen and its port. A neighbor that goes away leaves the table: the watch "Neighbor
// gone" raises for the ports it is given, the ports where a neighbor is expected (an uplink, a server).
// A port is named by its interface name when the device gives it, otherwise by its description.
need('protocol:snmp');
per('port', 'Ports');
output('neighbor', 'text', array('label' => 'Neighbor', 'per' => 'port'));
output('neighbor-port', 'text', array('label' => 'Port of the neighbor', 'per' => 'port'));
output('neighbors', 'number', array('label' => 'Neighbors'));
watch.missing('gone', 'Neighbor gone', 'neighbor', array(
'help' => 'Raises when no neighbor is seen any more on the ports given: name the uplinks and the ports where a device is expected.',
'enabled' => false,
));
watch.below('no-neighbor', 'No neighbor', 'neighbors', array('critical' => 1, 'enabled' => false));
// The name of a port, by LLDP: its id when the id is a name (interfaceAlias 1, interfaceName 5, local 7),
// otherwise its description; failing both, the name given. A MAC address (3) or a network address (4)
// is not a name a reader knows.
function port_name($subtype, $id, $description, $fallback) {
if (($subtype == 1 || $subtype == 5 || $subtype == 7) && $id != '') {
return $id;
}
if ($description != '') {
return $description;
}
return $fallback;
}
// lldpLocPortTable, by lldpLocPortNum: lldpLocPortIdSubtype, lldpLocPortId and lldpLocPortDesc.
$local = snmp.table(array(
'subtype' => '1.0.8802.1.1.2.1.3.7.1.2',
'id' => '1.0.8802.1.1.2.1.3.7.1.3',
'description' => '1.0.8802.1.1.2.1.3.7.1.4',
));
// lldpRemTable, by lldpRemTimeMark, lldpRemLocalPortNum and lldpRemIndex: lldpRemPortIdSubtype,
// lldpRemPortId, lldpRemPortDesc and lldpRemSysName.
$remote = snmp.table(array(
'subtype' => '1.0.8802.1.1.2.1.4.1.1.6',
'id' => '1.0.8802.1.1.2.1.4.1.1.7',
'description' => '1.0.8802.1.1.2.1.4.1.1.8',
'system' => '1.0.8802.1.1.2.1.4.1.1.9',
));
$count = 0;
$seen = array();
foreach ($remote as $index => $row) {
$parts = text.split($index, '.');
if (list.count($parts) != 3) {
continue;
}
$port = list.get($local, $parts[1], array());
$name = port_name(list.get($port, 'subtype', 0), list.get($port, 'id', ''), list.get($port, 'description', ''), 'port ' . $parts[1]);
// Two neighbors on one port (a phone and a computer behind it) each keep their own: the second
// carries its lldpRemIndex.
if (list.has($seen, $name)) {
$name = $name . ' #' . $parts[2];
}
$seen[$name] = true;
$count = $count + 1;
$system = list.get($row, 'system', '');
if ($system == '') {
$system = 'unnamed';
}
value('neighbor', $system, $name);
$neighbor_port = port_name(list.get($row, 'subtype', 0), list.get($row, 'id', ''), list.get($row, 'description', ''), '');
if ($neighbor_port != '') {
value('neighbor-port', $neighbor_port, $name);
}
}
value('neighbors', $count);