Merge branch 'ent-6296-10650-Añadir-widget-de-lista-de-servicios' into 'develop'

Ent 6296 10650 añadir widget de lista de servicios

See merge request artica/pandorafms!4355
This commit is contained in:
Daniel Rodriguez 2021-09-24 09:09:28 +00:00
commit 49961ed261
7 changed files with 640 additions and 8 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@ -222,20 +222,20 @@ class TreeService extends Tree
switch ($status) {
case SERVICE_STATUS_NORMAL:
$processed_items[$row['id']]['statusImageHTML'] = '<img src="'.'images/status_sets/default/agent_ok_ball.png'.'" data-title="NORMAL status." data-use_title_for_force_title="1" class="forced_title" alt="NORMAL status." />';
$processed_items[$row['id']]['statusImageHTML'] = '<img src="'.ui_get_full_url('images/status_sets/default/agent_ok_ball.png').'" data-title="NORMAL status." data-use_title_for_force_title="1" class="forced_title" alt="NORMAL status." />';
break;
case SERVICE_STATUS_CRITICAL:
$processed_items[$row['id']]['statusImageHTML'] = '<img src="'.'images/status_sets/default/agent_critical_ball.png'.'" data-title="CRITICAL status." data-use_title_for_force_title="1" class="forced_title" alt="CRITICAL status." />';
$processed_items[$row['id']]['statusImageHTML'] = '<img src="'.ui_get_full_url('images/status_sets/default/agent_critical_ball.png').'" data-title="CRITICAL status." data-use_title_for_force_title="1" class="forced_title" alt="CRITICAL status." />';
break;
case SERVICE_STATUS_WARNING:
$processed_items[$row['id']]['statusImageHTML'] = '<img src="'.'images/status_sets/default/agent_warning_ball.png'.'" data-title="WARNING status." data-use_title_for_force_title="1" class="forced_title" alt="WARNING status." />';
$processed_items[$row['id']]['statusImageHTML'] = '<img src="'.ui_get_full_url('images/status_sets/default/agent_warning_ball.png').'" data-title="WARNING status." data-use_title_for_force_title="1" class="forced_title" alt="WARNING status." />';
break;
case SERVICE_STATUS_UNKNOWN:
default:
$processed_items[$row['id']]['statusImageHTML'] = '<img src="'.'images/status_sets/default/agent_no_data_ball.png'.'" data-title="UNKNOWN status." data-use_title_for_force_title="1" class="forced_title" alt="UNKNOWN status." />';
$processed_items[$row['id']]['statusImageHTML'] = '<img src="'.ui_get_full_url('images/status_sets/default/agent_no_data_ball.png').'" data-title="UNKNOWN status." data-use_title_for_force_title="1" class="forced_title" alt="UNKNOWN status." />';
break;
}
}
@ -406,21 +406,21 @@ class TreeService extends Tree
switch ($item->agent()->lastStatus()) {
case AGENT_STATUS_NORMAL:
$tmp['statusImageHTML'] = '<img src="'.'images/status_sets/default/agent_ok_ball.png'.'" data-title="NORMAL status." data-use_title_for_force_title="1" class="forced_title" alt="NORMAL status." />';
$tmp['statusImageHTML'] = '<img src="'.ui_get_full_url('images/status_sets/default/agent_ok_ball.png').'" data-title="NORMAL status." data-use_title_for_force_title="1" class="forced_title" alt="NORMAL status." />';
break;
case AGENT_STATUS_CRITICAL:
case AGENT_STATUS_ALERT_FIRED:
$tmp['statusImageHTML'] = '<img src="'.'images/status_sets/default/agent_critical_ball.png'.'" data-title="CRITICAL status." data-use_title_for_force_title="1" class="forced_title" alt="CRITICAL status." />';
$tmp['statusImageHTML'] = '<img src="'.ui_get_full_url('images/status_sets/default/agent_critical_ball.png').'" data-title="CRITICAL status." data-use_title_for_force_title="1" class="forced_title" alt="CRITICAL status." />';
break;
case AGENT_STATUS_WARNING:
$tmp['statusImageHTML'] = '<img src="'.'images/status_sets/default/agent_warning_ball.png'.'" data-title="WARNING status." data-use_title_for_force_title="1" class="forced_title" alt="WARNING status." />';
$tmp['statusImageHTML'] = '<img src="'.ui_get_full_url('images/status_sets/default/agent_warning_ball.png').'" data-title="WARNING status." data-use_title_for_force_title="1" class="forced_title" alt="WARNING status." />';
break;
case AGENT_STATUS_UNKNOWN:
default:
$tmp['statusImageHTML'] = '<img src="'.'images/status_sets/default/agent_no_data_ball.png'.'" data-title="UNKNOWN status." data-use_title_for_force_title="1" class="forced_title" alt="UNKNOWN status." />';
$tmp['statusImageHTML'] = '<img src="'.ui_get_full_url('images/status_sets/default/agent_no_data_ball.png').'" data-title="UNKNOWN status." data-use_title_for_force_title="1" class="forced_title" alt="UNKNOWN status." />';
break;
}

View File

@ -948,6 +948,133 @@ function processTreeSearch(settings) {
});
}
function processServiceTree(settings) {
var treeController = TreeController.getController();
if (
typeof treeController.recipient != "undefined" &&
treeController.recipient.length > 0
)
treeController.recipient.empty();
$(".loading_tree").show();
var parameters = {};
parameters["page"] = "include/ajax/tree.ajax";
parameters["getChildren"] = 1;
parameters["type"] = "services";
parameters["filter"] = {};
parameters["filter"]["searchGroup"] = "";
parameters["filter"]["searchAgent"] = "";
parameters["filter"]["statusAgent"] = "";
parameters["filter"]["searchModule"] = "";
parameters["filter"]["statusModule"] = "";
parameters["filter"]["groupID"] = "";
parameters["filter"]["tagID"] = "";
parameters["filter"]["searchHirearchy"] = 1;
parameters["filter"]["show_not_init_agents"] = 1;
parameters["filter"]["show_not_init_modules"] = 1;
parameters["filter"]["is_favourite"] = 0;
parameters["filter"]["width"] = 100;
$.ajax({
type: "POST",
url: settings.ajaxURL,
data: parameters,
success: function(data) {
if (data.success) {
$(".loading_tree").hide();
// Get the main values of the tree.
var rawTree = Object.values(data.tree);
// Sorting tree by description (TreeController.js).
rawTree.sort(function(a, b) {
var x = a.description.toLowerCase();
var y = b.description.toLowerCase();
if (x < y) {
return -1;
}
if (x > y) {
return 1;
}
return 0;
});
treeController.init({
recipient: $("div#container_servicemap_" + settings.cellId),
detailRecipient: {
render: function(element, data) {
return {
open: function() {
$("#module_details_window")
.hide()
.empty()
.append(data)
.dialog({
resizable: true,
draggable: true,
modal: true,
title: "Info",
overlay: {
opacity: 0.5,
background: "black"
},
width: 450,
height: 500
});
}
};
}
},
page: parameters["page"],
emptyMessage: "No data found",
foundMessage: "Found groups",
tree: rawTree,
baseURL: settings.baseURL,
ajaxURL: settings.ajaxURL,
filter: parameters["filter"],
counterTitles: {
total: {
agents: "Total agents",
modules: "Total modules",
none: "Total"
},
alerts: {
agents: "Fired alerts",
modules: "Fired alerts",
none: "Fired alerts"
},
critical: {
agents: "Critical agents",
modules: "Critical modules')",
none: "Critical"
},
warning: {
agents: "Warning agents",
modules: "Warning modules",
none: "Warning"
},
unknown: {
agents: "Unknown agents",
modules: "Unknown modules",
none: "Unknown"
},
not_init: {
agents: "Not init agents",
modules: "Not init modules",
none: "Not init"
},
ok: {
agents: " Normal agents ",
modules: " Normal modules ",
none: " Normal "
}
}
});
}
},
dataType: "json"
});
}
function show_module_detail_dialog(
module_id,
id_agent,

View File

@ -352,6 +352,14 @@ class Widget
$className .= '\ServiceMapWidget';
break;
case 'service_view':
if (\enterprise_installed() === false) {
$not_installed = true;
}
$className .= '\ServiceViewWidget';
break;
case 'single_graph':
$className .= '\SingleGraphWidget';
break;

View File

@ -0,0 +1,471 @@
<?php
/**
* Widget Tree view Pandora FMS Console
*
* @category Console Class
* @package Pandora FMS
* @subpackage Widget Tree view
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
* Please see http://pandorafms.org for full contribution list
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation for version 2.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* ============================================================================
*/
namespace PandoraFMS\Dashboard;
use PandoraFMS\Dashboard\Manager;
/**
* Tree view Widgets.
*/
class ServiceViewWidget extends Widget
{
/**
* Name widget.
*
* @var string
*/
protected $name;
/**
* Title widget.
*
* @var string
*/
protected $title;
/**
* Page widget;
*
* @var string
*/
protected $page;
/**
* Class name widget.
*
* @var [type]
*/
protected $className;
/**
* Values options for each widget.
*
* @var [type]
*/
protected $values;
/**
* Configuration required.
*
* @var boolean
*/
protected $configurationRequired;
/**
* Error load widget.
*
* @var boolean
*/
protected $loadError;
/**
* Width.
*
* @var integer
*/
protected $width;
/**
* Heigth.
*
* @var integer
*/
protected $height;
/**
* Grid Width.
*
* @var integer
*/
protected $gridWidth;
/**
* Dashboard ID.
*
* @var integer
*/
protected $dashboardId;
/**
* Cell ID.
*
* @var integer
*/
protected $cellId;
/**
* Construct.
*
* @param integer $cellId Cell ID.
* @param integer $dashboardId Dashboard ID.
* @param integer $widgetId Widget ID.
* @param integer|null $width New width.
* @param integer|null $height New height.
* @param integer|null $gridWidth Grid width.
*/
public function __construct(
int $cellId,
int $dashboardId=0,
int $widgetId=0,
?int $width=0,
?int $height=0,
?int $gridWidth=0
) {
global $config;
ui_require_css_file('tree');
ui_require_css_file('fixed-bottom-box');
// Includes.
enterprise_include_once('/include/functions_services.php');
enterprise_include_once('/include/functions_servicemap.php');
// WARNING: Do not edit. This chunk must be in the constructor.
parent::__construct(
$cellId,
$dashboardId,
$widgetId
);
// Width.
$this->width = $width;
// Height.
$this->height = $height;
// Grid Width.
$this->gridWidth = $gridWidth;
// Cell Id.
$this->cellId = $cellId;
// Widget ID.
$this->widgetId = $widgetId;
// Dashboard ID.
$this->dashboardId = $dashboardId;
// Options.
$this->values = $this->decoders($this->getOptionsWidget());
// Positions.
$this->position = $this->getPositionWidget();
// Page.
$this->page = basename(__FILE__);
// ClassName.
$class = new \ReflectionClass($this);
$this->className = $class->getShortName();
// Title.
$this->title = __('Service View');
// Name.
if (empty($this->name) === true) {
$this->name = 'service_view';
}
// // This forces at least a first configuration.
// $this->configurationRequired = false;
// if (empty($this->values['serviceId']) === true) {
// $this->configurationRequired = true;
// }
$this->overflow_scrollbars = false;
}
/**
* Decoders hack for retrocompability.
*
* @param array $decoder Values.
*
* @return array Returns the values with the correct key.
*/
public function decoders(array $decoder): array
{
$values = [];
// Retrieve global - common inputs.
$values = parent::decoders($decoder);
if (isset($decoder['type']) === true) {
$values['type'] = $decoder['type'];
}
return $values;
}
/**
* Generates inputs for form (specific).
*
* @return array Of inputs.
*
* @throws Exception On error.
*/
public function getFormInputs(): array
{
// Retrieve global - common inputs.
$inputs = parent::getFormInputs();
$values = $this->values;
if (empty($values['type']) === true) {
$values['type'] = 'tree';
}
// Type services view.
$fields = [
'tree' => __('Tree'),
'table' => __('Table'),
];
$inputs[] = [
'label' => __('Type'),
'arguments' => [
'type' => 'select',
'fields' => $fields,
'name' => 'type',
'selected' => $values['type'],
'return' => true,
],
];
return $inputs;
}
/**
* Get Post for widget.
*
* @return array
*/
public function getPost():array
{
// Retrieve global - common inputs.
$values = parent::getPost();
$values['type'] = \get_parameter('type', 'tree');
return $values;
}
/**
* Draw widget.
*
* @return string;
*/
public function load()
{
global $config;
$values = $this->values;
$size = parent::getSize();
$output = '';
if ($values['type'] === 'tree' || empty($values['type'])) {
if (check_acl($config['id_user'], 0, 'AR') === 0) {
$output .= '<div class="container-center">';
$output .= \ui_print_error_message(
__('The user doesn\'t have permission to read agents'),
'',
true
);
$output .= '</div>';
return $output;
}
$containerId = 'container_servicemap_'.$this->cellId;
$output .= "<div id='".$containerId."' class='tree-controller-recipient'>";
$output .= '</div>';
$output .= \html_print_image(
'images/spinner.gif',
true,
[
'class' => 'loading_tree',
'style' => 'display: none;',
]
);
// Css Files.
\ui_require_css_file('tree', 'include/styles/', true);
if ($config['style'] == 'pandora_black') {
\ui_require_css_file('pandora_black', 'include/styles/', true);
}
\ui_require_javascript_file(
'TreeController',
'include/javascript/tree/',
true
);
\ui_require_javascript_file(
'fixed-bottom-box',
'include/javascript/',
true
);
$settings['cellId'] = $this->cellId;
$settings['baseURL'] = \ui_get_full_url('/', false, false, false);
$settings['ajaxURL'] = \ui_get_full_url('ajax.php', false, false, false);
// Show the modal window of an module.
$output .= '<div id="module_details_window" class="">';
$output .= '</div>';
// Script.
$output .= '<script type="text/javascript">';
$output .= 'processServiceTree('.json_encode($settings).');';
$output .= '</script>';
} else {
$own_info = \get_user_info($config['id_user']);
if ($own_info['is_admin'] || check_acl($config['id_user'], 0, 'PM')) {
$display_all_services = true;
} else {
$display_all_services = false;
}
$order = [
'field' => 'name',
'field2' => 'name',
'order' => 'ASC',
];
$filter['order'] = $order;
$services = services_get_services(
$filter,
false,
$display_all_services,
'AR'
);
$output .= '<div class="white_box mgn_btt_20px mrgn_top_20px pddng_50px services_table" >';
$output .= '<div id="table_services_dashboard">';
foreach ($services as $service) {
switch ($service['status']) {
case SERVICE_STATUS_NORMAL:
$color = COL_NORMAL;
break;
case SERVICE_STATUS_CRITICAL:
$color = COL_CRITICAL;
break;
case SERVICE_STATUS_WARNING:
$color = COL_WARNING;
break;
case SERVICE_STATUS_UNKNOWN:
default:
$color = COL_UNKNOWN;
break;
}
$output .= '<a id="service_'.$service['id'].'" style="background-color: '.$color.'; color: #fff;" class="table_services_item_link_dashboard" href="index.php?'.'sec=network&'.'sec2=enterprise/operation/services/services&tab=service_map&'.'id_service='.$service['id'].'">
<div class="table_services_item">
<div style="width:50px; text-align:center;">';
$output .= \ui_print_group_icon($service['id_group'], true, 'groups_small_white', '', false);
$output .= '</div>
<div class="tooltip" style="color: #fff;position: relative;opacity: 1">'.$service['description'].'
</div>
<div class="tooltip" style="color: #fff;position: relative;opacity: 1">';
$output .= \html_print_image('images/help_w.png', true, ['class' => 'img_help', 'title' => __($service['name']), 'id' => $service['id']]);
$output .= '</div>
</div>
</a>';
}
$output .= '</div>';
$output .= '<table cellspacing="0" cellpadding="0">';
$output .= '<tr>';
$output .= '<td>';
$output .= '<div class="service_status" style=" background: '.COL_UNKNOWN.';"></div>';
$output .= '</td>';
$output .= '<td>';
$output .= '<div class="service_status" style="background: '.COL_NORMAL.';"></div>';
$output .= '</td>';
$output .= '<td>';
$output .= '<div class="service_status" style="background: '.COL_WARNING.';"></div>';
$output .= '</td>';
$output .= '<td>';
$output .= '<div class="service_status" style="background: '.COL_CRITICAL.';"></div>';
$output .= '</td>';
$output .= '</tr><tr>';
$output .= '<td>';
$output .= '<div class="pdd_r_15px"><span class="font_12px">Unknown</span></div>';
$output .= '</td>';
$output .= '<td >';
$output .= '<div class="pdd_r_15px"><span class="font_12px">Normal</span></div>';
$output .= '</div>';
$output .= '<td>';
$output .= '<div class="pdd_r_15px"><span class="font_12px">Warning</span></div>';
$output .= '</td>';
$output .= '<td>';
$output .= '<div><span class="font_12px">Critical</span></div>';
$output .= '</td>';
$output .= '</tr>';
$output .= '</table>';
$output .= '</div>';
}
return $output;
}
/**
* Get description.
*
* @return string.
*/
public static function getDescription()
{
return __('Services view');
}
/**
* Get Name.
*
* @return string.
*/
public static function getName()
{
return 'service_view';
}
}

View File

@ -5814,6 +5814,18 @@ div#status_pie {
margin-bottom: 30px;
}
#table_services_dashboard {
display: grid;
grid-gap: 20px;
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
grid-template-rows: 1fr;
margin-bottom: 30px;
}
.services_table {
width: 97%;
}
.table_services_item_link {
font-size: 16px;
display: grid;
@ -5822,6 +5834,14 @@ div#status_pie {
padding: 10px 10px 10px 0;
}
.table_services_item_link_dashboard {
font-size: 16px;
display: grid;
min-height: 50px;
box-sizing: border-box;
padding: 10px 10px 10px 0;
}
.table_services_item {
display: grid;
align-items: center;

View File

@ -176,6 +176,12 @@ div#tree-controller-recipient {
margin-top: 10px;
}
.tree-controller-recipient {
text-align: left;
width: 98%;
margin-top: 10px;
}
.tree-node > .node-content > div + div:not(.tree-node-counters) {
margin-left: 3px;
}