diff --git a/pandora_console/extras/mr/30.sql b/pandora_console/extras/mr/30.sql index eeb3b8d797..58abf6c562 100644 --- a/pandora_console/extras/mr/30.sql +++ b/pandora_console/extras/mr/30.sql @@ -10,4 +10,6 @@ ALTER TABLE `treport_content_template` ADD COLUMN `failover_type` tinyint(1) DEF ALTER TABLE `tmodule_relationship` ADD COLUMN `type` ENUM('direct', 'failover') DEFAULT 'direct'; +ALTER TABLE `treport_content` MODIFY COLUMN `name` varchar(300) NULL; + COMMIT; \ No newline at end of file diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index 60e19998e8..b59a76dfd2 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -724,7 +724,7 @@ CREATE TABLE IF NOT EXISTS `treport_content_template` ( `type` varchar(30) default 'simple_graph', `period` int(11) NOT NULL default 0, `order` int (11) NOT NULL default 0, - `description` mediumtext, + `description` mediumtext, `text_agent` text, `text` TEXT, `external_source` Text, @@ -1446,6 +1446,7 @@ ALTER TABLE `treport_content` ADD COLUMN `agent_min_value` TINYINT(1) DEFAULT '1 ALTER TABLE `treport_content` ADD COLUMN `current_month` TINYINT(1) DEFAULT '1'; ALTER TABLE `treport_content` ADD COLUMN `failover_mode` tinyint(1) DEFAULT '0'; ALTER TABLE `treport_content` ADD COLUMN `failover_type` tinyint(1) DEFAULT '0'; +ALTER table `treport_content` MODIFY COLUMN `name` varchar(300) NULL; -- --------------------------------------------------------------------- -- Table `tmodule_relationship` diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index b7a9c6295f..dd2e577fe3 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -77,6 +77,7 @@ if (is_ajax()) { } $get_modules_json_for_multiple_snmp = (bool) get_parameter('get_modules_json_for_multiple_snmp', 0); + $get_common_modules = (bool) get_parameter('get_common_modules', 1); if ($get_modules_json_for_multiple_snmp) { include_once 'include/graphs/functions_utils.php'; @@ -100,7 +101,16 @@ if (is_ajax()) { if ($out === false) { $out = $oid_snmp; } else { - $out = array_intersect($out, $oid_snmp); + $commons = array_intersect($out, $oid_snmp); + if ($get_common_modules) { + // Common modules is selected (default) + $out = $commons; + } else { + // All modules is selected + $array1 = array_diff($out, $oid_snmp); + $array2 = array_diff($oid_snmp, $out); + $out = array_merge($commons, $array1, $array2); + } } $oid_snmp = []; diff --git a/pandora_console/godmode/agentes/agent_wizard.snmp_interfaces_explorer.php b/pandora_console/godmode/agentes/agent_wizard.snmp_interfaces_explorer.php index 45d899822a..3eb404340e 100644 --- a/pandora_console/godmode/agentes/agent_wizard.snmp_interfaces_explorer.php +++ b/pandora_console/godmode/agentes/agent_wizard.snmp_interfaces_explorer.php @@ -608,7 +608,24 @@ if (!empty($interfaces_list)) { $table->data[0][2] = ''.__('Modules').''; $table->data[1][0] = html_print_select($interfaces_list, 'id_snmp[]', 0, false, '', '', true, true, true, '', false, 'width:500px; overflow: auto;'); - $table->data[1][1] = html_print_image('images/darrowright.png', true); + + $table->data[1][1] = __('When selecting interfaces'); + $table->data[1][1] .= '
'; + $table->data[1][1] .= html_print_select( + [ + 1 => __('Show common modules'), + 0 => __('Show all modules'), + ], + 'modules_selection_mode', + 1, + false, + '', + '', + true, + false, + false + ); + $table->data[1][2] = html_print_select([], 'module[]', 0, false, '', 0, true, true, true, '', false, 'width:200px;'); $table->data[1][2] .= html_print_input_hidden('agent', $id_agent, true); @@ -655,10 +672,17 @@ $(document).ready (function () { $("#no_snmp").hide (); $("#form_interfaces").hide (); }); + + // When select interfaces changes + $("#modules_selection_mode").change (function() { + $("#id_snmp").trigger('change'); + }); + }); function snmp_changed_by_multiple_snmp (event, id_snmp, selected) { var idSNMP = Array(); + var get_common_modules = $("#modules_selection_mode option:selected").val(); jQuery.each ($("#id_snmp option:selected"), function (i, val) { idSNMP.push($(val).val()); @@ -670,6 +694,7 @@ function snmp_changed_by_multiple_snmp (event, id_snmp, selected) { jQuery.post ('ajax.php', {"page" : "godmode/agentes/agent_manager", "get_modules_json_for_multiple_snmp": 1, + "get_common_modules" : get_common_modules, "id_snmp[]": idSNMP, "id_snmp_serialize": $("#hidden-id_snmp_serialize").val() }, diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index ba82b66c30..031c114b4a 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -868,7 +868,18 @@ $class = 'databox filters'; @@ -926,7 +937,18 @@ $class = 'databox filters'; diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index d499fc35df..74adca3139 100755 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -1344,6 +1344,16 @@ switch ($action) { switch ($action) { case 'update': $values = []; + $server_name = get_parameter('server_id'); + if (is_metaconsole() && $server_name != '') { + $id_meta = metaconsole_get_id_server($server_name); + $connection = metaconsole_get_connection_by_id( + $id_meta + ); + metaconsole_connect($connection); + $values['server_name'] = $connection['server_name']; + } + $values['id_report'] = $idReport; $values['description'] = get_parameter('description'); $values['type'] = get_parameter('type', null); @@ -1352,14 +1362,36 @@ switch ($action) { $label = get_parameter('label', ''); + $id_agent = get_parameter('id_agent'); + $id_agent_module = get_parameter('id_agent_module'); + // Add macros name. - $items_label = []; - $items_label['type'] = get_parameter('type'); - $items_label['id_agent'] = get_parameter('id_agent'); - $items_label['id_agent_module'] = get_parameter( - 'id_agent_module' - ); $name_it = (string) get_parameter('name'); + + $agent_description = agents_get_description($id_agent); + $agent_group = agents_get_agent_group($id_agent); + $agent_address = agents_get_address($id_agent); + $agent_alias = agents_get_alias($id_agent); + $module_name = modules_get_agentmodule_name( + $id_agent_module + ); + + $module_description = modules_get_agentmodule_descripcion( + $id_agent_module + ); + + $items_label = [ + 'type' => get_parameter('type'), + 'id_agent' => $id_agent, + 'id_agent_module' => $id_agent_module, + 'agent_description' => $agent_description, + 'agent_group' => $agent_group, + 'agent_address' => $agent_address, + 'agent_alias' => $agent_alias, + 'module_name' => $module_name, + 'module_description' => $module_description, + ]; + $values['name'] = reporting_label_macro( $items_label, $name_it @@ -1715,13 +1747,6 @@ switch ($action) { ); $values['id_group'] = get_parameter('combo_group'); $values['server_name'] = get_parameter('server_name'); - $server_id = (int) get_parameter('server_id'); - if ($server_id != 0) { - $connection = metaconsole_get_connection_by_id( - $server_id - ); - $values['server_name'] = $connection['server_name']; - } if ($values['server_name'] == '') { $values['server_name'] = get_parameter( @@ -1978,22 +2003,11 @@ switch ($action) { $values['style'] = io_safe_input(json_encode($style)); + if (is_metaconsole()) { + metaconsole_restore_db(); + } + if ($good_format) { - switch ($config['dbtype']) { - case 'oracle': - if (isset($values['type'])) { - $values[db_escape_key_identifier( - 'type' - )] = $values['type']; - unset($values['type']); - } - break; - - default: - // Default. - break; - } - $resultOperationDB = db_process_sql_update( 'treport_content', $values, @@ -2006,21 +2020,62 @@ switch ($action) { case 'save': $values = []; + + $values['server_name'] = get_parameter('server_name'); + $server_id = (int) get_parameter('server_id'); + if ($server_id != 0) { + $connection = metaconsole_get_connection_by_id( + $server_id + ); + metaconsole_connect($connection); + $values['server_name'] = $connection['server_name']; + } + $values['id_report'] = $idReport; $values['type'] = get_parameter('type', null); $values['description'] = get_parameter('description'); $label = get_parameter('label', ''); - // Add macros name. - $items_label = []; - $items_label['type'] = get_parameter('type'); - $items_label['id_agent'] = get_parameter('id_agent'); - $items_label['id_agent_module'] = get_parameter( - 'id_agent_module' - ); - $name_it = (string) get_parameter('name'); $values['recursion'] = get_parameter('recursion', null); - $values['show_extended_events'] = get_parameter('include_extended_events', null); + $values['show_extended_events'] = get_parameter( + 'include_extended_events', + null + ); + + $id_agent = get_parameter('id_agent'); + $id_agent_module = get_parameter('id_agent_module'); + + // Add macros name. + $name_it = (string) get_parameter('name'); + + $agent_description = agents_get_description($id_agent); + $agent_group = agents_get_agent_group($id_agent); + $agent_address = agents_get_address($id_agent); + $agent_alias = agents_get_alias($id_agent); + $module_name = modules_get_agentmodule_name( + $id_agent_module + ); + + $module_description = modules_get_agentmodule_descripcion( + $id_agent_module + ); + + if (is_metaconsole()) { + metaconsole_restore_db(); + } + + $items_label = [ + 'type' => get_parameter('type'), + 'id_agent' => $id_agent, + 'id_agent_module' => $id_agent_module, + 'agent_description' => $agent_description, + 'agent_group' => $agent_group, + 'agent_address' => $agent_address, + 'agent_alias' => $agent_alias, + 'module_name' => $module_name, + 'module_description' => $module_description, + ]; + $values['name'] = reporting_label_macro( $items_label, $name_it @@ -2225,18 +2280,6 @@ switch ($action) { break; } - - - $values['server_name'] = get_parameter('server_name'); - $server_id = (int) get_parameter('server_id'); - if ($server_id != 0) { - $connection = metaconsole_get_connection_by_id( - $server_id - ); - - $values['server_name'] = $connection['server_name']; - } - if ($values['server_name'] == '') { $values['server_name'] = get_parameter( 'combo_server' diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index a07af2ff1e..fdcce4457a 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -1513,29 +1513,30 @@ function agents_get_name($id_agent, $case='none') * Get alias of an agent (cached function). * * @param integer $id_agent Agent id. - * @param string $case Case (upper, lower, none) + * @param string $case Case (upper, lower, none). * * @return string Alias of the given agent. */ function agents_get_alias($id_agent, $case='none') { global $config; - // Prepare cache + // Prepare cache. static $cache = []; if (empty($case)) { $case = 'none'; } - // Check cache + // Check cache. if (isset($cache[$case][$id_agent])) { return $cache[$case][$id_agent]; } - if (is_metaconsole()) { - $alias = (string) db_get_value('alias', 'tmetaconsole_agent', 'id_tagente', (int) $id_agent); - } else { - $alias = (string) db_get_value('alias', 'tagente', 'id_agente', (int) $id_agent); - } + $alias = (string) db_get_value( + 'alias', + 'tagente', + 'id_agente', + (int) $id_agent + ); switch ($case) { case 'upper': @@ -1545,6 +1546,10 @@ function agents_get_alias($id_agent, $case='none') case 'lower': $alias = mb_strtolower($alias, 'UTF-8'); break; + + default: + // Not posible. + break; } $cache[$case][$id_agent] = $alias; diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 51acf8c450..d6ce0ba8af 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -1277,12 +1277,34 @@ function graphic_combined_module( array_push($modules, $source['id_agent_module']); array_push($weights, $source['weight']); if ($source['label'] != '' || $params_combined['labels']) { - $item['type'] = 'custom_graph'; - $item['id_agent'] = agents_get_module_id( + $id_agent = agents_get_module_id( $source['id_agent_module'] ); - $item['id_agent_module'] = $source['id_agent_module']; - $labels[$source['id_agent_module']] = ($source['label'] != '') ? reporting_label_macro($item, $source['label']) : reporting_label_macro($item, $params_combined['labels']); + $agent_description = agents_get_description($id_agent); + $agent_group = agents_get_agent_group($id_agent); + $agent_address = agents_get_address($id_agent); + $agent_alias = agents_get_alias($id_agent); + $module_name = modules_get_agentmodule_name( + $source['id_agent_module'] + ); + + $module_description = modules_get_agentmodule_descripcion( + $source['id_agent_module'] + ); + + $items_label = [ + 'type' => 'custom_graph', + 'id_agent' => $id_agent, + 'id_agent_module' => $source['id_agent_module'], + 'agent_description' => $agent_description, + 'agent_group' => $agent_group, + 'agent_address' => $agent_address, + 'agent_alias' => $agent_alias, + 'module_name' => $module_name, + 'module_description' => $module_description, + ]; + + $labels[$source['id_agent_module']] = ($source['label'] != '') ? reporting_label_macro($items_label, $source['label']) : reporting_label_macro($item, $params_combined['labels']); } } } diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 97766305a2..083be8b063 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -251,12 +251,16 @@ function reporting_make_reporting_data( if ($metaconsole_on && $server_name != '') { $connection = metaconsole_get_connection($server_name); if (!metaconsole_load_external_db($connection)) { - // ui_print_error_message ("Error connecting to ".$server_name); continue; } } - array_push($agents_to_macro, modules_get_agentmodule_agent($graph_item['id_agent_module'])); + array_push( + $agents_to_macro, + modules_get_agentmodule_agent( + $graph_item['id_agent_module'] + ) + ); if ($metaconsole_on) { // Restore db connection. metaconsole_restore_db(); @@ -296,33 +300,54 @@ function reporting_make_reporting_data( if (!metaconsole_load_external_db($connection)) { continue; } + } - $items_label['agent_description'] = agents_get_description($content['id_agent']); - $items_label['agent_group'] = agents_get_agent_group($content['id_agent']); - $items_label['agent_address'] = agents_get_address($content['id_agent']); + $items_label['agent_description'] = agents_get_description( + $content['id_agent'] + ); + $items_label['agent_group'] = agents_get_agent_group( + $content['id_agent'] + ); + $items_label['agent_address'] = agents_get_address( + $content['id_agent'] + ); + $items_label['agent_alias'] = agents_get_alias( + $content['id_agent'] + ); - $modules = agents_get_modules( - $agent_value, - [ - 'id_agente_modulo', - 'nombre', - 'descripcion', - ], - [ - 'id_agente_modulo' => $content['id_agent_module'], - ] + $modules = agents_get_modules( + $agent_value, + [ + 'id_agente_modulo', + 'nombre', + 'descripcion', + ], + [ + 'id_agente_modulo' => $content['id_agent_module'], + ] + ); + + $items_label['module_name'] = $modules[$content['id_agent_module']]['nombre']; + $items_label['module_description'] = $modules[$content['id_agent_module']]['descripcion']; + + if (is_array($content['id_agent']) + && count($content['id_agent']) != 1 + ) { + $content['style']['name_label'] = str_replace( + '_agent_', + count($content['id_agent']).__(' agents'), + $content['style']['name_label'] ); - - $items_label['module_name'] = $modules[$content['id_agent_module']]['nombre']; - $items_label['module_description'] = $modules[$content['id_agent_module']]['descripcion']; } - if (is_array($content['id_agent']) && count($content['id_agent']) != 1) { - $content['style']['name_label'] = str_replace('_agent_', count($content['id_agent']).__(' agents'), $content['style']['name_label']); - } - - if (is_array($content['id_agent_module']) && count($content['id_agent_module']) != 1) { - $content['style']['name_label'] = str_replace('_module_', count($content['id_agent_module']).__(' modules'), $content['style']['name_label']); + if (is_array($content['id_agent_module']) + && count($content['id_agent_module']) != 1 + ) { + $content['style']['name_label'] = str_replace( + '_module_', + count($content['id_agent_module']).__(' modules'), + $content['style']['name_label'] + ); } if ($metaconsole_on) { @@ -330,7 +355,10 @@ function reporting_make_reporting_data( metaconsole_restore_db(); } - $content['name'] = reporting_label_macro($items_label, $content['style']['name_label']); + $content['name'] = reporting_label_macro( + $items_label, + $content['style']['name_label'] + ); } switch (reporting_get_type($content)) { @@ -1926,6 +1954,18 @@ function reporting_event_report_group( } +/** + * Events for module reports. + * + * @param array $report Report info. + * @param array $content Content info. + * @param string $type Type retun report. + * @param integer $force_width_chart Width chart. + * @param integer $force_height_chart Height chart. + * @param integer $pdf If pdf report. + * + * @return array + */ function reporting_event_report_module( $report, $content, @@ -1954,12 +1994,42 @@ function reporting_event_report_module( metaconsole_connect(null, $id_server); } - $return['title'] = $content['name']; - $return['subtitle'] = agents_get_alias($content['id_agent']).' - '.io_safe_output(modules_get_agentmodule_name($content['id_agent_module'])); + $id_agent = agents_get_module_id( + $content['id_agent_module'] + ); + $id_agent_module = $content['id_agent_module']; + $agent_description = agents_get_description($id_agent); + $agent_group = agents_get_agent_group($id_agent); + $agent_address = agents_get_address($id_agent); + $agent_alias = agents_get_alias($id_agent); + $module_name = modules_get_agentmodule_name( + $id_agent_module + ); + $module_description = modules_get_agentmodule_descripcion( + $id_agent_module + ); + $items_label = [ + 'type' => $content['type'], + 'id_agent' => $id_agent, + 'id_agent_module' => $id_agent_module, + 'agent_description' => $agent_description, + 'agent_group' => $agent_group, + 'agent_address' => $agent_address, + 'agent_alias' => $agent_alias, + 'module_name' => $module_name, + 'module_description' => $module_description, + ]; + + $return['title'] = $content['name']; + $return['subtitle'] = $agent_alias.' - '.io_safe_output($module_name); $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; + if ($return['label'] != '') { - $return['label'] = reporting_label_macro($content, $return['label']); + $return['label'] = reporting_label_macro( + $items_label, + $return['label'] + ); } if (is_metaconsole()) { @@ -1973,15 +2043,24 @@ function reporting_event_report_module( $event_filter = $content['style']; $return['show_summary_group'] = $event_filter['show_summary_group']; // Filter. - $show_summary_group = $event_filter['show_summary_group']; - $filter_event_severity = json_decode($event_filter['filter_event_severity'], true); - $filter_event_type = json_decode($event_filter['filter_event_type'], true); - $filter_event_status = json_decode($event_filter['filter_event_status'], true); + $show_summary_group = $event_filter['show_summary_group']; + $filter_event_severity = json_decode( + $event_filter['filter_event_severity'], + true + ); + $filter_event_type = json_decode( + $event_filter['filter_event_type'], + true + ); + $filter_event_status = json_decode( + $event_filter['filter_event_status'], + true + ); $filter_event_filter_search = $event_filter['event_filter_search']; // Graphs. - $event_graph_by_user_validator = $event_filter['event_graph_by_user_validator']; - $event_graph_by_criticity = $event_filter['event_graph_by_criticity']; + $event_graph_by_user_validator = $event_filter['event_graph_by_user_validator']; + $event_graph_by_criticity = $event_filter['event_graph_by_criticity']; $event_graph_validated_vs_unvalidated = $event_filter['event_graph_validated_vs_unvalidated']; $server_name = $content['server_name']; @@ -2819,8 +2898,42 @@ function reporting_event_report_agent( $history = true; } + $id_server = false; + if (is_metaconsole()) { + $id_server = metaconsole_get_id_server($content['server_name']); + metaconsole_connect(null, $id_server); + } + + $id_agent = $content['id_agent']; + $agent_description = agents_get_description($id_agent); + $agent_group = agents_get_agent_group($id_agent); + $agent_address = agents_get_address($id_agent); + $agent_alias = agents_get_alias($id_agent); + + $items_label = [ + 'type' => $return['type'], + 'id_agent' => $id_agent, + 'agent_description' => $agent_description, + 'agent_group' => $agent_group, + 'agent_address' => $agent_address, + 'agent_alias' => $agent_alias, + ]; + + if ($config['metaconsole']) { + metaconsole_restore_db(); + } + + $label = (isset($content['style']['label'])) ? $content['style']['label'] : ''; + if ($label != '') { + $label = reporting_label_macro( + $items_label, + $label + ); + } + + $return['label'] = $label; $return['title'] = $content['name']; - $return['subtitle'] = io_safe_output(agents_get_alias($content['id_agent'])); + $return['subtitle'] = io_safe_output($agent_alias); $return['description'] = $content['description']; $return['date'] = reporting_get_date_text($report, $content); @@ -2883,13 +2996,6 @@ function reporting_event_report_agent( $metaconsole_dbtable = false; } - $label = (isset($content['style']['label'])) ? $content['style']['label'] : ''; - if ($label != '') { - $label = reporting_label_macro($content, $label); - } - - $return['label'] = $label; - if ($event_graph_by_user_validator) { $data_graph = events_get_count_events_validated_by_user( ['id_agent' => $content['id_agent']], @@ -2969,10 +3075,6 @@ function reporting_event_report_agent( ); } - if ($config['metaconsole']) { - metaconsole_restore_db(); - } - // Total events. if ($return['data'] != '') { $return['total_events'] = count($return['data']); @@ -2984,6 +3086,14 @@ function reporting_event_report_agent( } +/** + * Show historical data. + * + * @param array $report Data report. + * @param array $content Content report. + * + * @return array + */ function reporting_historical_data($report, $content) { global $config; @@ -2995,21 +3105,46 @@ function reporting_historical_data($report, $content) $content['name'] = __('Historical data'); } - $module_name = io_safe_output( - modules_get_agentmodule_name($content['id_agent_module']) + $id_agent = agents_get_module_id( + $content['id_agent_module'] ); - $agent_name = io_safe_output( - modules_get_agentmodule_agent_alias($content['id_agent_module']) + $id_agent_module = $content['id_agent_module']; + $agent_description = agents_get_description($id_agent); + $agent_group = agents_get_agent_group($id_agent); + $agent_address = agents_get_address($id_agent); + $agent_alias = io_safe_output(agents_get_alias($id_agent)); + $module_name = io_safe_output( + modules_get_agentmodule_name( + $id_agent_module + ) + ); + $module_description = modules_get_agentmodule_descripcion( + $id_agent_module ); + $items_label = [ + 'type' => $return['type'], + 'id_agent' => $id_agent, + 'id_agent_module' => $id_agent_module, + 'agent_description' => $agent_description, + 'agent_group' => $agent_group, + 'agent_address' => $agent_address, + 'agent_alias' => $agent_alias, + 'module_name' => $module_name, + 'module_description' => $module_description, + ]; + $return['title'] = $content['name']; - $return['subtitle'] = $agent_name.' - '.$module_name; + $return['subtitle'] = $agent_alias.' - '.$module_name; $return['description'] = $content['description']; $return['date'] = reporting_get_date_text($report, $content); $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; if ($return['label'] != '') { - $return['label'] = reporting_label_macro($content, $return['label']); + $return['label'] = reporting_label_macro( + $items_label, + $return['label'] + ); } $return['keys'] = [ @@ -3065,6 +3200,14 @@ function reporting_historical_data($report, $content) } +/** + * Show data serialized. + * + * @param array $report Data report. + * @param array $content Content report. + * + * @return array + */ function reporting_database_serialized($report, $content) { global $config; @@ -3075,15 +3218,43 @@ function reporting_database_serialized($report, $content) $content['name'] = __('Database Serialized'); } - $module_name = io_safe_output( - modules_get_agentmodule_name($content['id_agent_module']) - ); - $agent_name = io_safe_output( - modules_get_agentmodule_agent_alias($content['id_agent_module']) + if (is_metaconsole()) { + $id_meta = metaconsole_get_id_server($content['server_name']); + $server = metaconsole_get_connection_by_id($id_meta); + metaconsole_connect($server); + } + + $id_agent = agents_get_module_id( + $content['id_agent_module'] ); + $id_agent_module = $content['id_agent_module']; + $agent_description = agents_get_description($id_agent); + $agent_group = agents_get_agent_group($id_agent); + $agent_address = agents_get_address($id_agent); + $agent_alias = agents_get_alias($id_agent); + $module_name = modules_get_agentmodule_name( + $id_agent_module + ); + + $module_description = modules_get_agentmodule_descripcion( + $id_agent_module + ); + + $items_label = [ + 'type' => $return['type'], + 'id_agent' => $id_agent, + 'id_agent_module' => $id_agent_module, + 'agent_description' => $agent_description, + 'agent_group' => $agent_group, + 'agent_address' => $agent_address, + 'agent_alias' => $agent_alias, + 'module_name' => $module_name, + 'module_description' => $module_description, + ]; + $return['title'] = $content['name']; - $return['subtitle'] = $agent_name.' - '.$module_name; + $return['subtitle'] = $agent_alias.' - '.$module_name; $return['description'] = $content['description']; $return['date'] = reporting_get_date_text($report, $content); @@ -3093,33 +3264,21 @@ function reporting_database_serialized($report, $content) } $return['keys'] = $keys; - - $module_name = io_safe_output( - modules_get_agentmodule_name($content['id_agent_module']) - ); - $agent_name = io_safe_output( - modules_get_agentmodule_agent_name($content['id_agent_module']) - ); - - $return['agent_name'] = $agent_name; + $return['agent_name'] = $agent_alias; $return['module_name'] = $module_name; - if ($config['metaconsole']) { - $id_meta = metaconsole_get_id_server($content['server_name']); - - $server = metaconsole_get_connection_by_id($id_meta); - metaconsole_connect($server); - } - $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; if ($return['label'] != '') { - $return['label'] = reporting_label_macro($content, $return['label']); + $return['label'] = reporting_label_macro( + $items_label, + $return['label'] + ); } $datelimit = ($report['datetime'] - $content['period']); $search_in_history_db = db_search_in_history_db($datelimit); - // This query gets information from the default and the historic database + // This query gets information from the default and the historic database. $result = db_get_all_rows_sql( 'SELECT * FROM tagente_datos @@ -3129,9 +3288,9 @@ function reporting_database_serialized($report, $content) $search_in_history_db ); - // Adds string data if there is no numeric data - if ((count($result) < 0) or (!$result)) { - // This query gets information from the default and the historic database + // Adds string data if there is no numeric data. + if ((count($result) < 0) || (!$result)) { + // This query gets information from the default and the historic database. $result = db_get_all_rows_sql( 'SELECT * FROM tagente_datos_string @@ -3151,13 +3310,16 @@ function reporting_database_serialized($report, $content) $date = date($config['date_format'], $row['utimestamp']); $serialized_data = $row['datos']; - // Cut line by line + // Cut line by line. if (empty($content['line_separator']) || empty($serialized_data) ) { $rowsUnserialize = [$row['datos']]; } else { - $rowsUnserialize = explode($content['line_separator'], $serialized_data); + $rowsUnserialize = explode( + $content['line_separator'], + $serialized_data + ); } foreach ($rowsUnserialize as $rowUnser) { @@ -3173,7 +3335,10 @@ function reporting_database_serialized($report, $content) $row['data'][][$keys[0]] = $rowUnser; } } else { - $columnsUnserialize = explode($content['column_separator'], $rowUnser); + $columnsUnserialize = explode( + $content['column_separator'], + $rowUnser + ); $i = 0; $temp_row = []; @@ -3639,6 +3804,14 @@ function reporting_alert_report_group($report, $content) } +/** + * Report alert agent. + * + * @param array $report Info report. + * @param array $content Content report. + * + * @return array + */ function reporting_alert_report_agent($report, $content) { global $config; @@ -3656,16 +3829,33 @@ function reporting_alert_report_agent($report, $content) metaconsole_connect($server); } - $agent_name = agents_get_alias($content['id_agent']); + $id_agent = $content['id_agent']; + $agent_description = agents_get_description($id_agent); + $agent_group = agents_get_agent_group($id_agent); + $agent_address = agents_get_address($id_agent); + $agent_alias = agents_get_alias($id_agent); + + $items_label = [ + 'type' => $return['type'], + 'id_agent' => $id_agent, + 'id_agent_module' => $id_agent_module, + 'agent_description' => $agent_description, + 'agent_group' => $agent_group, + 'agent_address' => $agent_address, + 'agent_alias' => $agent_alias, + ]; $return['title'] = $content['name']; - $return['subtitle'] = $agent_name; + $return['subtitle'] = $agent_alias; $return['description'] = $content['description']; $return['date'] = reporting_get_date_text($report, $content); $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; if ($return['label'] != '') { - $return['label'] = reporting_label_macro($content, $return['label']); + $return['label'] = reporting_label_macro( + $items_label, + $return['label'] + ); } $module_list = agents_get_modules($content['id_agent']); @@ -3673,10 +3863,10 @@ function reporting_alert_report_agent($report, $content) $data = []; foreach ($module_list as $id => $module_name) { $data_row = []; - $data_row['agent'] = $agent_name; + $data_row['agent'] = $agent_alias; $data_row['module'] = $module_name; - // Alerts over $id_agent_module + // Alerts over $id_agent_module. $alerts = alerts_get_effective_alert_actions($id); if ($alerts === false) { @@ -3770,6 +3960,14 @@ function reporting_alert_report_agent($report, $content) } +/** + * Alert report module. + * + * @param array $report Info report. + * @param array $content Content report. + * + * @return array + */ function reporting_alert_report_module($report, $content) { global $config; @@ -3787,36 +3985,56 @@ function reporting_alert_report_module($report, $content) metaconsole_connect($server); } - $module_name = io_safe_output( - modules_get_agentmodule_name($content['id_agent_module']) + $id_agent = agents_get_module_id( + $content['id_agent_module'] ); - $agent_name = io_safe_output( - modules_get_agentmodule_agent_alias($content['id_agent_module']) + $id_agent_module = $content['id_agent_module']; + $agent_description = agents_get_description($id_agent); + $agent_group = agents_get_agent_group($id_agent); + $agent_address = agents_get_address($id_agent); + $agent_alias = agents_get_alias($id_agent); + $module_name = modules_get_agentmodule_name( + $id_agent_module ); + $module_description = modules_get_agentmodule_descripcion( + $id_agent_module + ); + + $items_label = [ + 'type' => $return['type'], + 'id_agent' => $id_agent, + 'id_agent_module' => $id_agent_module, + 'agent_description' => $agent_description, + 'agent_group' => $agent_group, + 'agent_address' => $agent_address, + 'agent_alias' => $agent_alias, + 'module_name' => $module_name, + 'module_description' => $module_description, + ]; + $return['title'] = $content['name']; - $return['subtitle'] = $agent_name.' - '.$module_name; + $return['subtitle'] = $agent_alias.' - '.$module_name; $return['description'] = $content['description']; $return['date'] = reporting_get_date_text($report, $content); $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; if ($return['label'] != '') { - $return['label'] = reporting_label_macro($content, $return['label']); + $return['label'] = reporting_label_macro( + $items_label, + $return['label'] + ); } $data_row = []; - $data_row['agent'] = io_safe_output( - agents_get_alias( - agents_get_agent_id_by_module_id($content['id_agent_module']) - ) - ); + $data_row['agent'] = io_safe_output($agent_alias); $data_row['module'] = db_get_value_filter( 'nombre', 'tagente_modulo', ['id_agente_modulo' => $content['id_agent_module']] ); - // Alerts over $id_agent_module + // Alerts over $id_agent_module. $alerts = alerts_get_effective_alert_actions($content['id_agent_module']); $ntemplates = 0; @@ -3945,7 +4163,7 @@ function reporting_sql_graph( } } - // Get chart + // Get chart. reporting_set_conf_charts($width, $height, $only_image, $type, $content, $ttl); if (!empty($force_width_chart)) { @@ -3983,6 +4201,14 @@ function reporting_sql_graph( } +/** + * Monitor report module. + * + * @param array $report Info report. + * @param array $content Content report. + * + * @return array + */ function reporting_monitor_report($report, $content) { global $config; @@ -3993,48 +4219,67 @@ function reporting_monitor_report($report, $content) $content['name'] = __('Monitor Report'); } - $module_name = io_safe_output( - modules_get_agentmodule_name($content['id_agent_module']) - ); - $agent_name = io_safe_output( - modules_get_agentmodule_agent_alias($content['id_agent_module']) - ); - - $return['title'] = $content['name']; - $return['subtitle'] = $agent_name.' - '.$module_name; - $return['description'] = $content['description']; - $return['date'] = reporting_get_date_text($report, $content); - - if ($config['metaconsole']) { + if (is_metaconsole()) { $id_meta = metaconsole_get_id_server($content['server_name']); $server = metaconsole_get_connection_by_id($id_meta); metaconsole_connect($server); } + $id_agent = agents_get_module_id( + $content['id_agent_module'] + ); + $id_agent_module = $content['id_agent_module']; + $agent_description = agents_get_description($id_agent); + $agent_group = agents_get_agent_group($id_agent); + $agent_address = agents_get_address($id_agent); + $agent_alias = agents_get_alias($id_agent); + $module_name = modules_get_agentmodule_name( + $id_agent_module + ); + + $module_description = modules_get_agentmodule_descripcion( + $id_agent_module + ); + + $items_label = [ + 'type' => $return['type'], + 'id_agent' => $id_agent, + 'id_agent_module' => $id_agent_module, + 'agent_description' => $agent_description, + 'agent_group' => $agent_group, + 'agent_address' => $agent_address, + 'agent_alias' => $agent_alias, + 'module_name' => $module_name, + 'module_description' => $module_description, + ]; + + $return['title'] = $content['name']; + $return['subtitle'] = $agent_alias.' - '.$module_name; + $return['description'] = $content['description']; + $return['date'] = reporting_get_date_text($report, $content); + $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; if ($return['label'] != '') { - $return['label'] = reporting_label_macro($content, $return['label']); + $return['label'] = reporting_label_macro( + $items_label, + $return['label'] + ); } - $module_name = io_safe_output( - modules_get_agentmodule_name($content['id_agent_module']) - ); - $agent_name = io_safe_output( - modules_get_agentmodule_agent_name($content['id_agent_module']) - ); - - $return['agent_name'] = $agent_name; + $return['agent_name'] = $agent_alias; $return['module_name'] = $module_name; - // All values (except id module and report time) by default + // All values (except id module and report time) by default. $report = reporting_advanced_sla( $content['id_agent_module'], ($report['datetime'] - $content['period']), $report['datetime'] ); - if ($report['time_total'] === $report['time_unknown'] || empty($content['id_agent_module'])) { + if ($report['time_total'] === $report['time_unknown'] + || empty($content['id_agent_module']) + ) { $return['data']['unknown'] = 1; } else { $return['data']['ok']['value'] = $report['SLA']; @@ -7572,6 +7817,17 @@ function reporting_custom_graph( } +/** + * Simple graph report. + * + * @param array $report Info report. + * @param array $content Content report. + * @param string $type Type report. + * @param integer $force_width_chart Width chart. + * @param integer $force_height_chart Height chart. + * + * @return array + */ function reporting_simple_graph( $report, $content, @@ -7581,13 +7837,6 @@ function reporting_simple_graph( ) { global $config; - if ($config['metaconsole']) { - $id_meta = metaconsole_get_id_server($content['server_name']); - - $server = metaconsole_get_connection_by_id($id_meta); - metaconsole_connect($server); - } - $return = []; $return['type'] = 'simple_graph'; @@ -7595,16 +7844,52 @@ function reporting_simple_graph( $content['name'] = __('Simple graph'); } - $module_name = io_safe_output( - modules_get_agentmodule_name($content['id_agent_module']) + if ($config['metaconsole']) { + $id_meta = metaconsole_get_id_server($content['server_name']); + + $server = metaconsole_get_connection_by_id($id_meta); + metaconsole_connect($server); + } + + $id_agent = agents_get_module_id( + $content['id_agent_module'] ); - $agent_name = io_safe_output( - modules_get_agentmodule_agent_alias($content['id_agent_module']) + $id_agent_module = $content['id_agent_module']; + $agent_description = agents_get_description($id_agent); + $agent_group = agents_get_agent_group($id_agent); + $agent_address = agents_get_address($id_agent); + $agent_alias = agents_get_alias($id_agent); + $module_name = modules_get_agentmodule_name( + $id_agent_module ); + $module_description = modules_get_agentmodule_descripcion( + $id_agent_module + ); + + $items_label = [ + 'type' => $return['type'], + 'id_agent' => $id_agent, + 'id_agent_module' => $id_agent_module, + 'agent_description' => $agent_description, + 'agent_group' => $agent_group, + 'agent_address' => $agent_address, + 'agent_alias' => $agent_alias, + 'module_name' => $module_name, + 'module_description' => $module_description, + ]; + + $label = (isset($content['style']['label'])) ? $content['style']['label'] : ''; + if ($label != '') { + $label = reporting_label_macro( + $items_label, + $label + ); + } + $return['title'] = $content['name']; - $return['subtitle'] = $agent_name.' - '.$module_name; - $return['agent_name'] = $agent_name; + $return['subtitle'] = $agent_alias.' - '.$module_name; + $return['agent_name'] = $agent_alias; $return['module_name'] = $module_name; $return['description'] = $content['description']; $return['date'] = reporting_get_date_text( @@ -7612,11 +7897,6 @@ function reporting_simple_graph( $content ); - $label = (isset($content['style']['label'])) ? $content['style']['label'] : ''; - if ($label != '') { - $label = reporting_label_macro($content, $label); - } - if (isset($content['style']['fullscale'])) { $fullscale = (bool) $content['style']['fullscale']; } @@ -7624,7 +7904,14 @@ function reporting_simple_graph( $return['chart'] = ''; // Get chart. - reporting_set_conf_charts($width, $height, $only_image, $type, $content, $ttl); + reporting_set_conf_charts( + $width, + $height, + $only_image, + $type, + $content, + $ttl + ); if (!empty($force_width_chart)) { $width = $force_width_chart; @@ -7650,7 +7937,12 @@ function reporting_simple_graph( 'pure' => false, 'date' => $report['datetime'], 'only_image' => $only_image, - 'homeurl' => ui_get_full_url(false, false, false, false), + 'homeurl' => ui_get_full_url( + false, + false, + false, + false + ), 'ttl' => $ttl, 'compare' => $time_compare_overlapped, 'show_unknown' => true, @@ -7661,7 +7953,6 @@ function reporting_simple_graph( ]; $return['chart'] = grafico_modulo_sparse($params); - break; case 'data': @@ -7675,6 +7966,10 @@ function reporting_simple_graph( $return['chart'][$d['utimestamp']] = $d['data']; } break; + + default: + // Not Possible. + break; } if ($config['metaconsole']) { @@ -11713,149 +12008,72 @@ function reporting_get_agentmodule_sla_working_timestamp($period, $date_end, $wt } +/** + * Convert macros for value. + * Item content: + * type + * id_agent + * id_agent_module + * agent_description + * agent_group + * agent_address + * agent_alias + * module_name + * module_description. + * + * @param array $item Data to replace in the macros. + * @param string $label String check macros. + * + * @return string + */ function reporting_label_macro($item, $label) { - switch ($item['type']) { - case 'event_report_agent': - case 'alert_report_agent': - case 'agent_configuration': - case 'event_report_log': - if (preg_match('/_agent_/', $label)) { - $agent_name = agents_get_alias($item['id_agent']); - $label = str_replace('_agent_', $agent_name, $label); - } + if (preg_match('/_agent_/', $label)) { + $label = str_replace( + '_agent_', + $item['agent_alias'], + $label + ); + } - if (preg_match('/_agentdescription_/', $label)) { - if (!is_metaconsole()) { - $agent_name = agents_get_description($item['id_agent']); - } else { - $agent_name = $item['agent_description']; - } + if (preg_match('/_agentdescription_/', $label)) { + $label = str_replace( + '_agentdescription_', + $item['agent_description'], + $label + ); + } - $label = str_replace('_agentdescription_', $agent_name, $label); - } + if (preg_match('/_agentgroup_/', $label)) { + $label = str_replace( + '_agentgroup_', + $item['agent_group'], + $label + ); + } - if (preg_match('/_agentgroup_/', $label)) { - if (!is_metaconsole()) { - $agent_name = groups_get_name(agents_get_agent_group($item['id_agent']), true); - } else { - $agent_name = $item['agent_group']; - } + if (preg_match('/_address_/', $label)) { + $label = str_replace( + '_address_', + $item['agent_address'], + $label + ); + } - $label = str_replace('_agentgroup_', $agent_name, $label); - } + if (preg_match('/_module_/', $label)) { + $label = str_replace( + '_module_', + $item['module_name'], + $label + ); + } - if (preg_match('/_address_/', $label)) { - if (!is_metaconsole()) { - $agent_name = agents_get_address($item['id_agent']); - } else { - $agent_name = $item['agent_address']; - } - - $label = str_replace('_address_', $agent_name, $label); - } - break; - - case 'simple_graph': - case 'module_histogram_graph': - case 'custom_graph': - case 'simple_baseline_graph': - case 'event_report_module': - case 'alert_report_module': - case 'historical_data': - case 'sumatory': - case 'database_serialized': - case 'monitor_report': - case 'min_value': - case 'max_value': - case 'avg_value': - case 'projection_graph': - case 'prediction_date': - case 'TTRT': - case 'TTO': - case 'MTBF': - case 'MTTR': - case 'automatic_graph': - if (preg_match('/_agent_/', $label)) { - if (isset($item['agents']) && count($item['agents']) > 1) { - $agent_name = count($item['agents']).__(' agents'); - } else { - $agent_name = agents_get_alias($item['id_agent']); - } - - $label = str_replace('_agent_', $agent_name, $label); - } - - if (preg_match('/_agentdescription_/', $label)) { - if (count($item['agents']) > 1) { - $agent_name = ''; - } else { - if (!is_metaconsole()) { - $agent_name = agents_get_description($item['id_agent']); - } else { - $agent_name = $item['agent_description']; - } - } - - $label = str_replace('_agentdescription_', $agent_name, $label); - } - - if (preg_match('/_agentgroup_/', $label)) { - if (count($item['agents']) > 1) { - $agent_name = ''; - } else { - if (!is_metaconsole()) { - $agent_name = groups_get_name(agents_get_agent_group($item['id_agent']), true); - } else { - $agent_name = $item['agent_group']; - } - } - - $label = str_replace('_agentgroup_', $agent_name, $label); - } - - if (preg_match('/_address_/', $label)) { - if (count($item['agents']) > 1) { - $agent_name = ''; - } else { - if (!is_metaconsole()) { - $agent_name = agents_get_address($item['id_agent']); - } else { - $agent_name = $item['agent_address']; - } - } - - $label = str_replace('_address_', $agent_name, $label); - } - - if (preg_match('/_module_/', $label)) { - if ($item['modules'] > 1) { - $module_name = $item['modules'].__(' modules'); - } else { - if (!is_metaconsole()) { - $module_name = modules_get_agentmodule_name($item['id_agent_module']); - } else { - $module_name = $item['module_name']; - } - } - - $label = str_replace('_module_', $module_name, $label); - } - - if (preg_match('/_moduledescription_/', $label)) { - if ($item['modules'] > 1) { - $module_description = ''; - } else { - if (!is_metaconsole()) { - $module_description = modules_get_agentmodule_descripcion($item['id_agent_module']); - } else { - $module_description = $item['module_description']; - } - } - - $label = str_replace('_moduledescription_', $module_description, $label); - } - break; + if (preg_match('/_moduledescription_/', $label)) { + $label = str_replace( + '_moduledescription_', + $item['module_description'], + $label + ); } return $label; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 516bd4865f..6a7d60c620 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -141,6 +141,15 @@ function html_do_report_info($report) } +/** + * Print html report. + * + * @param array $report Info. + * @param boolean $mini Type. + * @param integer $report_info Show info. + * + * @return array + */ function reporting_html_print_report($report, $mini=false, $report_info=1) { if ($report_info == 1) { @@ -161,7 +170,38 @@ function reporting_html_print_report($report, $mini=false, $report_info=1) $table->rowstyle = []; if (isset($item['label']) && $item['label'] != '') { - $label = reporting_label_macro($item, $item['label']); + $id_agent = $item['id_agent']; + $id_agent_module = $item['id_agent_module']; + + // Add macros name. + $agent_description = agents_get_description($id_agent); + $agent_group = agents_get_agent_group($id_agent); + $agent_address = agents_get_address($id_agent); + $agent_alias = agents_get_alias($id_agent); + $module_name = modules_get_agentmodule_name( + $id_agent_module + ); + + $module_description = modules_get_agentmodule_descripcion( + $id_agent_module + ); + + $items_label = [ + 'type' => $item['type'], + 'id_agent' => $id_agent, + 'id_agent_module' => $id_agent_module, + 'agent_description' => $agent_description, + 'agent_group' => $agent_group, + 'agent_address' => $agent_address, + 'agent_alias' => $agent_alias, + 'module_name' => $module_name, + 'module_description' => $module_description, + ]; + + $label = reporting_label_macro( + $items_label, + $item['label'] + ); } else { $label = ''; } @@ -180,7 +220,10 @@ function reporting_html_print_report($report, $mini=false, $report_info=1) $table->data['description_row']['description'] = $item['description']; - if ($item['type'] == 'event_report_agent' || $item['type'] == 'event_report_group' || $item['type'] == 'event_report_module') { + if ($item['type'] == 'event_report_agent' + || $item['type'] == 'event_report_group' + || $item['type'] == 'event_report_module' + ) { $table->data['count_row']['count'] = 'Total events: '.$item['total_events']; } diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 362f827e4c..94c7a49689 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -5866,3 +5866,7 @@ table.table_modal_alternate tr td:first-child { padding-left: 20px; } /* END - Table for show more info in events and config menu in modules graphs */ + +.fullwidth { + width: 100%; +} diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 95d6caadfd..656a83a3e2 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -1402,8 +1402,8 @@ CREATE TABLE IF NOT EXISTS `treport_content` ( `type` varchar(30) default 'simple_graph', `period` int(11) NOT NULL default 0, `order` int (11) NOT NULL default 0, - `name` varchar(150) NULL, - `description` mediumtext, + `name` varchar(300) NULL, + `description` mediumtext, `id_agent` int(10) unsigned NOT NULL default 0, `text` TEXT, `external_source` Text,