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 {
|
2015-01-05 13:25:41 +01:00
|
|
|
protected $type = null;
|
2015-01-21 17:37:51 +01:00
|
|
|
protected $rootType = null;
|
|
|
|
protected $id = -1;
|
|
|
|
protected $rootID = -1;
|
2015-01-30 15:32:39 +01:00
|
|
|
protected $serverID = false;
|
2015-01-05 13:25:41 +01:00
|
|
|
protected $tree = array();
|
|
|
|
protected $filter = array();
|
|
|
|
protected $childrenMethod = "on_demand";
|
|
|
|
|
|
|
|
protected $userGroups;
|
2014-12-16 16:39:00 +01:00
|
|
|
|
2015-01-14 17:56:42 +01:00
|
|
|
protected $strictACL = false;
|
|
|
|
protected $acltags = false;
|
|
|
|
|
2015-01-30 15:32:39 +01:00
|
|
|
public function __construct($type, $rootType = '', $id = -1, $rootID = -1, $serverID = false, $childrenMethod = "on_demand") {
|
2014-12-18 14:22:10 +01:00
|
|
|
|
2014-12-16 16:39:00 +01:00
|
|
|
$this->type = $type;
|
2015-01-21 17:37:51 +01:00
|
|
|
$this->rootType = !empty($rootType) ? $rootType : $type;
|
|
|
|
$this->id = $id;
|
|
|
|
$this->rootID = !empty($rootID) ? $rootID : $id;
|
2015-01-30 15:32:39 +01:00
|
|
|
$this->serverID = $serverID;
|
2014-12-17 18:58:34 +01:00
|
|
|
$this->childrenMethod = $childrenMethod;
|
2015-01-08 16:39:35 +01:00
|
|
|
|
|
|
|
$userGroups = users_get_groups();
|
|
|
|
|
|
|
|
if (empty($userGroups))
|
|
|
|
$this->userGroups = false;
|
|
|
|
else
|
|
|
|
$this->userGroups = $userGroups;
|
2015-01-08 13:18:27 +01:00
|
|
|
|
|
|
|
global $config;
|
|
|
|
include_once($config['homedir']."/include/functions_servers.php");
|
2015-01-21 17:37:51 +01:00
|
|
|
|
2015-01-29 21:00:30 +01:00
|
|
|
if (defined("METACONSOLE"))
|
|
|
|
enterprise_include_once("meta/include/functions_ui_meta.php");
|
|
|
|
|
2015-01-22 16:56:44 +01:00
|
|
|
$this->strictACL = (bool) db_get_value("strict_acl", "tusuario", "id_user", $config['id_user']);
|
2015-01-26 17:51:06 +01:00
|
|
|
|
|
|
|
if ($this->strictACL) {
|
|
|
|
require_once($config['homedir']."/include/functions_tags.php");
|
|
|
|
$this->acltags = tags_get_user_module_and_tags($config['id_user'], 'AR');
|
|
|
|
}
|
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-30 16:24:23 +01:00
|
|
|
|
2015-01-22 16:56:44 +01:00
|
|
|
public function isStrict () {
|
|
|
|
return $this->strictACL;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setStrict ($value) {
|
|
|
|
$this->strictACL = (bool) $value;
|
|
|
|
}
|
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
protected function getAgentStatusFilter ($status = -1) {
|
|
|
|
if ($status == -1)
|
|
|
|
$status = $this->filter['statusAgent'];
|
|
|
|
|
2015-01-21 17:37:51 +01:00
|
|
|
$agent_status_filter = "";
|
2015-01-28 18:57:33 +01:00
|
|
|
switch ($status) {
|
2015-01-21 17:37:51 +01:00
|
|
|
case AGENT_STATUS_NOT_INIT:
|
|
|
|
$agent_status_filter = " AND (ta.total_count = 0
|
|
|
|
OR ta.total_count = ta.notinit_count) ";
|
|
|
|
break;
|
|
|
|
case AGENT_STATUS_CRITICAL:
|
|
|
|
$agent_status_filter = " AND ta.critical_count > 0 ";
|
|
|
|
break;
|
|
|
|
case AGENT_STATUS_WARNING:
|
|
|
|
$agent_status_filter = " AND (ta.critical_count = 0
|
|
|
|
AND ta.warning_count > 0) ";
|
|
|
|
break;
|
|
|
|
case AGENT_STATUS_UNKNOWN:
|
|
|
|
$agent_status_filter = " AND (ta.critical_count = 0
|
|
|
|
AND ta.warning_count = 0
|
|
|
|
AND ta.unknown_count > 0) ";
|
|
|
|
break;
|
|
|
|
case AGENT_STATUS_NORMAL:
|
|
|
|
$agent_status_filter = " AND (ta.critical_count = 0
|
|
|
|
AND ta.warning_count = 0
|
|
|
|
AND ta.unknown_count = 0
|
|
|
|
AND ta.normal_count > 0) ";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $agent_status_filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getAgentCounterColumnsSql ($agent_table) {
|
|
|
|
// Add the agent counters to the columns
|
2015-01-28 18:57:33 +01:00
|
|
|
|
|
|
|
$agent_status_filter = "";
|
|
|
|
|
|
|
|
if ($this->filter['statusAgent'] == -1) {
|
|
|
|
// Critical
|
|
|
|
$agent_critical_filter = $this->getAgentStatusFilter(AGENT_STATUS_CRITICAL);
|
|
|
|
$agents_critical_count = "($agent_table
|
|
|
|
$agent_critical_filter) AS total_critical_count";
|
|
|
|
// Warning
|
|
|
|
$agent_warning_filter = $this->getAgentStatusFilter(AGENT_STATUS_WARNING);
|
|
|
|
$agents_warning_count = "($agent_table
|
|
|
|
$agent_warning_filter) AS total_warning_count";
|
|
|
|
// Unknown
|
|
|
|
$agent_unknown_filter = $this->getAgentStatusFilter(AGENT_STATUS_UNKNOWN);
|
|
|
|
$agents_unknown_count = "($agent_table
|
|
|
|
$agent_unknown_filter) AS total_unknown_count";
|
|
|
|
// Normal
|
|
|
|
$agent_normal_filter = $this->getAgentStatusFilter(AGENT_STATUS_NORMAL);
|
|
|
|
$agents_normal_count = "($agent_table
|
|
|
|
$agent_normal_filter) AS total_normal_count";
|
|
|
|
// Not init
|
|
|
|
$agent_not_init_filter = $this->getAgentStatusFilter(AGENT_STATUS_NOT_INIT);
|
|
|
|
$agents_not_init_count = "($agent_table
|
|
|
|
$agent_not_init_filter) AS total_not_init_count";
|
|
|
|
// Alerts fired
|
|
|
|
$agents_fired_count = "($agent_table
|
|
|
|
AND ta.fired_count > 0) AS total_fired_count";
|
|
|
|
// Total
|
|
|
|
$agents_total_count = "($agent_table) AS total_count";
|
|
|
|
|
|
|
|
$columns = "$agents_critical_count, $agents_warning_count, "
|
|
|
|
. "$agents_unknown_count, $agents_normal_count, $agents_not_init_count, "
|
|
|
|
. "$agents_fired_count, $agents_total_count";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Alerts fired
|
|
|
|
$agents_fired_count = "($agent_table
|
|
|
|
AND ta.fired_count > 0) AS total_fired_count";
|
|
|
|
// Total
|
|
|
|
$agents_total_count = "($agent_table) AS total_count";
|
|
|
|
|
|
|
|
switch ($this->filter['statusAgent']) {
|
|
|
|
case AGENT_STATUS_NOT_INIT:
|
|
|
|
// Not init
|
|
|
|
$agent_not_init_filter = $this->getAgentStatusFilter(AGENT_STATUS_NOT_INIT);
|
|
|
|
$agents_not_init_count = "($agent_table
|
2015-01-29 21:00:30 +01:00
|
|
|
$agent_not_init_filter) AS total_not_init_count";
|
2015-01-28 18:57:33 +01:00
|
|
|
$columns = "$agents_not_init_count, $agents_fired_count, $agents_total_count";
|
|
|
|
break;
|
|
|
|
case AGENT_STATUS_CRITICAL:
|
|
|
|
// Critical
|
|
|
|
$agent_critical_filter = $this->getAgentStatusFilter(AGENT_STATUS_CRITICAL);
|
|
|
|
$agents_critical_count = "($agent_table
|
|
|
|
$agent_critical_filter) AS total_critical_count";
|
|
|
|
$columns = "$agents_critical_count, $agents_fired_count, $agents_total_count";
|
|
|
|
break;
|
|
|
|
case AGENT_STATUS_WARNING:
|
|
|
|
// Warning
|
|
|
|
$agent_warning_filter = $this->getAgentStatusFilter(AGENT_STATUS_WARNING);
|
|
|
|
$agents_warning_count = "($agent_table
|
|
|
|
$agent_warning_filter) AS total_warning_count";
|
|
|
|
$columns = "$agents_warning_count, $agents_fired_count, $agents_total_count";
|
|
|
|
break;
|
|
|
|
case AGENT_STATUS_UNKNOWN:
|
|
|
|
// Unknown
|
|
|
|
$agent_unknown_filter = $this->getAgentStatusFilter(AGENT_STATUS_UNKNOWN);
|
|
|
|
$agents_unknown_count = "($agent_table
|
|
|
|
$agent_unknown_filter) AS total_unknown_count";
|
|
|
|
$columns = "$agents_unknown_count, $agents_fired_count, $agents_total_count";
|
|
|
|
break;
|
|
|
|
case AGENT_STATUS_NORMAL:
|
|
|
|
// Normal
|
|
|
|
$agent_normal_filter = $this->getAgentStatusFilter(AGENT_STATUS_NORMAL);
|
|
|
|
$agents_normal_count = "($agent_table
|
|
|
|
$agent_normal_filter) AS total_normal_count";
|
|
|
|
$columns = "$agents_normal_count, $agents_fired_count, $agents_total_count";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $columns;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getAgentCountersSql ($agent_table) {
|
|
|
|
$columns = $this->getAgentCounterColumnsSql($agent_table);
|
|
|
|
$columns = "SELECT $columns FROM dual LIMIT 1";
|
2015-01-21 17:37:51 +01:00
|
|
|
|
|
|
|
return $columns;
|
|
|
|
}
|
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
protected function getSql ($item_for_count = false) {
|
2015-01-21 17:37:51 +01:00
|
|
|
// Get the type
|
|
|
|
if (empty($this->type))
|
|
|
|
$type = 'none';
|
|
|
|
else
|
|
|
|
$type = $this->type;
|
|
|
|
|
|
|
|
// Get the root type
|
|
|
|
if (empty($this->rootType))
|
|
|
|
$rootType = 'none';
|
|
|
|
else
|
|
|
|
$rootType = $this->rootType;
|
|
|
|
|
|
|
|
// Get the parent
|
|
|
|
$parent = $this->id;
|
|
|
|
|
|
|
|
// Get the root id
|
|
|
|
$rootID = $this->rootID;
|
|
|
|
|
2015-01-30 15:32:39 +01:00
|
|
|
// Get the server id
|
|
|
|
$serverID = $this->serverID;
|
|
|
|
|
2015-01-21 17:37:51 +01:00
|
|
|
// Agent name filter
|
|
|
|
$agent_search_filter = "";
|
|
|
|
if (!empty($this->filter['searchAgent'])) {
|
|
|
|
$agent_search_filter = " AND ta.nombre LIKE '%".$this->filter['searchAgent']."%' ";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Agent status filter
|
|
|
|
$agent_status_filter = "";
|
2015-01-22 16:56:44 +01:00
|
|
|
if (isset($this->filter['statusAgent'])
|
|
|
|
&& $this->filter['statusAgent'] != AGENT_STATUS_ALL) {
|
2015-01-21 17:37:51 +01:00
|
|
|
$agent_status_filter = $this->getAgentStatusFilter($this->filter['statusAgent']);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Agents join
|
|
|
|
$agents_join = "";
|
|
|
|
if (!empty($agent_search_filter) || !empty($agent_status_filter)) {
|
|
|
|
$agents_join = "INNER JOIN tagente AS ta
|
|
|
|
ON ta.disabled = 0
|
|
|
|
AND tam.id_agente = ta.id_agente
|
|
|
|
$agent_search_filter
|
|
|
|
$agent_status_filter";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Module name filter
|
|
|
|
$module_search_filter = "";
|
|
|
|
if (!empty($this->filter['searchModule'])) {
|
|
|
|
$module_search_filter = " AND tam.nombre LIKE '%".$this->filter['searchModule']."%' ";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Module status filter
|
|
|
|
$module_status_filter = "";
|
2015-01-22 16:56:44 +01:00
|
|
|
if (isset($this->filter['statusModule'])
|
|
|
|
&& $this->filter['statusModule'] != -1) {
|
|
|
|
|
2015-01-21 17:37:51 +01:00
|
|
|
switch ($this->filter['statusModule']) {
|
|
|
|
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
|
|
|
|
case AGENT_MODULE_STATUS_CRITICAL_BAD:
|
|
|
|
$module_status_filter = " AND (tae.estado = ".AGENT_MODULE_STATUS_CRITICAL_ALERT."
|
|
|
|
OR tae.estado = ".AGENT_MODULE_STATUS_CRITICAL_BAD.") ";
|
|
|
|
break;
|
|
|
|
case AGENT_MODULE_STATUS_WARNING_ALERT:
|
|
|
|
case AGENT_MODULE_STATUS_WARNING:
|
|
|
|
$module_status_filter = " AND (tae.estado = ".AGENT_MODULE_STATUS_WARNING_ALERT."
|
|
|
|
OR tae.estado = ".AGENT_MODULE_STATUS_WARNING.") ";
|
|
|
|
break;
|
|
|
|
case AGENT_MODULE_STATUS_UNKNOWN:
|
|
|
|
$module_status_filter = " AND tae.estado = ".AGENT_MODULE_STATUS_UNKNOWN." ";
|
|
|
|
break;
|
|
|
|
case AGENT_MODULE_STATUS_NO_DATA:
|
|
|
|
case AGENT_MODULE_STATUS_NOT_INIT:
|
|
|
|
$module_status_filter = " AND (tae.estado = ".AGENT_MODULE_STATUS_NO_DATA."
|
|
|
|
OR tae.estado = ".AGENT_MODULE_STATUS_NOT_INIT.") ";
|
|
|
|
break;
|
|
|
|
case AGENT_MODULE_STATUS_NORMAL_ALERT:
|
|
|
|
case AGENT_MODULE_STATUS_NORMAL:
|
|
|
|
$module_status_filter = " AND (tae.estado = ".AGENT_MODULE_STATUS_NORMAL_ALERT."
|
|
|
|
OR tae.estado = ".AGENT_MODULE_STATUS_NORMAL.") ";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Modules join
|
|
|
|
$modules_join = "";
|
|
|
|
$module_status_join = "";
|
|
|
|
if (!empty($module_search_filter) || !empty($module_status_filter)) {
|
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
if (!empty($module_status_filter)) {
|
2015-01-21 17:37:51 +01:00
|
|
|
$module_status_join = "INNER JOIN tagente_estado AS tae
|
|
|
|
ON tam.id_agente_modulo IS NOT NULL
|
|
|
|
AND tam.id_agente_modulo = tae.id_agente_modulo
|
|
|
|
$module_status_filter";
|
|
|
|
}
|
|
|
|
|
|
|
|
$modules_join = "INNER JOIN tagente_modulo AS tam
|
|
|
|
ON tam.disabled = 0
|
|
|
|
AND ta.id_agente = tam.id_agente
|
|
|
|
$module_search_filter
|
|
|
|
$module_status_join";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($module_status_join)) {
|
|
|
|
$module_status_join = "LEFT JOIN tagente_estado AS tae
|
|
|
|
ON tam.id_agente_modulo = tae.id_agente_modulo";
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = false;
|
|
|
|
|
|
|
|
switch ($rootType) {
|
|
|
|
case 'group':
|
2015-01-22 16:56:44 +01:00
|
|
|
// ACL Group
|
|
|
|
$group_acl = "";
|
2015-01-26 17:51:06 +01:00
|
|
|
if (!$this->strictACL) {
|
|
|
|
if (!empty($this->userGroups)) {
|
|
|
|
$user_groups_str = implode(",", array_keys($this->userGroups));
|
|
|
|
$group_acl = "AND ta.id_grupo IN ($user_groups_str)";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$group_acl = "AND ta.id_grupo = -1";
|
|
|
|
}
|
2015-01-22 16:56:44 +01:00
|
|
|
}
|
|
|
|
else {
|
2015-01-26 17:51:06 +01:00
|
|
|
if (!empty($this->acltags)) {
|
|
|
|
$groups = array();
|
|
|
|
foreach ($this->acltags as $group_id => $tags_str) {
|
2015-03-05 19:43:19 +01:00
|
|
|
if (empty($tags_str)) {
|
|
|
|
$hierarchy_groups = groups_get_id_recursive($group_id);
|
|
|
|
$groups = array_merge($groups, $hierarchy_groups);
|
|
|
|
}
|
2015-01-26 17:51:06 +01:00
|
|
|
}
|
|
|
|
if (!empty($groups)) {
|
2015-02-19 19:09:36 +01:00
|
|
|
if (array_search(0, $groups) === false) {
|
|
|
|
$user_groups_str = implode(",", $groups);
|
|
|
|
$group_acl = " AND ta.id_grupo IN ($user_groups_str) ";
|
|
|
|
}
|
2015-01-26 17:51:06 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$group_acl = "AND ta.id_grupo = -1";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$group_acl = "AND ta.id_grupo = -1";
|
|
|
|
}
|
2015-01-22 16:56:44 +01:00
|
|
|
}
|
|
|
|
|
2015-01-21 17:37:51 +01:00
|
|
|
switch ($type) {
|
|
|
|
// Get the agents of a group
|
|
|
|
case 'group':
|
2015-01-26 17:51:06 +01:00
|
|
|
if (empty($rootID) || $rootID == -1) {
|
|
|
|
if ($this->strictACL)
|
|
|
|
return false;
|
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$columns = 'tg.id_grupo AS id, tg.nombre AS name, tg.parent, tg.icon, COUNT(DISTINCT(ta.id_agente)) AS total_count';
|
2015-01-26 17:51:06 +01:00
|
|
|
$order_fields = 'tg.nombre ASC, tg.id_grupo ASC';
|
|
|
|
|
|
|
|
// Add the agent counters to the columns
|
2015-01-28 18:57:33 +01:00
|
|
|
$agent_table = "SELECT COUNT(DISTINCT(ta.id_agente))
|
|
|
|
FROM tagente AS ta
|
|
|
|
LEFT JOIN tagente_modulo AS tam
|
|
|
|
ON tam.disabled = 0
|
|
|
|
AND ta.id_agente = tam.id_agente
|
|
|
|
$module_search_filter
|
|
|
|
$module_status_join
|
|
|
|
WHERE ta.disabled = 0
|
|
|
|
AND ta.id_grupo = tg.id_grupo
|
2015-01-22 16:56:44 +01:00
|
|
|
$group_acl
|
|
|
|
$agent_search_filter
|
2015-01-28 18:57:33 +01:00
|
|
|
$agent_status_filter";
|
|
|
|
$counter_columns = $this->getAgentCounterColumnsSql($agent_table);
|
2015-01-26 17:51:06 +01:00
|
|
|
if (!empty($counter_columns))
|
|
|
|
$columns .= ", $counter_columns";
|
|
|
|
|
|
|
|
$sql = "SELECT $columns
|
|
|
|
FROM tgrupo AS tg
|
|
|
|
LEFT JOIN tagente AS ta
|
|
|
|
LEFT JOIN tagente_modulo AS tam
|
|
|
|
ON tam.disabled = 0
|
|
|
|
AND ta.id_agente = tam.id_agente
|
|
|
|
$module_search_filter
|
|
|
|
$module_status_join
|
|
|
|
ON ta.disabled = 0
|
|
|
|
AND tg.id_grupo = ta.id_grupo
|
2015-01-22 16:56:44 +01:00
|
|
|
$group_acl
|
|
|
|
$agent_search_filter
|
|
|
|
$agent_status_filter
|
2015-01-26 17:51:06 +01:00
|
|
|
GROUP BY tg.id_grupo
|
|
|
|
ORDER BY $order_fields";
|
|
|
|
}
|
|
|
|
else {
|
2015-01-29 21:00:30 +01:00
|
|
|
$columns = 'ta.id_agente AS id, ta.nombre AS name,
|
|
|
|
ta.fired_count, ta.normal_count, ta.warning_count,
|
|
|
|
ta.critical_count, ta.unknown_count, ta.notinit_count,
|
|
|
|
ta.total_count, ta.quiet';
|
2015-01-26 17:51:06 +01:00
|
|
|
$order_fields = 'ta.nombre ASC, ta.id_agente ASC';
|
|
|
|
|
|
|
|
$sql = "SELECT $columns
|
|
|
|
FROM tagente AS ta
|
|
|
|
LEFT JOIN tagente_modulo AS tam
|
|
|
|
ON tam.disabled = 0
|
|
|
|
AND ta.id_agente = tam.id_agente
|
|
|
|
$module_search_filter
|
|
|
|
$module_status_join
|
|
|
|
WHERE ta.disabled = 0
|
|
|
|
AND ta.id_grupo = $rootID
|
|
|
|
$group_acl
|
|
|
|
$agent_search_filter
|
|
|
|
$agent_status_filter
|
|
|
|
GROUP BY ta.id_agente
|
|
|
|
ORDER BY $order_fields";
|
|
|
|
}
|
2015-01-21 17:37:51 +01:00
|
|
|
break;
|
|
|
|
// Get the modules of an agent
|
|
|
|
case 'agent':
|
2015-01-22 16:56:44 +01:00
|
|
|
$columns = 'tam.id_agente_modulo AS id, tam.nombre AS name,
|
2015-01-21 17:37:51 +01:00
|
|
|
tam.id_tipo_modulo, tam.id_modulo, tae.estado, tae.datos';
|
|
|
|
$order_fields = 'tam.nombre ASC, tam.id_agente_modulo ASC';
|
|
|
|
|
|
|
|
$sql = "SELECT $columns
|
|
|
|
FROM tagente_modulo AS tam
|
|
|
|
$module_status_join
|
2015-01-22 16:56:44 +01:00
|
|
|
INNER JOIN tagente AS ta
|
|
|
|
ON ta.disabled = 0
|
|
|
|
AND tam.id_agente = ta.id_agente
|
|
|
|
AND ta.id_grupo = $rootID
|
|
|
|
$group_acl
|
|
|
|
$agent_search_filter
|
|
|
|
$agent_status_filter
|
2015-01-21 17:37:51 +01:00
|
|
|
WHERE tam.disabled = 0
|
2015-01-22 16:56:44 +01:00
|
|
|
AND tam.id_agente = $parent
|
2015-01-21 17:37:51 +01:00
|
|
|
$module_search_filter
|
2015-01-22 16:56:44 +01:00
|
|
|
GROUP BY tam.id_agente_modulo
|
2015-01-21 17:37:51 +01:00
|
|
|
ORDER BY $order_fields";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'tag':
|
2015-01-22 16:56:44 +01:00
|
|
|
// ACL Group
|
|
|
|
$group_acl = "";
|
2015-01-26 17:51:06 +01:00
|
|
|
if (!$this->strictACL) {
|
|
|
|
if (!empty($this->userGroups)) {
|
|
|
|
$user_groups_str = implode(",", array_keys($this->userGroups));
|
|
|
|
$group_acl = " AND ta.id_grupo IN ($user_groups_str) ";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$group_acl = "AND ta.id_grupo = -1";
|
|
|
|
}
|
2015-01-22 16:56:44 +01:00
|
|
|
}
|
|
|
|
else {
|
2015-01-26 17:51:06 +01:00
|
|
|
if (!empty($this->acltags) && !empty($rootID) && $rootID != -1) {
|
|
|
|
$groups = array();
|
|
|
|
foreach ($this->acltags as $group_id => $tags_str) {
|
|
|
|
if (!empty($tags_str)) {
|
|
|
|
$tags = explode(",", $tags_str);
|
|
|
|
|
2015-03-05 19:43:19 +01:00
|
|
|
if (in_array($rootID, $tags)) {
|
|
|
|
$hierarchy_groups = groups_get_id_recursive($group_id);
|
|
|
|
$groups = array_merge($groups, $hierarchy_groups);
|
|
|
|
}
|
2015-01-26 17:51:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!empty($groups)) {
|
2015-02-19 19:09:36 +01:00
|
|
|
if (array_search(0, $groups) === false) {
|
|
|
|
$user_groups_str = implode(",", $groups);
|
|
|
|
$group_acl = " AND ta.id_grupo IN ($user_groups_str) ";
|
|
|
|
}
|
2015-01-26 17:51:06 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$group_acl = "AND ta.id_grupo = -1";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$group_acl = "AND ta.id_grupo = -1";
|
|
|
|
}
|
2015-01-21 17:37:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
switch ($type) {
|
|
|
|
// Get the agents of a tag
|
|
|
|
case 'tag':
|
2015-01-22 16:56:44 +01:00
|
|
|
if (empty($rootID) || $rootID == -1) {
|
2015-01-26 17:51:06 +01:00
|
|
|
if ($this->strictACL)
|
|
|
|
return false;
|
|
|
|
|
2015-01-22 16:56:44 +01:00
|
|
|
$columns = 'tt.id_tag AS id, tt.name AS name';
|
|
|
|
$order_fields = 'tt.name ASC, tt.id_tag ASC';
|
2015-01-21 17:37:51 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
// Tags SQL
|
|
|
|
if ($item_for_count === false) {
|
|
|
|
$sql = "SELECT $columns
|
|
|
|
FROM ttag AS tt
|
|
|
|
INNER JOIN ttag_module AS ttm
|
|
|
|
ON tt.id_tag = ttm.id_tag
|
|
|
|
INNER JOIN tagente_modulo AS tam
|
|
|
|
ON tam.disabled = 0
|
|
|
|
AND ttm.id_agente_modulo = tam.id_agente_modulo
|
|
|
|
$module_search_filter
|
|
|
|
$module_status_join
|
|
|
|
INNER JOIN tagente AS ta
|
|
|
|
ON ta.disabled = 0
|
|
|
|
AND tam.id_agente = ta.id_agente
|
|
|
|
$group_acl
|
|
|
|
$agent_search_filter
|
|
|
|
$agent_status_filter
|
|
|
|
GROUP BY tt.id_tag
|
|
|
|
ORDER BY $order_fields";
|
|
|
|
}
|
|
|
|
// Counters SQL
|
|
|
|
else {
|
|
|
|
$agent_table = "SELECT COUNT(DISTINCT(ta.id_agente))
|
|
|
|
FROM tagente AS ta
|
|
|
|
INNER JOIN tagente_modulo AS tam
|
|
|
|
ON tam.disabled = 0
|
|
|
|
AND ta.id_agente = tam.id_agente
|
|
|
|
$module_search_filter
|
|
|
|
$module_status_join
|
|
|
|
INNER JOIN ttag_module AS ttm
|
|
|
|
ON tam.id_agente_modulo = ttm.id_agente_modulo
|
|
|
|
AND ttm.id_tag = $item_for_count
|
|
|
|
WHERE ta.disabled = 0
|
|
|
|
$group_acl
|
|
|
|
$agent_search_filter
|
|
|
|
$agent_status_filter";
|
|
|
|
$sql = $this->getAgentCountersSql($agent_table);
|
|
|
|
}
|
2015-01-22 16:56:44 +01:00
|
|
|
}
|
|
|
|
else {
|
2015-01-29 21:00:30 +01:00
|
|
|
$columns = 'ta.id_agente AS id, ta.nombre AS name,
|
|
|
|
ta.fired_count, ta.normal_count, ta.warning_count,
|
|
|
|
ta.critical_count, ta.unknown_count, ta.notinit_count,
|
|
|
|
ta.total_count, ta.quiet';
|
2015-01-22 16:56:44 +01:00
|
|
|
$order_fields = 'ta.nombre ASC, ta.id_agente ASC';
|
|
|
|
|
|
|
|
$sql = "SELECT $columns
|
|
|
|
FROM tagente AS ta
|
|
|
|
INNER JOIN tagente_modulo AS tam
|
|
|
|
ON tam.disabled = 0
|
|
|
|
AND ta.id_agente = tam.id_agente
|
|
|
|
$module_search_filter
|
|
|
|
$module_status_join
|
|
|
|
INNER JOIN ttag_module AS ttm
|
|
|
|
ON tam.id_agente_modulo = ttm.id_agente_modulo
|
|
|
|
AND ttm.id_tag = $rootID
|
|
|
|
WHERE ta.disabled = 0
|
|
|
|
$group_acl
|
|
|
|
$agent_search_filter
|
|
|
|
$agent_status_filter
|
|
|
|
GROUP BY ta.id_agente
|
|
|
|
ORDER BY $order_fields";
|
|
|
|
}
|
2015-01-21 17:37:51 +01:00
|
|
|
break;
|
|
|
|
// Get the modules of an agent
|
|
|
|
case 'agent':
|
2015-01-22 16:56:44 +01:00
|
|
|
$columns = 'tam.id_agente_modulo AS id, tam.nombre AS name,
|
2015-01-21 17:37:51 +01:00
|
|
|
tam.id_tipo_modulo, tam.id_modulo, tae.estado, tae.datos';
|
|
|
|
$order_fields = 'tam.nombre ASC, tam.id_agente_modulo ASC';
|
|
|
|
|
|
|
|
$sql = "SELECT $columns
|
|
|
|
FROM tagente_modulo AS tam
|
2015-01-22 16:56:44 +01:00
|
|
|
INNER JOIN ttag_module AS ttm
|
|
|
|
ON tam.id_agente_modulo = ttm.id_agente_modulo
|
|
|
|
AND ttm.id_tag = $rootID
|
2015-01-21 17:37:51 +01:00
|
|
|
$module_status_join
|
2015-01-22 16:56:44 +01:00
|
|
|
INNER JOIN tagente AS ta
|
|
|
|
ON ta.disabled = 0
|
|
|
|
AND tam.id_agente = ta.id_agente
|
|
|
|
$group_acl
|
|
|
|
$agent_search_filter
|
|
|
|
$agent_status_filter
|
2015-01-21 17:37:51 +01:00
|
|
|
WHERE tam.disabled = 0
|
2015-01-22 16:56:44 +01:00
|
|
|
AND tam.id_agente = $parent
|
2015-01-21 17:37:51 +01:00
|
|
|
$module_search_filter
|
2015-01-22 16:56:44 +01:00
|
|
|
GROUP BY tam.id_agente_modulo
|
2015-01-21 17:37:51 +01:00
|
|
|
ORDER BY $order_fields";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'os':
|
|
|
|
// 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) ";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$group_acl = "AND ta.id_grupo = -1";
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($type) {
|
|
|
|
// Get the agents of an os
|
|
|
|
case 'os':
|
|
|
|
if (empty($rootID) || $rootID == -1) {
|
2015-01-22 16:56:44 +01:00
|
|
|
$columns = 'tos.id_os AS id, tos.name AS name, tos.icon_name AS os_icon';
|
2015-01-21 17:37:51 +01:00
|
|
|
$order_fields = 'tos.icon_name ASC, tos.id_os ASC';
|
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
// OS SQL
|
|
|
|
if ($item_for_count === false) {
|
|
|
|
$sql = "SELECT $columns
|
|
|
|
FROM tconfig_os AS tos
|
|
|
|
INNER JOIN tagente AS ta
|
|
|
|
ON ta.disabled = 0
|
|
|
|
AND ta.id_os = tos.id_os
|
2015-01-21 17:37:51 +01:00
|
|
|
$agent_search_filter
|
|
|
|
$agent_status_filter
|
2015-01-28 18:57:33 +01:00
|
|
|
$group_acl
|
|
|
|
$modules_join
|
|
|
|
GROUP BY tos.id_os
|
|
|
|
ORDER BY $order_fields";
|
|
|
|
}
|
|
|
|
// Counters SQL
|
|
|
|
else {
|
|
|
|
$agent_table = "SELECT COUNT(DISTINCT(ta.id_agente))
|
|
|
|
FROM tagente AS ta
|
|
|
|
$modules_join
|
|
|
|
WHERE ta.disabled = 0
|
|
|
|
AND ta.id_os = $item_for_count
|
|
|
|
$group_acl
|
|
|
|
$agent_search_filter
|
|
|
|
$agent_status_filter";
|
|
|
|
$sql = $this->getAgentCountersSql($agent_table);
|
|
|
|
}
|
2015-01-21 17:37:51 +01:00
|
|
|
}
|
|
|
|
else {
|
2015-01-29 21:00:30 +01:00
|
|
|
$columns = 'ta.id_agente AS id, ta.nombre AS name,
|
|
|
|
ta.fired_count, ta.normal_count, ta.warning_count,
|
|
|
|
ta.critical_count, ta.unknown_count, ta.notinit_count,
|
|
|
|
ta.total_count, ta.quiet';
|
2015-01-21 17:37:51 +01:00
|
|
|
$order_fields = 'ta.nombre ASC, ta.id_agente ASC';
|
|
|
|
|
|
|
|
$sql = "SELECT $columns
|
|
|
|
FROM tagente AS ta
|
|
|
|
$modules_join
|
|
|
|
WHERE ta.disabled = 0
|
2015-01-28 18:57:33 +01:00
|
|
|
AND ta.id_os = $rootID
|
2015-01-21 17:37:51 +01:00
|
|
|
$group_acl
|
|
|
|
$agent_search_filter
|
|
|
|
$agent_status_filter
|
2015-01-22 16:56:44 +01:00
|
|
|
GROUP BY ta.id_agente
|
2015-01-21 17:37:51 +01:00
|
|
|
ORDER BY $order_fields";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
// Get the modules of an agent
|
|
|
|
case 'agent':
|
2015-01-22 16:56:44 +01:00
|
|
|
$columns = 'tam.id_agente_modulo AS id, tam.nombre AS name,
|
2015-01-21 17:37:51 +01:00
|
|
|
tam.id_tipo_modulo, tam.id_modulo, tae.estado, tae.datos';
|
|
|
|
$order_fields = 'tam.nombre ASC, tam.id_agente_modulo ASC';
|
|
|
|
|
|
|
|
$os_filter = "AND ta.id_os = $rootID";
|
|
|
|
$agent_filter = "AND ta.id_agente = $parent";
|
|
|
|
|
|
|
|
$sql = "SELECT $columns
|
|
|
|
FROM tagente_modulo AS tam
|
|
|
|
$module_status_join
|
|
|
|
INNER JOIN tagente AS ta
|
|
|
|
ON ta.disabled = 0
|
|
|
|
AND tam.id_agente = ta.id_agente
|
|
|
|
$os_filter
|
|
|
|
$group_acl
|
|
|
|
$agent_search_filter
|
|
|
|
$agent_status_filter
|
|
|
|
WHERE tam.disabled = 0
|
|
|
|
$agent_filter
|
|
|
|
$module_search_filter
|
2015-01-22 16:56:44 +01:00
|
|
|
GROUP BY tam.id_agente_modulo
|
2015-01-21 17:37:51 +01:00
|
|
|
ORDER BY $order_fields";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'module_group':
|
|
|
|
// 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) ";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$group_acl = "AND ta.id_grupo = -1";
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($type) {
|
|
|
|
// Get the agents of a module group
|
|
|
|
case 'module_group':
|
|
|
|
if (empty($rootID) || $rootID == -1) {
|
2015-01-22 16:56:44 +01:00
|
|
|
$columns = 'tmg.id_mg AS id, tmg.name AS name';
|
2015-01-21 17:37:51 +01:00
|
|
|
$order_fields = 'tmg.name ASC, tmg.id_mg ASC';
|
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
// Module groups SQL
|
|
|
|
if ($item_for_count === false) {
|
|
|
|
$sql = "SELECT $columns
|
|
|
|
FROM tmodule_group AS tmg
|
|
|
|
INNER JOIN tagente_modulo AS tam
|
|
|
|
ON tam.disabled = 0
|
|
|
|
AND tam.id_module_group = tmg.id_mg
|
|
|
|
$module_search_filter
|
|
|
|
$module_status_join
|
|
|
|
INNER JOIN tagente AS ta
|
|
|
|
ON ta.disabled = 0
|
|
|
|
AND tam.id_agente = ta.id_agente
|
2015-01-21 17:37:51 +01:00
|
|
|
$group_acl
|
|
|
|
$agent_search_filter
|
2015-01-28 18:57:33 +01:00
|
|
|
$agent_status_filter
|
|
|
|
GROUP BY tmg.id_mg
|
|
|
|
ORDER BY $order_fields";
|
|
|
|
}
|
|
|
|
// Counters SQL
|
|
|
|
else {
|
|
|
|
$agent_table = "SELECT COUNT(DISTINCT(ta.id_agente))
|
|
|
|
FROM tagente AS ta
|
|
|
|
INNER JOIN tagente_modulo AS tam
|
|
|
|
ON tam.disabled = 0
|
|
|
|
AND ta.id_agente = tam.id_agente
|
|
|
|
AND tam.id_module_group = $item_for_count
|
|
|
|
$module_search_filter
|
|
|
|
$module_status_join
|
|
|
|
WHERE ta.disabled = 0
|
|
|
|
$group_acl
|
|
|
|
$agent_search_filter
|
|
|
|
$agent_status_filter";
|
|
|
|
$sql = $this->getAgentCountersSql($agent_table);
|
|
|
|
}
|
2015-01-21 17:37:51 +01:00
|
|
|
}
|
|
|
|
else {
|
2015-01-29 21:00:30 +01:00
|
|
|
$columns = 'ta.id_agente AS id, ta.nombre AS name,
|
|
|
|
ta.fired_count, ta.normal_count, ta.warning_count,
|
|
|
|
ta.critical_count, ta.unknown_count, ta.notinit_count,
|
|
|
|
ta.total_count, ta.quiet';
|
2015-01-21 17:37:51 +01:00
|
|
|
$order_fields = 'ta.nombre ASC, ta.id_agente ASC';
|
|
|
|
|
|
|
|
$sql = "SELECT $columns
|
|
|
|
FROM tagente AS ta
|
|
|
|
INNER JOIN tagente_modulo AS tam
|
|
|
|
ON tam.disabled = 0
|
|
|
|
AND ta.id_agente = tam.id_agente
|
2015-01-28 18:57:33 +01:00
|
|
|
AND tam.id_module_group = $rootID
|
2015-01-21 17:37:51 +01:00
|
|
|
$module_search_filter
|
|
|
|
$module_status_join
|
|
|
|
WHERE ta.disabled = 0
|
|
|
|
$group_acl
|
|
|
|
$agent_search_filter
|
|
|
|
$agent_status_filter
|
2015-01-22 16:56:44 +01:00
|
|
|
GROUP BY ta.id_agente
|
2015-01-21 17:37:51 +01:00
|
|
|
ORDER BY $order_fields";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
// Get the modules of an agent
|
|
|
|
case 'agent':
|
2015-01-22 16:56:44 +01:00
|
|
|
$columns = 'tam.id_agente_modulo AS id, tam.nombre AS name,
|
2015-01-21 17:37:51 +01:00
|
|
|
tam.id_tipo_modulo, tam.id_modulo, tae.estado, tae.datos';
|
|
|
|
$order_fields = 'tam.nombre ASC, tam.id_agente_modulo ASC';
|
|
|
|
|
|
|
|
$module_group_filter = "AND tam.id_module_group = $rootID";
|
|
|
|
$agent_filter = "AND tam.id_agente = $parent";
|
|
|
|
|
|
|
|
$sql = "SELECT $columns
|
|
|
|
FROM tagente_modulo AS tam
|
|
|
|
$module_status_join
|
|
|
|
INNER JOIN tagente AS ta
|
|
|
|
ON ta.disabled = 0
|
|
|
|
AND tam.id_agente = ta.id_agente
|
|
|
|
$group_acl
|
|
|
|
$agent_search_filter
|
|
|
|
$agent_status_filter
|
|
|
|
WHERE tam.disabled = 0
|
|
|
|
$agent_filter
|
|
|
|
$module_group_filter
|
|
|
|
$module_search_filter
|
2015-01-22 16:56:44 +01:00
|
|
|
GROUP BY tam.id_agente_modulo
|
2015-01-21 17:37:51 +01:00
|
|
|
ORDER BY $order_fields";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'module':
|
|
|
|
// 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) ";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$group_acl = "AND ta.id_grupo = -1";
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($type) {
|
|
|
|
// Get the agents of a module
|
|
|
|
case 'module':
|
|
|
|
if (empty($rootID) || $rootID == -1) {
|
2015-01-22 16:56:44 +01:00
|
|
|
$columns = 'tam.nombre AS name';
|
2015-01-21 17:37:51 +01:00
|
|
|
$order_fields = 'tam.nombre ASC';
|
2015-01-28 18:57:33 +01:00
|
|
|
|
|
|
|
// Modules SQL
|
|
|
|
if ($item_for_count === false) {
|
|
|
|
$sql = "SELECT $columns
|
|
|
|
FROM tagente_modulo AS tam
|
|
|
|
INNER JOIN tagente AS ta
|
|
|
|
ON ta.disabled = 0
|
|
|
|
AND tam.id_agente = ta.id_agente
|
2015-01-21 17:37:51 +01:00
|
|
|
$group_acl
|
|
|
|
$agent_search_filter
|
2015-01-28 18:57:33 +01:00
|
|
|
$agent_status_filter
|
|
|
|
$module_status_join
|
|
|
|
WHERE tam.disabled = 0
|
|
|
|
$module_search_filter
|
|
|
|
GROUP BY tam.nombre
|
|
|
|
ORDER BY $order_fields";
|
|
|
|
}
|
|
|
|
// Counters SQL
|
|
|
|
else {
|
|
|
|
$agent_table = "SELECT COUNT(DISTINCT(ta.id_agente))
|
|
|
|
FROM tagente AS ta
|
|
|
|
INNER JOIN tagente_modulo AS tam
|
|
|
|
ON tam.disabled = 0
|
|
|
|
AND ta.id_agente = tam.id_agente
|
|
|
|
AND tam.nombre = '$item_for_count'
|
|
|
|
$module_group_filter
|
|
|
|
$module_search_filter
|
|
|
|
$module_status_join
|
|
|
|
WHERE ta.disabled = 0
|
|
|
|
$group_acl
|
|
|
|
$agent_search_filter
|
|
|
|
$agent_status_filter";
|
|
|
|
$sql = $this->getAgentCountersSql($agent_table);
|
|
|
|
}
|
2015-01-21 17:37:51 +01:00
|
|
|
}
|
|
|
|
else {
|
2015-01-29 21:00:30 +01:00
|
|
|
$columns = 'ta.id_agente AS id, ta.nombre AS name,
|
|
|
|
ta.fired_count, ta.normal_count, ta.warning_count,
|
|
|
|
ta.critical_count, ta.unknown_count, ta.notinit_count,
|
|
|
|
ta.total_count, ta.quiet';
|
2015-01-21 17:37:51 +01:00
|
|
|
$order_fields = 'ta.nombre ASC, ta.id_agente ASC';
|
|
|
|
|
|
|
|
$symbols = ' !"#$%&\'()*+,./:;<=>?@[\\]^{|}~';
|
|
|
|
$name = $rootID;
|
|
|
|
for ($i = 0; $i < strlen($symbols); $i++) {
|
|
|
|
$name = str_replace('_articapandora_' .
|
|
|
|
ord(substr($symbols, $i, 1)) .'_pandoraartica_',
|
|
|
|
substr($symbols, $i, 1), $name);
|
|
|
|
}
|
|
|
|
$name = io_safe_input($name);
|
|
|
|
|
|
|
|
$sql = "SELECT $columns
|
|
|
|
FROM tagente AS ta
|
|
|
|
INNER JOIN tagente_modulo AS tam
|
|
|
|
ON tam.disabled = 0
|
|
|
|
AND ta.id_agente = tam.id_agente
|
2015-01-28 18:57:33 +01:00
|
|
|
AND tam.nombre = '$name'
|
2015-01-21 17:37:51 +01:00
|
|
|
$module_group_filter
|
|
|
|
$module_search_filter
|
|
|
|
$module_status_join
|
|
|
|
WHERE ta.disabled = 0
|
|
|
|
$group_acl
|
|
|
|
$agent_search_filter
|
|
|
|
$agent_status_filter
|
2015-01-22 16:56:44 +01:00
|
|
|
GROUP BY ta.id_agente
|
2015-01-21 17:37:51 +01:00
|
|
|
ORDER BY $order_fields";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
// Get the modules of an agent
|
|
|
|
case 'agent':
|
2015-01-22 16:56:44 +01:00
|
|
|
$columns = 'tam.id_agente_modulo AS id, tam.nombre AS name,
|
2015-01-21 17:37:51 +01:00
|
|
|
tam.id_tipo_modulo, tam.id_modulo, tae.estado, tae.datos';
|
|
|
|
$order_fields = 'tam.nombre ASC, tam.id_agente_modulo ASC';
|
|
|
|
|
|
|
|
$symbols = ' !"#$%&\'()*+,./:;<=>?@[\\]^{|}~';
|
|
|
|
$name = $rootID;
|
|
|
|
for ($i = 0; $i < strlen($symbols); $i++) {
|
|
|
|
$name = str_replace('_articapandora_' .
|
|
|
|
ord(substr($symbols, $i, 1)) .'_pandoraartica_',
|
|
|
|
substr($symbols, $i, 1), $name);
|
|
|
|
}
|
|
|
|
$name = io_safe_input($name);
|
|
|
|
|
|
|
|
$module_name_filter = "AND tam.nombre = '$name'";
|
|
|
|
$agent_filter = "AND tam.id_agente = $parent";
|
|
|
|
|
|
|
|
// We need the agents table
|
|
|
|
if (empty($agents_join)) {
|
|
|
|
$agents_join = "INNER JOIN tagente AS ta
|
|
|
|
ON ta.disabled = 0
|
|
|
|
AND tam.id_agente = ta.id_agente
|
|
|
|
$group_acl";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$agents_join .= " $group_acl";
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "SELECT $columns
|
|
|
|
FROM tagente_modulo AS tam
|
|
|
|
$module_status_join
|
|
|
|
INNER JOIN tagente AS ta
|
|
|
|
ON ta.disabled = 0
|
|
|
|
AND tam.id_agente = ta.id_agente
|
|
|
|
$group_acl
|
|
|
|
WHERE tam.disabled = 0
|
|
|
|
$agent_filter
|
|
|
|
$module_name_filter
|
|
|
|
$module_group_filter
|
|
|
|
$module_search_filter
|
2015-01-22 16:56:44 +01:00
|
|
|
GROUP BY tam.id_agente_modulo
|
2015-01-21 17:37:51 +01:00
|
|
|
ORDER BY $order_fields";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2015-01-30 15:32:39 +01:00
|
|
|
$sql = $this->getSqlExtended($item_for_count, $type, $rootType, $parent, $rootID,
|
2015-01-30 20:06:49 +01:00
|
|
|
$agent_search_filter, $agent_status_filter, $agents_join,
|
|
|
|
$module_search_filter, $module_status_filter, $modules_join,
|
|
|
|
$module_status_join);
|
2015-01-21 17:37:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $sql;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Override this method
|
2015-01-30 15:32:39 +01:00
|
|
|
protected function getSqlExtended ($item_for_count, $type, $rootType, $parent, $rootID,
|
2015-01-30 20:06:49 +01:00
|
|
|
$agent_search_filter, $agent_status_filter, $agents_join,
|
|
|
|
$module_search_filter, $module_status_filter, $modules_join,
|
|
|
|
$module_status_join) {
|
2015-01-21 17:37:51 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
protected function getItems ($item_for_count = false) {
|
|
|
|
$sql = $this->getSql($item_for_count);
|
2015-01-21 17:37:51 +01:00
|
|
|
if (empty($sql))
|
|
|
|
return array();
|
|
|
|
|
2015-01-22 19:13:30 +01:00
|
|
|
$data = db_process_sql($sql);
|
2015-01-21 17:37:51 +01:00
|
|
|
if (empty($data))
|
|
|
|
return array();
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
protected function getCounters ($id) {
|
|
|
|
$counters = $this->getItems($id);
|
|
|
|
|
|
|
|
if (!empty($counters)) {
|
|
|
|
$counters = array_pop($counters);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $counters;
|
|
|
|
}
|
|
|
|
|
|
|
|
static function cmpSortNames($a, $b) {
|
|
|
|
return strcmp($a["name"], $b["name"]);
|
|
|
|
}
|
2015-03-05 19:43:19 +01:00
|
|
|
|
|
|
|
protected function getGroupsChildren(&$groups, &$groups_tmp, $parent_id, $server = false, $remove_empty = false) {
|
2015-01-28 18:57:33 +01:00
|
|
|
$children = array();
|
|
|
|
foreach ($groups as $key => $group) {
|
2015-03-05 19:43:19 +01:00
|
|
|
if (isset($group['parent']) && $group['parent'] == $parent_id) {
|
|
|
|
unset($groups[$key]);
|
|
|
|
|
|
|
|
$children_aux = $this->getProcessedItem($group, $server, $groups, $groups_tmp, $remove_empty);
|
2015-01-28 18:57:33 +01:00
|
|
|
if (!empty($children_aux))
|
|
|
|
$children[] = $children_aux;
|
|
|
|
}
|
|
|
|
}
|
2015-03-05 19:43:19 +01:00
|
|
|
foreach ($groups_tmp as $key_tmp => $group_tmp) {
|
|
|
|
if (isset($group_tmp['parent']) && $group_tmp['parent'] == $parent_id) {
|
|
|
|
unset($groups_tmp[$key_tmp]);
|
|
|
|
|
|
|
|
$children[] = $group_tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
usort($children, array("Tree", "cmpSortNames"));
|
|
|
|
$children = array_filter($children);
|
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
return $children;
|
|
|
|
}
|
|
|
|
|
2015-03-05 19:43:19 +01:00
|
|
|
protected function getProcessedItem ($item, $server = false, &$items = array(), &$items_tmp = array(), $remove_empty = false) {
|
|
|
|
// For strict items
|
|
|
|
if (isset($item['_id_'])) {
|
|
|
|
$item['id'] = $item['_id_'];
|
|
|
|
$item['name'] = $item['_name_'];
|
|
|
|
|
|
|
|
if (isset($item['_is_tag_']) && $item['_is_tag_']) {
|
|
|
|
$item['type'] = 'tag';
|
|
|
|
$item['rootType'] = 'tag';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$item['type'] = 'group';
|
|
|
|
$item['rootType'] = 'group';
|
|
|
|
$item['parent'] = $item['_parent_id_'];
|
|
|
|
|
|
|
|
if (!empty($item['_iconImg_']))
|
|
|
|
$item['iconHTML'] = $item['_iconImg_'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($item['_agents_unknown_']))
|
|
|
|
$item['total_unknown_count'] = $item['_agents_unknown_'];
|
|
|
|
if (isset($item['_agents_critical_']))
|
|
|
|
$item['total_critical_count'] = $item['_agents_critical_'];
|
|
|
|
if (isset($item['_agents_warning_']))
|
|
|
|
$item['total_warning_count'] = $item['_agents_warning_'];
|
|
|
|
if (isset($item['_agents_not_init_']))
|
|
|
|
$item['total_not_init_count'] = $item['_agents_not_init_'];
|
|
|
|
if (isset($item['_agents_ok_']))
|
|
|
|
$item['total_normal_count'] = $item['_agents_ok_'];
|
|
|
|
if (isset($item['_total_agents_']))
|
|
|
|
$item['total_count'] = $item['_total_agents_'];
|
|
|
|
if (isset($item['_monitors_alerts_fired_']))
|
|
|
|
$item['total_fired_count'] = $item['_monitors_alerts_fired_'];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$processed_item = array();
|
|
|
|
$processed_item['id'] = $item['id'];
|
|
|
|
$processed_item['name'] = $item['name'];
|
|
|
|
$processed_item['rootID'] = $item['id'];
|
|
|
|
$processed_item['rootType'] = $this->rootType;
|
|
|
|
$processed_item['searchChildren'] = 1;
|
|
|
|
|
|
|
|
if (isset($item['type']))
|
|
|
|
$processed_item['type'] = $item['type'];
|
|
|
|
else
|
|
|
|
$processed_item['type'] = $this->type;
|
|
|
|
|
|
|
|
if (isset($item['rootType']))
|
|
|
|
$processed_item['rootType'] = $item['rootType'];
|
|
|
|
else
|
|
|
|
$processed_item['rootType'] = $this->rootType;
|
|
|
|
|
|
|
|
if ($processed_item['type'] == 'group') {
|
2015-03-05 19:43:19 +01:00
|
|
|
$processed_item['parent'] = $item['parent'];
|
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
if (!empty($item['iconHTML']))
|
|
|
|
$processed_item['iconHTML'] = $item['iconHTML'];
|
|
|
|
else if (!empty($item['icon']))
|
|
|
|
$processed_item['icon'] = $item['icon'].".png";
|
|
|
|
else
|
|
|
|
$processed_item['icon'] = "without_group.png";
|
|
|
|
}
|
|
|
|
|
2015-01-29 21:00:30 +01:00
|
|
|
if (defined("METACONSOLE") && !empty($server)) {
|
2015-01-30 15:32:39 +01:00
|
|
|
$processed_item['serverID'] = $server['id'];
|
2015-01-28 18:57:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$counters = array();
|
|
|
|
if (isset($item['total_unknown_count']))
|
|
|
|
$counters['unknown'] = $item['total_unknown_count'];
|
|
|
|
if (isset($item['total_critical_count']))
|
|
|
|
$counters['critical'] = $item['total_critical_count'];
|
|
|
|
if (isset($item['total_warning_count']))
|
|
|
|
$counters['warning'] = $item['total_warning_count'];
|
|
|
|
if (isset($item['total_not_init_count']))
|
|
|
|
$counters['not_init'] = $item['total_not_init_count'];
|
|
|
|
if (isset($item['total_normal_count']))
|
|
|
|
$counters['ok'] = $item['total_normal_count'];
|
|
|
|
if (isset($item['total_count']))
|
|
|
|
$counters['total'] = $item['total_count'];
|
|
|
|
if (isset($item['total_fired_count']))
|
|
|
|
$counters['alerts'] = $item['total_fired_count'];
|
|
|
|
|
2015-03-05 19:43:19 +01:00
|
|
|
if ($processed_item['type'] == 'group') {
|
2015-01-28 18:57:33 +01:00
|
|
|
|
2015-03-05 19:43:19 +01:00
|
|
|
$children = $this->getGroupsChildren($items, $items_tmp, $item['id'], $server, $remove_empty);
|
2015-01-28 18:57:33 +01:00
|
|
|
if (!empty($children)) {
|
|
|
|
$processed_item['children'] = $children;
|
|
|
|
|
|
|
|
foreach ($children as $key => $child) {
|
|
|
|
if (isset($child['counters'])) {
|
|
|
|
foreach ($child['counters'] as $type => $value) {
|
|
|
|
if (isset($counters[$type]))
|
|
|
|
$counters[$type] += $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($counters))
|
|
|
|
$processed_item['counters'] = $counters;
|
2015-03-02 20:51:24 +01:00
|
|
|
|
|
|
|
if ($remove_empty && $processed_item['type'] == 'group'
|
|
|
|
&& (!isset($processed_item['counters']['total'])
|
|
|
|
|| empty($processed_item['counters']['total']))) {
|
|
|
|
$processed_item = array();
|
|
|
|
}
|
2015-01-28 18:57:33 +01:00
|
|
|
|
|
|
|
return $processed_item;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This function should be used only when retrieving the data of the metaconsole's nodes
|
|
|
|
protected function getMergedItems ($items) {
|
|
|
|
// This variable holds the result
|
|
|
|
$mergedItems = array();
|
|
|
|
|
|
|
|
foreach ($items as $key => $item) {
|
|
|
|
// Avoid the deleted items
|
|
|
|
if (!isset($items[$key]) || empty($item))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Store the item in a temporary element
|
|
|
|
$resultItem = $item;
|
|
|
|
|
|
|
|
// The 'id' parameter will be stored as 'server_id' => 'id'
|
|
|
|
$resultItem['id'] = array();
|
2015-01-30 15:32:39 +01:00
|
|
|
$resultItem['id'][$item['serverID']] = $item['id'];
|
2015-01-28 18:57:33 +01:00
|
|
|
$resultItem['rootID'] = array();
|
2015-01-30 15:32:39 +01:00
|
|
|
$resultItem['rootID'][$item['serverID']] = $item['rootID'];
|
|
|
|
$resultItem['serverID'] = array();
|
|
|
|
$resultItem['serverID'][$item['serverID']] = $item['rootID'];
|
2015-01-28 18:57:33 +01:00
|
|
|
|
|
|
|
// Initialize counters if any of it don't exist
|
|
|
|
if (!isset($resultItem['counters']))
|
|
|
|
$resultItem['counters'] = array();
|
|
|
|
if (!isset($resultItem['counters']['unknown']))
|
|
|
|
$resultItem['counters']['unknown'] = 0;
|
|
|
|
if (!isset($resultItem['counters']['critical']))
|
|
|
|
$resultItem['counters']['critical'] = 0;
|
|
|
|
if (!isset($resultItem['counters']['warning']))
|
|
|
|
$resultItem['counters']['warning'] = 0;
|
|
|
|
if (!isset($resultItem['counters']['not_init']))
|
|
|
|
$resultItem['counters']['not_init'] = 0;
|
|
|
|
if (!isset($resultItem['counters']['ok']))
|
|
|
|
$resultItem['counters']['ok'] = 0;
|
|
|
|
if (!isset($resultItem['counters']['total']))
|
|
|
|
$resultItem['counters']['total'] = 0;
|
|
|
|
if (!isset($resultItem['counters']['alerts']))
|
|
|
|
$resultItem['counters']['alerts'] = 0;
|
|
|
|
|
|
|
|
if ($item['type'] == 'group') {
|
|
|
|
// Add the children
|
|
|
|
if (!isset($resultItem['children']))
|
|
|
|
$resultItem['children'] = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iterate over the list to search items that match the actual item
|
|
|
|
foreach ($items as $key2 => $item2) {
|
|
|
|
// Skip the actual or empty items
|
|
|
|
if ($key == $key2 || !isset($items[$key2]))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Match with the name and type
|
|
|
|
if ($item['name'] == $item2['name'] && $item['type'] == $item2['type']) {
|
|
|
|
// Add the matched ids
|
2015-01-30 15:32:39 +01:00
|
|
|
$resultItem['id'][$item2['serverID']] = $item2['id'];
|
|
|
|
$resultItem['rootID'][$item2['serverID']] = $item2['rootID'];
|
|
|
|
$resultItem['serverID'][$item2['serverID']] = $item2['rootID'];
|
2015-01-28 18:57:33 +01:00
|
|
|
|
|
|
|
// Add the matched counters
|
|
|
|
if (isset($item2['counters']) && !empty($item2['counters'])) {
|
|
|
|
foreach ($item2['counters'] as $type => $value) {
|
|
|
|
if (isset($resultItem['counters'][$type]))
|
|
|
|
$resultItem['counters'][$type] += $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($item['type'] == 'group') {
|
|
|
|
// Add the matched children
|
|
|
|
if (isset($item2['children']))
|
|
|
|
$resultItem['children'] = array_merge($resultItem['children'], $item2['children']);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the item
|
|
|
|
unset($items[$key2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($item['type'] == 'group') {
|
|
|
|
// Get the merged children (recursion)
|
|
|
|
if (!empty($resultItem['children']))
|
|
|
|
$resultItem['children'] = $this->getMergedItems($resultItem['children']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the resulting item
|
|
|
|
if (!empty($resultItem) && !empty($resultItem['counters']['total']))
|
|
|
|
$mergedItems[] = $resultItem;
|
|
|
|
|
|
|
|
// Remove the item
|
|
|
|
unset($items[$key]);
|
|
|
|
}
|
|
|
|
|
|
|
|
usort($mergedItems, array("Tree", "cmpSortNames"));
|
|
|
|
|
|
|
|
return $mergedItems;
|
|
|
|
}
|
|
|
|
|
2015-01-29 21:00:30 +01:00
|
|
|
protected function processModule (&$module, $server = false) {
|
2015-01-08 11:45:31 +01:00
|
|
|
global $config;
|
|
|
|
|
2015-01-02 09:11:00 +01:00
|
|
|
$module['type'] = 'module';
|
2015-01-22 16:56:44 +01:00
|
|
|
$module['id'] = (int) $module['id'];
|
|
|
|
$module['name'] = $module['name'];
|
2015-01-02 09:45:53 +01:00
|
|
|
$module['id_module_type'] = (int) $module['id_tipo_modulo'];
|
2015-01-08 15:07:01 +01:00
|
|
|
$module['server_type'] = (int) $module['id_modulo'];
|
2015-01-21 17:37:51 +01:00
|
|
|
$module['status'] = $module['estado'];
|
|
|
|
$module['value'] = $module['datos'];
|
2015-01-29 21:00:30 +01:00
|
|
|
|
|
|
|
if (defined("METACONSOLE") && !empty($server)) {
|
2015-01-30 15:32:39 +01:00
|
|
|
$module['serverID'] = $server['id'];
|
|
|
|
$module['serverName'] = $server['server_name'];
|
2015-01-29 21:00:30 +01:00
|
|
|
}
|
2015-02-13 09:50:11 +01:00
|
|
|
else{
|
|
|
|
$module['serverName'] = false;
|
|
|
|
$module['serverID'] = false;
|
|
|
|
}
|
|
|
|
|
2015-01-12 12:47:54 +01:00
|
|
|
if (!isset($module['value']))
|
|
|
|
$module['value'] = modules_get_last_value($module['id']);
|
2015-01-02 09:11:00 +01:00
|
|
|
|
|
|
|
// Status
|
2015-01-12 12:47:54 +01:00
|
|
|
switch ($module['status']) {
|
2015-01-02 09:11:00 +01:00
|
|
|
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
|
2015-01-12 12:47:54 +01:00
|
|
|
$module['alert'] = 1;
|
|
|
|
case AGENT_MODULE_STATUS_CRITICAL_BAD:
|
|
|
|
$statusType = STATUS_MODULE_CRITICAL_BALL;
|
|
|
|
$statusTitle = __('CRITICAL');
|
|
|
|
$module['statusText'] = "critical";
|
2015-01-02 09:11:00 +01:00
|
|
|
break;
|
|
|
|
case AGENT_MODULE_STATUS_WARNING_ALERT:
|
2015-01-12 12:47:54 +01:00
|
|
|
$module['alert'] = 1;
|
|
|
|
case AGENT_MODULE_STATUS_WARNING:
|
|
|
|
$statusType = STATUS_MODULE_WARNING_BALL;
|
|
|
|
$statusTitle = __('WARNING');
|
|
|
|
$module['statusText'] = "warning";
|
2015-01-02 09:11:00 +01:00
|
|
|
break;
|
|
|
|
case AGENT_MODULE_STATUS_UNKNOWN:
|
2015-01-12 12:47:54 +01:00
|
|
|
$statusType = STATUS_MODULE_UNKNOWN_BALL;
|
|
|
|
$statusTitle = __('UNKNOWN');
|
|
|
|
$module['statusText'] = "unknown";
|
2015-01-02 09:11:00 +01:00
|
|
|
break;
|
|
|
|
case AGENT_MODULE_STATUS_NO_DATA:
|
|
|
|
case AGENT_MODULE_STATUS_NOT_INIT:
|
2015-01-12 12:47:54 +01:00
|
|
|
$statusType = STATUS_MODULE_NO_DATA_BALL;
|
|
|
|
$statusTitle = __('NO DATA');
|
|
|
|
$module['statusText'] = "not_init";
|
2015-01-02 09:11:00 +01:00
|
|
|
break;
|
|
|
|
case AGENT_MODULE_STATUS_NORMAL_ALERT:
|
2015-01-12 12:47:54 +01:00
|
|
|
$module['alert'] = 1;
|
|
|
|
case AGENT_MODULE_STATUS_NORMAL:
|
2015-01-02 09:11:00 +01:00
|
|
|
default:
|
2015-01-12 12:47:54 +01:00
|
|
|
$statusType = STATUS_MODULE_OK_BALL;
|
|
|
|
$statusTitle = __('NORMAL');
|
|
|
|
$module['statusText'] = "ok";
|
2015-01-02 09:11:00 +01:00
|
|
|
break;
|
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-12 12:47:54 +01:00
|
|
|
if ($statusType !== STATUS_MODULE_UNKNOWN_BALL
|
|
|
|
&& $statusType !== STATUS_MODULE_NO_DATA_BALL) {
|
|
|
|
if (is_numeric($module["value"])) {
|
|
|
|
$statusTitle .= " : " . format_for_graph($module["value"]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$statusTitle .= " : " . substr(io_safe_output($module["value"]),0,42);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$module['statusImageHTML'] = ui_print_status_image($statusType, $statusTitle, true);
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-08 13:18:27 +01:00
|
|
|
// HTML of the server type image
|
|
|
|
$module['serverTypeHTML'] = servers_show_type($module['server_type']);
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-08 11:45:31 +01:00
|
|
|
// Link to the Module graph
|
2015-02-23 15:36:07 +01:00
|
|
|
$graphType = return_graphtype($module['id_module_type']);
|
2015-01-08 11:45:31 +01:00
|
|
|
$winHandle = dechex(crc32($module['id'] . $module['name']));
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-29 21:00:30 +01:00
|
|
|
if (!defined('METACONSOLE')) {
|
|
|
|
$moduleGraphURL = $config['homeurl'] .
|
|
|
|
"/operation/agentes/stat_win.php?" .
|
|
|
|
"type=$graphType&" .
|
2015-02-16 18:37:16 +01:00
|
|
|
"period=" . SECONDS_1DAY . "&" .
|
2015-01-29 21:00:30 +01:00
|
|
|
"id=" . $module['id'] . "&" .
|
|
|
|
"label=" . rawurlencode(urlencode(base64_encode($module['name']))) . "&" .
|
2015-02-16 18:37:16 +01:00
|
|
|
"refresh=" . SECONDS_10MINUTES;
|
2015-01-29 21:00:30 +01:00
|
|
|
}
|
|
|
|
else if (!empty($server)) {
|
|
|
|
$moduleGraphURL = ui_meta_get_url_console_child(
|
|
|
|
$server, null, null, null, null,
|
|
|
|
"operation/agentes/stat_win.php?" .
|
2015-02-23 15:36:07 +01:00
|
|
|
"type=$graphType&" .
|
2015-02-16 18:37:16 +01:00
|
|
|
"period=" . SECONDS_1DAY . "&" .
|
2015-01-29 21:00:30 +01:00
|
|
|
"id=" . $module["id"] . "&" .
|
|
|
|
"label=" . rawurlencode(urlencode(base64_encode($module['name']))) . "&" .
|
2015-02-16 18:37:16 +01:00
|
|
|
"refresh=" . SECONDS_10MINUTES);
|
2015-01-29 21:00:30 +01:00
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-29 21:00:30 +01:00
|
|
|
if (!empty($moduleGraphURL)) {
|
|
|
|
$module['moduleGraph'] = array(
|
|
|
|
'url' => $moduleGraphURL,
|
|
|
|
'handle' => $winHandle
|
|
|
|
);
|
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-30 20:06:49 +01:00
|
|
|
// Alerts fired image
|
2015-02-16 18:37:16 +01:00
|
|
|
$has_alerts = (bool) db_get_value(
|
|
|
|
'COUNT(DISTINCT(id_agent_module))',
|
|
|
|
'talert_template_modules', 'id_agent_module', $module['id']);
|
|
|
|
|
2015-01-30 20:06:49 +01:00
|
|
|
if ($has_alerts) {
|
|
|
|
$module['alertsImageHTML'] = html_print_image("images/bell.png", true, array("title" => __('Module alerts')));
|
|
|
|
}
|
2015-01-02 09:11:00 +01:00
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-29 21:00:30 +01:00
|
|
|
protected function processModules (&$modules, $server = false) {
|
2015-01-21 17:37:51 +01:00
|
|
|
foreach ($modules as $iterator => $module) {
|
2015-01-29 21:00:30 +01:00
|
|
|
$this->processModule($modules[$iterator], $server);
|
2015-01-02 09:11:00 +01:00
|
|
|
}
|
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-29 21:00:30 +01:00
|
|
|
protected function processAgent (&$agent, $server = false) {
|
|
|
|
global $config;
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-12 11:07:16 +01:00
|
|
|
$agent['type'] = 'agent';
|
2015-01-22 16:56:44 +01:00
|
|
|
$agent['id'] = (int) $agent['id'];
|
|
|
|
$agent['name'] = $agent['name'];
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-21 17:37:51 +01:00
|
|
|
$agent['rootID'] = $this->rootID;
|
|
|
|
$agent['rootType'] = $this->rootType;
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-30 15:32:39 +01:00
|
|
|
if (defined("METACONSOLE") && !empty($server))
|
|
|
|
$agent['serverID'] = $server['id'];
|
2015-01-12 11:07:16 +01:00
|
|
|
|
|
|
|
// Counters
|
2015-01-14 17:56:42 +01:00
|
|
|
if (empty($agent['counters'])) {
|
|
|
|
$agent['counters'] = array();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-14 17:56:42 +01:00
|
|
|
if (isset($agent['unknown_count']))
|
|
|
|
$agent['counters']['unknown'] = $agent['unknown_count'];
|
|
|
|
else
|
2015-01-30 15:32:39 +01:00
|
|
|
$agent['counters']['unknown'] = agents_monitor_unknown($agent['id']);
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-14 17:56:42 +01:00
|
|
|
if (isset($agent['critical_count']))
|
|
|
|
$agent['counters']['critical'] = $agent['critical_count'];
|
|
|
|
else
|
2015-01-30 15:32:39 +01:00
|
|
|
$agent['counters']['critical'] = agents_monitor_critical($agent['id']);
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-14 17:56:42 +01:00
|
|
|
if (isset($agent['warning_count']))
|
|
|
|
$agent['counters']['warning'] = $agent['warning_count'];
|
|
|
|
else
|
2015-01-30 15:32:39 +01:00
|
|
|
$agent['counters']['warning'] = agents_monitor_warning($agent['id']);
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-14 17:56:42 +01:00
|
|
|
if (isset($agent['notinit_count']))
|
|
|
|
$agent['counters']['not_init'] = $agent['notinit_count'];
|
|
|
|
else
|
2015-01-30 15:32:39 +01:00
|
|
|
$agent['counters']['not_init'] = agents_monitor_notinit($agent['id']);
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-14 17:56:42 +01:00
|
|
|
if (isset($agent['normal_count']))
|
|
|
|
$agent['counters']['ok'] = $agent['normal_count'];
|
|
|
|
else
|
2015-01-30 15:32:39 +01:00
|
|
|
$agent['counters']['ok'] = agents_monitor_ok($agent['id']);
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-14 17:56:42 +01:00
|
|
|
if (isset($agent['total_count']))
|
|
|
|
$agent['counters']['total'] = $agent['total_count'];
|
|
|
|
else
|
2015-01-30 15:32:39 +01:00
|
|
|
$agent['counters']['total'] = agents_monitor_total($agent['id']);
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-14 17:56:42 +01:00
|
|
|
if (isset($agent['fired_count']))
|
|
|
|
$agent['counters']['alerts'] = $agent['fired_count'];
|
|
|
|
else
|
2015-01-30 15:32:39 +01:00
|
|
|
$agent['counters']['alerts'] = agents_get_alerts_fired($agent['id']);
|
2015-01-14 17:56:42 +01:00
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-12 11:07:16 +01:00
|
|
|
// Status image
|
|
|
|
$agent['statusImageHTML'] = agents_tree_view_status_img_ball(
|
|
|
|
$agent['counters']['critical'],
|
|
|
|
$agent['counters']['warning'],
|
|
|
|
$agent['counters']['unknown'],
|
|
|
|
$agent['counters']['total'],
|
|
|
|
$agent['counters']['not_init']);
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-12 11:07:16 +01:00
|
|
|
// Alerts fired image
|
|
|
|
$agent["alertImageHTML"] = agents_tree_view_alert_img_ball($agent['counters']['alerts']);
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-29 21:00:30 +01:00
|
|
|
// Quiet image
|
|
|
|
if (isset($agent['quiet']) && $agent['quiet'])
|
|
|
|
$agent['quietImageHTML'] = html_print_image("/images/dot_green.disabled.png", true, array("title" => __('Quiet')));
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-02 09:11:00 +01:00
|
|
|
// Status
|
2015-01-30 15:32:39 +01:00
|
|
|
$agent['statusRaw'] = agents_get_status($agent['id']);
|
2015-01-08 11:45:31 +01:00
|
|
|
switch ($agent['statusRaw']) {
|
2015-01-02 09:11:00 +01:00
|
|
|
case AGENT_STATUS_NORMAL:
|
|
|
|
$agent['status'] = "ok";
|
|
|
|
break;
|
|
|
|
case AGENT_STATUS_WARNING:
|
|
|
|
$agent['status'] = "warning";
|
|
|
|
break;
|
|
|
|
case AGENT_STATUS_CRITICAL:
|
|
|
|
$agent['status'] = "critical";
|
|
|
|
break;
|
|
|
|
case AGENT_STATUS_UNKNOWN:
|
|
|
|
$agent['status'] = "unknown";
|
|
|
|
break;
|
|
|
|
case AGENT_STATUS_NOT_INIT:
|
|
|
|
$agent['status'] = "not_init";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$agent['status'] = "none";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Children
|
2015-01-14 17:56:42 +01:00
|
|
|
if (empty($agent['children'])) {
|
|
|
|
$agent['children'] = array();
|
|
|
|
if ($agent['counters']['total'] > 0) {
|
|
|
|
switch ($this->childrenMethod) {
|
|
|
|
case 'on_demand':
|
|
|
|
$agent['searchChildren'] = 1;
|
|
|
|
break;
|
|
|
|
case 'live':
|
|
|
|
$agent['searchChildren'] = 0;
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
// if ($searchChildren)
|
2015-01-30 15:32:39 +01:00
|
|
|
// $agent['children'] = $this->getModules($agent['id'], $modulesFilter);
|
2015-01-14 17:56:42 +01:00
|
|
|
break;
|
|
|
|
}
|
2015-01-02 09:11:00 +01:00
|
|
|
}
|
2015-01-14 17:56:42 +01:00
|
|
|
else {
|
|
|
|
switch ($this->childrenMethod) {
|
|
|
|
case 'on_demand':
|
|
|
|
$agent['searchChildren'] = 0;
|
|
|
|
break;
|
|
|
|
case 'live':
|
|
|
|
$agent['searchChildren'] = 0;
|
|
|
|
break;
|
|
|
|
}
|
2015-01-02 09:11:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-29 21:00:30 +01:00
|
|
|
protected function processAgents (&$agents, $server = false) {
|
2015-01-02 09:11:00 +01:00
|
|
|
if (!empty($agents)) {
|
|
|
|
foreach ($agents as $iterator => $agent) {
|
2015-01-29 21:00:30 +01:00
|
|
|
$this->processAgent($agents[$iterator], $server);
|
2015-01-02 09:11:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-12 11:07:16 +01:00
|
|
|
public function getData() {
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-26 17:51:06 +01:00
|
|
|
if (! $this->strictACL) {
|
|
|
|
switch ($this->type) {
|
|
|
|
case 'os':
|
|
|
|
$this->getDataOS();
|
|
|
|
break;
|
|
|
|
case 'group':
|
|
|
|
$this->getDataGroup();
|
|
|
|
break;
|
|
|
|
case 'module_group':
|
|
|
|
$this->getDataModuleGroup();
|
|
|
|
break;
|
|
|
|
case 'module':
|
|
|
|
$this->getDataModules();
|
|
|
|
break;
|
|
|
|
case 'tag':
|
|
|
|
$this->getDataTag();
|
|
|
|
break;
|
|
|
|
case 'agent':
|
|
|
|
$this->getDataAgent();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$this->getDataExtended();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch ($this->type) {
|
|
|
|
case 'group':
|
|
|
|
case 'tag':
|
|
|
|
$this->getDataStrict();
|
|
|
|
break;
|
|
|
|
case 'agent':
|
|
|
|
$this->getDataAgent();
|
|
|
|
break;
|
|
|
|
}
|
2015-01-12 11:07:16 +01:00
|
|
|
}
|
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-12 11:07:16 +01:00
|
|
|
protected function getDataExtended () {
|
|
|
|
// Override this method to add new types
|
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-21 17:37:51 +01:00
|
|
|
private function getDataAgent () {
|
|
|
|
$processed_items = array();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-21 17:37:51 +01:00
|
|
|
// Module names
|
|
|
|
if ($this->id == -1) {
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-21 17:37:51 +01:00
|
|
|
}
|
|
|
|
// Agents
|
|
|
|
else {
|
2015-01-28 18:57:33 +01:00
|
|
|
if (! defined ('METACONSOLE')) {
|
|
|
|
$items = $this->getItems();
|
|
|
|
$this->processModules($items);
|
|
|
|
$processed_items = $items;
|
2015-01-22 16:56:44 +01:00
|
|
|
}
|
|
|
|
else {
|
2015-01-28 18:57:33 +01:00
|
|
|
$items = array();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-30 15:32:39 +01:00
|
|
|
if ($this->serverID !== false) {
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-30 15:32:39 +01:00
|
|
|
$server = metaconsole_get_servers($this->serverID);
|
|
|
|
if (metaconsole_connect($server) == NOERR) {
|
|
|
|
db_clean_cache();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-30 15:32:39 +01:00
|
|
|
$newItems = $this->getItems();
|
|
|
|
$this->processModules($newItems, $server);
|
|
|
|
$items = array_merge($items, $newItems);
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-30 15:32:39 +01:00
|
|
|
metaconsole_restore_db();
|
|
|
|
}
|
2015-01-26 17:51:06 +01:00
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
if (!empty($items))
|
|
|
|
usort($items, array("Tree", "cmpSortNames"));
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$processed_items = $items;
|
|
|
|
}
|
2015-01-26 17:51:06 +01:00
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$this->tree = $processed_items;
|
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
private function getDataStrict () {
|
|
|
|
global $config;
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
require_once($config['homedir']."/include/functions_groups.php");
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-26 17:51:06 +01:00
|
|
|
$processed_items = array();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-26 17:51:06 +01:00
|
|
|
// Groups and tags
|
|
|
|
if ($this->id == -1) {
|
|
|
|
if (! defined ('METACONSOLE')) {
|
|
|
|
$items = group_get_data($config['id_user'], $this->strictACL, $this->acltags, false, 'tree');
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-26 17:51:06 +01:00
|
|
|
// Build the group and tag hierarchy
|
|
|
|
$processed_items = array();
|
2015-03-05 19:43:19 +01:00
|
|
|
$processed_items_tmp = array();
|
2015-01-26 17:51:06 +01:00
|
|
|
foreach ($items as $key => $item) {
|
2015-03-05 19:43:19 +01:00
|
|
|
unset($items[$key]);
|
|
|
|
|
|
|
|
$processed_item = $this->getProcessedItem($item, false, $items, $processed_items_tmp, true);
|
|
|
|
if (!empty($processed_item)
|
|
|
|
&& isset($processed_item['counters'])
|
|
|
|
&& isset($processed_item['counters']['total'])
|
|
|
|
&& !empty($processed_item['counters']['total'])) {
|
|
|
|
$processed_items_tmp[] = $processed_item;
|
2015-01-26 17:51:06 +01:00
|
|
|
}
|
|
|
|
}
|
2015-03-05 19:43:19 +01:00
|
|
|
if (!empty($processed_items_tmp)) {
|
|
|
|
usort($processed_items_tmp, array("Tree", "cmpSortNames"));
|
|
|
|
// array_filter clean the empty elements
|
|
|
|
$processed_items = array_filter($processed_items_tmp);
|
|
|
|
}
|
2015-01-26 17:51:06 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$unmerged_items = array();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-26 17:51:06 +01:00
|
|
|
$servers = metaconsole_get_servers();
|
|
|
|
foreach ($servers as $server) {
|
|
|
|
if (metaconsole_connect($server) != NOERR)
|
|
|
|
continue;
|
2015-01-28 18:57:33 +01:00
|
|
|
db_clean_cache();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-26 17:51:06 +01:00
|
|
|
$items = group_get_data($config['id_user'], $this->strictACL, $this->acltags, false, 'tree');
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-03-05 19:43:19 +01:00
|
|
|
// Build the group and tag hierarchy
|
2015-01-26 17:51:06 +01:00
|
|
|
$processed_items = array();
|
2015-03-05 19:43:19 +01:00
|
|
|
$processed_items_tmp = array();
|
2015-01-26 17:51:06 +01:00
|
|
|
foreach ($items as $key => $item) {
|
2015-03-05 19:43:19 +01:00
|
|
|
unset($items[$key]);
|
|
|
|
$processed_items_tmp[] = $this->getProcessedItem($item, $server, $items, $processed_items_tmp);
|
|
|
|
}
|
|
|
|
if (!empty($processed_items_tmp)) {
|
|
|
|
usort($processed_items_tmp, array("Tree", "cmpSortNames"));
|
|
|
|
// array_filter clean the empty elements
|
|
|
|
$processed_items = array_filter($processed_items_tmp);
|
2015-01-26 17:51:06 +01:00
|
|
|
}
|
2015-03-05 19:43:19 +01:00
|
|
|
|
2015-01-26 17:51:06 +01:00
|
|
|
$unmerged_items += $processed_items;
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-26 17:51:06 +01:00
|
|
|
metaconsole_restore_db();
|
|
|
|
}
|
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$processed_items = $this->getMergedItems($unmerged_items);
|
2015-01-26 17:51:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Agents
|
|
|
|
else {
|
|
|
|
if (! defined ('METACONSOLE')) {
|
|
|
|
$items = $this->getItems();
|
|
|
|
$this->processAgents($items);
|
|
|
|
$processed_items = $items;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$rootIDs = $this->rootID;
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-26 17:51:06 +01:00
|
|
|
$items = array();
|
|
|
|
foreach ($rootIDs as $serverID => $rootID) {
|
|
|
|
$server = metaconsole_get_servers($serverID);
|
2015-01-26 19:04:29 +01:00
|
|
|
if (metaconsole_connect($server) != NOERR)
|
2015-01-26 17:51:06 +01:00
|
|
|
continue;
|
2015-01-28 18:57:33 +01:00
|
|
|
db_clean_cache();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-26 17:51:06 +01:00
|
|
|
$this->rootID = $rootID;
|
|
|
|
$newItems = $this->getItems();
|
2015-01-29 21:00:30 +01:00
|
|
|
$this->processAgents($newItems, $server);
|
2015-01-28 18:57:33 +01:00
|
|
|
$items = array_merge($items, $newItems);
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-26 17:51:06 +01:00
|
|
|
metaconsole_restore_db();
|
|
|
|
}
|
|
|
|
$this->rootID = $rootIDs;
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-26 17:51:06 +01:00
|
|
|
if (!empty($items))
|
2015-01-28 18:57:33 +01:00
|
|
|
usort($items, array("Tree", "cmpSortNames"));
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-26 17:51:06 +01:00
|
|
|
$processed_items = $items;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->tree = $processed_items;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getDataGroup() {
|
2015-01-28 18:57:33 +01:00
|
|
|
$processed_items = array();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
// Groups
|
|
|
|
if ($this->id == -1) {
|
|
|
|
if (! defined ('METACONSOLE')) {
|
|
|
|
$items = $this->getItems();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
// Build the group hierarchy
|
|
|
|
foreach ($items as $key => $item) {
|
|
|
|
if (empty($item['parent'])) {
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
unset($items[$key]);
|
2015-03-05 19:43:19 +01:00
|
|
|
$items_tmp = array();
|
|
|
|
$processed_item = $this->getProcessedItem($item, false, $items, $items_tmp, true);
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
if (!empty($processed_item)
|
|
|
|
&& isset($processed_item['counters'])
|
|
|
|
&& isset($processed_item['counters']['total'])
|
|
|
|
&& !empty($processed_item['counters']['total']))
|
|
|
|
$processed_items[] = $processed_item;
|
|
|
|
}
|
|
|
|
}
|
2015-01-26 17:51:06 +01:00
|
|
|
}
|
2015-01-28 18:57:33 +01:00
|
|
|
else {
|
|
|
|
$servers = metaconsole_get_servers();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$item_list = array();
|
|
|
|
foreach ($servers as $server) {
|
|
|
|
if (metaconsole_connect($server) != NOERR)
|
|
|
|
continue;
|
|
|
|
db_clean_cache();
|
|
|
|
|
|
|
|
$items = $this->getItems();
|
|
|
|
|
|
|
|
// Build the group hierarchy
|
|
|
|
$processed_items = array();
|
|
|
|
foreach ($items as $key => $item) {
|
|
|
|
if (empty($item['parent'])) {
|
|
|
|
|
|
|
|
unset($items[$key]);
|
2015-01-29 21:00:30 +01:00
|
|
|
$processed_items[] = $this->getProcessedItem($item, $server, $items);
|
2015-01-22 18:07:17 +01:00
|
|
|
}
|
|
|
|
}
|
2015-01-28 18:57:33 +01:00
|
|
|
|
|
|
|
$item_list = array_merge($item_list, $processed_items);
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
metaconsole_restore_db();
|
2015-01-16 17:16:24 +01:00
|
|
|
}
|
2015-01-28 18:57:33 +01:00
|
|
|
|
|
|
|
$processed_items = $this->getMergedItems($item_list);
|
2015-01-22 18:07:17 +01:00
|
|
|
}
|
|
|
|
}
|
2015-01-28 18:57:33 +01:00
|
|
|
// Agents
|
|
|
|
else {
|
|
|
|
if (! defined ('METACONSOLE')) {
|
|
|
|
$items = $this->getItems();
|
|
|
|
$this->processAgents($items);
|
|
|
|
$processed_items = $items;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$rootIDs = $this->rootID;
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$items = array();
|
|
|
|
foreach ($rootIDs as $serverID => $rootID) {
|
|
|
|
$server = metaconsole_get_servers($serverID);
|
|
|
|
if (metaconsole_connect($server) != NOERR)
|
2015-01-22 18:07:17 +01:00
|
|
|
continue;
|
2015-01-28 18:57:33 +01:00
|
|
|
db_clean_cache();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$this->rootID = $rootID;
|
|
|
|
$newItems = $this->getItems();
|
2015-01-29 21:00:30 +01:00
|
|
|
$this->processAgents($newItems, $server);
|
2015-01-28 18:57:33 +01:00
|
|
|
$items = array_merge($items, $newItems);
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
metaconsole_restore_db();
|
2015-01-14 17:56:42 +01:00
|
|
|
}
|
2015-01-28 18:57:33 +01:00
|
|
|
$this->rootID = $rootIDs;
|
|
|
|
|
|
|
|
if (!empty($items))
|
|
|
|
usort($items, array("Tree", "cmpSortNames"));
|
|
|
|
|
|
|
|
$processed_items = $items;
|
2015-01-14 17:56:42 +01:00
|
|
|
}
|
2015-01-22 18:07:17 +01:00
|
|
|
}
|
2015-01-28 18:57:33 +01:00
|
|
|
|
|
|
|
$this->tree = $processed_items;
|
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
private function getDataTag() {
|
2015-01-22 18:07:17 +01:00
|
|
|
$processed_items = array();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
// Tags
|
2015-01-22 18:07:17 +01:00
|
|
|
if ($this->id == -1) {
|
2015-01-16 17:16:24 +01:00
|
|
|
if (! defined ('METACONSOLE')) {
|
2015-01-22 18:07:17 +01:00
|
|
|
$items = $this->getItems();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-16 17:16:24 +01:00
|
|
|
foreach ($items as $key => $item) {
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$counters = $this->getCounters($item['id']);
|
|
|
|
if (!empty($counters)) {
|
|
|
|
foreach ($counters as $type => $value) {
|
|
|
|
$item[$type] = $value;
|
|
|
|
}
|
2015-01-22 18:07:17 +01:00
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$processed_item = $this->getProcessedItem($item);
|
|
|
|
$processed_items[] = $processed_item;
|
2015-01-16 17:16:24 +01:00
|
|
|
}
|
2015-01-14 17:56:42 +01:00
|
|
|
}
|
2015-01-16 17:16:24 +01:00
|
|
|
else {
|
2015-01-22 18:19:38 +01:00
|
|
|
$servers = metaconsole_get_servers();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-16 17:16:24 +01:00
|
|
|
$item_list = array();
|
2015-01-22 18:19:38 +01:00
|
|
|
foreach ($servers as $server) {
|
2015-01-26 19:04:29 +01:00
|
|
|
if (metaconsole_connect($server) != NOERR)
|
2015-01-22 19:13:30 +01:00
|
|
|
continue;
|
2015-01-28 18:57:33 +01:00
|
|
|
db_clean_cache();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-22 19:13:30 +01:00
|
|
|
$items = $this->getItems();
|
2015-01-28 18:57:33 +01:00
|
|
|
|
2015-01-16 17:16:24 +01:00
|
|
|
$processed_items = array();
|
|
|
|
foreach ($items as $key => $item) {
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$counters = $this->getCounters($item['id']);
|
|
|
|
if (!empty($counters)) {
|
|
|
|
foreach ($counters as $type => $value) {
|
|
|
|
$item[$type] = $value;
|
|
|
|
}
|
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-29 21:00:30 +01:00
|
|
|
$processed_item = $this->getProcessedItem($item, $server);
|
2015-01-28 18:57:33 +01:00
|
|
|
$processed_items[] = $processed_item;
|
2015-01-26 19:35:56 +01:00
|
|
|
}
|
2015-01-28 18:57:33 +01:00
|
|
|
$item_list = array_merge($item_list, $processed_items);
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-22 19:13:30 +01:00
|
|
|
metaconsole_restore_db();
|
2015-01-14 17:56:42 +01:00
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$processed_items = $this->getMergedItems($item_list);
|
2015-01-14 17:56:42 +01:00
|
|
|
}
|
|
|
|
}
|
2015-01-22 18:07:17 +01:00
|
|
|
// Agents
|
2015-01-14 17:56:42 +01:00
|
|
|
else {
|
2015-01-16 17:16:24 +01:00
|
|
|
if (! defined ('METACONSOLE')) {
|
2015-01-22 16:56:44 +01:00
|
|
|
$items = $this->getItems();
|
|
|
|
$this->processAgents($items);
|
2015-01-22 18:07:17 +01:00
|
|
|
$processed_items = $items;
|
2015-01-16 17:16:24 +01:00
|
|
|
}
|
|
|
|
else {
|
2015-01-22 16:56:44 +01:00
|
|
|
$rootIDs = $this->rootID;
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-22 16:56:44 +01:00
|
|
|
$items = array();
|
|
|
|
foreach ($rootIDs as $serverID => $rootID) {
|
2015-01-22 19:13:30 +01:00
|
|
|
$server = metaconsole_get_servers($serverID);
|
2015-01-26 19:04:29 +01:00
|
|
|
if (metaconsole_connect($server) != NOERR)
|
2015-01-22 19:13:30 +01:00
|
|
|
continue;
|
2015-01-28 18:57:33 +01:00
|
|
|
db_clean_cache();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-22 16:56:44 +01:00
|
|
|
$this->rootID = $rootID;
|
2015-01-22 19:13:30 +01:00
|
|
|
$newItems = $this->getItems();
|
2015-01-29 21:00:30 +01:00
|
|
|
$this->processAgents($newItems, $server);
|
2015-01-26 19:31:53 +01:00
|
|
|
$items = array_merge($items, $newItems);
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-22 19:13:30 +01:00
|
|
|
metaconsole_restore_db();
|
2015-01-16 17:16:24 +01:00
|
|
|
}
|
2015-01-22 16:56:44 +01:00
|
|
|
$this->rootID = $rootIDs;
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-22 16:56:44 +01:00
|
|
|
if (!empty($items))
|
2015-01-28 18:57:33 +01:00
|
|
|
usort($items, array("Tree", "cmpSortNames"));
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-22 18:07:17 +01:00
|
|
|
$processed_items = $items;
|
2015-01-16 17:16:24 +01:00
|
|
|
}
|
2015-01-14 17:56:42 +01:00
|
|
|
}
|
2015-01-22 18:07:17 +01:00
|
|
|
|
|
|
|
$this->tree = $processed_items;
|
2015-01-12 11:07:16 +01:00
|
|
|
}
|
2015-01-28 18:57:33 +01:00
|
|
|
|
|
|
|
private function getDataModules() {
|
|
|
|
$processed_items = array();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
// Module names
|
|
|
|
if ($this->id == -1) {
|
|
|
|
if (! defined ('METACONSOLE')) {
|
|
|
|
$items = $this->getItems();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
foreach ($items as $key => $item) {
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$counters = $this->getCounters($item['name']);
|
|
|
|
if (!empty($counters)) {
|
|
|
|
foreach ($counters as $type => $value) {
|
|
|
|
$item[$type] = $value;
|
|
|
|
}
|
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$name = str_replace(array(' ','#','/','.','(',')','¿','?','¡','!'),
|
|
|
|
array( '_articapandora_'.ord(' ').'_pandoraartica_',
|
|
|
|
'_articapandora_'.ord('#').'_pandoraartica_',
|
|
|
|
'_articapandora_'.ord('/').'_pandoraartica_',
|
|
|
|
'_articapandora_'.ord('.').'_pandoraartica_',
|
|
|
|
'_articapandora_'.ord('(').'_pandoraartica_',
|
|
|
|
'_articapandora_'.ord(')').'_pandoraartica_',
|
|
|
|
'_articapandora_'.ord('¿').'_pandoraartica_',
|
|
|
|
'_articapandora_'.ord('?').'_pandoraartica_',
|
|
|
|
'_articapandora_'.ord('¡').'_pandoraartica_',
|
|
|
|
'_articapandora_'.ord('!').'_pandoraartica_'),
|
|
|
|
io_safe_output($item['name']));
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$processed_item = $this->getProcessedItem($item);
|
|
|
|
$processed_item['id'] = $name;
|
|
|
|
$processed_item['rootID'] = $name;
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$processed_items[] = $processed_item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$servers = metaconsole_get_servers();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$item_list = array();
|
|
|
|
foreach ($servers as $server) {
|
|
|
|
if (metaconsole_connect($server) != NOERR)
|
2015-01-26 19:50:20 +01:00
|
|
|
continue;
|
2015-01-28 18:57:33 +01:00
|
|
|
db_clean_cache();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$items = $this->getItems();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$processed_items = array();
|
|
|
|
foreach ($items as $key => $item) {
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$counters = $this->getCounters($item['name']);
|
|
|
|
if (!empty($counters)) {
|
|
|
|
foreach ($counters as $type => $value) {
|
|
|
|
$item[$type] = $value;
|
2015-01-26 19:50:20 +01:00
|
|
|
}
|
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$name = str_replace(array(' ','#','/','.','(',')','¿','?','¡','!'),
|
|
|
|
array( '_articapandora_'.ord(' ').'_pandoraartica_',
|
|
|
|
'_articapandora_'.ord('#').'_pandoraartica_',
|
|
|
|
'_articapandora_'.ord('/').'_pandoraartica_',
|
|
|
|
'_articapandora_'.ord('.').'_pandoraartica_',
|
|
|
|
'_articapandora_'.ord('(').'_pandoraartica_',
|
|
|
|
'_articapandora_'.ord(')').'_pandoraartica_',
|
|
|
|
'_articapandora_'.ord('¿').'_pandoraartica_',
|
|
|
|
'_articapandora_'.ord('?').'_pandoraartica_',
|
|
|
|
'_articapandora_'.ord('¡').'_pandoraartica_',
|
|
|
|
'_articapandora_'.ord('!').'_pandoraartica_'),
|
|
|
|
io_safe_output($item['name']));
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-29 21:00:30 +01:00
|
|
|
$processed_item = $this->getProcessedItem($item, $server);
|
2015-01-28 18:57:33 +01:00
|
|
|
$processed_item['id'] = $name;
|
|
|
|
$processed_item['rootID'] = $name;
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$processed_items[] = $processed_item;
|
2015-01-26 19:50:20 +01:00
|
|
|
}
|
2015-01-28 18:57:33 +01:00
|
|
|
$item_list = array_merge($item_list, $processed_items);
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
metaconsole_restore_db();
|
2015-01-26 19:50:20 +01:00
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$processed_items = $this->getMergedItems($item_list);
|
2015-01-26 19:50:20 +01:00
|
|
|
}
|
2015-01-28 18:57:33 +01:00
|
|
|
}
|
|
|
|
// Agents
|
|
|
|
else {
|
|
|
|
if (! defined ('METACONSOLE')) {
|
|
|
|
$items = $this->getItems();
|
|
|
|
$this->processAgents($items);
|
|
|
|
$processed_items = $items;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$rootIDs = $this->rootID;
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$items = array();
|
|
|
|
foreach ($rootIDs as $serverID => $rootID) {
|
|
|
|
$server = metaconsole_get_servers($serverID);
|
|
|
|
if (metaconsole_connect($server) != NOERR)
|
|
|
|
continue;
|
|
|
|
db_clean_cache();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$this->rootID = $rootID;
|
|
|
|
$newItems = $this->getItems();
|
2015-01-29 21:00:30 +01:00
|
|
|
$this->processAgents($newItems, $server);
|
2015-01-28 18:57:33 +01:00
|
|
|
$items = array_merge($items, $newItems);
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
metaconsole_restore_db();
|
|
|
|
}
|
|
|
|
$this->rootID = $rootIDs;
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
if (!empty($items))
|
|
|
|
usort($items, array("Tree", "cmpSortNames"));
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$processed_items = $items;
|
|
|
|
}
|
2015-01-26 19:50:20 +01:00
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$this->tree = $processed_items;
|
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
private function getDataModuleGroup() {
|
2015-01-22 19:13:30 +01:00
|
|
|
$processed_items = array();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
// Module groups
|
2015-01-22 19:13:30 +01:00
|
|
|
if ($this->id == -1) {
|
2015-01-26 19:50:20 +01:00
|
|
|
if (! defined ('METACONSOLE')) {
|
|
|
|
$items = $this->getItems();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-26 19:50:20 +01:00
|
|
|
foreach ($items as $key => $item) {
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$counters = $this->getCounters($item['id']);
|
|
|
|
if (!empty($counters)) {
|
|
|
|
foreach ($counters as $type => $value) {
|
|
|
|
$item[$type] = $value;
|
|
|
|
}
|
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$processed_item = $this->getProcessedItem($item);
|
2015-01-26 19:50:20 +01:00
|
|
|
$processed_items[] = $processed_item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$servers = metaconsole_get_servers();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-26 19:50:20 +01:00
|
|
|
$item_list = array();
|
|
|
|
foreach ($servers as $server) {
|
|
|
|
if (metaconsole_connect($server) != NOERR)
|
|
|
|
continue;
|
2015-01-28 18:57:33 +01:00
|
|
|
db_clean_cache();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-26 19:50:20 +01:00
|
|
|
$items = $this->getItems();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-26 19:50:20 +01:00
|
|
|
$processed_items = array();
|
|
|
|
foreach ($items as $key => $item) {
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$counters = $this->getCounters($item['id']);
|
|
|
|
if (!empty($counters)) {
|
|
|
|
foreach ($counters as $type => $value) {
|
|
|
|
$item[$type] = $value;
|
|
|
|
}
|
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-29 21:00:30 +01:00
|
|
|
$processed_item = $this->getProcessedItem($item, $server);
|
2015-01-26 19:50:20 +01:00
|
|
|
$processed_items[] = $processed_item;
|
|
|
|
}
|
2015-01-28 18:57:33 +01:00
|
|
|
$item_list = array_merge($item_list, $processed_items);
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-26 19:50:20 +01:00
|
|
|
metaconsole_restore_db();
|
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$processed_items = $this->getMergedItems($item_list);
|
2015-01-22 19:13:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Agents
|
|
|
|
else {
|
|
|
|
if (! defined ('METACONSOLE')) {
|
|
|
|
$items = $this->getItems();
|
|
|
|
$this->processAgents($items);
|
|
|
|
$processed_items = $items;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$rootIDs = $this->rootID;
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-22 19:13:30 +01:00
|
|
|
$items = array();
|
|
|
|
foreach ($rootIDs as $serverID => $rootID) {
|
|
|
|
$server = metaconsole_get_servers($serverID);
|
2015-01-26 19:04:29 +01:00
|
|
|
if (metaconsole_connect($server) != NOERR)
|
2015-01-22 19:13:30 +01:00
|
|
|
continue;
|
2015-01-28 18:57:33 +01:00
|
|
|
db_clean_cache();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-22 19:13:30 +01:00
|
|
|
$this->rootID = $rootID;
|
|
|
|
$newItems = $this->getItems();
|
2015-01-29 21:00:30 +01:00
|
|
|
$this->processAgents($newItems, $server);
|
2015-01-28 18:57:33 +01:00
|
|
|
$items = array_merge($items, $newItems);
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-22 19:13:30 +01:00
|
|
|
metaconsole_restore_db();
|
|
|
|
}
|
|
|
|
$this->rootID = $rootIDs;
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-22 19:13:30 +01:00
|
|
|
if (!empty($items))
|
2015-01-28 18:57:33 +01:00
|
|
|
usort($items, array("Tree", "cmpSortNames"));
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-22 19:13:30 +01:00
|
|
|
$processed_items = $items;
|
|
|
|
}
|
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-22 19:13:30 +01:00
|
|
|
$this->tree = $processed_items;
|
2015-01-28 18:57:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function getDataOS() {
|
|
|
|
$processed_items = array();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
// OS
|
|
|
|
if ($this->id == -1) {
|
|
|
|
if (! defined ('METACONSOLE')) {
|
|
|
|
$items = $this->getItems();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
foreach ($items as $key => $item) {
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$counters = $this->getCounters($item['id']);
|
|
|
|
if (!empty($counters)) {
|
|
|
|
foreach ($counters as $type => $value) {
|
|
|
|
$item[$type] = $value;
|
|
|
|
}
|
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$processed_item = $this->getProcessedItem($item);
|
|
|
|
$processed_item['icon'] = $item['os_icon'];
|
|
|
|
$processed_items[] = $processed_item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$servers = metaconsole_get_servers();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$item_list = array();
|
|
|
|
foreach ($servers as $server) {
|
|
|
|
if (metaconsole_connect($server) != NOERR)
|
|
|
|
continue;
|
|
|
|
db_clean_cache();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$items = $this->getItems();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$processed_items = array();
|
|
|
|
foreach ($items as $key => $item) {
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$counters = $this->getCounters($item['id']);
|
|
|
|
if (!empty($counters)) {
|
|
|
|
foreach ($counters as $type => $value) {
|
|
|
|
$item[$type] = $value;
|
|
|
|
}
|
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-29 21:00:30 +01:00
|
|
|
$processed_item = $this->getProcessedItem($item, $server);
|
2015-01-28 18:57:33 +01:00
|
|
|
$processed_item['icon'] = $item['os_icon'];
|
|
|
|
$processed_items[] = $processed_item;
|
|
|
|
}
|
|
|
|
$item_list = array_merge($item_list, $processed_items);
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
metaconsole_restore_db();
|
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$processed_items = $this->getMergedItems($item_list);
|
2015-01-02 09:11:00 +01:00
|
|
|
}
|
|
|
|
}
|
2015-01-21 17:37:51 +01:00
|
|
|
// Agents
|
|
|
|
else {
|
2015-01-28 18:57:33 +01:00
|
|
|
if (! defined ('METACONSOLE')) {
|
|
|
|
$items = $this->getItems();
|
|
|
|
$this->processAgents($items);
|
|
|
|
$processed_items = $items;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$rootIDs = $this->rootID;
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$items = array();
|
|
|
|
foreach ($rootIDs as $serverID => $rootID) {
|
|
|
|
$server = metaconsole_get_servers($serverID);
|
|
|
|
if (metaconsole_connect($server) != NOERR)
|
|
|
|
continue;
|
|
|
|
db_clean_cache();
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$this->rootID = $rootID;
|
|
|
|
$newItems = $this->getItems();
|
2015-01-29 21:00:30 +01:00
|
|
|
$this->processAgents($newItems, $server);
|
2015-01-28 18:57:33 +01:00
|
|
|
$items = array_merge($items, $newItems);
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
metaconsole_restore_db();
|
|
|
|
}
|
|
|
|
$this->rootID = $rootIDs;
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
if (!empty($items))
|
|
|
|
usort($items, array("Tree", "cmpSortNames"));
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
$processed_items = $items;
|
2015-01-12 11:07:16 +01:00
|
|
|
}
|
|
|
|
}
|
2015-02-16 18:37:16 +01:00
|
|
|
|
2015-01-21 17:37:51 +01:00
|
|
|
$this->tree = $processed_items;
|
2015-01-12 11:07:16 +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
|
|
|
}
|
|
|
|
?>
|