2012-04-10 Sergio Martin <sergio.martin@artica.es>

* include/javascript/pandora.js
	operation/agentes/ver_agente.php
	godmode/massive/massive_add_alerts.php
	godmode/massive/massive_delete_action_alerts.php
	godmode/massive/massive_delete_alerts.php
	godmode/massive/massive_edit_modules.php
	godmode/massive/massive_add_action_alerts.php: Improve some parts
	of massive operations section as add ALL/COMMON switch in the
	agents/modules selectors, allow to select multiple alert actions 
	in the delete/add operations, add the period advanced control to
	the modules edition section and improve this period control



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5919 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
zarzuelo 2012-04-10 11:28:36 +00:00
parent 65d32498af
commit 80472fa14b
8 changed files with 131 additions and 35 deletions

View File

@ -1,3 +1,17 @@
2012-04-10 Sergio Martin <sergio.martin@artica.es>
* include/javascript/pandora.js
operation/agentes/ver_agente.php
godmode/massive/massive_add_alerts.php
godmode/massive/massive_delete_action_alerts.php
godmode/massive/massive_delete_alerts.php
godmode/massive/massive_edit_modules.php
godmode/massive/massive_add_action_alerts.php: Improve some parts
of massive operations section as add ALL/COMMON switch in the
agents/modules selectors, allow to select multiple alert actions
in the delete/add operations, add the period advanced control to
the modules edition section and improve this period control
2012-04-09 Juan Manuel Ramon <juanmanuel.ramon@artica.es>
* godmode/reporting/reporting_builder.list_items.php

View File

@ -59,11 +59,11 @@ if ($add) {
if(empty($id_agents) || $id_agents[0] == 0)
ui_print_result_message (false, '', __('Could not be added').". ".__('No agents selected'));
else {
$action = (int) get_parameter ('action');
$actions = get_parameter ('action');
$fires_min = get_parameter ('fires_min');
$fires_max = get_parameter ('fires_max');
if ($action > 0) {
if (!empty($actions)) {
$agent_alerts = agents_get_alerts($id_agents);
$cont = 0;
$agent_alerts_id = array();
@ -87,14 +87,16 @@ if ($add) {
else {
$results = true;
foreach ($agent_alerts_id as $agent_alert_id) {
$result = alerts_add_alert_agent_module_action($agent_alert_id, $action, $options);
if($result === false)
$results = false;
foreach($actions as $action) {
$result = alerts_add_alert_agent_module_action($agent_alert_id, $action, $options);
if($result === false)
$results = false;
}
}
db_pandora_audit("Masive management", "Add alert action " . json_encode($id_agents), false, false, 'Agents: ' .
json_encode($id_agents) . ' Alerts : ' . json_encode($agent_alerts) .
' Fires Min: ' . $fires_min . ' Fires Max: ' . $fires_max . ' Action: ' . $action);
' Fires Min: ' . $fires_min . ' Fires Max: ' . $fires_max . ' Actions: ' . implode(',',$actions));
ui_print_result_message ($results, __('Successfully added'), __('Could not be added'));
}
@ -141,7 +143,7 @@ $table->data[2][1] = html_print_select (array(), 'id_alert_templates[]', '', '',
$actions = alerts_get_alert_actions ();
$table->data[3][0] = __('Action');
$table->data[3][1] = html_print_select ($actions, 'action', '', '', __('None'), 0, true);
$table->data[3][1] = html_print_select ($actions, 'action[]', '', '', '', '', true, true);
$table->data[3][1] .= '<span><a href="#" class="show_advanced_actions">'.__('Advanced options').' &raquo; </a></span>';
$table->data[3][1] .= '<span id="advanced_actions" class="advanced_actions invisible">';
$table->data[3][1] .= __('Number of alerts match from').' ';

View File

@ -133,7 +133,10 @@ $agents_alerts = alerts_get_agents_with_alert_template ($id_alert_template, $id_
$agents = agents_get_agents();
$table->data[1][1] = html_print_select (index_array ($agents, 'id_agente', 'nombre'),
'id_agents[]', '', '', '', '', true, true, true, '', false, 'width:180px;');
$table->data[1][2] = __('Modules');
$table->data[1][2] = __('When select agents');
$table->data[1][2] .= '<br>';
$table->data[1][2] .= html_print_select (array('common' => __('Show common modules'), 'all' => __('Show all modules')), 'modules_selection_mode',
'common', false, '', '', true);
$table->data[1][3] = html_print_select (array(), 'module[]', '', false, '', '', true, true, false, '', false, 'width:180px;');
$templates = alerts_get_alert_templates (false, array ('id', 'name'));
@ -221,7 +224,11 @@ $(document).ready (function () {
$("#module").blur (function () {
$(this).css ("width", "180px");
});
});
$("#modules_selection_mode").change (function() {
$("#id_agents").trigger('change');
});
});
/* ]]> */

View File

@ -54,9 +54,9 @@ if ($delete) {
if(empty($id_agents) || $id_agents[0] == 0)
ui_print_result_message (false, '', __('Could not be deleted').". ".__('No agents selected'));
else {
$action = (int) get_parameter ('action');
$actions = get_parameter ('action');
if($action > 0){
if(!empty($actions)){
$agent_alerts = agents_get_alerts($id_agents);
$alerts_agent_modules = array();
@ -76,11 +76,13 @@ if ($delete) {
$agent_module_actions = alerts_get_alert_agent_module_actions ($alert_agent_module['id'], array('id','id_alert_action'));
foreach ($agent_module_actions as $agent_module_action){
if($agent_module_action['id_alert_action'] == $action) {
$result = alerts_delete_alert_agent_module_action ($agent_module_action['id']);
if($result === false)
$results = false;
foreach($actions as $action) {
if($agent_module_action['id_alert_action'] == $action) {
$result = alerts_delete_alert_agent_module_action ($agent_module_action['id']);
if($result === false)
$results = false;
}
}
}
}
@ -88,15 +90,15 @@ if ($delete) {
if ($results) {
db_pandora_audit("Masive management", "Delete alert action", false, false,
'Agent: ' . json_encode($id_agents) . ' Alert templates: ' . json_encode($id_alert_templates) .
' Action: ' . $action);
' Actions: ' . implode(',',$actions));
}
else {
db_pandora_audit("Masive management", "Fail try to delete alert action", false, false,
'Agent: ' . json_encode($id_agents) . ' Alert templates: ' . json_encode($id_alert_templates) .
' Action: ' . $action);
' Actions: ' . implode(',',$actions));
}
ui_print_result_message ($results, __('Successfully deleted'), __('Could not be deleted')/*.": ". $agent_alerts['simple'][0]['id']*/);
ui_print_result_message ($results, __('Successfully deleted'), __('Could not be deleted'));
}
}
else {
@ -146,7 +148,7 @@ $table->data[2][1] = html_print_select (index_array ($alert_templates, 'id_alert
$actions = alerts_get_alert_actions ();
$table->data[3][0] = __('Action');
$table->data[3][1] = html_print_select ($actions, 'action', '', '', __('None'), 0, true);
$table->data[3][1] = html_print_select ($actions, 'action[]', '', '', '', '', true, true);
echo '<form method="post" id="form_alert" action="index.php?sec=gmassive&sec2=godmode/massive/massive_operations&option=delete_action_alerts">';
html_print_table ($table);

View File

@ -158,7 +158,10 @@ $agents_alerts = alerts_get_agents_with_alert_template ($id_alert_template, $id_
false, array ('tagente.nombre', 'tagente.id_agente'));
$table->data[2][1] = html_print_select (index_array ($agents_alerts, 'id_agente', 'nombre'),
'id_agents[]', '', '', '', '', true, true, true, '', $id_alert_template == 0);
$table->data[2][2] = __('Modules');
$table->data[2][2] = __('When select agents');
$table->data[2][2] .= '<br>';
$table->data[2][2] .= html_print_select (array('common' => __('Show common modules'), 'all' => __('Show all modules')), 'modules_selection_mode',
'common', false, '', '', true);
$table->data[2][3] = html_print_select (array(), 'module[]', '', false, '', '', true, true, false);
echo '<form method="post" id="form_alerts" action="index.php?sec=gmassive&sec2=godmode/massive/massive_operations&option=delete_alerts" >';
@ -222,6 +225,10 @@ $(document).ready (function () {
$("#checkbox-recursion").click(function (){
$("#id_group").trigger("change");
});
$("#modules_selection_mode").change (function() {
$("#id_agents").trigger('change');
});
});
/* ]]> */
</script>

View File

@ -355,9 +355,8 @@ $table->data['edit1'][3] .= '<br /><em>'.__('Str.').'</em>';
$table->data['edit1'][3] .= html_print_input_text ('str_critical', '', '', 5, 15, true);
$table->data['edit2'][0] = __('Interval');
$table->data['edit2'][1] = html_print_input_text ('module_interval', '', '', 5, 15, true);
$table->data['edit2'][1] = html_print_extended_select_for_time ('module_interval', 0, '', __('No change'), '0', 10, true, 'width: 150px');
$table->data['edit2'][2] = __('Disabled');
//$table->data['edit2'][3] = html_print_checkbox ("disabled", 1, '', true);
$table->data['edit2'][3] = html_print_select(array('' => __('No change'), '1' => __('Yes'), '0' => __('No')),'disabled','','','', '', true);
$table->data['edit3'][0] = __('Post process');

View File

@ -236,6 +236,12 @@ function agent_changed_by_multiple_agents_with_alerts (event, id_agent, selected
//val() because the var is same <option val="NNN"></option>
idAgents.push($(val).val());
});
var selection_mode = $('#modules_selection_mode').val();
if(selection_mode == undefined) {
selection_mode = 'common';
}
template = $('#id_alert_template option:selected').attr("value");
$('#module').attr ('disabled', 1);
$('#module').empty ();
@ -244,7 +250,8 @@ function agent_changed_by_multiple_agents_with_alerts (event, id_agent, selected
{"page": "operation/agentes/ver_agente",
"get_agent_modules_alerts_json_for_multiple_agents": 1,
"template": template,
"id_agent[]": idAgents
"id_agent[]": idAgents,
"selection_mode": selection_mode
},
function (data) {
$('#module').empty ();
@ -643,15 +650,19 @@ function agent_autocomplete (id_agent_name, id_server_name, id_agent_id ) {
function period_select_init(name) {
// Manual mode is hidden by default
$('#'+name+'_manual').hide();
$('#'+name+'_default').show();
// If the text input is empty, we put on it 5 minutes by default
if($('#text-'+name+'_text').val() == '') {
$('#text-'+name+'_text').val(300);
$('#'+name+'_select option:eq(1)').attr('selected', true);
if($('#'+name+'_select option:eq(0)').val() == 0) {
$('#'+name+'_select option:eq(2)').attr('selected', 'selected');
}
else {
$('#'+name+'_select option:eq(1)').attr('selected', 'selected');
}
}
else if($('#text-'+name+'_text').val() == 0) {
$('#'+name+'_default').toggle();
$('#'+name+'_manual').toggle();
$('#'+name+'_units option:last').removeAttr('selected');
}
@ -667,8 +678,7 @@ function period_select_init(name) {
*/
function period_select_events(name) {
$('.'+name+'_toggler').click(function() {
$('#'+name+'_default').toggle();
$('#'+name+'_manual').toggle();
toggleBoth(name);
$('#text-'+name+'_text').focus();
});
@ -680,6 +690,8 @@ function period_select_events(name) {
if(value == -1) {
value = 300;
toggleBoth(name);
$('#text-'+name+'_text').focus();
}
$('.'+name).val(value);
@ -690,7 +702,7 @@ function period_select_events(name) {
// When select a custom units, the default period changes to 'custom' and
// the time in seconds is calculated into hidden input
$('#'+name+'_units').change(function() {
$('#'+name+'_select option:eq(0)').attr('selected', 'selected');
selectFirst(name);
calculateSeconds(name);
});
@ -704,11 +716,50 @@ function period_select_events(name) {
$('#text-'+name+'_text').val(cleanValue);
$('#'+name+'_select option:eq(0)').attr('selected', 'selected');
selectFirst(name+'_select');
calculateSeconds(name);
});
}
/**
*
* Select first option of a select if is not value=0
*
*/
function selectFirst(name) {
if($('#'+name+' option:eq(0)').val() == 0) {
$('#'+name+' option:eq(1)').attr('selected', 'selected');
}
else {
$('#'+name+' option:eq(0)').attr('selected', 'selected');
}
}
/**
*
* Toggle default and manual controls of period control
* It is done with css function because hide and show do not
* work properly when the divs are into a hiden div
*
*/
function toggleBoth(name) {
if($('#'+name+'_default').css('display') == 'none') {
$('#'+name+'_default').css('display','inline');
}
else {
$('#'+name+'_default').css('display','none');
}
if($('#'+name+'_manual').css('display') == 'none') {
$('#'+name+'_manual').css('display','inline');
}
else {
$('#'+name+'_manual').css('display','none');
}
}
/**
*
* Calculate the custom time in seconds into hidden input
@ -728,8 +779,12 @@ function adjustTextUnits(name) {
var restPrev;
var unitsSelected = false;
$('#'+name+'_units option').each(function() {
if($(this).val() < 0) {
return;
}
var rest = $('#text-'+name+'_text').val()/$(this).val();
var restInt = parseInt(rest).toString();
if(rest != restInt && unitsSelected == false) {
$('#'+name+'_units option:eq('+($(this).index()-1)+')').attr('selected', true);
$('#text-'+name+'_text').val(restPrev);
@ -745,6 +800,6 @@ function adjustTextUnits(name) {
}
if($('#text-'+name+'_text').val() == 0) {
$('#'+name+'_units option:eq(0)').attr('selected', true);
selectFirst(name+'_units');
}
}

View File

@ -118,18 +118,28 @@ if (is_ajax ()) {
$idAgents = get_parameter('id_agent');
$id_template = get_parameter('template');
$nameModules = db_get_all_rows_sql('SELECT DISTINCT(nombre)
$selection_mode = get_parameter('selection_mode','common');
$sql = 'SELECT DISTINCT(nombre)
FROM tagente_modulo t1, talert_template_modules t2
WHERE t2.id_agent_module = t1.id_agente_modulo
AND delete_pending = 0
AND id_alert_template = '.$id_template.'
AND id_agente IN (' . implode(',', $idAgents) . ') AND (
AND id_agente IN (' . implode(',', $idAgents) . ')';
if($selection_mode == 'common') {
$sql .= ' 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 (' . implode(',', $idAgents) . ')
AND id_alert_template = '.$id_template.') = (' . count($idAgents) . ')');
AND id_alert_template = '.$id_template.') = (' . count($idAgents) . ')';
}
$sql .= ' ORDER BY t1.nombre';
$nameModules = db_get_all_rows_sql($sql);
if ($nameModules == false) {
$nameModules = array();