Removed some linter errors

Former-commit-id: 7dfda1ad66f676059145e7ab34485798dc9c5264
This commit is contained in:
Alejandro Gallardo Escobar 2019-04-23 15:09:57 +02:00
parent 26b3fd23f5
commit daa627441a
1 changed files with 77 additions and 45 deletions

View File

@ -3961,38 +3961,54 @@ function visual_map_translate_module_status($module_status)
* layouts), and makes an AND operation to be sure that all the items * layouts), and makes an AND operation to be sure that all the items
* are OK. If any of them is down, then result is down (0) * are OK. If any of them is down, then result is down (0)
* *
* @param int Id of the layout * @param integer $layout_id Id of the layout.
* @param array Information about the status calculation of the item * @param array $status_data Information about the status calculation of the
* @param int Depth (for recursion control) * item.
* @param integer $depth Depth (for recursion control).
* *
* @return boolean The status of the given layout. True if it's OK, false if not. * @return integer The status of the given layout.
*/ */
function visual_map_get_layout_status($layout_id, $status_data=[], $depth=0) function visual_map_get_layout_status($layout_id, $status_data=[], $depth=0)
{ {
global $config; global $config;
// TODO: Implement this limit into the setup // TODO: Implement this limit into the setup.
if ($depth > 10) { if ($depth > 10) {
return VISUAL_MAP_STATUS_UNKNOWN; return VISUAL_MAP_STATUS_UNKNOWN;
} }
$layout_items = db_get_all_rows_filter('tlayout_data', ['id_layout' => $layout_id]); $layout_items = db_get_all_rows_filter(
'tlayout_data',
['id_layout' => $layout_id]
);
if ($layout_items === false) { if ($layout_items === false) {
return VISUAL_MAP_STATUS_UNKNOWN; return VISUAL_MAP_STATUS_UNKNOWN;
} }
// Check for valid items to retrieve the status for // Check for valid items to retrieve the status for.
$valid_layout_items = []; $valid_layout_items = [];
foreach ($layout_items as $layout_item_data) { foreach ($layout_items as $layout_item_data) {
if (($layout_item_data['type'] == GROUP_ITEM if (($layout_item_data['type'] == GROUP_ITEM
&& !empty($layout_item_data['id_group']) && !empty($layout_item_data['id_group'])
&& check_acl($config['id_user'], $layout_item_data['id_group'], 'VR') && check_acl(
&& check_acl($config['id_user'], $layout_item_data['element_group'], 'VR')) $config['id_user'],
$layout_item_data['id_group'],
'VR'
)
&& check_acl(
$config['id_user'],
$layout_item_data['element_group'],
'VR'
))
|| ((!empty($layout_item_data['id_layout_linked']) || ((!empty($layout_item_data['id_layout_linked'])
|| !empty($layout_item_data['id_agente_modulo']) || !empty($layout_item_data['id_agente_modulo'])
|| !empty($layout_item_data['id_agent'])) || !empty($layout_item_data['id_agent']))
&& check_acl($config['id_user'], $layout_item_data['element_group'], 'VR')) && check_acl(
$config['id_user'],
$layout_item_data['element_group'],
'VR'
))
) { ) {
$valid_layout_items[] = $layout_item_data; $valid_layout_items[] = $layout_item_data;
} }
@ -4002,7 +4018,7 @@ function visual_map_get_layout_status($layout_id, $status_data=[], $depth=0)
return VISUAL_MAP_STATUS_UNKNOWN; return VISUAL_MAP_STATUS_UNKNOWN;
} }
// Sort by node id to reduce the number of connections // Sort by node id to reduce the number of connections.
if (is_metaconsole()) { if (is_metaconsole()) {
sort_by_column($valid_layout_items, 'id_metaconsole'); sort_by_column($valid_layout_items, 'id_metaconsole');
} }
@ -4021,14 +4037,14 @@ function visual_map_get_layout_status($layout_id, $status_data=[], $depth=0)
if (empty($node_id) && $meta_connected_to) { if (empty($node_id) && $meta_connected_to) {
metaconsole_restore_db(); metaconsole_restore_db();
// Restore db connection // Restore db connection.
$meta_connected_to = null; $meta_connected_to = null;
} else if (!empty($node_id) && ( empty($meta_connected_to) } else if (!empty($node_id)
|| $meta_connected_to != $node_id) && (empty($meta_connected_to) || $meta_connected_to != $node_id)
) { ) {
if (!empty($meta_connected_to)) { if (!empty($meta_connected_to)) {
metaconsole_restore_db(); metaconsole_restore_db();
// Restore db connection // Restore db connection.
} }
$connection = metaconsole_get_connection_by_id($node_id); $connection = metaconsole_get_connection_by_id($node_id);
@ -4042,64 +4058,80 @@ function visual_map_get_layout_status($layout_id, $status_data=[], $depth=0)
$status = VISUAL_MAP_STATUS_NORMAL; $status = VISUAL_MAP_STATUS_NORMAL;
$ent_element_status = enterprise_hook('enterprise_visual_map_get_status_element', [$layoutData]); $ent_element_status = enterprise_hook(
'enterprise_visual_map_get_status_element',
[$layoutData]
);
if ($ent_element_status === ENTERPRISE_NOT_HOOK) { if ($ent_element_status === ENTERPRISE_NOT_HOOK) {
$ent_element_status = false; $ent_element_status = false;
} }
// Enterprise element
if ($ent_element_status !== false) { if ($ent_element_status !== false) {
// Enterprise element.
$status = $ent_element_status; $status = $ent_element_status;
} } else {
// Other // Other.
else {
switch ($layout_item_data['type']) { switch ($layout_item_data['type']) {
case STATIC_GRAPH: case STATIC_GRAPH:
case PERCENTILE_BAR: case PERCENTILE_BAR:
case PERCENTILE_BUBBLE: case PERCENTILE_BUBBLE:
case CIRCULAR_PROGRESS_BAR: case CIRCULAR_PROGRESS_BAR:
case CIRCULAR_INTERIOR_PROGRESS_BAR: case CIRCULAR_INTERIOR_PROGRESS_BAR:
// Linked layout
if (!empty($layout_item_data['id_layout_linked'])) { if (!empty($layout_item_data['id_layout_linked'])) {
$status = visual_map_get_layout_status($layout_item_data['id_layout_linked'], $layout_item_data, ($depth + 1)); // Linked layout.
} $status = visual_map_get_layout_status(
// Module $layout_item_data['id_layout_linked'],
else if (!empty($layout_item_data['id_agente_modulo'])) { $layout_item_data,
$module_status = modules_get_agentmodule_status($layout_item_data['id_agente_modulo']); ($depth + 1)
$status = visual_map_translate_module_status($module_status); );
} } else if (!empty($layout_item_data['id_agente_modulo'])) {
// Agent // Module.
else if (!empty($layout_item_data['id_agent'])) { $module_status = modules_get_agentmodule_status(
$agent_status = agents_get_status($layout_item_data['id_agent'], true); $layout_item_data['id_agente_modulo']
$status = visual_map_translate_agent_status($agent_status); );
} $status = visual_map_translate_module_status(
// Unknown $module_status
else { );
} else if (!empty($layout_item_data['id_agent'])) {
// Agent.
$agent_status = agents_get_status(
$layout_item_data['id_agent'],
true
);
$status = visual_map_translate_agent_status(
$agent_status
);
} else {
// Unknown.
$status = VISUAL_MAP_STATUS_UNKNOWN; $status = VISUAL_MAP_STATUS_UNKNOWN;
} }
break; break;
case GROUP_ITEM: case GROUP_ITEM:
$group_status = groups_get_status($layout_item_data['id_group']); $group_status = groups_get_status(
$layout_item_data['id_group']
);
$status = visual_map_translate_agent_status($group_status); $status = visual_map_translate_agent_status($group_status);
break; break;
default: default:
// If it's a graph, a progress bar or a data tag, ALWAYS report status OK // If it's a graph, a progress bar or a data tag,
// (=0) to avoid confussions here. // ALWAYS report status OK (=0) to avoid confussions here.
$status = VISUAL_MAP_STATUS_NORMAL; $status = VISUAL_MAP_STATUS_NORMAL;
break; break;
} }
} }
// When the status calculation type is 'default', only one critical element is required to // When the status calculation type is 'default', only one critical
// set the layout status as critical, so we can return the critical status right now. // element is required to set the layout status as critical, so we can
if ($status_data['linked_layout_status_type'] === 'default' && ( $status == VISUAL_MAP_STATUS_CRITICAL_BAD // return the critical status right now.
if ($status_data['linked_layout_status_type'] === 'default'
&& ($status == VISUAL_MAP_STATUS_CRITICAL_BAD
|| $status == VISUAL_MAP_STATUS_CRITICAL_ALERT) || $status == VISUAL_MAP_STATUS_CRITICAL_ALERT)
) { ) {
if (is_metaconsole() && $meta_connected_to) { if (is_metaconsole() && $meta_connected_to) {
// Restore db connection.
metaconsole_restore_db(); metaconsole_restore_db();
// Restore db connection
} }
return $status; return $status;
@ -4113,11 +4145,11 @@ function visual_map_get_layout_status($layout_id, $status_data=[], $depth=0)
} }
if (is_metaconsole() && $meta_connected_to) { if (is_metaconsole() && $meta_connected_to) {
// Restore db connection.
metaconsole_restore_db(); metaconsole_restore_db();
// Restore db connection
} }
// Status calculation // Status calculation.
switch ($status_data['linked_layout_status_type']) { switch ($status_data['linked_layout_status_type']) {
default: default:
case 'default': case 'default':
@ -4149,7 +4181,7 @@ function visual_map_get_layout_status($layout_id, $status_data=[], $depth=0)
if ($num_items_critical > 0 if ($num_items_critical > 0
&& ((($num_items_critical_alert + $num_items_critical) * 100) / $num_items) >= $weight && ((($num_items_critical_alert + $num_items_critical) * 100) / $num_items) >= $weight
) { ) {
return $num_items_critical_alert > 0 ? VISUAL_MAP_STATUS_CRITICAL_ALERT : VISUAL_MAP_STATUS_CRITICAL_BAD; return ($num_items_critical_alert > 0) ? VISUAL_MAP_STATUS_CRITICAL_ALERT : VISUAL_MAP_STATUS_CRITICAL_BAD;
} else if ($num_items_warning > 0 } else if ($num_items_warning > 0
&& (($num_items_warning * 100) / $num_items) >= $weight && (($num_items_warning * 100) / $num_items) >= $weight
) { ) {