Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

enh(perf): set LDAP contactgroup synchronization every hour #8070

Merged
merged 4 commits into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cron/centAcl-Func.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function getFilteredPollers($host, $resId)
}
}
} else {
# If result of query is empty and user have poller restriction, clean host table.
// If result of query is empty and user have poller restrictions, clean host table.
if ($isPollerFilter) {
$host = array();
}
Expand Down
72 changes: 44 additions & 28 deletions cron/centAcl.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
$centreonDbName = $conf_centreon['db'];
$centreonLog = new CentreonLog();

/*
* Define the period between two update in second for LDAP user/contactgroup
*/
define('LDAP_UPDATE_PERIOD', 3600);

/**
* CentAcl script
Expand Down Expand Up @@ -78,10 +82,7 @@
if (empty($data)) {
try {
// at first run (eg: after the install), data may be missing.
$pearDB->query(
"INSERT INTO cron_operation (name, system, activate)
VALUES ('centAcl.php', '1', '1')"
);
$pearDB->query("INSERT INTO cron_operation (name, system, activate) VALUES ('centAcl.php', '1', '1')");
} catch (\PDOException $e) {
programExit("Error can't insert centAcl values in the `cron_operation` table.");
}
Expand Down Expand Up @@ -110,9 +111,30 @@
programExit($errorMessage);
}

$resourceCache = array();
/**
* Sync ACL with LDAP's contactgroup
* If the LDAP is enabled and the last check is greater than the update period
*
* @TODO : Synchronize LDAP with contacts data in background to avoid it at login
*/
$ldapEnable = $ldapLastUpdate = 0;
sc979 marked this conversation as resolved.
Show resolved Hide resolved
$queryOptions = "SELECT `key`, `value` FROM `options` WHERE `key` IN ('ldap_auth_enable', 'ldap_last_acl_update')";
sc979 marked this conversation as resolved.
Show resolved Hide resolved
$res = $pearDB->query($queryOptions);
while ($row = $res->fetch()) {
switch ($row['key']) {
case 'ldap_auth_enable':
$ldapEnable = $row['value'];
break;
case 'ldap_last_acl_update':
$ldapLastUpdate = $row['value'];
break;
}
}
if ($ldapEnable == 1 && $ldapLastUpdate < (time() - LDAP_UPDATE_PERIOD)) {
sc979 marked this conversation as resolved.
Show resolved Hide resolved
$cgObj->syncWithLdap();
}

/** **********************************************
/**
* Check expected contact data sync on login with the LDAP, depending on last sync time and own sync interval
*/
$pearDB->beginTransaction();
Expand Down Expand Up @@ -143,14 +165,11 @@
programExit("Error when updating LDAP's reference date for next synchronization");
}

// @TODO : Synchronize LDAP with contacts data in background to avoid it at login
$cgObj->syncWithLdap();

/** **********************************************
/**
* Remove data from old groups (deleted groups)
*/
$aclGroupToDelete = "SELECT DISTINCT acl_group_id " .
"FROM " . $centreonDbName . ".acl_groups WHERE acl_group_activate = '1'";
$aclGroupToDelete = "SELECT DISTINCT acl_group_id
FROM " . $centreonDbName . ".acl_groups WHERE acl_group_activate = '1'";
$aclGroupToDelete2 = "SELECT DISTINCT acl_group_id FROM " . $centreonDbName . ".acl_res_group_relations";
$pearDB->beginTransaction();
try {
Expand All @@ -165,7 +184,7 @@
);
}

/** ***********************************************
/**
* Check if some ACL have global options selected for
* all the resources
*/
Expand All @@ -181,7 +200,6 @@
/**
* Add Hosts
*/

if ($row['all_hosts']) {
$pearDB->beginTransaction();
try {
Expand Down Expand Up @@ -219,7 +237,6 @@
}
}


/**
* Add Hostgroups
*/
Expand Down Expand Up @@ -316,7 +333,6 @@
* if no : go away.
* if yes : let's go to build cache and update database
*/

$tabGroups = array();
$dbResult1 = $pearDB->query(
"SELECT DISTINCT acl_groups.acl_group_id
Expand All @@ -333,9 +349,8 @@

if (count($tabGroups)) {

/** ***********************************************
/**
* Cache for hosts and host Templates
*
*/
$hostTemplateCache = [];
$res = $pearDB->query(
Expand All @@ -357,7 +372,7 @@
}
unset($h);

/** ***********************************************
/**
* Cache for host poller relation
*/
$hostPollerCache = array();
Expand All @@ -371,7 +386,7 @@
$hostPollerCache[$row['nagios_server_id']][$row['host_host_id']] = $row['host_host_id'];
}

/** ***********************************************
/**
* Get all included Hosts
*/
$hostIncCache = [];
Expand All @@ -386,7 +401,7 @@
$hostIncCache[$h["acl_res_id"]][$h["host_host_id"]] = 1;
}

/** ***********************************************
/**
* Get all excluded Hosts
*/
$hostExclCache = [];
Expand All @@ -401,7 +416,7 @@
$hostExclCache[$h["acl_res_id"]][$h["host_host_id"]] = 1;
}

/** ***********************************************
/**
* Service Cache
*/
$svcCache = [];
Expand All @@ -413,7 +428,7 @@
$svcCache[$s["service_id"]] = 1;
}

/** ***********************************************
/**
* Host Host relation
*/
$hostHGRelation = [];
Expand All @@ -426,7 +441,7 @@
}
unset($hg);

/** ***********************************************
/**
* Host Service relation
*/
$hsRelation = [];
Expand All @@ -453,7 +468,7 @@
}
$dbResult->closeCursor();

/** ***********************************************
/**
* Create Service template model Cache
*/
$svcTplCache = [];
Expand Down Expand Up @@ -522,17 +537,18 @@
// Prepare statement
$deleteHandler = $pearDBO->prepare("DELETE FROM centreon_acl WHERE group_id = ?");

/** ***********************************************
/**
* Begin to build ACL
*/
$cpt = 0;
$resourceCache = array();
foreach ($tabGroups as $aclGroupId) {
/*
* Delete old data for this group
*/
$deleteHandler->execute(array($aclGroupId));

/** ***********************************************
/**
* Select
*/
$dbResult2 = $pearDB->prepare(
Expand Down Expand Up @@ -743,7 +759,7 @@
require_once $extensionPath . 'centAcl.php';
}

/*
/**
* Remove lock
*/
$dbResult = $pearDB->prepare(
Expand Down