2009-01-15 Esteban Sanchez <estebans@artica.es>

* godmode/alerts/configure_alert_template.php: The steps are now
	available as soon as the alert is created.

	* include/functions_alerts.php: Added validate_alert_agent_module().

	* include/functions_db.php: Removed deprecated
	process_alerts_validate(). Improved process_sql_update() to add
	a row selection parameter, the documentation and a bit fix when
	joining the fields with a coma.

	* operation/agentes/alerts_status.php: Use new functions to validate
	an alert.

	* operation/agentes/ver_agente.php: Removed validation alert codes
	since it doesn't belong here.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1346 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
esanchezm 2009-01-15 11:52:49 +00:00
parent 4b6883109e
commit ad3500a10a
6 changed files with 139 additions and 74 deletions

View File

@ -1,3 +1,21 @@
2009-01-15 Esteban Sanchez <estebans@artica.es>
* godmode/alerts/configure_alert_template.php: The steps are now
available as soon as the alert is created.
* include/functions_alerts.php: Added validate_alert_agent_module().
* include/functions_db.php: Removed deprecated
process_alerts_validate(). Improved process_sql_update() to add
a row selection parameter, the documentation and a bit fix when
joining the fields with a coma.
* operation/agentes/alerts_status.php: Use new functions to validate
an alert.
* operation/agentes/ver_agente.php: Removed validation alert codes
since it doesn't belong here.
2009-01-15 Esteban Sanchez <estebans@artica.es>
* godmode/alerts/configure_alert_template.php: Max and min alerts

View File

@ -35,7 +35,7 @@ function print_alert_template_steps ($step, $id) {
/* Step 1 */
if ($step == 1)
echo '<strong>';
if ($id && ! isset ($_POST['create_template'])) {
if ($id) {
echo '<a href="index.php?sec=galertas&sec2=godmode/alerts/configure_alert_template&id='.$id.'">';
echo __('Step').' 1 : '.__('Conditions');
echo '</a>';
@ -50,7 +50,7 @@ function print_alert_template_steps ($step, $id) {
if ($step == 2)
echo '<strong>';
if ($id && ! isset ($_POST['create_template'])) {
if ($id) {
echo '<a href="index.php?sec=galertas&sec2=godmode/alerts/configure_alert_template&id='.$id.'&step=2">';
echo __('Step').' 2 : '.__('Firing');
echo '</a>';
@ -65,7 +65,7 @@ function print_alert_template_steps ($step, $id) {
if ($step == 3)
echo '<strong>';
if ($id && ! isset ($_POST['create_template'])) {
if ($id) {
echo '<a href="index.php?sec=galertas&sec2=godmode/alerts/configure_alert_template&id='.$id.'&step=3">';
echo __('Step').' 3 : '.__('Recovery');
echo '</a>';

View File

@ -672,4 +672,57 @@ function get_alert_agent_module_actions ($id_alert_agent_module) {
return $retval;
}
/**
* Validates an alert id or an array of alert id's
*
* @param mixed Array of alerts ids or single id
*
* @return bool True if it was successful, false otherwise.
*/
function validate_alert_agent_module ($id_alert_agent_module) {
global $config;
require_once ("include/functions_events.php");
$alerts = safe_int ($id_alert_agent_module, 1);
if (empty ($alerts)) {
return false;
}
$alerts = (array) $alerts;
foreach ($alerts as $id) {
$alert = get_alert_agent_module ($id);
if (! empty ($alert["id_agent_module"])) {
//Simple alert
$agent_id = get_agentmodule_agent ($alert["id_agent_module"]);
$group_id = get_agentmodule_group ($agent_id);
} else {
//Combined alert
$agent_id = $alert["id_agent"];
$group_id = get_agent_group ($agent_id);
}
if (! give_acl ($config['id_user'], $group_id, "AW")) {
continue;
}
$result = process_sql_update ('talert_template_modules',
array ('times_fired' => 0,
'internal_counter' => 0),
array ('id' => $id));
if ($result > 0) {
create_event ("Manual validation of alert for ".
get_alert_template_description ($alert["id_alert_template"]),
$group_id, $agent_id, 1, $config["id_user"],
"alert_manual_validation", 1, $alert["id_agent_module"],
$id);
} elseif ($result === false) {
return false;
}
}
return true;
}
?>

View File

@ -2252,54 +2252,6 @@ function get_agent_group ($id_agent) {
function get_group_name ($id_group) {
return (string) get_db_value ('nombre', 'tgrupo', 'id_grupo', (int) $id_group);
}
/**
* Validates an alert id or an array of alert id's
*
* Validates an alert id or an array of alert id's
*
* @param mixed Array of alerts ids or single id
*
* @return bool True if it was successful, false otherwise.
*/
function process_alerts_validate ($id_alert) {
global $config;
require_once ("include/functions_events.php");
$id_alert = safe_int ($id_alert, 1);
if (empty ($id_alert)) {
return false;
} else {
$id_alert = (array) $id_alert;
}
foreach ($id_alert as $id_aam) {
$alert = get_db_row ("talerta_agente_modulo", "id_aam", $id_aam);
if (empty ($alert["id_agent"])) {
//Simple alert
$agent_id = get_agentmodule_agent ($alert["id_agente_modulo"]);
$group_id = get_agentmodule_group ($alert["id_agente_modulo"]);
} else {
//Combined alert
$agent_id = $alert["id_agent"];
$group_id = get_agent_group ($agent_id);
}
if (give_acl ($config['id_user'], $group_id, "AW") == 0) {
continue;
}
$sql = sprintf ("UPDATE talerta_agente_modulo SET times_fired = 0, internal_counter = 0 WHERE id_aam = %d", $id_aam);
$result = process_sql ($sql);
if ($result > 0) {
create_event ("Manual validation of alert for ".$alert["descripcion"], $group_id, $agent_id, 1, $config["id_user"], "alert_manual_validation", 1, $alert["id_agente_modulo"], $id_aam);
} elseif ($result === false) {
return false;
}
}
return true;
}
/**
* Gets all module groups. (General, Networking, System).
@ -2335,17 +2287,17 @@ function get_modulegroup_name ($modulegroup_id) {
}
/**
* Inserts strings into database
* Inserts strings into database
*
* The number of values should be the same or a positive integer multiple as the number of rows
* If you have an associate array (eg. array ("row1" => "value1")) you can use this function with ($table, array_keys ($array), $array) in it's options
* All arrays and values should have been cleaned before passing. It's not neccessary to add quotes.
*
* @param string $table Table to insert into
* @param mixed $rows A single row or array of rows to insert to
* @param mixed $values A single value or array of values to insert (can be a multiple amount of rows)
* @param string Table to insert into
* @param mixed A single row or array of rows to insert to
* @param mixed A single value or array of values to insert (can be a multiple amount of rows)
*
* @result mixed False in case of error or invalid values passed. Affected rows otherwise
* @result mixed False in case of error or invalid values passed. Affected rows otherwise
*/
function process_sql_insert ($table, $rows, $values) {
if (empty ($rows) || empty ($values)) { //Empty rows or values not processed
@ -2401,19 +2353,33 @@ function process_sql_insert ($table, $rows, $values) {
}
/**
* Inserts strings into database
* Inserts strings into database
*
* All values should be cleaned before passing. Quoting isn't necessary
* All values should be cleaned before passing. Quoting isn't necessary.
* Examples:
*
* @param string $table Table to insert into
* @param array $rows An associative array of values to update
* <code>
process_sql_update ('table', array ('field' => 1), array ('id' => $id));
process_sql_update ('table', array ('field' => 1), array ('id' => $id, 'name' => $name));
process_sql_update ('table', array ('field' => 1), array ('id' => $id, 'name' => $name), 'OR');
process_sql_update ('table', array ('field' => 2), 'id in (1, 2, 3) OR id > 10');
* <code>
*
* @result mixed False in case of error or invalid values passed. Affected rows otherwise
* @param string Table to insert into
* @param array An associative array of values to update
* @param mixed An associative array of field and value matches. Will be joined
* with operator specified by $where_join. A custom string can also be provided.
* If nothing is provided, the update will affect all rows.
* @param string When a $where parameter is given, this will work as the glue
* between the fields. "AND" operator will be use by default. Other values might
* be "OR", "AND NOT", "XOR"
*
* @result mixed False in case of error or invalid values passed. Affected rows otherwise
*/
function process_sql_update ($table, $values) {
function process_sql_update ($table, $values, $where = false, $where_join = 'AND') {
$query = sprintf ("UPDATE `%s` SET ", $table);
$i = 0;
$i = 1;
$max = count ($values);
foreach ($values as $field => $value) {
if ($field[0] != "`") {
@ -2433,10 +2399,40 @@ function process_sql_update ($table, $values) {
if ($i < $max) {
$query .= ",";
}
$i++;
}
if ($where) {
$query .= ' WHERE ';
if (is_string ($where)) {
/* FIXME: Should we clean the string for sanity? */
$query .= $where;
} else if (is_array ($where)) {
$i = 1;
$max = count ($where);
foreach ($where as $field => $value) {
if ($field[0] != "`") {
$field = "`".$field."`";
}
if (is_null ($value)) {
$query .= sprintf ("%s IS NULL", $field);
} elseif (is_int ($value) || is_bool ($value)) {
$query .= sprintf ("%s = %d", $field, $value);
} else if (is_float ($value) || is_double ($value)) {
$query .= sprintf ("%s = %f", $field, $value);
} else {
$query .= sprintf ("%s = '%s'", $field, $value);
}
if ($i < $max) {
$query .= $where_join;
}
$i++;
}
}
}
return process_sql ($query);
}
?>

View File

@ -87,9 +87,14 @@ if ($tab != '') {
echo "<h3>".__('Alerts').'</h3>';
if (get_parameter ('alert_validate')) {
$validate = get_parameter_post ("validate", array ());
$result = process_alerts_validate ($validate);
print_error_message ($result, __('Alert(s) validated'), __('Error processing alert(s)'));
$ids = (array) get_parameter_post ("validate", array ());
if (! empty ($ids)) {
require_once ("include/functions_alerts.php");
$result = validate_alert_agent_module ($ids);
print_error_message ($result, __('Alert(s) validated'),
__('Error processing alert(s)'));
}
}
echo '<form method="post" action="'.$url.'">';

View File

@ -140,13 +140,6 @@ if (! give_acl ($config['id_user'], $id_grupo, "AR")) {
return;
}
// Check for validate alert request
$validate_alert = get_parameter ("validate_alert", 0);
if ($validate_alert > 0) {
$result = process_alerts_validate ($validate_alert);
print_error_message ($result, __('Alert(s) validated'), __('Error processing alert(s)'));
}
// Check for Network FLAG change request
if (isset($_GET["flag"])) {
if ($_GET["flag"] == 1 && give_acl ($config['id_user'], $id_grupo, "AW")) {