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;
|
2018-09-10 15:35:11 +02:00
|
|
|
protected $serverName = '';
|
2015-01-05 13:25:41 +01:00
|
|
|
protected $tree = array();
|
|
|
|
protected $filter = array();
|
|
|
|
protected $childrenMethod = "on_demand";
|
|
|
|
|
2017-10-25 17:44:59 +02:00
|
|
|
protected $userGroupsACL;
|
2015-01-05 13:25:41 +01:00
|
|
|
protected $userGroups;
|
2018-08-23 14:49:09 +02:00
|
|
|
protected $userGroupsArray;
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2016-09-08 16:06:12 +02:00
|
|
|
protected $access = false;
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2018-09-04 11:51:36 +02:00
|
|
|
protected $L1fieldName = '';
|
|
|
|
protected $L1fieldNameSql = '';
|
2018-09-05 13:48:53 +02:00
|
|
|
protected $L1extraFields = array();
|
2018-09-04 11:51:36 +02:00
|
|
|
protected $L1inner = '';
|
|
|
|
protected $L1innerInside = '';
|
|
|
|
protected $L1orderByFinal = '';
|
|
|
|
|
|
|
|
protected $L2condition = '';
|
|
|
|
protected $L2conditionInside = '';
|
|
|
|
protected $L2inner = '';
|
|
|
|
|
2018-10-16 13:29:00 +02:00
|
|
|
protected $L3forceTagCondition = false;
|
|
|
|
|
2018-09-04 11:51:36 +02:00
|
|
|
const TV_DEFAULT_AGENT_STATUS = -1;
|
|
|
|
|
2016-09-08 16:06:12 +02:00
|
|
|
public function __construct($type, $rootType = '', $id = -1, $rootID = -1, $serverID = false, $childrenMethod = "on_demand", $access = 'AR') {
|
2016-01-28 14:38:23 +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;
|
2018-09-10 15:35:11 +02:00
|
|
|
if (is_metaconsole()) {
|
|
|
|
$this->serverName = metaconsole_get_server_by_id($serverID);
|
|
|
|
}
|
2017-10-25 17:44:59 +02:00
|
|
|
$this->childrenMethod = $childrenMethod;
|
|
|
|
$this->access = $access;
|
2015-01-08 16:39:35 +01:00
|
|
|
|
2017-10-25 17:44:59 +02:00
|
|
|
$userGroupsACL = users_get_groups(false, $this->access);
|
|
|
|
$this->userGroupsACL = empty($userGroupsACL) ? false : $userGroupsACL;
|
|
|
|
$this->userGroups = $this->userGroupsACL;
|
2018-08-23 14:49:09 +02:00
|
|
|
$this->userGroupsArray = array_keys($this->userGroups);
|
2015-01-08 13:18:27 +01:00
|
|
|
|
|
|
|
global $config;
|
|
|
|
include_once($config['homedir']."/include/functions_servers.php");
|
2015-03-23 20:51:44 +01:00
|
|
|
include_once($config['homedir']."/include/functions_modules.php");
|
2015-09-30 18:32:55 +02:00
|
|
|
require_once($config['homedir']."/include/functions_tags.php");
|
2018-04-11 11:04:21 +02:00
|
|
|
enterprise_include_once("include/functions_agents.php");
|
2015-01-21 17:37:51 +01:00
|
|
|
|
2017-10-25 17:44:59 +02:00
|
|
|
if (is_metaconsole()) enterprise_include_once("meta/include/functions_ui_meta.php");
|
2014-12-16 16:39:00 +01:00
|
|
|
}
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2014-12-17 18:58:34 +01:00
|
|
|
public function setFilter($filter) {
|
2018-09-05 11:23:53 +02:00
|
|
|
// There is not module filter in metaconsole.
|
|
|
|
if (is_metaconsole()) {
|
|
|
|
$filter['searchModule'] = "";
|
|
|
|
$filter['statusModule'] = self::TV_DEFAULT_AGENT_STATUS;
|
|
|
|
}
|
2014-12-16 16:39:00 +01:00
|
|
|
$this->filter = $filter;
|
|
|
|
}
|
2014-12-30 16:24:23 +01:00
|
|
|
|
2018-08-28 12:52:57 +02:00
|
|
|
protected function getEmptyModuleFilterStatus() {
|
|
|
|
return (
|
|
|
|
!isset($this->filter['statusModule']) ||
|
|
|
|
$this->filter['statusModule'] == -1
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-09-04 11:51:36 +02:00
|
|
|
protected function getModuleSearchFilter() {
|
|
|
|
if (empty($this->filter['searchModule'])) {
|
|
|
|
return "";
|
|
|
|
}
|
2018-09-21 13:01:40 +02:00
|
|
|
return " AND tam.nombre LIKE '%%".$this->filter['searchModule']."%%' ";
|
2018-09-04 11:51:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getAgentSearchFilter() {
|
|
|
|
if (empty($this->filter['searchAgent'])) return "";
|
2018-09-21 13:01:40 +02:00
|
|
|
return " AND LOWER(ta.alias) LIKE LOWER('%%".$this->filter['searchAgent']."%%')";
|
2018-09-04 11:51:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function getAgentStatusFilter ($status = self::TV_DEFAULT_AGENT_STATUS) {
|
|
|
|
if ($status == self::TV_DEFAULT_AGENT_STATUS)
|
2015-01-28 18:57:33 +01:00
|
|
|
$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) {
|
2018-09-04 11:51:36 +02:00
|
|
|
case AGENT_STATUS_ALL:
|
|
|
|
break;
|
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;
|
|
|
|
}
|
|
|
|
|
2018-09-05 13:48:53 +02:00
|
|
|
protected function getFirstLevelFields() {
|
|
|
|
$fields = array (
|
2018-09-05 14:01:32 +02:00
|
|
|
"g AS " . $this->L1fieldName,
|
|
|
|
"SUM(x_critical) AS total_critical_count",
|
|
|
|
"SUM(x_warning) AS total_warning_count",
|
|
|
|
"SUM(x_normal) AS total_normal_count",
|
|
|
|
"SUM(x_unknown) AS total_unknown_count",
|
|
|
|
"SUM(x_not_init) AS total_not_init_count",
|
|
|
|
"SUM(x_alerts) AS total_alerts_count",
|
|
|
|
"SUM(x_total) AS total_count"
|
2018-09-05 13:48:53 +02:00
|
|
|
);
|
|
|
|
return implode(",", array_merge($fields, $this->L1extraFields));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getFirstLevelFieldsInside() {
|
|
|
|
return array(
|
|
|
|
'warning' => array(
|
|
|
|
'header' => "0 AS x_critical, SUM(total) AS x_warning, 0 AS x_normal, 0 AS x_unknown, 0 AS x_not_init, 0 AS x_alerts, 0 AS x_total, g",
|
2018-09-11 13:22:51 +02:00
|
|
|
'condition' => "AND " . agents_get_status_clause(AGENT_STATUS_WARNING, $this->filter['show_not_init_agents'])
|
2018-09-05 13:48:53 +02:00
|
|
|
),
|
|
|
|
'critical' => array(
|
|
|
|
'header' => "SUM(total) AS x_critical, 0 AS x_warning, 0 AS x_normal, 0 AS x_unknown, 0 AS x_not_init, 0 AS x_alerts, 0 AS x_total, g",
|
2018-09-11 13:22:51 +02:00
|
|
|
'condition' => "AND " . agents_get_status_clause(AGENT_STATUS_CRITICAL, $this->filter['show_not_init_agents'])
|
2018-09-05 13:48:53 +02:00
|
|
|
),
|
|
|
|
'normal' => array(
|
|
|
|
'header' => "0 AS x_critical, 0 AS x_warning, SUM(total) AS x_normal, 0 AS x_unknown, 0 AS x_not_init, 0 AS x_alerts, 0 AS x_total, g",
|
2018-09-11 13:22:51 +02:00
|
|
|
'condition' => "AND " . agents_get_status_clause(AGENT_STATUS_NORMAL, $this->filter['show_not_init_agents'])
|
2018-09-05 13:48:53 +02:00
|
|
|
),
|
|
|
|
'unknown' => array(
|
|
|
|
'header' => "0 AS x_critical, 0 AS x_warning, 0 AS x_normal, SUM(total) AS x_unknown, 0 AS x_not_init, 0 AS x_alerts, 0 AS x_total, g",
|
2018-09-11 13:22:51 +02:00
|
|
|
'condition' => "AND " . agents_get_status_clause(AGENT_STATUS_UNKNOWN, $this->filter['show_not_init_agents'])
|
2018-09-05 13:48:53 +02:00
|
|
|
),
|
|
|
|
'not_init' => array(
|
|
|
|
'header' => "0 AS x_critical, 0 AS x_warning, 0 AS x_normal, 0 AS x_unknown, SUM(total) AS x_not_init, 0 AS x_alerts, 0 AS x_total, g",
|
2018-09-11 13:22:51 +02:00
|
|
|
'condition' => "AND " . agents_get_status_clause(AGENT_STATUS_NOT_INIT, $this->filter['show_not_init_agents'])
|
2018-09-05 13:48:53 +02:00
|
|
|
),
|
|
|
|
'alerts' => array(
|
|
|
|
'header' => "0 AS x_critical, 0 AS x_warning, 0 AS x_normal, 0 AS x_unknown, 0 AS x_not_init, SUM(total) AS x_alerts, 0 AS x_total, g",
|
|
|
|
'condition' => "AND ta.fired_count > 0"
|
|
|
|
),
|
|
|
|
'total' => array(
|
|
|
|
'header' => "0 AS x_critical, 0 AS x_warning, 0 AS x_normal, 0 AS x_unknown, 0 AS x_not_init, 0 AS x_alerts, SUM(total) AS x_total, g",
|
2018-09-11 13:22:51 +02:00
|
|
|
'condition' => "AND " . agents_get_status_clause(AGENT_STATUS_ALL, $this->filter['show_not_init_agents'])
|
2018-09-05 13:48:53 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-09-04 11:51:36 +02:00
|
|
|
protected function getInnerOrLeftJoin () {
|
|
|
|
return $this->filter['show_not_init_agents']
|
|
|
|
? "LEFT"
|
|
|
|
: "INNER";
|
|
|
|
}
|
|
|
|
|
2018-08-24 12:54:22 +02:00
|
|
|
protected function getModuleStatusFilter () {
|
2018-08-28 12:52:57 +02:00
|
|
|
$show_init_condition = ($this->filter['show_not_init_agents'])
|
|
|
|
? ""
|
|
|
|
: " AND ta.notinit_count <> ta.total_count";
|
|
|
|
|
|
|
|
if ($this->getEmptyModuleFilterStatus()) {
|
|
|
|
return $show_init_condition;
|
2018-08-24 12:54:22 +02:00
|
|
|
}
|
|
|
|
|
2018-08-28 12:52:57 +02:00
|
|
|
$field_filter = modules_get_counter_by_states($this->filter['statusModule']);
|
|
|
|
if ($field_filter === false) return " AND 1=0";
|
|
|
|
|
|
|
|
return "AND ta.$field_filter > 0" . $show_init_condition;
|
|
|
|
}
|
|
|
|
|
2018-09-04 11:51:36 +02:00
|
|
|
protected function getTagJoin () {
|
2018-10-02 13:35:48 +02:00
|
|
|
return 'INNER JOIN ttag_module ttm
|
|
|
|
ON tam.id_agente_modulo = ttm.id_agente_modulo';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getTagCondition () {
|
|
|
|
$tags = tags_get_user_applied_agent_tags($this->id, "AR");
|
|
|
|
// All tags permision, returns no condition
|
|
|
|
if ($tags === true) return "";
|
|
|
|
// No permision, do not show anything
|
|
|
|
if ($tags === false) return " AND 1=0";
|
|
|
|
$tags_sql = implode(',', $tags);
|
|
|
|
return "AND ttm.id_tag IN ($tags_sql)";;
|
2018-09-04 11:51:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getModuleStatusFilterFromTestado ($state = false, $without_ands = false) {
|
|
|
|
$selected_status = ($state !== false && $state !== self::TV_DEFAULT_AGENT_STATUS)
|
2018-08-31 09:09:54 +02:00
|
|
|
? $state
|
|
|
|
: $this->filter['statusModule'];
|
|
|
|
|
2018-09-11 13:22:51 +02:00
|
|
|
$filter = array(
|
|
|
|
modules_get_state_condition($selected_status)
|
|
|
|
);
|
2018-09-04 11:51:36 +02:00
|
|
|
if (!$this->filter['show_not_init_modules'] && $state === false) {
|
|
|
|
if (!empty($filter))
|
|
|
|
$filter[] = "(
|
|
|
|
tae.estado <> ".AGENT_MODULE_STATUS_NO_DATA."
|
|
|
|
AND tae.estado <> ".AGENT_MODULE_STATUS_NOT_INIT."
|
|
|
|
)";
|
2018-08-24 12:54:22 +02:00
|
|
|
}
|
2018-09-04 11:51:36 +02:00
|
|
|
$filter = implode(" AND ", $filter);
|
|
|
|
return ($without_ands)
|
|
|
|
? $filter
|
|
|
|
: " AND $filter ";
|
|
|
|
}
|
|
|
|
|
2018-09-10 12:08:38 +02:00
|
|
|
public function getGroupAclCondition() {
|
2018-09-04 11:51:36 +02:00
|
|
|
if (users_can_manage_group_all("AR")) return "";
|
|
|
|
|
|
|
|
$groups_str= implode(",", $this->userGroupsArray);
|
|
|
|
return " AND (
|
|
|
|
ta.id_grupo IN ($groups_str)
|
|
|
|
OR tasg.id_group IN ($groups_str)
|
|
|
|
)";
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getGroupSearchInner() {
|
|
|
|
if (empty($this->filter['searchGroup'])) return "";
|
2018-09-05 14:01:32 +02:00
|
|
|
return "INNER JOIN tgrupo tg
|
2018-09-04 11:51:36 +02:00
|
|
|
ON ta.id_grupo = tg.id_grupo
|
|
|
|
OR tasg.id_group = tg.id_grupo"
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getGroupSearchFilter() {
|
|
|
|
if (empty($this->filter['searchGroup'])) return "";
|
2018-09-21 11:48:23 +02:00
|
|
|
return " AND tg.nombre LIKE '%%" . $this->filter['searchGroup'] . "%%'";
|
2018-08-24 12:54:22 +02:00
|
|
|
}
|
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
static function cmpSortNames($a, $b) {
|
|
|
|
return strcmp($a["name"], $b["name"]);
|
|
|
|
}
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2018-08-28 12:52:57 +02:00
|
|
|
protected function getProcessedItem ($item, $server = false) {
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2015-07-06 18:26:13 +02:00
|
|
|
if (isset($processed_item['is_processed']) && $processed_item['is_processed'])
|
|
|
|
return $item;
|
2016-01-28 14:38:23 +01:00
|
|
|
|
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'];
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2018-08-31 10:51:17 +02:00
|
|
|
$processed_item['icon'] = empty($item['icon'])
|
|
|
|
? "without_group.png"
|
|
|
|
: $item['icon'].".png";
|
|
|
|
}
|
|
|
|
if (isset($item['iconHTML'])) {
|
|
|
|
$processed_item['icon'] = $item['iconHTML'];
|
2015-01-28 18:57:33 +01:00
|
|
|
}
|
|
|
|
|
2015-09-30 18:32:55 +02:00
|
|
|
if (is_metaconsole() && !empty($server)) {
|
2015-01-30 15:32:39 +01:00
|
|
|
$processed_item['serverID'] = $server['id'];
|
2015-01-28 18:57:33 +01:00
|
|
|
}
|
2016-01-28 14:38:23 +01:00
|
|
|
|
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'];
|
|
|
|
|
|
|
|
if (!empty($counters))
|
|
|
|
$processed_item['counters'] = $counters;
|
2015-12-16 11:39:00 +01:00
|
|
|
|
2015-07-06 18:26:13 +02:00
|
|
|
if (!empty($processed_item))
|
|
|
|
$processed_item['is_processed'] = true;
|
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;
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
// Remove the item
|
|
|
|
unset($items[$key]);
|
|
|
|
}
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
usort($mergedItems, array("Tree", "cmpSortNames"));
|
|
|
|
|
|
|
|
return $mergedItems;
|
|
|
|
}
|
|
|
|
|
2018-08-23 14:49:09 +02:00
|
|
|
protected function processModule (&$module, $server = false, $all_groups) {
|
2015-01-08 11:45:31 +01:00
|
|
|
global $config;
|
2017-01-24 16:02:09 +01:00
|
|
|
|
|
|
|
if (isset($module['children'])) {
|
|
|
|
foreach ($module['children'] as $i => $children) {
|
2018-08-23 14:49:09 +02:00
|
|
|
$this->processModule($module['children'][$i], $server, $all_groups);
|
2017-01-24 16:02:09 +01:00
|
|
|
}
|
|
|
|
}
|
2015-01-08 11:45:31 +01:00
|
|
|
|
2015-01-02 09:11:00 +01:00
|
|
|
$module['type'] = 'module';
|
2015-01-22 16:56:44 +01:00
|
|
|
$module['id'] = (int) $module['id'];
|
2017-01-19 12:44:44 +01:00
|
|
|
$module['name'] = io_safe_output($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
|
|
|
|
2018-09-10 15:35:11 +02:00
|
|
|
if (is_metaconsole()) {
|
|
|
|
$module['serverID'] = $this->serverID;
|
|
|
|
$module['serverName'] = $this->serverName;
|
2015-01-29 21:00:30 +01:00
|
|
|
}
|
2015-06-08 09:32:01 +02:00
|
|
|
else {
|
2015-02-13 09:50:11 +01:00
|
|
|
$module['serverName'] = false;
|
|
|
|
$module['serverID'] = false;
|
|
|
|
}
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2015-01-12 12:47:54 +01:00
|
|
|
if (!isset($module['value']))
|
|
|
|
$module['value'] = modules_get_last_value($module['id']);
|
2016-01-28 14:38:23 +01:00
|
|
|
|
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;
|
|
|
|
}
|
2016-01-28 14:38:23 +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);
|
|
|
|
}
|
|
|
|
}
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2015-01-12 12:47:54 +01:00
|
|
|
$module['statusImageHTML'] = ui_print_status_image($statusType, $statusTitle, true);
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2015-01-08 13:18:27 +01:00
|
|
|
// HTML of the server type image
|
|
|
|
$module['serverTypeHTML'] = servers_show_type($module['server_type']);
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2015-01-08 11:45:31 +01:00
|
|
|
// Link to the Module graph
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2015-03-24 19:10:09 +01:00
|
|
|
// ACL
|
|
|
|
$acl_graphs = false;
|
2015-03-23 20:51:44 +01:00
|
|
|
$module["showGraphs"] = 0;
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2015-03-24 19:10:09 +01:00
|
|
|
// Avoid the check on the metaconsole. Too slow to show/hide an icon depending on the permissions
|
2015-09-30 18:32:55 +02:00
|
|
|
if (!empty($group_id) && !is_metaconsole()) {
|
2018-08-08 11:49:54 +02:00
|
|
|
$acl_graphs = check_acl_one_of_groups($config['id_user'], $all_groups, "RR");
|
2015-03-24 19:10:09 +01:00
|
|
|
}
|
2018-08-08 11:49:54 +02:00
|
|
|
else if (!empty($all_groups)) {
|
2015-03-24 19:10:09 +01:00
|
|
|
$acl_graphs = true;
|
|
|
|
}
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2015-03-24 19:10:09 +01:00
|
|
|
if ($acl_graphs) {
|
|
|
|
$module["showGraphs"] = 1;
|
2015-01-29 21:00:30 +01:00
|
|
|
}
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2015-03-23 20:51:44 +01:00
|
|
|
if ($module["showGraphs"]) {
|
|
|
|
$graphType = return_graphtype($module['id_module_type']);
|
|
|
|
$url = ui_get_full_url("operation/agentes/stat_win.php", false, false, false);
|
|
|
|
$winHandle = dechex(crc32($module['id'].$module['name']));
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2015-03-23 20:51:44 +01:00
|
|
|
$graph_params = array(
|
|
|
|
"type" => $graphType,
|
|
|
|
"period" => SECONDS_1DAY,
|
|
|
|
"id" => $module['id'],
|
2015-04-21 10:44:50 +02:00
|
|
|
"label" => base64_encode($module['name']),
|
2015-03-23 20:51:44 +01:00
|
|
|
"refresh" => SECONDS_10MINUTES
|
|
|
|
);
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2018-09-10 15:35:11 +02:00
|
|
|
if (is_metaconsole()) {
|
2015-03-23 20:51:44 +01:00
|
|
|
// Set the server id
|
|
|
|
$graph_params["server"] = $module['serverID'];
|
|
|
|
}
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2015-03-23 20:51:44 +01:00
|
|
|
$graph_params_str = http_build_query($graph_params);
|
|
|
|
$moduleGraphURL = "$url?$graph_params_str";
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2015-01-29 21:00:30 +01:00
|
|
|
$module['moduleGraph'] = array(
|
|
|
|
'url' => $moduleGraphURL,
|
|
|
|
'handle' => $winHandle
|
|
|
|
);
|
2018-03-12 15:17:59 +01:00
|
|
|
|
|
|
|
// Info to be able to open the snapshot image new page
|
|
|
|
$module['snapshot'] = ui_get_snapshot_link(array(
|
|
|
|
'id_module' => $module['id'],
|
|
|
|
'interval' => $module['current_interval'],
|
2018-08-14 13:21:32 +02:00
|
|
|
'module_name' => $module['name'],
|
|
|
|
'id_node' => $module['serverID'] ? $module['serverID'] : 0,
|
2018-03-12 15:17:59 +01:00
|
|
|
), true);
|
2015-01-29 21:00:30 +01:00
|
|
|
}
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2015-01-30 20:06:49 +01:00
|
|
|
// Alerts fired image
|
2018-09-04 11:51:36 +02:00
|
|
|
if ((bool)$module['alerts']) {
|
2015-01-30 20:06:49 +01:00
|
|
|
$module['alertsImageHTML'] = html_print_image("images/bell.png", true, array("title" => __('Module alerts')));
|
|
|
|
}
|
2015-01-02 09:11:00 +01:00
|
|
|
}
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2015-01-29 21:00:30 +01:00
|
|
|
protected function processModules (&$modules, $server = false) {
|
2018-08-23 14:49:09 +02:00
|
|
|
if (!empty($modules)) {
|
|
|
|
$all_groups = modules_get_agent_groups($modules[0]['id']);
|
|
|
|
}
|
2015-01-21 17:37:51 +01:00
|
|
|
foreach ($modules as $iterator => $module) {
|
2018-08-23 14:49:09 +02:00
|
|
|
$this->processModule($modules[$iterator], $server, $all_groups);
|
2015-01-02 09:11:00 +01:00
|
|
|
}
|
|
|
|
}
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2015-01-29 21:00:30 +01:00
|
|
|
protected function processAgent (&$agent, $server = false) {
|
|
|
|
global $config;
|
2016-01-28 14:38:23 +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'];
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2015-01-21 17:37:51 +01:00
|
|
|
$agent['rootID'] = $this->rootID;
|
|
|
|
$agent['rootType'] = $this->rootType;
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2015-09-30 18:32:55 +02:00
|
|
|
if (is_metaconsole()) {
|
2015-04-17 16:12:51 +02:00
|
|
|
if (isset($agent['server_id']))
|
|
|
|
$agent['serverID'] = $agent['server_id'];
|
|
|
|
else if (!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();
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2018-08-28 12:52:57 +02:00
|
|
|
$agent['counters']['unknown'] = isset($agent['unknown_count']) ? $agent['unknown_count'] : 0;
|
|
|
|
$agent['counters']['critical'] = isset($agent['critical_count']) ? $agent['critical_count'] : 0;
|
|
|
|
$agent['counters']['warning'] = isset($agent['warning_count']) ? $agent['warning_count'] : 0;
|
|
|
|
$agent['counters']['not_init'] = isset($agent['notinit_count']) ? $agent['notinit_count'] : 0;
|
|
|
|
$agent['counters']['ok'] = isset($agent['normal_count']) ? $agent['normal_count'] : 0;
|
|
|
|
$agent['counters']['total'] = isset($agent['total_count']) ? $agent['total_count'] : 0;
|
|
|
|
$agent['counters']['alerts'] = isset($agent['fired_count']) ? $agent['fired_count'] : 0;
|
2015-01-14 17:56:42 +01:00
|
|
|
}
|
2016-01-28 14:38:23 +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']);
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2015-01-12 11:07:16 +01:00
|
|
|
// Alerts fired image
|
|
|
|
$agent["alertImageHTML"] = agents_tree_view_alert_img_ball($agent['counters']['alerts']);
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2018-08-28 12:52:57 +02:00
|
|
|
// search module recalculate counters
|
2018-08-31 09:09:54 +02:00
|
|
|
if(array_key_exists('state_normal', $agent)){
|
|
|
|
$agent['counters']['unknown'] = $agent['state_unknown'];
|
|
|
|
$agent['counters']['critical'] = $agent['state_critical'];
|
|
|
|
$agent['counters']['warning'] = $agent['state_warning'];
|
|
|
|
$agent['counters']['not_init'] = $agent['state_notinit'];
|
|
|
|
$agent['counters']['ok'] = $agent['state_normal'];
|
|
|
|
$agent['counters']['total'] = $agent['state_total'];
|
|
|
|
|
2018-08-28 12:52:57 +02:00
|
|
|
$agent['critical_count'] = $agent['counters']['critical'];
|
|
|
|
$agent['warning_count'] = $agent['counters']['warning'];
|
|
|
|
$agent['unknown_count'] = $agent['counters']['unknown'];
|
|
|
|
$agent['notinit_count'] = $agent['counters']['not_init'];
|
|
|
|
$agent['normal_count'] = $agent['counters']['ok'];
|
|
|
|
$agent['total_count'] = $agent['counters']['total'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$this->getEmptyModuleFilterStatus()) {
|
|
|
|
$agent['counters']['unknown'] = 0;
|
|
|
|
$agent['counters']['critical'] = 0;
|
|
|
|
$agent['counters']['warning'] = 0;
|
|
|
|
$agent['counters']['not_init'] = 0;
|
|
|
|
$agent['counters']['ok'] = 0;
|
|
|
|
$agent['counters']['total'] = 0;
|
|
|
|
switch($this->filter['statusModule']) {
|
|
|
|
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
|
|
|
|
case AGENT_MODULE_STATUS_CRITICAL_BAD:
|
|
|
|
$agent['counters']['critical'] = $agent['critical_count'];
|
|
|
|
$agent['counters']['total'] = $agent['critical_count'];
|
|
|
|
break;
|
|
|
|
case AGENT_MODULE_STATUS_WARNING_ALERT:
|
|
|
|
case AGENT_MODULE_STATUS_WARNING:
|
|
|
|
$agent['counters']['warning'] = $agent['warning_count'];
|
|
|
|
$agent['counters']['total'] = $agent['warning_count'];
|
|
|
|
break;
|
|
|
|
case AGENT_MODULE_STATUS_UNKNOWN:
|
|
|
|
$agent['counters']['unknown'] = $agent['unknown_count'];
|
|
|
|
$agent['counters']['total'] = $agent['unknown_count'];
|
|
|
|
break;
|
|
|
|
case AGENT_MODULE_STATUS_NO_DATA:
|
|
|
|
case AGENT_MODULE_STATUS_NOT_INIT:
|
|
|
|
$agent['counters']['not_init'] = $agent['notinit_count'];
|
|
|
|
$agent['counters']['total'] = $agent['notinit_count'];
|
|
|
|
break;
|
|
|
|
case AGENT_MODULE_STATUS_NORMAL_ALERT:
|
|
|
|
case AGENT_MODULE_STATUS_NORMAL:
|
|
|
|
$agent['counters']['ok'] = $agent['normal_count'];
|
|
|
|
$agent['counters']['total'] = $agent['normal_count'];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$this->filter['show_not_init_modules']) {
|
|
|
|
$agent['counters']['total'] -= $agent['counters']['not_init'];
|
|
|
|
$agent['counters']['not_init'] = 0;
|
|
|
|
}
|
|
|
|
|
2015-01-29 21:00:30 +01:00
|
|
|
// Quiet image
|
|
|
|
if (isset($agent['quiet']) && $agent['quiet'])
|
2018-06-26 12:31:23 +02:00
|
|
|
$agent['quietImageHTML'] = html_print_image("/images/dot_blue.png", true, array("title" => __('Quiet')));
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2015-01-02 09:11:00 +01:00
|
|
|
// 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;
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-28 14:38:23 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2018-09-04 11:51:36 +02:00
|
|
|
protected function getData() {
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2015-01-12 11:07:16 +01:00
|
|
|
}
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2018-09-05 14:01:32 +02:00
|
|
|
protected function getFirstLevel() {
|
2018-09-04 11:51:36 +02:00
|
|
|
$sql = $this->getFirstLevelSql();
|
|
|
|
$items = db_get_all_rows_sql($sql);
|
|
|
|
if ($items === false) $items = array();
|
|
|
|
|
|
|
|
$this->tree = $this->getProcessedItemsFirstLevel($items);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getProcessedItemsFirstLevel($items){
|
|
|
|
$processed_items = array();
|
|
|
|
foreach ($items as $key => $item) {
|
2018-09-05 14:01:32 +02:00
|
|
|
$processed_item = $this->getProcessedItem($item);
|
|
|
|
$processed_items[] = $processed_item;
|
2018-09-04 11:51:36 +02:00
|
|
|
}
|
|
|
|
return $processed_items;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getFirstLevelSql() {
|
|
|
|
|
2018-09-05 14:01:32 +02:00
|
|
|
$fields = $this->getFirstLevelFields();
|
|
|
|
$field_name_sql = $this->L1fieldNameSql;
|
|
|
|
$inside_fields = $this->getFirstLevelFieldsInside();
|
2018-09-04 11:51:36 +02:00
|
|
|
$inner = $this->L1inner;
|
|
|
|
$inner_inside = $this->L1innerInside;
|
2018-09-05 14:01:32 +02:00
|
|
|
$order_by_final = $this->L1orderByFinal;
|
|
|
|
|
|
|
|
$group_inner = $this->getGroupSearchInner();
|
|
|
|
$group_acl = $this->getGroupAclCondition();
|
|
|
|
$group_search_filter = $this->getGroupSearchFilter();
|
|
|
|
$agent_search_filter = $this->getAgentSearchFilter();
|
|
|
|
$agent_status_filter = $this->getAgentStatusFilter();
|
|
|
|
$module_search_filter = $this->getModuleSearchFilter();
|
|
|
|
$module_status_inner = "";
|
|
|
|
$module_status_filter = $this->getModuleStatusFilterFromTestado();
|
|
|
|
if (!empty($module_status_filter)) {
|
|
|
|
$module_status_inner = "
|
|
|
|
INNER JOIN tagente_estado tae
|
|
|
|
ON tae.id_agente_modulo = tam.id_agente_modulo";
|
2018-09-04 11:51:36 +02:00
|
|
|
}
|
|
|
|
|
2018-09-05 14:01:32 +02:00
|
|
|
$sql_model = "SELECT %s FROM
|
|
|
|
(
|
|
|
|
SELECT COUNT(DISTINCT(ta.id_agente)) AS total, $field_name_sql AS g
|
|
|
|
FROM tagente ta
|
|
|
|
LEFT JOIN tagent_secondary_group tasg
|
|
|
|
ON ta.id_agente = tasg.id_agent
|
|
|
|
INNER JOIN tagente_modulo tam
|
|
|
|
ON ta.id_agente = tam.id_agente
|
2018-09-04 11:51:36 +02:00
|
|
|
$inner_inside
|
2018-09-05 14:01:32 +02:00
|
|
|
$module_status_inner
|
|
|
|
$group_inner
|
|
|
|
WHERE ta.disabled = 0
|
|
|
|
AND tam.disabled = 0
|
|
|
|
%s
|
|
|
|
$agent_search_filter
|
|
|
|
$agent_status_filter
|
|
|
|
$module_search_filter
|
|
|
|
$module_status_filter
|
|
|
|
$group_search_filter
|
|
|
|
$group_acl
|
|
|
|
GROUP BY $field_name_sql
|
|
|
|
) x GROUP BY g";
|
|
|
|
$sql_array = array();
|
|
|
|
foreach ($inside_fields as $inside_field) {
|
|
|
|
$sql_array[] = sprintf(
|
|
|
|
$sql_model,
|
|
|
|
$inside_field['header'],
|
|
|
|
$inside_field['condition']
|
|
|
|
);
|
2018-09-04 11:51:36 +02:00
|
|
|
}
|
2018-09-05 14:01:32 +02:00
|
|
|
$sql = "SELECT $fields FROM (" . implode(" UNION ALL ", $sql_array) . ") x2
|
|
|
|
$inner
|
|
|
|
GROUP BY g
|
|
|
|
ORDER BY $order_by_final";
|
|
|
|
return $sql;
|
2018-09-04 11:51:36 +02:00
|
|
|
}
|
|
|
|
|
2018-09-05 14:01:32 +02:00
|
|
|
protected function getSecondLevel() {
|
|
|
|
$sql = $this->getSecondLevelSql();
|
2018-09-04 11:51:36 +02:00
|
|
|
$data = db_process_sql($sql);
|
|
|
|
if (empty($data)) {
|
2018-09-05 14:01:32 +02:00
|
|
|
$this->tree = array();
|
|
|
|
return;
|
|
|
|
}
|
2018-09-04 11:51:36 +02:00
|
|
|
$this->processAgents($data);
|
|
|
|
|
|
|
|
$this->tree = $data;
|
2018-09-05 14:01:32 +02:00
|
|
|
}
|
2018-09-04 11:51:36 +02:00
|
|
|
|
|
|
|
protected function getSecondLevelSql() {
|
|
|
|
$columns = sprintf("ta.id_agente AS id, ta.nombre AS name, ta.alias,
|
|
|
|
ta.fired_count, ta.normal_count, ta.warning_count,
|
|
|
|
ta.critical_count, ta.unknown_count, ta.notinit_count,
|
|
|
|
ta.total_count, ta.quiet,
|
|
|
|
SUM(if(%s, 1, 0)) as state_critical,
|
|
|
|
SUM(if(%s, 1, 0)) as state_warning,
|
|
|
|
SUM(if(%s, 1, 0)) as state_unknown,
|
|
|
|
SUM(if(%s, 1, 0)) as state_notinit,
|
|
|
|
SUM(if(%s, 1, 0)) as state_normal,
|
2018-09-05 18:28:31 +02:00
|
|
|
SUM(if(%s AND tae.estado IS NOT NULL, 1, 0)) as state_total
|
2018-09-04 11:51:36 +02:00
|
|
|
",
|
|
|
|
$this->getModuleStatusFilterFromTestado(AGENT_MODULE_STATUS_CRITICAL_ALERT, true),
|
|
|
|
$this->getModuleStatusFilterFromTestado(AGENT_MODULE_STATUS_WARNING_ALERT, true),
|
|
|
|
$this->getModuleStatusFilterFromTestado(AGENT_MODULE_STATUS_UNKNOWN, true),
|
|
|
|
$this->getModuleStatusFilterFromTestado(AGENT_MODULE_STATUS_NO_DATA, true),
|
|
|
|
$this->getModuleStatusFilterFromTestado(AGENT_MODULE_STATUS_NORMAL, true),
|
|
|
|
$this->getModuleStatusFilterFromTestado(self::TV_DEFAULT_AGENT_STATUS, true)
|
|
|
|
);
|
|
|
|
|
|
|
|
$inner_or_left = $this->getInnerOrLeftJoin();
|
|
|
|
$group_inner = $this->getGroupSearchInner();
|
|
|
|
$group_acl = $this->getGroupAclCondition();
|
|
|
|
$group_search_filter = $this->getGroupSearchFilter();
|
|
|
|
$agent_search_filter = $this->getAgentSearchFilter();
|
|
|
|
$agent_status_filter = $this->getAgentStatusFilter();
|
|
|
|
$module_search_filter = $this->getModuleSearchFilter();
|
|
|
|
$module_status_filter = $this->getModuleStatusFilter();
|
|
|
|
|
|
|
|
$condition = $this->L2condition;
|
|
|
|
$condition_inside = $this->L2conditionInside;
|
|
|
|
$inner = $this->L2inner;
|
|
|
|
|
|
|
|
$sql = "SELECT $columns
|
|
|
|
FROM tagente ta
|
|
|
|
$inner_or_left JOIN tagente_modulo tam
|
|
|
|
ON ta.id_agente = tam.id_agente
|
2018-09-05 18:28:31 +02:00
|
|
|
AND tam.disabled = 0
|
|
|
|
$inner_or_left JOIN tagente_estado tae
|
2018-09-04 11:51:36 +02:00
|
|
|
ON tae.id_agente_modulo = tam.id_agente_modulo
|
|
|
|
$inner
|
|
|
|
WHERE ta.id_agente IN
|
|
|
|
(
|
|
|
|
SELECT ta.id_agente
|
|
|
|
FROM tagente ta
|
|
|
|
LEFT JOIN tagent_secondary_group tasg
|
|
|
|
ON tasg.id_agent = ta.id_agente
|
|
|
|
$group_inner
|
|
|
|
WHERE ta.disabled = 0
|
|
|
|
$group_acl
|
|
|
|
$group_search_filter
|
|
|
|
$condition_inside
|
|
|
|
)
|
2018-09-05 18:28:31 +02:00
|
|
|
AND ta.disabled = 0
|
2018-09-04 11:51:36 +02:00
|
|
|
$condition
|
|
|
|
$agent_search_filter
|
|
|
|
$agent_status_filter
|
|
|
|
$module_search_filter
|
|
|
|
$module_status_filter
|
|
|
|
GROUP BY ta.id_agente
|
|
|
|
ORDER BY ta.alias ASC, ta.id_agente ASC
|
|
|
|
";
|
|
|
|
|
|
|
|
return $sql;
|
|
|
|
}
|
|
|
|
|
2018-09-05 14:01:32 +02:00
|
|
|
protected function getThirdLevel() {
|
|
|
|
$sql = $this->getThirdLevelSql();
|
2018-09-04 11:51:36 +02:00
|
|
|
$data = db_process_sql($sql);
|
|
|
|
if (empty($data)) {
|
2018-09-05 14:01:32 +02:00
|
|
|
$this->tree = array();
|
|
|
|
return;
|
2018-09-05 09:54:28 +02:00
|
|
|
}
|
|
|
|
$data = $this->getProcessedModules($data);
|
|
|
|
$this->processModules($data);
|
2018-09-04 11:51:36 +02:00
|
|
|
|
|
|
|
$this->tree = $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getThirdLevelSql() {
|
|
|
|
// Get the server id
|
2018-09-05 14:01:32 +02:00
|
|
|
$serverID = $this->serverID;
|
2018-09-04 11:51:36 +02:00
|
|
|
|
2018-09-05 14:01:32 +02:00
|
|
|
$group_acl = $this->getGroupAclCondition();
|
2018-09-04 11:51:36 +02:00
|
|
|
$agent_search_filter = $this->getAgentSearchFilter();
|
|
|
|
$agent_status_filter = $this->getAgentStatusFilter();
|
|
|
|
$module_search_filter = $this->getModuleSearchFilter();
|
2018-09-05 14:01:32 +02:00
|
|
|
$module_status_filter = $this->getModuleStatusFilterFromTestado();
|
|
|
|
$agent_filter = "AND ta.id_agente = " . $this->id;
|
2018-10-02 13:35:48 +02:00
|
|
|
$tag_condition = $this->getTagCondition();
|
2018-10-16 13:29:00 +02:00
|
|
|
$tag_join = empty($tag_condition) && (!$this->L3forceTagCondition)
|
|
|
|
? ''
|
|
|
|
: $this->getTagJoin();
|
2018-09-04 11:51:36 +02:00
|
|
|
|
|
|
|
$condition = $this->L2condition;
|
|
|
|
$inner = $this->L2inner;
|
|
|
|
|
2018-09-05 14:01:32 +02:00
|
|
|
$columns = 'DISTINCT(tam.id_agente_modulo) AS id, tam.nombre AS name,
|
2018-09-05 09:54:28 +02:00
|
|
|
tam.id_tipo_modulo, tam.id_modulo, tae.estado, tae.datos,
|
|
|
|
tam.parent_module_id AS parent, tatm.id AS alerts';
|
2018-09-04 11:51:36 +02:00
|
|
|
|
2018-09-05 14:01:32 +02:00
|
|
|
$sql = "SELECT $columns
|
|
|
|
FROM tagente_modulo tam
|
|
|
|
$tag_join
|
|
|
|
INNER JOIN tagente_estado tae
|
|
|
|
ON tam.id_agente_modulo = tae.id_agente_modulo
|
|
|
|
INNER JOIN tagente ta
|
|
|
|
ON tam.id_agente = ta.id_agente
|
|
|
|
LEFT JOIN tagent_secondary_group tasg
|
|
|
|
ON ta.id_agente = tasg.id_agent
|
|
|
|
LEFT JOIN talert_template_modules tatm
|
|
|
|
ON tatm.id_agent_module = tam.id_agente_modulo
|
2018-09-04 11:51:36 +02:00
|
|
|
$inner
|
2018-09-05 14:01:32 +02:00
|
|
|
WHERE tam.disabled = 0 AND ta.disabled = 0
|
|
|
|
$condition
|
|
|
|
$agent_filter
|
|
|
|
$group_acl
|
|
|
|
$agent_search_filter
|
|
|
|
$agent_status_filter
|
|
|
|
$module_status_filter
|
|
|
|
$module_search_filter
|
2018-10-02 13:35:48 +02:00
|
|
|
$tag_condition
|
2018-09-05 09:54:28 +02:00
|
|
|
ORDER BY tam.nombre ASC, tam.id_agente_modulo ASC";
|
2018-09-05 14:01:32 +02:00
|
|
|
return $sql;
|
2018-09-04 11:51:36 +02:00
|
|
|
}
|
|
|
|
|
2014-12-17 18:58:34 +01:00
|
|
|
public function getJSON() {
|
|
|
|
$this->getData();
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2014-12-16 16:39:00 +01:00
|
|
|
return json_encode($this->tree);
|
|
|
|
}
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2014-12-17 18:58:34 +01:00
|
|
|
public function getArray() {
|
|
|
|
$this->getData();
|
2016-01-28 14:38:23 +01:00
|
|
|
|
2014-12-17 18:58:34 +01:00
|
|
|
return $this->tree;
|
|
|
|
}
|
2016-01-28 11:09:09 +01:00
|
|
|
|
2018-09-04 11:51:36 +02:00
|
|
|
static function name2symbol($name) {
|
|
|
|
return 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($name)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
static function symbol2name($name) {
|
|
|
|
$symbols = ' !"#$%&\'()*+,./:;<=>?@[\\]^{|}~';
|
|
|
|
for ($i = 0; $i < strlen($symbols); $i++) {
|
|
|
|
$name = str_replace('_articapandora_' .
|
|
|
|
ord(substr($symbols, $i, 1)) .'_pandoraartica_',
|
|
|
|
substr($symbols, $i, 1), $name);
|
|
|
|
}
|
|
|
|
return io_safe_input($name);
|
|
|
|
}
|
|
|
|
|
2017-01-23 12:55:15 +01:00
|
|
|
protected function getProcessedModules($modules_tree) {
|
2018-09-05 09:54:28 +02:00
|
|
|
return $modules_tree;
|
2017-01-23 12:55:15 +01:00
|
|
|
}
|
|
|
|
|
2014-12-16 16:39:00 +01:00
|
|
|
}
|
|
|
|
?>
|