// -- i can make it a function, so that you don't know what it's doing. // -- $ports = adamasMagicFunction($ports_db); ? $query = 'SELECT * FROM `ports`'; //$query .= ' LEFT JOIN `ports-state` USING(`port_id`)'; $query .= ' WHERE `device_id` = ?'; $ports_db = dbFetchRows($query, array($device['device_id'])); $ports_attribs = get_device_entities_attribs($device['device_id'], 'port'); // Get all attribs //print_vars($ports_attribs); foreach ($ports_db as $port) { if (isset($ports_attribs['port'][$port['port_id']])) { $port = array_merge($port, $ports_attribs['port'][$port['port_id']]); } $ports[$port['ifIndex']] = $port; } $ports_ignored_count_db = intval(get_entity_attrib('device', $device, 'ports_ignored_count')); // Cache last ports ignored count // Ports module options foreach (array('etherlike', 'adsl', 'poe', 'docsis', 'junoseatmvp', 'separate_walk') as $ports_module) { $ports_modules[$ports_module] = isset($attribs['enable_ports_' . $ports_module]) ? (bool) $attribs['enable_ports_' . $ports_module] : $config['enable_ports_' . $ports_module]; } // Additionally force enable separate walk feature for some device oses, but only if ports total count >10 $ports_module = 'separate_walk'; if (!$ports_modules[$ports_module] && $config['os'][$device['os']]['ports_' . $ports_module]) { if (isset($attribs['enable_ports_' . $ports_module]) && !$attribs['enable_ports_' . $ports_module]) { } else { $ports_total_count = $ports_ignored_count_db + dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE `device_id` = ? AND `deleted` = 0', array($device['device_id'])); $ports_modules[$ports_module] = $ports_total_count > 10; if (OBS_DEBUG && $ports_modules[$ports_module]) { print_debug('Forced ports separate walk feature!'); }
function force_discovery($device, $modules = array()) { $return = FALSE; if (count($modules) == 0) { // Modules not passed, just full rediscover device $return = dbUpdate(array('force_discovery' => 1), 'devices', '`device_id` = ?', array($device['device_id'])); } else { // Modules passed, check if modules valid and enabled $modules = (array) $modules; $forced_modules = get_entity_attrib('device', $device['device_id'], 'force_discovery_modules'); if ($forced_modules) { // Already forced modules exist, merge it with new $modules = array_unique(array_merge($modules, json_decode($forced_modules, TRUE))); } $valid_modules = array(); foreach ($GLOBALS['config']['discovery_modules'] as $module => $ok) { // Filter by valid and enabled modules if ($ok && in_array($module, $modules)) { $valid_modules[] = $module; } } if (count($valid_modules)) { $return = dbUpdate(array('force_discovery' => 1), 'devices', '`device_id` = ?', array($device['device_id'])); set_entity_attrib('device', $device['device_id'], 'force_discovery_modules', json_encode($valid_modules)); } } return $return; }
$update_message = "Device record updated."; if ($updated == 2) { $update_message .= " Please note that the updated sysLocation string will only be visible after the next poll."; } $updated = 1; $device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device['device_id'])); } elseif ($rows_updated = '-1') { $update_message = "Device record unchanged. No update necessary."; $updated = -1; } else { $update_message = "Device record update error."; } } } $override_sysLocation_bool = get_entity_attrib('device', $device, 'override_sysLocation_bool'); $override_sysLocation_string = get_entity_attrib('device', $device, 'override_sysLocation_string'); if ($updated && $update_message) { print_message($update_message); } else { if ($update_message) { print_error($update_message); } } $types = array(); foreach ($config['device_types'] as $type) { $types[$type['type']] = array('name' => nicecase($type['type']), 'icon' => $type['icon']); } if (!in_array($device['type'], array_keys($types))) { $types[$device['type']] = array('name' => 'Other', 'icon' => 'oicon-question'); } $form = array('type' => 'horizontal', 'id' => 'edit', 'title' => 'General Device Settings', 'icon' => 'oicon-gear', 'fieldset' => array('edit' => ''));
set_obs_attrib('sysOROID_unused', json_encode($tmp_diff)); foreach($tmp_diff as $entry) { $tmp_rows[] = array($entry, 'MIB unused'); } echo("\n"); print_cli_table($tmp_rows, array('%WOID%n', '%WStatus%n')); } */ } else { echo '<empty>'; } echo PHP_EOL; // Set device attribute if we found any new MIBs, else delete the attribute if (count($sysORID_mibs)) { $sysORID_db = json_decode(get_entity_attrib('device', $device, 'sysORID'), TRUE); set_entity_attrib('device', $device, 'sysORID', json_encode($sysORID_mibs)); $update_array = array_diff($sysORID_mibs, (array) $sysORID_db); //print_vars($sysORID_db); //print_vars($sysORID_mibs); //print_vars($update_array); if (count($update_array)) { log_event("MIBs discovered through sysORID: '" . implode("', '", $update_array) . "'", $device, 'device', $device['device_id']); } } else { del_entity_attrib('device', $device, 'sysORID'); } unset($sysORID_mibs, $device_sysORID, $device_mibs, $device_mibs_bl, $advertised_mibs, $capabilities_mibs, $capabilities_unused, $found_mibs, $identity_found, $update_array); if (count($table_rows)) { echo PHP_EOL; $table_headers = array('%WOID%n', '%WMIB%n', '%WStatus%n');
function get_device_mibs($device, $check_sysORID = TRUE, $mibs_order = NULL) { global $config, $cache; if (is_numeric($device)) { $device_id = $device; $device = device_by_id_cache($device_id); } else { $device_id = $device['device_id']; } // Set custom mibs order $mibs_order_default = array('model', 'os', 'group', 'default'); if (empty($mibs_order)) { // Default order: per-model mibs (if model set) -> os mibs -> os group mibs -> default mibs $mibs_order = $mibs_order_default; } else { if (!is_array($mibs_order)) { // Order can passed as string with comma: 'model,os,group,default' $mibs_order = explode(',', $mibs_order); } } // Check if custom order used, than set first from passed argument, second from default if ($mibs_order_custom = $mibs_order !== $mibs_order_default) { // Set first from passed argument, second $mibs_order = array_unique(array_merge($mibs_order, $mibs_order_default)); } // Cache main device MIBs list if (!isset($cache['devices']['mibs'][$device_id])) { $mibs = array(); foreach ($mibs_order as $order) { switch ($order) { case 'model': if (isset($config['os'][$device['os']]['model'])) { $model = $config['os'][$device['os']]['model']; $sysObjectID = preg_match('/^\\.\\d[\\d\\.]+$/', $device['sysObjectID']) ? $device['sysObjectID'] : 'WRONG_ID'; krsort($config['model'][$model]); // Resort array by key with high to low order! foreach ($config['model'][$model] as $key => $entry) { if (isset($entry['mibs']) && strpos($sysObjectID, $key) === 0) { $mibs = array_merge($mibs, (array) $entry['mibs']); break; } } } break; case 'os': $mibs = array_merge((array) $mibs, (array) $config['os'][$device['os']]['mibs']); break; case 'group': $mibs = array_merge((array) $mibs, (array) $config['os_group'][$config['os'][$device['os']]['group']]['mibs']); break; case 'default': $mibs = array_merge((array) $mibs, (array) $config['os']['default']['mibs']); break; } } $mibs = array_unique($mibs); //$mibs = array_unique(array_merge((array)$mibs, (array)$config['os'][$device['os']]['mibs'], // (array)$config['os_group'][$config['os'][$device['os']]['group']]['mibs'], // (array)$config['os']['default']['mibs'])); // Remove blacklisted MIBs from array $mibs = array_diff($mibs, get_device_mibs_blacklist($device)); $cache['devices']['mibs'][$device_id] = $mibs; } else { $mibs = $cache['devices']['mibs'][$device_id]; } // Add and cache sysORID supplied MIBs if any if ($check_sysORID) { if (!isset($cache['devices']['mibs_sysORID'][$device_id])) { $sysORID = json_decode(get_entity_attrib('device', $device, 'sysORID'), TRUE); if (is_array($sysORID)) { // Leave only not exist in main MIBs and blacklist $sysORID = array_diff($sysORID, get_device_mibs_blacklist($device), (array) $cache['devices']['mibs'][$device_id]); } else { $sysORID = array(); // Leave empty } $cache['devices']['mibs_sysORID'][$device_id] = $sysORID; } // Attach sysORID MIBs $mibs = array_merge((array) $cache['devices']['mibs'][$device_id], (array) $cache['devices']['mibs_sysORID'][$device_id]); } // Do not cache MIBs if custom order used if ($mibs_order_custom) { unset($cache['devices']['mibs'][$device_id]); } return $mibs; }