refactor: Use the Config class includes/discovery (#7299)

* refactor: use the Config class includes/discovery

* fix issue with $config variable not accessible in include-dir.inc.php

* improved whitespace

* Tidy up discovery_by_ip
This commit is contained in:
Tony Murray
2017-09-11 15:26:41 -05:00
committed by Neil Lathwood
parent 9cafcb6280
commit b18c41b1a9
26 changed files with 192 additions and 162 deletions

View File

@@ -23,6 +23,8 @@
* @author Tony Murray <murraytony@gmail.com>
*/
use LibreNMS\Config;
echo "\nApplications: ";
// fetch applications from the client
@@ -31,7 +33,7 @@ $results = snmpwalk_cache_oid($device, 'nsExtendStatus', array(), 'NET-SNMP-EXTE
// Load our list of available applications
$applications = array();
if ($results) {
foreach (glob($config['install_dir'] . '/includes/polling/applications/*.inc.php') as $file) {
foreach (glob(Config::get('install_dir') . '/includes/polling/applications/*.inc.php') as $file) {
$name = basename($file, '.inc.php');
$applications[$name] = $name;
}

View File

@@ -23,6 +23,8 @@
* @author Tony Murray <murraytony@gmail.com>
*/
use LibreNMS\Config;
if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0)) {
$vrfs_lite_cisco = $device['vrf_lite_cisco'];
} else {
@@ -33,8 +35,8 @@ foreach ($vrfs_lite_cisco as $vrf) {
$context = $vrf['context_name'];
$device['context_name']=$context;
if (file_exists($config['install_dir'] . "/includes/discovery/arp-table/{$device['os']}.inc.php")) {
include $config['install_dir'] . "/includes/discovery/arp-table/{$device['os']}.inc.php";
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";
} else {
$arp_data = snmpwalk_group($device, 'ipNetToPhysicalPhysAddress', 'IP-MIB');
$arp_data = snmpwalk_group($device, 'ipNetToMediaPhysAddress', 'IP-MIB', 1, $arp_data);

View File

@@ -1,8 +1,9 @@
<?php
use LibreNMS\Config;
use LibreNMS\Util\IP;
if ($config['enable_bgp']) {
if (Config::get('enable_bgp')) {
if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0)) {
$vrfs_lite_cisco = $device['vrf_lite_cisco'];
} else {

View File

@@ -1,6 +1,8 @@
<?php
if ($config['enable_pseudowires'] && $device['os_group'] == 'cisco') {
use LibreNMS\Config;
if (Config::get('enable_pseudowires') && $device['os_group'] == 'cisco') {
unset($cpw_count);
unset($cpw_exists);

View File

@@ -1,8 +1,9 @@
<?php
use LibreNMS\Config;
use LibreNMS\Util\IP;
if ($config['enable_sla'] && $device['os_group'] == 'cisco') {
if (Config::get('enable_sla') && $device['os_group'] == 'cisco') {
$slas = snmp_walk($device, 'ciscoRttMonMIB.ciscoRttMonObjects.rttMonCtrl', '-Osq', '+CISCO-RTTMON-MIB');
$sla_table = array();

View File

@@ -18,7 +18,9 @@
global $debug;
// This one only will work with the CISCO-CONTEXT-MAPPING-MIB V2 of cisco
if ($config['enable_vrf_lite_cisco']) {
use LibreNMS\Config;
if (Config::get('enable_vrf_lite_cisco')) {
$ids = array();
// For the moment only will be cisco and the version 3
@@ -42,15 +44,15 @@ if ($config['enable_vrf_lite_cisco']) {
}
}
unset($listVrf);
$listIntance = snmp_walk($device, "cContextMappingProtoInstName", "-Osq -Ln", $mib, null);
$listIntance = str_replace("cContextMappingProtoInstName.", "", $listIntance);
$listIntance = str_replace('"', "", $listIntance);
$listIntance = trim($listIntance);
d_echo("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n");
d_echo("\n[DEBUG]\n List Intance only names\n$listIntance\n[/DEBUG]\n");
foreach (explode("\n", $listIntance) as $lineIntance) {
$tmpIntance = explode(" ", $lineIntance, 2);
//the $tmpIntance[0] will be the context and $tmpIntance[1] the intance
@@ -72,7 +74,7 @@ if ($config['enable_vrf_lite_cisco']) {
if (!empty($tmpVrf)) {
$ids[$tmpVrf['vrf_lite_cisco_id']] = $tmpVrf['vrf_lite_cisco_id'];
$vrfUpdate=array();
foreach ($vrfUpdate as $key => $value) {
if ($vrf[$key]!=$value) {
$vrfUpdate[$key]=$value;

View File

@@ -1,7 +1,8 @@
<?php
// FIXME : dbFacile !
if ($config['enable_vrfs']) {
use LibreNMS\Config;
if (Config::get('enable_vrfs')) {
if ($device['os_group'] == 'cisco' || $device['os_group'] == 'junos' || $device['os'] == 'ironware') {
unset($vrf_count);

View File

@@ -13,6 +13,8 @@
// License: GPLv3
//
use LibreNMS\Config;
$hostname = $device['hostname'];
$deviceid = $device['device_id'];
@@ -36,8 +38,6 @@ $names = array();
$ips = array();
foreach (dbFetchRows($sql, array($deviceid)) as $entry) {
global $config;
$ip = $entry['ipv4_address'];
$mac = $entry['mac_address'];
$if = $entry['port_id'];
@@ -46,12 +46,12 @@ foreach (dbFetchRows($sql, array($deviceid)) as $entry) {
// Even though match_network is done inside discover_new_device, we do it here
// as well in order to skip unnecessary reverse DNS lookups on discovered IPs.
if (match_network($config['autodiscovery']['nets-exclude'], $ip)) {
if (match_network(Config::get('autodiscovery.nets-exclude'), $ip)) {
echo 'x';
continue;
}
if (!match_network($config['nets'], $ip)) {
if (!match_network(Config::get('nets'), $ip)) {
echo 'i';
log_event("Ignored $ip", $deviceid, 'interface', 3, $if);
continue;

View File

@@ -2,11 +2,12 @@
global $link_exists;
use LibreNMS\Config;
use LibreNMS\Util\IP;
$community = $device['community'];
if ($device['os'] == 'ironware' && $config['autodiscovery']['xdp'] === true) {
if ($device['os'] == 'ironware' && Config::get('autodiscovery.xdp') === true) {
echo ' Brocade FDP: ';
$fdp_array = snmpwalk_cache_twopart_oid($device, 'snFdpCacheEntry', array(), 'FOUNDRY-SN-SWITCH-GROUP-MIB');
d_echo($fdp_array);
@@ -19,8 +20,8 @@ if ($device['os'] == 'ironware' && $config['autodiscovery']['xdp'] === true) {
$remote_device_id = dbFetchCell('SELECT `device_id` FROM `devices` WHERE `sysName` = ? OR `hostname` = ?', array($fdp['snFdpCacheDeviceId'], $fdp['snFdpCacheDeviceId']));
if (!$remote_device_id &&
!can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysname_regexp'], $fdp['snFdpCacheDeviceId'], $fdp['snFdpCacheDeviceId']) &&
!can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysdesc_regexp'], $fdp['snFdpCacheVersion'], $fdp['snFdpCacheDeviceId'])
!can_skip_discovery(Config::get('autodiscovery.xdp_exclude.sysname_regexp'), $fdp['snFdpCacheDeviceId'], $fdp['snFdpCacheDeviceId']) &&
!can_skip_discovery(Config::get('autodiscovery.xdp_exclude.sysdesc_regexp'), $fdp['snFdpCacheVersion'], $fdp['snFdpCacheDeviceId'])
) {
$remote_device_id = discover_new_device($fdp['snFdpCacheDeviceId'], $device, 'FDP', $interface);
}
@@ -40,7 +41,7 @@ if ($device['os'] == 'ironware' && $config['autodiscovery']['xdp'] === true) {
echo ' CISCO-CDP-MIB: ';
unset($cdp_array);
if ($config['autodiscovery']['xdp'] === true) {
if (Config::get('autodiscovery.xdp') === true) {
$cdp_array = snmpwalk_cache_twopart_oid($device, 'cdpCache', array(), 'CISCO-CDP-MIB');
d_echo($cdp_array);
if ($cdp_array) {
@@ -49,19 +50,19 @@ if ($config['autodiscovery']['xdp'] === true) {
$interface = get_port_by_ifIndex($device['device_id'], $key);
d_echo($cdp_if_array);
foreach ($cdp_if_array as $entry_key => $cdp) {
if (is_valid_hostname($cdp['cdpCacheDeviceId']) || ($config['discovery_by_ip'] == true)) {
if (is_valid_hostname($cdp['cdpCacheDeviceId']) || Config::get('discovery_by_ip', false)) {
$cdp_ip = IP::fromHexString($cdp['cdpCacheAddress'], true);
$remote_device_id = dbFetchCell('SELECT `device_id` FROM `devices` WHERE `sysName` = ? OR `hostname` = ? OR `hostname` = ?', array($cdp['cdpCacheDeviceId'], $cdp['cdpCacheDeviceId'], $cdp_ip));
if (!$remote_device_id &&
!can_skip_discovery($config['autodiscovery']['cdp_exclude']['platform_regexp'], $cdp['cdpCachePlatform'], $cdp['cdpCacheDeviceId']) &&
!can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysname_regexp'], $cdp['cdpCacheDeviceId'], $cdp['cdpCacheDeviceId']) &&
!can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysdesc_regexp'], $cdp['cdpCacheVersion'], $cdp['cdpCacheDeviceId'])
!can_skip_discovery(Config::get('autodiscovery.cdp_exclude.platform_regexp'), $cdp['cdpCachePlatform'], $cdp['cdpCacheDeviceId']) &&
!can_skip_discovery(Config::get('autodiscovery.xdp_exclude.sysname_regexp'), $cdp['cdpCacheDeviceId'], $cdp['cdpCacheDeviceId']) &&
!can_skip_discovery(Config::get('autodiscovery.xdp_exclude.sysdesc_regexp'), $cdp['cdpCacheVersion'], $cdp['cdpCacheDeviceId'])
) {
if ($config['discovery_by_ip'] !== true) {
$remote_device_id = discover_new_device($cdp['cdpCacheDeviceId'], $device, 'CDP', $interface);
} else {
if (Config::get('discovery_by_ip', false)) {
$remote_device_id = discover_new_device($cdp_ip, $device, 'CDP', $interface);
} else {
$remote_device_id = discover_new_device($cdp['cdpCacheDeviceId'], $device, 'CDP', $interface);
}
}
@@ -88,7 +89,7 @@ unset(
$cdp_array
);
if ($device['os'] == 'pbn' && $config['autodiscovery']['xdp'] === true) {
if ($device['os'] == 'pbn' && Config::get('autodiscovery.xdp') === true) {
echo ' NMS-LLDP-MIB: ';
$lldp_array = snmpwalk_cache_oid($device, 'lldpRemoteSystemsData', array(), 'NMS-LLDP-MIB', 'pbn');
d_echo($lldp_array);
@@ -101,8 +102,8 @@ if ($device['os'] == 'pbn' && $config['autodiscovery']['xdp'] === true) {
if (!$remote_device_id &&
is_valid_hostname($lldp['lldpRemSysName']) &&
!can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysname_regexp'], $lldp['lldpRemSysName'], $lldp['lldpRemSysName']) &&
!can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysdesc_regexp'], $lldp['lldpRemSysDesc'], $lldp['lldpRemSysName'])
!can_skip_discovery(Config::get('autodiscovery.xdp_exclude.sysname_regexp'), $lldp['lldpRemSysName'], $lldp['lldpRemSysName']) &&
!can_skip_discovery(Config::get('autodiscovery.xdp_exclude.sysdesc_regexp'), $lldp['lldpRemSysDesc'], $lldp['lldpRemSysName'])
) {
$remote_device_id = discover_new_device($lldp['lldpRemSysName'], $device, 'LLDP', $interface);
}
@@ -120,7 +121,7 @@ if ($device['os'] == 'pbn' && $config['autodiscovery']['xdp'] === true) {
}
}//end foreach
}//end if
} elseif ($config['autodiscovery']['xdp'] === true) {
} elseif (Config::get('autodiscovery.xdp') === true) {
echo ' LLDP-MIB: ';
$lldp_array = snmpwalk_cache_threepart_oid($device, 'lldpRemoteSystemsData', array(), 'LLDP-MIB');
d_echo($lldp_array);
@@ -143,8 +144,8 @@ if ($device['os'] == 'pbn' && $config['autodiscovery']['xdp'] === true) {
$remote_device_id = dbFetchCell('SELECT `device_id` FROM `devices` WHERE `sysName` = ? OR `hostname` = ?', array($lldp['lldpRemSysName'], $lldp['lldpRemSysName']));
if (!$remote_device_id && is_valid_hostname($lldp['lldpRemSysName'])) {
if (!can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysname_regexp'], $lldp['lldpRemSysName'], $lldp['lldpRemSysName']) &&
!can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysdesc_regexp'], $lldp['lldpRemSysDesc'], $lldp['lldpRemSysName'])
if (!can_skip_discovery(Config::get('autodiscovery.xdp_exclude.sysname_regexp'), $lldp['lldpRemSysName'], $lldp['lldpRemSysName']) &&
!can_skip_discovery(Config::get('autodiscovery.xdp_exclude.sysdesc_regexp'), $lldp['lldpRemSysDesc'], $lldp['lldpRemSysName'])
) {
$remote_device_id = discover_new_device($lldp['lldpRemSysName'], $device, 'LLDP', $interface);
if (is_numeric($remote_device_id) === false) {
@@ -205,16 +206,16 @@ unset(
echo ' OSPF Discovery: ';
if ($config['autodiscovery']['ospf'] === true) {
if (Config::get('autodiscovery.ospf') === true) {
echo "enabled\n";
foreach (dbFetchRows('SELECT DISTINCT(`ospfNbrIpAddr`),`device_id` FROM `ospf_nbrs` WHERE `device_id`=?', array($device['device_id'])) as $nbr) {
$ip = $nbr['ospfNbrIpAddr'];
if (match_network($config['autodiscovery']['nets-exclude'], $ip)) {
if (match_network(Config::get('autodiscovery.nets-exclude'), $ip)) {
echo 'x';
continue;
}
if (!match_network($config['nets'], $ip)) {
if (!match_network(Config::get('nets'), $ip)) {
echo 'i';
continue;
}

View File

@@ -1,6 +1,8 @@
<?php
if ($config['enable_inventory']) {
use LibreNMS\Config;
if (Config::get('enable_inventory')) {
// Legacy entPhysical - junos/timos/cisco
include 'includes/discovery/entity-physical/entity-physical.inc.php';

View File

@@ -1,6 +1,8 @@
<?php
// Build a dictionary of vlans in database
use LibreNMS\Config;
$vlans_dict = array();
foreach (dbFetchRows("SELECT `vlan_id`, `vlan_vlan` from `vlans` WHERE `device_id` = ?", array($device['device_id'])) as $vlan_entry) {
$vlans_dict[$vlan_entry['vlan_vlan']] = $vlan_entry['vlan_id'];
@@ -15,13 +17,13 @@ foreach ($sql_result as $entry) {
}
$insert = array(); // populate $insert with database entries
if (file_exists($config['install_dir'] . "/includes/discovery/fdb-table/{$device['os']}.inc.php")) {
require $config['install_dir'] . "/includes/discovery/fdb-table/{$device['os']}.inc.php";
if (file_exists(Config::get('install_dir') . "/includes/discovery/fdb-table/{$device['os']}.inc.php")) {
require Config::get('install_dir') . "/includes/discovery/fdb-table/{$device['os']}.inc.php";
} elseif ($device['os'] == 'ios' || $device['os'] == 'iosxe') {
include $config['install_dir'] . '/includes/discovery/fdb-table/ios.inc.php';
include Config::get('install_dir') . '/includes/discovery/fdb-table/ios.inc.php';
} else {
// Check generic Q-BRIDGE-MIB and BRIDGE-MIB
include $config['install_dir'] . '/includes/discovery/fdb-table/bridge.inc.php';
include Config::get('install_dir') . '/includes/discovery/fdb-table/bridge.inc.php';
}
if (!empty($insert)) {

View File

@@ -12,16 +12,15 @@
* See COPYING for more details.
*/
use LibreNMS\Config;
use LibreNMS\Exceptions\HostExistsException;
use LibreNMS\Util\IP;
use LibreNMS\Util\IPv6;
function discover_new_device($hostname, $device = '', $method = '', $interface = '')
{
global $config;
if (!empty($config['mydomain'])) {
$full_host = rtrim($hostname, '.') . '.' . $config['mydomain'];
if (Config::has('mydomain')) {
$full_host = rtrim($hostname, '.') . '.' . Config::get('mydomain');
if (isDomainResolves($full_host)) {
$hostname = $full_host;
}
@@ -40,7 +39,7 @@ function discover_new_device($hostname, $device = '', $method = '', $interface =
}
} elseif (filter_var($hostname, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === true || filter_var($hostname, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === true) {
// gethostbyname returned a valid $ip, was $dst_host an IP?
if ($config['discovery_by_ip'] === false) {
if (!Config::get('discovery_by_ip', false)) {
d_echo('Discovery by IP disabled, skipping ' . $hostname);
log_event("$method discovery of " . $hostname . " failed - Discovery by IP disabled", $device['device_id'], 'discovery', 4);
@@ -52,15 +51,15 @@ function discover_new_device($hostname, $device = '', $method = '', $interface =
$hostname = rtrim($hostname, '.');
// remove trailing dot
if (match_network($config['autodiscovery']['nets-exclude'], $ip)) {
if (match_network(Config::get('autodiscovery.nets-exclude'), $ip)) {
d_echo("$ip in an excluded network - skipping\n");
return false;
}
if (match_network($config['nets'], $ip)) {
if (match_network(Config::get('nets'), $ip)) {
try {
$remote_device_id = addHost($hostname, '', '161', 'udp', $config['distributed_poller_group']);
$remote_device_id = addHost($hostname, '', '161', 'udp', Config::get('distributed_poller_group'));
$remote_device = device_by_id_cache($remote_device_id, 1);
echo '+[' . $remote_device['hostname'] . '(' . $remote_device['device_id'] . ')]';
discover_device($remote_device);
@@ -94,8 +93,7 @@ function discover_new_device($hostname, $device = '', $method = '', $interface =
*/
function load_discovery(&$device)
{
global $config;
$yaml_discovery = $config['install_dir'] . '/includes/definitions/discovery/' . $device['os'] . '.yaml';
$yaml_discovery = Config::get('install_dir') . '/includes/definitions/discovery/' . $device['os'] . '.yaml';
if (file_exists($yaml_discovery)) {
$device['dynamic_discovery'] = Symfony\Component\Yaml\Yaml::parse(
file_get_contents($yaml_discovery)
@@ -106,7 +104,7 @@ function load_discovery(&$device)
function discover_device(&$device, $options = null)
{
global $config, $valid;
global $valid;
$valid = array();
// Reset $valid array
@@ -136,25 +134,23 @@ function discover_device(&$device, $options = null)
load_os($device);
load_discovery($device);
if (is_array($config['os'][$device['os']]['register_mibs'])) {
register_mibs($device, $config['os'][$device['os']]['register_mibs'], 'includes/discovery/os/' . $device['os'] . '.inc.php');
}
register_mibs($device, Config::getOsSetting($device, 'register_mibs', array()), 'includes/discovery/os/' . $device['os'] . '.inc.php');
echo "\n";
// If we've specified modules, use them, else walk the modules array
$force_module = false;
if ($options['m']) {
$config['discovery_modules'] = array();
Config::set('discovery_modules', array());
foreach (explode(',', $options['m']) as $module) {
if (is_file("includes/discovery/$module.inc.php")) {
$config['discovery_modules'][$module] = 1;
Config::set("discovery_modules.$module", 1);
$force_module = true;
}
}
}
foreach ($config['discovery_modules'] as $module => $module_status) {
$os_module_status = $config['os'][$device['os']]['discovery_modules'][$module];
foreach (Config::get('discovery_modules', array()) as $module => $module_status) {
$os_module_status = Config::getOsSetting($device, "discovery_modules.$module");
d_echo("Modules status: Global" . (isset($module_status) ? ($module_status ? '+ ' : '- ') : ' '));
d_echo("OS" . (isset($os_module_status) ? ($os_module_status ? '+ ' : '- ') : ' '));
d_echo("Device" . (isset($attribs['discover_' . $module]) ? ($attribs['discover_' . $module] ? '+ ' : '- ') : ' '));
@@ -802,22 +798,16 @@ function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen
*/
function check_entity_sensor($string, $device)
{
global $config;
$valid = true;
$string = strtolower($string);
if (is_array($config['bad_entity_sensor_regex'])) {
$fringe = $config['bad_entity_sensor_regex'];
if (is_array($config['os'][$device['os']]['bad_entity_sensor_regex'])) {
$fringe = array_merge($config['bad_entity_sensor_regex'], $config['os'][$device['os']]['bad_entity_sensor_regex']);
}
foreach ($fringe as $bad) {
if (preg_match($bad . "i", $string)) {
$valid = false;
d_echo("Ignored entity sensor: $bad : $string");
}
$fringe = array_merge(Config::get('bad_entity_sensor_regex', array()), Config::getOsSetting($device, 'bad_entity_sensor_regex', array()));
foreach ($fringe as $bad) {
if (preg_match($bad . "i", $string)) {
d_echo("Ignored entity sensor: $bad : $string");
return false;
}
}
return $valid;
return true;
}
@@ -1005,35 +995,33 @@ function get_toner_capacity($raw_capacity)
}
/**
* @param $descr
* @return int
* @param string $descr
* @return bool
*/
function ignore_storage($descr)
{
global $config;
$deny = 0;
foreach ($config['ignore_mount'] as $bi) {
foreach (Config::get('ignore_mount', array()) as $bi) {
if ($bi == $descr) {
$deny = 1;
d_echo("$bi == $descr \n");
return true;
}
}
foreach ($config['ignore_mount_string'] as $bi) {
if (strpos($descr, $bi) !== false) {
$deny = 1;
foreach (Config::get('ignore_mount_string', array()) as $bi) {
if (str_contains($descr, $bi)) {
d_echo("strpos: $descr, $bi \n");
return true;
}
}
foreach ($config['ignore_mount_regexp'] as $bi) {
if (preg_match($bi, $descr) > '0') {
$deny = 1;
foreach (Config::get('ignore_mount_regexp', array()) as $bi) {
if (preg_match($bi, $descr)) {
d_echo("preg_match $bi, $descr \n");
return true;
}
}
return $deny;
return false;
}
/**
@@ -1165,10 +1153,9 @@ function discovery_process(&$valid, $device, $sensor_type, $pre_cache)
*/
function sensors($types, $device, $valid, $pre_cache = array())
{
global $config;
foreach ((array)$types as $sensor_type) {
echo ucfirst($sensor_type) . ': ';
$dir = $config['install_dir'] . '/includes/discovery/sensors/' . $sensor_type .'/';
$dir = Config::get('install_dir') . '/includes/discovery/sensors/' . $sensor_type .'/';
if (is_file($dir . $device['os_group'] . '.inc.php')) {
include $dir . $device['os_group'] . '.inc.php';
@@ -1176,7 +1163,7 @@ function sensors($types, $device, $valid, $pre_cache = array())
if (is_file($dir . $device['os'] . '.inc.php')) {
include $dir . $device['os'] . '.inc.php';
}
if (isset($config['os'][$device['os']]['rfc1628_compat']) && $config['os'][$device['os']]['rfc1628_compat']) {
if (Config::getOsSetting($device, 'rfc1628_compat', false)) {
if (is_file($dir . '/rfc1628.inc.php')) {
include $dir . '/rfc1628.inc.php';
}
@@ -1266,7 +1253,6 @@ function build_cbgp_peers($device, $peer, $af_data, $peer2)
function add_bgp_peer($device, $peer)
{
global $config;
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['ip'])) < '1') {
$bgpPeers = array(
'device_id' => $device['device_id'],
@@ -1286,8 +1272,8 @@ function add_bgp_peer($device, $peer)
'bgpPeerInUpdateElapsedTime' => 0,
);
dbInsert($bgpPeers, 'bgpPeers');
if ($config['autodiscovery']['bgp'] === true) {
$name = gethostbyaddr($peer['ip']);
if (Config::get('autodiscovery.bgp')) {
$name = gethostbyaddr($peer['ip']);
discover_new_device($name, $device, 'BGP');
}
echo '+';

View File

@@ -3,7 +3,9 @@
// We're discovering this MIB
// snmpwalk -v2c -c <community> <hostname> -M mibs/junose/ -m Juniper-UNI-ATM-MIB juniAtmVpStatsEntry
// JunOSe ATM vps
if ($device['os'] == 'junose' && $config['enable_ports_junoseatmvp']) {
use LibreNMS\Config;
if ($device['os'] == 'junose' && Config::get('enable_ports_junoseatmvp')) {
$vp_array = snmpwalk_cache_multi_oid($device, 'juniAtmVpStatsInCells', $vp_array, 'Juniper-UNI-ATM-MIB', 'junose');
$valid_vp = array();
d_echo($vp_array);

View File

@@ -1,25 +1,27 @@
<?php
use LibreNMS\Config;
// FIXME should do the deletion etc in a common file perhaps? like for the sensors
// Try to discover Libvirt Virtual Machines.
if ($config['enable_libvirt'] == '1' && $device['os'] == 'linux') {
if (Config::get('enable_libvirt') && $device['os'] == 'linux') {
$libvirt_vmlist = array();
$ssh_ok = 0;
$userHostname = $device['hostname'];
if (isset($config['libvirt_username'])) {
$userHostname = $config['libvirt_username'].'@'.$userHostname;
if (Config::has('libvirt_username')) {
$userHostname = Config::get('libvirt_username').'@'.$userHostname;
}
foreach ($config['libvirt_protocols'] as $method) {
if (strstr($method, 'qemu')) {
foreach (Config::get('libvirt_protocols') as $method) {
if (str_contains($method, 'qemu')) {
$uri = $method.'://'.$userHostname.'/system';
} else {
$uri = $method.'://'.$userHostname;
}
if (strstr($method, 'ssh') && !$ssh_ok) {
if (str_contains($method, 'ssh') && !$ssh_ok) {
// Check if we are using SSH if we can log in without password - without blocking the discovery
// Also automatically add the host key so discovery doesn't block on the yes/no question, and run echo so we don't get stuck in a remote shell ;-)
exec('ssh -o "StrictHostKeyChecking no" -o "PreferredAuthentications publickey" -o "IdentitiesOnly yes" '.$userHostname.' echo -e', $out, $ret);
@@ -28,10 +30,10 @@ if ($config['enable_libvirt'] == '1' && $device['os'] == 'linux') {
}
}
if ($ssh_ok || !strstr($method, 'ssh')) {
if ($ssh_ok || !str_contains($method, 'ssh')) {
// Fetch virtual machine list
unset($domlist);
exec($config['virsh'].' -rc '.$uri.' list', $domlist);
exec(Config::get('virsh').' -rc '.$uri.' list', $domlist);
foreach ($domlist as $dom) {
list($dom_id,) = explode(' ', trim($dom), 2);
@@ -39,7 +41,7 @@ if ($config['enable_libvirt'] == '1' && $device['os'] == 'linux') {
if (is_numeric($dom_id)) {
// Fetch the Virtual Machine information.
unset($vm_info_array);
exec($config['virsh'].' -rc '.$uri.' dumpxml '.$dom_id, $vm_info_array);
exec(Config::get('virsh').' -rc '.$uri.' dumpxml '.$dom_id, $vm_info_array);
// Example xml:
// <domain type='kvm' id='3'>
@@ -69,7 +71,7 @@ if ($config['enable_libvirt'] == '1' && $device['os'] == 'linux') {
$vmwVmDisplayName = $xml->name;
$vmwVmGuestOS = '';
// libvirt does not supply this
exec($config['virsh'].' -rc '.$uri.' domstate '.$dom_id, $vm_state);
exec(Config::get('virsh').' -rc '.$uri.' domstate '.$dom_id, $vm_state);
$vmwVmState = ucfirst($vm_state[0]);
$vmwVmCpus = $xml->vcpu['current'];

View File

@@ -1,12 +1,14 @@
<?php
use LibreNMS\Config;
$os = getHostOS($device);
if ($os != $device['os']) {
log_event('Device OS changed ' . $device['os'] . " => $os", $device, 'system', 3);
$device['os'] = $os;
$sql = dbUpdate(array('os' => $os), 'devices', 'device_id=?', array($device['device_id']));
if (!isset($config['os'][$device['os']])) {
if (!Config::has("os.{$device['os']}")) {
load_os($device);
}

View File

@@ -1,6 +1,8 @@
<?php
// Build SNMP Cache Array
use LibreNMS\Config;
$port_stats = array();
$port_stats = snmpwalk_cache_oid($device, 'ifDescr', $port_stats, 'IF-MIB');
$port_stats = snmpwalk_cache_oid($device, 'ifName', $port_stats, 'IF-MIB');
@@ -17,7 +19,7 @@ d_echo($port_stats);
// The port association configuration allows to choose between association via ifIndex, ifName,
// or maybe other means in the future. The default port association mode still is ifIndex for
// compatibility reasons.
$port_association_mode = $config['default_port_association_mode'];
$port_association_mode = Config::get('default_port_association_mode');
if ($device['port_association_mode']) {
$port_association_mode = get_port_assoc_mode_name($device['port_association_mode']);
}

View File

@@ -1,3 +1,5 @@
<?php
include_once $config['install_dir'] . '/includes/discovery/sensors/fanspeeds/supermicro.inc.php';
use LibreNMS\Config;
include_once Config::get('install_dir') . '/includes/discovery/sensors/fanspeeds/supermicro.inc.php';

View File

@@ -1,3 +1,5 @@
<?php
include_once $config['install_dir'] . '/includes/discovery/sensors/fanspeeds/supermicro.inc.php';
use LibreNMS\Config;
include_once Config::get('install_dir') . '/includes/discovery/sensors/fanspeeds/supermicro.inc.php';

View File

@@ -1,5 +1,7 @@
<?php
use LibreNMS\Config;
// IPMI - We can discover this on poll!
if ($ipmi['host'] = get_dev_attrib($device, 'ipmi_hostname')) {
echo 'IPMI : ';
@@ -7,41 +9,42 @@ if ($ipmi['host'] = get_dev_attrib($device, 'ipmi_hostname')) {
$ipmi['user'] = get_dev_attrib($device, 'ipmi_username');
$ipmi['password'] = get_dev_attrib($device, 'ipmi_password');
if ($config['own_hostname'] != $device['hostname'] || $ipmi['host'] != 'localhost') {
if (Config::get('own_hostname') != $device['hostname'] || $ipmi['host'] != 'localhost') {
$remote = " -H ".$ipmi['host']." -U '".$ipmi['user']."' -P '".$ipmi['password']."' -L USER";
}
foreach ($config['ipmi']['type'] as $ipmi_type) {
$results = external_exec($config['ipmitool']." -I $ipmi_type".$remote.' sensor 2>/dev/null|sort');
foreach (Config::get('ipmi.type', array()) as $ipmi_type) {
$results = external_exec(Config::get('ipmitool')." -I $ipmi_type".$remote.' sensor 2>/dev/null|sort');
if ($results != '') {
set_dev_attrib($device, 'ipmi_type', $ipmi_type);
echo "$ipmi_type ";
break;
}
}
echo $ipmi_type;
$index = 0;
foreach (explode("\n", $results) as $sensor) {
// BB +1.1V IOH | 1.089 | Volts | ok | na | 1.027 | 1.054 | 1.146 | 1.177 | na
list($desc,$current,$unit,$state,$low_nonrecoverable,$low_limit,$low_warn,$high_warn,$high_limit,$high_nonrecoverable) = explode('|', $sensor);
$values = array_map('trim', explode('|', $sensor));
list($desc,$current,$unit,$state,$low_nonrecoverable,$low_limit,$low_warn,$high_warn,$high_limit,$high_nonrecoverable) = $values;
$index++;
if (trim($current) != 'na' && $config['ipmi_unit'][trim($unit)]) {
if ($current != 'na' && Config::has("ipmi_unit.$unit")) {
discover_sensor(
$valid['sensor'],
$config['ipmi_unit'][trim($unit)],
Config::get("ipmi_unit.$unit"),
$device,
trim($desc),
$desc,
$index,
'ipmi',
trim($desc),
$desc,
'1',
'1',
(trim($low_limit) == 'na' ? null : trim($low_limit)),
(trim($low_warn) == 'na' ? null : trim($low_warn)),
(trim($high_warn) == 'na' ? null : trim($high_warn)),
(trim($high_limit) == 'na' ? null : trim($high_limit)),
$low_limit == 'na' ? null : $low_limit,
$low_warn == 'na' ? null : $low_warn,
$high_warn == 'na' ? null : $high_warn,
$high_limit == 'na' ? null : $high_limit,
$current,
'ipmi'
);

View File

@@ -4,6 +4,8 @@
* requires snmp extend agent script from librenms-agent
*/
use LibreNMS\Config;
$sensor_oid = ".1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.1";
$value = snmp_get($device, $sensor_oid, '-Oqve');
$value = trim($value, '"');
@@ -55,4 +57,4 @@ if (preg_match("/(Linux).+(ntc)/", $chip)) {
discover_sensor($valid['sensor'], 'temperature', $device, $oid.$index, $index, $sensor_type, $descr, '1', '1', $lowlimit, $lowwarnlimit, $warnlimit, $limit, $value);
}
include_once $config['install_dir'] . '/includes/discovery/sensors/temperature/supermicro.inc.php';
include_once Config::get('install_dir') . '/includes/discovery/sensors/temperature/supermicro.inc.php';

View File

@@ -1,3 +1,5 @@
<?php
include_once $config['install_dir'] . '/includes/discovery/sensors/temperature/supermicro.inc.php';
use LibreNMS\Config;
include_once Config::get('install_dir') . '/includes/discovery/sensors/temperature/supermicro.inc.php';

View File

@@ -1,6 +1,8 @@
<?php
if ($config['discover_services']) {
use LibreNMS\Config;
if (Config::get('discover_services')) {
// FIXME: use /etc/services?
$known_services = array(
22 => 'ssh',

View File

@@ -1,9 +1,28 @@
<?php
use LibreNMS\Config;
$hrstorage_array = snmpwalk_cache_oid($device, 'hrStorageEntry', null, 'HOST-RESOURCES-MIB:HOST-RESOURCES-TYPES:NetWare-Host-Ext-MIB');
if (is_array($hrstorage_array)) {
echo 'hrStorage : ';
$bad_fs_types = array(
'hrStorageVirtualMemory',
'hrStorageRam',
'hrStorageOther',
'nwhrStorageDOSMemory',
'nwhrStorageMemoryAlloc',
'nwhrStorageMemoryPermanent',
'nwhrStorageCacheBuffers',
'nwhrStorageCacheMovable',
'nwhrStorageCacheNonMovable',
'nwhrStorageCodeAndDataMemory',
'nwhrStorageIOEngineMemory',
'nwhrStorageMSEngineMemory',
'nwhrStorageUnclaimedMemory',
);
foreach ($hrstorage_array as $index => $storage) {
$fstype = $storage['hrStorageType'];
$descr = $storage['hrStorageDescr'];
@@ -13,51 +32,37 @@ if (is_array($hrstorage_array)) {
$used = ($storage['hrStorageUsed'] * $storage['hrStorageAllocationUnits']);
$units = $storage['hrStorageAllocationUnits'];
switch ($fstype) {
case 'hrStorageVirtualMemory':
case 'hrStorageRam':
case 'hrStorageOther':
case 'nwhrStorageDOSMemory':
case 'nwhrStorageMemoryAlloc':
case 'nwhrStorageMemoryPermanent':
case 'nwhrStorageCacheBuffers':
case 'nwhrStorageCacheMovable':
case 'nwhrStorageCacheNonMovable':
case 'nwhrStorageCodeAndDataMemory':
case 'nwhrStorageIOEngineMemory':
case 'nwhrStorageMSEngineMemory':
case 'nwhrStorageUnclaimedMemory':
$deny = 1;
break;
if (in_array($fstype, $bad_fs_types)) {
continue;
}
if ($device['os'] == 'vmware' && $descr == 'Real Memory') {
$old_rrdfile = array('storage', 'hrstorage', $descr);
$new_rrdfile = array('mempool', 'hrstorage', $storage['hrStorageIndex']);
rrd_file_rename($device, $old_rrdfile, $new_rrdfile);
$deny = 1;
continue;
}
if ($deny != 1) {
$deny = ignore_storage($descr);
if (ignore_storage($descr)) {
continue;
}
if (isset($config['ignore_mount_removable']) && $config['ignore_mount_removable'] && $fstype == 'hrStorageRemovableDisk') {
$deny = 1;
if (Config::get('ignore_mount_removable', false) && $fstype == 'hrStorageRemovableDisk') {
d_echo("skip(removable)\n");
continue;
}
if (isset($config['ignore_mount_network']) && $config['ignore_mount_network'] && $fstype == 'hrStorageNetworkDisk') {
$deny = 1;
if (Config::get('ignore_mount_network', false) && $fstype == 'hrStorageNetworkDisk') {
d_echo("skip(network)\n");
continue;
}
if (isset($config['ignore_mount_optical']) && $config['ignore_mount_optical'] && $fstype == 'hrStorageCompactDisc') {
$deny = 1;
if (Config::get('ignore_mount_optical', false) && $fstype == 'hrStorageCompactDisc') {
d_echo("skip(cd)\n");
continue;
}
if (!$deny && is_numeric($index)) {
if (is_numeric($index)) {
discover_storage($valid_storage, $device, $index, $fstype, 'hrstorage', $descr, $size, $units, $used);
}

View File

@@ -1,5 +1,7 @@
<?php
use LibreNMS\Config;
$netapp_storage = snmpwalk_cache_oid($device, 'dfEntry', null, 'NETAPP-MIB');
if (is_array($netapp_storage)) {
@@ -16,28 +18,28 @@ if (is_array($netapp_storage)) {
$used = ($storage['dfKBytesUsed'] * $units);
}
foreach ($config['ignore_mount'] as $bi) {
foreach (Config::get('ignore_mount', array()) as $bi) {
if ($bi == $descr) {
$deny = 1;
d_echo("$bi == $descr \n");
continue;
}
}
foreach ($config['ignore_mount_string'] as $bi) {
foreach (Config::get('ignore_mount_string', array()) as $bi) {
if (strpos($descr, $bi) !== false) {
$deny = 1;
d_echo("strpos: $descr, $bi \n");
continue;
}
}
foreach ($config['ignore_mount_regexp'] as $bi) {
foreach (Config::get('ignore_mount_regexp', array()) as $bi) {
if (preg_match($bi, $descr) > '0') {
$deny = 1;
d_echo("preg_match $bi, $descr \n");
continue;
}
}
if (!$deny && is_numeric($index)) {
if (is_numeric($index)) {
discover_storage($valid_storage, $device, $index, $fstype, 'netapp-storage', $descr, $size, $units, $used);
}

View File

@@ -13,9 +13,7 @@ if (is_array($dsktable_array)) {
$dsk['dskAvail'] = ($entry['dskAvail'] * 1024);
$dsk['dskUsed'] = $dsk['dskTotal'] - $dsk['dskAvail'];
$deny = ignore_storage($dsk['dskPath']);
if ($deny != 1) {
if (!ignore_storage($dsk['dskPath'])) {
discover_storage($valid_storage, $device, $dsk['dskIndex'], 'dsk', 'ucd-dsktable', $dsk['dskPath'], $dsk['dskTotal'], 1024, $dsk['dskUsed']);
}
}

View File

@@ -1,6 +1,8 @@
<?php
foreach (glob($config['install_dir'].'/'.$include_dir.'/*.inc.php') as $file) {
use LibreNMS\Config;
foreach (glob(Config::get('install_dir').'/'.$include_dir.'/*.inc.php') as $file) {
include $file;
}