From d47190c234c4e6abe579c595bb7da05ef2572c8d Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Fri, 4 Feb 2022 13:44:20 +0100 Subject: [PATCH] report SLA services to metaconsole pandora_enterprise#7063 --- .../reporting_builder.item_editor.php | 124 +++++++++++++++--- pandora_console/include/functions_reports.php | 5 +- 2 files changed, 109 insertions(+), 20 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index fb93b3b30d..e098be5001 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -27,6 +27,8 @@ * ============================================================================ */ +use PandoraFMS\Enterprise\Metaconsole\Synchronizer; + global $config; @@ -3837,7 +3839,12 @@ function print_SLA_list($width, $action, $idItem=null) [$item['id_agent_module']] ); echo ''; - echo printSmallFont($nameService); + if ($meta && $server_name != '') { + echo $server_name.' » '.$nameService; + } else { + echo $nameService; + } + echo ''; } @@ -3984,8 +3991,8 @@ function print_SLA_list($width, $action, $idItem=null) apply( + function ($node) { + try { + $node->connect(); + + $services_tmp = enterprise_hook( + 'services_get_services', + [ + false, + [ + 'id', + 'name', + 'description', + 'sla_id_module', + 'sla_value_id_module', + ], + ] + ); + + $all_services = []; + if (empty($services_tmp) === false + && $services_tmp !== ENTERPRISE_NOT_HOOK + ) { + foreach ($services_tmp as $service) { + $check_module_sla = modules_check_agentmodule_exists( + $service['sla_id_module'] + ); + $check_module_sla_value = modules_check_agentmodule_exists( + $service['sla_value_id_module'] + ); + + if ($check_module_sla === true + && $check_module_sla_value === true + ) { + $all_services[$service['id']] = $service; + } + } + } + + $node->disconnect(); + } catch (\Exception $e) { + $all_services = false; + } + + if ($all_services !== false) { + return array_reduce( + $all_services, + function ($carry, $item) use ($node) { + $carry[] = [ + 'id' => $node->id().'|'.$item['id'], + 'name' => io_safe_output( + $node->server_name().' » '.$item['name'] + ), + ]; + return $carry; + }, + [] + ); + } + + return []; + }, + false + ); + + foreach ($node_services as $ns) { + foreach ($ns as $k => $ser) { + $services[$ser['id']] = $ser['name']; + } + } } - } - } echo ''; echo html_print_select( @@ -5330,6 +5413,11 @@ function addSLARow() { var slaMax = $("input[name=sla_max]").val(); var slaLimit = $("input[name=sla_limit]").val(); var serviceId = $("select#id_service>option:selected").val(); + if(serviceId != '' && serviceId.split('|').length > 1 ) { + var ids = serviceId.split('|'); + serverId = ids[0]; + serviceId = ids[1]; + } var serviceName = $("select#id_service>option:selected").text(); if ((((idAgent != '') && (idAgent > 0)) diff --git a/pandora_console/include/functions_reports.php b/pandora_console/include/functions_reports.php index f310856ad2..5e7f53af16 100755 --- a/pandora_console/include/functions_reports.php +++ b/pandora_console/include/functions_reports.php @@ -653,7 +653,8 @@ function reports_get_report_types($template=false, $not_editor=false) 'optgroup' => __('Graphs'), 'name' => __('Custom graph'), ]; - // Only pandora managers have access to the whole database + + // Only pandora managers have access to the whole database. if (check_acl($config['id_user'], 0, 'PM')) { $types['sql_graph_vbar'] = [ 'optgroup' => __('Graphs'), @@ -711,7 +712,7 @@ function reports_get_report_types($template=false, $not_editor=false) 'name' => __('Hourly S.L.A.'), ]; - if (!$config['metaconsole'] && !$template) { + if ($template === false) { $types['SLA_services'] = [ 'optgroup' => __('SLA'), 'name' => __('Services S.L.A.'),