2014-12-16 16:39:00 +01:00
|
|
|
<?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;
|
2014-12-17 19:56:42 +01:00
|
|
|
private $childrenMethod = "on_demand";
|
2014-12-16 16:39:00 +01:00
|
|
|
|
2014-12-17 18:58:34 +01:00
|
|
|
public function __construct($type, $childrenMethod = "on_demand", $root = null) {
|
2014-12-16 16:39:00 +01:00
|
|
|
$this->type = $type;
|
|
|
|
$this->root = $root;
|
2014-12-17 18:58:34 +01:00
|
|
|
$this->childrenMethod = $childrenMethod;
|
2014-12-16 16:39:00 +01:00
|
|
|
}
|
|
|
|
|
2014-12-17 18:58:34 +01:00
|
|
|
public function setType($type) {
|
2014-12-16 16:39:00 +01:00
|
|
|
$this->type = $type;
|
|
|
|
}
|
|
|
|
|
2014-12-17 18:58:34 +01:00
|
|
|
public function setFilter($filter) {
|
2014-12-16 16:39:00 +01:00
|
|
|
$this->filter = $filter;
|
|
|
|
}
|
|
|
|
|
2014-12-17 18:58:34 +01:00
|
|
|
public function getData() {
|
2014-12-16 16:39:00 +01:00
|
|
|
switch ($this->type) {
|
|
|
|
case 'os':
|
2014-12-17 18:58:34 +01:00
|
|
|
$this->getDataOS();
|
2014-12-16 16:39:00 +01:00
|
|
|
break;
|
|
|
|
case 'group':
|
2014-12-17 18:58:34 +01:00
|
|
|
$this->getDataGroup();
|
2014-12-16 16:39:00 +01:00
|
|
|
break;
|
|
|
|
case 'module_group':
|
2014-12-17 18:58:34 +01:00
|
|
|
$this->getDataModuleGroup();
|
2014-12-16 16:39:00 +01:00
|
|
|
break;
|
|
|
|
case 'module':
|
2014-12-17 18:58:34 +01:00
|
|
|
$this->getDataModule();
|
2014-12-16 16:39:00 +01:00
|
|
|
break;
|
|
|
|
case 'tag':
|
2014-12-17 18:58:34 +01:00
|
|
|
$this->getDataTag();
|
2014-12-16 16:39:00 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-17 18:58:34 +01:00
|
|
|
public function getDataOS() {
|
2014-12-16 16:39:00 +01:00
|
|
|
}
|
|
|
|
|
2014-12-17 18:58:34 +01:00
|
|
|
private function getRecursiveGroup($parent, $limit = null) {
|
2014-12-16 16:39:00 +01:00
|
|
|
$filter = array();
|
|
|
|
|
2014-12-17 18:58:34 +01:00
|
|
|
|
|
|
|
$filter['parent'] = $parent;
|
|
|
|
|
2014-12-16 16:39:00 +01:00
|
|
|
if (!empty($this->filter['search'])) {
|
|
|
|
$filter['nombre'] = "%" . $this->filter['search'] . "%";
|
|
|
|
}
|
|
|
|
|
|
|
|
// First filter by name and father
|
|
|
|
$groups = db_get_all_rows_filter('tgrupo',
|
|
|
|
$filter,
|
2014-12-18 11:04:41 +01:00
|
|
|
array('id_grupo', 'nombre'));html_debug_print($groups, true);
|
2014-12-16 16:39:00 +01:00
|
|
|
if (empty($groups))
|
|
|
|
$groups = array();
|
|
|
|
|
2014-12-17 18:58:34 +01:00
|
|
|
|
2014-12-16 16:39:00 +01:00
|
|
|
// Filter by status
|
|
|
|
$status = AGENT_STATUS_ALL;
|
|
|
|
if (!empty($this->filter['status'])) {
|
|
|
|
$status = $this->filter['status'];
|
|
|
|
}
|
|
|
|
|
2014-12-17 18:58:34 +01:00
|
|
|
|
|
|
|
|
2014-12-16 16:39:00 +01:00
|
|
|
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]);
|
2014-12-17 18:58:34 +01:00
|
|
|
else {
|
|
|
|
if (is_null($limit)) {
|
|
|
|
$groups[$iterator]['children'] =
|
|
|
|
$this->getRecursiveGroup($group['id_grupo']);
|
|
|
|
}
|
|
|
|
else if ($limit >= 1) {
|
|
|
|
$groups[$iterator]['children'] =
|
|
|
|
$this->getRecursiveGroup(
|
|
|
|
$group['id_grupo'],
|
|
|
|
($limit - 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach ($groups as $iterator => $group) {
|
|
|
|
if (is_null($limit)) {
|
|
|
|
$groups[$iterator]['children'] =
|
|
|
|
$this->getRecursiveGroup($group['id_grupo']);
|
|
|
|
}
|
|
|
|
else if ($limit >= 1) {
|
|
|
|
$groups[$iterator]['children'] =
|
|
|
|
$this->getRecursiveGroup(
|
|
|
|
$group['id_grupo'],
|
|
|
|
($limit - 1));
|
|
|
|
}
|
2014-12-16 16:39:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-17 18:58:34 +01:00
|
|
|
|
|
|
|
return $groups;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDataGroup() {
|
|
|
|
|
|
|
|
if (!empty($this->root)) {
|
|
|
|
$parent = $this->root;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$parent = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($this->childrenMethod) {
|
|
|
|
case 'on_demand':
|
|
|
|
$groups = $this->getRecursiveGroup($parent, 1);
|
|
|
|
foreach ($groups as $iterator => $group) {
|
|
|
|
if (!empty($group['children'])) {
|
|
|
|
$groups[$iterator]['searchChildren'] = 1;
|
|
|
|
// I hate myself
|
|
|
|
unset($groups[$iterator]['children']);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$groups[$iterator]['searchChildren'] = 0;
|
|
|
|
// I hate myself
|
|
|
|
unset($groups[$iterator]['children']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-12-16 16:39:00 +01:00
|
|
|
// Make the data
|
|
|
|
$this->tree = array();
|
|
|
|
foreach ($groups as $group) {
|
|
|
|
$data = array();
|
|
|
|
$data['id'] = $group['id_grupo'];
|
2014-12-17 18:58:34 +01:00
|
|
|
$data['type'] = 'group';
|
2014-12-16 16:39:00 +01:00
|
|
|
$data['name'] = $group['nombre'];
|
2014-12-17 18:58:34 +01:00
|
|
|
$data['searchChildren'] = $group['searchChildren'];
|
2014-12-16 16:39:00 +01:00
|
|
|
|
|
|
|
$this->tree[] = $data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-17 18:58:34 +01:00
|
|
|
public function getDataModuleGroup() {
|
2014-12-16 16:39:00 +01:00
|
|
|
}
|
|
|
|
|
2014-12-17 18:58:34 +01:00
|
|
|
public function getDataModule() {
|
2014-12-16 16:39:00 +01:00
|
|
|
}
|
|
|
|
|
2014-12-17 18:58:34 +01:00
|
|
|
public function getDataTag() {
|
2014-12-16 16:39:00 +01:00
|
|
|
}
|
|
|
|
|
2014-12-17 18:58:34 +01:00
|
|
|
public function getJSON() {
|
|
|
|
$this->getData();
|
2014-12-16 16:39:00 +01:00
|
|
|
|
|
|
|
return json_encode($this->tree);
|
|
|
|
}
|
2014-12-17 18:58:34 +01:00
|
|
|
|
|
|
|
public function getArray() {
|
|
|
|
$this->getData();
|
|
|
|
|
|
|
|
return $this->tree;
|
|
|
|
}
|
2014-12-16 16:39:00 +01:00
|
|
|
}
|
|
|
|
?>
|