diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 9ad1e8e09b..915f0ebe30 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,21 @@ +2013-01-10 Juan Manuel Ramon + + * include/functions_agents.php + include/functions_treeview.php + extensions/net_tools.php + extensions/module_groups.php + operation/agentes/status_monitor.php + operation/agentes/sla_view.php + operation/messages/message_list.php + godmode/agentes/fields_manager.php + godmode/alerts/alert_list.builder.php + godmode/massive/massive_delete_agents.php + godmode/massive/massive_edit_agents.php + godmode/massive/massive_delete_modules.php + godmode/massive/massive_delete_alerts.php + godmode/massive/massive_edit_modules.php: Merged fixes from + branches. + 2012-01-09 Sancho Lerena * godmode/setup/setup.php: Fixed warning on enabling EACL. diff --git a/pandora_console/extensions/module_groups.php b/pandora_console/extensions/module_groups.php index a726929650..93996eba23 100644 --- a/pandora_console/extensions/module_groups.php +++ b/pandora_console/extensions/module_groups.php @@ -130,9 +130,9 @@ function mainModuleGroups() { //The big query switch ($config["dbtype"]) { case "mysql": - $sql = "SELECT COUNT(id_agente) AS count, estado + $sql = "SELECT COUNT(id_agente) AS count, case utimestamp when 0 then 5 else estado end as estado FROM tagente_estado - WHERE utimestamp != 0 AND id_agente IN + WHERE id_agente IN (SELECT id_agente FROM tagente WHERE id_grupo = %d AND disabled IS FALSE) AND id_agente_modulo IN (SELECT id_agente_modulo @@ -141,9 +141,9 @@ function mainModuleGroups() { GROUP BY estado"; break; case "postgresql": - $sql = "SELECT COUNT(id_agente) AS count, estado + $sql = "SELECT COUNT(id_agente) AS count, case utimestamp when 0 then 5 else estado end as estado FROM tagente_estado - WHERE utimestamp != 0 AND id_agente IN + WHERE id_agente IN (SELECT id_agente FROM tagente WHERE id_grupo = %d AND disabled = 0) AND id_agente_modulo IN (SELECT id_agente_modulo @@ -152,9 +152,9 @@ function mainModuleGroups() { GROUP BY estado"; break; case "oracle": - $sql = "SELECT COUNT(id_agente) AS count, estado + $sql = "SELECT COUNT(id_agente) AS count, case when utimestamp = 0 then 5 else estado end estado FROM tagente_estado - WHERE utimestamp != 0 AND id_agente IN + WHERE id_agente IN (SELECT id_agente FROM tagente WHERE id_grupo = %d AND (disabled IS NOT NULL AND disabled <> 0)) AND id_agente_modulo IN (SELECT id_agente_modulo @@ -258,6 +258,9 @@ function mainModuleGroups() { elseif (array_key_exists(0, $states)) { $color = '#8ae234'; //Green when the cell for this model group and agent has OK state all modules. } + elseif (array_key_exists(5, $states)) { + $color = '#729fcf'; // Blue when the cell for this module group and all modules have not init value. + } $alinkStart = ' ' . __("Grey cell when the module group and agent have at least one in unknown status and the others in green status") . '' . + '
  • +
     
    ' . + __("Blue cell when the module group and agent have all modules in not init status.") . + '
  • ' . "" . "

    "; } diff --git a/pandora_console/extensions/net_tools.php b/pandora_console/extensions/net_tools.php index a6b7521e94..090bfd140a 100644 --- a/pandora_console/extensions/net_tools.php +++ b/pandora_console/extensions/net_tools.php @@ -43,7 +43,7 @@ function main_net_tools () { $id_agente = get_parameter ("id_agente"); $ip = db_get_sql ("SELECT direccion FROM tagente WHERE id_agente = $id_agente"); if ($ip == "") { - echo "

    The agent hasn't got IP

    "; + echo "
    The agent hasn't got IP
    "; return; } echo "
    "; diff --git a/pandora_console/godmode/agentes/fields_manager.php b/pandora_console/godmode/agentes/fields_manager.php index 4d680d308d..5839c9829d 100644 --- a/pandora_console/godmode/agentes/fields_manager.php +++ b/pandora_console/godmode/agentes/fields_manager.php @@ -99,7 +99,7 @@ else { echo '
    '. __('No fields defined') .'
    '; } -if($fields === false) $fields = array(); +if ($fields === false) $fields = array(); foreach ($fields as $field) { diff --git a/pandora_console/godmode/alerts/alert_list.builder.php b/pandora_console/godmode/alerts/alert_list.builder.php index 8f97a94230..2bbd388c80 100644 --- a/pandora_console/godmode/alerts/alert_list.builder.php +++ b/pandora_console/godmode/alerts/alert_list.builder.php @@ -42,6 +42,12 @@ $table->size[1] = '80%'; $table->style[0] = 'font-weight: bold; vertical-align: top;'; $table->align[0] = 'left'; $table->align[1] = 'left'; +// This is because if this view is reused after list alert view then +// styles in the previous view can affect this table. +$table->rowstyle[0] = ''; +$table->rowstyle[1] = ''; +$table->rowstyle[2] = ''; +$table->rowstyle[3] = ''; /* Add an agent selector */ diff --git a/pandora_console/godmode/massive/massive_delete_agents.php b/pandora_console/godmode/massive/massive_delete_agents.php index 2851f2fd4b..3af8d99b6a 100644 --- a/pandora_console/godmode/massive/massive_delete_agents.php +++ b/pandora_console/godmode/massive/massive_delete_agents.php @@ -30,7 +30,7 @@ require_once ('include/functions_users.php'); function process_manage_delete ($id_agents) { if (empty ($id_agents)) { - echo '

    '.__('No agents selected').'

    '; + ui_print_error_message(__('No agents selected')); return false; } @@ -42,21 +42,28 @@ function process_manage_delete ($id_agents) { db_process_sql_begin (); $error = false; + $count_deleted = 0; + $agent_id_restore = 0; foreach ($id_agents as $id_agent) { $success = agents_delete_agent ($id_agent); - if (! $success) + if (! $success) { + $agent_id_restore = $id_agent; break; + } + $count_deleted++; } if (! $success) { - echo '

    '.__('There was an error deleting the agent, the operation has been cancelled').'

    '; - echo '

    '.__('Could not delete agent').' '.agents_get_name ($id_agent).'

    '; + ui_print_error_message(__('There was an error deleting the agent, the operation has been cancelled') . '. ' . __('Could not delete agent').' '.agents_get_name ($agent_id_restore)); + + //echo '

    '.__('There was an error deleting the agent, the operation has been cancelled').'

    '; + //echo '

    '.__('Could not delete agent').' '.agents_get_name ($id_agent).'

    '; db_process_sql_rollback (); return false; } else { - echo '

    '.__('Successfully deleted').'

    '; + ui_print_success_message(__('Successfully deleted') . ' (' . $count_deleted . ')'); db_process_sql_commit (); return true; diff --git a/pandora_console/godmode/massive/massive_delete_alerts.php b/pandora_console/godmode/massive/massive_delete_alerts.php index 33c8f7eb11..eab80a1b74 100644 --- a/pandora_console/godmode/massive/massive_delete_alerts.php +++ b/pandora_console/godmode/massive/massive_delete_alerts.php @@ -61,24 +61,52 @@ if (is_ajax ()) { function process_manage_delete ($id_alert_template, $id_agents, $module_names) { if (empty ($id_alert_template)) { - echo '

    '.__('No alert selected').'

    '; + ui_print_error_message(__('No alert selected')); return false; } if (empty ($id_agents) || $id_agents[0] == 0) { - echo '

    '.__('No agents selected').'

    '; + ui_print_error_message(__('No agents selected')); return false; } + $module_selection_mode = get_parameter('modules_selection_mode'); + foreach($module_names as $module){ foreach($id_agents as $id_agent) { $module_id = modules_get_agentmodule_id($module, $id_agent); $modules_id[] = $module_id['id_agente_modulo']; } } - - if(count($module_names) == 1 && $module_names[0] == '0'){ - $modules_id = agents_common_modules_with_alerts ($id_agents, false, true); + + // If is selected "ANY" option then we need the module selection mode: common or all modules + if (count($module_names) == 1 && $module_names[0] == '0') { + + if ($module_selection_mode == 'common') + $modules_id = agents_common_modules_with_alerts ($id_agents, false, true); + else { + // For agents selected + $modules_id = array(); + + foreach ($id_agents as $id_agent) { + $current_modules_agent = agents_get_modules($id_agent, 'id_agente_modulo', array ('disabled' => 0)); + + if ($current_modules_agent != false) { + // And their modules + foreach ($current_modules_agent as $current_module) { + $module_alerts = alerts_get_alerts_agent_module($current_module); + if ($module_alerts != false) { + // And for all alert in modules + foreach ($module_alerts as $module_alert) { + // Find the template in module + if ($module_alert['id_alert_template'] == $id_alert_template) + $modules_id[] = $module_alert['id_agent_module']; + } + } + } + } + } + } } $conttotal = 0; diff --git a/pandora_console/godmode/massive/massive_delete_modules.php b/pandora_console/godmode/massive/massive_delete_modules.php index 7d21f8d49b..4ed5c413d6 100644 --- a/pandora_console/godmode/massive/massive_delete_modules.php +++ b/pandora_console/godmode/massive/massive_delete_modules.php @@ -50,12 +50,12 @@ if (is_ajax ()) { function process_manage_delete ($module_name, $id_agents) { if (empty ($module_name)) { - echo '

    '.__('No module selected').'

    '; + ui_print_error_message(__('No module selected')); return false; } if (empty ($id_agents)) { - echo '

    '.__('No agents selected').'

    '; + ui_print_error_message(__('No agents selected')); return false; } @@ -63,19 +63,40 @@ function process_manage_delete ($module_name, $id_agents) { $module_name = (array)$module_name; - $modules = agents_get_modules ($id_agents, 'id_agente_modulo', - sprintf('nombre IN ("%s")', implode('","',$module_name)), true); - + // We are selecting "any" agent for the selected modules + if (($id_agents[0] == 0) and (is_array($id_agents)) and (count($id_agents) == 1)) + $id_agents = NULL; + + $selection_delete_mode = get_parameter('selection_mode', 'modules'); + + // Selection mode by Agents + if ($selection_delete_mode == 'agents') { + // We are selecting "any" module for the selecteds agents + if (($module_name[0] == 0) and (is_array($module_name)) and (count($module_name) == 1)) + $filter_for_module_deletion = false; + else + $filter_for_module_deletion = sprintf('nombre IN ("%s")', implode('","',$module_name)); + + $modules = agents_get_modules ($id_agents, 'id_agente_modulo', + $filter_for_module_deletion, true); + + } + else { + $modules = agents_get_modules ($id_agents, 'id_agente_modulo', + sprintf('nombre IN ("%s")', implode('","',$module_name)), true); + } + + $count_deleted_modules = count($modules); + $success = modules_delete_agent_module ($modules); if (! $success) { - echo '

    '.__('There was an error deleting the modules, the operation has been cancelled').'

    '; - echo '

    '.__('Could not delete modules').'

    '; + ui_print_error_message(__('There was an error deleting the modules, the operation has been cancelled')); db_process_sql_rollback (); return false; } else { - echo '

    '.__('Successfully deleted').'

    '; + ui_print_success_message(__('Successfully deleted') . ' (' . $count_deleted_modules . ')'); db_process_sql_commit (); return true; @@ -128,11 +149,11 @@ if ($delete) { $agents_ = db_get_all_rows_sql('SELECT DISTINCT(t1.id_agente) FROM tagente t1, tagente_modulo t2 - WHERE t1.id_agente = t2.id_agente'); - foreach ($agents_ as $id_agent) { - $module_name = db_get_all_rows_filter('tagente_modulo', array('id_agente' => $id_agent, 'id_tipo_modulo' => $module_type),'nombre'); - - if ($module_name == false) { + WHERE t1.id_agente = t2.id_agente AND t2.delete_pending = 0 ' . $condition); + foreach($agents_ as $id_agent) { + $module_name = db_get_all_rows_filter('tagente_modulo', array('id_agente' => $id_agent['id_agente'], 'id_tipo_modulo' => $module_type, 'delete_pending' => 0),'nombre'); + + if($module_name == false) { $module_name = array(); } foreach ($module_name as $mod_name) { @@ -149,11 +170,10 @@ if ($delete) { if($module_name == false) { $module_name = array(); } - foreach($module_name as $mod_name) { - $result = process_manage_delete ($mod_name['nombre'], $id_agent); - $count ++; - $success += (int)$result; + else { + $result = process_manage_delete (array(0 => 0), $id_agent); } + $success += (int)$result; } } @@ -161,7 +181,9 @@ if ($delete) { $agents_ = array(); } - $result = process_manage_delete ($modules_, $agents_); + if (!$force) + $result = process_manage_delete ($modules_, $agents_); + if ($result) { db_pandora_audit("Massive management", "Delete module ", false, false, 'Agent: ' . json_encode($agents_) . ' Module: ' . $module_name); diff --git a/pandora_console/godmode/massive/massive_edit_agents.php b/pandora_console/godmode/massive/massive_edit_agents.php index d11d1be635..bae746556d 100644 --- a/pandora_console/godmode/massive/massive_edit_agents.php +++ b/pandora_console/godmode/massive/massive_edit_agents.php @@ -352,8 +352,8 @@ $table->data[4][1] = html_print_select($arraySelectIcon, "icon_path", $icon_path if ($config['activate_gis']) { $table->data[5][0] = __('Ignore new GIS data:'); $table->data[5][1] = __('No change').' '.html_print_radio_button_extended ("update_gis_data", -1, '', $update_gis_data, false, '', 'style="margin-right: 40px;"', true); - $table->data[5][1] .= __('Disabled').' '.html_print_radio_button_extended ("update_gis_data", 0, '', $update_gis_data, false, '', 'style="margin-right: 40px;"', true); - $table->data[5][1] .= __('Active').' '.html_print_radio_button_extended ("update_gis_data", 1, '', $update_gis_data, false, '', 'style="margin-right: 40px;"', true); + $table->data[5][1] .= __('Disabled').' '.html_print_radio_button_extended ("update_gis_data", 1, '', $update_gis_data, false, '', 'style="margin-right: 40px;"', true); + $table->data[5][1] .= __('Active').' '.html_print_radio_button_extended ("update_gis_data", 0, '', $update_gis_data, false, '', 'style="margin-right: 40px;"', true); } $table->data[6][0] = __('Quiet'); diff --git a/pandora_console/godmode/massive/massive_edit_modules.php b/pandora_console/godmode/massive/massive_edit_modules.php index 5d09a65b1a..e4bec2d596 100644 --- a/pandora_console/godmode/massive/massive_edit_modules.php +++ b/pandora_console/godmode/massive/massive_edit_modules.php @@ -80,11 +80,11 @@ if ($update) { $agents_ = db_get_all_rows_sql('SELECT DISTINCT(t1.id_agente) FROM tagente t1, tagente_modulo t2 - WHERE t1.id_agente = t2.id_agente'); - foreach ($agents_ as $id_agent) { - $module_name = db_get_all_rows_filter('tagente_modulo', array('id_agente' => $id_agent, 'id_tipo_modulo' => $module_type),'nombre'); - - if ($module_name == false) { + WHERE t1.id_agente = t2.id_agente AND t2.delete_pending = 0 ' . $condition); + foreach($agents_ as $id_agent) { + $module_name = db_get_all_rows_filter('tagente_modulo', array('id_agente' => $id_agent, 'id_tipo_modulo' => $module_type, 'delete_pending' => 0),'nombre'); + + if($module_name == false) { $module_name = array(); } foreach ($module_name as $mod_name) { @@ -321,7 +321,10 @@ $table->data['edit4'][1] .= html_print_input_text ('min', '', '', 5, 15, true); $table->data['edit4'][1] .= '
    '.__('Max.').''; $table->data['edit4'][1] .= html_print_input_text ('max', '', '', 5, 15, true); $table->data['edit4'][2] = __('Module group'); -$module_groups = array_merge(array(0 => 'Not assigned'), modules_get_modulegroups()); +// Create module groups values for select +$module_groups = modules_get_modulegroups(); +$module_groups[0] = __('Not assigned'); + $table->data['edit4'][3] = html_print_select ($module_groups, 'id_module_group', '', '', __('No change'), '', true, false, false); @@ -583,10 +586,13 @@ $(document).ready (function () { '.__('No modules selected').''; + ui_print_error_message(__('No modules selected')); return false; } + + if (!is_array($agents_select)) + $agents_select = array($agents_select); /* List of fields which can be updated */ $fields = array ('min_warning', 'max_warning', 'str_warning', 'min_critical', 'max_critical', 'str_critical', 'min_ff_event', 'module_interval', @@ -620,6 +626,11 @@ function process_manage_edit ($module_name, $agents_select = null) { if (get_parameter('quiet_select', -1) != -1) { $values['quiet'] = get_parameter('quiet_select'); } + + $filter_modules = false; + + if (!is_numeric($module_name) or ($module_name != 0)) + $filter_modules['nombre'] = $module_name; // Whether to update module tag info $update_tags = get_parameter('id_tag', false); @@ -627,7 +638,7 @@ function process_manage_edit ($module_name, $agents_select = null) { if (array_search(0, $agents_select) !== false) { //Apply at All agents. $modules = db_get_all_rows_filter ('tagente_modulo', - array ('nombre' => $module_name), + $filter_modules, array ('id_agente_modulo')); } else { diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index ddb1d5ec68..9afc5e0b46 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -782,16 +782,8 @@ function agents_get_next_contact($idAgent, $maxModules = false) { */ function agents_common_modules_with_alerts ($id_agent, $filter = false, $indexed = true, $get_not_init_modules = true) { $id_agent = safe_int ($id_agent, 1); - + $where = ''; - if (! empty ($id_agent)) { - $where = sprintf (' WHERE t2.id_agent_module = t1.id_agente_modulo AND delete_pending = 0 - AND id_agente IN (%s) AND ( - SELECT count(nombre) - FROM tagente_modulo t3, talert_template_modules t4 - WHERE t4.id_agent_module = t3.id_agente_modulo AND delete_pending = 0 - AND t1.nombre = t3.nombre AND id_agente IN (%s)) = (%s)', implode (",", (array) $id_agent), implode (",", (array) $id_agent), count($id_agent)); - } if (! empty ($filter)) { $where .= ' AND '; @@ -804,14 +796,59 @@ function agents_common_modules_with_alerts ($id_agent, $filter = false, $indexed } else { $where .= $filter; } - } + } - $sql = sprintf ('SELECT DISTINCT(t1.id_agente_modulo) - FROM tagente_modulo t1, talert_template_modules t2 - %s - ORDER BY nombre', - $where); - $result = db_get_all_rows_sql ($sql); + if (! empty ($id_agent)) { + // Get module_name-template repetitions over agents selected + // Group by if there is more than one agent + $group_by = ''; + if (count((array)$id_agent) > 1) + $group_by = 'having count(*) > 1'; + + $sql = sprintf ('SELECT t1.nombre, t2.id_alert_template, count(*) + FROM tagente_modulo t1, talert_template_modules t2 + WHERE t2.id_agent_module = t1.id_agente_modulo + AND delete_pending = 0 + AND id_agente IN (%s) %s group by nombre, id_alert_template %s' + , implode (",", (array) $id_agent) + , $where + ,$group_by); + + $result_tmp = db_get_all_rows_sql ($sql); + + $result = array(); + if ($result_tmp != false) { + + foreach ($result_tmp as $module_template) { + + $sql_modules = sprintf ('SELECT t1.id_agente_modulo + FROM tagente_modulo t1, talert_template_modules t2 + WHERE t1.id_agente_modulo = t2.id_agent_module + AND delete_pending = 0 + AND t1.nombre = \'%s\' AND t2.id_alert_template = %s' + , $module_template['nombre'] + , $module_template['id_alert_template']); + + $id_modules_template = db_get_all_rows_sql ($sql_modules); + + if ($id_modules_template != false) + foreach ($id_modules_template as $id_module_template) + $result[] = $id_module_template; + + } + + } + } + else { + + $sql = sprintf ('SELECT DISTINCT(t1.id_agente_modulo) + FROM tagente_modulo t1, talert_template_modules t2 + %s + ORDER BY nombre', + $where); + $result = db_get_all_rows_sql ($sql); + + } if (empty ($result)) { return array (); diff --git a/pandora_console/include/functions_treeview.php b/pandora_console/include/functions_treeview.php index 1838bdc919..ebeb7812e0 100755 --- a/pandora_console/include/functions_treeview.php +++ b/pandora_console/include/functions_treeview.php @@ -277,7 +277,7 @@ function treeview_printTree($type) { } if ($list === false) { - ui_print_error_message("There aren't agents in this agrupation"); + echo '

    '.__('There aren\'t agents in this agrupation').'

    '; echo ''; echo ''; } @@ -423,6 +423,7 @@ function treeview_getData ($type, $server=false) { // If there are not groups display error and return if (empty($avariableGroups)) { + echo '

    '.__('There aren\'t agents in this agrupation').'

    '; return array (); } } diff --git a/pandora_console/operation/agentes/sla_view.php b/pandora_console/operation/agentes/sla_view.php index 90be4639c8..68962c63de 100644 --- a/pandora_console/operation/agentes/sla_view.php +++ b/pandora_console/operation/agentes/sla_view.php @@ -43,7 +43,7 @@ $offset = get_parameter ("offset", 0); // Get all module from agent -ui_pagination (count ($modules), "index.php?sec=estado&sec2=operation/agentes/ver_agente&tab=sla&id_agente=".$id_agent, $offset); +ui_pagination (count ($modules), "index.php?sec=estado&sec2=operation/agentes/ver_agente&tab=sla&id_agente=".$id_agent); $table->width = '95%'; $table->cellpadding = 4; @@ -115,7 +115,7 @@ $sql = "SELECT id_agent_module, sla_max, sla_min, sla_limit WHERE id_agent_module IN (".implode (",",array_keys ($modules)).")"; $result = db_get_all_rows_sql ($sql); if ($result !== false) { - echo "

    ".__('User-defined SLA items')." - ".human_time_description_raw ($config["sla_period"])."

    "; + echo "

    ".__('User-defined SLA items')." - ".human_time_description_raw ($config["sla_period"])."

    "; $table->width = '95%'; $table->cellpadding = 4; $table->cellspacing = 4; diff --git a/pandora_console/operation/agentes/status_monitor.php b/pandora_console/operation/agentes/status_monitor.php index 4c43177437..f4b608f47c 100644 --- a/pandora_console/operation/agentes/status_monitor.php +++ b/pandora_console/operation/agentes/status_monitor.php @@ -1035,8 +1035,7 @@ if (!empty ($table->data)) { html_print_table ($table); } else { - ui_print_error_message( - __('This group doesn\'t have any monitor') ); + echo "
    ".__('This group doesn\'t have any monitor')."
    "; } ?>