2009-03-24 Esteban Sanchez <estebans@artica.es>

* godmode/alerts/configure_alert_compound.php: Fixed clean up div for
	variable width styles. Min and max fire values commented because it's
	not implemented yet.

	* include/config_process.php: Keep database connection resource in
	config.

	* include/functions.php: Use mysql_real_escape_string(), replacing
	deprecated function.

	* include/functions_alerts.php: Updated to use process_sql_*
	functions. Many fixes done such as updating a template name or
	escaping the value when duplicating a template.

	* include/functions_ui.php: Fixed an error on refresh header when
	using other web servers like Cherokee.

	* operation/agentes/estado_agente.php: Style corrections.

	* reporting/fgraph.php: Fixed a typo on grafico_db_agentes_paquetes().

	* pandora_db.sql, extras/pandoradb_migrate_v2.x_to_v3.0.sql: Added
	foreign key on treport_content and id field on
	talert_compound_actions.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1555 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
esanchezm 2009-03-24 10:22:37 +00:00
parent 7634e45a55
commit ba1ebc842a
10 changed files with 176 additions and 166 deletions

View File

@ -1,3 +1,30 @@
2009-03-24 Esteban Sanchez <estebans@artica.es>
* godmode/alerts/configure_alert_compound.php: Fixed clean up div for
variable width styles. Min and max fire values commented because it's
not implemented yet.
* include/config_process.php: Keep database connection resource in
config.
* include/functions.php: Use mysql_real_escape_string(), replacing
deprecated function.
* include/functions_alerts.php: Updated to use process_sql_*
functions. Many fixes done such as updating a template name or
escaping the value when duplicating a template.
* include/functions_ui.php: Fixed an error on refresh header when
using other web servers like Cherokee.
* operation/agentes/estado_agente.php: Style corrections.
* reporting/fgraph.php: Fixed a typo on grafico_db_agentes_paquetes().
* pandoradb.sql, extras/pandoradb_migrate_v2.x_to_v3.0.sql: Added
foreign key on treport_content and id field on
talert_compound_actions.
2009-03-24 Sancho Lerena <slerena@gmail.com> 2009-03-24 Sancho Lerena <slerena@gmail.com>
* module_manager_editor.php, * module_manager_editor.php,

View File

@ -33,6 +33,9 @@ ALTER TABLE `tagente_modulo` DROP INDEX `tam_plugin`;
ALTER TABLE `tagente_modulo` DROP PRIMARY KEY , ADD PRIMARY KEY ALTER TABLE `tagente_modulo` DROP PRIMARY KEY , ADD PRIMARY KEY
( `id_agente_modulo` ); ( `id_agente_modulo` );
ALTER TABLE `treport_content` ADD FOREIGN KEY (`id_report`) REFERENCES treport(`id_report`)
ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE `tagent_access` DROP `timestamp`; ALTER TABLE `tagent_access` DROP `timestamp`;
ALTER TABLE `tlayout_data` ADD `id_agent` int(10) unsigned NOT NULL default 0; ALTER TABLE `tlayout_data` ADD `id_agent` int(10) unsigned NOT NULL default 0;
@ -241,10 +244,12 @@ CREATE TABLE IF NOT EXISTS `talert_compound_elements` (
DROP TABLE IF EXISTS talert_compound_actions; DROP TABLE IF EXISTS talert_compound_actions;
CREATE TABLE IF NOT EXISTS `talert_compound_actions` ( CREATE TABLE IF NOT EXISTS `talert_compound_actions` (
`id` int(10) unsigned NOT NULL auto_increment,
`id_alert_compound` int(10) unsigned NOT NULL, `id_alert_compound` int(10) unsigned NOT NULL,
`id_alert_action` int(10) unsigned NOT NULL, `id_alert_action` int(10) unsigned NOT NULL,
`fires_min` int(3) unsigned default 0, `fires_min` int(3) unsigned default 0,
`fires_max` int(3) unsigned default 0, `fires_max` int(3) unsigned default 0,
PRIMARY KEY (`id`),
FOREIGN KEY (`id_alert_compound`) REFERENCES talert_compound(`id`) FOREIGN KEY (`id_alert_compound`) REFERENCES talert_compound(`id`)
ON DELETE CASCADE ON UPDATE CASCADE, ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`id_alert_action`) REFERENCES talert_actions(`id`) FOREIGN KEY (`id_alert_action`) REFERENCES talert_actions(`id`)

View File

@ -89,7 +89,7 @@ function print_alert_compound_steps ($step, $id) {
} }
echo '</ol>'; echo '</ol>';
echo '<div style="clear: both;"> </div>'; echo '<div class="steps_clean"> </div>';
} }
function update_compound ($step) { function update_compound ($step) {
@ -155,6 +155,7 @@ function update_compound ($step) {
/* Update actions */ /* Update actions */
$actions = (array) get_parameter ('actions'); $actions = (array) get_parameter ('actions');
foreach ($actions as $id_action) { foreach ($actions as $id_action) {
/* TODO: fires_min and fires_max missing */ /* TODO: fires_min and fires_max missing */
add_alert_compound_action ($id, (int) $id_action); add_alert_compound_action ($id, (int) $id_action);
@ -352,7 +353,8 @@ if ($step == 2) {
$table->data[4][1] .= print_button (__('Add'), 'add_action', false, '', $table->data[4][1] .= print_button (__('Add'), 'add_action', false, '',
'class="sub next"', true); 'class="sub next"', true);
$table->data[4][1] .= '<br />'; $table->data[4][1] .= '<br />';
$table->data[4][1] .= '<span><a href="#" class="show_advanced_actions">'.__('Advanced options').' &raquo; </a></span>'; /* TODO: Finish fires_max and fires_min support */
/* $table->data[4][1] .= '<span><a href="" class="show_advanced_actions">'.__('Advanced options').' &raquo; </a></span>';
$table->data[4][1] .= '<span class="advanced_actions invisible">'; $table->data[4][1] .= '<span class="advanced_actions invisible">';
$table->data[4][1] .= __('From').' '; $table->data[4][1] .= __('From').' ';
$table->data[4][1] .= print_input_text ('fires_min', 0, '', 4, 10, true); $table->data[4][1] .= print_input_text ('fires_min', 0, '', 4, 10, true);
@ -361,7 +363,7 @@ if ($step == 2) {
$table->data[4][1] .= ' '.__('matches of the alert'); $table->data[4][1] .= ' '.__('matches of the alert');
$table->data[4][1] .= pandora_help("alert-matches", true); $table->data[4][1] .= pandora_help("alert-matches", true);
$table->data[4][1] .= '</span>'; $table->data[4][1] .= '</span>';
*/
$table->data['actions'][0] = __('Assigned actions'); $table->data['actions'][0] = __('Assigned actions');
$table->data['actions'][1] = '<ul id="alert_actions">'; $table->data['actions'][1] = '<ul id="alert_actions">';
if ($id) { if ($id) {

View File

@ -34,9 +34,9 @@ $config['fontpath'] = $config['homedir'].'/reporting/FreeSans.ttf';
// Style (pandora by default) // Style (pandora by default)
$config['style'] = 'pandora'; $config['style'] = 'pandora';
// Read remaining config tokens from DB //Non-persistent connection. If you want persistent conn change it to mysql_pconnect()
if (! mysql_connect ($config["dbhost"], $config["dbuser"], $config["dbpass"])) { $config['dbconnection'] = mysql_connect ($config["dbhost"], $config["dbuser"], $config["dbpass"]);
//Non-persistent connection. If you want persistent conn change it to mysql_pconnect() if (! $config['dbconnection']) {
exit ('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> exit ('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Pandora FMS Error</title> <html xmlns="http://www.w3.org/1999/xhtml"><head><title>Pandora FMS Error</title>
<link rel="stylesheet" href="./include/styles/pandora.css" type="text/css"> <link rel="stylesheet" href="./include/styles/pandora.css" type="text/css">

View File

@ -946,7 +946,9 @@ function unsafe_string ($string) {
function safe_sql_string ($string) { function safe_sql_string ($string) {
if (get_magic_quotes_gpc () == 0) if (get_magic_quotes_gpc () == 0)
return $string; return $string;
return mysql_escape_string ($string); global $config;
return mysql_real_escape_string ($string, $config['dbconnection']);
} }
/** /**

View File

@ -289,6 +289,8 @@ function clean_alert_template_values ($values, $set_empty = true) {
if (empty ($values)) if (empty ($values))
return $retvalues; return $retvalues;
if (isset ($values['name']))
$retvalues['name'] = (string) $values['name'];
if (isset ($values['type'])) if (isset ($values['type']))
$retvalues['type'] = (string) $values['type']; $retvalues['type'] = (string) $values['type'];
if (isset ($values['description'])) if (isset ($values['description']))
@ -359,23 +361,14 @@ function create_alert_template ($name, $type, $values = false) {
return false; return false;
$values = clean_alert_template_values ($values); $values = clean_alert_template_values ($values);
$values['name'] = $name;
$values['type'] = $type;
switch ($type) { switch ($type) {
/* TODO: Check values based on type, return false if failure */ /* TODO: Check values based on type, return false if failure */
} }
$sql = sprintf ('INSERT talert_templates (name, type, description, return @process_sql_insert ('talert_templates', $values);
field1, field2, field3, value, max_value, min_value,
time_threshold, max_alerts, min_alerts, matches_value)
VALUES ("%s", "%s", "%s", "%s", "%s", "%s", "%s", %.2f,
%.2f, %d, %d, %d, %d)',
$name, $type, $values['description'], $values['field1'],
$values['field2'], $values['field3'], $values['value'],
$values['max_value'], $values['min_value'],
$values['time_threshold'], $values['max_alerts'],
$values['min_alerts'], $values['matches_value']);
return @process_sql ($sql, 'insert_id');
} }
function update_alert_template ($id_alert_template, $values = false) { function update_alert_template ($id_alert_template, $values = false) {
@ -385,12 +378,9 @@ function update_alert_template ($id_alert_template, $values = false) {
$values = clean_alert_template_values ($values, false); $values = clean_alert_template_values ($values, false);
$sql = sprintf ('UPDATE talert_templates return (@process_sql_update ('talert_templates',
SET %s $values,
WHERE id = %d', array ('id' => $id_alert_template))) !== false;
format_array_to_update_sql ($values), $id_alert_template);
return @process_sql ($sql) !== false;
} }
function delete_alert_template ($id_alert_template) { function delete_alert_template ($id_alert_template) {
@ -398,9 +388,7 @@ function delete_alert_template ($id_alert_template) {
if (empty ($id_alert_template)) if (empty ($id_alert_template))
return false; return false;
$sql = sprintf ('DELETE FROM talert_templates WHERE id = %d', return @process_sql_delete ('talert_templates', array ('id' => $id_alert_template));
$id_alert_template);
return @process_sql ($sql);
} }
function get_alert_templates ($only_names = true) { function get_alert_templates ($only_names = true) {
@ -537,6 +525,7 @@ function duplicate_alert_template ($id_alert_template) {
unset ($template['name']); unset ($template['name']);
unset ($template['id']); unset ($template['id']);
unset ($template['type']); unset ($template['type']);
$template['value'] = safe_sql_string ($template['value']);
return create_alert_template ($name, $type, $template); return create_alert_template ($name, $type, $template);
} }
@ -579,17 +568,11 @@ function create_alert_agent_module ($id_agent_module, $id_alert_template, $value
return false; return false;
$values = clean_alert_agent_module_values ($values); $values = clean_alert_agent_module_values ($values);
$values['id_agent_module'] = $id_agent_module;
$sql = sprintf ('INSERT talert_template_modules (id_agent_module, $values['id_alert_template'] = $id_alert_template;
id_alert_template, internal_counter, last_fired, times_fired, return @process_sql_insert ('talert_template_modules',
disabled, priority, force_execution) $values,
VALUES (%d, %d, %d, %d, %d, %d, %d, %d)', array ('id' => $id_alert_template));
$id_agent_module, $id_alert_template,
$values['internal_counter'], $values['last_fired'],
$values['times_fired'], $values['disabled'], $values['priority'],
$values['force_execution']);
return @process_sql ($sql, 'insert_id');
} }
function update_alert_agent_module ($id_alert_agent_module, $values = false) { function update_alert_agent_module ($id_alert_agent_module, $values = false) {
@ -600,23 +583,17 @@ function update_alert_agent_module ($id_alert_agent_module, $values = false) {
if ($empty ($values)) if ($empty ($values))
return true; return true;
$sql = sprintf ('UPDATE talert_template_modules return (@process_sql_update ('talert_template_modules',
SET %s $values,
WHERE id = %d', array ('id' => $id_alert_template))) !== false;
format_array_to_update_sql ($values), $id_alert_agent_module);
return @process_sql ($sql) !== false;
} }
function delete_alert_agent_module ($id_alert_agent_module) { function delete_alert_agent_module ($id_alert_agent_module) {
if (empty ($id_alert_agent_module)) if (empty ($id_alert_agent_module))
return false; return false;
$sql = sprintf ('DELETE FROM talert_template_modules return (@process_sql_delete ('talert_template_modules',
WHERE id = %d', array ('id' => $id_alert_agent_module))) !== false;
$id_alert_agent_module);
return @process_sql ($sql) !== false;
} }
function get_alert_agent_module ($id_alert_agent_module) { function get_alert_agent_module ($id_alert_agent_module) {
@ -627,22 +604,17 @@ function get_alert_agent_module ($id_alert_agent_module) {
return get_db_row ('talert_template_modules', 'id', $id_alert_agent_module); return get_db_row ('talert_template_modules', 'id', $id_alert_agent_module);
} }
function get_alerts_agent_module ($id_agent_module, $disabled = false, $filter = false) { function get_alerts_agent_module ($id_agent_module, $disabled = false, $filter = false, $fields = false) {
$id_alert_agent_module = safe_int ($id_agent_module, 0); $id_alert_agent_module = safe_int ($id_agent_module, 0);
$where = ''; if (! is_array ($filter))
$filter = array ();
if (! $disabled) if (! $disabled)
$where .= ' AND disabled = 0 '; $filter['disabled'] = 0;
$filter['id_agent_module'] = $id_agent_module;
if ($filter) { return get_db_all_rows_filter ('talert_template_modules',
$where .= format_array_to_where_clause_sql ($filter, 'AND', ' AND '); $filter, $fields);
}
$sql = sprintf ('SELECT * FROM talert_template_modules
WHERE id_agent_module = %d %s',
$id_agent_module, $where);
return get_db_all_rows_sql ($sql);
} }
function get_alert_agent_module_disabled ($id_alert_agent_module) { function get_alert_agent_module_disabled ($id_alert_agent_module) {
@ -653,22 +625,16 @@ function get_alert_agent_module_disabled ($id_alert_agent_module) {
function set_alerts_agent_module_force_execution ($id_alert_agent_module) { function set_alerts_agent_module_force_execution ($id_alert_agent_module) {
$id_alert_agent_module = safe_int ($id_alert_agent_module, 0); $id_alert_agent_module = safe_int ($id_alert_agent_module, 0);
$sql = sprintf ('UPDATE talert_template_modules return (@process_sql_update ('talert_template_modules',
SET force_execution = 1 array ('force_execution' => 1),
WHERE id = %d', array ('id' => $id_alert_agent_module))) !== false;
$id_alert_agent_module);
return @process_sql ($sql) !== false;
} }
function set_alerts_agent_module_disable ($id_alert_agent_module, $disabled) { function set_alerts_agent_module_disable ($id_alert_agent_module, $disabled) {
$id_alert_agent_module = safe_int ($id_alert_agent_module, 0); $id_alert_agent_module = safe_int ($id_alert_agent_module, 0);
$sql = sprintf ('UPDATE talert_template_modules return (@process_sql_update ('talert_template_modules',
SET disabled = %d array ('disabled' => (bool) $disabled),
WHERE id = %d', array ('id' => $id_alert_agent_module))) !== false;
$disabled ? 1 : 0, $id_alert_agent_module);
return @process_sql ($sql) !== false;
} }
function get_alerts_agent_module_last_fired ($id_alert_agent_module) { function get_alerts_agent_module_last_fired ($id_alert_agent_module) {
@ -677,14 +643,17 @@ function get_alerts_agent_module_last_fired ($id_alert_agent_module) {
$id_alert_agent_module); $id_alert_agent_module);
} }
function add_alert_agent_module_action ($id_alert_agent_module, $id_alert_action, $options = false) { function add_alert_agent_module_action ($id_alert_template_module, $id_alert_action, $options = false) {
if (empty ($id_alert_agent_module)) if (empty ($id_alert_template_module))
return false; return false;
if (empty ($id_alert_action)) if (empty ($id_alert_action))
return false; return false;
$fires_max = 0; $values = array ();
$fires_min = 0; $values['id_alert_template_module'] = $id_alert_template_module;
$values['id_alert_action'] = $id_alert_action;
$values['fires_max'] = 0;
$values['fires_min'] = 0;
if ($options) { if ($options) {
$max = 0; $max = 0;
$min = 0; $min = 0;
@ -693,40 +662,32 @@ function add_alert_agent_module_action ($id_alert_agent_module, $id_alert_action
if (isset ($options['fires_min'])) if (isset ($options['fires_min']))
$min = (int) $options['fires_min']; $min = (int) $options['fires_min'];
$fires_max = max ($max, $min); $values['fires_max'] = max ($max, $min);
$fires_min = min ($max, $min); $values['fires_min'] = min ($max, $min);
} }
$sql = sprintf ('INSERT INTO talert_template_module_actions return (@process_sql_insert ('talert_template_module_actions', $values)) !== false;
(id_alert_template_module, id_alert_action, fires_min, fires_max)
VALUES (%d, %d, %d, %d)',
$id_alert_agent_module, $id_alert_action, $fires_min, $fires_max);
return process_sql ($sql, 'insert_id');
} }
function delete_alert_agent_module_action ($id_alert_agent_module_action) { function delete_alert_agent_module_action ($id_alert_agent_module_action) {
if (empty ($id_alert_agent_module_action)) if (empty ($id_alert_agent_module_action))
return false; return false;
$sql = sprintf ('DELETE FROM talert_template_module_actions return (@process_sql_delete ('talert_template_module_actions',
WHERE id = %d', array ('id' => $id_alert_agent_module_action))) !== false;
$id_alert_agent_module_action);
return process_sql ($sql) !== false;
} }
function get_alert_agent_module_actions ($id_alert_agent_module) { function get_alert_agent_module_actions ($id_alert_agent_module, $fields = false) {
if (empty ($id_alert_agent_module)) if (empty ($id_alert_agent_module))
return false; return false;
$sql = sprintf ('SELECT id, id_alert_action, fires_min, fires_max $actions = get_db_all_rows_filter ('talert_template_module_actions',
FROM talert_template_module_actions array ('id_alert_template_module' => $id_alert_agent_module),
WHERE id_alert_template_module = %d', $fields);
$id_alert_agent_module);
$actions = get_db_all_rows_sql ($sql);
if ($actions === false) if ($actions === false)
return array (); return array ();
if ($fields !== false)
return $actions;
$retval = array (); $retval = array ();
foreach ($actions as $element) { foreach ($actions as $element) {
@ -936,24 +897,26 @@ function create_alert_compound ($name, $id_agent, $values = false) {
} }
function update_alert_compound ($id_alert_compound, $values = false) { function update_alert_compound ($id_alert_compound, $values = false) {
$id_alert_compound = safe_int ($id_alert_compound);
if (empty ($id_alert_compound)) if (empty ($id_alert_compound))
return false; return false;
$values = clean_alert_compound_values ($values, false); $values = clean_alert_compound_values ($values, false);
return @process_sql_update ('talert_compound', $values, return (@process_sql_update ('talert_compound', $values,
array ('id' => $id_alert_compound)) !== false; array ('id' => $id_alert_compound))) !== false;
} }
function delete_alert_compound_elements ($id_alert_compound) { function delete_alert_compound_elements ($id_alert_compound) {
$id_alert_compound = safe_int ($id_alert_compound);
if (empty ($id_alert_compound)) if (empty ($id_alert_compound))
return false; return false;
$sql = sprintf ('DELETE FROM talert_compound_elements return (@process_sql_delete ('talert_compound_elements',
WHERE id_alert_compound = %d', $id_alert_compound); array ('id_alert_compound' => $id_alert_compound))) !== false;
return @process_sql ($sql);
} }
function add_alert_compound_element ($id_alert_compound, $id_alert_template_module, $operation) { function add_alert_compound_element ($id_alert_compound, $id_alert_template_module, $operation) {
$id_alert_compound = safe_int ($id_alert_compound);
if (empty ($id_alert_compound)) if (empty ($id_alert_compound))
return false; return false;
if (empty ($id_alert_template_module)) if (empty ($id_alert_template_module))
@ -973,31 +936,32 @@ function get_alert_compound ($id_alert_compound) {
return get_db_row ('talert_compound', 'id', $id_alert_compound); return get_db_row ('talert_compound', 'id', $id_alert_compound);
} }
function get_alert_compound_actions ($id_alert_compound) { function get_alert_compound_actions ($id_alert_compound, $fields = false) {
$id_alert_compound = safe_int ($id_alert_compound);
if (empty ($id_alert_compound)) if (empty ($id_alert_compound))
return false; return false;
$sql = sprintf ('SELECT id_alert_action id, fires_min, fires_max $actions = get_db_all_rows_filter ('talert_compound_actions',
FROM talert_compound_actions array ('id_alert_compound' => $id_alert_compound),
WHERE id_alert_compound = %d', $fields);
$id_alert_compound);
$actions = get_db_all_rows_sql ($sql);
if ($actions === false) if ($actions === false)
return array (); return array ();
if ($fields !== false)
return $actions;
$retval = array (); $retval = array ();
foreach ($actions as $element) { foreach ($actions as $element) {
$action = get_alert_action ($element['id']); $action = get_alert_action ($element['id_alert_action']);
$action['fires_min'] = $element['fires_min']; $action['fires_min'] = $element['fires_min'];
$action['fires_max'] = $element['fires_max']; $action['fires_max'] = $element['fires_max'];
array_push ($retval, $action); $retval[$element['id']] = $action;
} }
return $retval; return $retval;
} }
function get_alert_compound_name ($id_alert_compound) { function get_alert_compound_name ($id_alert_compound) {
return (string) get_db_value ('name', 'talert_compund', 'id', $id_alert_compound); return (string) get_db_value ('name', 'talert_compound', 'id', $id_alert_compound);
} }
function get_alert_compound_elements ($id_alert_compound) { function get_alert_compound_elements ($id_alert_compound) {
@ -1011,8 +975,11 @@ function add_alert_compound_action ($id_alert_compound, $id_alert_action, $optio
if (empty ($id_alert_action)) if (empty ($id_alert_action))
return false; return false;
$fires_max = 0; $values = array ();
$fires_min = 0; $values['id_alert_compound'] = $id_alert_compound;
$values['id_alert_action'] = $id_alert_action;
$values['fires_max'] = 0;
$values['fires_min'] = 0;
if ($options) { if ($options) {
$max = 0; $max = 0;
$min = 0; $min = 0;
@ -1021,25 +988,18 @@ function add_alert_compound_action ($id_alert_compound, $id_alert_action, $optio
if (isset ($options['fires_min'])) if (isset ($options['fires_min']))
$min = (int) $options['fires_min']; $min = (int) $options['fires_min'];
$fires_max = max ($max, $min); $values['fires_max'] = max ($max, $min);
$fires_min = min ($max, $min); $values['fires_min'] = min ($max, $min);
} }
$sql = sprintf ('INSERT INTO talert_compound_actions return (@process_sql_insert ('talert_compound_actions', $values)) !== false;
VALUES (%d, %d, %d, %d)',
$id_alert_compound, $id_alert_action, $fires_min, $fires_max);
return @process_sql ($sql) !== false;
} }
function set_alerts_compound_disable ($id_alert_compound, $disabled) { function set_alerts_compound_disable ($id_alert_compound, $disabled) {
$id_alert_agent_module = safe_int ($id_alert_compound, 0); $id_alert_agent_module = safe_int ($id_alert_compound, 0);
$sql = sprintf ('UPDATE talert_compound return (@process_sql_update ('talert_compound',
SET disabled = %d array ('disabled' => (bool) $disabled),
WHERE id = %d', array ('id' => $id_alert_compound))) !== false;
$disabled ? 1 : 0, $id_alert_compound);
return @process_sql ($sql) !== false;
} }
/** /**
@ -1092,9 +1052,7 @@ function delete_alert_compound ($id_alert_compound) {
$id_alert_compound = safe_int ($id_alert_compound, 1); $id_alert_compound = safe_int ($id_alert_compound, 1);
if (empty ($id_alert_compound)) if (empty ($id_alert_compound))
return false; return false;
return (@process_sql_delete ('talert_compound',
$sql = sprintf ('DELETE FROM talert_compound WHERE id = %d', array ('id' => $id_alert_compound))) !== false;
$id_alert_compound);
return @process_sql ($sql);
} }
?> ?>

View File

@ -537,9 +537,20 @@ function process_page_head ($string, $bitfield) {
if ($config["refr"] > 0) { if ($config["refr"] > 0) {
// Agent selection filters and refresh // Agent selection filters and refresh
$query = 'http' . (isset ($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == TRUE ? 's': '') . '://' . $_SERVER['SERVER_NAME']; $protocol = 'http';
if ($_SERVER['SERVER_PORT'] != 80 && (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == TRUE && $_SERVER['SERVER_PORT'] != 443)) { $ssl = false;
$query .= ":" . $_SERVER['SERVER_PORT']; if ($config['https']) {
/* Check with "on" because some web servers like Cherokee always
set this value even if SSL is not enabled */
if (isset ($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == true || $_SERVER['HTTPS'] == 'on')) {
$protocol = 'https';
$ssl = true;
}
}
$query = $protocol.'://' . $_SERVER['SERVER_NAME'];
if ($_SERVER['SERVER_PORT'] != 80 && ($ssl && $_SERVER['SERVER_PORT'] != 443)) {
$query .= ":".$_SERVER['SERVER_PORT'];
} }
$query .= $_SERVER['SCRIPT_NAME']; $query .= $_SERVER['SCRIPT_NAME'];

View File

@ -101,9 +101,9 @@ if ($search != ""){
// Show only selected groups // Show only selected groups
if ($ag_group > 1){ if ($ag_group > 1){
$sql="SELECT * FROM tagente WHERE id_grupo=$ag_group $sql="SELECT * FROM tagente WHERE id_grupo=$ag_group
AND disabled = 0 $search_sql ORDER BY nombre LIMIT $offset, ".$config["block_size"]; AND disabled = 0 $search_sql ORDER BY nombre LIMIT $offset, ".$config["block_size"];
$sql2="SELECT COUNT(id_agente) FROM tagente WHERE id_grupo=$ag_group $sql2="SELECT COUNT(id_agente) FROM tagente WHERE id_grupo=$ag_group
AND disabled = 0 $search_sql ORDER BY nombre"; AND disabled = 0 $search_sql ORDER BY nombre";
// Not selected any specific group // Not selected any specific group
} else { } else {
// Is admin user ?? // Is admin user ??
@ -118,31 +118,31 @@ if ($ag_group > 1){
if ($all_group > 0) { if ($all_group > 0) {
$sql = sprintf ("SELECT * FROM tagente $sql = sprintf ("SELECT * FROM tagente
WHERE disabled = 0 %s WHERE disabled = 0 %s
ORDER BY nombre, id_grupo LIMIT %d,%d", ORDER BY nombre, id_grupo LIMIT %d,%d",
$search_sql, $offset, $search_sql, $offset,
$config["block_size"]); $config["block_size"]);
$sql2 = sprintf ("SELECT COUNT(id_agente) $sql2 = sprintf ("SELECT COUNT(id_agente)
FROM tagente WHERE disabled = 0 %s FROM tagente WHERE disabled = 0 %s
ORDER BY nombre, id_grupo", ORDER BY nombre, id_grupo",
$search_sql); $search_sql);
} else { } else {
$sql = sprintf ("SELECT * FROM tagente $sql = sprintf ("SELECT * FROM tagente
WHERE disabled = 0 %s WHERE disabled = 0 %s
AND id_grupo IN (SELECT id_grupo AND id_grupo IN (SELECT id_grupo
FROM tusuario_perfil FROM tusuario_perfil
WHERE id_usuario='%s') WHERE id_usuario='%s')
ORDER BY nombre, id_grupo LIMIT %d,%d", ORDER BY nombre, id_grupo LIMIT %d,%d",
$search_sql, $config['id_user'], $offset, $search_sql, $config['id_user'], $offset,
$config["block_size"]); $config["block_size"]);
$sql2 = sprintf ("SELECT COUNT(id_agente) $sql2 = sprintf ("SELECT COUNT(id_agente)
FROM tagente FROM tagente
WHERE disabled = 0 %s WHERE disabled = 0 %s
AND id_grupo IN (SELECT id_grupo AND id_grupo IN (SELECT id_grupo
FROM tusuario_perfil FROM tusuario_perfil
WHERE id_usuario='%s') WHERE id_usuario='%s')
ORDER BY nombre, id_grupo", ORDER BY nombre, id_grupo",
$search_sql, $config['id_user']); $search_sql, $config['id_user']);
} }
} }
@ -181,14 +181,15 @@ if ($agents !== false) {
$id_os = $agent["id_os"]; $id_os = $agent["id_os"];
$ultimo_contacto = $agent["ultimo_contacto"]; $ultimo_contacto = $agent["ultimo_contacto"];
$biginterval = $intervalo; $biginterval = $intervalo;
$pertenece = 0; $belongs = false;
foreach ($groups as $migrupo) { //Verifiy if the group this agent begins is one of the user groups //Verifiy if the group this agent begins is one of the user groups
foreach ($groups as $migrupo) {
if ($migrupo || $id_grupo == $migrupo) { if ($migrupo || $id_grupo == $migrupo) {
$pertenece = 1; $belongs = true;
break; break;
} }
} }
if (! $pertenece == 1) if (! $belongs)
continue; continue;
// Obtenemos la lista de todos los modulos de cada agente // Obtenemos la lista de todos los modulos de cada agente
@ -231,7 +232,7 @@ if ($agents !== false) {
$async = 1; $async = 1;
} }
// Defines if Agent is down (interval x 2 > time last contact // Defines if Agent is down (interval x 2 > time last contact
if (($seconds >= ($intervalo_comp * 2)) AND ($module_type < 21)) { // If (intervalx2) secs. ago we don't get anything, show alert if (($seconds >= ($intervalo_comp * 2)) && ($module_type < 21)) { // If (intervalx2) secs. ago we don't get anything, show alert
$agent_down = 1; $agent_down = 1;
if ($async == 0) if ($async == 0)
$monitor_down++; $monitor_down++;
@ -302,7 +303,7 @@ if ($agents !== false) {
if ($numero_modulos > 0){ if ($numero_modulos > 0){
if ($agent_down > 0) { if ($agent_down > 0) {
echo '<img src="images/pixel_fucsia.png" width="40" height="18" title="'.__('Agent down').'" />'; echo '<img src="images/pixel_fucsia.png" width="40" height="18" title="'.__('Agent down').'" />';
} elseif ($monitor_critical > 0){ } elseif ($monitor_critical > 0) {
echo '<img src="images/pixel_red.png" width="40" height="18" title="'.__('At least one module in CRITICAL status').'" />'; echo '<img src="images/pixel_red.png" width="40" height="18" title="'.__('At least one module in CRITICAL status').'" />';
} elseif ($monitor_warning > 0) { } elseif ($monitor_warning > 0) {
echo '<img src="images/pixel_yellow.png" width="40" height="18" title="'.__('At least one module in WARNING status').'" />'; echo '<img src="images/pixel_yellow.png" width="40" height="18" title="'.__('At least one module in WARNING status').'" />';
@ -310,7 +311,7 @@ if ($agents !== false) {
echo '<img src="images/pixel_green.png" width="40" height="18" title="'.__('All Monitors OK').'" />'; echo '<img src="images/pixel_green.png" width="40" height="18" title="'.__('All Monitors OK').'" />';
} }
} else { } else {
echo '<img src="images/pixel_blue.png" width="40" height="18" title="'.__('Agent without data').'" />'; echo '<img src="images/pixel_blue.png" width="40" height="18" title="'.__('Agent without data').'" />';
} }
// checks if an alert was fired recently // checks if an alert was fired recently

View File

@ -330,10 +330,12 @@ CREATE TABLE IF NOT EXISTS `talert_compound_elements` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `talert_compound_actions` ( CREATE TABLE IF NOT EXISTS `talert_compound_actions` (
`id` int(10) unsigned NOT NULL auto_increment,
`id_alert_compound` int(10) unsigned NOT NULL, `id_alert_compound` int(10) unsigned NOT NULL,
`id_alert_action` int(10) unsigned NOT NULL, `id_alert_action` int(10) unsigned NOT NULL,
`fires_min` int(3) unsigned default 0, `fires_min` int(3) unsigned default 0,
`fires_max` int(3) unsigned default 0, `fires_max` int(3) unsigned default 0,
PRIMARY KEY (`id`),
FOREIGN KEY (`id_alert_compound`) REFERENCES talert_compound(`id`) FOREIGN KEY (`id_alert_compound`) REFERENCES talert_compound(`id`)
ON DELETE CASCADE ON UPDATE CASCADE, ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`id_alert_action`) REFERENCES talert_actions(`id`) FOREIGN KEY (`id_alert_action`) REFERENCES talert_actions(`id`)
@ -705,7 +707,9 @@ CREATE TABLE IF NOT EXISTS `treport_content` (
`order` int (11) NOT NULL default 0, `order` int (11) NOT NULL default 0,
`description` mediumtext, `description` mediumtext,
`id_agent` int(10) unsigned NOT NULL default 0, `id_agent` int(10) unsigned NOT NULL default 0,
PRIMARY KEY(`id_rc`) PRIMARY KEY(`id_rc`),
FOREIGN KEY (`id_report`) REFERENCES treport(`id_report`)
ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE = InnoDB DEFAULT CHARSET=utf8; ) ENGINE = InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `treport_content_sla_combined` ( CREATE TABLE IF NOT EXISTS `treport_content_sla_combined` (

View File

@ -817,7 +817,7 @@ function grafico_db_agentes_paquetes ($width = 380, $height = 300) {
$count = get_agent_modules_data_count (array_keys ($agents)); $count = get_agent_modules_data_count (array_keys ($agents));
unset ($count["total"]); unset ($count["total"]);
arsort ($count, SORT_NUMERIC); arsort ($count, SORT_NUMERIC);
$count = array_slice ($count, 10, 10, true); $count = array_slice ($count, 0, 10, true);
foreach ($count as $agent_id => $value) { foreach ($count as $agent_id => $value) {
$data[$agents[$agent_id]] = $value; $data[$agents[$agent_id]] = $value;