2014-07-22 Miguel de Dios <miguel.dedios@artica.es>

* 


git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@10346 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2014-07-22 16:07:31 +00:00
parent 77c4eefe5c
commit 012ae953a0
3 changed files with 179 additions and 111 deletions

View File

@ -1,3 +1,8 @@
2014-07-22 Miguel de Dios <miguel.dedios@artica.es>
* godmode/agentes/agent_wizard.snmp_explorer.php,
include/functions.php: some fixes for the snmp v3.
2014-07-22 Miguel de Dios <miguel.dedios@artica.es>
* godmode/agentes/agent_manager.php: fixed to show the QR code image

View File

@ -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') . '.<br><br>' . __('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) {
@ -153,7 +161,7 @@ if ($snmpwalk) {
$snmpis = array();
}
$processes = array();
// We get here only the interface part of the MIB, not full mib
foreach($snmpis as $key => $snmp) {
@ -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) {
@ -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,18 +356,18 @@ 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();
@ -379,7 +394,8 @@ if ($create_modules) {
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');
}
@ -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
@ -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
@ -568,19 +584,26 @@ if ($create_modules) {
$success_message = '';
$error_message = '';
if (count($results[NOERR]) > 0) {
$success_message .= sprintf(__('%s modules created succesfully'), count($results[NOERR])) . '<br>';
if (isset($results[NOERR])) {
if (count($results[NOERR]) > 0) {
$success_message .= sprintf(__('%s modules created succesfully'), count($results[NOERR])) . '<br>';
}
}
if (count($results[ERR_GENERIC]) > 0) {
$error_message .= sprintf(__('Error creating %s modules') . ': <br>&nbsp;&nbsp;* ' . implode('<br>&nbsp;&nbsp;* ', $results[ERR_GENERIC]), count($results[ERR_GENERIC])) . '<br>';
if (isset($results[ERR_GENERIC])) {
if (count($results[ERR_GENERIC]) > 0) {
$error_message .= sprintf(__('Error creating %s modules') . ': <br>&nbsp;&nbsp;* ' . implode('<br>&nbsp;&nbsp;* ', $results[ERR_GENERIC]), count($results[ERR_GENERIC])) . '<br>';
}
}
if (count($results[ERR_EXIST]) > 0) {
$error_message .= sprintf(__('%s modules already exist') . ': <br>&nbsp;&nbsp;* ' . implode('<br>&nbsp;&nbsp;* ', $results[ERR_EXIST]), count($results[ERR_EXIST])) . '<br>';
if (isset($results[ERR_EXIST])) {
if (count($results[ERR_EXIST]) > 0) {
$error_message .= sprintf(__('%s modules already exist') . ': <br>&nbsp;&nbsp;* ' . implode('<br>&nbsp;&nbsp;* ', $results[ERR_EXIST]), count($results[ERR_EXIST])) . '<br>';
}
}
if (!empty($error_message)) {
ui_print_error_message($error_message);
} else {
}
else {
if (empty($success_message)) {
$success_message .= sprintf(__('Modules created succesfully')) . '<br>';
}
@ -703,7 +726,7 @@ if (!$fail) {
$table->cellstyle[1][2] = 'vertical-align: middle;';
// Devices list
$table->data[2][0] .= '<div class="wizard_mode_form wizard_mode_devices">';
$table->data[2][0] = '<div class="wizard_mode_form wizard_mode_devices">';
$table->data[2][0] .= html_print_select ($devices, 'devices', '', '',
'', '', true, true, true, '', false, 'width: 300px;');
$table->data[2][0] .= '</div>';
@ -761,7 +784,7 @@ if (!$fail) {
$table->data[2][1] .= '<div class="wizard_mode_form wizard_mode_snmpdata wizard_mode_snmpdata_arrow clickable">' . html_print_image('images/darrowright.png', true, array('title' => __('Add to modules list'))) . '</div>';
}
$table->data[2][1] .= '<br><br><div class="wizard_mode_delete_arrow clickable">' . html_print_image('images/cross.png', true, array('title' => __('Remove from modules list'))) . '</div>';
$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);
@ -769,7 +792,7 @@ if (!$fail) {
html_print_table($table);
echo "<div style='text-align:right; width:".$table->width."'>";
echo "<div style='text-align:right; width:" . $table->width . "'>";
html_print_submit_button(__('Create modules'), 'create_modules_btn', false, array('class' => 'sub add'));
echo "</div>";
unset($table);

View File

@ -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;
@ -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) {