report SLA services to metaconsole pandora_enterprise#7063

This commit is contained in:
Daniel Barbero Martin 2022-02-04 13:44:20 +01:00
parent 887162322c
commit d47190c234
2 changed files with 109 additions and 20 deletions

View File

@ -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 '<td class="sla_list_service_col">';
echo printSmallFont($nameService);
if ($meta && $server_name != '') {
echo $server_name.' &raquo; '.$nameService;
} else {
echo $nameService;
}
echo '</th>';
}
@ -3984,8 +3991,8 @@ function print_SLA_list($width, $action, $idItem=null)
<?php
}
if (enterprise_installed()
&& $report_item_type == 'SLA_services'
if (enterprise_installed() === true
&& $report_item_type === 'SLA_services'
) {
enterprise_include_once(
'include/functions_services.php'
@ -4004,23 +4011,99 @@ function print_SLA_list($width, $action, $idItem=null)
],
]
);
if (!empty($services_tmp)
&& $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
&& $check_module_sla_value
if (empty($services_tmp) === false
&& $services_tmp !== ENTERPRISE_NOT_HOOK
) {
$services[$service['id']] = $service['name'];
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
) {
$services[$service['id']] = $service['name'];
}
}
}
if (is_metaconsole() === true) {
$sc = new Synchronizer();
$node_services = $sc->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().' &raquo; '.$item['name']
),
];
return $carry;
},
[]
);
}
return [];
},
false
);
foreach ($node_services as $ns) {
foreach ($ns as $k => $ser) {
$services[$ser['id']] = $ser['name'];
}
}
}
}
}
echo '<td class="sla_list_service_col">';
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))

View File

@ -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.'),