$id_agent, 'nombre' => $values['safe_mode_module'], ] ); } } // CONF FILE DELETION. if (isset($values['delete_conf'])) { unset($values['delete_conf']); $n_deleted = 0; foreach ($id_agents as $id_agent) { $agent_md5 = md5(agents_get_name($id_agent)); @unlink( $config['remote_config'].'/md5/'.$agent_md5.'.md5' ); $result = @unlink( $config['remote_config'].'/conf/'.$agent_md5.'.conf' ); $n_deleted += (int) $result; } if ($n_deleted > 0) { db_pandora_audit('Massive management', 'Delete conf file '.$id_agent); } else { db_pandora_audit('Massive management', 'Try to delete conf file '.$id_agent); } ui_print_result_message( $n_deleted > 0, __('Configuration files deleted successfully').'('.$n_deleted.')', __('Configuration files cannot be deleted') ); } if (empty($values) && empty($fields)) { $id_agents = []; } $n_edited = 0; $result = false; foreach ($id_agents as $id_agent) { $old_interval_value = db_get_value_filter('intervalo', 'tagente', ['id_agente' => $id_agent]); if (!empty($values)) { $group_old = false; $disabled_old = false; if ($values['id_grupo'] || isset($values['disabled'])) { $values_old = db_get_row_filter('tagente', ['id_agente' => $id_agent], ['id_grupo', 'disabled']); if ($values_old['id_grupo']) { $group_old = $values_old['id_grupo']; } if (isset($values['disabled'])) { $disabled_old = $values_old['disabled']; } } // Get the id_agent_module for this agent to update the 'safe_operation_mode' field. if (isset($values['safe_mode_module']) && ($values['safe_mode_module'] != '0')) { $values['safe_mode_module'] = $id_module_safe[$id_agent]; } $result = db_process_sql_update( 'tagente', $values, ['id_agente' => $id_agent] ); if ($result && $config['metaconsole_agent_cache'] == 1) { $server_name['server_name'] = db_get_sql('SELECT server_name FROM tagente WHERE id_agente ='.$id_agent); // Force an update of the agent cache. $result_metaconsole = agent_update_from_cache($id_agent, $values, $server_name); } // Update the configuration files. if ($result && ($old_interval_value != $values['intervalo']) && !empty($values['intervalo'])) { enterprise_hook( 'config_agents_update_config_token', [ $id_agent, 'interval', $values['intervalo'], ] ); } if ($disabled_old !== false && $disabled_old != $values['disabled']) { enterprise_hook( 'config_agents_update_config_token', [ $id_agent, 'standby', $values['disabled'], ] ); // Validate alerts for disabled agents. if ($values['disabled'] == 1) { alerts_validate_alert_agent($id_agent); } } if ($group_old || $result) { if ($group_old && $group_old != null) { $tpolicy_group_old = db_get_all_rows_sql( 'SELECT id_policy FROM tpolicy_groups WHERE id_group = '.$group_old ); } else { $tpolicy_group_old = db_get_all_rows_sql('SELECT id_policy FROM tpolicy_groups'); } if ($tpolicy_group_old) { foreach ($tpolicy_group_old as $key => $value) { $tpolicy_agents_old = db_get_sql( 'SELECT * FROM tpolicy_agents WHERE id_policy = '.$value['id_policy'].' AND id_agent = '.$id_agent ); if ($tpolicy_agents_old) { $result2 = db_process_sql_update( 'tpolicy_agents', ['pending_delete' => 1], [ 'id_agent' => $id_agent, 'id_policy' => $value['id_policy'], ] ); } } } if ($values['id_grupo'] && $values['id_grupo'] != null) { $tpolicy_group_new = db_get_all_rows_sql( 'SELECT id_policy FROM tpolicy_groups WHERE id_group = '.$values['id_grupo'] ); } else { $tpolicy_group_new = db_get_all_rows_sql('SELECT id_policy FROM tpolicy_groups'); } if ($tpolicy_group_new) { foreach ($tpolicy_group_new as $key => $value) { $tpolicy_agents_new = db_get_sql( 'SELECT * FROM tpolicy_agents WHERE id_policy = '.$value['id_policy'].' AND id_agent ='.$id_agent ); if (!$tpolicy_agents_new) { db_process_sql_insert( 'tpolicy_agents', [ 'id_policy' => $value['id_policy'], 'id_agent' => $id_agent, ] ); } else { $result3 = db_process_sql_update( 'tpolicy_agents', ['pending_delete' => 0], [ 'id_agent' => $id_agent, 'id_policy' => $value['id_policy'], ] ); } } } } } $info = []; // Update Custom Fields. foreach ($fields as $field) { $info[$field['id_field']] = $field['name']; $value = get_parameter('customvalue_'.$field['id_field']); if (empty($value) === false) { $key = $field['id_field']; $old_value = db_get_all_rows_filter( 'tagent_custom_data', [ 'id_agent' => $id_agent, 'id_field' => $key, ] ); if ($old_value === false) { // Create custom field if not exist. $result = db_process_sql_insert( 'tagent_custom_data', [ 'id_field' => $key, 'id_agent' => $id_agent, 'description' => $value, ] ); } else { if ($old_value[0]['description'] !== $value) { $result = db_process_sql_update( 'tagent_custom_data', ['description' => $value], [ 'id_field' => $key, 'id_agent' => $id_agent, ] ); } } } } // Create or Remove the secondary groups. if (empty($secondary_groups_added) === false || empty($secondary_groups_removed) === false ) { $result = enterprise_hook( 'agents_update_secondary_groups', [ $id_agent, explode(',', $secondary_groups_added), explode(',', $secondary_groups_removed), ] ); } $n_edited += (int) $result; } if ($result !== false) { db_pandora_audit( 'Massive management', 'Update agent '.$id_agent, false, false, json_encode($info) ); } else { if (isset($id_agent) === true) { db_pandora_audit( 'Massive management', 'Try to update agent '.$id_agent, false, false, json_encode($info) ); } } ui_print_result_message( $result !== false, __('Agents updated successfully (%d)', $n_edited), __('Agents cannot be updated (maybe there was no field to update)') ); } $id_group = 0; $table = new StdClass(); $table->id = 'delete_table'; $table->class = 'databox filters'; $table->width = '100%'; $table->data = []; $table->style = []; $table->style[0] = 'font-weight: bold;'; $table->style[2] = 'font-weight: bold'; $table->size = []; $table->size[0] = '15%'; $table->size[1] = '35%'; $table->size[2] = '15%'; $table->size[3] = '35%'; $table->data = []; $table->data[0][0] = __('Group'); $table->data[0][1] = html_print_select_groups( false, 'AW', true, 'id_group', $id_group, false, '', '', true ); $table->data[0][2] = __('Group recursion'); $table->data[0][3] = html_print_checkbox( 'recursion2', 1, $recursion, true, false ); $status_list = []; $status_list[AGENT_STATUS_NORMAL] = __('Normal'); $status_list[AGENT_STATUS_WARNING] = __('Warning'); $status_list[AGENT_STATUS_CRITICAL] = __('Critical'); $status_list[AGENT_STATUS_UNKNOWN] = __('Unknown'); $status_list[AGENT_STATUS_NOT_NORMAL] = __('Not normal'); $status_list[AGENT_STATUS_NOT_INIT] = __('Not init'); $table->data[1][0] = __('Status'); $table->data[1][1] = html_print_select( $status_list, 'status_agents', 'selected', '', __('All'), AGENT_STATUS_ALL, true ); $table->data[1][2] = __('Show agents'); $table->data[1][3] = html_print_select( [ 0 => 'Only enabled', 1 => 'Only disabled', ], 'disabled', 2, '', __('All'), 2, true, false, true, '', false, 'width:30%;' ); $table->data[2][0] = __('Agents'); $table->data[2][0] .= ''; $table->data[2][0] .= html_print_image('images/spinner.png', true); $table->data[2][0] .= ''; $all_agents = agents_get_group_agents( array_keys(users_get_groups($config['id_user'], 'AW', false)), ['disabled' => 2], 'none' ); $table->data[2][1] = html_print_select( $all_agents, 'id_agents[]', 0, false, '', '', true, true, true, '', false, 'min-width: 500px; max-width: 500px; max-height: 100px', false, false, false, '', false, false, false, false, true, true, true ); echo '
'; ui_require_jquery_file('form'); ui_require_jquery_file('pandora.controls'); ui_require_jquery_file('ajaxqueue'); ui_require_jquery_file('bgiframe'); ?>