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

Commit

Permalink
fix(remote-server): add missing host poller relation in export (#7928)
Browse files Browse the repository at this point in the history
* fix(remote-server): add missing host poller relation in export
  • Loading branch information
lpinsivy authored and sc979 committed Oct 9, 2019
1 parent a026674 commit b7bd612
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
25 changes: 25 additions & 0 deletions www/class/config-generate-remote/Abstracts/AbstractHost.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use ConfigGenerateRemote\Relations\ContactHostRelation;
use ConfigGenerateRemote\Relations\ContactGroupHostRelation;
use ConfigGenerateRemote\Relations\HostTemplateRelation;
use ConfigGenerateRemote\Relations\HostPollerRelation;
use ConfigGenerateRemote\Relations\MacroHost;

abstract class AbstractHost extends AbstractObject
Expand Down Expand Up @@ -104,6 +105,7 @@ abstract class AbstractHost extends AbstractObject
protected $stmtHtpl = null;
protected $stmtContact = null;
protected $stmtCg = null;
protected $stmtPoller = null;

/**
* Get host extended information
Expand Down Expand Up @@ -213,6 +215,29 @@ protected function getHostTemplates(array &$host): void
}
}

/**
* Get linked poller
*
* @param array $host
* @return void
*/
protected function getHostPoller(array $host): void
{
if (is_null($this->stmtPoller)) {
$this->stmtPoller = $this->backendInstance->db->prepare(
"SELECT nagios_server_id
FROM ns_host_relation
WHERE host_host_id = :host_id"
);
}
$this->stmtPoller->bindParam(':host_id', $host['host_id'], PDO::PARAM_INT);
$this->stmtPoller->execute();
$pollerId = $this->stmtPoller->fetchAll(PDO::FETCH_COLUMN);

HostPollerRelation::getInstance($this->dependencyInjector)
->addRelation($pollerId[0], $host['host_id']);
}

/**
* Get linked contacts
*
Expand Down
1 change: 1 addition & 0 deletions www/class/config-generate-remote/Generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ private function resetObjects()
Relations\HostGroupRelation::getInstance($this->dependencyInjector)->reset();
Relations\HostServiceRelation::getInstance($this->dependencyInjector)->reset();
Relations\HostTemplateRelation::getInstance($this->dependencyInjector)->reset();
Relations\HostPollerRelation::getInstance($this->dependencyInjector)->reset();
Relations\MacroHost::getInstance($this->dependencyInjector)->reset();
Relations\NagiosServer::getInstance($this->dependencyInjector)->reset();
Relations\ServiceCategoriesRelation::getInstance($this->dependencyInjector)->reset();
Expand Down
1 change: 1 addition & 0 deletions www/class/config-generate-remote/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public function generateFromHostId(array &$host)

$this->getHostTimezone($host);
$this->getHostTemplates($host);
$this->getHostPoller($host);
$this->getHostCommands($host);
$this->getHostPeriods($host);

Expand Down
49 changes: 49 additions & 0 deletions www/class/config-generate-remote/Relations/HostPollerRelation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/*
* Copyright 2005 - 2019 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/

namespace ConfigGenerateRemote\Relations;

use ConfigGenerateRemote\Abstracts\AbstractObject;

class HostPollerRelation extends AbstractObject
{
protected $table = 'ns_host_relation';
protected $generateFilename = 'ns_host_relation.infile';
protected $attributesWrite = [
'nagios_server_id',
'host_host_id',
];

/**
* Add relation between host and poller
*
* @param integer $pollerId
* @param integer $hostId
* @return void
*/
public function addRelation(int $pollerId, int $hostId)
{
$relation = [
'nagios_server_id' => $pollerId,
'host_host_id' => $hostId,
];
$this->generateObjectInFile($relation, $hostId . '.' . $serviceId);
}
}

0 comments on commit b7bd612

Please sign in to comment.