From b912834ce7d460ce9bdc6a0cf3dfd814b3e2eec5 Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Date: Wed, 12 Apr 2017 15:00:09 +0200 Subject: [PATCH] Added the new item to item editor builder and to html view --- .../reporting_builder.item_editor.php | 16 +++++ .../include/functions_reporting.php | 65 ++++++++++++++++++ .../include/functions_reporting_html.php | 66 +++++++++++++++++++ pandora_console/include/functions_reports.php | 3 +- 4 files changed, 149 insertions(+), 1 deletion(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 2e974b85fe..900cf4b475 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -144,6 +144,7 @@ switch ($action) { case 'network_interfaces_report': case 'availability': case 'event_report_log': + case 'increment': case 'availability_graph': case 'agent_module': $get_data_editor = true; @@ -272,6 +273,13 @@ switch ($action) { $idAgent = db_get_value_filter('id_agente', 'tagente_modulo', array('id_agente_modulo' => $idAgentModule)); break; + case 'increment': + $description = $item['description']; + $idAgentModule = $item['id_agent_module']; + $idAgent = db_get_value_filter('id_agente', 'tagente_modulo', array('id_agente_modulo' => $idAgentModule)); + $period = $item['period']; + break; + case 'SLA_services': $description = $item['description']; $period = $item['period']; @@ -578,6 +586,7 @@ switch ($action) { case 'MTTR': case 'simple_baseline_graph': case 'event_report_log': + case 'increment': $label = (isset($style['label'])) ? $style['label'] : ''; break; default: @@ -2646,6 +2655,13 @@ function chooseType() { $("#agents_row").show(); $("#row_source").show(); break; + + case 'increment': + $("#row_description").show(); + $("#row_agent").show(); + $("#row_module").show(); + $("#row_period").show(); + break; case 'simple_graph': $("#row_time_compare_overlapped").show(); diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 3d05c2099f..1a649d63ab 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -171,6 +171,12 @@ function reporting_make_reporting_data($report = null, $id_report, $report, $content); break; + case 'increment': + $report['contents'][] = + reporting_increment( + $report, + $content); + break; case 'general': $report['contents'][] = reporting_general( @@ -5464,6 +5470,65 @@ function reporting_availability_graph($report, $content, $pdf=false) { return reporting_check_structure_content($return); } +/** + * reporting_increment + * + * Generates a structure the report. + * + */ +function reporting_increment ($report, $content) { + global $config; + + $return = array(); + $return['type'] = 'increment'; + if (empty($content['name'])) { + $content['name'] = __('Increment'); + } + + $return['title'] = $content['name']; + $return["description"] = $content["description"]; + $return["id_agent_module"] = $content["id_agent_module"]; + $return["id_agent"] = $content["id_agent"]; + + $id_agent_module = $content['id_agent_module']; + $period = (int)$content['period']; + + $return["from"] = time() - $period; + $return["to"] = time(); + + $return["data"] = array(); + + $old_data = db_get_value_sql('SELECT datos FROM tagente_datos WHERE id_agente_modulo = ' . $id_agent_module . ' + AND utimestamp <= ' . (time() - $period) . ' ORDER BY utimestamp DESC'); + + $last_data = db_get_value_sql('SELECT datos FROM tagente_datos WHERE id_agente_modulo = ' . $id_agent_module . ' ORDER BY utimestamp DESC'); + + if (is_numeric($old_data) && is_numeric($last_data)) { + $return["data"]['old'] = $old_data; + $return["data"]['now'] = $last_data; + $increment = $old_data - $last_data; + + if ($increment < 0) { + $return["data"]['inc'] = 'positive'; + $return["data"]["inc_data"] = $last_data - $old_data; + } + else if ($increment == 0) { + $return["data"]['inc'] = 'neutral'; + $return["data"]["inc_data"] = 0; + } + else { + $return["data"]['inc'] = 'negative'; + $return["data"]["inc_data"] = $old_data - $last_data; + } + } + else { + $return["data"]['message'] = __('The monitor type is not numeric'); + $return["data"]['error'] = true; + } + + return reporting_check_structure_content($return); +} + /** * reporting_general * diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index f6acad7fbe..1cf64b4342 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -208,6 +208,9 @@ function reporting_html_print_report($report, $mini = false, $report_info = 1) { case 'avg_value': reporting_html_avg_value($table, $item, $mini); break; + case 'increment': + reporting_html_increment($table, $item); + break; case 'min_value': reporting_html_min_value($table, $item, $mini); break; @@ -2213,6 +2216,69 @@ function reporting_html_value(&$table, $item, $mini, $only_value = false, $check $table->data['data']['cell'] .= '

'; } +function reporting_html_increment(&$table, $item) { + global $config; + + if (isset($item["data"]['error'])) { + $table->colspan['error']['cell'] = 3; + $table->data['error']['cell'] = $item["data"]['message']; + } + else { + $table1 = new stdClass(); + $table1->width = '99%'; + $table1->data = array (); + + $table1->head = array (); + $table1->head[0] = __('Agent'); + $table1->head[1] = __('Module'); + $table1->head[2] = __('From'); + $table1->head[3] = __('To'); + $table1->head[4] = __('From data'); + $table1->head[5] = __('To data'); + $table1->head[6] = __('Increment'); + + $table1->headstyle = array(); + $table1->headstyle[0] = 'text-align: left'; + $table1->headstyle[1] = 'text-align: left'; + $table1->headstyle[2] = 'text-align: left'; + $table1->headstyle[3] = 'text-align: left'; + $table1->headstyle[4] = 'text-align: right'; + $table1->headstyle[5] = 'text-align: right'; + $table1->headstyle[6] = 'text-align: right'; + + $table1->style[0] = 'text-align: left'; + $table1->style[1] = 'text-align: left'; + $table1->style[2] = 'text-align: left'; + $table1->style[3] = 'text-align: left'; + $table1->style[4] = 'text-align: right'; + $table1->style[5] = 'text-align: right'; + $table1->style[6] = 'text-align: right'; + + $table1_row = array(); + $table1_row[0] = agents_get_alias($item['id_agent']); + $table1_row[1] = modules_get_agentmodule_name($item['id_agent_module']); + $table1_row[2] = date("F j, Y, g:i a", $item['from']); + $table1_row[3] = date("F j, Y, g:i a", $item['to']); + $table1_row[4] = $item["data"]['old']; + $table1_row[5] = $item["data"]['now']; + if ($item["data"]['inc'] == 'negative') { + $table1_row[6] = __('Negative increase: ') . $item["data"]["inc_data"]; + } + else if ($item["data"]['inc'] == 'positive') { + $table1_row[6] = __('Positive increase: ') . $item["data"]["inc_data"]; + } + else { + $table1_row[6] = __('Neutral increase: ') . $item["data"]["inc_data"]; + } + + $table1->data[] = $table1_row; + + $data = array(); + $data[0] = html_print_table($table1, true); + array_push ($table->data, $data); + } +} + function reporting_html_url(&$table, $item, $key) { $table->colspan['data']['cell'] = 3; $table->cellstyle['data']['cell'] = 'text-align: left;'; diff --git a/pandora_console/include/functions_reports.php b/pandora_console/include/functions_reports.php index 9282be345b..dfa3d3d490 100755 --- a/pandora_console/include/functions_reports.php +++ b/pandora_console/include/functions_reports.php @@ -574,7 +574,8 @@ function reports_get_report_types ($template = false, $not_editor = false) { 'name' => __('Summatory')); $types['historical_data'] = array('optgroup' => __('Modules'), 'name' => __('Historical Data')); - + $types['increment'] = array('optgroup' => __('Modules'), + 'name' => __('Increment')); $types['general'] = array('optgroup' => __('Grouped'),