From 7ce81aff5ae7fd0bff95e50154dac726eaf1e1c5 Mon Sep 17 00:00:00 2001 From: Etienne G Date: Wed, 16 Aug 2017 09:37:19 +0200 Subject: [PATCH] =?UTF-8?q?#8=20-=20Do=20not=20send=20BAM=20configuration?= =?UTF-8?q?=20unless=20the=20poller=20is=20link=20to=201=20BA=20=E2=80=A6?= =?UTF-8?q?=20(#9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * #8 - Do not send BAM configuration unless the poller is link to 1 BA at least * Coding style * Comment indentation --- .../core/class/configGenerate/Bam.php | 188 ++++++++++-------- 1 file changed, 103 insertions(+), 85 deletions(-) diff --git a/www/modules/centreon-poller-display-central/core/class/configGenerate/Bam.php b/www/modules/centreon-poller-display-central/core/class/configGenerate/Bam.php index 9a15042..bfd97fb 100644 --- a/www/modules/centreon-poller-display-central/core/class/configGenerate/Bam.php +++ b/www/modules/centreon-poller-display-central/core/class/configGenerate/Bam.php @@ -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; } @@ -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();