Merge branch 'ent-2588-service-like-visual-console-status' into 'develop'

Now is possible to link visual consoles from different nodes to the visual console elements

See merge request artica/pandorafms!1741
This commit is contained in:
vgilc 2018-09-10 12:43:06 +02:00
commit 683d748b38
6 changed files with 140 additions and 42 deletions

View File

@ -12,8 +12,10 @@ ALTER TABLE tagente_modulo ALTER COLUMN `parent_module_id` SET default 0;
ALTER TABLE `tlayout_data` ADD COLUMN `linked_layout_status_type` ENUM ('default', 'weight', 'service') DEFAULT 'default';
ALTER TABLE `tlayout_data` ADD COLUMN `linked_layout_status_as_service_warning` FLOAT(20, 3) NOT NULL default 0;
ALTER TABLE `tlayout_data` ADD COLUMN `linked_layout_status_as_service_critical` FLOAT(20, 3) NOT NULL default 0;
ALTER TABLE `tlayout_data` ADD COLUMN `linked_layout_node_id` INT(10) NOT NULL default 0;
ALTER TABLE `tlayout_template_data` ADD COLUMN `linked_layout_status_type` ENUM ('default', 'weight', 'service') DEFAULT 'default';
ALTER TABLE `tlayout_template_data` ADD COLUMN `linked_layout_status_as_service_warning` FLOAT(20, 3) NOT NULL default 0;
ALTER TABLE `tlayout_template_data` ADD COLUMN `linked_layout_status_as_service_critical` FLOAT(20, 3) NOT NULL default 0;
ALTER TABLE `tlayout_template_data` ADD COLUMN `linked_layout_node_id` INT(10) NOT NULL default 0;
COMMIT;

View File

@ -829,6 +829,7 @@ function readFields() {
values['bars_graph_type'] = $("select[name=bars_graph_type]").val();
values['parent'] = $("select[name=parent]").val();
values['map_linked'] = $("select[name=map_linked]").val();
values['linked_map_node_id'] = $("input[name=linked_map_node_id]").val();
values['linked_map_status_calculation_type'] = $("select[name=linked_map_status_calculation_type]").val();
values['map_linked_weight'] = $("input[name=map_linked_weight]").val();
values['linked_map_status_service_critical'] = $("input[name=linked_map_status_service_critical]").val();
@ -1544,6 +1545,8 @@ function loadFieldsFromDB(item) {
$("select[name=linked_map_status_calculation_type]").val(val).change();
if (key == 'id_layout_linked')
$("select[name=map_linked]").val(val).change();
if (key == 'linked_layout_node_id')
$("input[name=linked_map_node_id]").val(val);
if (key == 'id_layout_linked_weight')
$("input[name=map_linked_weight]").val(val);
if (key == 'linked_layout_status_as_service_critical')
@ -1958,6 +1961,7 @@ function cleanFields(item) {
$("select[name=parent]").val('');
$("select[name=linked_map_status_calculation_type]").val('default').change();
$("select[name=map_linked]").val('').change();
$("input[name=linked_map_node_id]").val(0);
$("input[name=map_linked_weight]").val('');
$("input[name=linked_map_status_service_critical]").val('');
$("input[name=linked_map_status_service_warning]").val('');

View File

@ -100,6 +100,7 @@ $width = get_parameter('width', null);
$height = get_parameter('height', null);
$parent = get_parameter('parent', null);
$map_linked = get_parameter('map_linked', null);
$linked_map_node_id = get_parameter('linked_map_node_id', null);
$linked_map_status_calculation_type = get_parameter('linked_map_status_calculation_type', 'default');
$map_linked_weight = get_parameter('map_linked_weight', null);
@ -613,6 +614,10 @@ switch ($action) {
if ($id_agent !== null) {
$values['id_agent'] = $id_agent;
}
if ($linked_map_node_id) {
$values['linked_layout_node_id'] = $linked_map_node_id;
}
}
else if ($id_agent == 0) {
$values['id_agent'] = 0;
@ -1135,6 +1140,11 @@ switch ($action) {
}
$values['id_agente_modulo'] = $id_module;
$values['id_layout_linked'] = $map_linked;
if (defined('METACONSOLE') && $metaconsole) {
$values['linked_layout_node_id'] = (int) $linked_map_node_id;
}
$values['linked_layout_status_type'] = $linked_map_status_calculation_type;
if ($map_linked_weight !== null) {
@ -1419,7 +1429,6 @@ if ($get_element_status) {
array('id' => $id_element));
$res = visual_map_get_status_element($layoutData);
html_debug($res, true);
echo $res;
return;

View File

@ -803,6 +803,18 @@ function visual_map_print_item($mode = "read", $layoutData,
}
break;
}
// Override url
if (
is_metaconsole() &&
!empty($layoutData["id_layout_linked"]) &&
!empty($layoutData["linked_layout_node_id"])
) {
$url = ui_meta_get_url_console_child(
$layoutData['linked_layout_node_id'],
"network", "operation/visual_console/render_view&id=" . (int) $layoutData["id_layout_linked"]
);
}
}
// + 1 for to avoid the box and lines items are on the top of
@ -3137,38 +3149,22 @@ function visual_map_get_status_element($layoutData) {
WHERE id_agente_modulo = ' . $layoutData['id_agente_modulo']);
//Linked to other layout ?? - Only if not module defined
if ($layoutData['id_layout_linked'] != 0) {
if ($layoutData['id_layout_linked_weight'] != 0) {
$calculate_weight = true;
}
else {
$calculate_weight = false;
if (!empty($layoutData['id_layout_linked'])) {
if (!empty($layoutData['linked_layout_node_id'])) {
//Metaconsole db connection
$connection = db_get_row_filter ('tmetaconsole_setup',
array('id' => $layoutData['linked_layout_node_id']));
if (metaconsole_load_external_db($connection) != NOERR) return VISUAL_MAP_STATUS_UNKNOWN;
}
$status = visual_map_get_layout_status($layoutData['id_layout_linked'], $layoutData);
if ($layoutData['id_layout_linked_weight'] > 0) {
$elements_to_compare = db_get_all_rows_sql("SELECT id, element_group FROM tlayout_data WHERE type = 0 AND id_layout = " . $layoutData['id_layout_linked']);
$childs_group_acl = array();
foreach ($elements_to_compare as $c) {
if (check_acl ($config['id_user'], $c['element_group'], "VR")) {
$childs_group_acl[] = $c['id'];
}
}
$elements_to_compare = $childs_group_acl;
$aux_weight = ($status['elements_in_critical'] / count($elements_to_compare)) * 100;
if ($aux_weight >= $layoutData['id_layout_linked_weight']) {
$status = $status['temp_total'];
}
else {
$status = VISUAL_MAP_STATUS_NORMAL;
if (count($elements_to_compare) == 0) {
$status = VISUAL_MAP_STATUS_UNKNOWN;
}
}
if (!empty($layoutData['linked_layout_node_id'])) {
//Restore db connection
metaconsole_restore_db();
}
return $status;
}
else {
switch ($layoutData["type"]) {
@ -3676,7 +3672,7 @@ function visual_map_translate_agent_status ($agent_status) {
}
function visual_map_translate_module_status ($module_status) {
switch ($agent_status) {
switch ($module_status) {
case AGENT_MODULE_STATUS_NORMAL:
case AGENT_MODULE_STATUS_NORMAL_ALERT:
default:
@ -3717,6 +3713,7 @@ function visual_map_get_layout_status ($layout_id, $status_data = array(), $dept
if ($depth > 10) return VISUAL_MAP_STATUS_UNKNOWN;
$layout_items = db_get_all_rows_filter("tlayout_data", array("id_layout" => $layout_id));
if ($layout_items === false) return VISUAL_MAP_STATUS_UNKNOWN;
// Check for valid items to retrieve the status for
@ -3769,21 +3766,30 @@ function visual_map_get_layout_status ($layout_id, $status_data = array(), $dept
$meta_connected_to = null;
foreach ($valid_layout_items as $layout_item_data) {
$node_id = null;
if (is_metaconsole()) {
if (empty($layout_item_data["id_metaconsole"]) && $meta_connected_to) {
$node_id = (
!empty($layout_item_data["id_layout_linked"]) &&
!empty($layout_item_data["linked_layout_node_id"])
)
? $layout_item_data["linked_layout_node_id"]
: $layout_item_data["id_metaconsole"];
if (empty($node_id) && $meta_connected_to) {
metaconsole_restore_db(); // Restore db connection
$meta_connected_to = null;
}
else if (
!empty($layout_item_data["id_metaconsole"]) && (
!empty($node_id) && (
empty($meta_connected_to) ||
$meta_connected_to != $layout_item_data["id_metaconsole"]
$meta_connected_to != $node_id
)
) {
if (!empty($meta_connected_to)) metaconsole_restore_db(); // Restore db connection
$connection = metaconsole_get_connection_by_id($layout_item_data["id_metaconsole"]);
$connection = metaconsole_get_connection_by_id($node_id);
if (metaconsole_load_external_db($connection) != NOERR) continue;
$meta_connected_to = $layout_item_data["id_metaconsole"];
$meta_connected_to = $node_id;
}
}

View File

@ -697,13 +697,88 @@ function visual_map_editor_print_item_palette($visualConsole_id, $background) {
'group_item', 'static_graph', 'percentile_bar',
'percentile_item', 'module_graph', 'simple_value',
'icon', 'label', 'datos', 'donut_graph');
$form_items_advance['map_linked_row']['html'] = '<td align="left">'.
__('Linked map') . '</td>' .
'<td align="left">' . html_print_select_from_sql (
'SELECT id, name
FROM tlayout
WHERE id != ' . (int) $visualConsole_id, 'map_linked', 0, 'onLinkedMapChange(event)', __('None'), 0, true) .
'</td>';
$visual_maps = db_get_all_rows_filter("tlayout", "id != " . (int) $visualConsole_id, array("id", "name"));
$form_items_advance['map_linked_row']['html'] = '<td align="left">'
. __('Linked map')
. '</td>'
. '<td align="left">';
if (is_metaconsole()) {
$meta_servers = metaconsole_get_servers();
foreach ($meta_servers as $server) {
if (metaconsole_load_external_db($server) !== NOERR) {
metaconsole_restore_db();
continue;
}
$node_visual_maps = db_get_all_rows_filter("tlayout", array(), array("id", "name"));
foreach ($node_visual_maps as $node_visual_map) {
$node_visual_map["node_id"] = (int) $server["id"];
$visual_maps[] = $node_visual_map;
}
metaconsole_restore_db();
}
$meta_servers_by_id = array_reduce($meta_servers, function ($arr, $item) {
$arr[$item["id"]] = $item;
return $arr;
}, array());
$form_items_advance['map_linked_row']['html'] .= html_print_select_from_sql(
array(), 'map_linked', 0, 'onLinkedMapChange(event)', __('None'), 0, true
);
$form_items_advance['map_linked_row']['html'] .= html_print_input_hidden(
"linked_map_node_id", 0, true
);
ob_start();
?>
<script type="text/javascript">
(function () {
var $mapLinkedSelect = $("select#map_linked");
var $linkedMapNodeIDInput = $("input#hidden-linked_map_node_id");
var visualMaps = <?php echo json_encode($visual_maps); ?>;
var nodesById = <?php echo json_encode($meta_servers_by_id); ?>;
visualMaps.forEach(function (vMap) {
$mapLinkedSelect.append(
'<option data-node-id="' + (vMap["node_id"] || 0) + '" value="' + vMap["id"] + '">'
+ vMap["name"]
+ (
nodesById[vMap["node_id"]]
? ' (' + nodesById[vMap["node_id"]]["server_name"] + ')'
: ''
)
+ '</option>'
);
});
$mapLinkedSelect.change(function (event) {
var mapLinkedID = Number.parseInt(event.target.value);
var itemSelected = $(event.target).children("option:selected");
if (itemSelected.length === 0) {
$linkedMapNodeIDInput.val(0);
} else {
var nodeId = itemSelected.data("node-id");
$linkedMapNodeIDInput.val(nodeId != null ? nodeId : 0);
}
});
})();
</script>
<?php
$form_items_advance['map_linked_row']['html'] .= ob_get_clean();
}
else {
$form_items_advance['map_linked_row']['html'] .= html_print_select_from_sql(
$visual_maps, 'map_linked', 0, 'onLinkedMapChange(event)', __('None'), 0, true
);
}
$form_items_advance['map_linked_row']['html'] .= '</td>';
$status_type_select_items = array(
"weight" => __("By status weight"),

View File

@ -1381,6 +1381,7 @@ CREATE TABLE IF NOT EXISTS `tlayout_data` (
`border_color` varchar(200) DEFAULT "",
`fill_color` varchar(200) DEFAULT "",
`show_statistics` tinyint(2) NOT NULL default '0',
`linked_layout_node_id` INT(10) NOT NULL default 0,
`linked_layout_status_type` ENUM ('default', 'weight', 'service') DEFAULT 'default',
`id_layout_linked_weight` int(10) NOT NULL default '0',
`linked_layout_status_as_service_warning` FLOAT(20, 3) NOT NULL default 0,
@ -3315,6 +3316,7 @@ CREATE TABLE IF NOT EXISTS `tlayout_template_data` (
`border_color` varchar(200) DEFAULT "",
`fill_color` varchar(200) DEFAULT "",
`show_statistics` tinyint(2) NOT NULL default '0',
`linked_layout_node_id` INT(10) NOT NULL default 0,
`linked_layout_status_type` ENUM ('default', 'weight', 'service') DEFAULT 'default',
`id_layout_linked_weight` int(10) NOT NULL default '0',
`linked_layout_status_as_service_warning` FLOAT(20, 3) NOT NULL default 0,