From 48991738caefd746e06def0f1286d9b7834f23c5 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 16 Dec 2014 16:39:00 +0100 Subject: [PATCH] Working in the new code of treeview --- pandora_console/include/ajax/tree.ajax.php | 33 ++++ pandora_console/include/class/tree.class.php | 158 +++++++++++++++++++ pandora_console/include/constants.php | 122 +++++++------- pandora_console/include/functions_groups.php | 20 ++- pandora_console/operation/tree.php | 2 +- pandora_console/operation/tree2.php | 114 +++++++++++++ 6 files changed, 382 insertions(+), 67 deletions(-) create mode 100644 pandora_console/include/ajax/tree.ajax.php create mode 100644 pandora_console/include/class/tree.class.php mode change 100644 => 100755 pandora_console/include/constants.php diff --git a/pandora_console/include/ajax/tree.ajax.php b/pandora_console/include/ajax/tree.ajax.php new file mode 100644 index 0000000000..40509c6ee1 --- /dev/null +++ b/pandora_console/include/ajax/tree.ajax.php @@ -0,0 +1,33 @@ +set_filter(array( + 'status' => $status, + 'search' => $search)); + echo $tree->get_json(); + return; +} +?> \ No newline at end of file diff --git a/pandora_console/include/class/tree.class.php b/pandora_console/include/class/tree.class.php new file mode 100644 index 0000000000..5a3c8d686d --- /dev/null +++ b/pandora_console/include/class/tree.class.php @@ -0,0 +1,158 @@ +type = $type; + $this->root = $root; + } + + public function set_type($type) { + $this->type = $type; + } + + public function set_filter($filter) { + $this->filter = $filter; + } + + public function get_data() { + switch ($this->type) { + case 'os': + $this->get_data_os(); + break; + case 'group': + $this->get_data_group(); + break; + case 'module_group': + $this->get_data_module_group(); + break; + case 'module': + $this->get_data_module(); + break; + case 'tag': + $this->get_data_tag(); + break; + } + } + + public function get_data_os() { + } + + public function get_data_group() { + $filter = array(); + + if (!empty($this->root)) { + $filter['parent'] = $this->root; + } + else { + $filter['parent'] = 0; + } + if (!empty($this->filter['search'])) { + $filter['nombre'] = "%" . $this->filter['search'] . "%"; + } + + + // First filter by name and father + $groups = db_get_all_rows_filter('tgrupo', + $filter, + array('id_grupo', 'nombre')); + if (empty($groups)) + $groups = array(); + + // Filter by status + $status = AGENT_STATUS_ALL; + if (!empty($this->filter['status'])) { + $status = $this->filter['status']; + } + + if ($status != AGENT_STATUS_ALL) { + foreach ($groups as $iterator => $group) { + $count_ok = groups_monitor_ok( + array($group['id_grupo'])); + $count_critical = groups_monitor_critical( + array($group['id_grupo'])); + $count_warning = groups_monitor_warning( + array($group['id_grupo'])); + $count_unknown = groups_monitor_unknown( + array($group['id_grupo'])); + $count_not_init = groups_monitor_not_init( + array($group['id_grupo'])); + + $remove_group = true; + switch ($status) { + case AGENT_STATUS_NORMAL: + if (($count_critical == 0) && + ($count_warning == 0) && + ($count_unknown == 0) && + ($count_not_init == 0)) { + + $remove_group = false; + } + break; + case AGENT_STATUS_WARNING: + if ($count_warning > 0) + $remove_group = false; + break; + case AGENT_STATUS_CRITICAL: + if ($count_critical > 0) + $remove_group = false; + break; + case AGENT_STATUS_UNKNOWN: + if ($count_unknown > 0) + $remove_group = false; + break; + case AGENT_STATUS_NOT_INIT: + if ($count_not_init > 0) + $remove_group = false; + break; + } + + if ($remove_group) + unset($groups[$iterator]); + } + } + + // Make the data + $this->tree = array(); + foreach ($groups as $group) { + $data = array(); + $data['id'] = $group['id_grupo']; + $data['name'] = $group['nombre']; + + $this->tree[] = $data; + } + } + + public function get_data_module_group() { + } + + public function get_data_module() { + } + + public function get_data_tag() { + } + + public function get_json() { + $this->get_data(); + + return json_encode($this->tree); + } +} +?> diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php old mode 100644 new mode 100755 index 3be630f662..b33ac7fdfa --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -19,25 +19,25 @@ */ /* Enterprise hook constant */ -define ('ENTERPRISE_NOT_HOOK', -1); +define ('ENTERPRISE_NOT_HOOK', -1); /**/ -define('DATE_FORMAT', 'Y/m/d'); -define('DATE_FORMAT_JS', 'yy/mm/d'); -define('TIME_FORMAT', 'H:i:s'); -define('TIME_FORMAT_JS', 'HH:mm:ss'); +define('DATE_FORMAT', 'Y/m/d'); +define('DATE_FORMAT_JS', 'yy/mm/d'); +define('TIME_FORMAT', 'H:i:s'); +define('TIME_FORMAT_JS', 'HH:mm:ss'); /* Events state constants */ -define ('EVENT_NEW', 0); -define ('EVENT_VALIDATE', 1); -define ('EVENT_PROCESS', 2); +define ('EVENT_NEW', 0); +define ('EVENT_VALIDATE', 1); +define ('EVENT_PROCESS', 2); /* Agents disabled status */ -define ('AGENT_ENABLED',0); -define ('AGENT_DISABLED',1); +define ('AGENT_ENABLED', 0); +define ('AGENT_DISABLED', 1); @@ -97,10 +97,10 @@ define('SECONDS_3YEARS', 93312000); /* Separator constats */ -define('SEPARATOR_COLUMN', ';'); -define('SEPARATOR_ROW', chr(10)); //chr(10) = '\n' -define('SEPARATOR_COLUMN_CSV', "#"); -define('SEPARATOR_ROW_CSV', "@\n"); +define('SEPARATOR_COLUMN', ';'); +define('SEPARATOR_ROW', chr(10)); //chr(10) = '\n' +define('SEPARATOR_COLUMN_CSV', "#"); +define('SEPARATOR_ROW_CSV', "@\n"); @@ -108,72 +108,72 @@ define('SEPARATOR_ROW_CSV', "@\n"); switch ($config["dbtype"]) { case "mysql": case "postgresql": - define ('BACKUP_DIR', 'attachment/backups'); - define ('BACKUP_FULLPATH', $config['homedir'] . '/' . BACKUP_DIR); + define ('BACKUP_DIR', 'attachment/backups'); + define ('BACKUP_FULLPATH', $config['homedir'] . '/' . BACKUP_DIR); break; case "oracle": - define ('BACKUP_DIR', 'DATA_PUMP_DIR'); - define ('BACKUP_FULLPATH', 'DATA_PUMP_DIR'); + define ('BACKUP_DIR', 'DATA_PUMP_DIR'); + define ('BACKUP_FULLPATH', 'DATA_PUMP_DIR'); break; } /* Color constants */ -define('COL_CRITICAL','#f85858'); -define('COL_WARNING','#ffea59'); -define('COL_WARNING_DARK','#FFB900'); -define('COL_NORMAL','#6EB432'); -define('COL_NOTINIT','#3BA0FF'); -define('COL_UNKNOWN','#AAAAAA'); -define('COL_ALERTFIRED','#FF8800'); -define('COL_MINOR','#F099A2'); -define('COL_MAJOR','#C97A4A'); -define('COL_INFORMATIONAL','#E4E4E4'); -define('COL_MAINTENANCE','#3BA0FF'); +define('COL_CRITICAL', '#f85858'); +define('COL_WARNING', '#ffea59'); +define('COL_WARNING_DARK', '#FFB900'); +define('COL_NORMAL', '#6EB432'); +define('COL_NOTINIT', '#3BA0FF'); +define('COL_UNKNOWN', '#AAAAAA'); +define('COL_ALERTFIRED', '#FF8800'); +define('COL_MINOR', '#F099A2'); +define('COL_MAJOR', '#C97A4A'); +define('COL_INFORMATIONAL', '#E4E4E4'); +define('COL_MAINTENANCE', '#3BA0FF'); -define('COL_GRAPH1', '#C397F2'); -define('COL_GRAPH2', '#FFE66C'); -define('COL_GRAPH3', '#92CCA3'); -define('COL_GRAPH4', '#EA6D5B'); -define('COL_GRAPH5', '#6BD8DD'); -define('COL_GRAPH6', '#F49B31'); -define('COL_GRAPH7', '#999999'); -define('COL_GRAPH8', '#F2B8C1'); -define('COL_GRAPH9', '#C4E8C1'); -define('COL_GRAPH10', '#C1DBE5'); -define('COL_GRAPH11', '#C9C1e0'); -define('COL_GRAPH12', '#F45B95'); -define('COL_GRAPH13', '#E83128'); +define('COL_GRAPH1', '#C397F2'); +define('COL_GRAPH2', '#FFE66C'); +define('COL_GRAPH3', '#92CCA3'); +define('COL_GRAPH4', '#EA6D5B'); +define('COL_GRAPH5', '#6BD8DD'); +define('COL_GRAPH6', '#F49B31'); +define('COL_GRAPH7', '#999999'); +define('COL_GRAPH8', '#F2B8C1'); +define('COL_GRAPH9', '#C4E8C1'); +define('COL_GRAPH10', '#C1DBE5'); +define('COL_GRAPH11', '#C9C1e0'); +define('COL_GRAPH12', '#F45B95'); +define('COL_GRAPH13', '#E83128'); /* The styles */ /* Size of text in characters for truncate */ -define('GENERIC_SIZE_TEXT', 25); +define('GENERIC_SIZE_TEXT', 25); /* Agent module status */ -define('AGENT_MODULE_STATUS_CRITICAL_BAD', 1); -define('AGENT_MODULE_STATUS_CRITICAL_ALERT', 100); -define('AGENT_MODULE_STATUS_NO_DATA', 4); -define('AGENT_MODULE_STATUS_NORMAL', 0); -define('AGENT_MODULE_STATUS_NORMAL_ALERT', 300); -define('AGENT_MODULE_STATUS_NOT_NORMAL', 6); -define('AGENT_MODULE_STATUS_WARNING', 2); -define('AGENT_MODULE_STATUS_WARNING_ALERT', 200); -define('AGENT_MODULE_STATUS_UNKNOWN', 3); -define('AGENT_MODULE_STATUS_NOT_INIT', 5); +define('AGENT_MODULE_STATUS_CRITICAL_BAD', 1); +define('AGENT_MODULE_STATUS_CRITICAL_ALERT', 100); +define('AGENT_MODULE_STATUS_NO_DATA', 4); +define('AGENT_MODULE_STATUS_NORMAL', 0); +define('AGENT_MODULE_STATUS_NORMAL_ALERT', 300); +define('AGENT_MODULE_STATUS_NOT_NORMAL', 6); +define('AGENT_MODULE_STATUS_WARNING', 2); +define('AGENT_MODULE_STATUS_WARNING_ALERT', 200); +define('AGENT_MODULE_STATUS_UNKNOWN', 3); +define('AGENT_MODULE_STATUS_NOT_INIT', 5); /* Agent status */ -define('AGENT_STATUS_ALL', -1); -define('AGENT_STATUS_CRITICAL', 1); -define('AGENT_STATUS_NORMAL', 0); -define('AGENT_STATUS_NOT_INIT', 5); -define('AGENT_STATUS_NOT_NORMAL', 6); -define('AGENT_STATUS_UNKNOWN', 3); -define('AGENT_STATUS_ALERT_FIRED', 4); -define('AGENT_STATUS_WARNING', 2); +define('AGENT_STATUS_ALL', -1); +define('AGENT_STATUS_CRITICAL', 1); +define('AGENT_STATUS_NORMAL', 0); +define('AGENT_STATUS_NOT_INIT', 5); +define('AGENT_STATUS_NOT_NORMAL', 6); +define('AGENT_STATUS_UNKNOWN', 3); +define('AGENT_STATUS_ALERT_FIRED', 4); +define('AGENT_STATUS_WARNING', 2); /* Visual maps contants */ diff --git a/pandora_console/include/functions_groups.php b/pandora_console/include/functions_groups.php index c07aae0ae0..33c24f5e7d 100644 --- a/pandora_console/include/functions_groups.php +++ b/pandora_console/include/functions_groups.php @@ -278,8 +278,12 @@ function groups_get_parents($parent, $onlyPropagate = false, $groups = null) { continue; } - if (($group['id_grupo'] == $parent) && ($group['propagate'] || !$onlyPropagate)) { - $return = $return + array($group['id_grupo'] => $group) + groups_get_parents($group['parent'], $onlyPropagate, $groups); + if (($group['id_grupo'] == $parent) + && ($group['propagate'] || !$onlyPropagate)) { + + $return = $return + + array($group['id_grupo'] => $group) + + groups_get_parents($group['parent'], $onlyPropagate, $groups); } } @@ -1303,7 +1307,9 @@ function groups_monitor_ok ($group_array) { $group_clause = "(" . $group_clause . ")"; //TODO REVIEW ORACLE AND POSTGRES - $count = db_get_sql ("SELECT SUM(normal_count) FROM tagente WHERE disabled = 0 AND id_grupo IN $group_clause"); + $count = db_get_sql ("SELECT SUM(normal_count) + FROM tagente + WHERE disabled = 0 AND id_grupo IN $group_clause"); return $count > 0 ? $count : 0; } @@ -1326,7 +1332,9 @@ function groups_monitor_critical ($group_array) { $group_clause = "(" . $group_clause . ")"; //TODO REVIEW ORACLE AND POSTGRES - $count = db_get_sql ("SELECT SUM(critical_count) FROM tagente WHERE disabled = 0 AND id_grupo IN $group_clause"); + $count = db_get_sql ("SELECT SUM(critical_count) + FROM tagente + WHERE disabled = 0 AND id_grupo IN $group_clause"); return $count > 0 ? $count : 0; } @@ -1372,7 +1380,9 @@ function groups_monitor_unknown ($group_array) { $group_clause = "(" . $group_clause . ")"; //TODO REVIEW ORACLE AND POSTGRES - $count = db_get_sql ("SELECT SUM(unknown_count) FROM tagente WHERE disabled = 0 AND id_grupo IN $group_clause"); + $count = db_get_sql ("SELECT SUM(unknown_count) + FROM tagente + WHERE disabled = 0 AND id_grupo IN $group_clause"); return $count > 0 ? $count : 0; } diff --git a/pandora_console/operation/tree.php b/pandora_console/operation/tree.php index 31686037b5..ca73cd5f1f 100755 --- a/pandora_console/operation/tree.php +++ b/pandora_console/operation/tree.php @@ -17,7 +17,7 @@ require_once("tree2.php"); -return; +//~ return; //////////////////////////////////////////////////////////////////////// diff --git a/pandora_console/operation/tree2.php b/pandora_console/operation/tree2.php index 1c77c1d6b7..e04cfb1945 100644 --- a/pandora_console/operation/tree2.php +++ b/pandora_console/operation/tree2.php @@ -14,5 +14,119 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. +global $config; +require_once("include/class/tree.class.php"); + +$tab = get_parameter('tab', 'group'); +$search = get_parameter('search', ''); +$status = get_parameter('status', AGENT_STATUS_ALL); + + +// ---------------------Tabs ------------------------------------------- +$url = 'index.php?' . + 'sec=estado&' . + 'sec2=operation/tree&' . + 'refr=0&' . + 'pure=' . (int)get_parameter('pure', 0) . '&' . + 'tab=%s'; + +$tabs = array(); +$tabs['os'] = array( + 'text' => "" . + html_print_image("images/operating_system.png", true, + array("title" => __('OS'))) . "", + 'active' => ($tab == "os")); + +$tabs['group'] = array( + 'text' => "" . + html_print_image("images/group.png", true, + array("title" => __('Groups'))) . "", + 'active' => ($tab == "group")); + +$tabs['module_group'] = array( + 'text' => "" . + html_print_image("images/module_group.png", true, + array("title" => __('Module groups'))) . "", + 'active' => ($tab == "module_group")); + +$tabs['module'] = array( + 'text' => "" . + html_print_image("images/brick.png", true, + array("title" => __('Modules'))) . "", + 'active' => ($tab == "module")); + +$tabs['tag'] = array( + 'text' => "" . + html_print_image("images/tag.png", true, + array("title" => __('Tags'))) . "", + 'active' => ($tab == "tag")); + +$header_title = ""; +switch ($tab) { + case 'os': + $header_title = + __('Tree view - Sort the agents by OS'); + break; + case 'group': + $header_title = + __('Tree view - Sort the agents by groups'); + break; + case 'module_group': + $header_title = + __('Tree view - Sort the agents by module groups'); + break; + case 'module': + $header_title = + __('Tree view - Sort the agents by modules'); + break; + case 'tag': + $header_title = + __('Tree view - Sort the agents by tags'); + break; +} + +ui_print_page_header( + $header_title, "images/extensions.png", false, "", false, $tabs); +// ---------------------Tabs ------------------------------------------- + + +// --------------------- form filter ----------------------------------- +$table = null; +$table->width = "100%"; + +$table->data[0][0] = __('Agent status'); +$fields = array (); +$fields[AGENT_STATUS_ALL] = __('All'); //default +$fields[AGENT_STATUS_NORMAL] = __('Normal'); +$fields[AGENT_STATUS_WARNING] = __('Warning'); +$fields[AGENT_STATUS_CRITICAL] = __('Critical'); +$fields[AGENT_STATUS_UNKNOWN] = __('Unknown'); +$fields[AGENT_STATUS_NOT_INIT] = __('Not init'); +$table->data[0][1] = html_print_select($fields, + "status", + $status, + '', + '', + 0, + true); +$table->data[0][2] = __('Search agent'); +$table->data[0][3] = html_print_input_text( + "search", $search, '', 40, 30, true); +$table->data[0][4] = html_print_submit_button( + __('Filter'), "uptbutton", false, 'class="sub search"', true); + +html_print_table($table); + +// --------------------- form filter ----------------------------------- + + + +$tree = new Tree($tab); +$tree->set_filter(array( + 'status' => $status, + 'search' => $search)); +$json_tree = $tree->get_json(); + +html_debug_print($json_tree); ?> \ No newline at end of file