From 716c90b3185ded649e5b7d040123da4e607faf97 Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Tue, 15 Feb 2011 16:40:23 +0000 Subject: [PATCH] 2011-02-15 Ramon Novoa * pandoradb_data.sql, include/functions_alerts.php, pandoradb.sql, extras/pandoradb_migrate_v3.2_to_v4.0.sql, godmode/alerts/alert_list.list.php, godmode/alerts/alert_list.php, godmode/alerts/configure_alert_action.php, godmode/alerts/alert_actions.php, godmode/alerts/alert_list.builder.php: Added support for action thresholds. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3855 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 8 +++++++ .../extras/pandoradb_migrate_v3.2_to_v4.0.sql | 11 ++++++++++ .../godmode/alerts/alert_actions.php | 12 +++++++--- .../godmode/alerts/alert_list.builder.php | 6 +++-- .../godmode/alerts/alert_list.list.php | 2 ++ pandora_console/godmode/alerts/alert_list.php | 2 ++ .../godmode/alerts/configure_alert_action.php | 22 +++++++++++-------- pandora_console/include/functions_alerts.php | 3 +++ pandora_console/pandoradb.sql | 3 +++ pandora_console/pandoradb_data.sql | 4 ++-- 10 files changed, 57 insertions(+), 16 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 56cc2c81f2..34e7ca7e4d 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2011-02-15 Ramon Novoa + + * pandoradb_data.sql, include/functions_alerts.php, + pandoradb.sql, extras/pandoradb_migrate_v3.2_to_v4.0.sql, + godmode/alerts/alert_list.list.php, godmode/alerts/alert_list.php, + godmode/alerts/configure_alert_action.php, godmode/alerts/alert_actions.php, + godmode/alerts/alert_list.builder.php: Added support for action thresholds. + 2011-02-15 Miguel de Dios * include/functions_alerts.php, operation/agentes/estado_agente.php: added diff --git a/pandora_console/extras/pandoradb_migrate_v3.2_to_v4.0.sql b/pandora_console/extras/pandoradb_migrate_v3.2_to_v4.0.sql index 7b6f28acbb..f024cb355a 100644 --- a/pandora_console/extras/pandoradb_migrate_v3.2_to_v4.0.sql +++ b/pandora_console/extras/pandoradb_migrate_v3.2_to_v4.0.sql @@ -39,3 +39,14 @@ ALTER TABLE treport_content ADD only_display_wrong tinyint(1) unsigned DEFAULT 0 ALTER TABLE `tusuario` ADD COLUMN `block_size` int(4) NOT NULL DEFAULT 20; ALTER TABLE `tusuario` ADD COLUMN `flash_chart` int(4) NOT NULL DEFAULT 1; +-- ----------------------------------------------------- +-- Table `talert_actions` +-- ----------------------------------------------------- +ALTER TABLE `talert_actions` ADD COLUMN `action_threshold` int(10) NOT NULL DEFAULT '0'; + +-- ----------------------------------------------------- +-- Table `talert_template_module_actions` +-- ----------------------------------------------------- +ALTER TABLE `talert_template_module_actions` ADD COLUMN `module_action_threshold` int(10) NOT NULL DEFAULT '0'; +ALTER TABLE `talert_template_module_actions` ADD COLUMN `last_execution` bigint(20) NOT NULL DEFAULT '0'; + diff --git a/pandora_console/godmode/alerts/alert_actions.php b/pandora_console/godmode/alerts/alert_actions.php index a2cc0dad9c..73ce4de072 100644 --- a/pandora_console/godmode/alerts/alert_actions.php +++ b/pandora_console/godmode/alerts/alert_actions.php @@ -92,15 +92,18 @@ if ($create_action) { $field2 = (string) get_parameter ('field2'); $field3 = (string) get_parameter ('field3'); $group = (string) get_parameter ('group'); + $action_threshold = (int) get_parameter ('action_threshold'); $result = create_alert_action ($name, $id_alert_command, array ('field1' => $field1, 'field2' => $field2, 'field3' => $field3, - 'id_group' => $group)); + 'id_group' => $group, + 'action_threshold' => $action_threshold)); $info = 'Name: ' . $name . ' ID alert Command: ' . $id_alert_command . - ' Field1: ' . $field1 . ' Field2: ' . $field2 . ' Field3: ' . $field3 . ' Group: ' . $group; + ' Field1: ' . $field1 . ' Field2: ' . $field2 . ' Field3: ' . $field3 . ' Group: ' . $group . + ' Action threshold: ' . $action_threshold; if ($result) { pandora_audit("Command management", "Create alert action " . $result, false, false, $info); @@ -141,6 +144,7 @@ if ($update_action) { $field2 = (string) get_parameter ('field2'); $field3 = (string) get_parameter ('field3'); $group = get_parameter ('group'); + $action_threshold = (int) get_parameter ('action_threshold'); $values = array (); $values['name'] = $name; @@ -149,11 +153,13 @@ if ($update_action) { $values['field2'] = $field2; $values['field3'] = $field3; $values['id_group'] = $group; + $values['action_threshold'] = $action_threshold; $result = update_alert_action ($id, $values); $info = 'Name: ' . $name . ' ID alert Command: ' . $id_alert_command . - ' Field1: ' . $field1 . ' Field2: ' . $field2 . ' Field3: ' . $field3 . ' Group: ' . $group; + ' Field1: ' . $field1 . ' Field2: ' . $field2 . ' Field3: ' . $field3 . ' Group: ' . $group . + ' Action threshold: ' . $action_threshold; if ($result) { pandora_audit("Command management", "Update alert action " . $id, false, false, json_encode($values)); diff --git a/pandora_console/godmode/alerts/alert_list.builder.php b/pandora_console/godmode/alerts/alert_list.builder.php index 6680ab75c9..baed8c1954 100644 --- a/pandora_console/godmode/alerts/alert_list.builder.php +++ b/pandora_console/godmode/alerts/alert_list.builder.php @@ -32,8 +32,8 @@ $table->head = array (); $table->data = array (); $table->size = array (); $table->size = array (); -$table->size[0] = '10%'; -$table->size[1] = '90%'; +$table->size[0] = '20%'; +$table->size[1] = '80%'; $table->style[0] = 'font-weight: bold; vertical-align: top;'; $table->align[0] = 'left'; $table->align[1] = 'left'; @@ -96,6 +96,8 @@ $table->data[2][1] .= print_image ('images/add.png', true); $table->data[2][1] .= ''; $table->data[2][1] .= __('Create Action'); $table->data[2][1] .= ''; +$table->data[3][0] = __('Threshold'); +$table->data[3][1] = print_input_text ('module_action_threshold', '', '', 4, 10, true) . print_help_icon ('action_threshold', true); echo '
'; diff --git a/pandora_console/godmode/alerts/alert_list.list.php b/pandora_console/godmode/alerts/alert_list.list.php index 924adeeea4..23a5ae4d21 100644 --- a/pandora_console/godmode/alerts/alert_list.list.php +++ b/pandora_console/godmode/alerts/alert_list.list.php @@ -489,6 +489,8 @@ foreach ($simple_alerts as $alert) { $data[6] .= ' '.__('to').' '; $data[6] .= print_input_text ('fires_max', -1, '', 4, 10, true); $data[6] .= print_help_icon ("alert-matches", true); + $data[6] .= '
' . __('Threshold'); + $data[6] .= print_input_text ('module_action_threshold', '', '', 4, 10, true) . print_help_icon ('action_threshold', true); $data[6] .= ''; $data[6] .= '
'; $data[6] .= print_submit_button (__('Add'), 'add_action', false, 'class="sub next"', true); diff --git a/pandora_console/godmode/alerts/alert_list.php b/pandora_console/godmode/alerts/alert_list.php index 9a8adee95b..2a217354ef 100644 --- a/pandora_console/godmode/alerts/alert_list.php +++ b/pandora_console/godmode/alerts/alert_list.php @@ -97,6 +97,7 @@ if ($create_alert) { $values = array(); $values['fires_min'] = get_parameter ('fires_min'); $values['fires_max'] = get_parameter ('fires_max'); + $values['module_action_threshold'] = (int) get_parameter ('module_action_threshold'); add_alert_agent_module_action ($id, $action_select, $values); } @@ -138,6 +139,7 @@ if ($add_action) { $values['fires_min'] = $fires_min; if ($fires_max != -1) $values['fires_max'] = $fires_max; + $values['module_action_threshold'] = (int) get_parameter ('module_action_threshold'); $result = add_alert_agent_module_action ($id_alert_module, $id_action, $values); diff --git a/pandora_console/godmode/alerts/configure_alert_action.php b/pandora_console/godmode/alerts/configure_alert_action.php index 91650fe15f..90fd3245ac 100644 --- a/pandora_console/godmode/alerts/configure_alert_action.php +++ b/pandora_console/godmode/alerts/configure_alert_action.php @@ -55,6 +55,7 @@ $field1 = ''; $field2 = ''; $field3 = ''; $group = 0; //All group is 0 +$action_threshold = 0; //All group is 0 if ($id) { $action = get_alert_action ($id); @@ -64,6 +65,7 @@ if ($id) { $field2 = $action['field2']; $field3 = $action['field3']; $group = $action ['id_group']; + $action_threshold = $action ['action_threshold']; } $table->width = '90%'; @@ -88,18 +90,20 @@ $table->data[2][1] .= print_image ('images/add.png', true); $table->data[2][1] .= ''; $table->data[2][1] .= __('Create Command'); $table->data[2][1] .= ''; +$table->data[3][0] = __('Threshold'); +$table->data[3][1] = print_input_text ('action_threshold', $action_threshold, '', 5, 7, true); +$table->data[3][1] .= ' '.__('seconds') . print_help_icon ('action_threshold', true); +$table->data[4][0] = __('Field 1'); +$table->data[4][1] = print_input_text ('field1', $field1, '', 35, 255, true) . print_help_icon ('alert_macros', true); -$table->data[3][0] = __('Field 1'); -$table->data[3][1] = print_input_text ('field1', $field1, '', 35, 255, true) . print_help_icon ('alert_macros', true); +$table->data[5][0] = __('Field 2'); +$table->data[5][1] = print_input_text ('field2', $field2, '', 80, 255, true); -$table->data[4][0] = __('Field 2'); -$table->data[4][1] = print_input_text ('field2', $field2, '', 80, 255, true); +$table->data[6][0] = __('Field 3'); +$table->data[6][1] = print_textarea ('field3', 10, 30, $field3, '', true); -$table->data[5][0] = __('Field 3'); -$table->data[5][1] = print_textarea ('field3', 10, 30, $field3, '', true); - -$table->data[6][0] = __('Command preview'); -$table->data[6][1] = print_textarea ('command_preview', 10, 30, '', 'disabled="disabled"', true); +$table->data[7][0] = __('Command preview'); +$table->data[7][1] = print_textarea ('command_preview', 10, 30, '', 'disabled="disabled"', true); echo ''; print_table ($table); diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index b810979d0c..38c1c4eff8 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -573,6 +573,7 @@ function add_alert_agent_module_action ($id_alert_template_module, $id_alert_act $values['id_alert_action'] = (int) $id_alert_action; $values['fires_max'] = 0; $values['fires_min'] = 0; + $values['module_action_threshold'] = 0; if ($options) { $max = 0; $min = 0; @@ -580,6 +581,8 @@ function add_alert_agent_module_action ($id_alert_template_module, $id_alert_act $max = (int) $options['fires_max']; if (isset ($options['fires_min'])) $min = (int) $options['fires_min']; + if (isset ($options['module_action_threshold'])) + $values['module_action_threshold'] = (int) $options['module_action_threshold']; $values['fires_max'] = max ($max, $min); $values['fires_min'] = min ($max, $min); diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 54a1724372..117be07ed6 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -237,6 +237,7 @@ CREATE TABLE IF NOT EXISTS `talert_actions` ( `field2` text default '', `field3` text default '', `id_group` mediumint(8) unsigned NULL default 0, + `action_threshold` int(10) NOT NULL default '0', PRIMARY KEY (`id`), FOREIGN KEY (`id_alert_command`) REFERENCES talert_commands(`id`) ON DELETE CASCADE ON UPDATE CASCADE @@ -306,6 +307,8 @@ CREATE TABLE IF NOT EXISTS `talert_template_module_actions` ( `id_alert_action` int(10) unsigned NOT NULL, `fires_min` int(3) unsigned default 0, `fires_max` int(3) unsigned default 0, + `module_action_threshold` int(10) NOT NULL default '0', + `last_execution` bigint(20) NOT NULL default '0', PRIMARY KEY (`id`), FOREIGN KEY (`id_alert_template_module`) REFERENCES talert_template_modules(`id`) ON DELETE CASCADE ON UPDATE CASCADE, diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index f5f24eb8e1..363d5d72c3 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -392,9 +392,9 @@ INSERT INTO `tgis_map_layer` VALUES (1,'Group All',1,0,1,0); INSERT INTO `talert_commands` VALUES (10,'Remote agent control','/usr/share/pandora_server/udp_client.pl _address_ 41122 "_field1_"','This command is used to send commands to the Pandora FMS agents with the UDP server enabled. The UDP server is used to order agents (Windows and UNIX) to "refresh" the agent execution: that means, to force the agent to execute and send data to s',0); -INSERT INTO `talert_actions` VALUES (1,'Mail to XXX',1,'yourmail@domain.es','[PANDORA] Alert from agent _agent_ on module _module_','',0); +INSERT INTO `talert_actions` VALUES (1,'Mail to XXX',1,'yourmail@domain.es','[PANDORA] Alert from agent _agent_ on module _module_','',0,0); -INSERT INTO `talert_actions` VALUES (2,'Restart agent',10,'REFRESH AGENT','','',0); +INSERT INTO `talert_actions` VALUES (2,'Restart agent',10,'REFRESH AGENT','','',0,0); INSERT INTO `talert_templates` VALUES (1,'Critical condition','This is a generic alert template to fire on condition CRITICAL',1,'','','Hello, this is an automated email coming from Pandora FMS\r\n\r\nThis alert has been fired because a CRITICAL condition in one of your monitored items:\r\n\r\nAgent : _agent_\r\nModule: _module_\r\nModule description: _moduledescription_\r\nTimestamp _timestamp_\r\nCurrent value: _data_\r\n\r\nThanks for your time.\r\n\r\nBest regards\r\nPandora FMS\r\n','critical','',1,0.00,0.00,86400,1,0,'12:00:00','12:00:00',1,1,1,1,1,1,1,1,'[PANDORA] Alert RECOVERED for CRITICAL status on _agent_ / _module_','Hello, this is an automated email coming from Pandora FMS\r\n\r\nThis alert has been RECOVERED from a CRITICAL condition in one of your monitored items:\r\n\r\nAgent : _agent_\r\nModule: _module_\r\nModule description: _moduledescription_\r\nTimestamp _timestamp_\r\nCurrent value: _data_\r\n\r\nThanks for your time.\r\n\r\nBest regards\r\nPandora FMS\r\n',4,0);