commit version 22.12.12447

This commit is contained in:
2023-01-01 22:36:12 -05:00
parent af1b03d79f
commit b948283a96
744 changed files with 620715 additions and 27381 deletions

View File

@ -23,7 +23,7 @@
* @return array
*/
function build_initial_device_array($hostname, $snmp_community, $snmp_version, $snmp_port = 161, $snmp_transport = 'udp', $options = []) {
$device = array();
$device = [];
$device['hostname'] = $hostname;
$device['snmp_port'] = $snmp_port;
$device['snmp_transport'] = $snmp_transport;
@ -46,6 +46,11 @@ function build_initial_device_array($hostname, $snmp_community, $snmp_version, $
}
}
// Append SNMPable OIDs if passed
if (isset($options['snmpable']) && strlen($options['snmpable'])) {
$device['snmpable'] = $options['snmpable'];
}
// Append SNMP context if passed
if (isset($options['snmp_context']) && strlen($options['snmp_context'])) {
$device['snmp_context'] = $options['snmp_context'];
@ -71,7 +76,7 @@ function add_device_vars($vars) {
// Add device to remote poller,
// only validate vars and add to pollers_actions
if (is_intnum($vars['poller_id']) && $vars['poller_id'] != $config['poller_id']) {
print_message("Requested add device with hostname '$hostname' to remote Poller [${vars['poller_id']}].");
print_message("Requested add device with hostname '$hostname' to remote Poller [{$vars['poller_id']}].");
if (!(is_valid_hostname($hostname) || get_ip_version($hostname))) {
// Failed DNS lookup
print_error("Hostname '$hostname' is not valid.");
@ -94,8 +99,8 @@ function add_device_vars($vars) {
}
if (function_exists('add_action_queue') &&
$action_id = add_action_queue('device_add', $hostname, $vars)) {
print_message("Device with hostname '$hostname' added to queue [$action_id] for addition on remote Poller [${vars['poller_id']}].");
log_event("Device with hostname '$hostname' added to queue [$action_id] for addition on remote Poller [${vars['poller_id']}].", NULL, 'info', NULL, 7);
print_message("Device with hostname '$hostname' added to queue [$action_id] for addition on remote Poller [{$vars['poller_id']}].");
log_event("Device with hostname '$hostname' added to queue [$action_id] for addition on remote Poller [{$vars['poller_id']}].", NULL, 'info', NULL, 7);
return TRUE;
}
print_error("Device with hostname '$hostname' not added. Incorrect addition to actions queue.");
@ -106,6 +111,25 @@ function add_device_vars($vars) {
$config_snmp = $config['snmp'];
$config_rrd = $config['rrd_override'];
$snmp_oids = [];
if (isset($vars['snmpable']) && !empty($vars['snmpable'])) {
foreach (explode(' ', $vars['snmpable']) as $oid) {
if (preg_match(OBS_PATTERN_SNMP_OID_NUM, $oid)) {
// Valid Numeric OID
$snmp_oids[] = $oid;
} elseif (str_contains($oid, '::') && $oid_num = snmp_translate($oid)) {
// Named MIB::Oid which we can translate
$snmp_oids[] = $oid_num;
} else {
print_warning("Invalid or unknown OID: ".$oid);
}
}
if (empty($snmp_oids)) {
print_error("Incorrect or not numeric OIDs passed for check device availability.");
return FALSE;
}
}
// Default snmp port
if (is_valid_param($vars['snmp_port'], 'port')) {
$snmp_port = (int)$vars['snmp_port'];
@ -124,10 +148,10 @@ function add_device_vars($vars) {
case 'v2c':
case 'v1':
if (strlen($vars['snmp_community'])) {
if (!safe_empty($vars['snmp_community'])) {
// Hrm, I not sure why strip_tags
$snmp_community = strip_tags($vars['snmp_community']);
$config['snmp']['community'] = array($snmp_community);
$config['snmp']['community'] = [ $snmp_community ];
}
$snmp_version = $vars['snmp_version'];
@ -137,15 +161,15 @@ function add_device_vars($vars) {
case 'v3':
if (strlen($vars['snmp_authlevel'])) {
$snmp_v3 = array (
if (!safe_empty($vars['snmp_authlevel'])) {
$snmp_v3 = [
'authlevel' => $vars['snmp_authlevel'],
'authname' => $vars['snmp_authname'],
'authpass' => $vars['snmp_authpass'],
'authalgo' => $vars['snmp_authalgo'],
'cryptopass' => $vars['snmp_cryptopass'],
'cryptoalgo' => $vars['snmp_cryptoalgo'],
);
];
array_unshift($config['snmp']['v3'], $snmp_v3);
}
@ -164,7 +188,7 @@ function add_device_vars($vars) {
$config['rrd_override'] = TRUE;
}
$snmp_options = array();
$snmp_options = [];
if (get_var_true($vars['ping_skip'])) {
$snmp_options['ping_skip'] = TRUE;
}
@ -182,6 +206,11 @@ function add_device_vars($vars) {
$snmp_options['snmp_maxrep'] = trim($vars['snmp_maxrep']);
}
// Optional SNMPable OIDs
if ($snmp_oids) {
$snmp_options['snmpable'] = implode(' ', $snmp_oids);
}
// Optional SNMP Context
if (trim($vars['snmp_context']) !== '') {
$snmp_options['snmp_context'] = trim($vars['snmp_context']);
@ -213,7 +242,7 @@ function add_device_vars($vars) {
* @return mixed Returns $device_id number if added, 0 (zero) if device not accessible with current auth and FALSE if device complete not accessible by network. When testing, returns -1 if the device is available.
*/
// TESTME needs unit testing
function add_device($hostname, $snmp_version = array(), $snmp_port = 161, $snmp_transport = 'udp', $options = array(), $flags = OBS_DNS_ALL) {
function add_device($hostname, $snmp_version = [], $snmp_port = 161, $snmp_transport = 'udp', $options = [], $flags = OBS_DNS_ALL) {
global $config;
// If $options['break'] set as TRUE, break recursive function execute
@ -315,6 +344,11 @@ function add_device($hostname, $snmp_version = array(), $snmp_port = 161, $snmp_
}
}
// Append SNMPable oids if passed
if (isset($options['snmpable']) && strlen($options['snmpable'])) {
$snmp['snmpable'] = $options['snmpable'];
}
// Append SNMP context if passed
if (isset($options['snmp_context']) && strlen($options['snmp_context'])) {
$snmp['snmp_context'] = $options['snmp_context'];
@ -371,6 +405,11 @@ function add_device($hostname, $snmp_version = array(), $snmp_port = 161, $snmp_
}
}
// Append SNMPable oids if passed
if (isset($options['snmpable']) && strlen($options['snmpable'])) {
$snmp['snmpable'] = $options['snmpable'];
}
// Append SNMP context if passed
if (isset($options['snmp_context']) && strlen($options['snmp_context'])) {
$snmp['snmp_context'] = $options['snmp_context'];
@ -384,6 +423,9 @@ function add_device($hostname, $snmp_version = array(), $snmp_port = 161, $snmp_
print_message("Trying $snmp_version community $snmp_community ...");
}
//r($options);
//r($snmp);
//r($device);
if (isSNMPable($device)) {
if (!check_device_duplicated($device)) {
if (isset($options['test']) && $options['test']) {
@ -920,6 +962,11 @@ function create_device($hostname, $snmp = []) {
}
}
// Append SNMPable oids if passed
if (isset($snmp['snmpable'])) {
$device['snmpable'] = $snmp['snmpable'];
}
// Local poller id (for distributed system)
$poller_id = $GLOBALS['config']['poller_id']; // $config['poller_id'] sets in sql-config.php
if (isset($GLOBALS['config']['poller_name']) &&
@ -1014,7 +1061,7 @@ function delete_device($id, $delete_rrd = FALSE) {
$deleted_entities = array();
foreach (get_device_entities($id) as $entity_type => $entity_ids) {
foreach ($config['entity_tables'] as $table) {
$where = '`entity_type` = ?' . generate_query_values($entity_ids, 'entity_id');
$where = '`entity_type` = ?' . generate_query_values_and($entity_ids, 'entity_id');
$table_status = dbDelete($table, $where, array($entity_type));
if ($table_status) { $deleted_entities[$entity_type] = 1; }
}
@ -1072,14 +1119,15 @@ function device_status_array(&$device) {
$flags |= OBS_PING_SKIP; // Add skip ping flag
}
$device['pingable'] = is_pingable($device['hostname'], $flags);
if ($device['pingable']) {
$device['snmpable'] = isSNMPable($device);
if ($device['snmpable']) {
$ping_msg = ($attribs['ping_skip'] ? '' : 'PING (' . $device['pingable'] . 'ms) and ');
$device['status_pingable'] = is_pingable($device['hostname'], $flags);
$device['pingable'] = $device['status_pingable']; // Compat
if ($device['status_pingable']) {
$device['status_snmpable'] = isSNMPable($device);
if ($device['status_snmpable']) {
$ping_msg = ($attribs['ping_skip'] ? '' : 'PING (' . $device['status_pingable'] . 'ms) and ');
//print_cli_data("Device status", "Device is reachable by " . $ping_msg . "SNMP (".$device['snmpable']."ms)", 1);
$status_message = "Device is reachable by " . $ping_msg . "SNMP (".$device['snmpable']."ms)";
//print_cli_data("Device status", "Device is reachable by " . $ping_msg . "SNMP (".$device['status_snmpable']."ms)", 1);
$status_message = "Device is reachable by " . $ping_msg . "SNMP (".$device['status_snmpable']."ms)";
$status = "1";
$status_type = 'ok';
} else {
@ -1094,6 +1142,7 @@ function device_status_array(&$device) {
$status = "0";
//print_vars(get_status_var('ping_dns'));
if (isset_status_var('ping_dns') && get_status_var('ping_dns') !== 'ok') {
$status_message = "Device hostname is not resolved";
$status_type = 'dns';
} else {
$status_type = 'ping';
@ -1103,6 +1152,48 @@ function device_status_array(&$device) {
return [ 'status' => $status, 'status_type' => $status_type, 'message' => $status_message ];
}
/**
* Return device name based on default hostname setting, ie purpose, descr, sysname
* @param array $device Device array
* @param integer $max_len Maximum length for returned name.
*
* @return string
*/
function device_name($device, $max_len = FALSE) {
global $config;
switch (strtolower($config['web_device_name'])) {
case 'sysname':
$name_field = 'sysName';
break;
case 'purpose':
case 'descr':
case 'description':
$name_field = 'purpose';
break;
default:
$name_field = 'hostname';
}
if ($max_len && !is_intnum($max_len)) {
$max_len = $config['short_hostname']['length'];
}
if ($name_field !== 'hostname' && !safe_empty($device[$name_field])) {
if ($name_field === 'sysName' && $max_len && $max_len > 3) {
// short sysname when is valid hostname (do not escape here)
return short_hostname($device[$name_field], $max_len, FALSE);
}
return $device[$name_field];
}
if ($max_len && $max_len > 3) {
// short hostname (do not escape here)
return short_hostname($device['hostname'], $max_len, FALSE);
}
return $device['hostname'];
}
/**
* Return device hostname or ip address, based on setting $config['use_ip']
*
@ -1195,52 +1286,58 @@ function get_device_id_by_entity_id($entity_id, $entity_type) {
// DOCME needs phpdoc block
// TESTME needs unit testing
function device_by_id_cache($device_id, $refresh = 0)
{
function device_by_id_cache($device_id, $refresh = FALSE) {
global $cache;
if (!$refresh && isset($cache['devices']['id'][$device_id]) && is_array($cache['devices']['id'][$device_id]))
{
if (!$refresh &&
isset($cache['devices']['id'][$device_id]) && is_array($cache['devices']['id'][$device_id])) {
$device = $cache['devices']['id'][$device_id];
// Note, cached $device can be not humanized (by cache-data)
$refresh = !isset($device['humanized']);
} else {
$device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device_id));
$device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", [ $device_id ]);
$refresh = TRUE; // Set refresh
}
if (!empty($device))
{
if (!empty($device) && $refresh) {
humanize_device($device);
if ($refresh || !isset($device['graphs']))
{
// Fetch device graphs
$device['graphs'] = dbFetchRows("SELECT * FROM `device_graphs` WHERE `device_id` = ?", array($device_id));
}
$cache['devices']['id'][$device_id] = $device;
get_device_graphs($device);
return $device;
} else {
return FALSE;
// Add to memory cache
$cache['devices']['id'][$device_id] = $device;
}
return $device;
}
function get_device_graphs(&$device) {
//if ($refresh || !isset($device['graphs']))
//{
// Fetch device graphs
foreach(dbFetchRows("SELECT * FROM `device_graphs` WHERE `device_id` = ?", [ $device['device_id'] ]) as $graph) {
$device['graphs'][$graph['graph']] = $graph;
}
//}
}
// DOCME needs phpdoc block
// TESTME needs unit testing
function get_device_id_by_hostname($hostname)
{
function get_device_id_by_hostname($hostname) {
global $cache;
if (isset($cache['devices']['hostname'][$hostname]))
{
if (isset($cache['devices']['hostname'][$hostname])) {
$id = $cache['devices']['hostname'][$hostname];
} else {
$id = dbFetchCell("SELECT `device_id` FROM `devices` WHERE `hostname` = ?", array($hostname));
$id = dbFetchCell("SELECT `device_id` FROM `devices` WHERE `hostname` = ?", [ $hostname ]);
}
if (is_numeric($id))
{
if (is_numeric($id)) {
return $id;
} else {
return FALSE;
}
return FALSE;
}
// DOCME needs phpdoc block
@ -1517,7 +1614,7 @@ function poll_device_mib_metatypes($device, $metatypes, &$poll_device = []) {
}
// if test not required, use first entry (as getnext)
$value = $values[$entry['oid']];
$full_oid = "$mib::${entry['oid']}.$index";
$full_oid = "$mib::{$entry['oid']}.$index";
break;
}
} elseif (isset($entry['oid_num'])) { // Use numeric OID if set, otherwise fetch text based string
@ -1526,15 +1623,15 @@ function poll_device_mib_metatypes($device, $metatypes, &$poll_device = []) {
} elseif (isset($entry['oid_next'])) {
// If Oid passed without index part use snmpgetnext (see FCMGMT-MIB definitions)
$value = snmp_getnext_oid($device, $entry['oid_next'], $mib, NULL, $flags);
$full_oid = "$mib::${entry['oid_next']}";
$full_oid = "$mib::{$entry['oid_next']}";
} elseif (isset($entry['oid_count'])) {
// This is special type of get data by snmpwalk and count entries
$data = snmpwalk_values($device, $entry['oid_count'], $mib);
$value = is_array($data) ? count($data) : '';
$full_oid = str_starts($entry['oid_count'], '.') ? $entry['oid_count'] : "$mib::${entry['oid_count']}";
$full_oid = str_starts($entry['oid_count'], '.') ? $entry['oid_count'] : "$mib::{$entry['oid_count']}";
} else {
$value = snmp_get_oid($device, $entry['oid'], $mib, NULL, $flags);
$full_oid = "$mib::${entry['oid']}";
$full_oid = "$mib::{$entry['oid']}";
}
if (snmp_status() && !safe_empty($value)) {
@ -1559,6 +1656,13 @@ function poll_device_mib_metatypes($device, $metatypes, &$poll_device = []) {
if ($metatype === 'version' && preg_match('/^[\d\.]+$/', $value)) {
// version -> xxx.y.z
$value .= '.' . implode('.', $extra);
} elseif ($metatype === 'sysname') {
$tmp = $value . '.' . implode('.', $extra);
if (is_valid_hostname($tmp, TRUE)) {
// Ie: ALLOT-MIB
$value = $tmp;
}
unset($tmp);
} else {
// others -> xxx (y, z)
$value .= ' (' . implode(', ', $extra) . ')';
@ -1594,6 +1698,9 @@ function poll_device_mib_metatypes($device, $metatypes, &$poll_device = []) {
//$uptimes['message'] = 'Using device MIB poller '.$metatype.': ' . $uptimes['message'];
print_debug("Added System Uptime from SNMP definition fetch: 'device_uptime' = '$value'");
// Continue for other possible sysUpTime and use maximum value
// but from different MIBs when valid time found (example UBNT-UniFi-MIB)
continue 2;
}
// Continue for other possible sysUpTime and use maximum value
continue;
@ -1649,7 +1756,7 @@ function poll_device_unix_packages($device, $metatypes, $defs = []) {
// by unix-agent packages
//$sql = 'SELECT * FROM `packages` WHERE `device_id` = ? AND `status` = ? AND `name` IN (?, ?, ?)';
$sql = 'SELECT * FROM `packages` WHERE `device_id` = ? AND `status` = ?';
$sql .= generate_query_values(array_keys($package_defs), 'name');
$sql .= generate_query_values_and(array_keys($package_defs), 'name');
$params = [ $device['device_id'], 1 ];
if ($package = dbFetchRow($sql, $params)) {
//$name = $package['name'];
@ -1759,8 +1866,33 @@ function poll_device_unix_packages($device, $metatypes, $defs = []) {
return $data;
}
function cache_device_attribs_exist($device, $refresh = FALSE) {
if (is_array($device)) {
$device_id = $device['device_id'];
} else {
$device_id = $device;
}
// Pre-check if entity attribs for device exist
if ($refresh || !isset($GLOBALS['cache']['devices_attribs'][$device_id])) {
$GLOBALS['cache']['devices_attribs'][$device_id] = [];
foreach (dbFetchColumn('SELECT DISTINCT `entity_type` FROM `entity_attribs` WHERE `device_id` = ?', [ $device_id ]) as $entity_type) {
$GLOBALS['cache']['devices_attribs'][$device_id][$entity_type] = TRUE;
}
//r($GLOBALS['cache']['devices_attribs'][$device_id]);
//$GLOBALS['cache']['devices_attribs'][$device_id][$entity_type] = dbExist('entity_attribs', '`entity_type` = ? AND `device_id` = ?', [ $entity_type, $device_id ]);
}
}
/* OBSOLETE, BUT STILL USED FUNCTIONS */
// CLEANME remove when all function calls will be deleted
function get_dev_attrib($device, $attrib_type)
{
// Call to new function
return get_entity_attrib('device', $device, $attrib_type);
}
// CLEANME remove when all function calls will be deleted
function get_dev_attribs($device_id)
{

View File

@ -278,7 +278,7 @@ function get_ip_prefix($entry) {
$net = Net_IPv4::parseAddress($entry['ip'].'/'.$prefix);
if (Net_IPv4::ipInNetwork($entry['gateway'], $net->network.'/'.$prefix)) {
// Gateway IP in network, stop loop
print_debug("Prefix '$prefix' detected by IP '${entry['ip']}' and Gateway '${entry['gateway']}'.");
print_debug("Prefix '$prefix' detected by IP '{$entry['ip']}' and Gateway '{$entry['gateway']}'.");
break;
}
$prefix++;
@ -291,7 +291,7 @@ function get_ip_prefix($entry) {
if (Net_IPv4::ipInNetwork($entry['gateway'], $net->network.'/'.$tmp_prefix)) {
// Gateway IP in network, stop loop
$prefix = $tmp_prefix;
print_debug("Prefix '$prefix' detected by IP '${entry['ip']}' and Gateway '${entry['gateway']}'.");
print_debug("Prefix '$prefix' detected by IP '{$entry['ip']}' and Gateway '{$entry['gateway']}'.");
break;
}
$tmp_prefix--;
@ -313,7 +313,7 @@ function get_ip_prefix($entry) {
}
// Incorrect IP
print_debug("Incorrect: ${entry['ip']}");
print_debug("Incorrect: {$entry['ip']}");
return NULL;
}

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage entities
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -87,21 +87,24 @@ function get_port_id_by_ip_cache($device, $ip)
// DOCME needs phpdoc block
// TESTME needs unit testing
function get_port_id_by_mac($device, $mac)
{
if (is_array($device) && isset($device['device_id']))
{
function get_port_id_by_mac($device, $mac) {
if (is_array($device) && isset($device['device_id'])) {
$device_id = $device['device_id'];
}
elseif (is_numeric($device))
{
} elseif (is_numeric($device)) {
$device_id = $device;
} else {
return FALSE;
}
$remote_mac = mac_zeropad($mac);
if ($remote_mac && $remote_mac != '000000000000')
{
return dbFetchCell("SELECT `port_id` FROM `ports` WHERE `deleted` = '0' AND `ifPhysAddress` = ? AND `device_id` = ? LIMIT 1", [ $remote_mac, $device_id ]);
if ($remote_mac && $remote_mac !== '000000000000' &&
$ids = dbFetchColumn("SELECT `port_id` FROM `ports` WHERE `ifPhysAddress` = ? AND `device_id` = ? AND `deleted` = ?", [ $remote_mac, $device_id, 0 ])) {
if (count($ids) > 1) {
print_debug("WARNING. Found multiple ports [".count($ids)."] with same MAC address $mac on device ($device_id).");
}
return $ids[0];
//return dbFetchCell("SELECT `port_id` FROM `ports` WHERE `deleted` = '0' AND `ifPhysAddress` = ? AND `device_id` = ? LIMIT 1", [ $remote_mac, $device_id ]);
}
return FALSE;
@ -507,14 +510,14 @@ function get_port_id_by_customer($customer)
{
case 'device':
case 'device_id':
$where .= generate_query_values($value, 'device_id');
$where .= generate_query_values_and($value, 'device_id');
break;
case 'type':
case 'descr':
case 'circuit':
case 'speed':
case 'notes':
$where .= generate_query_values($value, 'port_descr_'.$var);
$where .= generate_query_values_and($value, 'port_descr_'.$var);
break;
}
}
@ -573,17 +576,17 @@ function get_device_ids_by_customer($type, $customer)
{
case 'device':
case 'device_id':
$where .= generate_query_values($customer, 'device_id');
$where .= generate_query_values_and($customer, 'device_id');
break;
case 'type':
case 'descr':
case 'circuit':
case 'speed':
case 'notes':
$where .= generate_query_values($customer, 'port_descr_'.$type);
$where .= generate_query_values_and($customer, 'port_descr_'.$type);
break;
default:
$where .= generate_query_values($customer, 'port_descr_descr');
$where .= generate_query_values_and($customer, 'port_descr_descr');
}
$query = 'SELECT DISTINCT `device_id` FROM `ports` ' . $where;
@ -808,7 +811,7 @@ function delete_port($int_id, $delete_rrd = TRUE) {
$deleted_entities = array();
foreach ($config['entity_tables'] as $table)
{
$where = '`entity_type` = ?' . generate_query_values($int_id, 'entity_id');
$where = '`entity_type` = ?' . generate_query_values_and($int_id, 'entity_id');
$table_status = dbDelete($table, $where, array('port'));
if ($table_status) { $deleted_entities['port'] = 1; }
}
@ -910,6 +913,11 @@ function get_port_rrdindex($port)
return $this_port_identifier;
}
// DOCME needs phpdoc block
function humanspeed($speed) {
return safe_empty($speed) ? '-' : formatRates($speed);
}
// CLEANME DEPRECATED
function get_port_rrdfilename($port, $suffix = NULL, $fullpath = FALSE)
{

View File

@ -223,7 +223,14 @@ function get_bgp_localas_array($device) {
// append this mib to entries, ie HUAWEI-BGP-VPN-MIB, CUMULUS-BGPUN-MIB
snmp_getnext_oid($device, $def['oids']['PeerRemoteAs']['oid'], $mib);
if (snmp_status()) {
$entries[] = [ 'mib' => $mib ];
$entry = [ 'mib' => $mib ];
if ($mib === 'CUMULUS-BGPUN-MIB' && $local_as = snmp_get_oid($device, 'bgpLocalAs', $mib)) {
// Cumulus OS not always return LocalAs
$entry['oid'] = 'bgpLocalAs';
$entry['LocalAs'] = snmp_dewrap32bit($local_as); // .1.3.6.1.4.1.40310.4.2 = INTEGER: 64732
}
$entries[] = $entry;
unset($entry);
}
}
@ -552,6 +559,37 @@ function parse_bgp_peer_index(&$peer, $index, $mib = 'BGP4V2-MIB') {
if (get_ip_version($peer_ip)) {
$peer['os10bgp4V2PeerRemoteAddr'] = $peer_ip;
}
// Uptimes really reported with x100 multiplier
if (isset($peer['os10bgp4V2PeerFsmEstablishedTime'])) {
$peer['os10bgp4V2PeerFsmEstablishedTime'] *= 0.01;
}
if (isset($peer['os10bgp4V2PeerInUpdatesElapsedTime'])) {
$peer['os10bgp4V2PeerInUpdatesElapsedTime'] *= 0.01;
}
// It seems as firmware issue, always report as halted
// See: https://jira.observium.org/browse/OBS-4134
if ($peer['os10bgp4V2PeerAdminStatus'] === 'halted' && $peer['os10bgp4V2PeerState'] !== 'idle') {
// running: established, connect, active (not sure about opensent, openconfirm)
print_debug("Fixed Dell OS10 issue, DELLEMC-OS10-BGP4V2-MIB::os10bgp4V2PeerAdminStatus always report halted");
$peer['os10bgp4V2PeerAdminStatus'] = 'running';
} elseif ($peer['os10bgp4V2PeerAdminStatus'] === 'running' && $peer['os10bgp4V2PeerState'] === 'idle') {
// See: https://jira.observium.org/browse/OBS-4280
/*
* DELLEMC-OS10-BGP4V2-MIB::os10bgp4V2PeerAdminStatus.1.ipv4."255.79.16.154" = INTEGER: halted(1)
* DELLEMC-OS10-BGP4V2-MIB::os10bgp4V2PeerAdminStatus.1.ipv4."255.118.129.119" = INTEGER: running(2)
* DELLEMC-OS10-BGP4V2-MIB::os10bgp4V2PeerAdminStatus.1.ipv4."254.145.182.212" = INTEGER: halted(1)
* DELLEMC-OS10-BGP4V2-MIB::os10bgp4V2PeerAdminStatus.1.ipv4."254.145.182.214" = INTEGER: halted(1)
* DELLEMC-OS10-BGP4V2-MIB::os10bgp4V2PeerState.1.ipv4."255.79.16.154" = INTEGER: established(6)
* DELLEMC-OS10-BGP4V2-MIB::os10bgp4V2PeerState.1.ipv4."255.118.129.119" = INTEGER: idle(1)
* DELLEMC-OS10-BGP4V2-MIB::os10bgp4V2PeerState.1.ipv4."254.145.182.212" = INTEGER: established(6)
* DELLEMC-OS10-BGP4V2-MIB::os10bgp4V2PeerState.1.ipv4."254.145.182.214" = INTEGER: established(6)
*/
print_debug("Fixed Dell OS10 issue, DELLEMC-OS10-BGP4V2-MIB::os10bgp4V2PeerAdminStatus report running for shutdown");
$peer['os10bgp4V2PeerAdminStatus'] = 'halted';
}
break;
case 'FORCE10-BGP4-V2-MIB':
@ -625,6 +663,24 @@ function parse_bgp_peer_index(&$peer, $index, $mib = 'BGP4V2-MIB') {
$peer['bgpBgpNeighborAdminState'] = in_array($peer['bgpBgpNeighborState'], [ 'clearing', 'deleted' ]) ? 'stop' : 'start';
}
break;
case 'FIREBRICK-BGP-MIB':
$peer_type = array_shift($index_parts);
if (isset($address_types[$peer_type])) {
$peer['fbBgpPeerAddressType'] = $address_types[$peer_type];
}
$ip_len = array_shift($index_parts);
$peer_ip = implode('.', $index_parts);
if ((int)$ip_len === 16) {
$peer_ip = snmp2ipv6($peer_ip);
}
$peer['fbBgpPeerAddress'] = $peer_ip;
if (!isset($peer['fbBgpPeerAdminState'])) {
// Always set this Oid to start, while not really exist and while peer entry exist in this table
$peer['fbBgpPeerAdminState'] = in_array($peer['fbBgpPeerState'], [ 'clearing', 'deleted' ]) ? 'stop' : 'start';
}
break;
}
}

View File

@ -6,42 +6,36 @@
*
* @package observium
* @subpackage entities
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
/// MOVEME. states.inc.php
function get_bits_state_array($hex, $mib = NULL, $object = NULL, $bits_def = NULL)
{
function get_bits_state_array($hex, $mib = NULL, $object = NULL, $bits_def = NULL) {
global $config;
// Fetch validate BITS definition
if (is_array($bits_def))
{
if (!empty($bits_def) && is_array($bits_def)) {
// Use passed bits definitions
$def = $bits_def;
}
else if (strlen($mib) && strlen($object) &&
isset($config['mibs'][$mib]['states_bits'][$object]))
{
} elseif (!safe_empty($mib) && !safe_empty($object) &&
isset($config['mibs'][$mib]['states_bits'][$object])) {
$def = $config['mibs'][$mib]['states_bits'][$object];
}
if (empty($def))
{
if (empty($def) || !is_array($def)) {
print_debug("Incorrect BITS state definition passed.");
return NULL;
return [];
}
print_debug_vars($def);
//print_debug_vars($def);
//$bit_array = array_reverse(str_split(hex2binmap($hex)));
$bit_array = str_split(hex2binmap($hex));
print_debug_vars($bit_array);
//print_debug_vars($bit_array);
$state_array = [];
foreach ($bit_array as $bit => $value)
{
if ($value)
{
foreach ($bit_array as $bit => $set) {
if ($set) {
$state_array[$bit] = $def[$bit]['name'];
}
}
@ -736,7 +730,7 @@ function poll_status($device, &$oid_cache)
if (isset($old_state_array['discovery']) && is_module_enabled($device, $old_state_array['discovery'], 'discovery'))
{
force_discovery($device, $old_state_array['discovery']);
print_debug("Module ${old_state_array['discovery']} force for discovery by changed status type ${status_db['status_mib']}::${status_db['status_object']}");
print_debug("Module {$old_state_array['discovery']} force for discovery by changed status type {$status_db['status_mib']}::{$status_db['status_object']}");
}
}
} else {

View File

@ -0,0 +1,478 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage entities
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
function discover_storage_definition($device, $mib, $entry, $object) {
$entry['found'] = FALSE;
$entry['object'] = $object;
echo($object . ' [');
// Just append mib name to definition entry, for simple pass to external functions
if (empty($entry['mib'])) {
$entry['mib'] = $mib;
}
// Check that types listed in skip_if_valid_exist have already been found
if (discovery_check_if_type_exist($entry, 'storage')) { echo '!]'; return; }
// Check array requirements list
if (discovery_check_requires_pre($device, $entry, 'storage')) { echo '!]'; return; }
// oid_*_hc and oid_*_high/oid_*_low used with storage_hc flag
$table_oids = [ 'oid_total', 'oid_total_hc', 'oid_total_high', 'oid_total_low',
'oid_used', 'oid_used_hc', 'oid_used_high', 'oid_used_low',
'oid_free', 'oid_free_hc', 'oid_free_high', 'oid_free_low',
'oid_perc', 'oid_descr', 'oid_scale', 'oid_unit',
'oid_type', 'oid_online', 'oid_extra',
//'oid_limit_low', 'oid_limit_low_warn', 'oid_limit_high_warn', 'oid_limit_high',
//'oid_limit_nominal', 'oid_limit_delta_warn', 'oid_limit_delta', 'oid_limit_scale'
];
$storage_array = discover_fetch_oids($device, $mib, $entry, $table_oids);
// FIXME - generify description generation code and just pass it template and OID array.
$i = 1; // Used in descr as %i%
$storage_count = count($storage_array);
foreach ($storage_array as $index => $storage_entry) {
$options = [];
//$oid_num = $entry['oid_num'] . '.' . $index;
// Storage Type
if (isset($entry['oid_type']) && $storage_entry[$entry['oid_type']]) {
$storage_entry['type'] = $storage_entry[$entry['oid_type']];
} elseif (isset($entry['type'])) {
$storage_entry['type'] = $entry['type'];
} else {
// Compat (incorrect)
$storage_entry['type'] = $object;
}
$options['storage_type'] = $storage_entry['type'];
// Generate storage description
$storage_entry['i'] = $i;
$storage_entry['index'] = $index;
foreach (explode('.', $index) as $k => $i) {
$storage_entry['index'.$k] = $i; // Index parts
}
$descr = entity_descr_definition('storage', $entry, $storage_entry, $storage_count);
// Check valid exist with entity tags
if (discovery_check_if_type_exist($entry, 'storage', $storage_entry)) { continue; }
// Check array requirements list
if (discovery_check_requires($device, $entry, $storage_entry, 'storage')) { continue; }
// Init
$used = NULL;
$total = NULL;
$free = NULL;
$perc = NULL;
$hc = isset($entry['hc']) && $entry['hc'];
// Convert strings '3.40 TB' to value
// See QNAP NAS-MIB or HIK-DEVICE-MIB
$unit = !isset($entry['unit']) ? NULL : $entry['unit'];
// Fetch used, total, free and percentage values, if OIDs are defined for them
if (!safe_empty($entry['total'])) {
// Prefer hardcoded total over SNMP OIDs
$total = $entry['total'];
} else {
if (isset($entry['oid_total_high'], $entry['oid_total_low'])) {
$high = snmp_fix_numeric($storage_entry[$entry['oid_total_high']]);
$low = snmp_fix_numeric($storage_entry[$entry['oid_total_low']]);
if ($total = snmp_size64_high_low($high, $low)) {
$hc = TRUE; // set HC flag
}
}
if (!is_numeric($total) && isset($entry['oid_total_hc']) &&
$total = snmp_fix_numeric($storage_entry[$entry['oid_total_hc']], $unit)) {
$hc = TRUE; // set HC flag
}
if (!is_numeric($total) && isset($entry['oid_total'])) {
$total = snmp_fix_numeric($storage_entry[$entry['oid_total']], $unit);
}
}
if (isset($entry['oid_used_high'], $entry['oid_used_low'])) {
$high = snmp_fix_numeric($storage_entry[$entry['oid_used_high']]);
$low = snmp_fix_numeric($storage_entry[$entry['oid_used_low']]);
$used = snmp_size64_high_low($high, $low);
if (is_numeric($used)) {
$hc = TRUE; // set HC flag
}
}
if (!is_numeric($used) && isset($entry['oid_used_hc'])) {
$used = snmp_fix_numeric($storage_entry[$entry['oid_used_hc']], $unit);
if (is_numeric($used)) {
$hc = TRUE; // set HC flag
}
}
if (!is_numeric($used) && isset($entry['oid_used'])) {
$used = snmp_fix_numeric($storage_entry[$entry['oid_used']], $unit);
}
if (isset($entry['oid_free_high'], $entry['oid_free_low'])) {
$high = snmp_fix_numeric($storage_entry[$entry['oid_free_high']]);
$low = snmp_fix_numeric($storage_entry[$entry['oid_free_low']]);
$free = snmp_size64_high_low($high, $low);
if (is_numeric($free)) {
$hc = TRUE; // set HC flag
}
}
if (!is_numeric($free) && isset($entry['oid_free_hc'])) {
$free = snmp_fix_numeric($storage_entry[$entry['oid_free_hc']], $unit);
if (is_numeric($free)) {
$hc = TRUE; // set HC flag
}
}
if (!is_numeric($free) && isset($entry['oid_free'])) {
$free = snmp_fix_numeric($storage_entry[$entry['oid_free']], $unit);
}
if (isset($entry['oid_perc'])) {
$perc = snmp_fix_numeric($storage_entry[$entry['oid_perc']]);
}
// Scale
$scale = entity_scale_definition($device, $entry, $storage_entry);
// HC
if ($hc) {
$options['storage_hc'] = 1;
}
// Oper status / Ignore (see NIMBLE-MIB)
if (isset($entry['oid_online'], $storage_entry[$entry['oid_online']])) {
$options['storage_ignore'] = get_var_false($storage_entry[$entry['oid_online']]);
}
// Extrapolate all values from the ones we have.
$storage = calculate_mempool_properties($scale, $used, $total, $free, $perc, $entry);
print_debug_vars([ $scale, $used, $total, $free, $perc, $options ]);
print_debug_vars($storage_entry);
print_debug_vars($storage);
//print_debug_vars([ is_numeric($storage['used']), is_numeric($storage['total']) ]);
// If we have valid used and total, discover the storage
$entry['found'] = discover_storage_ng($device, $mib, $object, $index, $descr, $scale, $storage, $options);
$i++;
}
echo '] ';
}
function discover_storage_ng($device, $storage_mib, $storage_object, $storage_index, $storage_descr, $storage_units, $storage, $options = []) {
global $valid;
// options && limits
$option = 'storage_hc';
$$option = (isset($options[$option]) && $options[$option]) ? 1 : 0;
$option = 'storage_ignore';
$$option = (isset($options[$option]) && $options[$option]) ? 1 : 0;
if (isset($options['limit_high'])) { $storage_crit_limit = $options['limit_high']; }
if (isset($options['limit_high_warn'])) { $storage_warn_limit = $options['limit_high_warn']; }
// FIXME. Ignore 0 storage size?
$storage_size = $storage['total'];
$storage_used = $storage['used'];
$storage_free = $storage['free'];
$storage_perc = $storage['perc'];
$storage_type = isset($options['storage_type']) ? $options['storage_type'] : $object;
print_debug($device['device_id']." -> $storage_index, $storage_object, $storage_mib, $storage_descr, $storage_units, $storage_size, $storage_used, $storage_hc");
if (!is_numeric($storage['total']) || !is_numeric($storage['used'])) {
print_debug("Skipped by not numeric storage values.");
return FALSE;
}
if (isset($storage['valid']) && !$storage['valid']) {
print_debug("Skipped by empty storage Size [$storage_size] or invalid Percent [$storage_perc] values.");
return FALSE;
}
// Check storage ignore filters
if (entity_descr_check($storage_descr, 'storage')) { return FALSE; }
// Search duplicates for same mib/descr
if (in_array($storage_descr, array_values((array)$valid['storage'][$storage_mib]))) {
print_debug("Skipped by already exist: $storage_descr ");
return FALSE;
}
$params = [ 'storage_index', 'storage_mib', 'storage_object', 'storage_type', 'storage_descr',
'storage_hc', 'storage_ignore', 'storage_units', 'storage_crit_limit', 'storage_warn_limit' ];
// This is changeable params, not required for update
$params_state = [ 'storage_size', 'storage_used', 'storage_free', 'storage_perc' ];
$device_id = $device['device_id'];
$storage_db = dbFetchRow("SELECT * FROM `storage` WHERE `device_id` = ? AND `storage_index` = ? AND `storage_mib` = ?", [ $device_id, $storage_index, $storage_mib ]);
if (!isset($storage_db['storage_id'])) {
$update = [ 'device_id' => $device_id ];
foreach (array_merge($params, $params_state) as $param) {
$update[$param] = ($$param === NULL ? [ 'NULL' ] : $$param);
}
$id = dbInsert($update, 'storage');
$GLOBALS['module_stats']['storage']['added']++; //echo('+');
log_event("Storage added: index $storage_index, mib $storage_mib, descr $storage_descr", $device, 'storage', $id);
} else {
$update = [];
foreach ($params as $param) {
if ($$param != $storage_db[$param] ) { $update[$param] = ($$param === NULL ? [ 'NULL' ] : $$param); }
}
if (count($update)) {
//if (isset($update['storage_descr']))
//{
// // Rename storage rrds, because its filename based on description
// $old_rrd = $config['rrd_dir'] . '/' . $device['hostname'] . '/' . safename('storage-' . $storage_db['storage_mib'] . '-' . $storage_db['storage_descr'] . '.rrd');
// $new_rrd = $config['rrd_dir'] . '/' . $device['hostname'] . '/' . safename('storage-' . $storage_db['storage_mib'] . '-' . $storage_descr . '.rrd');
// if (is_file($old_rrd) && !is_file($new_rrd)) { rename($old_rrd, $new_rrd); print_warning("Moved RRD"); }
//}
dbUpdate($update, 'storage', '`storage_id` = ?', array($storage_db['storage_id']));
$GLOBALS['module_stats']['storage']['updated']++; //echo('U');
log_event("Storage updated: index $storage_index, mib $storage_mib, descr $storage_descr", $device, 'storage', $storage_db['storage_id']);
} else {
$GLOBALS['module_stats']['storage']['unchanged']++; //echo('.');
}
}
print_debug_vars($update);
if ($storage_ignore) {
$GLOBALS['module_stats']['storage']['ignored']++;
}
$valid['storage'][$storage_mib][$storage_index] = $storage_descr;
return TRUE;
}
function poll_storage_definition($device, $entry, &$storage, $cache_storage) {
// Fetch used, total, free and percentage values, if OIDs are defined for them
if (!safe_empty($entry['total'])) {
// Prefer hardcoded total over SNMP OIDs
$total = $entry['total'];
} else {
$total = get_storage_value($device, 'total', $entry, $storage, $cache_storage);
}
$used = get_storage_value($device, 'used', $entry, $storage, $cache_storage);
$free = get_storage_value($device, 'free', $entry, $storage, $cache_storage);
$perc = get_storage_value($device, 'perc', $entry, $storage, $cache_storage);
if (isset($entry['oid_online'])) {
$mib = $storage['storage_mib'];
$index = $storage['storage_index'];
if (isset($cache_storage[$mib][$index][$entry['oid_online']])) {
$value = $cache_storage[$mib][$index][$entry['oid_online']];
} else {
$value = snmp_get_oid($device, $entry['oid_online'].'.'.$index, $mib);
}
// FIXME, probably need additional field for storages like OperStatus up/down
$ignore = get_var_false($value) ? 1 : 0;
if ($storage['storage_ignore'] != $ignore) {
force_discovery($device, 'storage');
}
}
// Merge calculated used/total/free/perc array keys into $storage variable (with additional options)
$storage = array_merge($storage, calculate_mempool_properties($storage['storage_units'], $used, $total, $free, $perc, $entry));
$storage['size'] = $storage['total'];
}
function get_storage_value($device, $param, $entry, $storage, $cache_storage = []) {
$mib = $storage['storage_mib'];
$index = $storage['storage_index'];
$hc = $storage['storage_hc'];
// Convert strings '3.40 TB' to value
// See QNAP NAS-MIB or HIK-DEVICE-MIB
$unit = ($param !== 'perc' && isset($entry['unit'])) ? $entry['unit'] : NULL;
$value = NULL;
if (isset($entry['oid_'.$param.'_high'], $entry['oid_'.$param.'_low'])) {
// High+Low set of values
if (isset($cache_storage[$mib][$index][$entry['oid_'.$param.'_high']])) {
// Cached
$high = $cache_storage[$mib][$index][$entry['oid_'.$param.'_high']];
$low = $cache_storage[$mib][$index][$entry['oid_'.$param.'_low']];
} elseif ($hc) {
if (isset($entry['oid_'.$param.'_high_num'])) { $high = snmp_get_oid($device, $entry['oid_'.$param.'_high_num'].'.'.$index); }
elseif (isset($entry['oid_'.$param.'_high'])) { $high = snmp_get_oid($device, $entry['oid_'.$param.'_high'].'.'.$index, $mib); }
if (isset($entry['oid_'.$param.'_low_num'])) { $low = snmp_get_oid($device, $entry['oid_'.$param.'_low_num'].'.'.$index); }
elseif (isset($entry['oid_'.$param.'_low'])) { $low = snmp_get_oid($device, $entry['oid_'.$param.'_low'].'.'.$index, $mib); }
}
$high = snmp_fix_numeric($high);
$low = snmp_fix_numeric($low);
$value = snmp_size64_high_low($high, $low);
}
if ($hc && isset($entry['oid_'.$param.'_hc']) && !is_numeric($value)) {
// Common HC value
if (isset($cache_storage[$mib][$index][$entry['oid_'.$param.'_hc']])) {
$value = snmp_fix_numeric($cache_storage[$mib][$index][$entry['oid_'.$param.'_hc']], $unit);
} else {
if (isset($entry['oid_'.$param.'_hc_num'])) { $value = snmp_fix_numeric(snmp_get_oid($device, $entry['oid_'.$param.'_hc_num'].'.'.$index), $unit); }
elseif (isset($entry['oid_'.$param.'_hc'])) { $value = snmp_fix_numeric(snmp_get_oid($device, $entry['oid_'.$param.'_hc'].'.'.$index, $mib), $unit); }
}
}
if (!is_numeric($value) && isset($entry['oid_'.$param])) {
// Common value
if (isset($cache_storage[$mib][$index][$entry['oid_'.$param]])) {
$value = snmp_fix_numeric($cache_storage[$mib][$index][$entry['oid_'.$param]], $unit);
} else {
if (isset($entry['oid_'.$param.'_num'])) { $value = snmp_fix_numeric(snmp_get_oid($device, $entry['oid_'.$param.'_num'].'.'.$index), $unit); }
elseif (isset($entry['oid_'.$param])) { $value = snmp_fix_numeric(snmp_get_oid($device, $entry['oid_'.$param].'.'.$index, $mib), $unit); }
}
}
return $value;
}
/**
* Poll and cache entity _NUMERIC_ Oids,
* need for cross cache between different entities, ie status and sensors
*
* @param $device
* @param $oid_cache
*
* @return bool
*/
function poll_cache_storage($device, &$oid_cache) {
global $config;
$mib_walk_option = 'storage_walk'; // ie: $config['mibs'][$mib]['storage_walk']
//$snmp_flags = OBS_SNMP_ALL_NUMERIC; // Numeric Oids by default
// CLEANME. Compatibility with old (incorrect) field
$object_field = get_db_version() > 468 ? 'storage_object' : 'storage_type';
// Walk query
$walk_query = "SELECT `storage_mib`, `$object_field`, `storage_hc`, GROUP_CONCAT(`storage_index` SEPARATOR ?) AS `indexes` FROM `storage` WHERE `device_id` = ? GROUP BY `storage_mib`, `$object_field`, `storage_hc`";
$walk_params = [ ',', $device['device_id'] ];
$oid_to_cache = [];
foreach (dbFetchRows($walk_query, $walk_params, TRUE) as $entry) {
if (!isset($config['mibs'][$entry['storage_mib']]['storage'][$entry[$object_field]])) {
// Cache only definition based
continue;
}
$def = $config['mibs'][$entry['storage_mib']]['storage'][$entry[$object_field]];
$hc = $entry['storage_hc'];
// Explode indexes from GROUP_CONCAT()
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['indexes'] = explode(',', $entry['indexes']);
// Storage need only this oids in poller
$total = FALSE;
$used = FALSE;
$free = FALSE;
if ($hc) {
// HC oids
if (isset($def['oid_total_high'], $def['oid_total_low'])) {
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_total_high'];
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_total_low'];
$total = TRUE;
} elseif (isset($def['oid_total_hc'])) {
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_total_hc'];
$total = TRUE;
}
if (isset($def['oid_used_high'], $def['oid_used_low'])) {
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_used_high'];
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_used_low'];
$used = TRUE;
} elseif (isset($def['oid_used_hc'])) {
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_used_hc'];
$used = TRUE;
}
if (isset($def['oid_free_high'], $def['oid_free_low'])) {
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_free_high'];
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_free_low'];
$free = TRUE;
} elseif (isset($def['oid_free_hc'])) {
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_free_hc'];
$free = TRUE;
}
}
if (!$total && isset($def['oid_total'])) {
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_total'];
}
if (!$used && isset($def['oid_used'])) {
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_used'];
}
if (!$free && isset($def['oid_free'])) {
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_free'];
}
if (isset($def['oid_perc'])) {
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_perc'];
}
if (isset($def['oid_online'])) {
$oid_to_cache[$entry['storage_mib']][$entry[$object_field]]['oids'][] = $def['oid_online'];
}
}
foreach ($oid_to_cache as $mib => $object_array) {
foreach ($object_array as $object => $entry) {
//$def = $config['mibs'][$mib]['storage'][$type];
if (isset($config['mibs'][$mib][$mib_walk_option]) &&
!$config['mibs'][$mib][$mib_walk_option]) {
// MIB not support walk (by definition)
$use_walk = FALSE;
} else {
// Walk on multiple indexes
$use_walk = count($entry['indexes']) > 1;
}
if ($use_walk) {
// SNMP walk
if (isset($GLOBALS['cache']['snmp_object_polled'][$mib][$object])) {
print_debug("MIB/Type ($mib::$object) already polled.");
continue;
}
print_debug("Caching storage snmpwalk by $mib");
foreach ($entry['oids'] as $oid) {
$oid_cache[$mib] = snmpwalk_multipart_oid($device, $oid, $oid_cache[$mib], $mib, NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
}
$GLOBALS['cache']['snmp_object_polled'][$mib][$object] = 1;
} else {
// SNMP multiget
print_debug("Caching storage snmpget by $mib");
$oids = [];
foreach ($entry['oids'] as $oid) {
foreach ($entry['indexes'] as $index) {
$oids[] = $oid . '.' . $index;
}
}
$oid_cache[$mib] = snmp_get_multi_oid($device, $oids, $oid_cache[$mib], $mib);
}
}
}
print_debug_vars($oid_to_cache);
print_debug_vars($oid_cache);
return !empty($oid_to_cache);
}
// EOF

View File

@ -13,10 +13,11 @@
//MOVEME. to includes/entities/wifi.inc.php
// Discover an entity by populating/updating a database table and returning an id
/* I think this is still experimental by adama, pls see discover_entity_definition() common as other entities
function discover_entity($device_id, $entity_type, $data)
{
return FALSE;
if (is_array($GLOBALS['config']['entities'][$entity_type])) {
$def = $GLOBALS['config']['entities'][$entity_type];
@ -26,8 +27,6 @@ function discover_entity($device_id, $entity_type, $data)
if (isset($params['table_fields']['index']) && is_array())
{
} elseif (isset($params['table_fields']['index'])) {
} else {
@ -89,7 +88,6 @@ function discover_entity($device_id, $entity_type, $data)
return $id;
}
*/
/**
* Discover WIFI Access Point. Returns ap_id.