-
Notifications
You must be signed in to change notification settings - Fork 238
enh(ldap): improve ldap import and PHP memory #8933
Description
Environment
Centreon 20.0.4.5 on CentOS 7, updated today.
Symptoms
LDAP search works fine and displays all Active Directory users.
After selecting users to be imported pages reloads to user list, but users have not been imported.
Debugging
It took me a while to figure out because the form related code is cryptic and at the end it turned out being even more vicious.
The key part of debugging is to find out how to access PHP logs which are here:
tail -f /var/opt/rh/rh-php72/log/php-fpm/centreon-error.log
When importing the following log appears:
PHP Warning: Unknown: Input variables exceeded 1000. To increase the limit change max_input_vars in php.ini. in Unknown on line 0
This is very interresting because the list of Active Directory users contains around 380 accounts and accounts have 4 or 5 fields, so obvisouly recently created users fields are above 1000.
The form code at /usr/share/centreon/www/include/configuration/configObject/contact/ldapImportContact.php seems to confirm the whole users list is passed as POST:
if ($form->validate()) {
if (isset($_POST["contact_select"]["select"]) && $form->getSubmitValue("submitA")) {
// extracting the chosen contacts Id from the POST
$selectedUsers = $_POST["contact_select"]['select'];
unset($_POST["contact_select"]['select']);
// removing the useless data sent
$arrayToReturn = array();
foreach ($_POST["contact_select"] as $key => $subKey) {
$arrayToReturn[$key] = array_intersect_key($_POST["contact_select"][$key], $selectedUsers);
}
// restoring the filtered $_POST['contact_select']['select'] as it's needed in some DB-Func.php functions
$arrayToReturn['select'] = $selectedUsers;
$_POST['contact_select'] = $arrayToReturn;
unset($selectedUsers);
unset($arrayToReturn);
insertLdapContactInDB($_POST["contact_select"]);
}
$form->freeze();
$valid = true;
}So basically what happens is that the users list passed as POST in truncated, so the user we've selected is basically missing from the list, so no import and no error message.
Fix
The fix is easy, we just need to increase this limit, as stated in the PHP warning:
sed -i 's!;*\s*max_input_vars\s*\=.*!max_input_vars = 10000!' /etc/opt/rh/rh-php72/php.ini
systemctl restart rh-php72-php-fpm.service
Possible improvment
I'm not sure how Centreon works with forms but it could be an option to filter the user list to only keep users being selected, so the list won't reach the limit.
Otherwise, Centreon could check the limit currently being set in PHP and display a warning if the returned list is close or above the limit.