From f5d1e60ec3e273bdd9106f4d0fda752c8b06c4d1 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Mon, 5 Jan 2015 16:48:11 +0100 Subject: [PATCH] Finished the tag tree view --- pandora_console/include/class/Tree.class.php | 131 ++++++++++++++++++ .../include/javascript/tree/TreeController.js | 15 +- 2 files changed, 144 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index 66d0e133f0..1df2873dbc 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -758,6 +758,137 @@ class Tree { } private function getDataTag() { + // Get the parent + if (empty($this->root)) + $parent = 0; + else + $parent = $this->root; + + // ACL Group + $group_acl = ""; + if (!empty($this->userGroups)) { + $user_groups_str = implode(",", array_keys($this->userGroups)); + $group_acl = " AND ta.id_grupo IN ($user_groups_str) "; + } + + $sql = "SELECT tam.nombre AS module_name, tam.id_agente_modulo, + tam.id_tipo_modulo, tam.id_module_group, + ta.id_agente, ta.nombre AS agent_name, + tt.name AS tag_name, tt.id_tag + FROM tagente ta, tagente_modulo tam, ttag_module ttm, ttag tt + WHERE ta.id_agente = tam.id_agente + AND tam.id_agente_modulo = ttm.id_agente_modulo + AND ttm.id_tag = tt.id_tag + AND ta.disabled = 0 + AND tam.disabled = 0 + $group_acl + ORDER BY tt.name ASC, ta.id_agente ASC"; + $data = db_process_sql($sql); + + if (empty($data)) { + $data = array(); + } + + $nodes = array(); + $actual_tag_root = array( + 'id' => null, + 'name' => '', + 'children' => array(), + 'counters' => array() + ); + $actual_agent = array(); + foreach ($data as $key => $value) { + + // Module + $module = array(); + $module['id_agente_modulo'] = (int) $value['id_agente_modulo']; + $module['nombre'] = $value['module_name']; + $module['id_tipo_modulo'] = (int) $value['id_tipo_modulo']; + $module['id_module_group'] = (int) $value['id_module_group']; + + $this->processModule($module); + + // Tag + if ($actual_tag_root['id'] === (int)$value['id_tag']) { + // Agent + if (empty($actual_agent) || $actual_agent['id'] !== (int)$value['id_agente']) { + // Add the last agent to the tag + if (!empty($actual_agent)) + $actual_tag_root['children'][] = $actual_agent; + + // Create the new agent + $actual_agent = array(); + $actual_agent['id_agente'] = (int) $value['id_agente']; + $actual_agent['nombre'] = $value['agent_name']; + $actual_agent['children'] = array(); + + $this->processAgent(&$actual_agent, array(), false); + + // Add the module to the agent + $actual_agent['children'][] = $module; + + // Increase counters + $actual_tag_root['counters']['total']++; + + if (isset($actual_tag_root['counters'][$actual_agent['status']])) + $actual_tag_root['counters'][$actual_agent['status']]++; + } + else { + $actual_agent['children'][] = $module; + } + } + else { + // The first iteration doesn't enter here + if ($actual_tag_root['id'] !== null) { + // Add the agent to the tag + $actual_tag_root['children'][] = $actual_agent; + // Add the tag to the branch + $nodes[] = $actual_tag_root; + } + + // Create the new agent + $actual_agent = array(); + $actual_agent['id_agente'] = (int) $value['id_agente']; + $actual_agent['nombre'] = $value['agent_name']; + $actual_agent['children'] = array(); + + $this->processAgent(&$actual_agent, array(), false); + + // Add the module to the agent + $actual_agent['children'][] = $module; + + // Create new tag + $actual_tag_root = array(); + $actual_tag_root['id'] = (int) $value['id_tag']; + $actual_tag_root['name'] = $value['tag_name']; + $actual_tag_root['type'] = $this->type; + + // Initialize counters + $actual_tag_root['counters'] = array(); + $actual_tag_root['counters']['total'] = 0; + $actual_tag_root['counters']['alerts'] = 0; + $actual_tag_root['counters']['critical'] = 0; + $actual_tag_root['counters']['warning'] = 0; + $actual_tag_root['counters']['unknown'] = 0; + $actual_tag_root['counters']['not_init'] = 0; + $actual_tag_root['counters']['ok'] = 0; + + // Increase counters + $actual_tag_root['counters']['total']++; + + if (isset($actual_tag_root['counters'][$actual_agent['status']])) + $actual_tag_root['counters'][$actual_agent['status']]++; + } + } + // If there is an agent and a tag opened and not saved + if ($actual_tag_root['id'] !== null) { + // Add the last agent to the tag + $actual_tag_root['children'][] = $actual_agent; + // Add the last tag to the branch + $nodes[] = $actual_tag_root; + } + + $this->tree = $nodes; } public function getJSON() { diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index c595ad9ae8..dd390608d1 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -301,7 +301,7 @@ TreeController = { case 'group': if (typeof element.icon != 'undefined' && element.icon.length > 0) { $content.append(' ') + +'images/groups_small/'+element.icon+'" /> '); } $content.append(element.name); break; @@ -314,7 +314,18 @@ TreeController = { case 'os': if (typeof element.icon != 'undefined' && element.icon.length > 0) { $content.append(' ') + +'images/os_icons/'+element.icon+'" /> '); + } + $content.append(element.name); + break; + case 'tag': + if (typeof element.icon != 'undefined' && element.icon.length > 0) { + $content.append(' '); + } + else { + $content.append(' '); } $content.append(element.name); break;