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

Commit

Permalink
Adding a notification method in case of configuration change (#8623)
Browse files Browse the repository at this point in the history
  • Loading branch information
callapa authored Apr 17, 2020
1 parent 626325b commit c33595b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
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();
}
}
}

0 comments on commit c33595b

Please sign in to comment.