From 986a09f3ea69d5c351bf407bd012a3403e5177a7 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 27 Jul 2010 18:11:42 +0000 Subject: [PATCH] 2010-07-27 Miguel de Dios * include/functions_reporting.php: added new parameters in the function "get_agentmodule_sla", the parameters days of week to search and range of time. And use new parameteres in the call for SLA data in function "render_report_html_item". * pandoradb.sql, extras/pandoradb_migrate_v3.1_to_v3.2.sql: in table "treport_content" added the fields for set days of week and range time for SLA. * operation/reporting/reporting_xml.php: use new parameters in the call for SLA data. * godmode/reporting/reporting_builder.php: added source code for save, update new fields (days of week and time range). * godmode/reporting/reporting_builder.item_editor.php: added source code to show the fields (days of week and time range). Pending task: #3033457 git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3070 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 21 ++++ .../extras/pandoradb_migrate_v3.1_to_v3.2.sql | 13 +++ .../reporting_builder.item_editor.php | 107 +++++++++--------- .../godmode/reporting/reporting_builder.php | 20 +++- .../include/functions_reporting.php | 49 +++++++- .../operation/reporting/reporting_xml.php | 18 +-- pandora_console/pandoradb.sql | 48 +++++--- 7 files changed, 186 insertions(+), 90 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 6c64aa38c0..a8ebbd8ae3 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,24 @@ +2010-07-27 Miguel de Dios + * include/functions_reporting.php: added new parameters in the function + "get_agentmodule_sla", the parameters days of week to search and range of + time. And use new parameteres in the call for SLA data in function + "render_report_html_item". + + * pandoradb.sql, extras/pandoradb_migrate_v3.1_to_v3.2.sql: in table + "treport_content" added the fields for set days of week and range time + for SLA. + + * operation/reporting/reporting_xml.php: use new parameters in the call for + SLA data. + + * godmode/reporting/reporting_builder.php: added source code for save, + update new fields (days of week and time range). + + * godmode/reporting/reporting_builder.item_editor.php: added source code to + show the fields (days of week and time range). + + Pending task: #3033457 + 2010-07-27 Miguel de Dios * operation/agentes/exportdata.php: fixed the date into export, before it was 12 hour format, now it is 24 hour format. diff --git a/pandora_console/extras/pandoradb_migrate_v3.1_to_v3.2.sql b/pandora_console/extras/pandoradb_migrate_v3.1_to_v3.2.sql index f737891eff..a56a0a157d 100644 --- a/pandora_console/extras/pandoradb_migrate_v3.1_to_v3.2.sql +++ b/pandora_console/extras/pandoradb_migrate_v3.1_to_v3.2.sql @@ -22,3 +22,16 @@ -- Table `tgrupo` -- ----------------------------------------------------- ALTER TABLE `tgrupo` ADD COLUMN `propagate` tinyint(1) unsigned NOT NULL default '0'; + +-- ----------------------------------------------------- +-- Table `treport_content` +-- ----------------------------------------------------- +ALTER TABLE `treport_content` ADD COLUMN `time_from` time default '00:00:00'; +ALTER TABLE `treport_content` ADD COLUMN `time_to` time default '00:00:00'; +ALTER TABLE `treport_content` ADD COLUMN `monday` tinyint(1) default 1; +ALTER TABLE `treport_content` ADD COLUMN `tuesday` tinyint(1) default 1; +ALTER TABLE `treport_content` ADD COLUMN `wednesday` tinyint(1) default 1; +ALTER TABLE `treport_content` ADD COLUMN `thursday` tinyint(1) default 1; +ALTER TABLE `treport_content` ADD COLUMN `friday` tinyint(1) default 1; +ALTER TABLE `treport_content` ADD COLUMN `saturday` tinyint(1) default 1; +ALTER TABLE `treport_content` ADD COLUMN `sunday` tinyint(1) default 1; diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 1774a36030..3e896dc6da 100644 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -39,6 +39,16 @@ switch ($action) { $description = null; $sql = null; $group = null; + + $monday = true; + $tuesday = true; + $wednesday = true; + $thursday = true; + $friday = true; + $saturday = true; + $sunday = true; + $time_from = '00:00'; + $time_to = '23:59'; break; default: $actionParameter = 'update'; @@ -66,6 +76,16 @@ switch ($action) { case 'SLA': $description = $item['description']; $period = $item['period']; + + $monday = $item['monday']; + $tuesday = $item['tuesday']; + $wednesday = $item['wednesday']; + $thursday = $item['thursday']; + $friday = $item['friday']; + $saturday = $item['saturday']; + $sunday = $item['sunday']; + $time_from = $item['time_from']; + $time_to = $item['time_to']; break; case 'monitor_report': $description = $item['description']; @@ -102,17 +122,6 @@ switch ($action) { $idAgentModule = $item['id_agent_module']; $period = $item['period']; break; -// case 'agent_detailed': -// $description = $item['description']; -// $idAgent = $item['id_agent']; -// $period = $item['period']; -// break; -// case 'agent_detailed_event': -// $description = $item['description']; -// $idAgent = get_db_value_filter('id_agente', 'tagente_modulo', array('id_agente_modulo' => $idAgentModule)); -// $idAgentModule = $item['id_agent_module']; -// $period = $item['period']; -// break; case 'text': $description = $item['description']; $text = $item['text']; @@ -187,24 +196,6 @@ switch ($action) { $idAgent = get_db_value_filter('id_agente', 'tagente_modulo', array('id_agente_modulo' => $idAgentModule)); $period = $item['period']; break; -// case 'list_events_module': -// $description = $item['description']; -// $idAgent = get_db_value_filter('id_agente', 'tagente_modulo', array('id_agente_modulo' => $idAgentModule)); -// $idAgentModule = $item['id_agent_module']; -// break; -// case 'list_events_agent': -// $description = $item['description']; -// $idAgent = get_db_value_filter('id_agente', 'tagente_modulo', array('id_agente_modulo' => $idAgentModule)); -// break; -// case 'list_alerts_agent': -// $description = $item['description']; -// $idAgent = get_db_value_filter('id_agente', 'tagente_modulo', array('id_agente_modulo' => $idAgentModule)); -// break; -// case 'list_alerts_module': -// $description = $item['description']; -// $idAgent = get_db_value_filter('id_agente', 'tagente_modulo', array('id_agente_modulo' => $idAgentModule)); -// $idAgentModule = $item['id_agent_module']; -// break; } break; @@ -247,6 +238,30 @@ print_input_hidden('id_item', $idItem); + + + + + + + + + + + + + + + + + + + + + +
+ + @@ -334,6 +349,7 @@ else { echo ''; echo ''; +require_jquery_file ('timeentry'); require_jquery_file ('autocomplete'); require_javascript_file('pandora'); if ($enterpriseEnable) { @@ -427,6 +443,13 @@ $(document).ready (function () { agent_module_autocomplete('#text-agent_sla', '#hidden-id_agent_sla', '#id_agent_module_sla'); chooseType(); chooseSQLquery(); + + $("#text-time_to, #text-time_from").timeEntry ({ + spinnerImage: 'images/time-entry.png', + spinnerSize: [20, 20, 0], + show24Hours: true + } + ); }); function chooseSQLquery() { @@ -553,6 +576,7 @@ function chooseType() { $("#sla_list").css('display', 'none'); $("#row_custom_example").css('display', 'none'); $("#row_group").css('display', 'none'); + $("#row_working_time").css('display', 'none'); switch (type) { case 'event_report_group': @@ -575,6 +599,7 @@ function chooseType() { $("#row_description").css('display', ''); $("#row_period").css('display', ''); $("#sla_list").css('display', ''); + $("#row_working_time").css('display', ''); break; case 'monitor_report': $("#row_description").css('display', ''); @@ -611,12 +636,6 @@ function chooseType() { $("#row_agent").css('display', ''); $("#row_period").css('display', ''); break; -// case 'agent_detailed_event': -// $("#row_description").css('display', ''); -// $("#row_agent").css('display', ''); -// $("#row_module").css('display', ''); -// $("#row_period").css('display', ''); -// break; case 'text': $("#row_description").css('display', ''); $("#row_text").css('display', ''); @@ -687,24 +706,6 @@ function chooseType() { $("#row_module").css('display', ''); $("#row_period").css('display', ''); break; -// case 'list_events_module': -// $("#row_description").css('display', ''); -// $("#row_agent").css('display', ''); -// $("#row_module").css('display', ''); -// break; -// case 'list_events_agent': -// $("#row_description").css('display', ''); -// $("#row_agent").css('display', ''); -// break; -// case 'list_alerts_agent': -// $("#row_description").css('display', ''); -// $("#row_agent").css('display', ''); -// break; -// case 'list_alerts_module': -// $("#row_description").css('display', ''); -// $("#row_agent").css('display', ''); -// $("#row_module").css('display', ''); -// break; } } diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index ef72f3a160..031a76c260 100644 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -171,7 +171,16 @@ switch ($action) { $values['text'] = get_parameter('text'); $values['id_agent_module'] = get_parameter('id_agent_module'); $values['type'] = get_parameter('type', null); - + $values['monday'] = get_parameter('monday', 0); + $values['tuesday'] = get_parameter('tuesday', 0); + $values['wednesday'] = get_parameter('wednesday', 0); + $values['thursday'] = get_parameter('thursday', 0); + $values['friday'] = get_parameter('friday', 0); + $values['saturday'] = get_parameter('saturday', 0); + $values['sunday'] = get_parameter('sunday', 0); + $values['time_from'] = get_parameter('time_from'); + $values['time_to'] = get_parameter('time_to'); + if ($values['type'] == 'sql') { $values['treport_custom_sql_id'] = get_parameter('id_custom'); if ($values['treport_custom_sql_id'] == 0) { @@ -201,6 +210,15 @@ switch ($action) { $values['id_gs'] = get_parameter('id_custom_graph'); $values['text'] = get_parameter('text'); $values['id_agent_module'] = get_parameter('id_agent_module'); + $values['monday'] = get_parameter('monday', 0); + $values['tuesday'] = get_parameter('tuesday', 0); + $values['wednesday'] = get_parameter('wednesday', 0); + $values['thursday'] = get_parameter('thursday', 0); + $values['friday'] = get_parameter('friday', 0); + $values['saturday'] = get_parameter('saturday', 0); + $values['sunday'] = get_parameter('sunday', 0); + $values['time_from'] = get_parameter('time_from'); + $values['time_to'] = get_parameter('time_to'); if ($values['type'] == 'sql') { $values['treport_custom_sql_id'] = get_parameter('id_custom'); diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 822b81ca3f..457e8e48f2 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -305,11 +305,14 @@ function get_agentmodule_data_sum ($id_agent_module, $period, $date = 0) { * @param int Maximum data value the module in the right interval. False will * ignore max value * @param int Beginning date of the report in UNIX time (current date by default). + * @param array $dayWeek Array of days week to extract as array('monday' => false, 'tuesday' => true....), and by default is null. + * @param string $timeFrom Time in the day to start to extract in mysql format, by default null. + * @param string $timeTo Time in the day to end to extract in mysql format, by default null. * * @return float SLA percentage of the requested module. False if no data were * found */ -function get_agentmodule_sla ($id_agent_module, $period = 0, $min_value = 1, $max_value = false, $date = 0) { +function get_agentmodule_sla ($id_agent_module, $period = 0, $min_value = 1, $max_value = false, $date = 0, $daysWeek = null, $timeFrom = null, $timeTo = null) { global $config; // Initialize variables @@ -324,6 +327,48 @@ function get_agentmodule_sla ($id_agent_module, $period = 0, $min_value = 1, $ma WHERE id_agente_modulo = %d AND utimestamp > %d AND utimestamp <= %d', $id_agent_module, $datelimit, $date); + + //Add the working times (mon - tue - wed ...) and from time to time + $days = array(); + //Translate to mysql week days + foreach ($daysWeek as $key => $value) { + if (!$value) { + if ($key == 'monday') { + $days[] = 2; + } + if ($key == 'tuesday') { + $days[] = 3; + } + if ($key == 'wednesday') { + $days[] = 4; + } + if ($key == 'thursday') { + $days[] = 5; + } + if ($key == 'friday') { + $days[] = 6; + } + if ($key == 'saturday') { + $days[] = 7; + } + if ($key == 'sunday') { + $days[] = 1; + } + } + } + + if (count($days) > 0) { + $sql .= ' AND DAYOFWEEK(FROM_UNIXTIME(utimestamp)) NOT IN (' . implode(',', $days) . ')'; + } + + if (!empty($timeFrom)) { + $sql .= ' AND TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '"'; + } + + if (!empty($timeTo)) { + $sql .= ' AND TIME(FROM_UNIXTIME(utimestamp)) <= "' . $timeTo . '"'; + } + $interval_data = get_db_all_rows_sql ($sql, true); if ($interval_data === false) $interval_data = array (); @@ -1707,7 +1752,7 @@ function render_report_html_item ($content, $table, $report, $mini = false) { $data[0] .= ''.__('SLA Limit')." : "; $data[0] .= $sla['sla_limit']; $sla_value = get_agentmodule_sla ($sla['id_agent_module'], $content['period'], - $sla['sla_min'], $sla['sla_max'], $report["datetime"]); + $sla['sla_min'], $sla['sla_max'], $report["datetime"], $content, $content['time_from'], $content['time_to']); if ($sla_value === false) { $data[1] = ''; $data[1] .= __('Unknown'); diff --git a/pandora_console/operation/reporting/reporting_xml.php b/pandora_console/operation/reporting/reporting_xml.php index 84c01757f9..2efc3a7571 100644 --- a/pandora_console/operation/reporting/reporting_xml.php +++ b/pandora_console/operation/reporting/reporting_xml.php @@ -219,13 +219,14 @@ foreach ($contents as $content) { $data["objdata"]["sla"] = array (); $sla_failed = false; + foreach ($slas as $sla) { $sla_data = array (); $sla_data["agent"] = get_agentmodule_agent_name ($sla['id_agent_module']); $sla_data["module"] = get_agentmodule_name ($sla['id_agent_module']); $sla_data["max"] = $sla['sla_max']; $sla_data["min"] = $sla['sla_min']; - $sla_value = get_agentmodule_sla ($sla['id_agent_module'], $content['period'], $sla['sla_min'], $sla['sla_max'], $datetime); + $sla_value = get_agentmodule_sla ($sla['id_agent_module'], $content['period'], $sla['sla_min'], $sla['sla_max'], $datetime, $content, $content['time_from'], $content['time_to']); if ($sla_value === false) { $sla_data["error"] = __('Unknown'); } else { @@ -237,21 +238,6 @@ foreach ($contents as $content) { array_push ($data["objdata"]["sla"], $sla_data); } break; -// case 4: -// case 'event_report': -// $data["title"] = __("Event report"); -// $table_report = event_reporting ($report['id_group'], $content['period'], $datetime, true); -// $data["objdata"] = ""; -// break; -// case 5: -// case 'alert_report': -// $data["title"] = __('Alert report'); -// $data["objdata"] = ""; -// break; case 6: case 'monitor_report': $data["title"] = __('Monitor report'); diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 5791f4bee1..2709c5f0b0 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -761,25 +761,37 @@ CREATE TABLE IF NOT EXISTS `treport` ( PRIMARY KEY(`id_report`) ) ENGINE = InnoDB DEFAULT CHARSET=utf8; +-- ----------------------------------------------------- +-- Table `treport_content` +-- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `treport_content` ( - `id_rc` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, - `id_report` INTEGER UNSIGNED NOT NULL default 0, - `id_gs` INTEGER UNSIGNED NULL default NULL, - `id_agent_module` bigint(14) unsigned NULL default NULL, - `type` varchar(30) default 'simple_graph', - `period` int(11) NOT NULL default 0, - `order` int (11) NOT NULL default 0, - `description` mediumtext, - `id_agent` int(10) unsigned NOT NULL default 0, - `text` TEXT default NULL, - `external_source` TinyText default NULL, - `treport_custom_sql_id` INTEGER UNSIGNED default 0, - `header_definition` TinyText default NULL, - `column_separator` TinyText default NULL, - `line_separator` TinyText default NULL, - PRIMARY KEY(`id_rc`), - FOREIGN KEY (`id_report`) REFERENCES treport(`id_report`) - ON UPDATE CASCADE ON DELETE CASCADE + `id_rc` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, + `id_report` INTEGER UNSIGNED NOT NULL default 0, + `id_gs` INTEGER UNSIGNED NULL default NULL, + `id_agent_module` bigint(14) unsigned NULL default NULL, + `type` varchar(30) default 'simple_graph', + `period` int(11) NOT NULL default 0, + `order` int (11) NOT NULL default 0, + `description` mediumtext, + `id_agent` int(10) unsigned NOT NULL default 0, + `text` TEXT default NULL, + `external_source` TinyText default NULL, + `treport_custom_sql_id` INTEGER UNSIGNED default 0, + `header_definition` TinyText default NULL, + `column_separator` TinyText default NULL, + `line_separator` TinyText default NULL, + `time_from` time default '00:00:00', + `time_to` time default '00:00:00', + `monday` tinyint(1) default 1, + `tuesday` tinyint(1) default 1, + `wednesday` tinyint(1) default 1, + `thursday` tinyint(1) default 1, + `friday` tinyint(1) default 1, + `saturday` tinyint(1) default 1, + `sunday` tinyint(1) default 1, + PRIMARY KEY(`id_rc`), + FOREIGN KEY (`id_report`) REFERENCES treport(`id_report`) + ON UPDATE CASCADE ON DELETE CASCADE ) ENGINE = InnoDB DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `treport_content_sla_combined` (