2010-05-31 Sergio Martin <sergio.martin@artica.es>

* images/cog_del.png
	godmode/agentes/massive_add_alerts.php
	godmode/agentes/massive_delete_action_alerts.php
	godmode/agentes/massive_operations.php
	godmode/agentes/massive_add_action_alerts.php: Added the alert massive
	operations 'add alerts', 'add actions' and 'delete actions'.
	An icon to delete actions added too.
	All for pending task: 3004606



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2815 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
zarzuelo 2010-05-31 09:22:15 +00:00
parent 19a726a5d7
commit 5776cb0d7a
6 changed files with 493 additions and 1 deletions

View File

@ -1,3 +1,14 @@
2010-05-31 Sergio Martin <sergio.martin@artica.es>
* images/cog_del.png
godmode/agentes/massive_add_alerts.php
godmode/agentes/massive_delete_action_alerts.php
godmode/agentes/massive_operations.php
godmode/agentes/massive_add_action_alerts.php: Added the alert massive
operations 'add alerts', 'add actions' and 'delete actions'.
An icon to delete actions added too.
All for pending task: 3004606
2010-05-28 Miguel de Dios <miguel.dedios@artica.es>
* godmode/reporting/reporting_builder.item_editor.php: added more intervals

View File

@ -0,0 +1,149 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2009 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation for version 2.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Load global vars
check_login ();
if (! give_acl ($config['id_user'], 0, "AW")) {
audit_db ($config['id_user'], $_SERVER['REMOTE_ADDR'], "ACL Violation",
"Trying to access massive agent deletion section");
require ("general/noaccess.php");
return;
}
require_once ('include/functions_agents.php');
require_once ('include/functions_alerts.php');
$id_group = (int) get_parameter ('id_group');
$id_agents = get_parameter ('id_agents');
$add = (bool) get_parameter_post ('add');
if ($add) {
if(empty($id_agents))
print_result_message (false, '', __('Could not be added').". ".__('No agents selected'));
else {
$action = (int) get_parameter ('action');
$fires_min = get_parameter ('fires_min');
$fires_max = get_parameter ('fires_max');
if($action > 0){
$agent_alerts = get_agent_alerts($id_agents);
$cont = 0;
$agent_alerts_id = array();
foreach($agent_alerts['simple'] as $agent_alert){
$agent_alerts_id[$cont] = $agent_alert['id'];
$cont = $cont + 1;
}
foreach($agent_alerts['compounds'] as $agent_alert){
$agent_alerts_id[$cont] = $agent_alert['id'];
$cont = $cont + 1;
}
$options = array();
if($fires_min > 0)
$options['fires_min'] = $fires_min;
if($fires_max > 0)
$options['fires_max'] = $fires_max;
$results = true;
foreach($agent_alerts_id as $agent_alert_id){
$result = add_alert_agent_module_action($agent_alert_id, $action, $options);
if($result === false)
$results = false;
}
print_result_message ($results, __('Successfully added'), __('Could not be added'));
}
else {
print_result_message (false, '', __('Could not be added').". ".__('No action selected'));
}
}
}
echo '<h3>'.__('Massive alert actions addition').'</h3>';
$groups = get_user_groups ();
$table->id = 'delete_table';
$table->width = '95%';
$table->data = array ();
$table->style = array ();
$table->style[0] = 'font-weight: bold; vertical-align:top';
$table->style[2] = 'font-weight: bold';
$table->size = array ();
$table->size[0] = '15%';
$table->size[1] = '85%';
$table->data = array ();
$table->data[0][0] = __('Group');
$table->data[0][1] = print_select ($groups, 'id_group', $id_group,
false, '', '', true);
$table->data[1][0] = __('Agents');
$table->data[1][0] .= '<span id="agent_loading" class="invisible">';
$table->data[1][0] .= '<img src="images/spinner.png" />';
$table->data[1][0] .= '</span>';
$table->data[1][1] = print_select (get_group_agents ($id_group, false, "none"),
'id_agents[]', 0, false, '', '', true, true);
$actions = get_alert_actions ();
$table->data[2][0] = __('Action');
$table->data[2][1] = print_select ($actions, 'action', '', '', __('None'), 0, true);
$table->data[2][1] .= '<span><a href="#" class="show_advanced_actions">'.__('Advanced options').' &raquo; </a></span>';
$table->data[2][1] .= '<span id="advanced_actions" class="advanced_actions invisible">';
$table->data[2][1] .= __('Number of alerts match from').' ';
$table->data[2][1] .= print_input_text ('fires_min', 0, '', 4, 10, true);
$table->data[2][1] .= ' '.__('to').' ';
$table->data[2][1] .= print_input_text ('fires_max', 0, '', 4, 10, true);
$table->data[2][1] .= print_help_icon ("alert-matches", true);
$table->data[2][1] .= '</span>';
echo '<form method="post" onsubmit="if (! confirm(\''.__('Are you sure?').'\')) return false;">';
print_table ($table);
echo '<div class="action-buttons" style="width: '.$table->width.'" onsubmit="if (!confirm(\' '.__('Are you sure?').'\')) return false;">';
print_input_hidden ('add', 1);
print_submit_button (__('Add'), 'go', false, 'class="sub add"');
echo '</div>';
echo '</form>';
echo '<h3 class="error invisible" id="message"> </h3>';
require_jquery_file ('form');
require_jquery_file ('pandora.controls');
?>
<script type="text/javascript">
$(document).ready (function () {
$("#id_group").pandoraSelectGroupAgent ({
agentSelect: "select#id_agents"
});
$("a.show_advanced_actions").click (function () {
/* It can be done in two different sites, so it must use two different selectors */
actions = $(this).parents ("form").children ("span.advanced_actions");
if (actions.length == 0)
actions = $(this).parents ("div").children ("span.advanced_actions")
$("#advanced_actions").removeClass("advanced_actions invisible");
$(this).remove ();
return false;
});
});
/* ]]> */
</script>

View File

@ -0,0 +1,165 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2009 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation for version 2.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Load global vars
check_login ();
if (! give_acl ($config['id_user'], 0, "AW")) {
audit_db ($config['id_user'], $_SERVER['REMOTE_ADDR'], "ACL Violation",
"Trying to access massive alert deletion");
require ("general/noaccess.php");
return;
}
require_once ('include/functions_agents.php');
require_once ('include/functions_alerts.php');
if (is_ajax ()) {
$get_agents = (bool) get_parameter ('get_agents');
if ($get_agents) {
$id_group = (int) get_parameter ('id_group');
$agents_alerts = get_group_agents ($id_group);
echo json_encode ($agents_alerts);
return;
}
return;
}
echo '<h3>'.__('Massive alerts addition').'</h3>';
function process_manage_add ($id_alert_template, $id_agents) {
if (empty ($id_agents)) {
echo '<h3 class="error">'.__('No agents selected').'</h3>';
return false;
}
if (empty ($id_alert_template)) {
echo '<h3 class="error">'.__('No alert selected').'</h3>';
return false;
}
process_sql_begin ();
$modules = get_agent_modules ($id_agents, 'id_agente_modulo', false, true);
$contfail = 0;
$contsuccess = 0;
foreach($modules as $module){
$success = create_alert_agent_module ($module, $id_alert_template);
if(!$success)
$contfail = $contfail + 1;
else
$contsuccess = $contsuccess + 1;
}
if ($contfail > 0) {
echo '<h3 class="error">'.__('There was an error adding the alerts, the operation has been cancelled').'</h3>';
echo '<h3 class="error">'.__('Could not add alerts').'</h3>';
process_sql_rollback ();
}
else {
echo '<h3 class="suc">'.__('Successfully added').' '.$contsuccess.' '.__('Alerts').'</h3>';
process_sql_commit ();
}
}
$id_group = (int) get_parameter ('id_group', -1);
$id_agents = get_parameter ('id_agents');
$id_alert_template = (int) get_parameter ('id_alert_template');
$add = (bool) get_parameter_post ('add');
if ($add) {
process_manage_add ($id_alert_template, $id_agents);
}
$groups = get_user_groups ();
$table->id = 'delete_table';
$table->width = '95%';
$table->data = array ();
$table->style = array ();
$table->style[0] = 'font-weight: bold; vertical-align:top';
$table->style[2] = 'font-weight: bold';
$table->size = array ();
$table->size[0] = '15%';
$table->size[1] = '85%';
$table->data = array ();
$table->data[0][0] = __('Group');
$table->data[0][1] = print_select ($groups, 'id_group', $id_group,
'', 'Select', -1, true, false, true, '', false);
$table->data[1][0] = __('Agent');
$table->data[1][0] .= '<span id="agent_loading" class="invisible">';
$table->data[1][0] .= '<img src="images/spinner.png" />';
$table->data[1][0] .= '</span>';
$agents_alerts = get_agents_with_alert_template ($id_alert_template, $id_group,
false, array ('tagente.nombre', 'tagente.id_agente'));
$table->data[1][1] = print_select (index_array ($agents_alerts, 'id_agente', 'nombre'),
'id_agents[]', '', '', '', '', true, true, true, '', false);
$templates = get_alert_templates (false, array ('id', 'name'));
$table->data[2][0] = __('Alert template');
$table->data[2][1] = print_select (index_array ($templates, 'id', 'name'),
'id_alert_template', $id_alert_template, false, __('Select'), 0, true);
echo '<form method="post" onsubmit="if (! confirm(\''.__('Are you sure?').'\')) return false;">';
print_table ($table);
echo '<div class="action-buttons" style="width: '.$table->width.'" onsubmit="if (!confirm(\' '.__('Are you sure?').'\')) return false;">';
print_input_hidden ('add', 1);
print_submit_button (__('Add'), 'go', false, 'class="sub add"');
echo '</div>';
echo '</form>';
echo '<h3 class="error invisible" id="message"> </h3>';
require_jquery_file ('form');
require_jquery_file ('pandora.controls');
?>
<script type="text/javascript">
/* <![CDATA[ */
$(document).ready (function () {
$("#id_group").change (function () {
var $select = $("#id_agents").enable ();
$("#agent_loading").show ();
$("option", $select).remove ();
jQuery.post ("ajax.php",
{"page" : "godmode/agentes/massive_add_alerts",
"get_agents" : 1,
"id_group" : this.value
},
function (data, status) {
options = "";
jQuery.each (data, function (id, value) {
options += "<option value=\""+id+"\">"+value+"</option>";
});
$("#id_agents").append (options);
$("#agent_loading").hide ();
$select.enable ();
},
"json"
);
});
$("#id_group").value = "0";
});
/* ]]> */
</script>

View File

@ -0,0 +1,131 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2009 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation for version 2.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Load global vars
check_login ();
if (! give_acl ($config['id_user'], 0, "AW")) {
audit_db ($config['id_user'], $_SERVER['REMOTE_ADDR'], "ACL Violation",
"Trying to access massive agent deletion section");
require ("general/noaccess.php");
return;
}
require_once ('include/functions_agents.php');
require_once ('include/functions_alerts.php');
$id_group = (int) get_parameter ('id_group');
$id_agents = get_parameter ('id_agents');
$delete = (bool) get_parameter_post ('delete');
if ($delete) {
if(empty($id_agents))
print_result_message (false, '', __('Could not be deleted').". ".__('No agents selected'));
else {
$action = (int) get_parameter ('action');
if($action > 0){
$agent_alerts = get_agent_alerts($id_agents);
$alerts_agent_modules = array();
foreach($agent_alerts['simple'] as $agent_alert){
$alerts_agent_modules = array_merge($alerts_agent_modules, get_alerts_agent_module ($agent_alert['id_agent_module'], true, false, 'id'));
}
foreach($agent_alerts['compounds'] as $agent_alert){
$alerts_agent_modules = array_merge($alerts_agent_modules, get_alerts_agent_module ($agent_alert['id'], false, false, 'id'));
}
$results = true;
$agent_module_actions = array();
foreach($alerts_agent_modules as $alert_agent_module){
$agent_module_actions = 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) {
echo $agent_module_action['id']." . ". $alert_agent_module['id'] ." ; ";
$result = delete_alert_agent_module_action ($agent_module_action['id']);
if($result === false)
$results = false;
}
}
}
print_result_message ($results, __('Successfully deleted'), __('Could not be deleted')/*.": ". $agent_alerts['simple'][0]['id']*/);
}
else {
print_result_message (false, '', __('Could not be deleted').". ".__('No action selected'));
}
}
}
echo '<h3>'.__('Massive alert actions deletion').'</h3>';
$groups = get_user_groups ();
$table->id = 'delete_table';
$table->width = '95%';
$table->data = array ();
$table->style = array ();
$table->style[0] = 'font-weight: bold; vertical-align:top';
$table->style[2] = 'font-weight: bold';
$table->size = array ();
$table->size[0] = '15%';
$table->size[1] = '85%';
$table->data = array ();
$table->data[0][0] = __('Group');
$table->data[0][1] = print_select ($groups, 'id_group', $id_group,
false, '', '', true);
$table->data[1][0] = __('Agents');
$table->data[1][0] .= '<span id="agent_loading" class="invisible">';
$table->data[1][0] .= '<img src="images/spinner.png" />';
$table->data[1][0] .= '</span>';
$table->data[1][1] = print_select (get_group_agents ($id_group, false, "none"),
'id_agents[]', 0, false, '', '', true, true);
$actions = get_alert_actions ();
$table->data[2][0] = __('Action');
$table->data[2][1] = print_select ($actions, 'action', '', '', __('None'), 0, true);
echo '<form method="post" onsubmit="if (! confirm(\''.__('Are you sure?').'\')) return false;">';
print_table ($table);
echo '<div class="action-buttons" style="width: '.$table->width.'" onsubmit="if (!confirm(\' '.__('Are you sure?').'\')) return false;">';
print_input_hidden ('delete', 1);
print_submit_button (__('Delete'), 'go', false, 'class="sub delete"');
echo '</div>';
echo '</form>';
echo '<h3 class="error invisible" id="message"> </h3>';
require_jquery_file ('form');
require_jquery_file ('pandora.controls');
?>
<script type="text/javascript">
$(document).ready (function () {
$("#id_group").pandoraSelectGroupAgent ({
agentSelect: "select#id_agents"
});
});
/* ]]> */
</script>

View File

@ -65,6 +65,33 @@ if($tab == 'delete_agents')
else
$deleteagenttab['active'] = false;
/* Add alerts actions */
$addactionalerttab['text'] = '<a href="index.php?sec=gagente&sec2=godmode/agentes/massive_operations&tab=add_action_alerts">'
. print_image ("images/cog.png", true, array ("title" => __('Add Actions')))
. "</a>";
if($tab == 'add_action_alerts')
$addactionalerttab['active'] = true;
else
$addactionalerttab['active'] = false;
/* Delete alerts actions */
$deleteactionalerttab['text'] = '<a href="index.php?sec=gagente&sec2=godmode/agentes/massive_operations&tab=delete_action_alerts">'
. print_image ("images/cog_del.png", true, array ("title" => __('Delete Actions')))
. "</a>";
if($tab == 'delete_action_alerts')
$deleteactionalerttab['active'] = true;
else
$deleteactionalerttab['active'] = false;
/* Add Alerts */
$addalerttab['text'] = '<a href="index.php?sec=gagente&sec2=godmode/agentes/massive_operations&tab=add_alerts">'
. print_image ("images/god2.png", true, array ("title" => __('Add alerts')))
. "</a>";
if($tab == 'add_alerts')
$addalerttab['active'] = true;
else
$addalerttab['active'] = false;
/* Delete Alerts */
$deletealerttab['text'] = '<a href="index.php?sec=gagente&sec2=godmode/agentes/massive_operations&tab=delete_alerts">'
. print_image ("images/delete_alerts.png", true, array ("title" => __('Delete alerts')))
@ -75,7 +102,7 @@ else
$deletealerttab['active'] = false;
$onheader = array('copy_modules' => $copymoduletab, 'edit_modules' => $editmoduletab, 'delete_modules' => $deletemoduletab, 'delete_agents' => $deleteagenttab, 'delete_alerts' => $deletealerttab);
$onheader = array('copy_modules' => $copymoduletab, 'edit_modules' => $editmoduletab, 'delete_modules' => $deletemoduletab, 'delete_agents' => $deleteagenttab, 'add_action_alerts' => $addactionalerttab, 'delete_action_alerts' => $deleteactionalerttab, 'add_alerts' => $addalerttab, 'delete_alerts' => $deletealerttab);
print_page_header (__('Agent configuration'). ' &raquo; '. __('Massive operations'), "images/god1.png", false, "", true, $onheader);
@ -84,6 +111,15 @@ switch ($tab) {
case 'delete_alerts':
require_once ('godmode/agentes/massive_delete_alerts.php');
break;
case 'add_alerts':
require_once ('godmode/agentes/massive_add_alerts.php');
break;
case 'delete_action_alerts':
require_once ('godmode/agentes/massive_delete_action_alerts.php');
break;
case 'add_action_alerts':
require_once ('godmode/agentes/massive_add_action_alerts.php');
break;
case 'delete_agents':
require_once ('godmode/agentes/massive_delete_agents.php');
break;

Binary file not shown.

After

Width:  |  Height:  |  Size: 702 B