Working in the new code of treeview

This commit is contained in:
mdtrooper 2014-12-16 16:39:00 +01:00
parent 42fdf3bebb
commit 3e6fde548b
6 changed files with 382 additions and 67 deletions

View File

@ -0,0 +1,33 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2012 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; version 2
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
require_once("include/class/tree.class.php");
$get_data = (bool)get_parameter('get_data', 0);
if ($get_data) {
$tab = get_parameter('type', 'group');
$search = get_parameter('search', '');
$status = (int)get_parameter('status', AGENT_STATUS_ALL);
$root = (int)get_parameter('root', 0);
$tree = new Tree($tab);
$tree->set_filter(array(
'status' => $status,
'search' => $search));
echo $tree->get_json();
return;
}
?>

View File

@ -0,0 +1,158 @@
<?php
//Pandora FMS- http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; version 2
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
class Tree {
private $type = null;
private $tree = array();
private $filter = array();
private $root = null;
public function __construct($type, $root = null) {
$this->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);
}
}
?>

122
pandora_console/include/constants.php Normal file → Executable file
View File

@ -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 */

View File

@ -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;
}

View File

@ -17,7 +17,7 @@
require_once("tree2.php");
return;
//~ return;
////////////////////////////////////////////////////////////////////////

View File

@ -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' => "<a href='" . sprintf($url, "os") . "'>" .
html_print_image("images/operating_system.png", true,
array("title" => __('OS'))) . "</a>",
'active' => ($tab == "os"));
$tabs['group'] = array(
'text' => "<a href='" . sprintf($url, "group") . "'>" .
html_print_image("images/group.png", true,
array("title" => __('Groups'))) . "</a>",
'active' => ($tab == "group"));
$tabs['module_group'] = array(
'text' => "<a href='" . sprintf($url, "module_group") . "'>" .
html_print_image("images/module_group.png", true,
array("title" => __('Module groups'))) . "</a>",
'active' => ($tab == "module_group"));
$tabs['module'] = array(
'text' => "<a href='" . sprintf($url, "module") . "'>" .
html_print_image("images/brick.png", true,
array("title" => __('Modules'))) . "</a>",
'active' => ($tab == "module"));
$tabs['tag'] = array(
'text' => "<a href='" . sprintf($url, "tag") . "'>" .
html_print_image("images/tag.png", true,
array("title" => __('Tags'))) . "</a>",
'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);
?>