Skip to content

Instantly share code, notes, and snippets.

@p3r7
Created August 16, 2017 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save p3r7/1965c70c4eeb84c30bad513404a2518c to your computer and use it in GitHub Desktop.
Save p3r7/1965c70c4eeb84c30bad513404a2518c to your computer and use it in GitHub Desktop.
centreonSyncLdapGroups.php
<?php
/*
* Script to force the declaration of all LDAP contact groups after they got lost.
* This houdl be placed in the /usr/share/centreon/cron/ directory and executed manually.
*/
// -------------------------------------------------------------------------
// REQUIRES
include_once "DB.php";
require_once realpath(dirname(__FILE__) . "/../config/centreon.config.php");
include_once _CENTREON_PATH_ . "/cron/centAcl-Func.php";
include_once _CENTREON_PATH_ . "/www/class/centreonDB.class.php";
include_once _CENTREON_PATH_ . "/www/class/centreonLDAP.class.php";
include_once _CENTREON_PATH_ . "/www/class/centreonMeta.class.php";
include_once _CENTREON_PATH_ . "/www/class/centreonContactgroup.class.php";
// -------------------------------------------------------------------------
// INIT
$centreonDbName = $conf_centreon['db'];
$pearDB = new CentreonDB();
$cg = new CentreonContactgroup($pearDB);
$ldapFilter = ''; // taking them all
// -------------------------------------------------------------------------
// GET ALL LDAP GROUP
$ldapCgs = array();
$ldapCgs = $cg->getLdapContactgroups($ldapFilter);
// -------------------------------------------------------------------------
// INSERT / UPDATE THEM IF MISSING IN CENTREON DB
foreach ($ldapCgs as $cg_name_with_ar_id => $cg_name_formatted){
$res = $cg->insertLdapGroup($cg_name_with_ar_id);
}
// -------------------------------------------------------------------------
// ASSOCIATE WITH USERS
$cg->syncWithLdap();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment