From 2ab1aa601c7d8220a3f7c9b021c14d719f1578b2 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 20 Apr 2022 14:10:23 +0200 Subject: [PATCH 01/26] Service tree view with local scope parents --- pandora_console/general/header.php | 2 +- .../include/class/TreeService.class.php | 2 + pandora_console/include/functions.php | 50 +++++++++++++++++++ .../include/javascript/tree/TreeController.js | 3 +- 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/pandora_console/general/header.php b/pandora_console/general/header.php index 9b0333c55a..5e2ad24ce2 100644 --- a/pandora_console/general/header.php +++ b/pandora_console/general/header.php @@ -954,7 +954,7 @@ echo sprintf('
', $menuTypeClass); $("a.autorefresh").click (function () { $("a.autorefresh_txt").toggle (); - $("#combo_refr").toggle (); + $("#combo_refr").toggle(); $("select#ref").change (function () { href = $("a.autorefresh").attr ("href"); diff --git a/pandora_console/include/class/TreeService.class.php b/pandora_console/include/class/TreeService.class.php index ebca4562a6..e69862a9fd 100644 --- a/pandora_console/include/class/TreeService.class.php +++ b/pandora_console/include/class/TreeService.class.php @@ -523,6 +523,8 @@ class TreeService extends Tree continue 2; } + $tmp['parents'] = $item->service()->getAncestors(); + $tmp['title'] = join('/', $tmp['parents']); $tmp['id'] = (int) $item->service()->id(); $tmp['name'] = $item->service()->name(); $tmp['alias'] = $item->service()->name(); diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index ca0c9dad7d..c1b6697022 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -5986,6 +5986,56 @@ function send_test_email( } +/** + * Return array of ancestors of item, given array. + * + * @param integer $item From index. + * @param array $data Array data. + * @param string $key Pivot key (identifies the parent). + * @param string|null $extract Extract certain column or index. + * @param array $visited Cycle detection. + * + * @return array Array of ancestors. + */ +function get_ancestors( + int $item, + array $data, + string $key, + ?string $extract=null, + array &$visited=[] +) :array { + if (isset($visited[$item]) === true) { + return []; + } + + $visited[$item] = 1; + + if (isset($data[$item]) === false) { + return []; + } + + if (isset($data[$item][$key]) === false) { + if ($extract !== null) { + return [$data[$item][$extract]]; + } + + return [$item]; + } + + if ($extract !== null) { + return array_merge( + get_ancestors($data[$item][$key], $data, $key, $extract, $visited), + [$data[$item][$extract]] + ); + } + + return array_merge( + get_ancestors($data[$item][$key], $data, $key, $extract, $visited), + [$item] + ); +} + + if (function_exists('str_contains') === false) { diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index 7f22c6e9d0..a09be1880d 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -848,6 +848,7 @@ var TreeController = { break; case "services": + console.log(element); if ( typeof element.statusImageHTML != "undefined" && element.statusImageHTML.length > 0 @@ -861,7 +862,7 @@ var TreeController = { '' +
                 element.name +
                 ' '; From 87cd23b08a214eba49ae59f4a2d05c7d0a7dc6a1 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 20 Apr 2022 18:41:03 +0200 Subject: [PATCH 02/26] a nice trick --- pandora_console/include/class/TreeService.class.php | 10 ++++++++-- .../include/javascript/tree/TreeController.js | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/class/TreeService.class.php b/pandora_console/include/class/TreeService.class.php index e69862a9fd..43da11116e 100644 --- a/pandora_console/include/class/TreeService.class.php +++ b/pandora_console/include/class/TreeService.class.php @@ -523,8 +523,14 @@ class TreeService extends Tree continue 2; } - $tmp['parents'] = $item->service()->getAncestors(); - $tmp['title'] = join('/', $tmp['parents']); + $title = get_parameter('title', ''); + if (empty($title) === true) { + $tmp['title'] = ''; + } else { + $tmp['title'] = $title.'/'; + } + + $tmp['title'] .= $service->name(); $tmp['id'] = (int) $item->service()->id(); $tmp['name'] = $item->service()->name(); $tmp['alias'] = $item->service()->name(); diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index a09be1880d..b90b76a021 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -848,7 +848,6 @@ var TreeController = { break; case "services": - console.log(element); if ( typeof element.statusImageHTML != "undefined" && element.statusImageHTML.length > 0 @@ -1302,6 +1301,7 @@ var TreeController = { .removeClass("leaf-error") .addClass("leaf-loading"); + console.log(element); $.ajax({ url: controller.ajaxURL, type: "POST", @@ -1315,6 +1315,7 @@ var TreeController = { serverID: element.serverID, rootType: element.rootType, metaID: element.metaID, + title: element.title, filter: controller.filter, auth_class: controller.auth_class, id_user: controller.id_user, From 78907e691c810cfee568aac4b6e05dfde138967e Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 20 Apr 2022 18:45:52 +0200 Subject: [PATCH 03/26] removed traces --- pandora_console/include/javascript/tree/TreeController.js | 1 - 1 file changed, 1 deletion(-) diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index b90b76a021..073a862c4c 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -1301,7 +1301,6 @@ var TreeController = { .removeClass("leaf-error") .addClass("leaf-loading"); - console.log(element); $.ajax({ url: controller.ajaxURL, type: "POST", From 00f594293cbb57f05ecbb1d1930ae5eb3a4857e8 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 20 Apr 2022 19:20:54 +0200 Subject: [PATCH 04/26] hint parents in service selection --- .../include/lib/Dashboard/Widgets/service_map.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/lib/Dashboard/Widgets/service_map.php b/pandora_console/include/lib/Dashboard/Widgets/service_map.php index a2122c6dca..3dbcbdf5b0 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/service_map.php +++ b/pandora_console/include/lib/Dashboard/Widgets/service_map.php @@ -268,7 +268,20 @@ class ServiceMapWidget extends Widget $fields = array_reduce( $services_res, function ($carry, $item) { - $carry[$item['id']] = $item['name']; + $parents = ''; + if (class_exists('\PandoraFMS\Enterprise\Service') === true) { + try { + $service = new \PandoraFMS\Enterprise\Service($item['id']); + $ancestors = $service->getAncestors(); + if (empty($ancestors) === false) { + $parents = '('.join('/', $ancestors).')'; + } + } catch (\Exception $e) { + $parents = ''; + } + } + + $carry[$item['id']] = $item['name'].' '.$parents; return $carry; }, [] From dfc599b2d8004ed883337780509116dc339344f7 Mon Sep 17 00:00:00 2001 From: Calvo Date: Fri, 22 Apr 2022 18:27:29 +0200 Subject: [PATCH 05/26] WIP: Meta disable groups CLI --- pandora_server/util/pandora_manage.pl | 66 +++++++++++++++++++-------- 1 file changed, 46 insertions(+), 20 deletions(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 0b6a96f3a4..a80b55c8ac 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -375,29 +375,55 @@ sub pandora_disable_group ($$$) { exit; } - if ($group == 0){ - # Extract all the names of the pandora agents if it is for all = 0. - @agents_bd = get_db_rows ($dbh, 'SELECT nombre FROM tagente'); + if(is_metaconsole($conf) == 1) { + my $servers = enterprise_hook('get_metaconsole_setup_servers',[$dbh]); + my @servers_id = split(',',$servers); + use Data:Dumper; + print Dumper() + foreach my $server (@servers_id) { + my $dbh_metaconsole = enterprise_hook('get_node_dbh',[$conf, $server, $dbh]); - # Update bbdd. - db_do ($dbh, "UPDATE tagente SET disabled = 1"); - } - else { - # Extract all the names of the pandora agents if it is for group. - @agents_bd = get_db_rows ($dbh, 'SELECT nombre FROM tagente WHERE id_grupo = ?', $group); + if ($group == 0){ + # Extract all the names of the pandora agents if it is for all = 0. + @agents_bd = get_db_rows ($dbh_metaconsole, 'SELECT id_agente FROM tagente'); + } + else { + # Extract all the names of the pandora agents if it is for group. + @agents_bd = get_db_rows ($dbh_metaconsole, 'SELECT id_agente FROM tagente WHERE id_grupo = ?', $group); + } - # Update bbdd. - db_do ($dbh, "UPDATE tagente SET disabled = 1 WHERE id_grupo = $group"); - } + foreach my $id_agent (@agents_bd) { + # Call the API. + $result = api_call( + $conf, 'set', 'disabled_and_standby', $id_agent, $server, 1 + ); + } + } + } else { + if ($group == 0){ + # Extract all the names of the pandora agents if it is for all = 0. + @agents_bd = get_db_rows ($dbh, 'SELECT nombre FROM tagente'); - foreach my $name_agent (@agents_bd) { - # Check the standby field I put it to 0. - my $new_conf = update_conf_txt( - $conf, - $name_agent->{'nombre'}, - 'standby', - '1' - ); + # Update bbdd. + db_do ($dbh, "UPDATE tagente SET disabled = 1"); + } + else { + # Extract all the names of the pandora agents if it is for group. + @agents_bd = get_db_rows ($dbh, 'SELECT nombre FROM tagente WHERE id_grupo = ?', $group); + + # Update bbdd. + db_do ($dbh, "UPDATE tagente SET disabled = 1 WHERE id_grupo = $group"); + } + + foreach my $name_agent (@agents_bd) { + # Check the standby field I put it to 0. + my $new_conf = update_conf_txt( + $conf, + $name_agent->{'nombre'}, + 'standby', + '1' + ); + } } return $result; From f4ac0d19d033c46bd658d91690c0bdcebc19d688 Mon Sep 17 00:00:00 2001 From: Luis Date: Mon, 25 Apr 2022 13:17:13 +0200 Subject: [PATCH 06/26] WIP: pandora manage disable group --- pandora_server/util/pandora_manage.pl | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index a80b55c8ac..6b89b6c35c 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -36,7 +36,7 @@ use Encode::Locale; Encode::Locale::decode_argv; # version: define current version -my $version = "7.0NG.761 Build 220420"; +my $version = "7.0NG.761 Build 220425"; # save program name for logging my $progname = basename($0); @@ -378,8 +378,6 @@ sub pandora_disable_group ($$$) { if(is_metaconsole($conf) == 1) { my $servers = enterprise_hook('get_metaconsole_setup_servers',[$dbh]); my @servers_id = split(',',$servers); - use Data:Dumper; - print Dumper() foreach my $server (@servers_id) { my $dbh_metaconsole = enterprise_hook('get_node_dbh',[$conf, $server, $dbh]); @@ -394,9 +392,11 @@ sub pandora_disable_group ($$$) { foreach my $id_agent (@agents_bd) { # Call the API. - $result = api_call( - $conf, 'set', 'disabled_and_standby', $id_agent, $server, 1 - ); + use Data::Dumper; + print Dumper($conf); + $result .= api_call( + $conf, 'set', 'disabled_and_standby', $id_agent, $server, 1, 1 + ).'\n'; } } } else { @@ -1164,7 +1164,8 @@ sub cli_disable_group() { print_log "[INFO] Disabling group '$group_name'\n\n"; } - pandora_disable_group ($conf, $dbh, $id_group); + my $result = pandora_disable_group ($conf, $dbh, $id_group); + print $result.'\n\n'; } ############################################################################## From 7c2625fddfb11325c859756aa1e501fbcbaf235e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Tue, 26 Apr 2022 11:47:34 +0200 Subject: [PATCH 07/26] Fix recursion checkbox position --- .../godmode/agentes/modificar_agente.php | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pandora_console/godmode/agentes/modificar_agente.php b/pandora_console/godmode/agentes/modificar_agente.php index 9c63363df2..a84bf918f8 100644 --- a/pandora_console/godmode/agentes/modificar_agente.php +++ b/pandora_console/godmode/agentes/modificar_agente.php @@ -315,7 +315,20 @@ html_print_select_groups( '', false ); -echo '
'; +echo ''; + +// Recursion checkbox. +echo ''; +echo __('Recursion').' '; +html_print_checkbox( + 'recursion', + 1, + $recursion, + false, + false, + 'this.form.submit()' +); +echo ''; echo ''; echo __('Show Agents').' '; $fields = [ @@ -346,19 +359,6 @@ foreach ($pre_fields as $key => $value) { html_print_select($fields, 'os', $os, 'this.form.submit()', 'All', 0); -echo ''; - -echo ''; -echo __('Recursion').' '; -html_print_checkbox( - 'recursion', - 1, - $recursion, - false, - false, - 'this.form.submit()' -); - echo ''; echo __('Search').' '; html_print_input_text('search', $search, '', 12); From 7190a797ec17f0d2fe86c6a4f94928c091aca43e Mon Sep 17 00:00:00 2001 From: Luis Date: Tue, 26 Apr 2022 14:47:49 +0200 Subject: [PATCH 08/26] Fix meta CLI disable group --- pandora_server/util/pandora_manage.pl | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 6b89b6c35c..8bdfc165cf 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -21,7 +21,7 @@ use JSON qw(decode_json encode_json); use MIME::Base64; use Encode qw(decode encode_utf8); use LWP::Simple; -use Data::Dumper; +#use Data::Dumper; # Default lib dir for RPM and DEB packages BEGIN { push @INC, '/usr/lib/perl5'; } @@ -392,11 +392,9 @@ sub pandora_disable_group ($$$) { foreach my $id_agent (@agents_bd) { # Call the API. - use Data::Dumper; - print Dumper($conf); - $result .= api_call( - $conf, 'set', 'disabled_and_standby', $id_agent, $server, 1, 1 - ).'\n'; + $result += api_call( + $conf, 'set', 'disabled_and_standby', $id_agent->{'id_agente'}, $server, '1|1' + ); } } } else { @@ -405,14 +403,14 @@ sub pandora_disable_group ($$$) { @agents_bd = get_db_rows ($dbh, 'SELECT nombre FROM tagente'); # Update bbdd. - db_do ($dbh, "UPDATE tagente SET disabled = 1"); + $result = db_update ($dbh, "UPDATE tagente SET disabled = 1"); } else { # Extract all the names of the pandora agents if it is for group. @agents_bd = get_db_rows ($dbh, 'SELECT nombre FROM tagente WHERE id_grupo = ?', $group); # Update bbdd. - db_do ($dbh, "UPDATE tagente SET disabled = 1 WHERE id_grupo = $group"); + $result = db_update ($dbh, "UPDATE tagente SET disabled = 1 WHERE id_grupo = $group"); } foreach my $name_agent (@agents_bd) { @@ -1165,7 +1163,7 @@ sub cli_disable_group() { } my $result = pandora_disable_group ($conf, $dbh, $id_group); - print $result.'\n\n'; + print_log "[INFO] Disbaled ".$result." agents from group ".$group_name."\n\n"; } ############################################################################## @@ -5566,8 +5564,6 @@ sub cli_get_agents() { my $head_print = 0; - # use Data::Dumper; - foreach my $agent (@agents) { if($status ne '') { From b5b273407090cd2ffd5834cf16b209291add5c27 Mon Sep 17 00:00:00 2001 From: Luis Date: Wed, 27 Apr 2022 10:42:06 +0200 Subject: [PATCH 09/26] Fix CLI delete group on meta --- pandora_server/util/pandora_manage.pl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 96253a489c..890c905823 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -5953,6 +5953,24 @@ sub cli_delete_group() { $group_id = db_do ($dbh, 'DELETE FROM tgrupo WHERE nombre=?', safe_input($group_name)); + # Delete on nodes too if metaconsole. + if(is_metaconsole($conf) == 1 && pandora_get_tconfig_token ($dbh, 'centralized_management', '')) { + my $servers = enterprise_hook('get_metaconsole_setup_servers',[$dbh]); + my @servers_id = split(',',$servers); + + foreach my $server (@servers_id) { + + my $dbh_node = enterprise_hook('get_node_dbh',[$conf, $server, $dbh]); + + my $group_id = get_group_id($dbh_node,$group_name); + exist_check($group_id, 'group name', $group_name); + + $group_id = db_do ($dbh_node, 'DELETE FROM tgrupo WHERE nombre=?', safe_input($group_name)); + + } + } + + if($group_id == -1) { print_log "[ERROR] A problem has been ocurred deleting group '$group_name'\n\n"; }else{ From 7164bb0137011b7f5743a2deac121e1d0c18a813 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Thu, 28 Apr 2022 13:13:10 +0200 Subject: [PATCH 10/26] #8153 Added custom data --- .../reporting_builder.item_editor.php | 26 +++++++++- .../godmode/reporting/reporting_builder.php | 12 +++++ .../include/functions_reporting.php | 18 +++++-- .../include/functions_reporting_html.php | 51 ++++++++++++++++++- 4 files changed, 101 insertions(+), 6 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 2186c455d2..b5c66651b1 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -606,6 +606,7 @@ switch ($action) { $event_graph_by_criticity = $style['event_graph_by_criticity']; $event_graph_validated_vs_unvalidated = $style['event_graph_validated_vs_unvalidated']; $include_extended_events = $item['show_extended_events']; + $custom_data_events = $style['custom_data_events']; $filter_search = $style['event_filter_search']; $filter_exclude = $style['event_filter_exclude']; @@ -631,6 +632,7 @@ switch ($action) { $include_extended_events = $item['show_extended_events']; + $custom_data_events = $style['custom_data_events']; break; case 'event_report_module': @@ -665,6 +667,7 @@ switch ($action) { $include_extended_events = $item['show_extended_events']; + $custom_data_events = $style['custom_data_events']; break; case 'general': @@ -2911,6 +2914,23 @@ $class = 'databox filters'; + + + + + + + + + @@ -5974,6 +5994,7 @@ function chooseType() { $("#row_event_graph_by_criticity").hide(); $("#row_event_graph_by_validated").hide(); $("#row_extended_events").hide(); + $("#row_custom_data_events").hide(); $("#row_netflow_filter").hide(); $("#row_max_values").hide(); $("#row_resolution").hide(); @@ -6044,6 +6065,7 @@ function chooseType() { $("#row_event_graph_by_criticity").show(); $("#row_event_graph_by_validated").show(); $("#row_extended_events").show(); + $("#row_custom_data_events").show(); $("#row_filter_search").show(); $("#row_filter_exclude").show(); @@ -6371,6 +6393,7 @@ function chooseType() { $("#row_event_graph_by_validated").show(); $("#row_event_type").show(); $("#row_extended_events").show(); + $("#row_custom_data_events").show(); $("#row_filter_search").show(); $("#row_filter_exclude").show(); @@ -6389,7 +6412,7 @@ function chooseType() { $("#row_event_graphs").show(); $("#row_event_type").show(); $("#row_extended_events").show(); - $("#row_extended_events").show(); + $("#row_custom_data_events").show(); $("#row_event_graph_by_user").show(); $("#row_event_graph_by_criticity").show(); @@ -6414,6 +6437,7 @@ function chooseType() { $("#row_event_graphs").show(); $("#row_event_type").show(); $("#row_extended_events").show(); + $("#row_custom_data_events").show(); $("#row_event_graph_by_user").show(); $("#row_event_graph_by_criticity").show(); diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index 608f2f6a54..94c9e0b454 100755 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -2224,12 +2224,18 @@ switch ($action) { $filter_event_status ); + $custom_data_events = get_parameter_switch( + 'custom_data_events', + 0 + ); + $style['event_graph_by_agent'] = $event_graph_by_agent; $style['event_graph_by_user_validator'] = $event_graph_by_user_validator; $style['event_graph_by_criticity'] = $event_graph_by_criticity; $style['event_graph_validated_vs_unvalidated'] = $event_graph_validated_vs_unvalidated; $style['event_filter_search'] = $event_filter_search; $style['event_filter_exclude'] = $event_filter_exclude; + $style['custom_data_events'] = $custom_data_events; if ($label != '') { @@ -2957,6 +2963,11 @@ switch ($action) { '' ); + $custom_data_events = get_parameter_switch( + 'custom_data_events', + 0 + ); + // Added for events items. $style['show_summary_group'] = $show_summary_group; @@ -2976,6 +2987,7 @@ switch ($action) { $style['event_graph_validated_vs_unvalidated'] = $event_graph_validated_vs_unvalidated; $style['event_filter_search'] = $event_filter_search; $style['event_filter_exclude'] = $event_filter_exclude; + $style['custom_data_events'] = $custom_data_events; if ($label != '') { $style['label'] = $label; diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 6bf29c1235..ae40d03de3 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -810,7 +810,7 @@ function reporting_make_reporting_data( break; } - $report['contents'][] = $report_control; + $report['contents'][] = $report_control; break; case 'event_report_module': @@ -826,7 +826,7 @@ function reporting_make_reporting_data( break; } - $report['contents'][] = $report_control; + $report['contents'][] = $report_control; break; case 'event_report_group': @@ -1943,6 +1943,8 @@ function reporting_event_report_group( $event_filter = $content['style']; $return['show_summary_group'] = $event_filter['show_summary_group']; + $return['show_custom_data'] = (isset($event_filter['custom_data_events']) === true) ? (bool) $event_filter['custom_data_events'] : false; + // Filter. $show_summary_group = $event_filter['show_summary_group']; $filter_event_severity = json_decode($event_filter['filter_event_severity'], true); @@ -2246,6 +2248,8 @@ function reporting_event_report_module( $event_filter = $content['style']; $return['show_summary_group'] = $event_filter['show_summary_group']; + $return['show_custom_data'] = (isset($event_filter['custom_data_events']) === true) ? (bool) $event_filter['custom_data_events'] : false; + // Filter. $show_summary_group = $event_filter['show_summary_group']; $filter_event_severity = json_decode( @@ -3779,6 +3783,8 @@ function reporting_event_report_agent( $filter_event_status = json_decode($style['filter_event_status'], true); $filter_event_filter_search = $style['event_filter_search']; $filter_event_filter_exclude = $style['event_filter_exclude']; + $show_custom_data = (isset($style['custom_data_events']) === true) ? (bool) $style['custom_data_events'] : false; + $return['show_custom_data'] = $show_custom_data; // Graph. $event_graph_by_user_validator = $style['event_graph_by_user_validator']; @@ -3798,7 +3804,8 @@ function reporting_event_report_agent( $filter_event_status, $filter_event_filter_search, $filter_event_filter_exclude, - $id_server + $id_server, + $show_custom_data ); if (is_metaconsole() === true) { @@ -10594,7 +10601,8 @@ function reporting_get_agents_detailed_event( $filter_event_status=false, $filter_event_filter_search=false, $filter_event_filter_exclude=false, - $id_server=0 + $id_server=0, + $show_custom_data=false ) { global $config; @@ -10651,6 +10659,7 @@ function reporting_get_agents_detailed_event( 'validated_by' => $e['id_usuario'], 'timestamp' => $e['timestamp_rep'], 'id_evento' => $e['id_evento'], + 'custom_data' => ($show_custom_data === true) ? $e['custom_data'] : '', ]; } else { $return_data[] = [ @@ -10661,6 +10670,7 @@ function reporting_get_agents_detailed_event( 'validated_by' => $e['id_usuario'], 'timestamp' => $e['timestamp'], 'id_evento' => $e['id_evento'], + 'custom_data' => ($show_custom_data === true) ? $e['custom_data'] : '', ]; } } diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index cd6af07794..d6450e37bd 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -1025,6 +1025,7 @@ function reporting_html_event_report_group($table, $item, $pdf=0) global $config; $show_extended_events = $item['show_extended_events']; + $show_custom_data = (bool) $item['show_custom_data']; if ($item['total_events']) { $table1 = new stdClass(); @@ -1060,6 +1061,10 @@ function reporting_html_event_report_group($table, $item, $pdf=0) $table1->head[6] = __('Timestamp'); } + if ($show_custom_data === true) { + $table1->head[8] = __('Custom data'); + } + foreach ($item['data'] as $k => $event) { // First pass along the class of this row. if ($item['show_summary_group']) { @@ -1132,6 +1137,16 @@ function reporting_html_event_report_group($table, $item, $pdf=0) $data[] = ''.date($config['date_format'], strtotime($event['timestamp'])).''; } + if ($show_custom_data === true) { + $custom_data = json_decode($event['custom_data'], true); + $custom_data_text = ''; + foreach ($custom_data as $key => $value) { + $custom_data_text .= $key.' = '.$value.'
'; + } + + $data[] = $custom_data_text; + } + array_push($table1->data, $data); if ($show_extended_events == 1 && events_has_extended_info($event['id_evento'])) { @@ -1246,10 +1261,10 @@ function reporting_html_event_report_group($table, $item, $pdf=0) function reporting_html_event_report_module($table, $item, $pdf=0) { global $config; - $show_extended_events = $item['show_extended_events']; $show_summary_group = $item['show_summary_group']; + $show_custom_data = (bool) $item['show_custom_data']; if ($item['total_events']) { if (!empty($item['failed'])) { $table->colspan['events']['cell'] = 3; @@ -1279,6 +1294,10 @@ function reporting_html_event_report_module($table, $item, $pdf=0) $table1->style[0] = 'text-align: center;'; } + if ($show_custom_data === true) { + $table1->head[6] = __('Custom data'); + } + if (is_array($item['data']) || is_object($item['data'])) { $item_data = array_reverse($item['data']); } @@ -1331,6 +1350,16 @@ function reporting_html_event_report_module($table, $item, $pdf=0) $data[4] = date($config['date_format'], strtotime($event['timestamp'])); } + if ($show_custom_data === true) { + $custom_data = json_decode($event['custom_data'], true); + $custom_data_text = ''; + foreach ($custom_data as $key => $value) { + $custom_data_text .= $key.' = '.$value.'
'; + } + + $data[6] = $custom_data_text; + } + $table1->data[] = $data; if ($show_extended_events == 1 && events_has_extended_info($event['id_evento'])) { @@ -2341,6 +2370,13 @@ function reporting_html_event_report_agent($table, $item, $pdf=0) $table1->align[0] = 'center'; $table1->align[1] = 'center'; $table1->align[3] = 'center'; + if ((bool) $item['show_custom_data'] === true) { + if ($item['show_summary_group']) { + $table1->align[7] = 'left'; + } else { + $table1->align[6] = 'left'; + } + } $table1->data = []; @@ -2355,6 +2391,9 @@ function reporting_html_event_report_agent($table, $item, $pdf=0) $table1->head[4] = __('Severity'); $table1->head[5] = __('Val. by'); $table1->head[6] = __('Timestamp'); + if ((bool) $item['show_custom_data'] === true) { + $table1->head[7] = __('Custom data'); + } foreach ($item['data'] as $i => $event) { if ($item['show_summary_group']) { @@ -2420,6 +2459,16 @@ function reporting_html_event_report_agent($table, $item, $pdf=0) $data[] = ''.date($config['date_format'], strtotime($event['timestamp'])).''; } + if ((bool) $item['show_custom_data'] === true) { + $custom_data = json_decode($event['custom_data'], true); + $custom_data_text = ''; + foreach ($custom_data as $key => $value) { + $custom_data_text .= $key.' = '.$value.'
'; + } + + $data[] = $custom_data_text; + } + array_push($table1->data, $data); if ($show_extended_events == 1 && events_has_extended_info($event['id_evento'])) { From a858c31d3973c7f00ded4f540bc3e539c99c2829 Mon Sep 17 00:00:00 2001 From: Luis Date: Wed, 4 May 2022 12:48:39 +0000 Subject: [PATCH 11/26] Update pandora_manage.pl --- pandora_server/util/pandora_manage.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index ee6dc73d2b..681d035916 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -1163,7 +1163,7 @@ sub cli_disable_group() { } my $result = pandora_disable_group ($conf, $dbh, $id_group); - print_log "[INFO] Disbaled ".$result." agents from group ".$group_name."\n\n"; + print_log "[INFO] Disabled ".$result." agents from group ".$group_name."\n\n"; } ############################################################################## @@ -8744,4 +8744,4 @@ sub pandora_validate_alert_id($$$$) { ); return 1; -} \ No newline at end of file +} From eaef84b5b297063bff52ff2f5e6b27dc8f2211bc Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Wed, 4 May 2022 16:38:38 +0200 Subject: [PATCH 12/26] #8708 only enabled agent --- pandora_console/include/functions_alerts.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 81b36f7476..070ff52831 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -118,6 +118,9 @@ function alerts_get_alerts($id_group=0, $free_search='', $status='all', $standby $sql .= ' AND t3.id_agente = '.$id_agent; } + // Only enabled agent. + $sql .= ' AND t3.disabled = 0'; + $row_alerts = db_get_all_rows_sql($sql); if ($total) { From 752a716c21a17069deb8f2d04f23805e28571c5a Mon Sep 17 00:00:00 2001 From: Calvo Date: Mon, 9 May 2022 08:58:14 +0200 Subject: [PATCH 13/26] Changed link to Suggest new feature on new installation --- pandora_console/pandoradb_data.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index 865d06cfba..4072e4b77f 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -218,7 +218,7 @@ INSERT INTO `tlink` VALUES (1,'Documentation','https://pandorafms.com/manual'), (2,'Enterprise Edition','http://pandorafms.com'), (3,'Report a bug','https://github.com/pandorafms/pandorafms/issues'), -(4,'Suggest new feature','http://forums.pandorafms.com/index.php?board=22.0'), +(4,'Suggest new feature','https://pandorafms.com/community/beta-program/'), (5,'Module library','http://library.pandorafms.com/'); UNLOCK TABLES; From 6e03653b508ddd381be9ab575356082b03c43108 Mon Sep 17 00:00:00 2001 From: Rafael Ameijeiras Date: Mon, 9 May 2022 09:51:09 +0200 Subject: [PATCH 14/26] 8952-13576-quitar-check-a-google-del-script-de-instalacion --- extras/deploy-scripts/pandora_deploy_community.sh | 3 +-- extras/deploy-scripts/pandora_deploy_community_el8.sh | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/extras/deploy-scripts/pandora_deploy_community.sh b/extras/deploy-scripts/pandora_deploy_community.sh index cb800cf29b..ef38435bfd 100644 --- a/extras/deploy-scripts/pandora_deploy_community.sh +++ b/extras/deploy-scripts/pandora_deploy_community.sh @@ -11,7 +11,7 @@ PANDORA_SERVER_CONF=/etc/pandora/pandora_server.conf PANDORA_AGENT_CONF=/etc/pandora/pandora_agent.conf -S_VERSION='2022020801' +S_VERSION='2022050901' LOGFILE="/tmp/pandora-deploy-community-$(date +%F).log" # define default variables @@ -82,7 +82,6 @@ check_pre_pandora () { } check_repo_connection () { - execute_cmd "ping -c 2 8.8.8.8" "Checking internet connection" execute_cmd "ping -c 2 firefly.artica.es" "Checking Community repo" execute_cmd "ping -c 2 support.pandorafms.com" "Checking Enterprise repo" } diff --git a/extras/deploy-scripts/pandora_deploy_community_el8.sh b/extras/deploy-scripts/pandora_deploy_community_el8.sh index cdfcd951ca..145c1445ca 100644 --- a/extras/deploy-scripts/pandora_deploy_community_el8.sh +++ b/extras/deploy-scripts/pandora_deploy_community_el8.sh @@ -14,7 +14,7 @@ PANDORA_SERVER_CONF=/etc/pandora/pandora_server.conf PANDORA_AGENT_CONF=/etc/pandora/pandora_agent.conf -S_VERSION='2022020801' +S_VERSION='2022050901' LOGFILE="/tmp/pandora-deploy-community-$(date +%F).log" # define default variables @@ -84,7 +84,6 @@ check_pre_pandora () { } check_repo_connection () { - execute_cmd "ping -c 2 8.8.8.8" "Checking internet connection" execute_cmd "ping -c 2 firefly.artica.es" "Checking Community repo" execute_cmd "ping -c 2 support.pandorafms.com" "Checking Enterprise repo" } From a2de9121b764e4d02e9ef55b8e83f081fd391ec7 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Tue, 10 May 2022 15:15:40 +0200 Subject: [PATCH 15/26] #8958 remove the option none --- pandora_console/godmode/alerts/configure_alert_action.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/godmode/alerts/configure_alert_action.php b/pandora_console/godmode/alerts/configure_alert_action.php index 8b276d7233..068026c953 100644 --- a/pandora_console/godmode/alerts/configure_alert_action.php +++ b/pandora_console/godmode/alerts/configure_alert_action.php @@ -261,7 +261,7 @@ $table->data[2][1] = html_print_select_from_sql( 'id_command', $id_command, '', - __('None'), + '', 0, true, false, From 2953bab0df23009d438d9d5a54abf8a899bea186 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Tue, 24 May 2022 09:55:37 +0200 Subject: [PATCH 16/26] #8999 Optimised delete agents in bulk --- .../godmode/massive/massive_delete_agents.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pandora_console/godmode/massive/massive_delete_agents.php b/pandora_console/godmode/massive/massive_delete_agents.php index e85a12486d..cc87efebed 100755 --- a/pandora_console/godmode/massive/massive_delete_agents.php +++ b/pandora_console/godmode/massive/massive_delete_agents.php @@ -140,7 +140,7 @@ function process_manage_delete($id_agents) } -$id_group = (int) get_parameter('id_group'); +$id_group = (is_metaconsole() === true) ? get_parameter('id_group', '') : (int) get_parameter('id_group'); $id_agents = get_parameter('id_agents'); $recursion = get_parameter('recursion'); $delete = (bool) get_parameter_post('delete'); @@ -282,15 +282,15 @@ $table->data[3][0] .= ''; -$agents = agents_get_group_agents( - array_keys(users_get_groups($config['id_user'], 'AW', false)), - ['disabled' => 2], - 'none', - false, - false, - is_metaconsole(), - '|' -); +$agents = []; +if (is_metaconsole() === false) { + $agents = agents_get_group_agents( + array_keys(users_get_groups($config['id_user'], 'AW', false)), + ['disabled' => 2], + 'none' + ); +} + $table->data[3][1] = html_print_select( $agents, From fc7b4d8a119d2ee89adf2acb8d2684735a8e1682 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Wed, 25 May 2022 13:13:09 +0200 Subject: [PATCH 17/26] #8897 Fixed tdashboard name --- pandora_console/extras/mr/55.sql | 5 +++++ pandora_console/pandoradb.sql | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 pandora_console/extras/mr/55.sql diff --git a/pandora_console/extras/mr/55.sql b/pandora_console/extras/mr/55.sql new file mode 100644 index 0000000000..d9693047c1 --- /dev/null +++ b/pandora_console/extras/mr/55.sql @@ -0,0 +1,5 @@ +START TRANSACTION; + +ALTER TABLE `tdashboard` MODIFY `name` TEXT NOT NULL DEFAULT ''; + +COMMIT; \ No newline at end of file diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 29ec6e572b..49f5edb991 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -2578,7 +2578,7 @@ CREATE TABLE IF NOT EXISTS `tpolicy_group_agents` ( -- --------------------------------------------------------------------- CREATE TABLE IF NOT EXISTS `tdashboard` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, - `name` VARCHAR(60) NOT NULL DEFAULT '', + `name` TEXT NOT NULL DEFAULT '', `id_user` VARCHAR(60) NOT NULL DEFAULT '', `id_group` INT NOT NULL DEFAULT 0, `active` TINYINT NOT NULL DEFAULT 0, From 353e8773f856a1c1bee7cc75ea2a1b5232ca4b9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Thu, 26 May 2022 08:13:30 +0200 Subject: [PATCH 18/26] Hide inventory view if agent dont have inventory modules --- pandora_console/operation/agentes/ver_agente.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index bca69043e2..3ce033fbe3 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -1403,7 +1403,7 @@ if ($agent_interfaces_count > 0) { ] ).''; - if ($tab == 'interface') { + if ($tab === 'interface') { $interfacetab['active'] = true; } else { $interfacetab['active'] = false; @@ -1420,19 +1420,19 @@ $alerttab['text'] = 'data[1][0] = __('Module name'); $table->data[1][1] = html_print_autocomplete_modules( 'ag_modulename', @@ -579,7 +570,12 @@ if (empty($tags)) { ); } - +$table2 = new StdClass(); +$table2->width = '100%'; +$table2->class = 'filters'; +$table2->style = []; +$table2->style[0] = 'font-weight: bold;'; +$table2->style[1] = 'font-weight: bold;'; $network_available = db_get_sql( 'SELECT count(*) @@ -647,9 +643,9 @@ if (enterprise_installed()) { } -$table->data[2][0] = ''.__('Server type').''; +$table2->data[0][0] = ''.__('Server type').''; -$table->data[2][1] = html_print_select($typemodules, 'moduletype', $moduletype, '', __($is_none), '', true, false, true, '', false, 'width: 150px;'); +$table2->data[0][1] = html_print_select($typemodules, 'moduletype', $moduletype, '', __($is_none), '', true, false, true, '', false, 'width: 150px;'); $monitor_options = [ 0 => __('All'), @@ -657,21 +653,18 @@ $monitor_options = [ 2 => __('Only disabled'), ]; -$table->data[2][2] = ''.__('Show monitors...').''; +$table2->data[0][2] = ''.__('Show monitors...').''; -$table->data[2][3] = html_print_select($monitor_options, 'module_option', $module_option, '', '', '', true, false, true, '', false, 'width: 150px;'); +$table2->data[0][3] = html_print_select($monitor_options, 'module_option', $module_option, '', '', '', true, false, true, '', false, 'width: 150px;'); $min_hours_val = empty($min_hours_status) ? '' : (int) $min_hours_status; -$table->data[2][4] = ''.__('Min. hours in current status').''; -$table->data[2][5] = html_print_input_text('min_hours_status', $min_hours_val, '', 12, 20, true); +$table2->data[0][4] = ''.__('Min. hours in current status').''; +$table2->data[0][5] = html_print_input_text('min_hours_status', $min_hours_val, '', 12, 20, true); -$table->data[3][0] = 'data[3][0] .= '>'.__('Data type').''; - - -$table->data[3][1] .= '
'; +$table2->data[1][0] = 'data[1][0] .= '>'.__('Data type').''; +$table2->data[1][1] .= '
'; switch ($moduletype) { @@ -744,143 +737,349 @@ switch ($moduletype) { } $a = db_get_all_rows_sql($sql); -$table->data[3][1] .= 'data[3][1] .= '>'; +$table2->data[1][1] .= '>'; -$table->data[3][1] .= ''; +$table2->data[1][1] .= ''; foreach ($a as $valor) { - $table->data[3][1] .= ''; + $table2->data[1][1] .= '>'.$valor['descripcion'].''; } - $table->data[3][1] .= ''; - - - - - $table->data[3][1] .= '
'; - $check_not_condition = ''; +$table2->data[1][1] .= ''; +$table2->data[1][1] .= '
'; +$check_not_condition = ''; if ($not_condition !== '') { $check_not_condition = true; } -$table->data[4][0] .= __('Not condition').' '.ui_print_help_tip(__('If you check this option, those elements that do NOT meet any of the requirements will be shown'), true); - $table->data[4][1] = html_print_div( +$table2->data[1][2] .= __('Not condition').' '.ui_print_help_tip(__('If you check this option, those elements that do NOT meet any of the requirements will be shown'), true); +$table2->data[1][3] = html_print_div( + [ + 'class' => 'w120px mrgn_5px mrgn_lft_0px mrgn_right_0px', + 'content' => html_print_input( [ - 'class' => 'w120px mrgn_5px mrgn_lft_0px mrgn_right_0px', - 'content' => html_print_input( - [ - 'type' => 'switch', - 'name' => 'not_condition', - 'return' => false, - 'checked' => $check_not_condition, - 'value' => 'NOT', - 'id' => 'not_condition_switch', - 'onclick' => 'changeNotConditionStatus(this)', - ] - ), - ], - true - ); + 'type' => 'switch', + 'name' => 'not_condition', + 'return' => false, + 'checked' => $check_not_condition, + 'value' => 'NOT', + 'id' => 'not_condition_switch', + 'onclick' => 'changeNotConditionStatus(this)', + ] + ), + ], + true +); - $table_custom_fields = new stdClass(); - $table_custom_fields->class = 'filters'; - $table_custom_fields->width = '100%'; - $table_custom_fields->style = []; - $table_custom_fields->style[0] = 'font-weight: bold;'; - - // Style is different in metaconsole. - if ($is_metaconsole === false) { - $table_custom_fields->style[0] = 'font-weight: bold; width: 150px;'; - } - - if ($is_metaconsole === true) { - $table_custom_fields->styleTable = 'margin-left:0px; margin-top:15px;'; - $table_custom_fields->cellpadding = '0'; - $table_custom_fields->cellspacing = '0'; - } - - $table_custom_fields->colspan = []; - $table_custom_fields->data = []; - - $custom_fields = db_get_all_fields_in_table('tagent_custom_fields'); - if ($custom_fields === false) { - $custom_fields = []; - } - - foreach ($custom_fields as $custom_field) { - $row = []; - $row[0] = $custom_field['name']; +$custom_fields = db_get_all_fields_in_table('tagent_custom_fields'); +if ($custom_fields === false) { + $custom_fields = []; +} +$div_custom_fields = '
'; +foreach ($custom_fields as $custom_field) { + $custom_field_value = ''; + if (empty($ag_custom_fields) === false) { + $custom_field_value = $ag_custom_fields[$custom_field['id_field']]; + if (empty($custom_field_value) === true) { $custom_field_value = ''; - if (empty($ag_custom_fields) === false) { - $custom_field_value = $ag_custom_fields[$custom_field['id_field']]; - if (empty($custom_field_value) === true) { - $custom_field_value = ''; - } - } - - $row[1] = html_print_input_text('ag_custom_fields['.$custom_field['id_field'].']', $custom_field_value, '', 100, 300, true); - - $table_custom_fields->data[] = $row; } + } - $filters = '
'; + $div_custom_fields .= '
'; + $div_custom_fields .= '
'; + $div_custom_fields .= ''.$custom_field['name'].''; + $div_custom_fields .= '
'; - if (is_metaconsole() === true) { - $table->colspan[5][0] = 7; - $table->cellstyle[5][0] = 'padding: 10px;'; - $table->data[5][0] = ui_toggle( - html_print_table($table_custom_fields, true), - __('Advanced Options'), - '', - '', - true, - true - ); + $div_custom_fields .= '
'; + $div_custom_fields .= html_print_input_text( + 'ag_custom_fields['.$custom_field['id_field'].']', + $custom_field_value, + '', + 0, + 300, + true, + false, + false, + '', + 'div-input' + ); + $div_custom_fields .= '
'; - $filters .= html_print_table($table, true); - $filters .= ''; - ui_toggle($filters, __('Show filters'), '', '', false); - } else { - $table->colspan[5][0] = 7; - $table->cellstyle[5][0] = 'padding-left: 10px;'; - $table->data[5][0] = ui_toggle( - html_print_table( - $table_custom_fields, - true - ), - __('Agent custom fields'), - '', - '', - true, - true, - '', - 'white-box-content', - 'white_table_graph' - ); + $div_custom_fields .= '
'; +} - $filters .= html_print_table($table, true); - $filters .= ''; - echo $filters; +$div_custom_fields .= '
'; + +$filters = '
'; + +$table2->colspan[2][0] = 7; +$table2->cellstyle[2][0] = 'padding-left: 10px;'; +$table2->data[2][0] = ui_toggle( + $div_custom_fields, + __('Agent custom fields'), + '', + '', + true, + true, + '', + 'white-box-content', + 'white_table_graph' +); + +$table->colspan[3][0] = 7; +$table->cellstyle[3][0] = 'padding-left: 10px;padding-bottom: 0px;'; +$table->data[3][0] = ui_toggle( + html_print_table( + $table2, + true + ), + __('Advanced options'), + '', + '', + true, + true, + '', + 'white-box-content', + 'white_table_graph' +); + +$table->colspan[4][0] = 7; +$table->cellstyle[4][0] = 'padding-top: 0px;'; +$table->data[4][0] = html_print_submit_button( + __('Show'), + 'uptbutton', + false, + 'class="sub search mgn_tp_0 right"', + true +); + +$filters .= html_print_table($table, true); +$filters .= '
'; + +if (is_metaconsole() === true) { + ui_toggle($filters, __('Show filters'), '', '', false); +} else { + echo $filters; +} + +unset($table); +// End Build Search Form. +// +// Sort functionality. +$selected = true; +$selectAgentNameUp = false; +$selectAgentNameDown = false; +$selectDataTypeUp = false; +$selectDataTypeDown = false; +$selectTypeUp = false; +$selectTypeDown = false; +$selectModuleNameUp = false; +$selectModuleNameDown = false; +$selectIntervalUp = false; +$selectIntervalDown = false; +$selectStatusUp = false; +$selectStatusDown = false; +$selectDataUp = false; +$selectDataDown = false; +$selectTimestampUp = false; +$selectTimestampDown = false; +$order = null; + +switch ($sortField) { + case 'agent_alias': + switch ($sort) { + case 'up': + $selectAgentNameUp = $selected; + $order = [ + 'field' => 'tagente.alias', + 'order' => 'ASC', + ]; + break; + + case 'down': + $selectAgentNameDown = $selected; + $order = [ + 'field' => 'tagente.alias', + 'order' => 'DESC', + ]; + break; } + break; - unset($table); - // End Build Search Form. - // - // Sort functionality. - $selected = true; - $selectAgentNameUp = false; + case 'type': + switch ($sort) { + case 'up': + $selectDataTypeUp = $selected; + $order = [ + 'field' => 'tagente_modulo.id_tipo_modulo', + 'order' => 'ASC', + ]; + break; + + case 'down': + $selectDataTypeDown = $selected; + $order = [ + 'field' => 'tagente_modulo.id_tipo_modulo', + 'order' => 'DESC', + ]; + break; + } + break; + + case 'moduletype': + switch ($sort) { + case 'up': + $selectTypeUp = $selected; + $order = [ + 'field' => 'tagente_modulo.id_modulo', + 'order' => 'ASC', + ]; + break; + + case 'down': + $selectTypeDown = $selected; + $order = [ + 'field' => 'tagente_modulo.id_modulo', + 'order' => 'DESC', + ]; + break; + } + break; + + case 'module_name': + switch ($sort) { + case 'up': + $selectModuleNameUp = $selected; + $order = [ + 'field' => 'tagente_modulo.nombre', + 'order' => 'ASC', + ]; + break; + + case 'down': + $selectModuleNameDown = $selected; + $order = [ + 'field' => 'tagente_modulo.nombre', + 'order' => 'DESC', + ]; + break; + } + break; + + case 'interval': + switch ($sort) { + case 'up': + $selectIntervalUp = $selected; + $order = [ + 'field' => 'tagente_modulo.module_interval', + 'order' => 'ASC', + ]; + break; + + case 'down': + $selectIntervalDown = $selected; + $order = [ + 'field' => 'tagente_modulo.module_interval', + 'order' => 'DESC', + ]; + break; + } + break; + + case 'status': + switch ($sort) { + case 'up': + $selectStatusUp = $selected; + $order = [ + 'field' => 'tagente_estado.estado', + 'order' => 'ASC', + ]; + break; + + case 'down': + $selectStatusDown = $selected; + $order = [ + 'field' => 'tagente_estado.estado', + 'order' => 'DESC', + ]; + break; + } + break; + + case 'last_status_change': + switch ($sort) { + case 'up': + $selectStatusUp = $selected; + $order = [ + 'field' => 'tagente_estado.last_status_change', + 'order' => 'ASC', + ]; + break; + + case 'down': + $selectStatusDown = $selected; + $order = [ + 'field' => 'tagente_estado.last_status_change', + 'order' => 'DESC', + ]; + break; + } + break; + + case 'timestamp': + switch ($sort) { + case 'up': + $selectTimestampUp = $selected; + $order = [ + 'field' => 'tagente_estado.utimestamp', + 'order' => 'ASC', + ]; + break; + + case 'down': + $selectTimestampDown = $selected; + $order = [ + 'field' => 'tagente_estado.utimestamp', + 'order' => 'DESC', + ]; + break; + } + break; + + case 'data': + switch ($sort) { + case 'up': + $selectDataUp = $selected; + $order = [ + 'field' => 'tagente_estado.datos', + 'order' => 'ASC', + ]; + break; + + case 'down': + $selectDataDown = $selected; + $order = [ + 'field' => 'tagente_estado.datos', + 'order' => 'DESC', + ]; + break; + } + break; + + default: + $selectAgentNameUp = $selected; $selectAgentNameDown = false; $selectDataTypeUp = false; $selectDataTypeDown = false; @@ -896,212 +1095,12 @@ $table->data[4][0] .= __('Not condition').' '.ui_print_help_tip(__('If you $selectDataDown = false; $selectTimestampUp = false; $selectTimestampDown = false; - $order = null; - - switch ($sortField) { - case 'agent_alias': - switch ($sort) { - case 'up': - $selectAgentNameUp = $selected; - $order = [ - 'field' => 'tagente.alias', - 'order' => 'ASC', - ]; - break; - - case 'down': - $selectAgentNameDown = $selected; - $order = [ - 'field' => 'tagente.alias', - 'order' => 'DESC', - ]; - break; - } - break; - - case 'type': - switch ($sort) { - case 'up': - $selectDataTypeUp = $selected; - $order = [ - 'field' => 'tagente_modulo.id_tipo_modulo', - 'order' => 'ASC', - ]; - break; - - case 'down': - $selectDataTypeDown = $selected; - $order = [ - 'field' => 'tagente_modulo.id_tipo_modulo', - 'order' => 'DESC', - ]; - break; - } - break; - - case 'moduletype': - switch ($sort) { - case 'up': - $selectTypeUp = $selected; - $order = [ - 'field' => 'tagente_modulo.id_modulo', - 'order' => 'ASC', - ]; - break; - - case 'down': - $selectTypeDown = $selected; - $order = [ - 'field' => 'tagente_modulo.id_modulo', - 'order' => 'DESC', - ]; - break; - } - break; - - case 'module_name': - switch ($sort) { - case 'up': - $selectModuleNameUp = $selected; - $order = [ - 'field' => 'tagente_modulo.nombre', - 'order' => 'ASC', - ]; - break; - - case 'down': - $selectModuleNameDown = $selected; - $order = [ - 'field' => 'tagente_modulo.nombre', - 'order' => 'DESC', - ]; - break; - } - break; - - case 'interval': - switch ($sort) { - case 'up': - $selectIntervalUp = $selected; - $order = [ - 'field' => 'tagente_modulo.module_interval', - 'order' => 'ASC', - ]; - break; - - case 'down': - $selectIntervalDown = $selected; - $order = [ - 'field' => 'tagente_modulo.module_interval', - 'order' => 'DESC', - ]; - break; - } - break; - - case 'status': - switch ($sort) { - case 'up': - $selectStatusUp = $selected; - $order = [ - 'field' => 'tagente_estado.estado', - 'order' => 'ASC', - ]; - break; - - case 'down': - $selectStatusDown = $selected; - $order = [ - 'field' => 'tagente_estado.estado', - 'order' => 'DESC', - ]; - break; - } - break; - - case 'last_status_change': - switch ($sort) { - case 'up': - $selectStatusUp = $selected; - $order = [ - 'field' => 'tagente_estado.last_status_change', - 'order' => 'ASC', - ]; - break; - - case 'down': - $selectStatusDown = $selected; - $order = [ - 'field' => 'tagente_estado.last_status_change', - 'order' => 'DESC', - ]; - break; - } - break; - - case 'timestamp': - switch ($sort) { - case 'up': - $selectTimestampUp = $selected; - $order = [ - 'field' => 'tagente_estado.utimestamp', - 'order' => 'ASC', - ]; - break; - - case 'down': - $selectTimestampDown = $selected; - $order = [ - 'field' => 'tagente_estado.utimestamp', - 'order' => 'DESC', - ]; - break; - } - break; - - case 'data': - switch ($sort) { - case 'up': - $selectDataUp = $selected; - $order = [ - 'field' => 'tagente_estado.datos', - 'order' => 'ASC', - ]; - break; - - case 'down': - $selectDataDown = $selected; - $order = [ - 'field' => 'tagente_estado.datos', - 'order' => 'DESC', - ]; - break; - } - break; - - default: - $selectAgentNameUp = $selected; - $selectAgentNameDown = false; - $selectDataTypeUp = false; - $selectDataTypeDown = false; - $selectTypeUp = false; - $selectTypeDown = false; - $selectModuleNameUp = false; - $selectModuleNameDown = false; - $selectIntervalUp = false; - $selectIntervalDown = false; - $selectStatusUp = false; - $selectStatusDown = false; - $selectDataUp = false; - $selectDataDown = false; - $selectTimestampUp = false; - $selectTimestampDown = false; - $order = [ - 'field' => 'tagente.alias', - 'order' => 'ASC', - ]; - break; - } + $order = [ + 'field' => 'tagente.alias', + 'order' => 'ASC', + ]; + break; +} $sql = 'SELECT (SELECT GROUP_CONCAT(ttag.name SEPARATOR \',\') @@ -1150,91 +1149,91 @@ $table->data[4][0] .= __('Not condition').' '.ui_print_help_tip(__('If you // We do not show the modules until the user searches with the filter. - if ($autosearch) { - if (! defined('METACONSOLE')) { - $result = db_get_all_rows_sql($sql); +if ($autosearch) { + if (! defined('METACONSOLE')) { + $result = db_get_all_rows_sql($sql); - if ($result === false) { - $result = []; - } else { - ui_pagination($count, false, $offset, 0, false, 'offset', true); - } - } else { - // For each server defined and not disabled. - $servers = db_get_all_rows_sql( - 'SELECT * + if ($result === false) { + $result = []; + } else { + ui_pagination($count, false, $offset, 0, false, 'offset', true); + } + } else { + // For each server defined and not disabled. + $servers = db_get_all_rows_sql( + 'SELECT * FROM tmetaconsole_setup WHERE disabled = 0' - ); - if ($servers === false) { - $servers = []; - } - - $result = []; - $count_modules = 0; - foreach ($servers as $server) { - // If connection was good then retrieve all data server. - if (metaconsole_connect($server) == NOERR) { - $connection = true; - } else { - $connection = false; - } - - $result_server = db_get_all_rows_sql($sql); - - if (!empty($result_server)) { - // Create HASH login info. - $pwd = $server['auth_token']; - $auth_serialized = json_decode($pwd, true); - - if (is_array($auth_serialized)) { - $pwd = $auth_serialized['auth_token']; - $api_password = $auth_serialized['api_password']; - $console_user = $auth_serialized['console_user']; - $console_password = $auth_serialized['console_password']; - } - - $user = $config['id_user']; - $user_rot13 = str_rot13($config['id_user']); - $hashdata = $user.$pwd; - $hashdata = md5($hashdata); - $url_hash = '&'.'loginhash=auto&'.'loginhash_data='.$hashdata.'&'.'loginhash_user='.$user_rot13; - - foreach ($result_server as $result_element_key => $result_element_value) { - $result_server[$result_element_key]['server_id'] = $server['id']; - $result_server[$result_element_key]['server_name'] = $server['server_name']; - $result_server[$result_element_key]['server_url'] = $server['server_url'].'/'; - $result_server[$result_element_key]['hashdata'] = $hashdata; - $result_server[$result_element_key]['user'] = $config['id_user']; - $result_server[$result_element_key]['groups_in_server'] = agents_get_all_groups_agent( - $result_element_value['id_agent'], - $result_element_value['id_group'] - ); - - $count_modules++; - } - - $result = array_merge($result, $result_server); - } - - metaconsole_restore_db(); - } - - if ($count_modules > $config['block_size']) { - ui_pagination($count_modules, false, $offset); - } - - // Get number of elements of the pagination. - $result = ui_meta_get_subset_array($result, $inferior_limit, $superior_limit); - } + ); + if ($servers === false) { + $servers = []; } - if (($config['dbtype'] == 'oracle') && ($result !== false)) { - for ($i = 0; $i < count($result); $i++) { - unset($result[$i]['rnum']); + $result = []; + $count_modules = 0; + foreach ($servers as $server) { + // If connection was good then retrieve all data server. + if (metaconsole_connect($server) == NOERR) { + $connection = true; + } else { + $connection = false; } + + $result_server = db_get_all_rows_sql($sql); + + if (!empty($result_server)) { + // Create HASH login info. + $pwd = $server['auth_token']; + $auth_serialized = json_decode($pwd, true); + + if (is_array($auth_serialized)) { + $pwd = $auth_serialized['auth_token']; + $api_password = $auth_serialized['api_password']; + $console_user = $auth_serialized['console_user']; + $console_password = $auth_serialized['console_password']; + } + + $user = $config['id_user']; + $user_rot13 = str_rot13($config['id_user']); + $hashdata = $user.$pwd; + $hashdata = md5($hashdata); + $url_hash = '&'.'loginhash=auto&'.'loginhash_data='.$hashdata.'&'.'loginhash_user='.$user_rot13; + + foreach ($result_server as $result_element_key => $result_element_value) { + $result_server[$result_element_key]['server_id'] = $server['id']; + $result_server[$result_element_key]['server_name'] = $server['server_name']; + $result_server[$result_element_key]['server_url'] = $server['server_url'].'/'; + $result_server[$result_element_key]['hashdata'] = $hashdata; + $result_server[$result_element_key]['user'] = $config['id_user']; + $result_server[$result_element_key]['groups_in_server'] = agents_get_all_groups_agent( + $result_element_value['id_agent'], + $result_element_value['id_group'] + ); + + $count_modules++; + } + + $result = array_merge($result, $result_server); + } + + metaconsole_restore_db(); } + if ($count_modules > $config['block_size']) { + ui_pagination($count_modules, false, $offset); + } + + // Get number of elements of the pagination. + $result = ui_meta_get_subset_array($result, $inferior_limit, $superior_limit); + } +} + +if (($config['dbtype'] == 'oracle') && ($result !== false)) { + for ($i = 0; $i < count($result); $i++) { + unset($result[$i]['rnum']); + } +} + // Urls to sort the table. $url_agent_name = 'index.php?sec='.$section.'&sec2=operation/agentes/status_monitor'; @@ -1284,570 +1283,553 @@ $table->data[4][0] .= __('Not condition').' '.ui_print_help_tip(__('If you $url_timestamp_down .= '&sort_field=timestamp&sort=down'; // Start Build List Result. - if (!empty($result)) { - $table = new StdClass(); - $table->cellpadding = 0; - $table->cellspacing = 0; - $table->width = '100%'; - $table->class = 'info_table'; - $table->head = []; - $table->data = []; - $table->size = []; - $table->align = []; +if (!empty($result)) { + $table = new StdClass(); + $table->cellpadding = 0; + $table->cellspacing = 0; + $table->width = '100%'; + $table->class = 'info_table'; + $table->head = []; + $table->data = []; + $table->size = []; + $table->align = []; - $show_fields = explode(',', $config['status_monitor_fields']); + $show_fields = explode(',', $config['status_monitor_fields']); - if (in_array('policy', $show_fields)) { - if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) { - $table->head[0] = ''.__('P.').''; - } - } + if (in_array('policy', $show_fields)) { + if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) { + $table->head[0] = ''.__('P.').''; + } + } - if (in_array('agent', $show_fields) || is_metaconsole()) { - $table->head[1] = __('Agent'); - $table->head[1] .= ui_get_sorting_arrows($url_agent_name.'up', $url_agent_name.'down', $selectAgentNameUp, $selectAgentNameDown); - } + if (in_array('agent', $show_fields) || is_metaconsole()) { + $table->head[1] = __('Agent'); + $table->head[1] .= ui_get_sorting_arrows($url_agent_name.'up', $url_agent_name.'down', $selectAgentNameUp, $selectAgentNameDown); + } - if (in_array('data_type', $show_fields) || is_metaconsole()) { - $table->head[2] = __('Data Type'); - $table->head[2] .= ui_get_sorting_arrows($url_type.'up', $url_type.'down', $selectDataTypeUp, $selectDataTypeDown); - $table->align[2] = 'left'; - } + if (in_array('data_type', $show_fields) || is_metaconsole()) { + $table->head[2] = __('Data Type'); + $table->head[2] .= ui_get_sorting_arrows($url_type.'up', $url_type.'down', $selectDataTypeUp, $selectDataTypeDown); + $table->align[2] = 'left'; + } - if (in_array('module_name', $show_fields) || is_metaconsole()) { - $table->head[3] = __('Module name'); - $table->head[3] .= ui_get_sorting_arrows($url_module_name.'up', $url_module_name.'down', $selectModuleNameUp, $selectModuleNameDown); - } + if (in_array('module_name', $show_fields) || is_metaconsole()) { + $table->head[3] = __('Module name'); + $table->head[3] .= ui_get_sorting_arrows($url_module_name.'up', $url_module_name.'down', $selectModuleNameUp, $selectModuleNameDown); + } - if (in_array('server_type', $show_fields) || is_metaconsole()) { - $table->head[4] = __('Server type'); - $table->head[4] .= ui_get_sorting_arrows($url_server_type.'up', $url_server_type.'down', $selectTypeUp, $selectTypeDown); - } + if (in_array('server_type', $show_fields) || is_metaconsole()) { + $table->head[4] = __('Server type'); + $table->head[4] .= ui_get_sorting_arrows($url_server_type.'up', $url_server_type.'down', $selectTypeUp, $selectTypeDown); + } - if (in_array('interval', $show_fields) || is_metaconsole()) { - $table->head[5] = __('Interval'); - $table->head[5] .= ui_get_sorting_arrows($url_interval.'up', $url_interval.'down', $selectIntervalUp, $selectIntervalDown); - $table->align[5] = 'left'; - } + if (in_array('interval', $show_fields) || is_metaconsole()) { + $table->head[5] = __('Interval'); + $table->head[5] .= ui_get_sorting_arrows($url_interval.'up', $url_interval.'down', $selectIntervalUp, $selectIntervalDown); + $table->align[5] = 'left'; + } - if (in_array('status', $show_fields) || is_metaconsole()) { - $table->head[6] = __('Status'); - $table->head[6] .= ui_get_sorting_arrows($url_status.'up', $url_status.'down', $selectStatusUp, $selectStatusDown); - $table->align[6] = 'left'; - } + if (in_array('status', $show_fields) || is_metaconsole()) { + $table->head[6] = __('Status'); + $table->head[6] .= ui_get_sorting_arrows($url_status.'up', $url_status.'down', $selectStatusUp, $selectStatusDown); + $table->align[6] = 'left'; + } - if (in_array('last_status_change', $show_fields)) { - $table->head[7] = __('Last status change'); - $table->head[7] .= ui_get_sorting_arrows($url_status.'up', $url_status.'down', $selectStatusUp, $selectStatusDown); - $table->align[7] = 'left'; - } + if (in_array('last_status_change', $show_fields)) { + $table->head[7] = __('Last status change'); + $table->head[7] .= ui_get_sorting_arrows($url_status.'up', $url_status.'down', $selectStatusUp, $selectStatusDown); + $table->align[7] = 'left'; + } - if (in_array('graph', $show_fields) || is_metaconsole()) { - $table->head[8] = __('Graph'); - $table->align[8] = 'left'; - } + if (in_array('graph', $show_fields) || is_metaconsole()) { + $table->head[8] = __('Graph'); + $table->align[8] = 'left'; + } - if (in_array('warn', $show_fields) || is_metaconsole()) { - $table->head[9] = __('Warn'); - $table->align[9] = 'left'; - } + if (in_array('warn', $show_fields) || is_metaconsole()) { + $table->head[9] = __('Warn'); + $table->align[9] = 'left'; + } - if (in_array('data', $show_fields) || is_metaconsole()) { - $table->head[10] = __('Data'); - $table->align[10] = 'left'; + if (in_array('data', $show_fields) || is_metaconsole()) { + $table->head[10] = __('Data'); + $table->align[10] = 'left'; + if (is_metaconsole()) { + $table->head[10] .= ui_get_sorting_arrows($url_data.'up', $url_data.'down', $selectDataUp, $selectDataDown); + } + } + + if (in_array('timestamp', $show_fields) || is_metaconsole()) { + $table->head[11] = __('Timestamp'); + $table->head[11] .= ui_get_sorting_arrows($url_timestamp_up, $url_timestamp_down, $selectTimestampUp, $selectTimestampDown); + $table->align[11] = 'left'; + } + + $id_type_web_content_string = db_get_value( + 'id_tipo', + 'ttipo_modulo', + 'nombre', + 'web_content_string' + ); + + foreach ($result as $row) { + // Avoid unset, null and false value. + if (empty($row['server_name'])) { + $row['server_name'] = ''; + } + + $is_web_content_string = (bool) db_get_value_filter( + 'id_agente_modulo', + 'tagente_modulo', + [ + 'id_agente_modulo' => $row['id_agente_modulo'], + 'id_tipo_modulo' => $id_type_web_content_string, + ] + ); + + // Fixed the goliat sends the strings from web. + // Without HTML entities. + if ($is_web_content_string) { + $row['datos'] = io_safe_input($row['datos']); + } + + // Fixed the data from Selenium Plugin. + if ($row['datos'] != strip_tags($row['datos'])) { + $row['datos'] = io_safe_input($row['datos']); + } + + $data = []; + + if (in_array('policy', $show_fields) || is_metaconsole()) { + if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) { if (is_metaconsole()) { - $table->head[10] .= ui_get_sorting_arrows($url_data.'up', $url_data.'down', $selectDataUp, $selectDataDown); - } - } - - if (in_array('timestamp', $show_fields) || is_metaconsole()) { - $table->head[11] = __('Timestamp'); - $table->head[11] .= ui_get_sorting_arrows($url_timestamp_up, $url_timestamp_down, $selectTimestampUp, $selectTimestampDown); - $table->align[11] = 'left'; - } - - $id_type_web_content_string = db_get_value( - 'id_tipo', - 'ttipo_modulo', - 'nombre', - 'web_content_string' - ); - - foreach ($result as $row) { - // Avoid unset, null and false value. - if (empty($row['server_name'])) { - $row['server_name'] = ''; + $node = metaconsole_get_connection_by_id($row['server_id']); + if (metaconsole_load_external_db($node) !== NOERR) { + // Restore the default connection. + metaconsole_restore_db(); + $errors++; + break; + } } - $is_web_content_string = (bool) db_get_value_filter( - 'id_agente_modulo', - 'tagente_modulo', + $policyInfo = policies_info_module_policy($row['id_agente_modulo']); + + if ($policyInfo === false) { + $data[0] = ''; + } else { + $linked = policies_is_module_linked($row['id_agente_modulo']); + + $adopt = false; + if (policies_is_module_adopt($row['id_agente_modulo'])) { + $adopt = true; + } + + if ($linked) { + if ($adopt) { + $img = 'images/policies_brick.png'; + $title = __('(Adopt) ').$policyInfo['name_policy']; + } else { + $img = 'images/policies_mc.png'; + $title = $policyInfo['name_policy']; + } + } else { + if ($adopt) { + $img = 'images/policies_not_brick.png'; + $title = __('(Unlinked) (Adopt) ').$policyInfo['name_policy']; + } else { + $img = 'images/unlinkpolicy.png'; + $title = __('(Unlinked) ').$policyInfo['name_policy']; + } + } + + if (is_metaconsole()) { + $data[0] = '
'.html_print_image($img, true, ['title' => $title]).''; + } else { + $data[0] = ''.html_print_image($img, true, ['title' => $title]).''; + } + } + + if (is_metaconsole()) { + metaconsole_restore_db(); + } + } + } + + if (in_array('agent', $show_fields) || is_metaconsole()) { + $agent_alias = !empty($row['agent_alias']) ? $row['agent_alias'] : $row['agent_name']; + + // TODO: Calculate hash access before to use it more simply like other sections. I.E. Events view + if (defined('METACONSOLE')) { + $agent_link = ''; + $agent_alias = ui_print_truncate_text( + $agent_alias, + 'agent_small', + false, + true, + false, + '[…]', + 'font-size:7.5pt;' + ); + if (can_user_access_node()) { + $data[1] = $agent_link.''.$agent_alias.''; + } else { + $data[1] = $agent_alias; + } + } else { + $data[1] = ''; + $data[1] .= ui_print_truncate_text($agent_alias, 'agent_medium', false, true, false, '[…]', 'font-size:7.5pt;'); + $data[1] .= ''; + } + } + + if (in_array('data_type', $show_fields) || is_metaconsole()) { + $data[2] = html_print_image('images/'.modules_show_icon_type($row['module_type']), true, ['class' => 'invert_filter']); + $agent_groups = is_metaconsole() ? $row['groups_in_server'] : agents_get_all_groups_agent($row['id_agent'], $row['id_group']); + if (check_acl_one_of_groups($config['id_user'], $agent_groups, 'AW')) { + $show_edit_icon = true; + if (defined('METACONSOLE')) { + if (!can_user_access_node()) { + $show_edit_icon = false; + } + + $url_edit_module = $row['server_url'].'index.php?'.'sec=gagente&'.'sec2=godmode/agentes/configurar_agente&'.'id_agente='.$row['id_agent'].'&'.'tab=module&'.'id_agent_module='.$row['id_agente_modulo'].'&'.'edit_module=1'.'&loginhash=auto&loginhash_data='.$row['hashdata'].'&loginhash_user='.str_rot13($row['user']); + } else { + $url_edit_module = 'index.php?'.'sec=gagente&'.'sec2=godmode/agentes/configurar_agente&'.'id_agente='.$row['id_agent'].'&'.'tab=module&'.'id_agent_module='.$row['id_agente_modulo'].'&'.'edit_module=1'; + } + + if ($show_edit_icon) { + $table->cellclass[][2] = 'action_buttons'; + $data[2] .= ''.html_print_image( + 'images/config.png', + true, + [ + 'alt' => '0', + 'border' => '', + 'title' => __('Edit'), + ] + ).''; + } + } + } + + if (in_array('module_name', $show_fields) || is_metaconsole()) { + $data[3] = ui_print_truncate_text($row['module_name'], 'module_small', false, true, true); + if ($row['extended_info'] != '') { + $data[3] .= ui_print_help_tip($row['extended_info'], true, '/images/default_list.png'); + } + + if ($row['tags'] != '') { + $data[3] .= html_print_image( + '/images/tag_red.png', + true, [ - 'id_agente_modulo' => $row['id_agente_modulo'], - 'id_tipo_modulo' => $id_type_web_content_string, + 'title' => $row['tags'], + 'class' => 'tag_row', ] ); + } + } - // Fixed the goliat sends the strings from web. - // Without HTML entities. - if ($is_web_content_string) { - $row['datos'] = io_safe_input($row['datos']); - } - - // Fixed the data from Selenium Plugin. - if ($row['datos'] != strip_tags($row['datos'])) { - $row['datos'] = io_safe_input($row['datos']); - } - - $data = []; - - if (in_array('policy', $show_fields) || is_metaconsole()) { - if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) { - if (is_metaconsole()) { - $node = metaconsole_get_connection_by_id($row['server_id']); - if (metaconsole_load_external_db($node) !== NOERR) { - // Restore the default connection. - metaconsole_restore_db(); - $errors++; - break; - } - } - - $policyInfo = policies_info_module_policy($row['id_agente_modulo']); - - if ($policyInfo === false) { - $data[0] = ''; - } else { - $linked = policies_is_module_linked($row['id_agente_modulo']); - - $adopt = false; - if (policies_is_module_adopt($row['id_agente_modulo'])) { - $adopt = true; - } - - if ($linked) { - if ($adopt) { - $img = 'images/policies_brick.png'; - $title = __('(Adopt) ').$policyInfo['name_policy']; - } else { - $img = 'images/policies_mc.png'; - $title = $policyInfo['name_policy']; - } - } else { - if ($adopt) { - $img = 'images/policies_not_brick.png'; - $title = __('(Unlinked) (Adopt) ').$policyInfo['name_policy']; - } else { - $img = 'images/unlinkpolicy.png'; - $title = __('(Unlinked) ').$policyInfo['name_policy']; - } - } - - if (is_metaconsole()) { - $data[0] = ''.html_print_image($img, true, ['title' => $title]).''; - } else { - $data[0] = ''.html_print_image($img, true, ['title' => $title]).''; - } - } - - if (is_metaconsole()) { - metaconsole_restore_db(); - } - } - } - - if (in_array('agent', $show_fields) || is_metaconsole()) { - $agent_alias = !empty($row['agent_alias']) ? $row['agent_alias'] : $row['agent_name']; - - // TODO: Calculate hash access before to use it more simply like other sections. I.E. Events view - if (defined('METACONSOLE')) { - $agent_link = ''; - $agent_alias = ui_print_truncate_text( - $agent_alias, - 'agent_small', - false, - true, - false, - '[…]', - 'font-size:7.5pt;' - ); - if (can_user_access_node()) { - $data[1] = $agent_link.''.$agent_alias.''; - } else { - $data[1] = $agent_alias; - } - } else { - $data[1] = ''; - $data[1] .= ui_print_truncate_text($agent_alias, 'agent_medium', false, true, false, '[…]', 'font-size:7.5pt;'); - $data[1] .= ''; - } - } - - if (in_array('data_type', $show_fields) || is_metaconsole()) { - $data[2] = html_print_image('images/'.modules_show_icon_type($row['module_type']), true, ['class' => 'invert_filter']); - $agent_groups = is_metaconsole() ? $row['groups_in_server'] : agents_get_all_groups_agent($row['id_agent'], $row['id_group']); - if (check_acl_one_of_groups($config['id_user'], $agent_groups, 'AW')) { - $show_edit_icon = true; - if (defined('METACONSOLE')) { - if (!can_user_access_node()) { - $show_edit_icon = false; - } - - $url_edit_module = $row['server_url'].'index.php?'.'sec=gagente&'.'sec2=godmode/agentes/configurar_agente&'.'id_agente='.$row['id_agent'].'&'.'tab=module&'.'id_agent_module='.$row['id_agente_modulo'].'&'.'edit_module=1'.'&loginhash=auto&loginhash_data='.$row['hashdata'].'&loginhash_user='.str_rot13($row['user']); - } else { - $url_edit_module = 'index.php?'.'sec=gagente&'.'sec2=godmode/agentes/configurar_agente&'.'id_agente='.$row['id_agent'].'&'.'tab=module&'.'id_agent_module='.$row['id_agente_modulo'].'&'.'edit_module=1'; - } - - if ($show_edit_icon) { - $table->cellclass[][2] = 'action_buttons'; - $data[2] .= ''.html_print_image( - 'images/config.png', - true, - [ - 'alt' => '0', - 'border' => '', - 'title' => __('Edit'), - ] - ).''; - } - } - } - - if (in_array('module_name', $show_fields) || is_metaconsole()) { - $data[3] = ui_print_truncate_text($row['module_name'], 'module_small', false, true, true); - if ($row['extended_info'] != '') { - $data[3] .= ui_print_help_tip($row['extended_info'], true, '/images/default_list.png'); - } - - if ($row['tags'] != '') { - $data[3] .= html_print_image( - '/images/tag_red.png', - true, - [ - 'title' => $row['tags'], - 'class' => 'tag_row', - ] - ); - } - } - - if (in_array('server_type', $show_fields) || is_metaconsole()) { - $data[4] = servers_show_type($row['id_modulo']); - } + if (in_array('server_type', $show_fields) || is_metaconsole()) { + $data[4] = servers_show_type($row['id_modulo']); + } - if (in_array('module_name', $show_fields) || is_metaconsole()) { - $data[3] = ui_print_truncate_text($row['module_name'], 'module_small', false, true, true); - if ($row['extended_info'] != '') { - $data[3] .= ui_print_help_tip($row['extended_info'], true, '/images/default_list.png'); - } + if (in_array('module_name', $show_fields) || is_metaconsole()) { + $data[3] = ui_print_truncate_text($row['module_name'], 'module_small', false, true, true); + if ($row['extended_info'] != '') { + $data[3] .= ui_print_help_tip($row['extended_info'], true, '/images/default_list.png'); + } - if ($row['tags'] != '') { - $data[3] .= html_print_image( - '/images/tag_red.png', - true, - [ - 'title' => $row['tags'], - 'class' => 'tag_row invert_filter', - ] - ); - } - } + if ($row['tags'] != '') { + $data[3] .= html_print_image( + '/images/tag_red.png', + true, + [ + 'title' => $row['tags'], + 'class' => 'tag_row invert_filter', + ] + ); + } + } - if (in_array('server_type', $show_fields) || is_metaconsole()) { - $data[4] = servers_show_type($row['id_modulo']); - } + if (in_array('server_type', $show_fields) || is_metaconsole()) { + $data[4] = servers_show_type($row['id_modulo']); + } - if (in_array('interval', $show_fields) || is_metaconsole()) { - $data[5] = ($row['module_interval'] == 0) ? human_time_description_raw($row['agent_interval']) : human_time_description_raw($row['module_interval']); - } + if (in_array('interval', $show_fields) || is_metaconsole()) { + $data[5] = ($row['module_interval'] == 0) ? human_time_description_raw($row['agent_interval']) : human_time_description_raw($row['module_interval']); + } - if (in_array('status', $show_fields) || is_metaconsole()) { - if ($row['utimestamp'] == 0 && (($row['module_type'] < 21 - || $row['module_type'] > 23) && $row['module_type'] != 100) - ) { - $data[6] = ui_print_status_image( - STATUS_MODULE_NO_DATA, - __('NOT INIT'), - true - ); - } else if ($row['estado'] == 0) { - if (is_numeric($row['datos'])) { - $data[6] = ui_print_status_image( - STATUS_MODULE_OK, - __('NORMAL').': '.remove_right_zeros(number_format($row['datos'], $config['graph_precision'])), - true - ); - } else { - $data[6] = ui_print_status_image( - STATUS_MODULE_OK, - __('NORMAL').': '.htmlspecialchars($row['datos']), - true - ); - } - } else if ($row['estado'] == 1) { - if (is_numeric($row['datos'])) { - $data[6] = ui_print_status_image( - STATUS_MODULE_CRITICAL, - __('CRITICAL').': '.remove_right_zeros( - number_format($row['datos'], $config['graph_precision']) - ), - true - ); - } else { - $data[6] = ui_print_status_image( - STATUS_MODULE_CRITICAL, - __('CRITICAL').': '.htmlspecialchars($row['datos']), - true - ); - } - } else if ($row['estado'] == 2) { - if (is_numeric($row['datos'])) { - $data[6] = ui_print_status_image( - STATUS_MODULE_WARNING, - __('WARNING').': '.remove_right_zeros( - number_format($row['datos'], $config['graph_precision']) - ), - true - ); - } else { - $data[6] = ui_print_status_image( - STATUS_MODULE_WARNING, - __('WARNING').': '.htmlspecialchars($row['datos']), - true - ); - } - } else if ($row['estado'] == 3) { - if (is_numeric($row['datos'])) { - $data[6] = ui_print_status_image( - STATUS_MODULE_UNKNOWN, - __('UNKNOWN').': '.remove_right_zeros( - number_format($row['datos'], $config['graph_precision']) - ), - true - ); - } else { - $data[6] = ui_print_status_image( - STATUS_MODULE_UNKNOWN, - __('UNKNOWN').': '.htmlspecialchars($row['datos']), - true - ); - } - } else if ($row['estado'] == 4) { - if (is_numeric($row['datos'])) { - $data[6] = ui_print_status_image( - STATUS_MODULE_NO_DATA, - __('NO DATA').': '.remove_right_zeros( - number_format($row['datos'], $config['graph_precision']) - ), - true - ); - } else { - $data[6] = ui_print_status_image( - STATUS_MODULE_NO_DATA, - __('NO DATA').': '.htmlspecialchars($row['datos']), - true - ); - } - } else { - $last_status = modules_get_agentmodule_last_status( - $row['id_agente_modulo'] - ); - switch ($last_status) { - case 0: - if (is_numeric($row['datos'])) { - $data[6] = ui_print_status_image( - STATUS_MODULE_UNKNOWN, - __('UNKNOWN').' - '.__('Last status').' '.__('NORMAL').': '.remove_right_zeros(number_format($row['datos'], $config['graph_precision'])), - true - ); - } else { - $data[6] = ui_print_status_image( - STATUS_MODULE_UNKNOWN, - __('UNKNOWN').' - '.__('Last status').' '.__('NORMAL').': '.htmlspecialchars($row['datos']), - true - ); - } - break; - - case 1: - if (is_numeric($row['datos'])) { - $data[6] = ui_print_status_image( - STATUS_MODULE_UNKNOWN, - __('UNKNOWN').' - '.__('Last status').' '.__('CRITICAL').': '.remove_right_zeros(number_format($row['datos'], $config['graph_precision'])), - true - ); - } else { - $data[6] = ui_print_status_image( - STATUS_MODULE_UNKNOWN, - __('UNKNOWN').' - '.__('Last status').' '.__('CRITICAL').': '.htmlspecialchars($row['datos']), - true - ); - } - break; - - case 2: - if (is_numeric($row['datos'])) { - $data[6] = ui_print_status_image( - STATUS_MODULE_UNKNOWN, - __('UNKNOWN').' - '.__('Last status').' '.__('WARNING').': '.remove_right_zeros(number_format($row['datos'], $config['graph_precision'])), - true - ); - } else { - $data[6] = ui_print_status_image( - STATUS_MODULE_UNKNOWN, - __('UNKNOWN').' - '.__('Last status').' '.__('WARNING').': '.htmlspecialchars($row['datos']), - true - ); - } - break; - } - } - } - - if (in_array('last_status_change', $show_fields) || is_metaconsole()) { - $data[7] = ($row['last_status_change'] > 0) ? human_time_comparation($row['last_status_change']) : __('N/A'); - } - - if (in_array('graph', $show_fields) || is_metaconsole()) { - $data[8] = ''; - - $acl_graphs = false; - - // Avoid the check on the metaconsole. Too slow to show/hide an icon depending on the permissions. - if (!is_metaconsole()) { - $agent_groups = agents_get_all_groups_agent($row['id_agent'], $row['id_group']); - $acl_graphs = check_acl_one_of_groups($config['id_user'], $agent_groups, 'RR'); - } else { - $acl_graphs = true; - } - - if ($row['history_data'] == 1 && $acl_graphs) { - $tresholds = true; - if (empty((float) $module['min_warning']) === true - && empty((float) $module['max_warning']) === true - && empty($module['warning_inverse']) === true - && empty((float) $module['min_critical']) === true - && empty((float) $module['max_critical']) === true - && empty($module['critical_inverse']) === true - ) { - $tresholds = false; - } - - $graph_type = return_graphtype($row['module_type']); - - $url = ui_get_full_url('operation/agentes/stat_win.php', false, false, false); - $handle = dechex(crc32($row['id_agente_modulo'].$row['module_name'])); - $win_handle = 'day_'.$handle; - - $graph_params = [ - 'type' => $graph_type, - 'period' => SECONDS_1DAY, - 'id' => $row['id_agente_modulo'], - 'refresh' => SECONDS_10MINUTES, - ]; - - if ($tresholds === true || $graph_type === 'boolean') { - $graph_params['histogram'] = 1; - } - - if (is_metaconsole() && isset($row['server_id'])) { - // Set the server id. - $graph_params['server'] = $row['server_id']; - } - - $graph_params_str = http_build_query($graph_params); - - $link = 'winopeng_var(\''.$url.'?'.$graph_params_str.'\',\''.$win_handle.'\', 800, 480)'; - - $data[8] = get_module_realtime_link_graph($row); - - if ($tresholds === true || $graph_type === 'boolean') { - $data[8] .= ''.html_print_image( - 'images/histograma.png', - true, - [ - 'border' => '0', - 'alt' => '', - 'class' => 'invert_filter', - ] - ).''; - } - - if (!is_snapshot_data($row['datos'])) { - if ($tresholds === true || $graph_type === 'boolean') { - unset($graph_params['histogram']); - } - - $graph_params_str = http_build_query($graph_params); - - $link = 'winopeng_var(\''.$url.'?'.$graph_params_str.'\',\''.$win_handle.'\', 800, 480)'; - $data[8] .= ''.html_print_image('images/chart.png', true, ['border' => '0', 'alt' => '', 'class' => 'invert_filter']).''; - } - - $data[8] .= ''.html_print_image( - 'images/binary.png', - true, - [ - 'border' => '0', - 'alt' => '', - 'class' => 'invert_filter', - ] - ).''; - - $data[8] .= ''.$row['module_name'].''; - } - } - - if (in_array('warn', $show_fields) || is_metaconsole()) { - $data[9] = ui_print_module_warn_value( - $row['max_warning'], - $row['min_warning'], - $row['str_warning'], - $row['max_critical'], - $row['min_critical'], - $row['str_critical'], - $row['warning_inverse'], - $row['critical_inverse'] + if (in_array('status', $show_fields) || is_metaconsole()) { + if ($row['utimestamp'] == 0 && (($row['module_type'] < 21 + || $row['module_type'] > 23) && $row['module_type'] != 100) + ) { + $data[6] = ui_print_status_image( + STATUS_MODULE_NO_DATA, + __('NOT INIT'), + true + ); + } else if ($row['estado'] == 0) { + if (is_numeric($row['datos'])) { + $data[6] = ui_print_status_image( + STATUS_MODULE_OK, + __('NORMAL').': '.remove_right_zeros(number_format($row['datos'], $config['graph_precision'])), + true ); - - if (is_numeric($row['datos']) && !modules_is_string_type($row['module_type'])) { - if ($config['render_proc']) { - switch ($row['module_type']) { - case 2: - case 6: - case 9: - case 18: - case 21: - case 31: - if ($row['datos'] >= 1) { - $salida = $config['render_proc_ok']; - } else { - $salida = $config['render_proc_fail']; - } - break; - - default: - switch ($row['module_type']) { - case 15: - $value = db_get_value('snmp_oid', 'tagente_modulo', 'id_agente_modulo', $row['id_agente_modulo']); - if ($value == '.1.3.6.1.2.1.1.3.0' || $value == '.1.3.6.1.2.1.25.1.1.0') { - $salida = human_milliseconds_to_string($row['datos']); - } else { - $salida = remove_right_zeros(number_format($row['datos'], $config['graph_precision'])); - } - break; - - default: - $salida = remove_right_zeros(number_format($row['datos'], $config['graph_precision'])); - break; - } - break; - } + } else { + $data[6] = ui_print_status_image( + STATUS_MODULE_OK, + __('NORMAL').': '.htmlspecialchars($row['datos']), + true + ); + } + } else if ($row['estado'] == 1) { + if (is_numeric($row['datos'])) { + $data[6] = ui_print_status_image( + STATUS_MODULE_CRITICAL, + __('CRITICAL').': '.remove_right_zeros( + number_format($row['datos'], $config['graph_precision']) + ), + true + ); + } else { + $data[6] = ui_print_status_image( + STATUS_MODULE_CRITICAL, + __('CRITICAL').': '.htmlspecialchars($row['datos']), + true + ); + } + } else if ($row['estado'] == 2) { + if (is_numeric($row['datos'])) { + $data[6] = ui_print_status_image( + STATUS_MODULE_WARNING, + __('WARNING').': '.remove_right_zeros( + number_format($row['datos'], $config['graph_precision']) + ), + true + ); + } else { + $data[6] = ui_print_status_image( + STATUS_MODULE_WARNING, + __('WARNING').': '.htmlspecialchars($row['datos']), + true + ); + } + } else if ($row['estado'] == 3) { + if (is_numeric($row['datos'])) { + $data[6] = ui_print_status_image( + STATUS_MODULE_UNKNOWN, + __('UNKNOWN').': '.remove_right_zeros( + number_format($row['datos'], $config['graph_precision']) + ), + true + ); + } else { + $data[6] = ui_print_status_image( + STATUS_MODULE_UNKNOWN, + __('UNKNOWN').': '.htmlspecialchars($row['datos']), + true + ); + } + } else if ($row['estado'] == 4) { + if (is_numeric($row['datos'])) { + $data[6] = ui_print_status_image( + STATUS_MODULE_NO_DATA, + __('NO DATA').': '.remove_right_zeros( + number_format($row['datos'], $config['graph_precision']) + ), + true + ); + } else { + $data[6] = ui_print_status_image( + STATUS_MODULE_NO_DATA, + __('NO DATA').': '.htmlspecialchars($row['datos']), + true + ); + } + } else { + $last_status = modules_get_agentmodule_last_status( + $row['id_agente_modulo'] + ); + switch ($last_status) { + case 0: + if (is_numeric($row['datos'])) { + $data[6] = ui_print_status_image( + STATUS_MODULE_UNKNOWN, + __('UNKNOWN').' - '.__('Last status').' '.__('NORMAL').': '.remove_right_zeros(number_format($row['datos'], $config['graph_precision'])), + true + ); } else { + $data[6] = ui_print_status_image( + STATUS_MODULE_UNKNOWN, + __('UNKNOWN').' - '.__('Last status').' '.__('NORMAL').': '.htmlspecialchars($row['datos']), + true + ); + } + break; + + case 1: + if (is_numeric($row['datos'])) { + $data[6] = ui_print_status_image( + STATUS_MODULE_UNKNOWN, + __('UNKNOWN').' - '.__('Last status').' '.__('CRITICAL').': '.remove_right_zeros(number_format($row['datos'], $config['graph_precision'])), + true + ); + } else { + $data[6] = ui_print_status_image( + STATUS_MODULE_UNKNOWN, + __('UNKNOWN').' - '.__('Last status').' '.__('CRITICAL').': '.htmlspecialchars($row['datos']), + true + ); + } + break; + + case 2: + if (is_numeric($row['datos'])) { + $data[6] = ui_print_status_image( + STATUS_MODULE_UNKNOWN, + __('UNKNOWN').' - '.__('Last status').' '.__('WARNING').': '.remove_right_zeros(number_format($row['datos'], $config['graph_precision'])), + true + ); + } else { + $data[6] = ui_print_status_image( + STATUS_MODULE_UNKNOWN, + __('UNKNOWN').' - '.__('Last status').' '.__('WARNING').': '.htmlspecialchars($row['datos']), + true + ); + } + break; + } + } + } + + if (in_array('last_status_change', $show_fields) || is_metaconsole()) { + $data[7] = ($row['last_status_change'] > 0) ? human_time_comparation($row['last_status_change']) : __('N/A'); + } + + if (in_array('graph', $show_fields) || is_metaconsole()) { + $data[8] = ''; + + $acl_graphs = false; + + // Avoid the check on the metaconsole. Too slow to show/hide an icon depending on the permissions. + if (!is_metaconsole()) { + $agent_groups = agents_get_all_groups_agent($row['id_agent'], $row['id_group']); + $acl_graphs = check_acl_one_of_groups($config['id_user'], $agent_groups, 'RR'); + } else { + $acl_graphs = true; + } + + if ($row['history_data'] == 1 && $acl_graphs) { + $tresholds = true; + if (empty((float) $module['min_warning']) === true + && empty((float) $module['max_warning']) === true + && empty($module['warning_inverse']) === true + && empty((float) $module['min_critical']) === true + && empty((float) $module['max_critical']) === true + && empty($module['critical_inverse']) === true + ) { + $tresholds = false; + } + + $graph_type = return_graphtype($row['module_type']); + + $url = ui_get_full_url('operation/agentes/stat_win.php', false, false, false); + $handle = dechex(crc32($row['id_agente_modulo'].$row['module_name'])); + $win_handle = 'day_'.$handle; + + $graph_params = [ + 'type' => $graph_type, + 'period' => SECONDS_1DAY, + 'id' => $row['id_agente_modulo'], + 'refresh' => SECONDS_10MINUTES, + ]; + + if ($tresholds === true || $graph_type === 'boolean') { + $graph_params['histogram'] = 1; + } + + if (is_metaconsole() && isset($row['server_id'])) { + // Set the server id. + $graph_params['server'] = $row['server_id']; + } + + $graph_params_str = http_build_query($graph_params); + + $link = 'winopeng_var(\''.$url.'?'.$graph_params_str.'\',\''.$win_handle.'\', 800, 480)'; + + $data[8] = get_module_realtime_link_graph($row); + + if ($tresholds === true || $graph_type === 'boolean') { + $data[8] .= ''.html_print_image( + 'images/histograma.png', + true, + [ + 'border' => '0', + 'alt' => '', + 'class' => 'invert_filter', + ] + ).''; + } + + if (!is_snapshot_data($row['datos'])) { + if ($tresholds === true || $graph_type === 'boolean') { + unset($graph_params['histogram']); + } + + $graph_params_str = http_build_query($graph_params); + + $link = 'winopeng_var(\''.$url.'?'.$graph_params_str.'\',\''.$win_handle.'\', 800, 480)'; + $data[8] .= ''.html_print_image('images/chart.png', true, ['border' => '0', 'alt' => '', 'class' => 'invert_filter']).''; + } + + $data[8] .= ''.html_print_image( + 'images/binary.png', + true, + [ + 'border' => '0', + 'alt' => '', + 'class' => 'invert_filter', + ] + ).''; + + $data[8] .= ''.$row['module_name'].''; + } + } + + if (in_array('warn', $show_fields) || is_metaconsole()) { + $data[9] = ui_print_module_warn_value( + $row['max_warning'], + $row['min_warning'], + $row['str_warning'], + $row['max_critical'], + $row['min_critical'], + $row['str_critical'], + $row['warning_inverse'], + $row['critical_inverse'] + ); + + if (is_numeric($row['datos']) && !modules_is_string_type($row['module_type'])) { + if ($config['render_proc']) { + switch ($row['module_type']) { + case 2: + case 6: + case 9: + case 18: + case 21: + case 31: + if ($row['datos'] >= 1) { + $salida = $config['render_proc_ok']; + } else { + $salida = $config['render_proc_fail']; + } + break; + + default: switch ($row['module_type']) { case 15: $value = db_get_value('snmp_oid', 'tagente_modulo', 'id_agente_modulo', $row['id_agente_modulo']); @@ -1862,128 +1844,145 @@ $table->data[4][0] .= __('Not condition').' '.ui_print_help_tip(__('If you $salida = remove_right_zeros(number_format($row['datos'], $config['graph_precision'])); break; } - } + break; + } + } else { + switch ($row['module_type']) { + case 15: + $value = db_get_value('snmp_oid', 'tagente_modulo', 'id_agente_modulo', $row['id_agente_modulo']); + if ($value == '.1.3.6.1.2.1.1.3.0' || $value == '.1.3.6.1.2.1.25.1.1.0') { + $salida = human_milliseconds_to_string($row['datos']); + } else { + $salida = remove_right_zeros(number_format($row['datos'], $config['graph_precision'])); + } + break; - // Show units ONLY in numeric data types. - if (isset($row['unit'])) { + default: + $salida = remove_right_zeros(number_format($row['datos'], $config['graph_precision'])); + break; + } + } + + // Show units ONLY in numeric data types. + if (isset($row['unit'])) { + $data_macro = modules_get_unit_macro($row['datos'], $row['unit']); + if ($data_macro) { + $salida = $data_macro; + } else { + $salida .= ' '.''.io_safe_output($row['unit']).''; + if (strlen($salida) > $config['agent_size_text_small']) { + $salida = ui_print_truncate_text($salida, 'agent_small', true, true, false, '[…]', 'font-size:7.5pt;'); + // Clean tag . + $text_aux = explode(' $row['id_agente_modulo'], + 'interval' => $row['current_interval'], + 'module_name' => $row['module_name'], + 'id_node' => $row['server_id'], + ] + ); + $salida = ui_get_snapshot_image($link, $is_snapshot).'  '; + } else { + $sub_string = substr(io_safe_output($row['datos']), 0, 12); + if ($module_value == $sub_string) { + if ($module_value == 0 && !$sub_string) { + $salida = 0; + } else { $data_macro = modules_get_unit_macro($row['datos'], $row['unit']); if ($data_macro) { $salida = $data_macro; } else { - $salida .= ' '.''.io_safe_output($row['unit']).''; - if (strlen($salida) > $config['agent_size_text_small']) { - $salida = ui_print_truncate_text($salida, 'agent_small', true, true, false, '[…]', 'font-size:7.5pt;'); - // Clean tag . - $text_aux = explode(' $row['id_agente_modulo'], - 'interval' => $row['current_interval'], - 'module_name' => $row['module_name'], - 'id_node' => $row['server_id'], - ] - ); - $salida = ui_get_snapshot_image($link, $is_snapshot).'  '; - } else { - $sub_string = substr(io_safe_output($row['datos']), 0, 12); - if ($module_value == $sub_string) { - if ($module_value == 0 && !$sub_string) { - $salida = 0; - } else { - $data_macro = modules_get_unit_macro($row['datos'], $row['unit']); - if ($data_macro) { - $salida = $data_macro; - } else { - $salida = $row['datos']; - } - } + // Fixed the data from Selenium Plugin. + if ($module_value != strip_tags($module_value)) { + $module_value = io_safe_input($module_value); + $sub_string = substr($row['datos'], 0, 12); } else { - // Fixed the goliat sends the strings from web. - // Without HTML entities. - if ($is_web_content_string) { - $sub_string = substr($row['datos'], 0, 12); - } else { - // Fixed the data from Selenium Plugin. - if ($module_value != strip_tags($module_value)) { - $module_value = io_safe_input($module_value); - $sub_string = substr($row['datos'], 0, 12); - } else { - $sub_string = substr(io_safe_output($row['datos']), 0, 12); - } - } - - if ($module_value == $sub_string) { - $salida = $module_value; - } else { - $salida = ''.'".''.$sub_string.' '."".html_print_image('images/rosette.png', true).''; - } + $sub_string = substr(io_safe_output($row['datos']), 0, 12); } } + + if ($module_value == $sub_string) { + $salida = $module_value; + } else { + $salida = ''.'".''.$sub_string.' '."".html_print_image('images/rosette.png', true).''; + } } } - - if (in_array('data', $show_fields) || is_metaconsole()) { - $data[10] = $salida; - } - - if (in_array('timestamp', $show_fields) || is_metaconsole()) { - if ($row['module_interval'] > 0) { - $interval = $row['module_interval']; - } else { - $interval = $row['agent_interval']; - } - - if ($row['estado'] == 3) { - $option = [ - 'html_attr' => 'class="redb"', - 'style' => 'font-size:7pt;', - ]; - } else { - $option = ['style' => 'font-size:7pt;']; - } - - $data[11] = ui_print_timestamp($row['utimestamp'], true, $option); - } - - array_push($table->data, $data); - } - - html_print_table($table); - - - if ($count_modules > $config['block_size']) { - ui_pagination($count_modules, false, $offset, 0, false, 'offset', true, 'pagination-bottom'); - } - } else { - if ($first_interaction) { - ui_print_info_message(['no_close' => true, 'message' => __('This group doesn\'t have any monitor')]); - } else { - ui_print_info_message(['no_close' => true, 'message' => __('Sorry no search parameters')]); } } + if (in_array('data', $show_fields) || is_metaconsole()) { + $data[10] = $salida; + } + + if (in_array('timestamp', $show_fields) || is_metaconsole()) { + if ($row['module_interval'] > 0) { + $interval = $row['module_interval']; + } else { + $interval = $row['agent_interval']; + } + + if ($row['estado'] == 3) { + $option = [ + 'html_attr' => 'class="redb"', + 'style' => 'font-size:7pt;', + ]; + } else { + $option = ['style' => 'font-size:7pt;']; + } + + $data[11] = ui_print_timestamp($row['utimestamp'], true, $option); + } + + array_push($table->data, $data); + } + + html_print_table($table); + + + if ($count_modules > $config['block_size']) { + ui_pagination($count_modules, false, $offset, 0, false, 'offset', true, 'pagination-bottom'); + } +} else { + if ($first_interaction) { + ui_print_info_message(['no_close' => true, 'message' => __('This group doesn\'t have any monitor')]); + } else { + ui_print_info_message(['no_close' => true, 'message' => __('Sorry no search parameters')]); + } +} + // End Build List Result. echo "
"; @@ -1992,7 +1991,7 @@ $table->data[4][0] .= __('Not condition').' '.ui_print_help_tip(__('If you ui_require_javascript_file('pandora_modules'); - ?> +?>