mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Common contexts for polling (#13158)
* Common contexts for polling Don't store contexts on the device array, use the device model Also should be easier to add different contexts later. * rename variables for consistency
This commit is contained in:
@@ -91,7 +91,7 @@ class Splunk extends Transport
|
||||
$splunk_prefix .= $key . '="' . $val . '", ';
|
||||
}
|
||||
|
||||
$ignore = ['attribs', 'vrf_lite_cisco', 'community', 'authlevel', 'authname', 'authpass', 'authalgo', 'cryptopass', 'cryptoalgo', 'snmpver', 'port'];
|
||||
$ignore = ['attribs', 'community', 'authlevel', 'authname', 'authpass', 'authalgo', 'cryptopass', 'cryptoalgo', 'snmpver', 'port'];
|
||||
foreach ($device as $key => $val) {
|
||||
if (in_array($key, $ignore)) {
|
||||
continue;
|
||||
|
@@ -116,6 +116,17 @@ class Device extends BaseModel
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get VRF contexts to poll.
|
||||
* If no contexts are found, return the default context ''
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVrfContexts(): array
|
||||
{
|
||||
return $this->vrfLites->isEmpty() ? [''] : $this->vrfLites->pluck('context_name')->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the display name of this device (hostname) unless force_ip_to_sysname is set
|
||||
* and hostname is an IP and sysName is set
|
||||
|
@@ -315,7 +315,6 @@ function device_by_id_cache($device_id, $refresh = false)
|
||||
$device['lat'] = $model->location->lat ?? null;
|
||||
$device['lng'] = $model->location->lng ?? null;
|
||||
$device['attribs'] = $model->getAttribs();
|
||||
$device['vrf_lite_cisco'] = $model->vrfLites->keyBy('context_name')->toArray();
|
||||
|
||||
return $device;
|
||||
}
|
||||
|
@@ -24,15 +24,8 @@
|
||||
|
||||
use LibreNMS\Config;
|
||||
|
||||
if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco']) != 0)) {
|
||||
$vrfs_lite_cisco = $device['vrf_lite_cisco'];
|
||||
} else {
|
||||
$vrfs_lite_cisco = [['context_name'=>'']];
|
||||
}
|
||||
|
||||
foreach ($vrfs_lite_cisco as $vrf) {
|
||||
$context = $vrf['context_name'];
|
||||
$device['context_name'] = $context;
|
||||
foreach (DeviceCache::getPrimary()->getVrfContexts() as $context_name) {
|
||||
$device['context_name'] = $context_name;
|
||||
|
||||
if (file_exists(Config::get('install_dir') . "/includes/discovery/arp-table/{$device['os']}.inc.php")) {
|
||||
include Config::get('install_dir') . "/includes/discovery/arp-table/{$device['os']}.inc.php";
|
||||
@@ -42,7 +35,7 @@ foreach ($vrfs_lite_cisco as $vrf) {
|
||||
}
|
||||
|
||||
$sql = 'SELECT * from `ipv4_mac` WHERE `device_id`=? AND `context_name`=?';
|
||||
$existing_data = dbFetchRows($sql, [$device['device_id'], $context]);
|
||||
$existing_data = dbFetchRows($sql, [$device['device_id'], $context_name]);
|
||||
|
||||
$ipv4_addresses = array_map(function ($data) {
|
||||
return $data['ipv4_address'];
|
||||
@@ -73,7 +66,7 @@ foreach ($vrfs_lite_cisco as $vrf) {
|
||||
if ($mac != $old_mac && $mac != '') {
|
||||
d_echo("Changed mac address for $ip from $old_mac to $mac\n");
|
||||
log_event("MAC change: $ip : " . \LibreNMS\Util\Rewrite::readableMac($old_mac) . ' -> ' . \LibreNMS\Util\Rewrite::readableMac($mac), $device, 'interface', 4, $port_id);
|
||||
dbUpdate(['mac_address' => $mac], 'ipv4_mac', 'port_id=? AND ipv4_address=? AND context_name=?', [$port_id, $ip, $context]);
|
||||
dbUpdate(['mac_address' => $mac], 'ipv4_mac', 'port_id=? AND ipv4_address=? AND context_name=?', [$port_id, $ip, $context_name]);
|
||||
}
|
||||
d_echo("$raw_mac => $ip\n", '.');
|
||||
} elseif (isset($interface['port_id'])) {
|
||||
@@ -83,7 +76,7 @@ foreach ($vrfs_lite_cisco as $vrf) {
|
||||
'device_id' => $device['device_id'],
|
||||
'mac_address' => $mac,
|
||||
'ipv4_address' => $ip,
|
||||
'context_name' => (string) $context,
|
||||
'context_name' => (string) $context_name,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -108,7 +101,7 @@ foreach ($vrfs_lite_cisco as $vrf) {
|
||||
$entry_if = $entry['port_id'];
|
||||
$entry_ip = $entry['ipv4_address'];
|
||||
if ($arp_table[$entry_if][$entry_ip] != $entry_mac) {
|
||||
dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address`=? AND `ipv4_address`=? AND `context_name`=?', [$entry_if, $entry_mac, $entry_ip, $context]);
|
||||
dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address`=? AND `ipv4_address`=? AND `context_name`=?', [$entry_if, $entry_mac, $entry_ip, $context_name]);
|
||||
d_echo(null, '-');
|
||||
}
|
||||
}
|
||||
@@ -123,9 +116,7 @@ foreach ($vrfs_lite_cisco as $vrf) {
|
||||
$insert_data,
|
||||
$sql,
|
||||
$params,
|
||||
$context,
|
||||
$entry,
|
||||
$device['context_name']
|
||||
);
|
||||
}
|
||||
unset($vrfs_lite_cisco);
|
||||
|
@@ -12,18 +12,12 @@ if (Config::get('enable_bgp')) {
|
||||
include Config::get('install_dir') . "/includes/discovery/bgp-peers/{$device['os']}.inc.php";
|
||||
}
|
||||
|
||||
if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco']) != 0)) {
|
||||
$vrfs_lite_cisco = $device['vrf_lite_cisco'];
|
||||
} else {
|
||||
$vrfs_lite_cisco = [['context_name'=>'']];
|
||||
}
|
||||
|
||||
if (empty($bgpLocalAs)) {
|
||||
$bgpLocalAs = snmp_getnext($device, 'bgpLocalAs', '-OQUsv', 'BGP4-MIB');
|
||||
}
|
||||
|
||||
foreach ($vrfs_lite_cisco as $vrf) {
|
||||
$device['context_name'] = $vrf['context_name'];
|
||||
foreach (DeviceCache::getPrimary()->getVrfContexts() as $context_name) {
|
||||
$device['context_name'] = $context_name;
|
||||
if (is_numeric($bgpLocalAs)) {
|
||||
echo "AS$bgpLocalAs ";
|
||||
if ($bgpLocalAs != $device['bgpLocalAs']) {
|
||||
@@ -180,7 +174,8 @@ if (Config::get('enable_bgp')) {
|
||||
'SELECT DISTINCT context_name FROM bgpPeers WHERE device_id=?',
|
||||
[$device['device_id']]
|
||||
);
|
||||
$existing_contexts = array_column($vrfs_lite_cisco, 'context_name');
|
||||
|
||||
$existing_contexts = DeviceCache::getPrimary()->getVrfContexts();
|
||||
foreach ($contexts as $context) {
|
||||
if (! in_array($context, $existing_contexts)) {
|
||||
dbDelete('bgpPeers', 'device_id=? and context_name=?', [$device['device_id'], $context]);
|
||||
@@ -191,10 +186,8 @@ if (Config::get('enable_bgp')) {
|
||||
|
||||
unset(
|
||||
$device['context_name'],
|
||||
$vrfs_lite_cisco,
|
||||
$peers_data,
|
||||
$af_data,
|
||||
$contexts,
|
||||
$vrfs_c
|
||||
$contexts
|
||||
);
|
||||
}
|
||||
|
@@ -98,7 +98,6 @@ if (Config::get('enable_vrf_lite_cisco')) {
|
||||
//get all vrf_lite_cisco, this will used where the value depend of the context, be careful with the order that you call this module, if the module is disabled the context search will not work
|
||||
$tmpVrfC = dbFetchRows('SELECT * FROM vrf_lite_cisco WHERE device_id = ? ', [
|
||||
$device['device_id'], ]);
|
||||
$device['vrf_lite_cisco'] = $tmpVrfC;
|
||||
|
||||
//Delete all vrf that chaged
|
||||
foreach ($tmpVrfC as $vrfC) {
|
||||
|
@@ -3,13 +3,8 @@
|
||||
use LibreNMS\Exceptions\InvalidIpException;
|
||||
use LibreNMS\Util\IPv4;
|
||||
|
||||
if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco']) != 0)) {
|
||||
$vrfs_lite_cisco = $device['vrf_lite_cisco'];
|
||||
} else {
|
||||
$vrfs_lite_cisco = [['context_name'=>null]];
|
||||
}
|
||||
foreach ($vrfs_lite_cisco as $vrf) {
|
||||
$device['context_name'] = $vrf['context_name'];
|
||||
foreach (DeviceCache::getPrimary()->getVrfContexts() as $context_name) {
|
||||
$device['context_name'] = $context_name;
|
||||
|
||||
$oids = trim(snmp_walk($device, 'ipAdEntIfIndex', '-Osq', 'IP-MIB'));
|
||||
$oids = str_replace('ipAdEntIfIndex.', '', $oids);
|
||||
|
@@ -1,12 +1,7 @@
|
||||
<?php
|
||||
|
||||
if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco']) != 0)) {
|
||||
$vrfs_lite_cisco = $device['vrf_lite_cisco'];
|
||||
} else {
|
||||
$vrfs_lite_cisco = [['context_name'=>null]];
|
||||
}
|
||||
foreach ($vrfs_lite_cisco as $vrf) {
|
||||
$device['context_name'] = $vrf['context_name'];
|
||||
foreach (DeviceCache::getPrimary()->getVrfContexts() as $context_name) {
|
||||
$device['context_name'] = $context_name;
|
||||
|
||||
$oids = snmp_walk($device, 'ipAddressIfIndex.ipv6', ['-Osq', '-Ln'], 'IP-MIB');
|
||||
$oids = str_replace('ipAddressIfIndex.ipv6.', '', $oids);
|
||||
|
@@ -8,12 +8,9 @@ use App\Models\OspfPort;
|
||||
use LibreNMS\RRD\RrdDefinition;
|
||||
|
||||
$device_model = DeviceCache::getPrimary();
|
||||
$vrfs_lite_cisco = empty($device['vrf_lite_cisco'])
|
||||
? [['context_name' => null]]
|
||||
: $device['vrf_lite_cisco'];
|
||||
|
||||
foreach ($vrfs_lite_cisco as $vrf_lite) {
|
||||
$device['context_name'] = $vrf_lite['context_name'];
|
||||
foreach ($device_model->getVrfContexts() as $context_name) {
|
||||
$device['context_name'] = $context_name;
|
||||
|
||||
echo ' Processes: ';
|
||||
|
||||
@@ -160,7 +157,7 @@ foreach ($vrfs_lite_cisco as $vrf_lite) {
|
||||
echo $ospf_tos_metrics->count();
|
||||
}
|
||||
|
||||
unset($device['context_name'], $vrfs_lite_cisco, $vrf_lite);
|
||||
unset($device['context_name'], $context_name);
|
||||
|
||||
if ($instance_count) {
|
||||
// Create device-wide statistics RRD
|
||||
|
@@ -131,11 +131,6 @@ if (! isset($query)) {
|
||||
|
||||
foreach (dbFetch($query) as $device) {
|
||||
DeviceCache::setPrimary($device['device_id']);
|
||||
if ($device['os_group'] == 'cisco') {
|
||||
$device['vrf_lite_cisco'] = dbFetchRows('SELECT * FROM `vrf_lite_cisco` WHERE `device_id` = ' . $device['device_id']);
|
||||
} else {
|
||||
$device['vrf_lite_cisco'] = '';
|
||||
}
|
||||
|
||||
if (! poll_device($device, $module_override)) {
|
||||
$unreachable_devices++;
|
||||
|
Reference in New Issue
Block a user