From 7f4701f22e88dba28df80d28187391c92fa19085 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Wed, 17 Jul 2019 11:11:38 +0200 Subject: [PATCH] exec server error wizard --- .../godmode/agentes/agent_manager.php | 4 +- .../agent_wizard.snmp_interfaces_explorer.php | 126 ++++++++++-------- pandora_console/include/functions_modules.php | 68 +++++++--- pandora_console/include/functions_servers.php | 9 +- 4 files changed, 123 insertions(+), 84 deletions(-) diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index 2c121c87fb..b7a9c6295f 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -372,13 +372,13 @@ $table_server = '

'.__('Server') $table_server .= '

'; if ($new_agent) { // Set first server by default. - $servers_get_names = servers_get_names(); + $servers_get_names = $servers; $array_keys_servers_get_names = array_keys($servers_get_names); $server_name = reset($array_keys_servers_get_names); } $table_server .= html_print_select( - servers_get_names(), + $servers, 'server_name', $server_name, '', diff --git a/pandora_console/godmode/agentes/agent_wizard.snmp_interfaces_explorer.php b/pandora_console/godmode/agentes/agent_wizard.snmp_interfaces_explorer.php index 2dca9353ac..45d899822a 100644 --- a/pandora_console/godmode/agentes/agent_wizard.snmp_interfaces_explorer.php +++ b/pandora_console/godmode/agentes/agent_wizard.snmp_interfaces_explorer.php @@ -1,16 +1,32 @@ ] => [] array + // Build a [] => [] array. if (!empty($snmp_int_ip)) { foreach ($snmp_int_ip as $key => $value) { - // The key is something like IP-MIB::ipAddressIfIndex.ipv4."" - // or IP-MIB::ipAddressIfIndex.ipv6."" - // The value is something like INTEGER: + // The key is something like IP-MIB::ipAddressIfIndex.ipv4."". + // or IP-MIB::ipAddressIfIndex.ipv6."". + // The value is something like INTEGER: . $data = explode(': ', $value); $interface_id = !empty($data) && isset($data[1]) ? $data[1] : false; @@ -110,7 +126,7 @@ if ($snmpwalk) { $interface_ip = $matches[1]; } - // Get the first ip + // Get the first ip. if ($interface_id !== false && !empty($interface_ip) && !isset($interfaces_ip[$interface_id])) { $interfaces_ip[$interface_id] = $interface_ip; } @@ -119,17 +135,17 @@ if ($snmpwalk) { unset($snmp_int_ip); } - $snmpis = array_merge(($snmpis === false ? [] : $snmpis), ($ifxitems === false ? [] : $ifxitems)); + $snmpis = array_merge((($snmpis === false) ? [] : $snmpis), (($ifxitems === false) ? [] : $ifxitems)); $interfaces = []; - // We get here only the interface part of the MIB, not full mib + // We get here only the interface part of the MIB, not full mib. foreach ($snmpis as $key => $snmp) { $data = explode(': ', $snmp, 2); $keydata = explode('::', $key); $keydata2 = explode('.', $keydata[1]); - // Avoid results without index and interfaces without name + // Avoid results without index and interfaces without name. if (!isset($keydata2[1]) || !isset($data[1])) { continue; } @@ -239,24 +255,22 @@ if ($create_modules) { $oid_array[(count($oid_array) - 1)] = $id; $oid = implode('.', $oid_array); - // Get the name + // Get the name. $name_array = explode('::', $oid_array[0]); $name = $ifname.'_'.$name_array[1]; - // Clean the name + // Clean the name. $name = str_replace('"', '', $name); - // Proc moduletypes + // Proc moduletypes. if (preg_match('/Status/', $name_array[1])) { $module_type = 18; } else if (preg_match('/Present/', $name_array[1])) { $module_type = 18; } else if (preg_match('/PromiscuousMode/', $name_array[1])) { $module_type = 18; - } - - // String moduletypes - else if (preg_match('/Alias/', $name_array[1])) { + } else if (preg_match('/Alias/', $name_array[1])) { + // String moduletypes. $module_type = 17; } else if (preg_match('/Address/', $name_array[1])) { $module_type = 17; @@ -266,15 +280,11 @@ if ($create_modules) { $module_type = 17; } else if (preg_match('/Descr/', $name_array[1])) { $module_type = 17; - } - - // Specific counters (ends in s) - else if (preg_match('/s$/', $name_array[1])) { + } else if (preg_match('/s$/', $name_array[1])) { + // Specific counters (ends in s). $module_type = 16; - } - - // Otherwise, numeric - else { + } else { + // Otherwise, numeric. $module_type = 15; } @@ -330,7 +340,7 @@ if ($create_modules) { $output_oid = ''; - exec('ssh pandora_exec_proxy@'.$row['ip_address'].' snmptranslate -On '.$oid, $output_oid, $rc); + exec('snmptranslate -On '.$oid, $output_oid, $rc); $conf_oid = $output_oid[0]; $oid = $conf_oid; @@ -397,7 +407,9 @@ if ($create_modules) { } if ($done > 0) { - ui_print_success_message(__('Successfully modules created')." ($done)"); + ui_print_success_message( + __('Successfully modules created').' ('.$done.')' + ); } if (!empty($errors)) { @@ -407,17 +419,17 @@ if ($create_modules) { foreach ($errors as $code => $number) { switch ($code) { case ERR_EXIST: - $msg .= '
'.__('Another module already exists with the same name')." ($number)"; + $msg .= '
'.__('Another module already exists with the same name').' ('.$number.')'; break; case ERR_INCOMPLETE: - $msg .= '
'.__('Some required fields are missed').': ('.__('name').') '." ($number)"; + $msg .= '
'.__('Some required fields are missed').': ('.__('name').') ('.$number.')'; break; case ERR_DB: case ERR_GENERIC: default: - $msg .= '
'.__('Processing error')." ($number)"; + $msg .= '
'.__('Processing error').' ('.$number.')'; break; } } @@ -426,10 +438,10 @@ if ($create_modules) { } } -// Create the interface list for the interface +// Create the interface list for the interface. $interfaces_list = []; foreach ($interfaces as $interface) { - // Get the interface name, removing " " characters and avoid "blank" interfaces + // Get the interface name, removing " " characters and avoid "blank" interfaces. if (isset($interface['ifDescr']) && $interface['ifDescr']['value'] != '') { $ifname = $interface['ifDescr']['value']; } else if (isset($interface['ifName']) && $interface['ifName']['value'] != '') { @@ -442,7 +454,7 @@ foreach ($interfaces as $interface) { } echo ''; -echo "
"; +echo ""; $table->width = '100%'; $table->cellpadding = 0; @@ -464,12 +476,14 @@ if (enterprise_installed()) { enterprise_include_once('include/functions_satellite.php'); $rows = get_proxy_servers(); + + // Check if satellite server has remote configuration enabled. + $satellite_remote = config_agents_has_remote_configuration($id_agent); + foreach ($rows as $row) { if ($row['server_type'] != 13) { $s_type = ' (Standard)'; } else { - // Check if satellite server has remote configuration enabled - $satellite_remote = config_agents_has_remote_configuration($id_agent); $id_satellite = $row['id_server']; $s_type = ' (Satellite)'; } @@ -484,8 +498,7 @@ $table->data[1][4] = html_print_select( $servers_to_exec, 'server_to_exec', $server_to_exec, - 'satellite_remote_warn('.$id_satellite.','.$satellite_remote.') -', + 'satellite_remote_warn('.$id_satellite.','.$satellite_remote.')', '', '', true @@ -509,7 +522,7 @@ html_print_table($table); unset($table); -// SNMP3 OPTIONS +// SNMP3 OPTIONS. $table->width = '100%'; $table->data[2][1] = ''.__('Auth user').''; @@ -564,7 +577,7 @@ echo '
'; if (!empty($interfaces_list)) { echo ''; - echo "
"; + echo ""; echo ''; $id_snmp_serialize = serialize_in_temp($interfaces, $config['id_user'].'_snmp'); @@ -589,7 +602,7 @@ if (!empty($interfaces_list)) { $table->width = '100%'; - // Agent selector + // Agent selector. $table->data[0][0] = ''.__('Interfaces').''; $table->data[0][1] = ''; $table->data[0][2] = ''.__('Modules').''; @@ -619,12 +632,10 @@ ui_require_jquery_file('bgiframe'); /* $name, 'id_agente' => (int) $id_agent]); + $exists = (bool) db_get_value_filter( + 'id_agente_modulo', + 'tagente_modulo', + [ + 'nombre' => $name, + 'id_agente' => (int) $id_agent, + ] + ); if ($exists) { return ERR_EXIST; } - // Encrypt passwords + // Encrypt passwords. if (isset($values['plugin_pass'])) { $values['plugin_pass'] = io_input_password($values['plugin_pass']); } - // Encrypt SNMPv3 passwords - if (isset($values['id_tipo_modulo']) && ($values['id_tipo_modulo'] >= 15 && $values['id_tipo_modulo'] <= 18) + // Encrypt SNMPv3 passwords. + if (isset($values['id_tipo_modulo']) && ($values['id_tipo_modulo'] >= 15 + && $values['id_tipo_modulo'] <= 18) && isset($values['tcp_send']) && ($values['tcp_send'] == 3) && isset($values['custom_string_2']) ) { - $values['custom_string_2'] = io_input_password($values['custom_string_2']); + $values['custom_string_2'] = io_input_password( + $values['custom_string_2'] + ); } $id_agent_module = db_process_sql_insert('tagente_modulo', $values); @@ -645,25 +657,33 @@ function modules_create_agent_module( } if (isset($values['id_tipo_modulo']) - && ($values['id_tipo_modulo'] == 21 || $values['id_tipo_modulo'] == 22 || $values['id_tipo_modulo'] == 23) + && ($values['id_tipo_modulo'] == 21 + || $values['id_tipo_modulo'] == 22 + || $values['id_tipo_modulo'] == 23) ) { - // Async modules start in normal status + // Async modules start in normal status. $status = AGENT_MODULE_STATUS_NORMAL; } else { - // Sync modules start in unknown status + // Sync modules start in unknown status. $status = AGENT_MODULE_STATUS_NO_DATA; } + // Condition for cron modules. Don't touch. + $time = 0; + if (empty($values['interval']) === false) { + $time = (time() - (int) $values['interval']); + } + $result = db_process_sql_insert( 'tagente_estado', [ 'id_agente_modulo' => $id_agent_module, - 'datos' => 0, + 'datos' => '', 'timestamp' => '01-01-1970 00:00:00', 'estado' => $status, 'known_status' => $status, 'id_agente' => (int) $id_agent, - 'utimestamp' => (time() - (int) $values['interval']), + 'utimestamp' => $time, 'status_changes' => 0, 'last_status' => $status, 'last_known_status' => $status, @@ -680,12 +700,20 @@ function modules_create_agent_module( return ERR_DB; } - // Update module status count if the module is not created disabled + // Update module status count if the module is not created disabled. if (!isset($values['disabled']) || $values['disabled'] == 0) { if ($status == 0) { - db_process_sql('UPDATE tagente SET total_count=total_count+1, normal_count=normal_count+1 WHERE id_agente='.(int) $id_agent); + db_process_sql( + 'UPDATE tagente + SET total_count=total_count+1, normal_count=normal_count+1 + WHERE id_agente='.(int) $id_agent + ); } else { - db_process_sql('UPDATE tagente SET total_count=total_count+1, notinit_count=notinit_count+1 WHERE id_agente='.(int) $id_agent); + db_process_sql( + 'UPDATE tagente + SET total_count=total_count+1, notinit_count=notinit_count+1 + WHERE id_agente='.(int) $id_agent + ); } } diff --git a/pandora_console/include/functions_servers.php b/pandora_console/include/functions_servers.php index 1151db3469..5f82faa91d 100644 --- a/pandora_console/include/functions_servers.php +++ b/pandora_console/include/functions_servers.php @@ -61,11 +61,12 @@ function servers_get_server($id_server, $filter=false, $fields=false) */ function servers_get_names() { - $all_servers = @db_get_all_rows_filter( - 'tserver', - false, - ['DISTINCT(name) as name'] + $all_servers = db_get_all_rows_sql( + 'SELECT DISTINCT(`name`) as name + FROM tserver + WHERE server_type <> 13' ); + if ($all_servers === false) { return []; }