diff --git a/pandora_console/godmode/agentes/agent_wizard.snmp_explorer.php b/pandora_console/godmode/agentes/agent_wizard.snmp_explorer.php index 5403d9aeb9..a51d8eacb2 100644 --- a/pandora_console/godmode/agentes/agent_wizard.snmp_explorer.php +++ b/pandora_console/godmode/agentes/agent_wizard.snmp_explorer.php @@ -20,10 +20,11 @@ require_once ('include/functions_modules.php'); require_once ('include/functions_alerts.php'); require_once ('include/functions_reporting.php'); require_once ('include/graphs/functions_utils.php'); +require_once("include/functions_snmp.php"); // Define a separator to implode/explode data $separator = '_.._'; - + $idAgent = (int) get_parameter('id_agente', 0); $ipAgent = db_get_value('direccion', 'tagente', 'id_agente', $idAgent); @@ -63,56 +64,6 @@ 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', - 'sysUpTime' => 'system Up 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', - 'sysUpTime' => '1.3.6.1.2.1.1.3.0'); - -$static_snmp_post_process = array( - 'sysUpTime' => "0.00000011574074"); - // Using plugin if (!empty($plugin)) { $static_snmp_descriptions['avgCpuLoad'] = 'Average of CPUs Load (%)'; @@ -128,6 +79,7 @@ $temperatures = array(); $arrow = false; +$snmp_translation_data = index_array(snmp_get_translation_wizard(), null, 'description'); $other_snmp_data = array(); if ($snmpwalk) { @@ -283,16 +235,16 @@ if ($snmpwalk) { // Other SNMP Data $arrow = true; - foreach ($static_snmp_oids as $key => $oid) { + foreach ($snmp_translation_data as $oid => $temp) { if ($snmp_version == 3) { $result = false; //It is statics oids. } else { - $result = snmpget($ip_target, $snmp_community, $oid); + $result = @snmpget($ip_target, $snmp_community, $oid); } if ($result != false) { - $other_snmp_data[$key] = $static_snmp_descriptions[$key]; + $other_snmp_data[$oid] = $snmp_translation_data[$oid]; } } if (empty($other_snmp_data)) { @@ -375,10 +327,14 @@ if ($create_modules) { ); $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(); @@ -457,18 +413,17 @@ if ($create_modules) { // SNMP DATA (STATIC MODULES) - foreach ($snmpdata as $snmpdata_name) { + foreach ($snmpdata as $snmpdata_oid) { $module_values = $common_values; + $snmp_translation = snmp_get_translation($snmpdata_oid); - $module_values['descripcion'] = $static_snmp_descriptions[$snmpdata_name]; + $module_values['descripcion'] = + $snmp_translation['description']; $module_values['id_tipo_modulo'] = modules_get_type_id('remote_snmp'); - if (isset($static_snmp_post_process[$snmpdata_name])) { - $module_values['post_process'] = - $static_snmp_post_process[$snmpdata_name]; - } + $module_values['post_process'] = $snmp_translation['post_process']; //Average use of CPUs is a plugin module - switch ($snmpdata_name) { + switch ($snmpdata_oid) { case 'avgCpuLoad': case 'memoryUse': $module_values['id_modulo'] = MODULE_PLUGIN; @@ -538,15 +493,16 @@ if ($create_modules) { unset($module_values['tcp_send']); //snmp_version break; default: - $module_values['snmp_oid'] = $static_snmp_oids[$snmpdata_name]; + $module_values['snmp_oid'] = $snmpdata_oid; $module_values['id_modulo'] = MODULE_SNMP; break; } - $result = modules_create_agent_module ($id_agent, io_safe_input($snmpdata_name), $module_values); + $result = modules_create_agent_module( + $id_agent, io_safe_input($snmp_translation['description']), $module_values); - $results[$result][] = $snmpdata_name; + $results[$result][] = $snmp_translation['description']; } // PROCESSES @@ -924,7 +880,7 @@ ui_require_javascript_file ('pandora_modules'); var separator = ''; -$(document).ready (function () { +$(document).ready (function () { $("#walk_form").submit(function() { $("#oid_loading").show (); }); @@ -951,11 +907,11 @@ $(document).ready (function () { $("#snmp_wizard_modes").trigger('change'); - $('#form_interfaces').hide(); + $('#form_interfaces').hide(); $('.wizard_mode_devices_arrow').click(function() { @@ -1045,7 +1001,7 @@ $(document).ready (function () { $(value).remove(); } }); - + if($("#module option").length == 0) { $("select[name='module[]']").append($("").val(0).html()); } diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index 2287852d37..bb66431627 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -306,10 +306,16 @@ if (check_acl ($config['id_user'], 0, "PM")) { } $sub["extras/pandora_diag"]["text"] = __('Diagnostic info'); $sub["extras/pandora_diag"]["id"] = 'Diagnostic info'; + $sub["godmode/setup/news"]["text"] = __('Site news'); $sub["godmode/setup/news"]["id"] = 'Site news'; + $sub["godmode/setup/file_manager"]["text"] = __('File manager'); $sub["godmode/setup/file_manager"]["id"] = 'File manager'; + + $sub["godmode/setup/snmp_wizard"]["text"] = __('SNMP Wizard'); + $sub["godmode/setup/snmp_wizard"]["id"] = 'SNMP Wizard'; + $menu_godmode["gextensions"]["sub"] = $sub; } diff --git a/pandora_console/godmode/setup/setup_general.php b/pandora_console/godmode/setup/setup_general.php index 0e4b0c72d4..ee5f2b4cf1 100644 --- a/pandora_console/godmode/setup/setup_general.php +++ b/pandora_console/godmode/setup/setup_general.php @@ -288,7 +288,6 @@ echo "" . __('General options') . ""; echo ""; - //enterprise_hook ('setup'); echo '
'; html_print_submit_button (__('Update'), 'update_button', false, 'class="sub upd"'); echo '
'; diff --git a/pandora_console/godmode/setup/snmp_wizard.php b/pandora_console/godmode/setup/snmp_wizard.php new file mode 100644 index 0000000000..2fec395f86 --- /dev/null +++ b/pandora_console/godmode/setup/snmp_wizard.php @@ -0,0 +1,305 @@ +id = 'snmp'; +$table->width = '100%'; +$table->class = 'databox data'; +$table->cellpadding = 0; +$table->cellspacing = 0; + +$table->head = array (); +$table->head["description"] = __('Description'); +$table->head["oid"] = __('OID'); +$table->head["post_process"] = __('Post process'); +$table->head["op"] = __('OP'); + +$table->headstyle = array (); +$table->headstyle["description"] = "text-align: left;"; +$table->headstyle["oid"] = "text-align: left;"; +$table->headstyle["post_process"] = "text-align: right;"; +$table->headstyle["op"] = "text-align: center;"; + +$table->align = array (); +$table->align["description"] = 'left'; +$table->align["oid"] = 'left'; +$table->align["post_process"] = 'right'; +$table->align["op"] = 'center'; + + +$table->size = array(); +$table->size["description"] = '40%'; +$table->size["oid"] = '25%'; +$table->size["post_process"] = '25%'; +$table->size["op"] = '10%'; + +$oid_translations = snmp_get_translation_wizard(); + +$table->data = array (); + +foreach ($oid_translations as $oid => $data) { + $row = array(); + + $row['oid'] = $oid; + $row['description'] = $data['description']; + $row['post_process'] = $data['post_process']; + + if ($data['readonly']) { + $row['op'] = ''; + } + else { + $row['op'] = cell_op($oid); + } + + + $table->data[$oid] = $row; +} + + +$table->data['template'] = array( + 'oid' => '', + 'description' => '', + 'post_process' => '', + 'op' => cell_op() + ); +$table->rowstyle['template'] = 'display: none;'; + +// Form editor +$table->data['editor'] = array( + 'oid' => html_print_input_text('oid_editor', '', '', 40, 255, true), + 'description' => + html_print_input_text('description_editor', '', '', 40, 255, true), + 'post_process' => + html_print_input_text('post_process_editor', '', '', 20, 255, true), + 'op' => '' . + '' . + html_print_image("images/save_mc.png", true, array ("title" => __('Save'))) .'' . + '' . + ''); + + + +html_print_table($table); + +function cell_op($oid = "") { + return '' . + '' . + html_print_image("images/cog.png", true, array ("title" => __('Edit'))) . + '' . + '' . + html_print_image("images/cross.png", true, array ("title" => __('Delete'))) . + ''; +} +?> + + \ No newline at end of file diff --git a/pandora_console/include/ajax/snmp.ajax.php b/pandora_console/include/ajax/snmp.ajax.php new file mode 100644 index 0000000000..7b3e45c704 --- /dev/null +++ b/pandora_console/include/ajax/snmp.ajax.php @@ -0,0 +1,59 @@ + $result)); + + return; +} + +if ($delete_snmp_translation) { + $oid = get_parameter('oid', ''); + + $result = snmp_delete_translation($oid); + + echo json_encode(array('correct' => $result)); + + return; +} + +if ($update_snmp_translation) { + $oid = get_parameter('oid', ''); + $new_oid = get_parameter('new_oid', ''); + $description = get_parameter('description', ''); + $post_process = get_parameter('post_process', ''); + + $result = snmp_update_translation($oid, $new_oid, $description, $post_process); + + echo json_encode(array('correct' => $result)); + + return; +} +?> diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index ae711e3fa2..042cbb14d8 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -1371,9 +1371,11 @@ function index_array ($array, $index = 'id', $value = 'name') { if (! is_array ($array)) return $retval; - foreach ($array as $element) { - if (! isset ($element[$index])) - continue; + foreach ($array as $index_array => $element) { + if (!is_null($index)) { + if (! isset ($element[$index])) + continue; + } if ($value === false) { $retval[$element[$index]] = $element; continue; @@ -1381,7 +1383,13 @@ function index_array ($array, $index = 'id', $value = 'name') { if (! isset ($element[$value])) continue; - $retval[$element[$index]] = $element[$value]; + + if (is_null($index)) { + $retval[$index_array] = $element[$value]; + } + else { + $retval[$element[$index]] = $element[$value]; + } } return $retval; diff --git a/pandora_console/include/functions_snmp.php b/pandora_console/include/functions_snmp.php index dc9141e7e9..31b6beb8bf 100644 --- a/pandora_console/include/functions_snmp.php +++ b/pandora_console/include/functions_snmp.php @@ -42,9 +42,13 @@ function snmp_generate_trap($snmp_host_address, $snmp_community, $snmp_oid, $snm else { $snmpwalk_bin = $config['snmptrap']; } - - $command = "snmptrap -v 1 -c " . escapeshellarg($snmp_community) . " " . escapeshellarg($snmp_host_address) . " " . escapeshellarg($snmp_oid) . " " - . escapeshellarg($snmp_agent) . " " . escapeshellarg($snmp_type) . " " . escapeshellarg($snmp_data) . " 0 2>&1"; + + $command = "snmptrap -v 1 -c " . escapeshellarg($snmp_community) . + " " . escapeshellarg($snmp_host_address) . + " " . escapeshellarg($snmp_oid) . + " " . escapeshellarg($snmp_agent) . + " " . escapeshellarg($snmp_type) . + " " . escapeshellarg($snmp_data) . " 0 2>&1"; $output = null; exec($command, $output, $return); @@ -57,4 +61,222 @@ function snmp_generate_trap($snmp_host_address, $snmp_community, $snmp_oid, $snm } } -?> +function snmp_get_default_translations() { + $return = array(); + $return['.1.3.6.1.4.1.2021.10.1.5.1'] = array( + 'description' => __('Load Average (Last minute)'), + 'post_process' => '1' + ); + $return['.1.3.6.1.4.1.2021.10.1.5.2'] = array( + 'description' => __('Load Average (Last 5 minutes)'), + 'post_process' => '1' + ); + $return['.1.3.6.1.4.1.2021.10.1.5.3'] = array( + 'description' => __('Load Average (Last 15 minutes)'), + 'post_process' => '1' + ); + $return['.1.3.6.1.4.1.2021.4.3.0'] = array( + 'description' => __('Total Swap Size configured for the host'), + 'post_process' => '1' + ); + $return['.1.3.6.1.4.1.2021.4.4.0'] = array( + 'description' => __('Available Swap Space on the host'), + 'post_process' => '1' + ); + $return['.1.3.6.1.4.1.2021.4.5.0'] = array( + 'description' => __('Total Real/Physical Memory Size on the host'), + 'post_process' => '1' + ); + $return['.1.3.6.1.4.1.2021.4.6.0'] = array( + 'description' => __('Available Real/Physical Memory Space on the host'), + 'post_process' => '1' + ); + $return['.1.3.6.1.4.1.2021.4.11.0'] = array( + 'description' => __('Total Available Memory on the host'), + 'post_process' => '1' + ); + $return['.1.3.6.1.4.1.2021.4.15.0'] = array( + 'description' => __('Total Cached Memory'), + 'post_process' => '1' + ); + $return['.1.3.6.1.4.1.2021.4.14.0'] = array( + 'description' => __('Total Buffered Memory'), + 'post_process' => '1' + ); + $return['.1.3.6.1.4.1.2021.11.3.0'] = array( + 'description' => __('Amount of memory swapped in from disk (kB/s)'), + 'post_process' => '1' + ); + $return['.1.3.6.1.4.1.2021.11.4.0'] = array( + 'description' => __('Amount of memory swapped to disk (kB/s)'), + 'post_process' => '1' + ); + $return['.1.3.6.1.4.1.2021.11.57.0'] = array( + 'description' => __('Number of blocks sent to a block device'), + 'post_process' => '1' + ); + $return['.1.3.6.1.4.1.2021.11.58.0'] = array( + 'description' => __('Number of blocks received from a block device'), + 'post_process' => '1' + ); + $return['.1.3.6.1.4.1.2021.11.59.0'] = array( + 'description' => __('Number of interrupts processed'), + 'post_process' => '1' + ); + $return['.1.3.6.1.4.1.2021.11.60.0'] = array( + 'description' => __('Number of context switches'), + 'post_process' => '1' + ); + $return['.1.3.6.1.4.1.2021.11.50.0'] = array( + 'description' => __('user CPU time'), + 'post_process' => '1' + ); + $return['.1.3.6.1.4.1.2021.11.52.0'] = array( + 'description' => __('system CPU time'), + 'post_process' => '1' + ); + $return['.1.3.6.1.4.1.2021.11.53.0'] = array( + 'description' => __('idle CPU time'), + 'post_process' => '1' + ); + $return['1.3.6.1.2.1.1.3.0'] = array( + 'description' => __('system Up time'), + 'post_process' => '0.00000011574074' + ); + + return $return; +} + +function snmp_get_user_translations() { + $row = db_get_row('tconfig', 'token', 'snmp_translations'); + + if (empty($row)) { + db_process_sql_insert('tconfig', + array('token' => 'snmp_translations', + 'value' => json_encode(array()))); + + $return = array(); + } + else { + $return = json_decode($row['value'], true); + } + + return $return; +} + +function snmp_get_translation_wizard() { + $return = array(); + + $snmp_default_translations = snmp_get_default_translations(); + $snmp_user_translations = snmp_get_user_translations(); + + foreach ($snmp_default_translations as $oid => $translation) { + $return[$oid] = array_merge($translation, array('readonly' => 1)); + } + + foreach ($snmp_user_translations as $oid => $translation) { + $return[$oid] = array_merge($translation, array('readonly' => 0)); + } + + return $return; +} + +function snmp_save_translation($oid, $description, $post_process) { + $row = db_get_row('tconfig', 'token', 'snmp_translations'); + + if (empty($row)) { + db_process_sql_insert('tconfig', + array('token' => 'snmp_translations', + 'value' => json_encode(array()))); + + $snmp_translations = array(); + } + else { + $snmp_translations = json_decode($row['value'], true); + } + + if (isset($snmp_translations[$oid])) { + // exists the oid + return false; + } + else { + $snmp_translations[$oid] = array( + 'description' => $description, + 'post_process' => $post_process + ); + + return (bool)db_process_sql_update('tconfig', + array('value' => json_encode($snmp_translations)), + array('token' => 'snmp_translations')); + } +} + +function snmp_delete_translation($oid) { + $row = db_get_row('tconfig', 'token', 'snmp_translations'); + + if (empty($row)) { + db_process_sql_insert('tconfig', + array('token' => 'snmp_translations', + 'value' => json_encode(array()))); + + $snmp_translations = array(); + } + else { + $snmp_translations = json_decode($row['value'], true); + } + + if (isset($snmp_translations[$oid])) { + unset($snmp_translations[$oid]); + + return (bool)db_process_sql_update('tconfig', + array('value' => json_encode($snmp_translations)), + array('token' => 'snmp_translations')); + } + else { + // exists the oid + return false; + } +} + +function snmp_get_translation($oid) { + $snmp_translations = snmp_get_translation_wizard(); + + return $snmp_translations[$oid]; +} + +function snmp_update_translation($oid, $new_oid, $description, $post_process) { + $row = db_get_row('tconfig', 'token', 'snmp_translations'); + + if (empty($row)) { + db_process_sql_insert('tconfig', + array('token' => 'snmp_translations', + 'value' => json_encode(array()))); + + $snmp_translations = array(); + } + else { + $snmp_translations = json_decode($row['value'], true); + } + + if (isset($snmp_translations[$new_oid])) { + return false; + } + else { + if (isset($snmp_translations[$oid])) { + unset($snmp_translations[$oid]); + + $snmp_translations[$new_oid] = array( + 'description' => $description, + 'post_process' => $post_process + ); + + return (bool)db_process_sql_update('tconfig', + array('value' => json_encode($snmp_translations)), + array('token' => 'snmp_translations')); + } + else { + return false; + } + } +} +?> \ No newline at end of file