2018-02-05 07:39:13 -06:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* YamlDiscovery.php
|
|
|
|
*
|
|
|
|
* -Description-
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-02-09 00:29:04 +01:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2018-02-05 07:39:13 -06:00
|
|
|
*
|
2021-02-09 00:29:04 +01:00
|
|
|
* @link https://www.librenms.org
|
2018-02-05 07:39:13 -06:00
|
|
|
* @copyright 2017 Tony Murray
|
|
|
|
* @author Tony Murray <murraytony@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace LibreNMS\Device;
|
|
|
|
|
2020-04-17 17:37:56 -05:00
|
|
|
use Illuminate\Support\Arr;
|
|
|
|
use Illuminate\Support\Str;
|
Modernize mempools (#12282)
* mempools to modern module
quick hacky hrstorage port
* port ucd-snmp-mib to Mempools
* Populate DB for ucd
Prep for yaml
* initial yaml attempt
* more complex conversions
fixes to YamlDiscovery, make leading $ optional and allow mib::oid format
* walk full tables and skip values
normalize percentages above 100
* handle precent only ones (specify total as 100)
* Move default polling out of YamlMempoolsDiscovery
* fixes
* Update test data hrstorage should be correct.
* perc_warn for hrstorage
* Host Resources, record buffer, cached, and shared
* Host Resources is always better, don't do both HR and UCD
* fix unix, include warning levels
* variable size
* consolidate skip_values
* define mempools schema
* number instead of integer
* more schema refactor
* one more skip_values reference
* throw error for invalid oid translation
aos6
* a* and Cisco
* updated test data
* update almost all hrstorage data files
* b*
* c* with test data
use standard cache for hrStorage
* use cache for storage module too
* hand bsnmp properly
* bdcom
* exclude total oid from yaml so it is not polled
May add a way to ignore this behavior and poll it, but I don't know if that is needed.
* automatically handle percent only values
* ciscowlc
* only poll used or free if we have used, free, and total.
* fix skipping
* the dlinkoning
fix find value when value "name" is numeric
* support numeric oids
* dnos/ftos attempt
* I guess we can't filter on total > 0
* edgecos
* e*
* f WIP
* f*
* gwd (aka g*)
* h* + procurve
* i*
* j*
* m*
* support 0% used memory (however unlikely)
* n*
* CISCO-PROCESS-MIB memory, share cache with processors module
* ignore mempools with invalid total
* p*
* quanta
* r*
fix raisecom mibs terribly broken
* s-z
* style fixes
* Move VRP back to PHP and make it actually work
* fix zynos
* update schema
* Update Cisco processor data for description bug fixes
* fix comware processors
* comware mempools with memory size
default precision to 1
* sophos-xg updated data
* hrstorage use ram size for buffers, cache, and shared
* Show memory available instead of free in device overview
* UCD, use same rrd format, store available instead of free in the db.
* Calculate availability for HOST-RESOURCES-MIB
* Convert UCD to standard polling
* rename old rrd files
* initial graph work
* graph WIP
* Graph looking decent
* Graph looking decent for hr
* remove old ucd_graph code
* handle availability mempool
more graph cleanup
* color adjustments
* remove accidental free calculation
* Update test data and fix corner cases
* fis pfsense
* update schema
* add default value for mempool_class
* fix whitespace
* update schema
* update schema correctly
* one more time
* fortigate_1500d-sensors missing oids
* Update docs.
* fix indent
* add implements MempoolsDiscovery explicitly to OS
* remove ucd_memory graph references
remove unused device_memory graph
* remove unused functions
* set devices with mempools to rediscover to prevent/minimize gaps
* use a subquery
* add overview graph
* port health mempools table
* Update device mempool
* only show overview if multiple
* Don't override user set warn percentages in discovery
* fix missed usage
* fix style
* Safety check to not rename rrd files incorrectly if migration has not been run.
* Fix overview percent bar and represent available and used on the bar
* missed an item to convert to mempool_class
* percent on the wrong side
2020-11-23 15:35:35 -06:00
|
|
|
use LibreNMS\Exceptions\InvalidOidException;
|
2018-02-05 07:39:13 -06:00
|
|
|
use LibreNMS\Interfaces\Discovery\DiscoveryItem;
|
|
|
|
use LibreNMS\OS;
|
|
|
|
|
|
|
|
class YamlDiscovery
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param OS $os
|
|
|
|
* @param DiscoveryItem|string $class
|
|
|
|
* @param $yaml_data
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function discover(OS $os, $class, $yaml_data)
|
|
|
|
{
|
|
|
|
$pre_cache = $os->preCache();
|
2020-09-21 14:54:51 +02:00
|
|
|
$items = [];
|
2018-02-05 07:39:13 -06:00
|
|
|
|
|
|
|
// convert to class name for static call below
|
|
|
|
if (is_object($class)) {
|
|
|
|
$class = get_class($class);
|
|
|
|
}
|
|
|
|
|
2020-09-21 15:59:34 +02:00
|
|
|
d_echo('YAML Discovery Data: ');
|
2018-02-05 07:39:13 -06:00
|
|
|
d_echo($yaml_data);
|
|
|
|
|
|
|
|
foreach ($yaml_data as $first_key => $first_yaml) {
|
|
|
|
if ($first_key == 'pre-cache') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-09-21 14:54:51 +02:00
|
|
|
$group_options = isset($first_yaml['options']) ? $first_yaml['options'] : [];
|
2018-02-05 07:39:13 -06:00
|
|
|
|
|
|
|
// find the data array, we could already be at for simple modules
|
|
|
|
if (isset($data['data'])) {
|
|
|
|
$first_yaml = $first_yaml['data'];
|
|
|
|
} elseif ($first_key !== 'data') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($first_yaml as $data) {
|
2020-09-21 14:54:51 +02:00
|
|
|
$raw_data = (array) $pre_cache[$data['oid']];
|
2018-02-05 07:39:13 -06:00
|
|
|
|
|
|
|
d_echo("Data {$data['oid']}: ");
|
|
|
|
d_echo($raw_data);
|
|
|
|
|
|
|
|
$count = 0;
|
|
|
|
foreach ($raw_data as $index => $snmp_data) {
|
|
|
|
$count++;
|
2020-09-21 14:54:51 +02:00
|
|
|
$current_data = [];
|
2018-02-05 07:39:13 -06:00
|
|
|
|
2020-09-21 14:54:51 +02:00
|
|
|
if (! isset($data['value'])) {
|
2018-02-05 07:39:13 -06:00
|
|
|
$data['value'] = $data['oid'];
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($data as $name => $value) {
|
|
|
|
if ($name == '$oid' || $name == 'skip_values') {
|
|
|
|
$current_data[$name] = $value;
|
2020-04-17 17:37:56 -05:00
|
|
|
} elseif (Str::contains($value, '{{')) {
|
2018-02-05 07:39:13 -06:00
|
|
|
// replace embedded values
|
|
|
|
$current_data[$name] = static::replaceValues($name, $index, $count, $data, $pre_cache);
|
|
|
|
} else {
|
|
|
|
// replace references to data
|
2020-02-01 23:28:03 +01:00
|
|
|
$current_data[$name] = static::getValueFromData($name, $index, $data, $pre_cache, $value);
|
2018-02-05 07:39:13 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-05 19:40:29 +01:00
|
|
|
if (static::canSkipItem($current_data['value'], $index, $current_data, $group_options, $snmp_data)) {
|
2018-02-05 07:39:13 -06:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$item = $class::fromYaml($os, $index, $current_data);
|
|
|
|
|
|
|
|
if ($item->isValid()) {
|
|
|
|
$items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-21 14:54:51 +02:00
|
|
|
|
2018-02-05 07:39:13 -06:00
|
|
|
return $items;
|
|
|
|
}
|
|
|
|
|
Modernize mempools (#12282)
* mempools to modern module
quick hacky hrstorage port
* port ucd-snmp-mib to Mempools
* Populate DB for ucd
Prep for yaml
* initial yaml attempt
* more complex conversions
fixes to YamlDiscovery, make leading $ optional and allow mib::oid format
* walk full tables and skip values
normalize percentages above 100
* handle precent only ones (specify total as 100)
* Move default polling out of YamlMempoolsDiscovery
* fixes
* Update test data hrstorage should be correct.
* perc_warn for hrstorage
* Host Resources, record buffer, cached, and shared
* Host Resources is always better, don't do both HR and UCD
* fix unix, include warning levels
* variable size
* consolidate skip_values
* define mempools schema
* number instead of integer
* more schema refactor
* one more skip_values reference
* throw error for invalid oid translation
aos6
* a* and Cisco
* updated test data
* update almost all hrstorage data files
* b*
* c* with test data
use standard cache for hrStorage
* use cache for storage module too
* hand bsnmp properly
* bdcom
* exclude total oid from yaml so it is not polled
May add a way to ignore this behavior and poll it, but I don't know if that is needed.
* automatically handle percent only values
* ciscowlc
* only poll used or free if we have used, free, and total.
* fix skipping
* the dlinkoning
fix find value when value "name" is numeric
* support numeric oids
* dnos/ftos attempt
* I guess we can't filter on total > 0
* edgecos
* e*
* f WIP
* f*
* gwd (aka g*)
* h* + procurve
* i*
* j*
* m*
* support 0% used memory (however unlikely)
* n*
* CISCO-PROCESS-MIB memory, share cache with processors module
* ignore mempools with invalid total
* p*
* quanta
* r*
fix raisecom mibs terribly broken
* s-z
* style fixes
* Move VRP back to PHP and make it actually work
* fix zynos
* update schema
* Update Cisco processor data for description bug fixes
* fix comware processors
* comware mempools with memory size
default precision to 1
* sophos-xg updated data
* hrstorage use ram size for buffers, cache, and shared
* Show memory available instead of free in device overview
* UCD, use same rrd format, store available instead of free in the db.
* Calculate availability for HOST-RESOURCES-MIB
* Convert UCD to standard polling
* rename old rrd files
* initial graph work
* graph WIP
* Graph looking decent
* Graph looking decent for hr
* remove old ucd_graph code
* handle availability mempool
more graph cleanup
* color adjustments
* remove accidental free calculation
* Update test data and fix corner cases
* fis pfsense
* update schema
* add default value for mempool_class
* fix whitespace
* update schema
* update schema correctly
* one more time
* fortigate_1500d-sensors missing oids
* Update docs.
* fix indent
* add implements MempoolsDiscovery explicitly to OS
* remove ucd_memory graph references
remove unused device_memory graph
* remove unused functions
* set devices with mempools to rediscover to prevent/minimize gaps
* use a subquery
* add overview graph
* port health mempools table
* Update device mempool
* only show overview if multiple
* Don't override user set warn percentages in discovery
* fix missed usage
* fix style
* Safety check to not rename rrd files incorrectly if migration has not been run.
* Fix overview percent bar and represent available and used on the bar
* missed an item to convert to mempool_class
* percent on the wrong side
2020-11-23 15:35:35 -06:00
|
|
|
/**
|
|
|
|
* @param string $name Name of the field in yaml
|
|
|
|
* @param string $index index in the snmp table
|
|
|
|
* @param int $count current count of snmp table entries
|
|
|
|
* @param array $def yaml definition
|
|
|
|
* @param array $pre_cache snmp data fetched from device
|
|
|
|
* @return mixed|string|string[]|null
|
|
|
|
*/
|
|
|
|
public static function replaceValues($name, $index, $count, $def, $pre_cache)
|
2018-02-05 07:39:13 -06:00
|
|
|
{
|
Modernize mempools (#12282)
* mempools to modern module
quick hacky hrstorage port
* port ucd-snmp-mib to Mempools
* Populate DB for ucd
Prep for yaml
* initial yaml attempt
* more complex conversions
fixes to YamlDiscovery, make leading $ optional and allow mib::oid format
* walk full tables and skip values
normalize percentages above 100
* handle precent only ones (specify total as 100)
* Move default polling out of YamlMempoolsDiscovery
* fixes
* Update test data hrstorage should be correct.
* perc_warn for hrstorage
* Host Resources, record buffer, cached, and shared
* Host Resources is always better, don't do both HR and UCD
* fix unix, include warning levels
* variable size
* consolidate skip_values
* define mempools schema
* number instead of integer
* more schema refactor
* one more skip_values reference
* throw error for invalid oid translation
aos6
* a* and Cisco
* updated test data
* update almost all hrstorage data files
* b*
* c* with test data
use standard cache for hrStorage
* use cache for storage module too
* hand bsnmp properly
* bdcom
* exclude total oid from yaml so it is not polled
May add a way to ignore this behavior and poll it, but I don't know if that is needed.
* automatically handle percent only values
* ciscowlc
* only poll used or free if we have used, free, and total.
* fix skipping
* the dlinkoning
fix find value when value "name" is numeric
* support numeric oids
* dnos/ftos attempt
* I guess we can't filter on total > 0
* edgecos
* e*
* f WIP
* f*
* gwd (aka g*)
* h* + procurve
* i*
* j*
* m*
* support 0% used memory (however unlikely)
* n*
* CISCO-PROCESS-MIB memory, share cache with processors module
* ignore mempools with invalid total
* p*
* quanta
* r*
fix raisecom mibs terribly broken
* s-z
* style fixes
* Move VRP back to PHP and make it actually work
* fix zynos
* update schema
* Update Cisco processor data for description bug fixes
* fix comware processors
* comware mempools with memory size
default precision to 1
* sophos-xg updated data
* hrstorage use ram size for buffers, cache, and shared
* Show memory available instead of free in device overview
* UCD, use same rrd format, store available instead of free in the db.
* Calculate availability for HOST-RESOURCES-MIB
* Convert UCD to standard polling
* rename old rrd files
* initial graph work
* graph WIP
* Graph looking decent
* Graph looking decent for hr
* remove old ucd_graph code
* handle availability mempool
more graph cleanup
* color adjustments
* remove accidental free calculation
* Update test data and fix corner cases
* fis pfsense
* update schema
* add default value for mempool_class
* fix whitespace
* update schema
* update schema correctly
* one more time
* fortigate_1500d-sensors missing oids
* Update docs.
* fix indent
* add implements MempoolsDiscovery explicitly to OS
* remove ucd_memory graph references
remove unused device_memory graph
* remove unused functions
* set devices with mempools to rediscover to prevent/minimize gaps
* use a subquery
* add overview graph
* port health mempools table
* Update device mempool
* only show overview if multiple
* Don't override user set warn percentages in discovery
* fix missed usage
* fix style
* Safety check to not rename rrd files incorrectly if migration has not been run.
* Fix overview percent bar and represent available and used on the bar
* missed an item to convert to mempool_class
* percent on the wrong side
2020-11-23 15:35:35 -06:00
|
|
|
$value = static::getValueFromData($name, $index, $def, $pre_cache);
|
|
|
|
|
2018-02-05 07:39:13 -06:00
|
|
|
if (is_null($value)) {
|
|
|
|
// built in replacements
|
2019-03-05 04:17:14 +01:00
|
|
|
$search = [
|
|
|
|
'{{ $index }}',
|
|
|
|
'{{ $count }}',
|
|
|
|
];
|
|
|
|
$replace = [
|
|
|
|
$index,
|
|
|
|
$count,
|
|
|
|
];
|
|
|
|
|
|
|
|
// prepare the $subindexX match variable replacement
|
|
|
|
foreach (explode('.', $index) as $pos => $subindex) {
|
|
|
|
$search[] = '{{ $subindex' . $pos . ' }}';
|
|
|
|
$replace[] = $subindex;
|
|
|
|
}
|
|
|
|
|
Modernize mempools (#12282)
* mempools to modern module
quick hacky hrstorage port
* port ucd-snmp-mib to Mempools
* Populate DB for ucd
Prep for yaml
* initial yaml attempt
* more complex conversions
fixes to YamlDiscovery, make leading $ optional and allow mib::oid format
* walk full tables and skip values
normalize percentages above 100
* handle precent only ones (specify total as 100)
* Move default polling out of YamlMempoolsDiscovery
* fixes
* Update test data hrstorage should be correct.
* perc_warn for hrstorage
* Host Resources, record buffer, cached, and shared
* Host Resources is always better, don't do both HR and UCD
* fix unix, include warning levels
* variable size
* consolidate skip_values
* define mempools schema
* number instead of integer
* more schema refactor
* one more skip_values reference
* throw error for invalid oid translation
aos6
* a* and Cisco
* updated test data
* update almost all hrstorage data files
* b*
* c* with test data
use standard cache for hrStorage
* use cache for storage module too
* hand bsnmp properly
* bdcom
* exclude total oid from yaml so it is not polled
May add a way to ignore this behavior and poll it, but I don't know if that is needed.
* automatically handle percent only values
* ciscowlc
* only poll used or free if we have used, free, and total.
* fix skipping
* the dlinkoning
fix find value when value "name" is numeric
* support numeric oids
* dnos/ftos attempt
* I guess we can't filter on total > 0
* edgecos
* e*
* f WIP
* f*
* gwd (aka g*)
* h* + procurve
* i*
* j*
* m*
* support 0% used memory (however unlikely)
* n*
* CISCO-PROCESS-MIB memory, share cache with processors module
* ignore mempools with invalid total
* p*
* quanta
* r*
fix raisecom mibs terribly broken
* s-z
* style fixes
* Move VRP back to PHP and make it actually work
* fix zynos
* update schema
* Update Cisco processor data for description bug fixes
* fix comware processors
* comware mempools with memory size
default precision to 1
* sophos-xg updated data
* hrstorage use ram size for buffers, cache, and shared
* Show memory available instead of free in device overview
* UCD, use same rrd format, store available instead of free in the db.
* Calculate availability for HOST-RESOURCES-MIB
* Convert UCD to standard polling
* rename old rrd files
* initial graph work
* graph WIP
* Graph looking decent
* Graph looking decent for hr
* remove old ucd_graph code
* handle availability mempool
more graph cleanup
* color adjustments
* remove accidental free calculation
* Update test data and fix corner cases
* fis pfsense
* update schema
* add default value for mempool_class
* fix whitespace
* update schema
* update schema correctly
* one more time
* fortigate_1500d-sensors missing oids
* Update docs.
* fix indent
* add implements MempoolsDiscovery explicitly to OS
* remove ucd_memory graph references
remove unused device_memory graph
* remove unused functions
* set devices with mempools to rediscover to prevent/minimize gaps
* use a subquery
* add overview graph
* port health mempools table
* Update device mempool
* only show overview if multiple
* Don't override user set warn percentages in discovery
* fix missed usage
* fix style
* Safety check to not rename rrd files incorrectly if migration has not been run.
* Fix overview percent bar and represent available and used on the bar
* missed an item to convert to mempool_class
* percent on the wrong side
2020-11-23 15:35:35 -06:00
|
|
|
$value = str_replace($search, $replace, $def[$name]);
|
2018-02-05 07:39:13 -06:00
|
|
|
|
|
|
|
// search discovery data for values
|
Modernize mempools (#12282)
* mempools to modern module
quick hacky hrstorage port
* port ucd-snmp-mib to Mempools
* Populate DB for ucd
Prep for yaml
* initial yaml attempt
* more complex conversions
fixes to YamlDiscovery, make leading $ optional and allow mib::oid format
* walk full tables and skip values
normalize percentages above 100
* handle precent only ones (specify total as 100)
* Move default polling out of YamlMempoolsDiscovery
* fixes
* Update test data hrstorage should be correct.
* perc_warn for hrstorage
* Host Resources, record buffer, cached, and shared
* Host Resources is always better, don't do both HR and UCD
* fix unix, include warning levels
* variable size
* consolidate skip_values
* define mempools schema
* number instead of integer
* more schema refactor
* one more skip_values reference
* throw error for invalid oid translation
aos6
* a* and Cisco
* updated test data
* update almost all hrstorage data files
* b*
* c* with test data
use standard cache for hrStorage
* use cache for storage module too
* hand bsnmp properly
* bdcom
* exclude total oid from yaml so it is not polled
May add a way to ignore this behavior and poll it, but I don't know if that is needed.
* automatically handle percent only values
* ciscowlc
* only poll used or free if we have used, free, and total.
* fix skipping
* the dlinkoning
fix find value when value "name" is numeric
* support numeric oids
* dnos/ftos attempt
* I guess we can't filter on total > 0
* edgecos
* e*
* f WIP
* f*
* gwd (aka g*)
* h* + procurve
* i*
* j*
* m*
* support 0% used memory (however unlikely)
* n*
* CISCO-PROCESS-MIB memory, share cache with processors module
* ignore mempools with invalid total
* p*
* quanta
* r*
fix raisecom mibs terribly broken
* s-z
* style fixes
* Move VRP back to PHP and make it actually work
* fix zynos
* update schema
* Update Cisco processor data for description bug fixes
* fix comware processors
* comware mempools with memory size
default precision to 1
* sophos-xg updated data
* hrstorage use ram size for buffers, cache, and shared
* Show memory available instead of free in device overview
* UCD, use same rrd format, store available instead of free in the db.
* Calculate availability for HOST-RESOURCES-MIB
* Convert UCD to standard polling
* rename old rrd files
* initial graph work
* graph WIP
* Graph looking decent
* Graph looking decent for hr
* remove old ucd_graph code
* handle availability mempool
more graph cleanup
* color adjustments
* remove accidental free calculation
* Update test data and fix corner cases
* fis pfsense
* update schema
* add default value for mempool_class
* fix whitespace
* update schema
* update schema correctly
* one more time
* fortigate_1500d-sensors missing oids
* Update docs.
* fix indent
* add implements MempoolsDiscovery explicitly to OS
* remove ucd_memory graph references
remove unused device_memory graph
* remove unused functions
* set devices with mempools to rediscover to prevent/minimize gaps
* use a subquery
* add overview graph
* port health mempools table
* Update device mempool
* only show overview if multiple
* Don't override user set warn percentages in discovery
* fix missed usage
* fix style
* Safety check to not rename rrd files incorrectly if migration has not been run.
* Fix overview percent bar and represent available and used on the bar
* missed an item to convert to mempool_class
* percent on the wrong side
2020-11-23 15:35:35 -06:00
|
|
|
$value = preg_replace_callback('/{{ \$?([a-zA-Z0-9\-.:]+) }}/', function ($matches) use ($index, $def, $pre_cache) {
|
|
|
|
$replace = static::getValueFromData($matches[1], $index, $def, $pre_cache, null);
|
2018-02-05 07:39:13 -06:00
|
|
|
if (is_null($replace)) {
|
2019-03-14 03:04:50 +01:00
|
|
|
d_echo('Warning: No variable available to replace ' . $matches[1] . ".\n");
|
2020-09-21 14:54:51 +02:00
|
|
|
|
2019-03-14 03:04:50 +01:00
|
|
|
return ''; // remove the unavailable variable
|
2018-02-05 07:39:13 -06:00
|
|
|
}
|
2020-09-21 14:54:51 +02:00
|
|
|
|
2018-02-05 07:39:13 -06:00
|
|
|
return $replace;
|
|
|
|
}, $value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function for dynamic discovery to search for data from pre_cached snmp data
|
|
|
|
*
|
|
|
|
* @param string $name The name of the field from the discovery data or just an oid
|
2020-02-01 23:28:03 +01:00
|
|
|
* @param string $index The index of the current sensor
|
2018-02-05 07:39:13 -06:00
|
|
|
* @param array $discovery_data The discovery data for the current sensor
|
|
|
|
* @param array $pre_cache all pre-cached snmp data
|
|
|
|
* @param mixed $default The default value to return if data is not found
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public static function getValueFromData($name, $index, $discovery_data, $pre_cache, $default = null)
|
|
|
|
{
|
2020-04-10 13:24:49 +02:00
|
|
|
//create the sub-index values in order to try to match them with precache
|
|
|
|
foreach (explode('.', $index) as $pos => $sindex) {
|
|
|
|
$subindex[$pos] = $sindex;
|
|
|
|
}
|
2018-02-05 07:39:13 -06:00
|
|
|
if (isset($discovery_data[$name])) {
|
|
|
|
$name = $discovery_data[$name];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($pre_cache[$discovery_data['oid']][$index][$name])) {
|
|
|
|
return $pre_cache[$discovery_data['oid']][$index][$name];
|
|
|
|
}
|
|
|
|
|
Modernize mempools (#12282)
* mempools to modern module
quick hacky hrstorage port
* port ucd-snmp-mib to Mempools
* Populate DB for ucd
Prep for yaml
* initial yaml attempt
* more complex conversions
fixes to YamlDiscovery, make leading $ optional and allow mib::oid format
* walk full tables and skip values
normalize percentages above 100
* handle precent only ones (specify total as 100)
* Move default polling out of YamlMempoolsDiscovery
* fixes
* Update test data hrstorage should be correct.
* perc_warn for hrstorage
* Host Resources, record buffer, cached, and shared
* Host Resources is always better, don't do both HR and UCD
* fix unix, include warning levels
* variable size
* consolidate skip_values
* define mempools schema
* number instead of integer
* more schema refactor
* one more skip_values reference
* throw error for invalid oid translation
aos6
* a* and Cisco
* updated test data
* update almost all hrstorage data files
* b*
* c* with test data
use standard cache for hrStorage
* use cache for storage module too
* hand bsnmp properly
* bdcom
* exclude total oid from yaml so it is not polled
May add a way to ignore this behavior and poll it, but I don't know if that is needed.
* automatically handle percent only values
* ciscowlc
* only poll used or free if we have used, free, and total.
* fix skipping
* the dlinkoning
fix find value when value "name" is numeric
* support numeric oids
* dnos/ftos attempt
* I guess we can't filter on total > 0
* edgecos
* e*
* f WIP
* f*
* gwd (aka g*)
* h* + procurve
* i*
* j*
* m*
* support 0% used memory (however unlikely)
* n*
* CISCO-PROCESS-MIB memory, share cache with processors module
* ignore mempools with invalid total
* p*
* quanta
* r*
fix raisecom mibs terribly broken
* s-z
* style fixes
* Move VRP back to PHP and make it actually work
* fix zynos
* update schema
* Update Cisco processor data for description bug fixes
* fix comware processors
* comware mempools with memory size
default precision to 1
* sophos-xg updated data
* hrstorage use ram size for buffers, cache, and shared
* Show memory available instead of free in device overview
* UCD, use same rrd format, store available instead of free in the db.
* Calculate availability for HOST-RESOURCES-MIB
* Convert UCD to standard polling
* rename old rrd files
* initial graph work
* graph WIP
* Graph looking decent
* Graph looking decent for hr
* remove old ucd_graph code
* handle availability mempool
more graph cleanup
* color adjustments
* remove accidental free calculation
* Update test data and fix corner cases
* fis pfsense
* update schema
* add default value for mempool_class
* fix whitespace
* update schema
* update schema correctly
* one more time
* fortigate_1500d-sensors missing oids
* Update docs.
* fix indent
* add implements MempoolsDiscovery explicitly to OS
* remove ucd_memory graph references
remove unused device_memory graph
* remove unused functions
* set devices with mempools to rediscover to prevent/minimize gaps
* use a subquery
* add overview graph
* port health mempools table
* Update device mempool
* only show overview if multiple
* Don't override user set warn percentages in discovery
* fix missed usage
* fix style
* Safety check to not rename rrd files incorrectly if migration has not been run.
* Fix overview percent bar and represent available and used on the bar
* missed an item to convert to mempool_class
* percent on the wrong side
2020-11-23 15:35:35 -06:00
|
|
|
if (isset($pre_cache[$index][$name])) {
|
|
|
|
return $pre_cache[$index][$name];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($pre_cache[$name]) && ! is_numeric($name)) {
|
2018-02-05 07:39:13 -06:00
|
|
|
if (is_array($pre_cache[$name])) {
|
|
|
|
if (isset($pre_cache[$name][$index][$name])) {
|
|
|
|
return $pre_cache[$name][$index][$name];
|
2020-02-01 23:28:03 +01:00
|
|
|
} elseif (isset($pre_cache[$name][$index])) {
|
|
|
|
return $pre_cache[$name][$index];
|
2018-02-05 07:39:13 -06:00
|
|
|
} elseif (count($pre_cache[$name]) === 1) {
|
|
|
|
return current($pre_cache[$name]);
|
2020-04-10 13:24:49 +02:00
|
|
|
} elseif (isset($pre_cache[$name][$subindex[0]][$name])) {
|
|
|
|
return $pre_cache[$name][$subindex[0]][$name];
|
2018-02-05 07:39:13 -06:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return $pre_cache[$name];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function preCache(OS $os)
|
|
|
|
{
|
|
|
|
// Pre-cache data for later use
|
2020-09-21 14:54:51 +02:00
|
|
|
$pre_cache = [];
|
2020-09-18 08:12:07 -05:00
|
|
|
$device = $os->getDeviceArray();
|
2018-02-05 07:39:13 -06:00
|
|
|
|
|
|
|
$pre_cache_file = 'includes/discovery/sensors/pre-cache/' . $device['os'] . '.inc.php';
|
|
|
|
if (is_file($pre_cache_file)) {
|
|
|
|
echo "Pre-cache {$device['os']}: ";
|
|
|
|
include $pre_cache_file;
|
|
|
|
echo PHP_EOL;
|
|
|
|
d_echo($pre_cache);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO change to exclude os with pre-cache php file, but just exclude them by hand for now (like avtech)
|
|
|
|
if ($device['os'] == 'avtech') {
|
|
|
|
return $pre_cache;
|
|
|
|
}
|
|
|
|
|
2020-09-21 14:54:51 +02:00
|
|
|
if (! empty($device['dynamic_discovery']['modules'])) {
|
2020-09-21 15:59:34 +02:00
|
|
|
echo 'Caching data: ';
|
2018-02-05 07:39:13 -06:00
|
|
|
foreach ($device['dynamic_discovery']['modules'] as $module => $discovery_data) {
|
|
|
|
echo "$module ";
|
|
|
|
foreach ($discovery_data as $key => $data_array) {
|
|
|
|
// find the data array, we could already be at for simple modules
|
|
|
|
if (isset($data_array['data'])) {
|
|
|
|
$data_array = $data_array['data'];
|
|
|
|
} elseif ($key !== 'data') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($data_array as $data) {
|
2020-09-21 14:54:51 +02:00
|
|
|
foreach ((array) $data['oid'] as $oid) {
|
|
|
|
if (! array_key_exists($oid, $pre_cache)) {
|
2018-02-05 07:39:13 -06:00
|
|
|
if (isset($data['snmp_flags'])) {
|
2020-04-17 17:37:56 -05:00
|
|
|
$snmp_flag = Arr::wrap($data['snmp_flags']);
|
2018-02-05 07:39:13 -06:00
|
|
|
} else {
|
2018-12-16 07:42:50 -06:00
|
|
|
$snmp_flag = ['-OteQUs'];
|
2018-02-05 07:39:13 -06:00
|
|
|
}
|
2018-12-16 07:42:50 -06:00
|
|
|
$snmp_flag[] = '-Ih';
|
2018-02-05 07:39:13 -06:00
|
|
|
|
|
|
|
$mib = $device['dynamic_discovery']['mib'];
|
|
|
|
$pre_cache[$oid] = snmpwalk_cache_oid($device, $oid, $pre_cache[$oid], $mib, null, $snmp_flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo PHP_EOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $pre_cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check to see if we should skip this discovery item
|
|
|
|
*
|
|
|
|
* @param mixed $value
|
|
|
|
* @param array $yaml_item_data The data key from this item
|
|
|
|
* @param array $group_options The options key from this group of items
|
Modernize mempools (#12282)
* mempools to modern module
quick hacky hrstorage port
* port ucd-snmp-mib to Mempools
* Populate DB for ucd
Prep for yaml
* initial yaml attempt
* more complex conversions
fixes to YamlDiscovery, make leading $ optional and allow mib::oid format
* walk full tables and skip values
normalize percentages above 100
* handle precent only ones (specify total as 100)
* Move default polling out of YamlMempoolsDiscovery
* fixes
* Update test data hrstorage should be correct.
* perc_warn for hrstorage
* Host Resources, record buffer, cached, and shared
* Host Resources is always better, don't do both HR and UCD
* fix unix, include warning levels
* variable size
* consolidate skip_values
* define mempools schema
* number instead of integer
* more schema refactor
* one more skip_values reference
* throw error for invalid oid translation
aos6
* a* and Cisco
* updated test data
* update almost all hrstorage data files
* b*
* c* with test data
use standard cache for hrStorage
* use cache for storage module too
* hand bsnmp properly
* bdcom
* exclude total oid from yaml so it is not polled
May add a way to ignore this behavior and poll it, but I don't know if that is needed.
* automatically handle percent only values
* ciscowlc
* only poll used or free if we have used, free, and total.
* fix skipping
* the dlinkoning
fix find value when value "name" is numeric
* support numeric oids
* dnos/ftos attempt
* I guess we can't filter on total > 0
* edgecos
* e*
* f WIP
* f*
* gwd (aka g*)
* h* + procurve
* i*
* j*
* m*
* support 0% used memory (however unlikely)
* n*
* CISCO-PROCESS-MIB memory, share cache with processors module
* ignore mempools with invalid total
* p*
* quanta
* r*
fix raisecom mibs terribly broken
* s-z
* style fixes
* Move VRP back to PHP and make it actually work
* fix zynos
* update schema
* Update Cisco processor data for description bug fixes
* fix comware processors
* comware mempools with memory size
default precision to 1
* sophos-xg updated data
* hrstorage use ram size for buffers, cache, and shared
* Show memory available instead of free in device overview
* UCD, use same rrd format, store available instead of free in the db.
* Calculate availability for HOST-RESOURCES-MIB
* Convert UCD to standard polling
* rename old rrd files
* initial graph work
* graph WIP
* Graph looking decent
* Graph looking decent for hr
* remove old ucd_graph code
* handle availability mempool
more graph cleanup
* color adjustments
* remove accidental free calculation
* Update test data and fix corner cases
* fis pfsense
* update schema
* add default value for mempool_class
* fix whitespace
* update schema
* update schema correctly
* one more time
* fortigate_1500d-sensors missing oids
* Update docs.
* fix indent
* add implements MempoolsDiscovery explicitly to OS
* remove ucd_memory graph references
remove unused device_memory graph
* remove unused functions
* set devices with mempools to rediscover to prevent/minimize gaps
* use a subquery
* add overview graph
* port health mempools table
* Update device mempool
* only show overview if multiple
* Don't override user set warn percentages in discovery
* fix missed usage
* fix style
* Safety check to not rename rrd files incorrectly if migration has not been run.
* Fix overview percent bar and represent available and used on the bar
* missed an item to convert to mempool_class
* percent on the wrong side
2020-11-23 15:35:35 -06:00
|
|
|
* @param array $pre_cache The pre-cache data array
|
2018-02-05 07:39:13 -06:00
|
|
|
* @return bool
|
|
|
|
*/
|
2020-09-21 14:54:51 +02:00
|
|
|
public static function canSkipItem($value, $index, $yaml_item_data, $group_options, $pre_cache = [])
|
2018-02-05 07:39:13 -06:00
|
|
|
{
|
2020-09-21 14:54:51 +02:00
|
|
|
$skip_values = array_replace((array) $group_options['skip_values'], (array) $yaml_item_data['skip_values']);
|
2018-02-05 07:39:13 -06:00
|
|
|
|
|
|
|
foreach ($skip_values as $skip_value) {
|
2018-12-05 19:40:29 +01:00
|
|
|
if (is_array($skip_value) && $pre_cache) {
|
2018-02-05 07:39:13 -06:00
|
|
|
// Dynamic skipping of data
|
2020-09-12 16:26:20 -05:00
|
|
|
$op = $skip_value['op'] ?? '!=';
|
2018-12-05 19:40:29 +01:00
|
|
|
$tmp_value = static::getValueFromData($skip_value['oid'], $index, $yaml_item_data, $pre_cache);
|
2020-04-17 17:37:56 -05:00
|
|
|
if (Str::contains($skip_value['oid'], '.')) {
|
2020-09-12 16:26:20 -05:00
|
|
|
[$skip_value['oid'], $targeted_index] = explode('.', $skip_value['oid'], 2);
|
2020-02-01 23:28:03 +01:00
|
|
|
$tmp_value = static::getValueFromData($skip_value['oid'], $targeted_index, $yaml_item_data, $pre_cache);
|
|
|
|
}
|
2018-02-05 07:39:13 -06:00
|
|
|
if (compare_var($tmp_value, $skip_value['value'], $op)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($value == $skip_value) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-21 14:54:51 +02:00
|
|
|
$skip_value_lt = array_replace((array) $group_options['skip_value_lt'], (array) $yaml_item_data['skip_value_lt']);
|
2018-02-05 07:39:13 -06:00
|
|
|
foreach ($skip_value_lt as $skip_value) {
|
|
|
|
if ($value < $skip_value) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-21 14:54:51 +02:00
|
|
|
$skip_value_gt = array_replace((array) $group_options['skip_value_gt'], (array) $yaml_item_data['skip_value_gt']);
|
2018-02-05 07:39:13 -06:00
|
|
|
foreach ($skip_value_gt as $skip_value) {
|
|
|
|
if ($value > $skip_value) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
Modernize mempools (#12282)
* mempools to modern module
quick hacky hrstorage port
* port ucd-snmp-mib to Mempools
* Populate DB for ucd
Prep for yaml
* initial yaml attempt
* more complex conversions
fixes to YamlDiscovery, make leading $ optional and allow mib::oid format
* walk full tables and skip values
normalize percentages above 100
* handle precent only ones (specify total as 100)
* Move default polling out of YamlMempoolsDiscovery
* fixes
* Update test data hrstorage should be correct.
* perc_warn for hrstorage
* Host Resources, record buffer, cached, and shared
* Host Resources is always better, don't do both HR and UCD
* fix unix, include warning levels
* variable size
* consolidate skip_values
* define mempools schema
* number instead of integer
* more schema refactor
* one more skip_values reference
* throw error for invalid oid translation
aos6
* a* and Cisco
* updated test data
* update almost all hrstorage data files
* b*
* c* with test data
use standard cache for hrStorage
* use cache for storage module too
* hand bsnmp properly
* bdcom
* exclude total oid from yaml so it is not polled
May add a way to ignore this behavior and poll it, but I don't know if that is needed.
* automatically handle percent only values
* ciscowlc
* only poll used or free if we have used, free, and total.
* fix skipping
* the dlinkoning
fix find value when value "name" is numeric
* support numeric oids
* dnos/ftos attempt
* I guess we can't filter on total > 0
* edgecos
* e*
* f WIP
* f*
* gwd (aka g*)
* h* + procurve
* i*
* j*
* m*
* support 0% used memory (however unlikely)
* n*
* CISCO-PROCESS-MIB memory, share cache with processors module
* ignore mempools with invalid total
* p*
* quanta
* r*
fix raisecom mibs terribly broken
* s-z
* style fixes
* Move VRP back to PHP and make it actually work
* fix zynos
* update schema
* Update Cisco processor data for description bug fixes
* fix comware processors
* comware mempools with memory size
default precision to 1
* sophos-xg updated data
* hrstorage use ram size for buffers, cache, and shared
* Show memory available instead of free in device overview
* UCD, use same rrd format, store available instead of free in the db.
* Calculate availability for HOST-RESOURCES-MIB
* Convert UCD to standard polling
* rename old rrd files
* initial graph work
* graph WIP
* Graph looking decent
* Graph looking decent for hr
* remove old ucd_graph code
* handle availability mempool
more graph cleanup
* color adjustments
* remove accidental free calculation
* Update test data and fix corner cases
* fis pfsense
* update schema
* add default value for mempool_class
* fix whitespace
* update schema
* update schema correctly
* one more time
* fortigate_1500d-sensors missing oids
* Update docs.
* fix indent
* add implements MempoolsDiscovery explicitly to OS
* remove ucd_memory graph references
remove unused device_memory graph
* remove unused functions
* set devices with mempools to rediscover to prevent/minimize gaps
* use a subquery
* add overview graph
* port health mempools table
* Update device mempool
* only show overview if multiple
* Don't override user set warn percentages in discovery
* fix missed usage
* fix style
* Safety check to not rename rrd files incorrectly if migration has not been run.
* Fix overview percent bar and represent available and used on the bar
* missed an item to convert to mempool_class
* percent on the wrong side
2020-11-23 15:35:35 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Translate an oid to numeric format (if already numeric, return as-is)
|
|
|
|
*
|
|
|
|
* @param string $oid
|
|
|
|
* @param array|null $device
|
|
|
|
* @param string $mib
|
|
|
|
* @param string|null $mibdir
|
|
|
|
* @return string numeric oid
|
|
|
|
* @throws \LibreNMS\Exceptions\InvalidOidException
|
|
|
|
*/
|
|
|
|
public static function oidToNumeric($oid, $device = null, $mib = 'ALL', $mibdir = null)
|
|
|
|
{
|
|
|
|
if (self::oidIsNumeric($oid)) {
|
|
|
|
return $oid;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (explode(':', $mib) as $mib_name) {
|
|
|
|
if ($numeric_oid = snmp_translate($oid, $mib_name, $mibdir, null, $device)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($numeric_oid)) {
|
|
|
|
throw new InvalidOidException("Unable to translate oid $oid");
|
|
|
|
}
|
|
|
|
|
|
|
|
return $numeric_oid;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function oidIsNumeric($oid)
|
|
|
|
{
|
|
|
|
return (bool) preg_match('/^[.\d]+$/', $oid);
|
|
|
|
}
|
2018-02-05 07:39:13 -06:00
|
|
|
}
|