$old_ifSpeed_bool = $new_ifSpeed_bool = FALSE; // Skip change } } if ($old_ifSpeed_bool && $new_ifSpeed_bool) { // Both set, compare values if ($vars['ifSpeed_custom_' . $port_id] != $port['ifSpeed_custom']) { //r($vars['ifSpeed_custom_' . $port_id]); r($port['ifSpeed_custom']); set_entity_attrib('port', $port_id, 'ifSpeed_custom', $vars['ifSpeed_custom_' . $port_id]); $updated = TRUE; } } else { if ($old_ifSpeed_bool !== $new_ifSpeed_bool) { // Added or removed if ($old_ifSpeed_bool) { del_entity_attrib('port', $port_id, 'ifSpeed_custom'); } else { set_entity_attrib('port', $port_id, 'ifSpeed_custom', $vars['ifSpeed_custom_' . $port_id]); } $updated = TRUE; } } // Count updates if ($updated) { $rows_updated++; } } if ($rows_updated > 0) { $update_message = $rows_updated . " Port entries updated."; $updated = 1; } else {
function discover_device($device, $options = NULL) { global $config, $valid, $exec_status, $discovered_devices; // Initialise variables $valid = array(); // Reset $valid array $modules = array(); $cache_discovery = array(); // Specific discovery cache for exchange snmpwalk data between modules (memory/storage/sensors/etc) $attribs = get_entity_attribs('device', $device['device_id']); $device_start = utime(); // Start counting device poll time // Check if device discovery already running $pid_info = check_process_run($device); if ($pid_info) { // Process ID exist in DB print_message("%rAnother " . $pid_info['process_name'] . " process (PID: " . $pid_info['PID'] . ", UID: " . $pid_info['UID'] . ", STARTED: " . $pid_info['STARTED'] . ") already running for device " . $device['hostname'] . " (" . $device['device_id'] . ").%n", 'color'); return FALSE; } add_process_info($device); // Store process info print_cli_heading($device['hostname'] . " [" . $device['device_id'] . "]", 1); $detect_os = TRUE; // Set TRUE or FALSE for module 'os' (exclude double os detection) if ($device['os'] == 'generic' || isset($options['h']) && $options['h'] == 'new') { $detect_os = FALSE; $old_os = $device['os']; $device['os'] = get_device_os($device); if ($device['os'] != $old_os) { print_cli_data("Device OS changed", $old_os . " -> " . $device['os'], 1); log_event('OS changed: ' . $old_os . ' -> ' . $device['os'], $device, 'device', $device['device_id'], 'warning'); dbUpdate(array('os' => $device['os']), 'devices', '`device_id` = ?', array($device['device_id'])); } } print_cli_data("OS Type", $device['os'], 1); if ($config['os'][$device['os']]['group']) { $device['os_group'] = $config['os'][$device['os']]['group']; print_cli_data("OS Group", $device['os_group'], 1); } print_cli_data("SNMP Version", $device['snmp_version'], 1); print_cli_data("Last discovery", $device['last_discovered'], 1); print_cli_data("Last duration", $device['last_discovered_timetaken'] . " seconds", 1); echo PHP_EOL; // Either only run the modules specified on the commandline, or run all modules in config. if ($options['m']) { foreach (explode(",", $options['m']) as $module) { $modules[$module] = TRUE; } } else { if ($device['force_discovery'] && $options['h'] == 'new' && isset($attribs['force_discovery_modules'])) { // Forced discovery specific modules foreach (json_decode($attribs['force_discovery_modules'], TRUE) as $module) { $modules[$module] = TRUE; } log_event('Forced discovery module(s): ' . implode(', ', array_keys($modules)), $device, 'device', $device['device_id'], 'debug'); } else { $modules = $config['discovery_modules']; } } // Use os specific modules order //print_vars($modules); if (isset($config['os'][$device['os']]['discovery_order'])) { //print_vars($config['os'][$device['os']]['discovery_order']); foreach ($config['os'][$device['os']]['discovery_order'] as $module => $module_order) { if (array_key_exists($module, $modules)) { $module_status = $modules[$module]; switch ($module_order) { case 'last': // add to end of modules list unset($modules[$module]); $modules[$module] = $module_status; break; case 'first': // add to begin of modules list, but not before os/system $new_modules = array(); if ($modules['os']) { $new_modules['os'] = $modules['os']; unset($modules['os']); } if ($modules['system']) { $new_modules['system'] = $modules['system']; unset($modules['system']); } $new_modules[$module] = $module_status; unset($modules[$module]); $modules = $new_modules + $modules; break; default: // add into specific place (after module name in $module_order) // yes, this is hard and magically if (array_key_exists($module_order, $modules)) { unset($modules[$module]); $new_modules = array(); foreach ($modules as $new_module => $new_status) { array_shift($modules); $new_modules[$new_module] = $new_status; if ($new_module == $module_order) { $new_modules[$module] = $module_status; break; } } $modules = array_merge($new_modules, (array) $modules); } } } } //print_vars($modules); } foreach ($modules as $module => $module_status) { if (discovery_module_excluded($device, $module) === FALSE) { if ($attribs['discover_' . $module] || $module_status && !isset($attribs['discover_' . $module])) { $m_start = utime(); $GLOBALS['module_stats'][$module] = array(); print_cli_heading("Module Start: %R" . $module . ""); include "includes/discovery/{$module}.inc.php"; $m_end = utime(); $GLOBALS['module_stats'][$module]['time'] = round($m_end - $m_start, 4); print_module_stats($device, $module); echo PHP_EOL; //print_cli_heading("Module End: %R".$module.""); } elseif (isset($attribs['discover_' . $module]) && $attribs['discover_' . $module] == "0") { print_debug("Module [ {$module} ] disabled on host."); } else { print_debug("Module [ {$module} ] disabled globally."); } } } // Set type to a predefined type for the OS if it's not already set if ($device['type'] == "unknown" || $device['type'] == "") { if ($config['os'][$device['os']]['type']) { $device['type'] = $config['os'][$device['os']]['type']; } } $device_end = utime(); $device_run = $device_end - $device_start; $device_time = substr($device_run, 0, 5); dbUpdate(array('last_discovered' => array('NOW()'), 'type' => $device['type'], 'last_discovered_timetaken' => $device_time, 'force_discovery' => 0), 'devices', '`device_id` = ?', array($device['device_id'])); if (isset($attribs['force_discovery_modules'])) { del_entity_attrib('device', $device['device_id'], 'force_discovery_modules'); } // Put performance into devices_perftimes table // Not worth putting discovery data into rrd. it's not done every 5 mins :) dbInsert(array('device_id' => $device['device_id'], 'operation' => 'discover', 'start' => $device_start, 'duration' => $device_run), 'devices_perftimes'); print_cli_heading($device['hostname'] . " [" . $device['device_id'] . "] completed discovery modules at " . date("Y-m-d H:i:s"), 1); print_cli_data("Discovery time", $device_time . " seconds", 1); echo PHP_EOL; $discovered_devices++; // Clean del_process_info($device); // Remove process info unset($cache_discovery); }
} */ } 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'); print_cli_table($table_rows, $table_headers); } } else { // sysORID table disabled, delete the attribute del_entity_attrib('device', $device, 'sysORID'); } // EOF
$updated = 2; } if ($override_sysLocation_bool) { set_entity_attrib('device', $device, 'override_sysLocation_bool', '1'); } else { del_entity_attrib('device', $device, 'override_sysLocation_bool'); } if (isset($override_sysLocation_string)) { set_entity_attrib('device', $device, 'override_sysLocation_string', $override_sysLocation_string); } $ping_skip_set = isset($vars['ping_skip']) && ($vars['ping_skip'] == 'on' || $vars['ping_skip'] == '1'); if ($ping_skip != $ping_skip_set) { if ($ping_skip_set) { set_entity_attrib('device', $device, 'ping_skip', '1'); } else { del_entity_attrib('device', $device, 'ping_skip'); } $ping_skip = get_entity_attrib('device', $device, 'ping_skip'); $updated++; } # FIXME needs more sanity checking! and better feedback # FIXME -- update location too? Need to trigger geolocation! $param = array('purpose' => $vars['descr'], 'type' => $vars['type'], 'ignore' => $vars['ignore'], 'disabled' => $vars['disabled']); $rows_updated = dbUpdate($param, 'devices', '`device_id` = ?', array($device['device_id'])); if ($rows_updated > 0 || $updated) { if ((bool) $vars['ignore'] != (bool) $device['ignore']) { log_event('Device ' . ((bool) $vars['ignore'] ? 'ignored' : 'attended') . ': ' . $device['hostname'], $device['device_id'], 'device', $device['device_id'], 5); } if ((bool) $vars['disabled'] != (bool) $device['disabled']) { log_event('Device ' . ((bool) $vars['disabled'] ? 'disabled' : 'enabled') . ': ' . $device['hostname'], $device['device_id'], 'device', $device['device_id'], 5); }
function del_dev_attrib($device, $attrib_type) { // Call to new function return del_entity_attrib('device', $device, $attrib_type); }
include $config['install_dir'] . '/includes/polling/functions.inc.php'; // Fetch all MIBs we support for this specific OS foreach (get_device_mibs($device) as $mib) { $mibs[$mib]++; } // Sort alphabetically ksort($mibs); $attribs = get_entity_attribs('device', $device['device_id']); if ($vars['submit']) { if ($readonly) { print_error_permission('You have insufficient permissions to edit settings.'); } else { if ($vars['toggle_mib'] && isset($mibs[$vars['toggle_mib']])) { $mib = $vars['toggle_mib']; if (isset($attribs['mib_' . $mib])) { del_entity_attrib('device', $device, 'mib_' . $mib); } else { set_entity_attrib('device', $device, 'mib_' . $mib, "0"); } // reload attribs $attribs = get_entity_attribs('device', $device['device_id']); } } } //$poll_period = 300; $error_codes = $GLOBALS['config']['snmp']['errorcodes']; $poll_period = $GLOBALS['config']['rrd']['step']; // Count critical errors into DB (only for poller) $snmp_errors = array(); $sql = 'SELECT * FROM `snmp_errors` WHERE `device_id` = ?;'; foreach (dbFetchRows($sql, array($device['device_id'])) as $entry) {