2019-02-22 13:07:47 +01:00
|
|
|
<?php
|
2020-07-02 14:53:33 +02:00
|
|
|
/**
|
|
|
|
* Service tree view.
|
|
|
|
*
|
|
|
|
* @category Class
|
|
|
|
* @package Pandora FMS
|
|
|
|
* @subpackage Enterprise
|
|
|
|
* @version 1.0.0
|
|
|
|
* @license See below
|
|
|
|
*
|
|
|
|
* ______ ___ _______ _______ ________
|
|
|
|
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
|
|
|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
|
|
|
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
|
|
|
*
|
|
|
|
* ============================================================================
|
2020-11-27 13:52:35 +01:00
|
|
|
* Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
|
2020-07-02 14:53:33 +02:00
|
|
|
* 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 General Public License
|
|
|
|
* as published by the Free Software Foundation for 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.
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Begin.
|
2019-02-22 13:07:47 +01:00
|
|
|
global $config;
|
|
|
|
|
2019-02-27 10:28:36 +01:00
|
|
|
require_once $config['homedir'].'/include/class/Tree.class.php';
|
|
|
|
|
2020-07-01 20:50:07 +02:00
|
|
|
use PandoraFMS\Enterprise\Service;
|
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
/**
|
|
|
|
* Class to handle service tree view.
|
|
|
|
*/
|
2019-02-27 10:28:36 +01:00
|
|
|
class TreeService extends Tree
|
|
|
|
{
|
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
/**
|
|
|
|
* Some definitions.
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
2019-02-27 10:28:36 +01:00
|
|
|
protected $propagateCounters = true;
|
2019-02-22 13:07:47 +01:00
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
/**
|
|
|
|
* Some definitions.
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
2019-02-27 10:28:36 +01:00
|
|
|
protected $displayAllGroups = false;
|
2019-02-22 13:07:47 +01:00
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
/**
|
|
|
|
* If element is stored on remote node, this value will be greater than 0.
|
|
|
|
*
|
|
|
|
* @var integer
|
|
|
|
*/
|
|
|
|
public $metaID = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Flag to avoid double connection to node.
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
private $connectedToNode = false;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builder.
|
|
|
|
*
|
|
|
|
* @param mixed $type Type.
|
|
|
|
* @param string $rootType RootType.
|
|
|
|
* @param integer $id Id.
|
|
|
|
* @param integer $rootID RootID.
|
|
|
|
* @param boolean $serverID ServerID.
|
|
|
|
* @param string $childrenMethod ChildrenMethod.
|
|
|
|
* @param string $access Access.
|
|
|
|
* @param integer $id_server_meta Id_server_meta.
|
|
|
|
*/
|
2020-07-01 20:50:07 +02:00
|
|
|
public function __construct(
|
|
|
|
$type,
|
|
|
|
$rootType='',
|
|
|
|
$id=-1,
|
|
|
|
$rootID=-1,
|
|
|
|
$serverID=false,
|
|
|
|
$childrenMethod='on_demand',
|
|
|
|
$access='AR',
|
|
|
|
$id_server_meta=0
|
|
|
|
) {
|
2019-02-27 10:28:36 +01:00
|
|
|
global $config;
|
2019-02-22 13:07:47 +01:00
|
|
|
|
2020-07-01 20:50:07 +02:00
|
|
|
if ($id_server_meta > 0) {
|
|
|
|
$this->metaID = $id_server_meta;
|
2020-07-02 14:53:33 +02:00
|
|
|
$this->serverID = $id_server_meta;
|
2020-07-01 20:50:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
parent::__construct(
|
|
|
|
$type,
|
|
|
|
$rootType,
|
|
|
|
$id,
|
|
|
|
$rootID,
|
|
|
|
$serverID,
|
|
|
|
$childrenMethod,
|
|
|
|
$access,
|
|
|
|
$id_server_meta
|
|
|
|
);
|
2019-02-22 13:07:47 +01:00
|
|
|
|
2019-02-27 10:28:36 +01:00
|
|
|
$this->L1fieldName = 'id_group';
|
|
|
|
$this->L1extraFields = [
|
|
|
|
'ts.name AS `name`',
|
|
|
|
'ts.id AS `sid`',
|
|
|
|
];
|
2019-02-22 13:07:47 +01:00
|
|
|
|
2019-02-27 10:28:36 +01:00
|
|
|
$this->filter['statusAgent'] = AGENT_STATUS_ALL;
|
2019-02-22 13:07:47 +01:00
|
|
|
|
2019-02-27 10:28:36 +01:00
|
|
|
$this->avoid_condition = true;
|
2019-02-22 13:07:47 +01:00
|
|
|
|
2019-02-27 10:28:36 +01:00
|
|
|
$this->L2inner = 'LEFT JOIN tservice_element tse
|
2019-02-22 13:07:47 +01:00
|
|
|
ON tse.id_agent = ta.id_agente';
|
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
$this->L2condition = sprintf(
|
|
|
|
' AND tse.id_service=%d AND tse.id_server_meta=0 ',
|
|
|
|
$this->id
|
|
|
|
);
|
2019-02-22 13:07:47 +01:00
|
|
|
|
2019-02-27 10:28:36 +01:00
|
|
|
}
|
2019-02-22 13:07:47 +01:00
|
|
|
|
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
/**
|
|
|
|
* Setter (propagate counters).
|
|
|
|
*
|
|
|
|
* @param boolean $value Set.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-02-27 10:28:36 +01:00
|
|
|
public function setPropagateCounters($value)
|
|
|
|
{
|
|
|
|
$this->propagateCounters = (bool) $value;
|
|
|
|
}
|
2019-02-22 13:07:47 +01:00
|
|
|
|
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
/**
|
|
|
|
* Set display all groups.
|
|
|
|
*
|
|
|
|
* @param boolean $value Set.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-02-27 10:28:36 +01:00
|
|
|
public function setDisplayAllGroups($value)
|
|
|
|
{
|
|
|
|
$this->displayAllGroups = (bool) $value;
|
|
|
|
}
|
2019-02-22 13:07:47 +01:00
|
|
|
|
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
/**
|
|
|
|
* Generates tree data.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-02-27 10:28:36 +01:00
|
|
|
protected function getData()
|
|
|
|
{
|
2020-07-01 20:50:07 +02:00
|
|
|
if (is_metaconsole() === true && $this->metaID > 0) {
|
|
|
|
// Impersonate node.
|
|
|
|
\enterprise_include_once('include/functions_metaconsole.php');
|
|
|
|
\enterprise_hook(
|
|
|
|
'metaconsole_connect',
|
|
|
|
[
|
|
|
|
null,
|
|
|
|
$this->metaID,
|
|
|
|
]
|
|
|
|
);
|
2020-07-02 14:53:33 +02:00
|
|
|
$this->connectedToNode = true;
|
2020-07-01 20:50:07 +02:00
|
|
|
}
|
|
|
|
|
2019-02-27 10:28:36 +01:00
|
|
|
if ($this->id == -1) {
|
|
|
|
$this->getFirstLevel();
|
|
|
|
} else if ($this->type == 'services') {
|
|
|
|
$this->getSecondLevel();
|
|
|
|
} else if ($this->type == 'agent') {
|
2021-06-25 11:37:09 +02:00
|
|
|
$this->filter['showDisabled'] = true;
|
2019-02-27 10:28:36 +01:00
|
|
|
$this->getThirdLevel();
|
|
|
|
}
|
2020-07-01 20:50:07 +02:00
|
|
|
|
|
|
|
if (is_metaconsole() === true && $this->metaID > 0) {
|
|
|
|
// Restore connection.
|
|
|
|
\enterprise_hook('metaconsole_restore_db');
|
|
|
|
}
|
2019-02-27 10:28:36 +01:00
|
|
|
}
|
2019-02-22 13:07:47 +01:00
|
|
|
|
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
/**
|
|
|
|
* Generates first level data.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-02-27 10:28:36 +01:00
|
|
|
protected function getFirstLevel()
|
|
|
|
{
|
2019-06-17 13:38:05 +02:00
|
|
|
global $config;
|
|
|
|
|
2019-02-27 10:28:36 +01:00
|
|
|
$processed_items = $this->getProcessedServices();
|
|
|
|
$ids = array_keys($processed_items);
|
2019-02-22 13:07:47 +01:00
|
|
|
|
2019-02-27 10:28:36 +01:00
|
|
|
$filter = ['id' => $ids];
|
2019-02-22 13:07:47 +01:00
|
|
|
|
2019-02-27 10:28:36 +01:00
|
|
|
$own_info = get_user_info($config['id_user']);
|
2019-02-22 13:07:47 +01:00
|
|
|
|
2019-02-27 10:28:36 +01:00
|
|
|
if ($own_info['is_admin'] || check_acl($config['id_user'], 0, 'PM')) {
|
|
|
|
$display_all_services = true;
|
|
|
|
} else {
|
|
|
|
$display_all_services = false;
|
|
|
|
}
|
2019-02-22 13:07:47 +01:00
|
|
|
|
2019-02-27 10:28:36 +01:00
|
|
|
$this->tree = [];
|
2019-02-22 13:07:47 +01:00
|
|
|
|
2019-02-27 10:28:36 +01:00
|
|
|
$services = services_get_services($filter, false, $display_all_services);
|
2019-02-22 13:07:47 +01:00
|
|
|
|
2019-02-27 10:28:36 +01:00
|
|
|
foreach ($services as $row) {
|
|
|
|
$status = services_get_status($row, true);
|
2019-02-22 13:07:47 +01:00
|
|
|
|
2019-02-27 10:28:36 +01:00
|
|
|
switch ($status) {
|
|
|
|
case SERVICE_STATUS_NORMAL:
|
2021-09-21 13:22:37 +02:00
|
|
|
$processed_items[$row['id']]['statusImageHTML'] = '<img src="'.ui_get_full_url('images/status_sets/default/agent_ok_ball.png').'" data-title="NORMAL status." data-use_title_for_force_title="1" class="forced_title" alt="NORMAL status." />';
|
2019-02-27 10:28:36 +01:00
|
|
|
break;
|
2019-02-22 13:07:47 +01:00
|
|
|
|
2019-02-27 10:28:36 +01:00
|
|
|
case SERVICE_STATUS_CRITICAL:
|
2021-09-21 13:22:37 +02:00
|
|
|
$processed_items[$row['id']]['statusImageHTML'] = '<img src="'.ui_get_full_url('images/status_sets/default/agent_critical_ball.png').'" data-title="CRITICAL status." data-use_title_for_force_title="1" class="forced_title" alt="CRITICAL status." />';
|
2019-02-27 10:28:36 +01:00
|
|
|
break;
|
2019-02-22 13:07:47 +01:00
|
|
|
|
2019-02-27 10:28:36 +01:00
|
|
|
case SERVICE_STATUS_WARNING:
|
2021-09-21 13:22:37 +02:00
|
|
|
$processed_items[$row['id']]['statusImageHTML'] = '<img src="'.ui_get_full_url('images/status_sets/default/agent_warning_ball.png').'" data-title="WARNING status." data-use_title_for_force_title="1" class="forced_title" alt="WARNING status." />';
|
2019-02-27 10:28:36 +01:00
|
|
|
break;
|
2019-02-22 13:07:47 +01:00
|
|
|
|
2019-02-27 10:28:36 +01:00
|
|
|
case SERVICE_STATUS_UNKNOWN:
|
|
|
|
default:
|
2021-09-21 13:22:37 +02:00
|
|
|
$processed_items[$row['id']]['statusImageHTML'] = '<img src="'.ui_get_full_url('images/status_sets/default/agent_no_data_ball.png').'" data-title="UNKNOWN status." data-use_title_for_force_title="1" class="forced_title" alt="UNKNOWN status." />';
|
2019-02-27 10:28:36 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-02-22 13:07:47 +01:00
|
|
|
|
2019-02-27 10:28:36 +01:00
|
|
|
$this->tree = $processed_items;
|
|
|
|
}
|
2019-02-22 13:07:47 +01:00
|
|
|
|
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
/**
|
|
|
|
* Retrieve root services.
|
|
|
|
*
|
|
|
|
* @return array Of root services.
|
|
|
|
*/
|
2019-02-27 10:28:36 +01:00
|
|
|
protected function getProcessedServices()
|
|
|
|
{
|
2020-03-11 15:00:35 +01:00
|
|
|
$is_favourite = $this->getServiceFavouriteFilter();
|
2022-05-23 12:51:32 +02:00
|
|
|
$service_search = $this->getServiceNameSearchFilter();
|
2020-03-11 15:00:35 +01:00
|
|
|
|
2019-02-27 10:28:36 +01:00
|
|
|
if (users_can_manage_group_all('AR')) {
|
|
|
|
$groups_acl = '';
|
|
|
|
} else {
|
|
|
|
$groups_acl = 'AND ts.id_group IN ('.implode(',', $this->userGroupsArray).')';
|
|
|
|
}
|
2019-02-22 13:07:47 +01:00
|
|
|
|
2022-05-23 12:51:32 +02:00
|
|
|
$exclude_children = 'ts.id NOT IN (
|
|
|
|
SELECT DISTINCT id_service_child
|
|
|
|
FROM tservice_element
|
|
|
|
WHERE id_server_meta = 0
|
|
|
|
)';
|
|
|
|
|
|
|
|
if ($service_search !== '') {
|
|
|
|
$exclude_children = '1=1';
|
|
|
|
}
|
|
|
|
|
2019-02-27 10:28:36 +01:00
|
|
|
$sql = sprintf(
|
2020-07-01 20:50:07 +02:00
|
|
|
'SELECT
|
|
|
|
ts.id,
|
|
|
|
ts.id_agent_module,
|
|
|
|
ts.name,
|
|
|
|
ts.name as `alias`,
|
2020-10-26 12:05:37 +01:00
|
|
|
ts.description as `description`,
|
2020-07-01 20:50:07 +02:00
|
|
|
ts.id as `rootID`,
|
|
|
|
"services" as `rootType`,
|
|
|
|
"services" as `type`,
|
|
|
|
ts.quiet,
|
|
|
|
SUM(if((tse.id_agent<>0), 1, 0)) AS `total_agents`,
|
|
|
|
SUM(if((tse.id_agente_modulo<>0), 1, 0)) AS `total_modules`,
|
2020-07-06 11:10:43 +02:00
|
|
|
SUM(if((tse.id_service_child<>0), 1, 0)) AS `total_services`,
|
|
|
|
SUM(if((tse.rules != ""), 1, 0)) AS `total_dynamic`
|
2020-07-01 20:50:07 +02:00
|
|
|
FROM tservice ts
|
|
|
|
LEFT JOIN tservice_element tse
|
|
|
|
ON tse.id_service = ts.id
|
2022-05-23 12:51:32 +02:00
|
|
|
WHERE %s
|
|
|
|
%s
|
2020-07-01 20:50:07 +02:00
|
|
|
%s
|
|
|
|
%s
|
|
|
|
GROUP BY ts.id',
|
2022-05-23 12:51:32 +02:00
|
|
|
$exclude_children,
|
2020-07-01 20:50:07 +02:00
|
|
|
$is_favourite,
|
2022-05-23 12:51:32 +02:00
|
|
|
$service_search,
|
2020-07-01 20:50:07 +02:00
|
|
|
$groups_acl
|
2019-02-27 10:28:36 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$stats = db_get_all_rows_sql($sql);
|
|
|
|
|
|
|
|
$services = [];
|
|
|
|
|
|
|
|
foreach ($stats as $service) {
|
2020-07-06 11:10:43 +02:00
|
|
|
$services[$service['id']] = $this->getProcessedItem(
|
|
|
|
$services[$service['id']]
|
|
|
|
);
|
|
|
|
$n_items = ($service['total_services'] + $service['total_agents']);
|
|
|
|
$n_items += ($service['total_modules'] + $service['total_dynamic']);
|
|
|
|
|
|
|
|
if ($n_items > 0) {
|
2019-02-27 10:28:36 +01:00
|
|
|
$services[$service['id']]['searchChildren'] = 1;
|
|
|
|
} else {
|
|
|
|
$services[$service['id']]['searchChildren'] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$services[$service['id']]['counters'] = [
|
|
|
|
'total_services' => $service['total_services'],
|
|
|
|
'total_agents' => $service['total_agents'],
|
|
|
|
'total_modules' => $service['total_modules'],
|
|
|
|
];
|
|
|
|
$services[$service['id']]['name'] = $service['name'];
|
|
|
|
$services[$service['id']]['id'] = $service['id'];
|
2020-10-26 12:05:37 +01:00
|
|
|
$services[$service['id']]['description'] = $service['description'];
|
2019-02-27 10:28:36 +01:00
|
|
|
$services[$service['id']]['serviceDetail'] = 'index.php?sec=network&sec2=enterprise/operation/services/services&tab=service_map&id_service='.(int) $service['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $services;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
/**
|
|
|
|
* Retrieve first level fields.
|
|
|
|
*
|
|
|
|
* @deprecated 746.
|
|
|
|
*
|
|
|
|
* @return string With a first level fields.
|
|
|
|
*/
|
2019-02-27 10:28:36 +01:00
|
|
|
protected function getFirstLevelFields()
|
|
|
|
{
|
|
|
|
$fields = [];
|
|
|
|
|
|
|
|
return implode(',', array_merge($fields, $this->L1extraFields));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
/**
|
|
|
|
* Retrieves elements (second level) from selected rootID.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-02-27 10:28:36 +01:00
|
|
|
protected function getSecondLevel()
|
|
|
|
{
|
2020-12-02 11:45:54 +01:00
|
|
|
global $config;
|
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
$service = new Service($this->id, true);
|
2019-02-27 10:28:36 +01:00
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
$output = [];
|
|
|
|
foreach ($service->children() as $item) {
|
|
|
|
$tmp = [];
|
2019-02-27 10:28:36 +01:00
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
if ($this->metaID > 0) {
|
|
|
|
$tmp['metaID'] = $this->metaID;
|
|
|
|
} else if ($item->id_server_meta() !== 0) {
|
|
|
|
$tmp['metaID'] = $item->id_server_meta();
|
|
|
|
}
|
2019-02-27 10:28:36 +01:00
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
$tmp['serverID'] = $tmp['metaID'];
|
2019-02-27 10:28:36 +01:00
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
switch ($item->type()) {
|
|
|
|
case SERVICE_ELEMENT_AGENT:
|
|
|
|
if ($item->agent() === null) {
|
|
|
|
// Skip item.
|
|
|
|
continue 2;
|
|
|
|
}
|
2019-02-27 10:28:36 +01:00
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
$tmp['id'] = $item->agent()->id_agente();
|
|
|
|
$tmp['name'] = $item->agent()->nombre();
|
|
|
|
$tmp['alias'] = $item->agent()->alias();
|
|
|
|
$tmp['fired_count'] = $item->agent()->fired_count();
|
|
|
|
$tmp['normal_count'] = $item->agent()->normal_count();
|
|
|
|
$tmp['warning_count'] = $item->agent()->warning_count();
|
|
|
|
$tmp['critical_count'] = $item->agent()->critical_count();
|
|
|
|
$tmp['unknown_count'] = $item->agent()->unknown_count();
|
|
|
|
$tmp['notinit_count'] = $item->agent()->notinit_count();
|
|
|
|
$tmp['total_count'] = $item->agent()->total_count();
|
|
|
|
|
|
|
|
if ($item->agent()->quiet() > 0
|
|
|
|
|| $item->agent()->cps() > 0
|
|
|
|
) {
|
|
|
|
$tmp['quiet'] = 1;
|
|
|
|
} else {
|
|
|
|
$tmp['quiet'] = 0;
|
|
|
|
}
|
2019-02-27 10:28:36 +01:00
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
$tmp['state_critical'] = $tmp['critical_count'];
|
|
|
|
$tmp['state_warning'] = $tmp['warning_count'];
|
|
|
|
$tmp['state_unknown'] = $tmp['unknown_count'];
|
|
|
|
$tmp['state_notinit'] = $tmp['notinit_count'];
|
|
|
|
$tmp['state_normal'] = $tmp['normal_count'];
|
|
|
|
$tmp['state_total'] = $tmp['total_count'];
|
|
|
|
$tmp['type'] = SERVICE_ELEMENT_AGENT;
|
|
|
|
$tmp['rootID'] = $this->rootID;
|
|
|
|
$tmp['rootType'] = $this->rootType;
|
|
|
|
$tmp['counters'] = [
|
|
|
|
'alerts' => $item->agent()->fired_count(),
|
|
|
|
'ok' => $item->agent()->normal_count(),
|
|
|
|
'warning' => $item->agent()->warning_count(),
|
|
|
|
'critical' => $item->agent()->critical_count(),
|
|
|
|
'unknown' => $item->agent()->unknown_count(),
|
|
|
|
'not_init' => $item->agent()->notinit_count(),
|
|
|
|
'total' => $item->agent()->total_count(),
|
|
|
|
];
|
|
|
|
|
|
|
|
switch ($item->agent()->lastStatus()) {
|
|
|
|
case AGENT_STATUS_NORMAL:
|
2021-09-21 13:22:37 +02:00
|
|
|
$tmp['statusImageHTML'] = '<img src="'.ui_get_full_url('images/status_sets/default/agent_ok_ball.png').'" data-title="NORMAL status." data-use_title_for_force_title="1" class="forced_title" alt="NORMAL status." />';
|
2020-07-02 14:53:33 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AGENT_STATUS_CRITICAL:
|
|
|
|
case AGENT_STATUS_ALERT_FIRED:
|
2021-09-21 13:22:37 +02:00
|
|
|
$tmp['statusImageHTML'] = '<img src="'.ui_get_full_url('images/status_sets/default/agent_critical_ball.png').'" data-title="CRITICAL status." data-use_title_for_force_title="1" class="forced_title" alt="CRITICAL status." />';
|
2020-07-02 14:53:33 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AGENT_STATUS_WARNING:
|
2021-09-21 13:22:37 +02:00
|
|
|
$tmp['statusImageHTML'] = '<img src="'.ui_get_full_url('images/status_sets/default/agent_warning_ball.png').'" data-title="WARNING status." data-use_title_for_force_title="1" class="forced_title" alt="WARNING status." />';
|
2020-07-02 14:53:33 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AGENT_STATUS_UNKNOWN:
|
|
|
|
default:
|
2021-09-21 13:22:37 +02:00
|
|
|
$tmp['statusImageHTML'] = '<img src="'.ui_get_full_url('images/status_sets/default/agent_no_data_ball.png').'" data-title="UNKNOWN status." data-use_title_for_force_title="1" class="forced_title" alt="UNKNOWN status." />';
|
2020-07-02 14:53:33 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$tmp['children'] = [];
|
2020-12-02 11:45:54 +01:00
|
|
|
|
|
|
|
if (check_acl($config['id_user'], $item->agent()->id_grupo(), 'AR')) {
|
|
|
|
$tmp['searchChildren'] = 1;
|
|
|
|
} else {
|
|
|
|
$tmp['searchChildren'] = 0;
|
2022-01-14 09:49:26 +01:00
|
|
|
$tmp['noAcl'] = 1;
|
2020-12-02 11:45:54 +01:00
|
|
|
}
|
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
$tmp['showEventsBtn'] = 1;
|
|
|
|
$tmp['eventAgent'] = $item->agent()->id_agente();
|
2021-06-25 11:37:09 +02:00
|
|
|
$tmp['disabled'] = (bool) $item->agent()->disabled();
|
2020-07-02 14:53:33 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SERVICE_ELEMENT_MODULE:
|
|
|
|
if ($item->module() === null) {
|
|
|
|
// Skip item.
|
|
|
|
continue 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
$tmp['id'] = $item->module()->id_agente_modulo();
|
|
|
|
$tmp['name'] = $item->module()->nombre();
|
|
|
|
$tmp['id_tipo_modulo'] = $item->module()->id_tipo_modulo();
|
|
|
|
$tmp['id_modulo'] = $item->module()->id_modulo();
|
|
|
|
$tmp['estado'] = $item->module()->lastStatus();
|
|
|
|
$tmp['datos'] = $item->module()->lastValue();
|
|
|
|
$tmp['parent'] = $item->module()->parent_module_id();
|
|
|
|
$alerts = alerts_get_alerts_module_name(
|
|
|
|
$item->module()->id_agente_modulo()
|
|
|
|
);
|
|
|
|
if ($alerts !== false) {
|
|
|
|
// Seems to be used as 'flag'.
|
|
|
|
$tmp['alerts'] = $alerts[0]['id'];
|
|
|
|
}
|
2019-02-27 10:28:36 +01:00
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
$tmp['unit'] = $item->module()->unit();
|
|
|
|
$tmp['type'] = SERVICE_ELEMENT_MODULE;
|
|
|
|
$tmp['id_module_type'] = $item->module()->id_tipo_modulo();
|
|
|
|
$tmp['server_type'] = $tmp['id_module_type'];
|
|
|
|
$tmp['status'] = $item->module()->lastStatus();
|
|
|
|
$tmp['value'] = modules_get_agentmodule_data_for_humans(
|
|
|
|
array_merge(
|
|
|
|
$item->module()->toArray(),
|
|
|
|
[ 'datos' => $item->module()->lastValue() ]
|
|
|
|
)
|
2020-07-01 20:50:07 +02:00
|
|
|
);
|
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
$title = $item->module()->lastStatusTitle();
|
|
|
|
|
|
|
|
if (is_numeric($item->module()->lastValue())) {
|
|
|
|
$divisor = get_data_multiplier($item->module()->unit());
|
|
|
|
$title .= ' : '.format_for_graph(
|
|
|
|
$item->module()->lastValue(),
|
|
|
|
1,
|
|
|
|
'.',
|
|
|
|
',',
|
|
|
|
$divisor
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$title .= ' : '.substr(
|
|
|
|
io_safe_output(
|
|
|
|
$item->module()->lastValue()
|
|
|
|
),
|
|
|
|
0,
|
|
|
|
42
|
2020-07-01 20:50:07 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
$tmp['serverName'] = $item->module()->agent()->server_name();
|
|
|
|
$tmp['serverID'] = $tmp['metaID'];
|
|
|
|
$tmp['statusText'] = $item->module()->lastStatusText();
|
|
|
|
$tmp['showGraphs'] = 1;
|
|
|
|
$tmp['showEventsBtn'] = 1;
|
|
|
|
$tmp['eventAgent'] = $item->module()->id_agente();
|
2021-06-25 11:37:09 +02:00
|
|
|
$tmp['disabled'] = $item->module()->disabled();
|
2020-07-01 20:50:07 +02:00
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
$html = '<img src="';
|
|
|
|
$html .= ui_get_full_url(
|
|
|
|
'/images/status_sets/default/'.$item->module()->lastStatusImage()
|
|
|
|
);
|
|
|
|
$html .= '" data-title="'.$title;
|
|
|
|
$html .= '" data-use_title_for_force_title="1" ';
|
|
|
|
$html .= 'class="forced_title" alt="';
|
|
|
|
$html .= $item->module()->lastStatusTitle().'" />';
|
|
|
|
$tmp['statusImageHTML'] = $html;
|
|
|
|
$tmp = array_merge(
|
|
|
|
$tmp,
|
|
|
|
$this->getModuleGraphLinks(
|
|
|
|
$tmp
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
2020-07-01 20:50:07 +02:00
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
case SERVICE_ELEMENT_SERVICE:
|
|
|
|
if ($item->service() === null) {
|
|
|
|
// Skip item.
|
|
|
|
continue 2;
|
|
|
|
}
|
2019-02-27 10:28:36 +01:00
|
|
|
|
2022-04-20 18:41:03 +02:00
|
|
|
$title = get_parameter('title', '');
|
|
|
|
if (empty($title) === true) {
|
|
|
|
$tmp['title'] = '';
|
|
|
|
} else {
|
2022-10-11 09:46:53 +02:00
|
|
|
$tmp['title'] = io_safe_output($title).'/';
|
2022-04-20 18:41:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$tmp['title'] .= $service->name();
|
2020-07-02 14:53:33 +02:00
|
|
|
$tmp['id'] = (int) $item->service()->id();
|
|
|
|
$tmp['name'] = $item->service()->name();
|
|
|
|
$tmp['alias'] = $item->service()->name();
|
2020-10-26 12:05:37 +01:00
|
|
|
$tmp['description'] = $item->service()->description();
|
|
|
|
$tmp['elementDescription'] = $item->description();
|
2021-06-25 11:37:09 +02:00
|
|
|
$tmp['disabled'] = $item->service()->disabled();
|
2020-07-02 14:53:33 +02:00
|
|
|
|
|
|
|
$counters = [
|
|
|
|
'total_modules' => 0,
|
|
|
|
'total_agents' => 0,
|
|
|
|
'total_services' => 0,
|
|
|
|
'total_dynamic' => 0,
|
|
|
|
'total' => 0,
|
|
|
|
];
|
|
|
|
|
2022-04-11 14:20:17 +02:00
|
|
|
if (is_metaconsole() === false
|
|
|
|
|| (isset($config['realtimestats']) === true
|
|
|
|
&& $config['realtimestats'] === true
|
|
|
|
&& $tmp['metaID'] > 0)
|
|
|
|
) {
|
|
|
|
// Look for counters.
|
|
|
|
if ($this->connectedToNode === false
|
|
|
|
&& is_metaconsole() === true
|
|
|
|
&& $tmp['metaID'] > 0
|
|
|
|
) {
|
|
|
|
// Impersonate node.
|
|
|
|
\enterprise_include_once('include/functions_metaconsole.php');
|
|
|
|
\enterprise_hook(
|
|
|
|
'metaconsole_connect',
|
|
|
|
[
|
|
|
|
null,
|
|
|
|
$tmp['metaID'],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (check_acl($config['id_user'], $item->service()->id_group(), 'AR')) {
|
|
|
|
$grandchildren = $item->service()->children();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->connectedToNode === false
|
|
|
|
&& is_metaconsole() === true
|
|
|
|
&& $tmp['metaID'] > 0
|
|
|
|
) {
|
|
|
|
// Restore connection.
|
|
|
|
\enterprise_hook('metaconsole_restore_db');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_array($grandchildren) === true) {
|
|
|
|
$counters = array_reduce(
|
|
|
|
$grandchildren,
|
|
|
|
function ($carry, $item) {
|
|
|
|
if ($item->type() === SERVICE_ELEMENT_MODULE) {
|
|
|
|
$carry['total_modules']++;
|
|
|
|
} else if ($item->type() === SERVICE_ELEMENT_AGENT) {
|
|
|
|
$carry['total_agents']++;
|
|
|
|
} else if ($item->type() === SERVICE_ELEMENT_SERVICE) {
|
|
|
|
$carry['total_services']++;
|
|
|
|
} else if ($item->type() === SERVICE_ELEMENT_DYNAMIC) {
|
|
|
|
$carry['total_dynamic']++;
|
|
|
|
}
|
|
|
|
|
|
|
|
$carry['total']++;
|
|
|
|
|
|
|
|
return $carry;
|
|
|
|
},
|
|
|
|
$counters
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($counters['total'] > 0) {
|
|
|
|
$tmp['searchChildren'] = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Always search for.
|
2020-07-02 14:53:33 +02:00
|
|
|
$tmp['searchChildren'] = 1;
|
|
|
|
}
|
2019-02-27 10:28:36 +01:00
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
$tmp['type'] = 'services';
|
|
|
|
$tmp['rootType'] = 'services';
|
|
|
|
$tmp['children'] = [];
|
|
|
|
$tmp['serviceDetail'] = ui_get_full_url(
|
|
|
|
'index.php?sec=network&sec2=enterprise/operation/services/services&tab=service_map&id_service='.$item->service()->id()
|
|
|
|
);
|
|
|
|
$tmp['counters'] = $counters;
|
|
|
|
$tmp['rootID'] = $this->rootID;
|
|
|
|
switch ($item->service()->lastStatus()) {
|
|
|
|
case SERVICE_STATUS_NORMAL:
|
|
|
|
$tmp['statusImageHTML'] = '<img src="';
|
|
|
|
$tmp['statusImageHTML'] .= ui_get_full_url(
|
|
|
|
'images/status_sets/default/agent_ok_ball.png'
|
|
|
|
);
|
|
|
|
$tmp['statusImageHTML'] .= '" data-title="NORMAL status." data-use_title_for_force_title="1" class="forced_title" alt="NORMAL status." />';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SERVICE_STATUS_CRITICAL:
|
|
|
|
$tmp['statusImageHTML'] = '<img src="';
|
|
|
|
$tmp['statusImageHTML'] .= ui_get_full_url(
|
|
|
|
'images/status_sets/default/agent_critical_ball.png'
|
|
|
|
);
|
|
|
|
$tmp['statusImageHTML'] .= '" data-title="CRITICAL status." data-use_title_for_force_title="1" class="forced_title" alt="CRITICAL status." />';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SERVICE_STATUS_WARNING:
|
|
|
|
$tmp['statusImageHTML'] = '<img src="';
|
|
|
|
$tmp['statusImageHTML'] .= ui_get_full_url(
|
|
|
|
'images/status_sets/default/agent_warning_ball.png'
|
|
|
|
);
|
|
|
|
$tmp['statusImageHTML'] .= '" data-title="WARNING status." data-use_title_for_force_title="1" class="forced_title" alt="WARNING status." />';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SERVICE_STATUS_UNKNOWN:
|
|
|
|
default:
|
|
|
|
$tmp['statusImageHTML'] = '<img src="';
|
|
|
|
$tmp['statusImageHTML'] .= ui_get_full_url(
|
|
|
|
'images/status_sets/default/agent_no_data_ball.png'
|
|
|
|
);
|
|
|
|
$tmp['statusImageHTML'] .= '" data-title="UNKNOWN status." data-use_title_for_force_title="1" class="forced_title" alt="UNKNOWN status." />';
|
|
|
|
break;
|
|
|
|
}
|
2019-02-27 10:28:36 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-07-02 14:53:33 +02:00
|
|
|
// Unknown type.
|
|
|
|
continue 2;
|
2019-02-27 10:28:36 +01:00
|
|
|
}
|
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
$output[] = $tmp;
|
2019-02-27 10:28:36 +01:00
|
|
|
}
|
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
$this->tree = $output;
|
2019-02-27 10:28:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
/**
|
|
|
|
* SQL query to retrieve second level items.
|
|
|
|
*
|
|
|
|
* @return string SQL.
|
|
|
|
*/
|
2019-02-27 10:28:36 +01:00
|
|
|
protected function getSecondLevelServicesSql()
|
|
|
|
{
|
|
|
|
$group_acl = $this->getGroupAclCondition();
|
|
|
|
|
2020-07-01 20:50:07 +02:00
|
|
|
$sql = sprintf(
|
|
|
|
'SELECT
|
|
|
|
ts.id,
|
|
|
|
ts.id_agent_module,
|
|
|
|
ts.name,
|
|
|
|
ts.name as `alias`,
|
2020-10-26 12:05:37 +01:00
|
|
|
ts.description as `description`,
|
|
|
|
tse.description as `elementDescription`,
|
2020-07-01 20:50:07 +02:00
|
|
|
tse.id_service as `rootID`,
|
|
|
|
"services" as `rootType`,
|
|
|
|
"services" as `type`,
|
|
|
|
ts.quiet,
|
|
|
|
tse.id_server_meta,
|
|
|
|
SUM(if((tse.id_agent<>0), 1, 0)) AS `total_agents`,
|
|
|
|
SUM(if((tse.id_agente_modulo<>0), 1, 0)) AS `total_modules`,
|
|
|
|
SUM(if((tse.id_service_child<>0), 1, 0)) AS `total_services`
|
|
|
|
FROM tservice ts
|
|
|
|
INNER JOIN tservice_element tse
|
|
|
|
ON tse.id_service_child = ts.id
|
|
|
|
WHERE
|
|
|
|
tse.id_service = %d
|
|
|
|
%s
|
|
|
|
GROUP BY ts.id',
|
|
|
|
$this->id,
|
|
|
|
$group_acl
|
|
|
|
);
|
2019-02-22 13:07:47 +01:00
|
|
|
|
2019-02-27 10:28:36 +01:00
|
|
|
return $sql;
|
|
|
|
}
|
2019-02-22 13:07:47 +01:00
|
|
|
|
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
/**
|
|
|
|
* Retrieve SQL filter for current filte.r
|
|
|
|
*
|
|
|
|
* @return string SQL filter.
|
|
|
|
*/
|
|
|
|
protected function getServiceFavouriteFilter()
|
2019-02-27 10:28:36 +01:00
|
|
|
{
|
2020-07-02 14:53:33 +02:00
|
|
|
if (isset($this->filter['is_favourite']) === true
|
|
|
|
&& empty($this->filter['is_favourite']) === false
|
|
|
|
) {
|
|
|
|
return ' AND is_favourite = 1';
|
|
|
|
}
|
2019-02-22 13:07:47 +01:00
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
return '';
|
2019-02-27 10:28:36 +01:00
|
|
|
}
|
2019-02-22 13:07:47 +01:00
|
|
|
|
|
|
|
|
2022-05-23 12:51:32 +02:00
|
|
|
/**
|
|
|
|
* Retrieve SQL filter for current filter
|
|
|
|
*
|
|
|
|
* @return string SQL filter.
|
|
|
|
*/
|
|
|
|
protected function getServiceNameSearchFilter()
|
|
|
|
{
|
|
|
|
if (isset($this->filter['searchService']) === true
|
|
|
|
&& empty($this->filter['searchService']) === false
|
|
|
|
) {
|
|
|
|
return " AND (ts.name LIKE '%".$this->filter['searchService']."%' OR ts.description LIKE '%".$this->filter['searchService']."%')";
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
/**
|
|
|
|
* Overwrites partial functionality of general Tree.class.
|
|
|
|
*
|
|
|
|
* @param array $module Data of given module.
|
|
|
|
*
|
|
|
|
* @return array Complementary information.
|
|
|
|
*/
|
|
|
|
protected function getModuleGraphLinks(array $module)
|
2019-02-27 10:28:36 +01:00
|
|
|
{
|
2020-07-02 14:53:33 +02:00
|
|
|
$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']));
|
2019-02-22 13:07:47 +01:00
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
$graph_params = [
|
|
|
|
'type' => $graphType,
|
|
|
|
'period' => SECONDS_1DAY,
|
|
|
|
'id' => $module['id'],
|
|
|
|
'refresh' => SECONDS_10MINUTES,
|
|
|
|
];
|
2019-02-22 13:07:47 +01:00
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
if (is_metaconsole() === true) {
|
|
|
|
// Set the server id.
|
|
|
|
$graph_params['server'] = $module['serverID'];
|
2020-03-11 15:00:35 +01:00
|
|
|
}
|
|
|
|
|
2020-07-02 14:53:33 +02:00
|
|
|
$graph_params_str = http_build_query($graph_params);
|
|
|
|
$moduleGraphURL = $url.'?'.$graph_params_str;
|
|
|
|
|
|
|
|
return [
|
|
|
|
'moduleGraph' => [
|
|
|
|
'url' => $moduleGraphURL,
|
|
|
|
'handle' => $winHandle,
|
|
|
|
],
|
|
|
|
'snapshot' => ui_get_snapshot_link(
|
|
|
|
[
|
|
|
|
'id_module' => $module['id'],
|
|
|
|
'interval' => $module['current_interval'],
|
|
|
|
'module_name' => $module['name'],
|
|
|
|
'id_node' => (($module['serverID'] > 0) ? $module['serverID'] : 0),
|
|
|
|
],
|
|
|
|
true
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Needs to be defined to maintain Tree view functionality.
|
|
|
|
*
|
|
|
|
* @param integer $status Status.
|
|
|
|
*
|
|
|
|
* @return string Fixed string.
|
|
|
|
*/
|
|
|
|
protected function getAgentStatusFilter(
|
|
|
|
$status=self::TV_DEFAULT_AGENT_STATUS
|
|
|
|
) {
|
2020-03-11 15:00:35 +01:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-27 10:28:36 +01:00
|
|
|
}
|