mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
wip smart services
This commit is contained in:
parent
ffba7b8285
commit
112f578512
@ -40,6 +40,7 @@ if (is_ajax()) {
|
|||||||
$id = get_parameter('id', -1);
|
$id = get_parameter('id', -1);
|
||||||
$rootID = get_parameter('rootID', -1);
|
$rootID = get_parameter('rootID', -1);
|
||||||
$serverID = get_parameter('serverID', false);
|
$serverID = get_parameter('serverID', false);
|
||||||
|
$metaID = (int) get_parameter('metaID', 0);
|
||||||
$childrenMethod = get_parameter('childrenMethod', 'on_demand');
|
$childrenMethod = get_parameter('childrenMethod', 'on_demand');
|
||||||
|
|
||||||
$default_filters = [
|
$default_filters = [
|
||||||
@ -98,7 +99,16 @@ if (is_ajax()) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'services':
|
case 'services':
|
||||||
$tree = new TreeService($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access);
|
$tree = new TreeService(
|
||||||
|
$type,
|
||||||
|
$rootType,
|
||||||
|
$id,
|
||||||
|
$rootID,
|
||||||
|
$serverID,
|
||||||
|
$childrenMethod,
|
||||||
|
$access,
|
||||||
|
$metaID
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -64,14 +64,22 @@ class Tree
|
|||||||
const TV_DEFAULT_AGENT_STATUS = -1;
|
const TV_DEFAULT_AGENT_STATUS = -1;
|
||||||
|
|
||||||
|
|
||||||
public function __construct($type, $rootType='', $id=-1, $rootID=-1, $serverID=false, $childrenMethod='on_demand', $access='AR')
|
public function __construct(
|
||||||
{
|
$type,
|
||||||
|
$rootType='',
|
||||||
|
$id=-1,
|
||||||
|
$rootID=-1,
|
||||||
|
$serverID=false,
|
||||||
|
$childrenMethod='on_demand',
|
||||||
|
$access='AR',
|
||||||
|
$id_meta_server=0
|
||||||
|
) {
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
$this->rootType = !empty($rootType) ? $rootType : $type;
|
$this->rootType = !empty($rootType) ? $rootType : $type;
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
$this->rootID = !empty($rootID) ? $rootID : $id;
|
$this->rootID = !empty($rootID) ? $rootID : $id;
|
||||||
$this->serverID = $serverID;
|
$this->serverID = $serverID;
|
||||||
if (is_metaconsole()) {
|
if (is_metaconsole() && $id_meta_server == 0) {
|
||||||
$this->serverName = metaconsole_get_server_by_id($serverID);
|
$this->serverName = metaconsole_get_server_by_id($serverID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +98,7 @@ class Tree
|
|||||||
include_once $config['homedir'].'/include/functions_tags.php';
|
include_once $config['homedir'].'/include/functions_tags.php';
|
||||||
enterprise_include_once('include/functions_agents.php');
|
enterprise_include_once('include/functions_agents.php');
|
||||||
|
|
||||||
if (is_metaconsole()) {
|
if (is_metaconsole() && $id_meta_server == 0) {
|
||||||
enterprise_include_once('meta/include/functions_ui_meta.php');
|
enterprise_include_once('meta/include/functions_ui_meta.php');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,8 @@ global $config;
|
|||||||
|
|
||||||
require_once $config['homedir'].'/include/class/Tree.class.php';
|
require_once $config['homedir'].'/include/class/Tree.class.php';
|
||||||
|
|
||||||
|
use PandoraFMS\Enterprise\Service;
|
||||||
|
|
||||||
class TreeService extends Tree
|
class TreeService extends Tree
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -21,12 +23,35 @@ class TreeService extends Tree
|
|||||||
|
|
||||||
protected $displayAllGroups = false;
|
protected $displayAllGroups = false;
|
||||||
|
|
||||||
|
private $metaID = 0;
|
||||||
|
|
||||||
public function __construct($type, $rootType='', $id=-1, $rootID=-1, $serverID=false, $childrenMethod='on_demand', $access='AR')
|
|
||||||
{
|
public function __construct(
|
||||||
|
$type,
|
||||||
|
$rootType='',
|
||||||
|
$id=-1,
|
||||||
|
$rootID=-1,
|
||||||
|
$serverID=false,
|
||||||
|
$childrenMethod='on_demand',
|
||||||
|
$access='AR',
|
||||||
|
$id_server_meta=0
|
||||||
|
) {
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
parent::__construct($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access);
|
if ($id_server_meta > 0) {
|
||||||
|
$this->metaID = $id_server_meta;
|
||||||
|
}
|
||||||
|
|
||||||
|
parent::__construct(
|
||||||
|
$type,
|
||||||
|
$rootType,
|
||||||
|
$id,
|
||||||
|
$rootID,
|
||||||
|
$serverID,
|
||||||
|
$childrenMethod,
|
||||||
|
$access,
|
||||||
|
$id_server_meta
|
||||||
|
);
|
||||||
|
|
||||||
$this->L1fieldName = 'id_group';
|
$this->L1fieldName = 'id_group';
|
||||||
$this->L1extraFields = [
|
$this->L1extraFields = [
|
||||||
@ -60,6 +85,18 @@ class TreeService extends Tree
|
|||||||
|
|
||||||
protected function getData()
|
protected function getData()
|
||||||
{
|
{
|
||||||
|
if (is_metaconsole() === true && $this->metaID > 0) {
|
||||||
|
// Impersonate node.
|
||||||
|
\enterprise_include_once('include/functions_metaconsole.php');
|
||||||
|
\enterprise_hook(
|
||||||
|
'metaconsole_connect',
|
||||||
|
[
|
||||||
|
null,
|
||||||
|
$this->metaID,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->id == -1) {
|
if ($this->id == -1) {
|
||||||
$this->getFirstLevel();
|
$this->getFirstLevel();
|
||||||
} else if ($this->type == 'services') {
|
} else if ($this->type == 'services') {
|
||||||
@ -67,6 +104,11 @@ class TreeService extends Tree
|
|||||||
} else if ($this->type == 'agent') {
|
} else if ($this->type == 'agent') {
|
||||||
$this->getThirdLevel();
|
$this->getThirdLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_metaconsole() === true && $this->metaID > 0) {
|
||||||
|
// Restore connection.
|
||||||
|
\enterprise_hook('metaconsole_restore_db');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -120,8 +162,6 @@ class TreeService extends Tree
|
|||||||
|
|
||||||
protected function getProcessedServices()
|
protected function getProcessedServices()
|
||||||
{
|
{
|
||||||
$fields = $this->getFirstLevelFields();
|
|
||||||
|
|
||||||
$is_favourite = $this->getServiceFavouriteFilter();
|
$is_favourite = $this->getServiceFavouriteFilter();
|
||||||
|
|
||||||
if (users_can_manage_group_all('AR')) {
|
if (users_can_manage_group_all('AR')) {
|
||||||
@ -131,29 +171,31 @@ class TreeService extends Tree
|
|||||||
}
|
}
|
||||||
|
|
||||||
$sql = sprintf(
|
$sql = sprintf(
|
||||||
"SELECT t1.*
|
'SELECT
|
||||||
FROM tservice_element tss
|
ts.id,
|
||||||
RIGHT JOIN
|
ts.id_agent_module,
|
||||||
(SELECT ts.id, ts.id_agent_module, ts.name, ts.name AS `alias`, ts.id AS `rootID`,
|
ts.name,
|
||||||
'services' AS rootType, 'services' AS type,
|
ts.name as `alias`,
|
||||||
0 AS quiet,
|
ts.id as `rootID`,
|
||||||
SUM(if((tse.id_agent<>0), 1, 0)) AS `total_agents`,
|
"services" as `rootType`,
|
||||||
SUM(if((tse.id_agente_modulo<>0), 1, 0)) AS `total_modules`,
|
"services" as `type`,
|
||||||
SUM(if((tse.id_service_child<>0), 1, 0)) AS `total_services`
|
ts.quiet,
|
||||||
FROM tservice ts
|
SUM(if((tse.id_agent<>0), 1, 0)) AS `total_agents`,
|
||||||
LEFT JOIN tservice_element tse
|
SUM(if((tse.id_agente_modulo<>0), 1, 0)) AS `total_modules`,
|
||||||
ON ts.id=tse.id_service
|
SUM(if((tse.id_service_child<>0), 1, 0)) AS `total_services`
|
||||||
WHERE
|
FROM tservice ts
|
||||||
1=1
|
LEFT JOIN tservice_element tse
|
||||||
%s
|
ON tse.id_service = ts.id
|
||||||
%s
|
WHERE ts.id NOT IN (
|
||||||
GROUP BY id
|
SELECT DISTINCT id_service_child
|
||||||
) as t1
|
FROM tservice_element
|
||||||
ON tss.id_service_child = t1.id
|
WHERE id_server_meta = 0
|
||||||
WHERE tss.id_service_child IS NULL
|
)
|
||||||
",
|
%s
|
||||||
$groups_acl,
|
%s
|
||||||
$is_favourite
|
GROUP BY ts.id',
|
||||||
|
$is_favourite,
|
||||||
|
$groups_acl
|
||||||
);
|
);
|
||||||
|
|
||||||
$stats = db_get_all_rows_sql($sql);
|
$stats = db_get_all_rows_sql($sql);
|
||||||
@ -259,6 +301,63 @@ class TreeService extends Tree
|
|||||||
$sql = $this->getSecondLevelServicesSql();
|
$sql = $this->getSecondLevelServicesSql();
|
||||||
$data_services = db_process_sql($sql);
|
$data_services = db_process_sql($sql);
|
||||||
|
|
||||||
|
$data_services = array_reduce(
|
||||||
|
$data_services,
|
||||||
|
function ($carry, $item) {
|
||||||
|
if ($item['id_server_meta'] > 0
|
||||||
|
&& is_metaconsole() === true
|
||||||
|
) {
|
||||||
|
// Impersonate node.
|
||||||
|
\enterprise_include_once('include/functions_metaconsole.php');
|
||||||
|
$r = \enterprise_hook(
|
||||||
|
'metaconsole_connect',
|
||||||
|
[
|
||||||
|
null,
|
||||||
|
$item['id_server_meta'],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($r === NOERR) {
|
||||||
|
$item = db_get_row_sql(
|
||||||
|
sprintf(
|
||||||
|
'SELECT
|
||||||
|
ts.id,
|
||||||
|
ts.id_agent_module,
|
||||||
|
ts.name,
|
||||||
|
ts.name as `alias`,
|
||||||
|
%d as `rootID`,
|
||||||
|
"services" as `rootType`,
|
||||||
|
"services" as `type`,
|
||||||
|
ts.quiet,
|
||||||
|
%d as 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
|
||||||
|
LEFT JOIN tservice_element tse
|
||||||
|
ON tse.id_service = ts.id
|
||||||
|
WHERE ts.id = %d
|
||||||
|
GROUP BY ts.id',
|
||||||
|
$item['id_server_meta'],
|
||||||
|
$item['rootID'],
|
||||||
|
$item['id']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$item['obj'] = new Service($item['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore connection.
|
||||||
|
\enterprise_hook('metaconsole_restore_db');
|
||||||
|
} else {
|
||||||
|
$item['obj'] = new Service($item['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$carry[] = $item;
|
||||||
|
return $carry;
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
$service_stats = [];
|
$service_stats = [];
|
||||||
|
|
||||||
foreach ($data_services as $service) {
|
foreach ($data_services as $service) {
|
||||||
@ -272,6 +371,12 @@ class TreeService extends Tree
|
|||||||
}
|
}
|
||||||
|
|
||||||
$service_stats[$service['id']]['rootID'] = $service['rootID'];
|
$service_stats[$service['id']]['rootID'] = $service['rootID'];
|
||||||
|
if ($this->metaID > 0) {
|
||||||
|
$service_stats[$service['id']]['metaID'] = $this->metaID;
|
||||||
|
} else {
|
||||||
|
$service_stats[$service['id']]['metaID'] = $service['id_server_meta'];
|
||||||
|
}
|
||||||
|
|
||||||
$service_stats[$service['id']]['rootType'] = $service['rootType'];
|
$service_stats[$service['id']]['rootType'] = $service['rootType'];
|
||||||
$service_stats[$service['id']]['type'] = 'services';
|
$service_stats[$service['id']]['type'] = 'services';
|
||||||
$service_stats[$service['id']]['children'] = [];
|
$service_stats[$service['id']]['children'] = [];
|
||||||
@ -281,41 +386,23 @@ class TreeService extends Tree
|
|||||||
'total_agents' => $service['total_agents'],
|
'total_agents' => $service['total_agents'],
|
||||||
'total_modules' => $service['total_modules'],
|
'total_modules' => $service['total_modules'],
|
||||||
];
|
];
|
||||||
}
|
|
||||||
|
|
||||||
$own_info = get_user_info($config['id_user']);
|
switch ($service['obj']->status()) {
|
||||||
|
|
||||||
if ($own_info['is_admin'] || check_acl($config['id_user'], 0, 'PM')) {
|
|
||||||
$display_all_services = true;
|
|
||||||
} else {
|
|
||||||
$display_all_services = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$services = services_get_services($filter, false, $display_all_services);
|
|
||||||
|
|
||||||
foreach ($services as $row) {
|
|
||||||
if (!array_key_exists($row['id'], $service_stats)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$status = services_get_status($row, true);
|
|
||||||
|
|
||||||
switch ($status) {
|
|
||||||
case SERVICE_STATUS_NORMAL:
|
case SERVICE_STATUS_NORMAL:
|
||||||
$service_stats[$row['id']]['statusImageHTML'] = '<img src="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." />';
|
$service_stats[$service['id']]['statusImageHTML'] = '<img src="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." />';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SERVICE_STATUS_CRITICAL:
|
case SERVICE_STATUS_CRITICAL:
|
||||||
$service_stats[$row['id']]['statusImageHTML'] = '<img src="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." />';
|
$service_stats[$service['id']]['statusImageHTML'] = '<img src="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." />';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SERVICE_STATUS_WARNING:
|
case SERVICE_STATUS_WARNING:
|
||||||
$service_stats[$row['id']][$key]['statusImageHTML'] = '<img src="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." />';
|
$service_stats[$service['id']]['statusImageHTML'] = '<img src="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." />';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SERVICE_STATUS_UNKNOWN:
|
case SERVICE_STATUS_UNKNOWN:
|
||||||
default:
|
default:
|
||||||
$service_stats[$row['id']]['statusImageHTML'] = '<img src="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." />';
|
$service_stats[$service['id']]['statusImageHTML'] = '<img src="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." />';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -337,13 +424,30 @@ class TreeService extends Tree
|
|||||||
{
|
{
|
||||||
$group_acl = $this->getGroupAclCondition();
|
$group_acl = $this->getGroupAclCondition();
|
||||||
|
|
||||||
$sql = "SELECT ts.id, ts.name, tse1.id_service AS `rootID`, 'services' AS rootType, 'services' AS type, 0 AS quiet, SUM(if((tse2.id_agent<>0), 1, 0)) AS `total_agents`, SUM(if((tse2.id_agente_modulo<>0), 1, 0)) AS `total_modules`, SUM(if((tse2.id_service_child<>0), 1, 0)) AS `total_services`, 0 AS fired_count, 0 AS normal_count, 0 AS warning_count, 0 AS critical_count, 0 AS unknown_count, 0 AS notinit_count, 0 AS state_critical, 0 AS state_warning, 0 AS state_unknown, 0 AS state_notinit, 0 AS state_normal, 0 AS state_total, '' AS statusImageHTML, '' AS alertImageHTML
|
$sql = sprintf(
|
||||||
FROM tservice_element tse1
|
'SELECT
|
||||||
LEFT JOIN tservice_element tse2 ON tse1.id_service_child=tse2.id_service
|
ts.id,
|
||||||
LEFT JOIN tservice ts ON tse1.id_service_child=ts.id
|
ts.id_agent_module,
|
||||||
WHERE tse1.id_service=$this->id AND tse1.id_service_child<>0
|
ts.name,
|
||||||
GROUP BY tse1.id_service_child
|
ts.name as `alias`,
|
||||||
";
|
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
|
||||||
|
);
|
||||||
|
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
@ -4251,6 +4251,7 @@ function html_print_input($data, $wrapper='div', $input_only=false)
|
|||||||
}
|
}
|
||||||
|
|
||||||
$params = [];
|
$params = [];
|
||||||
|
$params['disabled'] = $data['disabled'];
|
||||||
$params['return'] = $data['return'];
|
$params['return'] = $data['return'];
|
||||||
$params['show_helptip'] = false;
|
$params['show_helptip'] = false;
|
||||||
$params['input_name'] = $data['name'];
|
$params['input_name'] = $data['name'];
|
||||||
|
@ -1008,6 +1008,7 @@ var TreeController = {
|
|||||||
rootID: element.rootID,
|
rootID: element.rootID,
|
||||||
serverID: element.serverID,
|
serverID: element.serverID,
|
||||||
rootType: element.rootType,
|
rootType: element.rootType,
|
||||||
|
metaID: element.metaID,
|
||||||
filter: controller.filter,
|
filter: controller.filter,
|
||||||
hash: public_hash,
|
hash: public_hash,
|
||||||
id_user: public_user
|
id_user: public_user
|
||||||
|
Loading…
x
Reference in New Issue
Block a user