From 012ae953a0c32230bcbfffe764b866fb88215549 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 22 Jul 2014 16:07:31 +0000 Subject: [PATCH] 2014-07-22 Miguel de Dios * git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@10346 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 5 + .../agentes/agent_wizard.snmp_explorer.php | 233 ++++++++++-------- pandora_console/include/functions.php | 52 +++- 3 files changed, 179 insertions(+), 111 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index a6005a28a6..05a6f03e72 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,8 @@ +2014-07-22 Miguel de Dios + + * godmode/agentes/agent_wizard.snmp_explorer.php, + include/functions.php: some fixes for the snmp v3. + 2014-07-22 Miguel de Dios * godmode/agentes/agent_manager.php: fixed to show the QR code image diff --git a/pandora_console/godmode/agentes/agent_wizard.snmp_explorer.php b/pandora_console/godmode/agentes/agent_wizard.snmp_explorer.php index 4695500330..67687b215b 100644 --- a/pandora_console/godmode/agentes/agent_wizard.snmp_explorer.php +++ b/pandora_console/godmode/agentes/agent_wizard.snmp_explorer.php @@ -50,65 +50,74 @@ $create_modules = (int) get_parameter("create_modules", 0); // Get the plugin $plugin = db_get_row_sql('SELECT * FROM tplugin WHERE execute LIKE "%/snmp_remote.pl"'); -if(empty($plugin)) { +if (empty($plugin)) { ui_print_info_message(array('message' => __('The SNMP remote plugin doesnt seem to be installed') . '. ' . __('It is necessary to use some features') . '.

' . __('Please, install the SNMP remote plugin (The name of the plugin must be snmp_remote.pl)'), 'no_close' => true)); } // Define STATIC SNMP data $static_snmp_descriptions = array( - 'Load-1' => 'Load Average (Last minute)', - 'Load-5' => 'Load Average (Last 5 minutes)', - 'Load-15' => 'Load Average (Last 5 minutes)', - 'memTotalSwap' => 'Total Swap Size configured for the host', - 'memAvailSwap' => 'Available Swap Space on the host', - 'memTotalReal' => 'Total Real/Physical Memory Size on the host', - 'memAvailReal' => 'Available Real/Physical Memory Space on the host', - 'memTotalFree' => 'Total Available Memory on the host', - //'memShared' => 'Total Shared Memory', - 'memCached' => 'Total Cached Memory', - 'memBuffer' => 'Total Buffered Memory', - 'ssSwapIn' => 'Amount of memory swapped in from disk (kB/s)', - 'ssSwapOut' => 'Amount of memory swapped to disk (kB/s)', - 'ssIORawSent' => 'Number of blocks sent to a block device', - 'ssIORawReceived' => 'Number of blocks received from a block device', - 'ssRawInterrupts' => 'Number of interrupts processed', - 'ssRawContexts' => 'Number of context switches', - 'ssCpuRawUser' => 'user CPU time', - 'ssCpuRawSystem' => 'system CPU time', - 'ssCpuRawIdle' => 'idle CPU time' - ); - + 'Load-1' => 'Load Average (Last minute)', + 'Load-5' => 'Load Average (Last 5 minutes)', + 'Load-15' => 'Load Average (Last 5 minutes)', + 'memTotalSwap' => 'Total Swap Size configured for the host', + 'memAvailSwap' => 'Available Swap Space on the host', + 'memTotalReal' => 'Total Real/Physical Memory Size on the host', + 'memAvailReal' => 'Available Real/Physical Memory Space on the host', + 'memTotalFree' => 'Total Available Memory on the host', + //'memShared' => 'Total Shared Memory', + 'memCached' => 'Total Cached Memory', + 'memBuffer' => 'Total Buffered Memory', + 'ssSwapIn' => 'Amount of memory swapped in from disk (kB/s)', + 'ssSwapOut' => 'Amount of memory swapped to disk (kB/s)', + 'ssIORawSent' => 'Number of blocks sent to a block device', + 'ssIORawReceived' => 'Number of blocks received from a block device', + 'ssRawInterrupts' => 'Number of interrupts processed', + 'ssRawContexts' => 'Number of context switches', + 'ssCpuRawUser' => 'user CPU time', + 'ssCpuRawSystem' => 'system CPU time', + 'ssCpuRawIdle' => 'idle CPU time' + ); + $static_snmp_oids = array( - 'Load-1' => '.1.3.6.1.4.1.2021.10.1.5.1', - 'Load-5' => '.1.3.6.1.4.1.2021.10.1.5.2', - 'Load-15' => '.1.3.6.1.4.1.2021.10.1.5.3', - 'memTotalSwap' => '.1.3.6.1.4.1.2021.4.3.0', - 'memAvailSwap' => '.1.3.6.1.4.1.2021.4.4.0', - 'memTotalReal' => '.1.3.6.1.4.1.2021.4.5.0', - 'memAvailReal' => '.1.3.6.1.4.1.2021.4.6.0', - 'memTotalFree' => '.1.3.6.1.4.1.2021.4.11.0', - //'memShared' => '.1.3.6.1.4.1.2021.4.13', - 'memCached' => '.1.3.6.1.4.1.2021.4.15.0', - 'memBuffer' => '.1.3.6.1.4.1.2021.4.14.0', - 'ssSwapIn' => '.1.3.6.1.4.1.2021.11.3.0', - 'ssSwapOut' => '.1.3.6.1.4.1.2021.11.4.0', - 'ssIORawSent' => '.1.3.6.1.4.1.2021.11.57.0', - 'ssIORawReceived' => '.1.3.6.1.4.1.2021.11.58.0', - 'ssRawInterrupts' => '.1.3.6.1.4.1.2021.11.59.0', - 'ssRawContexts' => '.1.3.6.1.4.1.2021.11.60.0', - 'ssCpuRawUser' => '.1.3.6.1.4.1.2021.11.50.0', - 'ssCpuRawSystem' => '.1.3.6.1.4.1.2021.11.52.0', - 'ssCpuRawIdle' => '.1.3.6.1.4.1.2021.11.53.0' - ); + 'Load-1' => '.1.3.6.1.4.1.2021.10.1.5.1', + 'Load-5' => '.1.3.6.1.4.1.2021.10.1.5.2', + 'Load-15' => '.1.3.6.1.4.1.2021.10.1.5.3', + 'memTotalSwap' => '.1.3.6.1.4.1.2021.4.3.0', + 'memAvailSwap' => '.1.3.6.1.4.1.2021.4.4.0', + 'memTotalReal' => '.1.3.6.1.4.1.2021.4.5.0', + 'memAvailReal' => '.1.3.6.1.4.1.2021.4.6.0', + 'memTotalFree' => '.1.3.6.1.4.1.2021.4.11.0', + //'memShared' => '.1.3.6.1.4.1.2021.4.13', + 'memCached' => '.1.3.6.1.4.1.2021.4.15.0', + 'memBuffer' => '.1.3.6.1.4.1.2021.4.14.0', + 'ssSwapIn' => '.1.3.6.1.4.1.2021.11.3.0', + 'ssSwapOut' => '.1.3.6.1.4.1.2021.11.4.0', + 'ssIORawSent' => '.1.3.6.1.4.1.2021.11.57.0', + 'ssIORawReceived' => '.1.3.6.1.4.1.2021.11.58.0', + 'ssRawInterrupts' => '.1.3.6.1.4.1.2021.11.59.0', + 'ssRawContexts' => '.1.3.6.1.4.1.2021.11.60.0', + 'ssCpuRawUser' => '.1.3.6.1.4.1.2021.11.50.0', + 'ssCpuRawSystem' => '.1.3.6.1.4.1.2021.11.52.0', + 'ssCpuRawIdle' => '.1.3.6.1.4.1.2021.11.53.0' + ); // Using plugin -if(!empty($plugin)) { +if (!empty($plugin)) { $static_snmp_descriptions['avgCpuLoad'] = 'Average of CPUs Load (%)'; $static_snmp_descriptions['memoryUse'] = 'Memory use (%)'; } $fail = false; +$devices = array(); +$processes = array(); +$disks = array(); +$temperatures = array(); + +$arrow = false; + +$other_snmp_data = array(); + if ($snmpwalk) { // OID Used is for DISKS $snmpis = get_snmpwalk($ip_target, $snmp_version, $snmp_community, $snmp3_auth_user, @@ -120,7 +129,6 @@ if ($snmpwalk) { $snmpis = array(); } else { - $disks = array(); // We get here only the interface part of the MIB, not full mib foreach($snmpis as $key => $snmp) { @@ -136,14 +144,14 @@ if ($snmpwalk) { if (array_key_exists(1,$data)) { $disks[$data[1]] = $data[1]; - + } else { $disks[$data[0]] = $data[0]; - - } + + } } - + // OID Used is for PROCESSES $snmpis = get_snmpwalk($ip_target, $snmp_version, $snmp_community, $snmp3_auth_user, $snmp3_security_level, $snmp3_auth_method, $snmp3_auth_pass, @@ -152,8 +160,8 @@ if ($snmpwalk) { if ($snmpis === false) { $snmpis = array(); } - - $processes = array(); + + // We get here only the interface part of the MIB, not full mib foreach($snmpis as $key => $snmp) { @@ -168,12 +176,12 @@ if ($snmpwalk) { if (array_key_exists(1,$data)) { $process_name = str_replace ( "\"" , "" , $data[1]); - + } else { $process_name = str_replace ( "\"" , "" , $data[0]); - - } + + } $processes[$process_name] = $process_name; } @@ -191,7 +199,7 @@ if ($snmpwalk) { $snmpis = array(); } - $temperatures = array(); + // We get here only the interface part of the MIB, not full mib foreach($snmpis as $key => $snmp) { @@ -208,11 +216,11 @@ if ($snmpwalk) { if ($keydata2[0] == 'lmTempSensorsDevice') { if (array_key_exists(1,$data)) { $temperatures[$keydata2[1]] = $data[1]; - + } else { $temperatures[$keydata2[1]] = $data[0]; - + } } } @@ -229,7 +237,7 @@ if ($snmpwalk) { $snmpis = array(); } - $devices = array(); + // We get here only the interface part of the MIB, not full mib foreach($snmpis as $key => $snmp) { @@ -262,8 +270,15 @@ if ($snmpwalk) { // Other SNMP Data $arrow = true; - foreach ($static_snmp_oids as $key=>$oid) { - $result = snmpget($ip_target, $snmp_community, $oid); + + foreach ($static_snmp_oids as $key => $oid) { + if ($snmp_version == 3) { + $result = false; //It is statics oids. + } + else { + $result = snmpget($ip_target, $snmp_community, $oid); + } + if ($result != false) { $other_snmp_data[$key] = $static_snmp_descriptions[$key]; } @@ -341,33 +356,33 @@ if ($create_modules) { // DEVICES $devices_prefix_oids = array( - 'diskIONRead' => '.1.3.6.1.4.1.2021.13.15.1.1.3.', - 'diskIONWritten' => '.1.3.6.1.4.1.2021.13.15.1.1.4.', - 'diskIONReads' => '.1.3.6.1.4.1.2021.13.15.1.1.5.', - 'diskIONWrites' => '.1.3.6.1.4.1.2021.13.15.1.1.6.' - ); - + 'diskIONRead' => '.1.3.6.1.4.1.2021.13.15.1.1.3.', + 'diskIONWritten' => '.1.3.6.1.4.1.2021.13.15.1.1.4.', + 'diskIONReads' => '.1.3.6.1.4.1.2021.13.15.1.1.5.', + 'diskIONWrites' => '.1.3.6.1.4.1.2021.13.15.1.1.6.' + ); + $devices_prefix_descriptions = array( - 'diskIONRead' => 'The number of bytes read from this device since boot', - 'diskIONWritten' => 'The number of bytes written to this device since boot', - 'diskIONReads' => 'The number of read accesses from this device since boot', - 'diskIONWrites' => 'The number of write accesses from this device since boot' - ); - + 'diskIONRead' => 'The number of bytes read from this device since boot', + 'diskIONWritten' => 'The number of bytes written to this device since boot', + 'diskIONReads' => 'The number of read accesses from this device since boot', + 'diskIONWrites' => 'The number of write accesses from this device since boot' + ); + $results = array(); foreach ($devices as $device) { $module_values = $common_values; - + // Split module data to get type, name, etc $device_exploded = explode($separator, $device); $device_name = $device_exploded[0]; $name_exploded = explode('-', $device_name); $name = ltrim(html_entity_decode($name_exploded[1])); - + $device_type = $device_exploded[1]; - + // Delete type from device id unset($device_exploded[0]); unset($device_exploded[1]); @@ -376,10 +391,11 @@ if ($create_modules) { $device_id = implode($separator, $device_exploded); $module_values['descripcion'] = $devices_prefix_descriptions[$device_type]; - + if (($name == 'Bytes read') || ($name == 'Bytes written')) { $module_values['id_tipo_modulo'] = modules_get_type_id('remote_snmp_inc'); - } else { + } + else { $module_values['id_tipo_modulo'] = modules_get_type_id('remote_snmp'); } @@ -398,7 +414,7 @@ if ($create_modules) { foreach ($temperatures as $temperature) { $module_values = $common_values; - + // Split module data to get type, name, etc $temperature_exploded = explode($separator, $temperature); $temperature_name = $temperature_exploded[0]; @@ -434,14 +450,14 @@ if ($create_modules) { $module_values['descripcion'] = $static_snmp_descriptions[$snmpdata_name]; $module_values['id_tipo_modulo'] = modules_get_type_id('remote_snmp'); - + //Average use of CPUs is a plugin module switch ($snmpdata_name) { case 'avgCpuLoad': case 'memoryUse': $module_values['id_modulo'] = MODULE_PLUGIN; $module_values['id_plugin'] = $plugin['id']; - + $macros = json_decode($plugin['macros'], true); foreach($macros as $k => $macro) { @@ -497,7 +513,7 @@ if ($create_modules) { $macros = json_decode($plugin['macros'], true); - foreach($macros as $k => $macro) { + foreach ($macros as $k => $macro) { switch($macro['macro']) { case '_field1_': // Field 1 is the IP Address @@ -519,7 +535,7 @@ if ($create_modules) { unset($module_values['snmp_community']); //snmp_community unset($module_values['ip_target']); //ip_target unset($module_values['tcp_send']); //snmp_version - + $result = modules_create_agent_module ($id_agent, io_safe_input($process), $module_values); $results[$result][] = $process; @@ -537,7 +553,7 @@ if ($create_modules) { $macros = json_decode($plugin['macros'], true); - foreach($macros as $k => $macro) { + foreach ($macros as $k => $macro) { switch($macro['macro']) { case '_field1_': // Field 1 is the IP Address @@ -559,34 +575,41 @@ if ($create_modules) { unset($module_values['snmp_community']); //snmp_community unset($module_values['ip_target']); //ip_target unset($module_values['tcp_send']); //snmp_version - + $result = modules_create_agent_module ($id_agent, io_safe_input($disk), $module_values); $results[$result][] = $disk; } - + $success_message = ''; $error_message = ''; - - if (count($results[NOERR]) > 0) { - $success_message .= sprintf(__('%s modules created succesfully'), count($results[NOERR])) . '
'; + + if (isset($results[NOERR])) { + if (count($results[NOERR]) > 0) { + $success_message .= sprintf(__('%s modules created succesfully'), count($results[NOERR])) . '
'; + } } - if (count($results[ERR_GENERIC]) > 0) { - $error_message .= sprintf(__('Error creating %s modules') . ':
  * ' . implode('
  * ', $results[ERR_GENERIC]), count($results[ERR_GENERIC])) . '
'; + if (isset($results[ERR_GENERIC])) { + if (count($results[ERR_GENERIC]) > 0) { + $error_message .= sprintf(__('Error creating %s modules') . ':
  * ' . implode('
  * ', $results[ERR_GENERIC]), count($results[ERR_GENERIC])) . '
'; + } } - if (count($results[ERR_EXIST]) > 0) { - $error_message .= sprintf(__('%s modules already exist') . ':
  * ' . implode('
  * ', $results[ERR_EXIST]), count($results[ERR_EXIST])) . '
'; + if (isset($results[ERR_EXIST])) { + if (count($results[ERR_EXIST]) > 0) { + $error_message .= sprintf(__('%s modules already exist') . ':
  * ' . implode('
  * ', $results[ERR_EXIST]), count($results[ERR_EXIST])) . '
'; + } } if (!empty($error_message)) { ui_print_error_message($error_message); - } else { + } + else { if (empty($success_message)) { $success_message .= sprintf(__('Modules created succesfully')) . '
'; } ui_print_success_message($success_message); } - } + } } echo ''; @@ -697,17 +720,17 @@ if (!$fail) { $table->data[1][0] .= html_print_select ($modes, 'snmp_wizard_modes', '', '', '', '', true, false, false); $table->cellstyle[1][0] = 'vertical-align: middle;'; - + $table->colspan[1][0] = 2; $table->data[1][2] = ''.__('Modules').''; $table->cellstyle[1][2] = 'vertical-align: middle;'; - + // Devices list - $table->data[2][0] .= '
'; + $table->data[2][0] = '
'; $table->data[2][0] .= html_print_select ($devices, 'devices', '', '', '', '', true, true, true, '', false, 'width: 300px;'); $table->data[2][0] .= '
'; - + // If SNMP remote plugin is not installed, show an advice if(empty($plugin)) { // Processes list @@ -747,7 +770,7 @@ if (!$fail) { $table->data[2][0] .= '
'; $table->cellstyle[2][0] = 'vertical-align: top; text-align: center;'; - + // Devices arrow $table->data[2][1] = '
' . html_print_image('images/darrowright.png', true, array('title' => __('Add to modules list'))) . '
'; // Processes arrow @@ -761,15 +784,15 @@ if (!$fail) { $table->data[2][1] .= '
' . html_print_image('images/darrowright.png', true, array('title' => __('Add to modules list'))) . '
'; } $table->data[2][1] .= '

' . html_print_image('images/cross.png', true, array('title' => __('Remove from modules list'))) . '
'; - $table->cellstyle[2][1] .= 'vertical-align: middle; text-align: center;'; - + $table->cellstyle[2][1] = 'vertical-align: middle; text-align: center;'; + $table->data[2][2] = html_print_select (array (), 'module[]', 0, false, '', 0, true, true, true, '', false, 'width:300px; height: 100%;'); $table->data[2][2] .= html_print_input_hidden('agent', $id_agent, true); $table->cellstyle[2][2] = 'vertical-align: top; text-align: center;'; - + html_print_table($table); - echo "
"; + echo "
"; html_print_submit_button(__('Create modules'), 'create_modules_btn', false, array('class' => 'sub add')); echo "
"; unset($table); @@ -778,7 +801,7 @@ if (!$fail) { echo ""; echo '
'; } - + ui_require_jquery_file ('pandora.controls'); ui_require_jquery_file ('ajaxqueue'); ui_require_jquery_file ('bgiframe'); diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index d8c1cbae3d..e70b6ff52d 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -1430,9 +1430,11 @@ function array_key_to_offset($array, $key) { * * @return array SNMP result. */ -function get_snmpwalk($ip_target, $snmp_version, $snmp_community = '', $snmp3_auth_user = '', - $snmp3_security_level = '', $snmp3_auth_method = '', $snmp3_auth_pass = '', - $snmp3_privacy_method = '', $snmp3_privacy_pass = '', $quick_print = 0, $base_oid = "", $snmp_port = '') { +function get_snmpwalk($ip_target, $snmp_version, $snmp_community = '', + $snmp3_auth_user = '', $snmp3_security_level = '', + $snmp3_auth_method = '', $snmp3_auth_pass = '', + $snmp3_privacy_method = '', $snmp3_privacy_pass = '', + $quick_print = 0, $base_oid = "", $snmp_port = '') { global $config; @@ -1464,7 +1466,7 @@ function get_snmpwalk($ip_target, $snmp_version, $snmp_community = '', $snmp3_au else { $snmpwalk_bin = $config['snmpwalk']; } - + switch (PHP_OS) { case "WIN32": case "WINNT": @@ -1480,16 +1482,54 @@ function get_snmpwalk($ip_target, $snmp_version, $snmp_community = '', $snmp3_au $rc = 0; switch ($snmp_version) { case '3': - exec ($snmpwalk_bin . ' -m ALL -v 3 -u ' . escapeshellarg($snmp3_auth_user) . ' -A ' . escapeshellarg($snmp3_auth_pass) . ' -l ' . escapeshellarg($snmp3_security_level) . ' -a ' . escapeshellarg($snmp3_auth_method) . ' -x ' . escapeshellarg($snmp3_privacy_method) . ' -X ' . escapeshellarg($snmp3_privacy_pass) . ' ' . escapeshellarg($ip_target) . ' ' . $base_oid . ' 2> ' . $error_redir_dir, $output, $rc); + switch ($snmp3_security_level) { + case "authNoPriv": + $command_str = $snmpwalk_bin . + ' -m ALL -v 3' . + ' -u ' . escapeshellarg($snmp3_auth_user) . + ' -A ' . escapeshellarg($snmp3_auth_pass) . + ' -l ' . escapeshellarg($snmp3_security_level) . + ' -a ' . escapeshellarg($snmp3_auth_method) . + ' ' . escapeshellarg($ip_target) . + ' ' . $base_oid . + ' 2> ' . $error_redir_dir; + break; + case "noAuthNoPriv": + $command_str = $snmpwalk_bin . + ' -m ALL -v 3' . + ' -u ' . escapeshellarg($snmp3_auth_user) . + ' -l ' . escapeshellarg($snmp3_security_level) . + ' ' . escapeshellarg($ip_target) . + ' ' . $base_oid . + ' 2> ' . $error_redir_dir; + break; + default: + $command_str = $snmpwalk_bin . + ' -m ALL -v 3' . + ' -u ' . escapeshellarg($snmp3_auth_user) . + ' -A ' . escapeshellarg($snmp3_auth_pass) . + ' -l ' . escapeshellarg($snmp3_security_level) . + ' -a ' . escapeshellarg($snmp3_auth_method) . + ' -x ' . escapeshellarg($snmp3_privacy_method) . + ' -X ' . escapeshellarg($snmp3_privacy_pass) . + ' ' . escapeshellarg($ip_target) . + ' ' . $base_oid . + ' 2> ' . $error_redir_dir; + break; + } break; case '2': case '2c': case '1': default: - exec ($snmpwalk_bin . ' -m ALL -v ' . escapeshellarg($snmp_version) . ' -c ' . escapeshellarg($snmp_community) . ' ' . escapeshellarg($ip_target) . ' ' . $base_oid . ' 2> ' . $error_redir_dir, $output, $rc); + $command_str = $snmpwalk_bin . ' -m ALL -v ' . escapeshellarg($snmp_version) . ' -c ' . escapeshellarg($snmp_community) . ' ' . escapeshellarg($ip_target) . ' ' . $base_oid . ' 2> ' . $error_redir_dir; break; } + //html_debug_print($command_str); + + exec($command_str, $output, $rc); + // Parse the output of snmpwalk $snmpwalk = array(); foreach ($output as $line) {