Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
#8 - Do not send BAM configuration unless the poller is link to 1 BA … (
Browse files Browse the repository at this point in the history
#9)

* #8 - Do not send BAM configuration unless the poller is link to 1 BA at least

* Coding style

* Comment indentation
  • Loading branch information
Moujimouja authored and kduret committed Aug 16, 2017
1 parent 1a84c70 commit 7ce81af
Showing 1 changed file with 103 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function isBamModuleAvailable()
$resSelectBamModule = $this->backend_instance->db->query($querySelectBamModule);

$rowSelectModule = $resSelectBamModule->fetch();

if (($rowSelectModule !== false) && (count($rowSelectModule) > 0)) {
$bamAvailable = true;
}
Expand All @@ -102,92 +102,110 @@ public function isBamModuleAvailable()
*/
public function generateObjects($poller_id)
{

#Check that the poller id is used as a BAM poller display to prevent
#a BAM configuration to be sent to a poller display without Bam
$isBamPoller = false;

$queryIsPollerUsedWithBAM = "SELECT count(*) as nbBa FROM mod_bam_poller_relations where poller_id = " . $poller_id;
$IsPollerUsedWithBAM = $this->backend_instance->db->query($queryIsPollerUsedWithBAM);

$rowIsPollerUsedWithBAM = $IsPollerUsedWithBAM->fetch();

if ((($rowIsPollerUsedWithBAM !== false) && $rowIsPollerUsedWithBAM['nbBa'] > 0)) {
$isBamPoller = true;
}

#If the poller is used as an additionnal poller for BAM, he should have
#Centreon BAM installed so we can continue
$sql = '';
$filteredObjects = array();

// Disable MySQL foreign key check
$sql .= $this->setForeignKey(0). "\n\n";

$impactsObj = new Impacts($this->backend_instance->db, $pollerId);
$impactsList = $impactsObj->getList();
$sql .= $impactsObj->generateSql($impactsList) . "\n\n";

// Generate BAM Poller relation
$baPollerObj = new BaPollerRelations($this->backend_instance->db, $poller_id);
$baPollerList = $baPollerObj->getList();
$sql .= $baPollerObj->generateSql($baPollerList) . "\n\n";
$baSimpleList = $this->getSimpleObjectList($baPollerList, 'ba_id');

// Generate BA
$baObj = new Ba($this->backend_instance->db, $poller_id);
$baList = $baObj->getList(array('ba_id' => $baSimpleList));
$sql .= $baObj->generateSql($baList) . "\n\n";

// Generate Ba-BV relation
$baBvObj = new BaBvRelations($this->backend_instance->db, $poller_id);
$baBvList = $baBvObj->getList(array('id_ba' => $baSimpleList));
$sql .= $baBvObj->generateSql($baBvList) . "\n\n";
$bvSimpleList = $this->getSimpleObjectList($baBvList, 'id_ba_group');

// Generate Ba-Cg relation
$baCgObj = new BaCgRelations($this->backend_instance->db, $poller_id);
$baCgList = $baCgObj->getList(array('id_ba' => $baSimpleList));
$sql .= $baCgObj->generateSql($baCgList) . "\n\n";

// Generate Ba Children relation
$baChildrenObj = new BaChildrenRelations($this->backend_instance->db, $poller_id);
$baChildrenList = $baChildrenObj->getList(array('id_ba' => $baSimpleList));
$sql .= $baChildrenObj->generateSql($baChildrenList) . "\n\n";

// Generate Ba Parent relation
$baParentsObj = new BaParentsRelations($this->backend_instance->db, $poller_id);
$baParentsList = $baParentsObj->getList(array('id_dep' => $baSimpleList));
$sql .= $baParentsObj->generateSql($baParentsList) . "\n\n";

// Generate Ba Escalation relation
$baEscalationsObj = new BaEscalationRelations($this->backend_instance->db, $poller_id);
$baEscalationsList = $baEscalationsObj->getList(array('id_ba' => $baSimpleList));
$sql .= $baEscalationsObj->generateSql($baEscalationsList) . "\n\n";

// Generate Ba Timeperiod relation
$baTimeperiodObj = new BaTimeperiodRelations($this->backend_instance->db, $poller_id);
$baTimeperiodList = $baTimeperiodObj->getList(array('ba_id' => $baSimpleList));
$sql .= $baTimeperiodObj->generateSql($baTimeperiodList) . "\n\n";

// Generate Ba User Overview relation
$baUserOverviewObj = new BaUserOverViewRelations($this->backend_instance->db, $poller_id);
$baUserOverviewList = $baUserOverviewObj->getList(array('ba_id' => $baSimpleList));
$sql .= $baUserOverviewObj->generateSql($baUserOverviewList) . "\n\n";

// Generate BV
$bvObj = new Bv($this->backend_instance->db, $poller_id);
$bvList = $bvObj->getList(array('id_ba_group' => $bvSimpleList));
$sql .= $bvObj->generateSql($bvList) . "\n\n";

// Generate usual Kpi
$kpiObj = new Kpi($this->backend_instance->db, $poller_id);
$kpiList = $kpiObj->getList(array('id_ba' => $baSimpleList));
$sql .= $kpiObj->generateSql($kpiList) . "\n\n";
$booleanKpiSimpleList = $this->getSimpleObjectList($kpiList, 'boolean_id');

// Generate boolean Kpi
$booleanKpiObj = new Boolean($this->backend_instance->db, $poller_id);
$booleanKpiList = $booleanKpiObj->getList($booleanKpiSimpleList);
$sql .= $booleanKpiObj->generateSql($booleanKpiList) . "\n\n";

// Generate Bam ACL
$bamAcl = new BamAcl($this->backend_instance->db, $poller_id);
$bamAclList = $bamAcl->getList(array('ba_group_id' => $bvSimpleList));
$sql .= $bamAcl->generateSql($bamAclList) . "\n\n";

// Generate Bam ACL
$bamUserPreferences = new BamUserPreferences($this->backend_instance->db, $poller_id);
$bamuserPreferencesList = $bamUserPreferences->getList();
$sql .= $bamUserPreferences->generateSql($bamuserPreferencesList) . "\n\n";

// Enable MySQL foreign key check
$sql .= $this->setForeignKey(1). "\n\n";

if ($isBamPoller) {
$filteredObjects = array();

// Disable MySQL foreign key check
$sql .= $this->setForeignKey(0). "\n\n";

$impactsObj = new Impacts($this->backend_instance->db, $pollerId);
$impactsList = $impactsObj->getList();
$sql .= $impactsObj->generateSql($impactsList) . "\n\n";

// Generate BAM Poller relation
$baPollerObj = new BaPollerRelations($this->backend_instance->db, $poller_id);
$baPollerList = $baPollerObj->getList();
$sql .= $baPollerObj->generateSql($baPollerList) . "\n\n";
$baSimpleList = $this->getSimpleObjectList($baPollerList, 'ba_id');

// Generate BA
$baObj = new Ba($this->backend_instance->db, $poller_id);
$baList = $baObj->getList(array('ba_id' => $baSimpleList));
$sql .= $baObj->generateSql($baList) . "\n\n";

// Generate Ba-BV relation
$baBvObj = new BaBvRelations($this->backend_instance->db, $poller_id);
$baBvList = $baBvObj->getList(array('id_ba' => $baSimpleList));
$sql .= $baBvObj->generateSql($baBvList) . "\n\n";
$bvSimpleList = $this->getSimpleObjectList($baBvList, 'id_ba_group');

// Generate Ba-Cg relation
$baCgObj = new BaCgRelations($this->backend_instance->db, $poller_id);
$baCgList = $baCgObj->getList(array('id_ba' => $baSimpleList));
$sql .= $baCgObj->generateSql($baCgList) . "\n\n";

// Generate Ba Children relation
$baChildrenObj = new BaChildrenRelations($this->backend_instance->db, $poller_id);
$baChildrenList = $baChildrenObj->getList(array('id_ba' => $baSimpleList));
$sql .= $baChildrenObj->generateSql($baChildrenList) . "\n\n";

// Generate Ba Parent relation
$baParentsObj = new BaParentsRelations($this->backend_instance->db, $poller_id);
$baParentsList = $baParentsObj->getList(array('id_dep' => $baSimpleList));
$sql .= $baParentsObj->generateSql($baParentsList) . "\n\n";

// Generate Ba Escalation relation
$baEscalationsObj = new BaEscalationRelations($this->backend_instance->db, $poller_id);
$baEscalationsList = $baEscalationsObj->getList(array('id_ba' => $baSimpleList));
$sql .= $baEscalationsObj->generateSql($baEscalationsList) . "\n\n";

// Generate Ba Timeperiod relation
$baTimeperiodObj = new BaTimeperiodRelations($this->backend_instance->db, $poller_id);
$baTimeperiodList = $baTimeperiodObj->getList(array('ba_id' => $baSimpleList));
$sql .= $baTimeperiodObj->generateSql($baTimeperiodList) . "\n\n";

// Generate Ba User Overview relation
$baUserOverviewObj = new BaUserOverViewRelations($this->backend_instance->db, $poller_id);
$baUserOverviewList = $baUserOverviewObj->getList(array('ba_id' => $baSimpleList));
$sql .= $baUserOverviewObj->generateSql($baUserOverviewList) . "\n\n";

// Generate BV
$bvObj = new Bv($this->backend_instance->db, $poller_id);
$bvList = $bvObj->getList(array('id_ba_group' => $bvSimpleList));
$sql .= $bvObj->generateSql($bvList) . "\n\n";

// Generate usual Kpi
$kpiObj = new Kpi($this->backend_instance->db, $poller_id);
$kpiList = $kpiObj->getList(array('id_ba' => $baSimpleList));
$sql .= $kpiObj->generateSql($kpiList) . "\n\n";
$booleanKpiSimpleList = $this->getSimpleObjectList($kpiList, 'boolean_id');

// Generate boolean Kpi
$booleanKpiObj = new Boolean($this->backend_instance->db, $poller_id);
$booleanKpiList = $booleanKpiObj->getList($booleanKpiSimpleList);
$sql .= $booleanKpiObj->generateSql($booleanKpiList) . "\n\n";

// Generate Bam ACL
$bamAcl = new BamAcl($this->backend_instance->db, $poller_id);
$bamAclList = $bamAcl->getList(array('ba_group_id' => $bvSimpleList));
$sql .= $bamAcl->generateSql($bamAclList) . "\n\n";

// Generate Bam ACL
$bamUserPreferences = new BamUserPreferences($this->backend_instance->db, $poller_id);
$bamuserPreferencesList = $bamUserPreferences->getList();
$sql .= $bamUserPreferences->generateSql($bamuserPreferencesList) . "\n\n";

// Enable MySQL foreign key check
$sql .= $this->setForeignKey(1). "\n\n";
}
$this->createFile($this->backend_instance->getPath());
fwrite($this->fp, $sql);
$this->close_file();
Expand Down

0 comments on commit 7ce81af

Please sign in to comment.