mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 00:04:37 +02:00
[Tags performance] check agents_get_modules in networkmap and removed unused code
This commit is contained in:
parent
198eb1bbc3
commit
1e4c570541
@ -4188,11 +4188,9 @@ function graph_monitor_wheel ($width = 550, $height = 600, $filter = false) {
|
|||||||
}
|
}
|
||||||
$agents = $agents_aux;
|
$agents = $agents_aux;
|
||||||
$agents_aux = null;
|
$agents_aux = null;
|
||||||
$fields = array('id_agente_modulo', 'id_agente', 'id_module_group', 'nombre');
|
|
||||||
|
|
||||||
$module_groups = modules_get_modulegroups();
|
$module_groups = modules_get_modulegroups();
|
||||||
$module_groups[0] = __('Not assigned');
|
$module_groups[0] = __('Not assigned');
|
||||||
// TODO TAGS agents_get_modules
|
|
||||||
$modules = agents_get_modules(array_keys($agents), '*');
|
$modules = agents_get_modules(array_keys($agents), '*');
|
||||||
|
|
||||||
$data_agents = array();
|
$data_agents = array();
|
||||||
|
@ -271,17 +271,8 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
|
|||||||
$filter['disabled'] = 0;
|
$filter['disabled'] = 0;
|
||||||
|
|
||||||
if (!empty($text_filter)) {
|
if (!empty($text_filter)) {
|
||||||
switch ($config['dbtype']) {
|
$filter[] =
|
||||||
case "mysql":
|
'(nombre COLLATE utf8_general_ci LIKE "%' . $text_filter . '%")';
|
||||||
case "postgresql":
|
|
||||||
$filter[] =
|
|
||||||
'(nombre COLLATE utf8_general_ci LIKE "%' . $text_filter . '%")';
|
|
||||||
break;
|
|
||||||
case "oracle":
|
|
||||||
$filter[] =
|
|
||||||
'(upper(nombre) LIKE upper(\'%' . $text_filter . '%\'))';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($group >= 1) {
|
if ($group >= 1) {
|
||||||
@ -305,33 +296,11 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
|
|||||||
//foreach loop are without parent (id_parent = 0)
|
//foreach loop are without parent (id_parent = 0)
|
||||||
|
|
||||||
// Get agents data
|
// Get agents data
|
||||||
if ($strict_user) {
|
$agents = agents_get_agents ($filter,
|
||||||
if ($dont_show_subgroups)
|
array ('id_grupo, nombre, id_os, id_parent, id_agente,
|
||||||
$filter['id_group'] = $group;
|
normal_count, warning_count, critical_count,
|
||||||
else {
|
unknown_count, total_count, notinit_count'), 'AR',
|
||||||
if (!empty($childrens)) {
|
array('field' => 'id_parent', 'order' => 'ASC'));
|
||||||
foreach ($childrens as $children) {
|
|
||||||
$filter_id_groups[$children] = $children;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$filter_id_groups[$group] = $group;
|
|
||||||
$filter['id_group'] = implode(',', $filter_id_groups);
|
|
||||||
}
|
|
||||||
|
|
||||||
$filter['group_by'] = 'tagente.id_agente';
|
|
||||||
$fields = array ('tagente.id_grupo, tagente.nombre, tagente.id_os, tagente.id_parent, tagente.id_agente,
|
|
||||||
tagente.normal_count, tagente.warning_count, tagente.critical_count,
|
|
||||||
tagente.unknown_count, tagente.total_count, tagente.notinit_count');
|
|
||||||
$acltags = tags_get_user_groups_and_tags ($config['id_user'],'AR', $strict_user);
|
|
||||||
$agents = tags_get_all_user_agents (false, $config['id_user'], $acltags, $filter, $fields, false, $strict_user, true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$agents = agents_get_agents ($filter,
|
|
||||||
array ('id_grupo, nombre, id_os, id_parent, id_agente,
|
|
||||||
normal_count, warning_count, critical_count,
|
|
||||||
unknown_count, total_count, notinit_count'), 'AR',
|
|
||||||
array('field' => 'id_parent', 'order' => 'ASC'));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if ($group == -666) {
|
else if ($group == -666) {
|
||||||
$agents = false;
|
$agents = false;
|
||||||
@ -343,21 +312,11 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
|
|||||||
unknown_count, total_count, notinit_count'), $strict_user);
|
unknown_count, total_count, notinit_count'), $strict_user);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ($strict_user) {
|
$agents = agents_get_agents ($filter,
|
||||||
$filter['group_by'] = 'tagente.id_agente';
|
array ('id_grupo, nombre, id_os, id_parent, id_agente,
|
||||||
$fields = array ('tagente.id_grupo, tagente.nombre, tagente.id_os, tagente.id_parent, tagente.id_agente,
|
normal_count, warning_count, critical_count,
|
||||||
tagente.normal_count, tagente.warning_count, tagente.critical_count,
|
unknown_count, total_count, notinit_count'), 'AR',
|
||||||
tagente.unknown_count, tagente.total_count, tagente.notinit_count');
|
array('field' => 'id_parent', 'order' => 'ASC'));
|
||||||
$acltags = tags_get_user_groups_and_tags ($config['id_user'],'AR', $strict_user);
|
|
||||||
$agents = tags_get_all_user_agents (false, $config['id_user'], $acltags, $filter, $fields, false, $strict_user, true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$agents = agents_get_agents ($filter,
|
|
||||||
array ('id_grupo, nombre, id_os, id_parent, id_agente,
|
|
||||||
normal_count, warning_count, critical_count,
|
|
||||||
unknown_count, total_count, notinit_count'), 'AR',
|
|
||||||
array('field' => 'id_parent', 'order' => 'ASC'));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($agents === false)
|
if ($agents === false)
|
||||||
@ -392,7 +351,6 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
|
|||||||
$filter['disabled'] = 0;
|
$filter['disabled'] = 0;
|
||||||
|
|
||||||
// Get agent modules data
|
// Get agent modules data
|
||||||
// TODO TAGS agents_get_modules
|
|
||||||
$modules = agents_get_modules($agent['id_agente'], '*', $filter, true, true);
|
$modules = agents_get_modules($agent['id_agente'], '*', $filter, true, true);
|
||||||
|
|
||||||
if ($modules === false)
|
if ($modules === false)
|
||||||
@ -615,260 +573,6 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
|
|||||||
return $graph;
|
return $graph;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate a dot graph definition for graphviz with groups
|
|
||||||
function networkmap_generate_dot_groups ($pandora_name, $group = 0,
|
|
||||||
$simple = 0, $font_size = 12, $layout = 'radial', $nooverlap = 0,
|
|
||||||
$zoom = 1, $ranksep = 2.5, $center = 0, $regen = 1, $pure = 0,
|
|
||||||
$modwithalerts = 0, $module_group = 0, $hidepolicymodules = 0,
|
|
||||||
$depth = 'all', $id_networkmap = 0, $dont_show_subgroups = 0,
|
|
||||||
$text_filter = '', $strict_user = false, $size_canvas = null) {
|
|
||||||
|
|
||||||
global $config;
|
|
||||||
|
|
||||||
if ($strict_user) {
|
|
||||||
$acltags = tags_get_user_groups_and_tags ($config['id_user'],'AR', $strict_user);
|
|
||||||
}
|
|
||||||
$parents = array();
|
|
||||||
$orphans = array();
|
|
||||||
|
|
||||||
$filter = array ();
|
|
||||||
$filter['disabled'] = 0;
|
|
||||||
|
|
||||||
if (!empty($text_filter)) {
|
|
||||||
switch ($config['dbtype']) {
|
|
||||||
case "mysql":
|
|
||||||
case "postgresql":
|
|
||||||
$filter[] =
|
|
||||||
'(nombre COLLATE utf8_general_ci LIKE "%' . $text_filter . '%")';
|
|
||||||
break;
|
|
||||||
case "oracle":
|
|
||||||
$filter[] =
|
|
||||||
'(upper(nombre) LIKE upper(\'%' . $text_filter . '%\'))';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get groups data
|
|
||||||
if ($group > 0) {
|
|
||||||
$groups = array();
|
|
||||||
$id_groups = groups_get_id_recursive($group, true);
|
|
||||||
|
|
||||||
foreach($id_groups as $id_group) {
|
|
||||||
$add = false;
|
|
||||||
if (check_acl($config["id_user"], $id_group, 'AR')) {
|
|
||||||
$add = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($add) {
|
|
||||||
$groups[] = db_get_row ('tgrupo', 'id_grupo', $id_group);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$filter['id_grupo'] = $id_groups;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if ($strict_user) {
|
|
||||||
$groups = users_get_groups ($config['id_user'],"AR", false, true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$groups = db_get_all_rows_in_table ('tgrupo');
|
|
||||||
}
|
|
||||||
if ($groups === false) {
|
|
||||||
$groups = array();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Open Graph
|
|
||||||
$graph = networkmap_open_graph ($layout, $nooverlap, $pure, $zoom,
|
|
||||||
$ranksep, $font_size, $size_canvas);
|
|
||||||
|
|
||||||
$node_count = 0;
|
|
||||||
|
|
||||||
// Parse groups
|
|
||||||
$nodes = array ();
|
|
||||||
$nodes_groups = array();
|
|
||||||
foreach ($groups as $group2) {
|
|
||||||
$node_count ++;
|
|
||||||
$group2['type'] = 'group';
|
|
||||||
$group2['id_node'] = $node_count;
|
|
||||||
|
|
||||||
// Add node
|
|
||||||
$nodes_groups[$group2['id_grupo']] = $group2;
|
|
||||||
}
|
|
||||||
|
|
||||||
$node_count = 0;
|
|
||||||
|
|
||||||
$groups_hiden = array();
|
|
||||||
foreach ($nodes_groups as $node_group) {
|
|
||||||
|
|
||||||
$node_count++;
|
|
||||||
|
|
||||||
// Save node parent information to define edges later
|
|
||||||
if ($node_group['parent'] != "0" && $node_group['id_grupo'] != $group) {
|
|
||||||
if ((!$dont_show_subgroups) || ($group == 0)) {
|
|
||||||
$parents[$node_count] = $nodes_groups[$node_group['parent']]['id_node'];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$groups_hiden[$node_group['id_grupo']] = 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$orphans[$node_count] = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
$nodes[$node_count] = $node_group;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($depth != 'group') {
|
|
||||||
if ($strict_user) {
|
|
||||||
$filter['group_by'] = 'tagente.nombre';
|
|
||||||
$filter['id_group'] = $filter['id_grupo'];
|
|
||||||
$fields = array ('tagente.id_grupo, tagente.nombre, tagente.id_os, tagente.id_agente,
|
|
||||||
tagente.normal_count, tagente.warning_count, tagente.critical_count,
|
|
||||||
tagente.unknown_count, tagente.total_count, tagente.notinit_count');
|
|
||||||
$agents = tags_get_all_user_agents (false, $config['id_user'], $acltags, $filter, $fields, false, $strict_user, true);
|
|
||||||
unset($filter['id_group']);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Get agents data
|
|
||||||
$agents = agents_get_agents ($filter,
|
|
||||||
array ('id_grupo, nombre, id_os, id_agente,
|
|
||||||
normal_count, warning_count, critical_count,
|
|
||||||
unknown_count, total_count, notinit_count'));
|
|
||||||
}
|
|
||||||
if ($agents === false)
|
|
||||||
$agents = array();
|
|
||||||
|
|
||||||
// Parse agents
|
|
||||||
$nodes_agents = array();
|
|
||||||
foreach ($agents as $agent) {
|
|
||||||
if ($dont_show_subgroups) {
|
|
||||||
if (!empty($groups_hiden[$agent['id_grupo']])) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If only agents with alerts => agents without alerts discarded
|
|
||||||
$alert_agent = agents_get_alerts($agent['id_agente']);
|
|
||||||
|
|
||||||
if ($modwithalerts and empty($alert_agent['simple'])) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$node_count ++;
|
|
||||||
// Save node parent information to define edges later
|
|
||||||
$parents[$node_count] = $agent['parent'] = $nodes_groups[$agent['id_grupo']]['id_node'];
|
|
||||||
|
|
||||||
$agent['id_node'] = $node_count;
|
|
||||||
$agent['type'] = 'agent';
|
|
||||||
// Add node
|
|
||||||
$nodes[$node_count] = $nodes_agents[$agent['id_agente']] = $agent;
|
|
||||||
|
|
||||||
if ($depth == 'agent') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get agent modules data
|
|
||||||
// TODO TAGS agents_get_modules
|
|
||||||
$modules = agents_get_modules ($agent['id_agente'], false, array('disabled' => 0), true, false);
|
|
||||||
|
|
||||||
// Parse modules
|
|
||||||
foreach ($modules as $key => $module) {
|
|
||||||
$node_count ++;
|
|
||||||
$agent_module = modules_get_agentmodule($key);
|
|
||||||
$alerts_module = db_get_sql('SELECT count(*) AS num
|
|
||||||
FROM talert_template_modules
|
|
||||||
WHERE id_agent_module = ' . $key);
|
|
||||||
|
|
||||||
if ($alerts_module == 0 && $modwithalerts) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($agent_module['id_module_group'] != $module_group &&
|
|
||||||
$module_group != 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($hidepolicymodules && $config['enterprise_installed']) {
|
|
||||||
enterprise_include_once('include/functions_policies.php');
|
|
||||||
if (policies_is_module_in_policy($key)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save node parent information to define edges later
|
|
||||||
$parents[$node_count] = $agent_module['parent'] = $agent['id_node'];
|
|
||||||
|
|
||||||
$agent_module['id_node'] = $node_count;
|
|
||||||
|
|
||||||
$agent_module['type'] = 'module';
|
|
||||||
// Add node
|
|
||||||
$nodes[$node_count] = $agent_module;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty ($nodes)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create void statistics array
|
|
||||||
$stats = array();
|
|
||||||
|
|
||||||
// Create nodes
|
|
||||||
foreach ($nodes as $node_id => $node) {
|
|
||||||
if ($center > 0 && ! networkmap_is_descendant ($node_id, $center, $parents)) {
|
|
||||||
unset ($parents[$node_id]);
|
|
||||||
unset ($orphans[$node_id]);
|
|
||||||
unset ($nodes[$node_id]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
switch ($node['type']) {
|
|
||||||
case 'group':
|
|
||||||
$graph .= networkmap_create_group_node ($node , $simple, $font_size, $metaconsole = false, null, $strict_user) .
|
|
||||||
"\n\t\t";
|
|
||||||
$stats['groups'][] = $node['id_grupo'];
|
|
||||||
break;
|
|
||||||
case 'agent':
|
|
||||||
$graph .= networkmap_create_agent_node ($node , $simple, $font_size, true, true) .
|
|
||||||
"\n\t\t";
|
|
||||||
$stats['agents'][] = $node['id_agente'];
|
|
||||||
break;
|
|
||||||
case 'module':
|
|
||||||
$graph .= networkmap_create_module_node ($node , $simple, $font_size) .
|
|
||||||
"\n\t\t";
|
|
||||||
$stats['modules'][] = $node['id_agente_modulo'];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Define edges
|
|
||||||
foreach ($parents as $node => $parent_id) {
|
|
||||||
// Verify that the parent is in the graph
|
|
||||||
if (isset ($nodes[$parent_id])) {
|
|
||||||
$graph .= networkmap_create_edge ($node, $parent_id, $layout, $nooverlap, $pure, $zoom, $ranksep, $simple, $regen, $font_size, $group, 'operation/agentes/networkmap', 'groups', $id_networkmap);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$orphans[$node] = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a central node if orphan nodes exist
|
|
||||||
if (count ($orphans)) {
|
|
||||||
$graph .= networkmap_create_pandora_node ($pandora_name, $font_size, $simple, $stats);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Define edges for orphan nodes
|
|
||||||
foreach (array_keys($orphans) as $node) {
|
|
||||||
$graph .= networkmap_create_edge ('0', $node, $layout, $nooverlap, $pure, $zoom, $ranksep, $simple, $regen, $font_size, $group, 'operation/agentes/networkmap', 'groups', $id_networkmap);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close graph
|
|
||||||
$graph .= networkmap_close_graph ();
|
|
||||||
|
|
||||||
return $graph;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns an edge definition
|
// Returns an edge definition
|
||||||
function networkmap_create_edge ($head, $tail, $layout, $nooverlap, $pure, $zoom, $ranksep, $simple, $regen, $font_size, $group, $sec2 = 'operation/agentes/networkmap', $tab = 'topology', $id_networkmap = 0) {
|
function networkmap_create_edge ($head, $tail, $layout, $nooverlap, $pure, $zoom, $ranksep, $simple, $regen, $font_size, $group, $sec2 = 'operation/agentes/networkmap', $tab = 'topology', $id_networkmap = 0) {
|
||||||
if (defined("METACONSOLE")) {
|
if (defined("METACONSOLE")) {
|
||||||
|
@ -3958,26 +3958,6 @@ function get_status_module() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function check_changes_num_modules() {
|
|
||||||
var params = [];
|
|
||||||
params.push("check_changes_num_modules=1");
|
|
||||||
params.push("id=" + id_agent);
|
|
||||||
params.push("page=operation/agentes/pandora_networkmap.view");
|
|
||||||
jQuery.ajax({
|
|
||||||
data: params.join("&"),
|
|
||||||
dataType: 'json',
|
|
||||||
type: 'POST',
|
|
||||||
url: action = "../../../ajax.php",
|
|
||||||
success: function (data) {
|
|
||||||
if (data['correct']) {
|
|
||||||
if (module_count != data['count']) {
|
|
||||||
//location.reload(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function show_networkmap_node(id_agent_param, refresh_state) {
|
function show_networkmap_node(id_agent_param, refresh_state) {
|
||||||
id_agent = id_agent_param;
|
id_agent = id_agent_param;
|
||||||
|
|
||||||
|
@ -563,8 +563,6 @@ if (is_ajax ()) {
|
|||||||
$get_status_node = (bool)get_parameter('get_status_node', false);
|
$get_status_node = (bool)get_parameter('get_status_node', false);
|
||||||
$get_status_module = (bool)get_parameter('get_status_module',
|
$get_status_module = (bool)get_parameter('get_status_module',
|
||||||
false);
|
false);
|
||||||
$check_changes_num_modules = (bool)get_parameter(
|
|
||||||
'check_changes_num_modules', false);
|
|
||||||
|
|
||||||
if ($get_status_node) {
|
if ($get_status_node) {
|
||||||
$id = (int)get_parameter('id', 0);
|
$id = (int)get_parameter('id', 0);
|
||||||
@ -593,20 +591,6 @@ if (is_ajax ()) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($check_changes_num_modules) {
|
|
||||||
$id = (int)get_parameter('id', 0);
|
|
||||||
// TODO TAGS agents_get_modules
|
|
||||||
$modules = agents_get_modules($id);
|
|
||||||
|
|
||||||
$return = array();
|
|
||||||
$return['correct'] = true;
|
|
||||||
$return['count'] = count($modules);
|
|
||||||
|
|
||||||
echo json_encode($return);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($update_node_alert) {
|
if ($update_node_alert) {
|
||||||
$map_id = (int)get_parameter('map_id', 0);
|
$map_id = (int)get_parameter('map_id', 0);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user