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

enh(poller): Adding a notification method in case of configuration change #8623

Merged
merged 1 commit into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,12 @@ public function findResource(int $monitoringServerId, string $resourceName): ?Mo
* @throws \Exception
*/
public function findLocalServer(): ?MonitoringServer;

/**
* We notify that the configuration has changed.
*
* @param MonitoringServer $monitoringServer Monitoring server to notify
* @throws \Exception
*/
public function notifyConfigurationChanged(MonitoringServer $monitoringServer): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,12 @@ public function findResource(int $monitoringServerId, string $resourceName): ?Mo
* @throws MonitoringServerException
*/
public function findLocalServer(): ?MonitoringServer;

/**
* We notify that the configuration has changed.
*
* @param MonitoringServer $monitoringServer Monitoring server to notify
* @throws MonitoringServerException
*/
public function notifyConfigurationChanged(MonitoringServer $monitoringServer): void;
}
17 changes: 17 additions & 0 deletions src/Centreon/Domain/MonitoringServer/MonitoringServerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,21 @@ public function findLocalServer(): ?MonitoringServer
throw new MonitoringServerException('Error when searching for the local monitoring servers', 0, $ex);
}
}

/**
* @inheritDoc
*/
public function notifyConfigurationChanged(MonitoringServer $monitoringServer): void
{
if ($monitoringServer->getId() === null && $monitoringServer->getName() === null) {
throw new MonitoringServerException(
'The id or name of the monitoring server must be defined and not null'
);
}
try {
$this->monitoringServerRepository->notifyConfigurationChanged($monitoringServer);
} catch (\Exception $ex) {
throw new MonitoringServerException('Error when notifying a configuration change', 0, $ex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,26 @@ public function findResource(int $monitoringServerId, string $resourceName): ?Mo
}
return null;
}

/**
* @inheritDoc
*/
public function notifyConfigurationChanged(MonitoringServer $monitoringServer): void
{
if ($monitoringServer->getId() !== null) {
$request = $this->translateDbName(
'UPDATE `:db`.nagios_server SET updated = "1" WHERE id = :server_id'
);
$statement = $this->db->prepare($request);
$statement->bindValue(':server_id', $monitoringServer->getId(), \PDO::PARAM_INT);
$statement->execute();
} elseif ($monitoringServer->getName() !== null) {
$request = $this->translateDbName(
'UPDATE `:db`.nagios_server SET updated = "1" WHERE name = :server_name'
);
$statement = $this->db->prepare($request);
$statement->bindValue(':server_name', $monitoringServer->getName(), \PDO::PARAM_STR);
$statement->execute();
}
}
}