2012-01-25 Junichi Satoh <junichi@rworks.jp>

* godmode/menu.php, godmode/alerts/alert_special_days.php,
	godmode/alerts/configure_alert_special_days.php,
	godmode/alerts/configure_alert_template.php,
	extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql,
	extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql,
	extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql,
	pandoradb.oracle.sql, pandoradb.postgreSQL.sql, pandoradb.sql,
	include/functions_alerts.php: Added special days feature. It allows
	to define special days (holidays and special working days) for 
	alert templates.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5421 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
jsatoh 2012-01-25 06:13:43 +00:00
parent 05e87ef279
commit 7238782cda
12 changed files with 495 additions and 3 deletions

View File

@ -1,3 +1,16 @@
2012-01-25 Junichi Satoh <junichi@rworks.jp>
* godmode/menu.php, godmode/alerts/alert_special_days.php,
godmode/alerts/configure_alert_special_days.php,
godmode/alerts/configure_alert_template.php,
extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql,
extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql,
extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql,
pandoradb.oracle.sql, pandoradb.postgreSQL.sql, pandoradb.sql,
include/functions_alerts.php: Added special days feature. It allows
to define special days (holidays and special working days) for
alert templates.
2012-01-24 Juan Manuel Ramon <juanmanuel.ramon@artica.es>
* operation/incidents/incident.php

View File

@ -47,7 +47,7 @@ CREATE TABLE IF NOT EXISTS `tnetflow_report_content` (
ON DELETE CASCADE,
FOREIGN KEY (`id_filter`) REFERENCES tnetflow_filter(`id_sg`)
ON DELETE CASCADE
) ENGINE = InnoDB DEFAULT CHARSET=utf8
) ENGINE = InnoDB DEFAULT CHARSET=utf8;
-- -----------------------------------------------------
-- Table `tusuario`
@ -66,3 +66,21 @@ ALTER TABLE `tincidencia` ADD COLUMN `id_agent` int(10) unsigned NULL default 0;
-- -----------------------------------------------------
ALTER TABLE `tagente` ADD COLUMN `url_address` mediumtext NULL default '';
-- -----------------------------------------------------
-- Table `talert_special_days`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `talert_special_days` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`date` date NOT NULL DEFAULT '0000-00-00',
`same_day` enum('monday','tuesday','wednesday','thursday','friday','saturday','sunday') NOT NULL DEFAULT 'sunday',
`description` text,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- -----------------------------------------------------
-- Table `talert_templates`
-- -----------------------------------------------------
ALTER TABLE `talert_templates` ADD COLUMN `special_day` tinyint(1) DEFAULT '0';

View File

@ -67,3 +67,24 @@ alter table tincidencia add (id_agent NUMBER(10,0) default 0 NULL);
-- Table `tagente`
-- -----------------------------------------------------
alter table tagente add (url_address CLOB default '' NULL);
-- -----------------------------------------------------
-- Table `talert_special_days`
-- -----------------------------------------------------
CREATE TABLE talert_special_days (
id NUMBER(10,0) NOT NULL PRIMARY KEY,
date DATE default '0000-00-00' NOT NULL,
same_day VARCHAR2(20) default 'sunday',
description CLOB,
CONSTRAINT talert_special_days_same_day_cons CHECK (same_day IN ('monday','tuesday','wednesday','thursday','friday','saturday','sunday'))
);
CREATE SEQUENCE talert_special_days_s INCREMENT BY 1 START WITH 1;
CREATE OR REPLACE TRIGGER talert_special_days_inc BEFORE INSERT ON talert_special_days REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT talert_special_days_s.nextval INTO :NEW.ID FROM dual; END talert_special_days_inc;;
-- -----------------------------------------------------
-- Table `talert_templates`
-- -----------------------------------------------------
alter table talert_templates add (special_day NUMBER(5,0) default 0);

View File

@ -56,3 +56,21 @@ ALTER TABLE "tincidencia" ADD COLUMN "id_agent" INTEGER(10) NULL DEFAULT 0;
-- -----------------------------------------------------
ALTER TABLE "tagente" ADD COLUMN "url_address" text NULL default '';
-- -----------------------------------------------------
-- Table `talert_special_days`
-- -----------------------------------------------------
CREATE TYPE type_talert_special_days_same_day AS ENUM ('monday','tuesday','wednesday','thursday','friday','saturday','sunday');
CREATE TABLE "talert_special_days" (
"id" SERIAL NOT NULL PRIMARY KEY,
"date" DATE NOT NULL default '0000-00-00',
"same_day" type_talert_special_days_same_day NOT NULL default 'sunday',
"description" TEXT
);
-- -----------------------------------------------------
-- Table `talert_templates`
-- -----------------------------------------------------
ALTER TABLE "talert_templates" ADD COLUMN "special_day" SMALLINT default 0;

View File

@ -0,0 +1,218 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
// Copyright (c) 2012 Junichi Satoh
// 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
global $config;
require_once ("include/functions_alerts.php");
check_login ();
if (! check_acl ($config['id_user'], 0, "LM")) {
db_pandora_audit("ACL Violation",
"Trying to access Alert Management");
require ("general/noaccess.php");
exit;
}
if (is_ajax ()) {
$get_alert_command = (bool) get_parameter ('get_alert_command');
if ($get_alert_command) {
$id = (int) get_parameter ('id');
$command = alerts_get_alert_command ($id);
echo json_encode ($command);
}
return;
}
// Header
ui_print_page_header (__('Alerts').' &raquo; '.__('Special days list'), "images/god2.png", false, "alert_special_days", true);
$update_special_day = (bool) get_parameter ('update_special_day');
$create_special_day = (bool) get_parameter ('create_special_day');
$delete_special_day = (bool) get_parameter ('delete_special_day');
if ($create_special_day) {
$date = (string) get_parameter ('date');
$same_day = (string) get_parameter ('same_day');
$description = (string) get_parameter ('description');
list($year, $month, $day) = explode("-", $date);
if ($year == '*') {
# '0001' means every year.
$year = '0001';
$date = $year . '-' . $month . '-' . $day;
}
if (!checkdate ($month, $day, $year)) {
$result = '';
}
else {
$date_check = db_get_value ('date', 'talert_special_days', 'date
', $date);
if ($date_check == $date) {
$result = '';
}
else {
$result = alerts_create_alert_special_day ($date, $same_day, array ('description' => $description));
$info = 'Date: ' . $date . ' Same day of the week: ' . $same_day . ' Description: ' . $description;
}
}
if ($result) {
db_pandora_audit("Command management", "Create special day " . $result, false, false, $info);
}
else {
db_pandora_audit("Command management", "Fail try to create special day", false, false);
}
ui_print_result_message ($result,
__('Successfully created'),
__('Could not be created'));
}
if ($update_special_day) {
$id = (int) get_parameter ('id');
$alert = alerts_get_alert_special_day ($id);
$date = (string) get_parameter ('date');
$same_day = (string) get_parameter ('same_day');
$description = (string) get_parameter ('description');
list($year, $month, $day) = explode("-", $date);
if ($year == '*') {
# '0001' means every year.
$year = '0001';
$date = $year . '-' . $month . '-' . $day;
}
$values = array ();
$values['date'] = $date;
$values['same_day'] = $same_day;
$values['description'] = $description;
if (!checkdate ($month, $day, $year)) {
$result = '';
}
else {
$result = alerts_update_alert_special_day ($id, $values);
$info = 'Date: ' . $date . ' Same day of the week: ' . $same_day . ' Description: ' . $description;
}
if ($result) {
db_pandora_audit("Command management", "Update special day " . $id, false, false, $info);
}
else {
db_pandora_audit("Command management", "Fail to update special day " . $id, false, false);
}
ui_print_result_message ($result,
__('Successfully updated'),
__('Could not be updated'));
}
if ($delete_special_day) {
$id = (int) get_parameter ('id');
$result = alerts_delete_alert_special_day ($id);
if ($result) {
db_pandora_audit("Command management", "Delete special day " . $id);
}
else {
db_pandora_audit("Command management", "Fail to delete special day " . $id);
}
ui_print_result_message ($result,
__('Successfully deleted'),
__('Could not be deleted'));
}
$table->width = '98%';
$table->data = array ();
$table->head = array ();
$table->head[0] = __('Date');
$table->head[1] = __('Same day of the week');
$table->head[2] = __('Description');
$table->head[3] = __('Delete');
$table->style = array ();
$table->style[0] = 'font-weight: bold';
$table->size = array ();
$table->size[0] = '20%';
$table->size[1] = '15%';
$table->size[2] = '60%';
$table->size[3] = '5%';
$table->align = array ();
$table->align[3] = 'center';
$special_days = db_get_all_rows_in_table ('talert_special_days', 'date');
if ($special_days === false)
$special_days = array ();
foreach ($special_days as $special_day) {
$data = array ();
$data[0] = '<span style="font-size: 7.5pt">';
# '0001' means every year.
$data[0] .= '<a href="index.php?sec=galertas&sec2=godmode/alerts/configure_alert_special_days&id='.$special_day['id'].'">'.
str_replace('0001', '*', $special_day['date']) . '</a>';
$data[0] .= '</span>';
switch ($special_day['same_day']) {
case 'monday':
$data[1] = __('Monday');
break;
case 'tuesday':
$data[1] = __('Tuesday');
break;
case 'wednesday':
$data[1] = __('Wednesday');
break;
case 'thursday':
$data[1] = __('Thursday');
break;
case 'friday':
$data[1] = __('Friday');
break;
case 'saturday':
$data[1] = __('Saturday');
break;
case 'sunday':
$data[1] = __('Sunday');
break;
}
$data[2] = $special_day['description'];
$data[3] = '';
$data[3] = '<a href="index.php?sec=galertas&sec2=godmode/alerts/alert_special_days&delete_special_day=1&id='.$special_day['id'].'"
onClick="if (!confirm(\''.__('Are you sure?').'\')) return false;">'.
html_print_image("images/cross.png", true) . '</a>';
array_push ($table->data, $data);
}
if(isset($data)) {
html_print_table ($table);
}
else {
echo "<div class='nf'>".__('No special days configured')."</div>";
}
echo '<div class="action-buttons" style="width: '.$table->width.'">';
echo '<form method="post" action="index.php?sec=galertas&sec2=godmode/alerts/configure_alert_special_days">';
html_print_submit_button (__('Create'), 'create', false, 'class="sub next"');
html_print_input_hidden ('create_special_day', 1);
echo '</form>';
echo '</div>';
?>

View File

@ -0,0 +1,92 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
// Copyright (c) 2012 Junichi Satoh
// 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
global $config;
require_once ("include/functions_alerts.php");
check_login ();
if (! check_acl ($config['id_user'], 0, "LM")) {
db_pandora_audit("ACL Violation",
"Trying to access Alert Management");
require ("general/noaccess.php");
exit;
}
ui_require_javascript_file ('calendar');
$id = (int) get_parameter ('id');
$name = '';
$command = '';
$description = '';
$date = '';
$same_day = '';
if ($id) {
$special_day = alerts_get_alert_special_day ($id);
$date = str_replace('0001', '*', $special_day['date']);
$same_day = $special_day['same_day'];
$description = $special_day['description'];
}
if ($date == '') {
$date = date ("Y-m-d", get_system_time());
}
// Header
ui_print_page_header (__('Alerts').' &raquo; '.__('Configure special day'), "images/god2.png", false, "", true);
$table->width = '98%';
$table->style = array ();
$table->style[0] = 'font-weight: bold';
$table->size = array ();
$table->size[0] = '20%';
$table->data = array ();
$table->data[0][0] = __('Date');
$table->data[0][1] = html_print_input_text ('date', $date, '', 10, 10, true);
$table->data[0][1] .= html_print_image ("images/calendar_view_day.png", true, array ("alt" => "calendar", "onclick" => "scwShow(scwID('text-date'),this);"));
$table->data[1][0] = __('Same day of the week');
$days = array ();
$days["monday"] = __('Monday');
$days["tuesday"] = __('Tuesday');
$days["wednesday"] = __('Wednesday');
$days["thursday"] = __('Thursday');
$days["friday"] = __('Friday');
$days["saturday"] = __('Saturday');
$days["sunday"] = __('Sunday');
$table->data[1][1] = html_print_select ($days, "same_day", $same_day, '', '', 0, true, false, false);
#$table->data[1][1] = html_print_input_text ('same_day', $same_day, '', 80, 255, true);
$table->data[2][0] = __('Description');
$table->data[2][1] = html_print_textarea ('description', 10, 30, $description, '', true);
echo '<form method="post" action="index.php?sec=galertas&sec2=godmode/alerts/alert_special_days">';
html_print_table ($table);
echo '<div class="action-buttons" style="width: '.$table->width.'">';
if ($id) {
html_print_input_hidden ('id', $id);
html_print_input_hidden ('update_special_day', 1);
html_print_submit_button (__('Update'), 'create', false, 'class="sub upd"');
} else {
html_print_input_hidden ('create_special_day', 1);
html_print_submit_button (__('Create'), 'create', false, 'class="sub wand"');
}
echo '</div>';
echo '</form>';
?>

View File

@ -200,6 +200,7 @@ function update_template ($step) {
$friday = (bool) get_parameter ('friday');
$saturday = (bool) get_parameter ('saturday');
$sunday = (bool) get_parameter ('sunday');
$special_day = (bool) get_parameter ('special_day');
$time_from = (string) get_parameter ('time_from');
$time_from = date ("H:i:00", strtotime ($time_from));
$time_to = (string) get_parameter ('time_to');
@ -226,6 +227,7 @@ function update_template ($step) {
'friday' => $friday,
'saturday' => $saturday,
'sunday' => $sunday,
'special_day' => $special_day,
'time_from' => $time_from,
'time_to' => $time_to,
'time_threshold' => $threshold,
@ -245,6 +247,7 @@ function update_template ($step) {
'friday' => $friday,
'saturday' => $saturday,
'sunday' => $sunday,
'special_day' => $special_day,
'time_from' => "#to_date('" . $time_from . "','hh24:mi:ss')",
'time_to' => "#to_date('" . $time_to . "','hh24:mi:ss')",
'time_threshold' => $threshold,
@ -307,6 +310,7 @@ $thursday = true;
$friday = true;
$saturday = true;
$sunday = true;
$special_day = false;
$default_action = 0;
$field1 = '';
$field2 = '';
@ -409,6 +413,7 @@ if ($id && ! $create_template) {
$friday = (bool) $template['friday'];
$saturday = (bool) $template['saturday'];
$sunday = (bool) $template['sunday'];
$special_day = (bool) $template['special_day'];
$max_alerts = $template['max_alerts'];
$min_alerts = $template['min_alerts'];
$threshold = $template['time_threshold'];
@ -447,7 +452,6 @@ if ($step == 2) {
}
$table->colspan = array ();
$table->colspan[0][1] = 3;
$table->colspan[4][1] = 3;
$table->colspan['field1'][1] = 3;
$table->colspan['field2'][1] = 3;
@ -468,6 +472,9 @@ if ($step == 2) {
$table->data[0][1] .= html_print_checkbox ('saturday', 1, $saturday, true);
$table->data[0][1] .= __('Sun');
$table->data[0][1] .= html_print_checkbox ('sunday', 1, $sunday, true);
$table->data[0][2] = __('Use special days list');
$table->data[0][3] = html_print_checkbox ('special_day', 1, $special_day, true);
$table->data[1][0] = __('Time from');
$table->data[1][1] = html_print_input_text ('time_from', $time_from, '', 7, 7,

View File

@ -92,6 +92,7 @@ if (check_acl ($config['id_user'], 0, "LM")) {
$sub["godmode/alerts/alert_commands"]["text"] = __('Commands');
}
$sub["godmode/alerts/alert_compounds"]["text"] = __('Correlation');
$sub["godmode/alerts/alert_special_days"]["text"] = __('Special days list');
enterprise_hook('eventalerts_submenu');
$menu["galertas"]["sub"] = $sub;

View File

@ -1830,4 +1830,77 @@ function get_alert_last_fire_timestamp_in_period ($id_alert_module, $period, $da
return db_get_sql ($sql);
}
/**
* Insert in talert_special_days a new special day.
*
* @param date of special day.
* @param same day of the week.
* @param mixed A single value or array of values to insert (can be a multiple a mount of rows).
*
* @return mixed False in case of error or invalid values passed. Affected rows otherwise.
*/
function alerts_create_alert_special_day ($date, $same_day, $values = false) {
if (empty ($date))
return false;
if (empty ($same_day))
return false;
if (! is_array ($values))
$values = array ();
$values['date'] = $date;
$values['same_day'] = $same_day;
return @db_process_sql_insert ('talert_special_days', $values);
}
/**
* Update a special day in talert_special_days.
*
* @param int special day Id.
* @param mixed Array of values to update.
*
* @return mixed False in case of error or invalid values passed. Affected rows otherwise
*/
function alerts_update_alert_special_day ($id_special_day, $values) {
$id_special_day = safe_int ($id_special_day, 1);
if (empty ($id_special_day))
return false;
if (! is_array ($values))
return false;
return (@db_process_sql_update ('talert_special_days',
$values,
array ('id' => $id_special_day))) !== false;
}
/**
* Delete a special day in talert_special_days.
*
* @param int special day Id.
*
* @return mixed False in case of error or invalid values passed. Affected rows otherwise
*/
function alerts_delete_alert_special_day ($id_special_day) {
$id_special_day = safe_int ($id_special_day, 1);
if (empty ($id_special_day))
return false;
return (@db_process_sql_delete ('talert_special_days',
array ('id' => $id_special_day))) !== false;
}
/**
* Get a special day in talert_special_days.
*
* @param int special day Id.
*
* @return mixed False in case of error or invalid values passed. All row of the selected command otherwise
*/
function alerts_get_alert_special_day ($id_special_day) {
$id_special_day = safe_int ($id_special_day, 1);
if (empty ($id_special_day))
return false;
return db_get_row ('talert_special_days', 'id', $id_special_day);
}
?>

View File

@ -312,6 +312,7 @@ CREATE TABLE talert_templates (
field3_recovery CLOB NOT NULL,
priority NUMBER(10, 0) default 0 NOT NULL,
id_group NUMBER(10, 0) default 0 NOT NULL,
special_day NUMBER(5, 0) default 0,
CONSTRAINT t_alert_templates_type_cons CHECK (type IN ('regex', 'max_min', 'max', 'min', 'equal', 'not_equal', 'warning', 'critical', 'onchange', 'unknown', 'always'))
);
CREATE INDEX talert_templates_id_al_act_idx ON talert_templates(id_alert_action);
@ -439,6 +440,18 @@ CREATE OR REPLACE TRIGGER talert_compound_actions_update AFTER UPDATE OF ID ON t
-- on update trigger 1
CREATE OR REPLACE TRIGGER talert_compound_action_update1 AFTER UPDATE OF ID ON talert_actions FOR EACH ROW BEGIN UPDATE talert_compound_actions SET ID_ALERT_ACTION = :NEW.ID WHERE ID_ALERT_ACTION = :OLD.ID; END;;
CREATE TABLE talert_special_days (
id NUMBER(10,0) NOT NULL PRIMARY KEY,
date DATE default '0000-00-00' NOT NULL,
same_day VARCHAR2(20) default 'sunday',
description CLOB,
CONSTRAINT talert_special_days_same_day_cons CHECK (same_day IN ('monday','tuesday','wednesday','thursday','friday','saturday','sunday'))
);
-- on update trigger
CREATE SEQUENCE talert_special_days_s INCREMENT BY 1 START WITH 1;
CREATE OR REPLACE TRIGGER talert_special_days_inc BEFORE INSERT ON talert_special_days REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT talert_special_days_s.nextval INTO :NEW.ID FROM dual; END talert_special_days_inc;;
-- Priority : 0 - Maintance (grey)
-- Priority : 1 - Low (green)
-- Priority : 2 - Normal (blue)

View File

@ -269,7 +269,8 @@ CREATE TABLE "talert_templates" (
"field2_recovery" text NOT NULL default '',
"field3_recovery" text NOT NULL,
"priority" INTEGER NOT NULL default 0,
"id_group" INTEGER NOT NULL default 0
"id_group" INTEGER NOT NULL default 0,
"special_day" SMALLINT default 0
);
CREATE INDEX "talert_templates_id_alert_action_idx" ON "talert_templates"("id_alert_action");
@ -342,6 +343,14 @@ CREATE TABLE "talert_compound_actions" (
"fires_max" INTEGER default 0
);
CREATE TYPE type_talert_special_days_same_day AS ENUM ('monday','tuesday','wednesday','thursday','friday','saturday','sunday');
CREATE TABLE "talert_special_days" (
"id" SERIAL NOT NULL PRIMARY KEY,
"date" DATE NOT NULL default '0000-00-00',
"same_day" type_talert_special_days_same_day NOT NULL default 'sunday',
"description" TEXT
);
-- Priority : 0 - Maintance (grey)
-- Priority : 1 - Low (green)
-- Priority : 2 - Normal (blue)

View File

@ -281,6 +281,7 @@ CREATE TABLE IF NOT EXISTS `talert_templates` (
`field3_recovery` text NOT NULL,
`priority` tinyint(4) default '0',
`id_group` mediumint(8) unsigned NULL default 0,
`special_day` tinyint(1) default 0,
PRIMARY KEY (`id`),
KEY `idx_template_action` (`id_alert_action`),
FOREIGN KEY (`id_alert_action`) REFERENCES talert_actions(`id`)
@ -381,6 +382,14 @@ CREATE TABLE IF NOT EXISTS `talert_compound_actions` (
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `talert_special_days` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`date` date NOT NULL DEFAULT '0000-00-00',
`same_day` enum('monday','tuesday','wednesday','thursday','friday','saturday','sunday') NOT NULL DEFAULT 'sunday',
`description` text,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- Priority : 0 - Maintance (grey)
-- Priority : 1 - Low (green)
-- Priority : 2 - Normal (blue)