From 3052abd1a48d4766cbcc8aedeefe60b4b45ea590 Mon Sep 17 00:00:00 2001 From: Laurent Calvet Date: Wed, 11 Dec 2019 18:58:43 +0100 Subject: [PATCH 01/14] Added API to manage the proxy configuration Added the topology rules in contact for the security --- composer.json | 3 +- config/Modules/Centreon.yaml | 7 + config/packages/validator/validation.yaml | 24 +++- .../Controller/ProxyController.php | 112 +++++++++++++++ src/Centreon/Domain/Contact/Contact.php | 19 ++- .../Interfaces/ProxyRepositoryInterface.php | 41 ++++++ .../Interfaces/ProxyServiceInterface.php | 42 ++++++ src/Centreon/Domain/Proxy/Proxy.php | 128 ++++++++++++++++++ src/Centreon/Domain/Proxy/ProxyService.php | 67 +++++++++ .../Contact/ContactRepositoryRDB.php | 115 +++++++++++++++- .../Proxy/ProxyRepositoryRDB.php | 92 +++++++++++++ .../CentreonEventSubscriber.php | 18 ++- 12 files changed, 653 insertions(+), 15 deletions(-) create mode 100644 src/Centreon/Application/Controller/ProxyController.php create mode 100644 src/Centreon/Domain/Proxy/Interfaces/ProxyRepositoryInterface.php create mode 100644 src/Centreon/Domain/Proxy/Interfaces/ProxyServiceInterface.php create mode 100644 src/Centreon/Domain/Proxy/Proxy.php create mode 100644 src/Centreon/Domain/Proxy/ProxyService.php create mode 100644 src/Centreon/Infrastructure/Proxy/ProxyRepositoryRDB.php diff --git a/composer.json b/composer.json index e675620b072..629972e138d 100644 --- a/composer.json +++ b/composer.json @@ -54,7 +54,8 @@ "symfony/translation": "4.3.*", "symfony/expression-language": "4.3.*", "ext-json": "*", - "justinrainbow/json-schema": "^5.2" + "justinrainbow/json-schema": "^5.2", + "ext-pdo": "*" }, "autoload": { "psr-4": { diff --git a/config/Modules/Centreon.yaml b/config/Modules/Centreon.yaml index 09b4efa20a8..e97154da0e1 100644 --- a/config/Modules/Centreon.yaml +++ b/config/Modules/Centreon.yaml @@ -98,3 +98,10 @@ services: Centreon\Domain\Acknowledgement\Interfaces\AcknowledgementServiceInterface: class: Centreon\Domain\Acknowledgement\AcknowledgementService + + # Proxy configuration + Centreon\Domain\Proxy\Interfaces\ProxyServiceInterface: + class: Centreon\Domain\Proxy\ProxyService + + Centreon\Domain\Proxy\Interfaces\ProxyRepositoryInterface: + class: Centreon\Infrastructure\Proxy\ProxyRepositoryRDB \ No newline at end of file diff --git a/config/packages/validator/validation.yaml b/config/packages/validator/validation.yaml index 1ee39e83a7b..42c99265e13 100644 --- a/config/packages/validator/validation.yaml +++ b/config/packages/validator/validation.yaml @@ -81,4 +81,26 @@ Centreon\Domain\Downtime\Downtime: type: integer pollerId: - Type: - type: integer \ No newline at end of file + type: integer + +# Used to validate the Downtime entity +Centreon\Domain\Proxy\Proxy: + properties: + url: + - Type: + type: string + - NotNull: ~ + port: + - Type: + type: integer + - PositiveOrZero: ~ + - LessThanOrEqual: 65535 + - NotNull: ~ + user: + - Type: + type: string + - NotNull: ~ + password: + - Type: + type: string + - NotNull: ~ \ No newline at end of file diff --git a/src/Centreon/Application/Controller/ProxyController.php b/src/Centreon/Application/Controller/ProxyController.php new file mode 100644 index 00000000000..3ade165d2de --- /dev/null +++ b/src/Centreon/Application/Controller/ProxyController.php @@ -0,0 +1,112 @@ +proxyService = $proxyService; + } + + /** + * @IsGranted("ROLE_API_CONFIGURATION", message="You are not authorized to access this resource") + * @Rest\Get( + * "/configuration/proxy", + * condition="request.attributes.get('version.is_beta') == true", + * name="configuration.proxy.getProxy") + * @return View + * @throws \Exception + */ + public function getProxy(): View + { + if (!$this->getUser()->isAdmin() && !$this->isGranted('ROLE_ADMINISTRATION_PARAMETERS_CENTREON_UI')) { + return $this->view(null, Response::HTTP_FORBIDDEN); + } + return $this->view($this->proxyService->getProxy()); + } + + /** + * @IsGranted("ROLE_API_CONFIGURATION", message="You are not authorized to access this resource") + * @Rest\Post( + * "/configuration/proxy", + * condition="request.attributes.get('version.is_beta') == true", + * name="configuration.proxy.updateProxy") + * @param Request $request + * @param EntityValidator $entityValidator + * @param SerializerInterface $serializer + * @return View + * @throws \Exception + */ + public function updateProxy( + Request $request, + EntityValidator $entityValidator, + SerializerInterface $serializer + ): View { + if (!$this->getUser()->isAdmin() && !$this->isGranted('ROLE_ADMINISTRATION_PARAMETERS_CENTREON_UI')) { + return $this->view(null, Response::HTTP_FORBIDDEN); + } + + $errors = $entityValidator->validateEntity( + Proxy::class, + json_decode($request->getContent(), true), + ['Default'], + false // We don't allow extra fields + ); + if ($errors->count() > 0) { + throw new ValidationFailedException($errors); + } + + $proxy = $serializer->deserialize( + $request->getContent(), + Proxy::class, + 'json' + ); + + $this->proxyService->updateProxy($proxy); + return $this->view(); + } +} diff --git a/src/Centreon/Domain/Contact/Contact.php b/src/Centreon/Domain/Contact/Contact.php index 56ca11749aa..16ca135aab2 100644 --- a/src/Centreon/Domain/Contact/Contact.php +++ b/src/Centreon/Domain/Contact/Contact.php @@ -103,6 +103,11 @@ class Contact implements UserInterface, ContactInterface */ private $roles = []; + /** + * @var string[] List of topology names to which the contact can access + */ + private $topologies = []; + /** * @return int */ @@ -303,7 +308,7 @@ public function setEncodedPassword(?string $encodedPassword): self */ public function getRoles() { - return $this->roles; + return array_merge($this->roles, $this->topologies); } /** @@ -425,4 +430,16 @@ private function removeRole(string $roleName): void { unset($this->roles[$roleName]); } + + public function addTopology(string $topologyName): void + { + if (!in_array($topologyName, $this->topologies)) { + $this->topologies[] = $topologyName; + } + } + + public function hasTopology(string $topologyName): bool + { + return in_array($topologyName, $this->topologies); + } } diff --git a/src/Centreon/Domain/Proxy/Interfaces/ProxyRepositoryInterface.php b/src/Centreon/Domain/Proxy/Interfaces/ProxyRepositoryInterface.php new file mode 100644 index 00000000000..f733776b28b --- /dev/null +++ b/src/Centreon/Domain/Proxy/Interfaces/ProxyRepositoryInterface.php @@ -0,0 +1,41 @@ +url; + } + + /** + * @param string|null $url + * @return Proxy + */ + public function setUrl (?string $url): Proxy + { + $this->url = $url; + return $this; + } + + /** + * @return int|null + */ + public function getPort (): ?int + { + return $this->port; + } + + /** + * @param int|null $port + * @return Proxy + */ + public function setPort (?int $port): Proxy + { + $this->port = $port; + return $this; + } + + /** + * @return string|null + */ + public function getUser (): ?string + { + return $this->user; + } + + /** + * @param string|null $user + * @return Proxy + */ + public function setUser (?string $user): Proxy + { + $this->user = $user; + return $this; + } + + /** + * @return string|null + */ + public function getPassword (): ?string + { + return $this->password; + } + + /** + * @param string|null $password + * @return Proxy + */ + public function setPassword (?string $password): Proxy + { + $this->password = $password; + return $this; + } +} diff --git a/src/Centreon/Domain/Proxy/ProxyService.php b/src/Centreon/Domain/Proxy/ProxyService.php new file mode 100644 index 00000000000..b29e02a72b8 --- /dev/null +++ b/src/Centreon/Domain/Proxy/ProxyService.php @@ -0,0 +1,67 @@ +proxyRepository = $proxyRepository; + } + + /** + * @inheritDoc + */ + public function getProxy (): Proxy + { + return $this->proxyRepository->getProxy(); + } + + /** + * @inheritDoc + */ + public function updateProxy(Proxy $proxy): void + { + $this->proxyRepository->updateProxy($proxy); + } +} diff --git a/src/Centreon/Infrastructure/Contact/ContactRepositoryRDB.php b/src/Centreon/Infrastructure/Contact/ContactRepositoryRDB.php index abf46e81987..409d51e36ab 100644 --- a/src/Centreon/Infrastructure/Contact/ContactRepositoryRDB.php +++ b/src/Centreon/Infrastructure/Contact/ContactRepositoryRDB.php @@ -62,7 +62,8 @@ public function findById(int $contactId): ?Contact if (($result = $statement->fetch(\PDO::FETCH_ASSOC)) !== false) { $contact = $this->createContact($result); - $this->findAndAddRules($contact); + $this->addActionRules($contact); + $this->addTopologyRules($contact); } return $contact; } @@ -86,7 +87,8 @@ public function findByName(string $name): ?Contact $contact = null; if (($result = $statement->fetch(\PDO::FETCH_ASSOC)) !== false) { $contact = $this->createContact($result); - $this->findAndAddRules($contact); + $this->addActionRules($contact); + $this->addTopologyRules($contact); } return $contact; @@ -112,18 +114,117 @@ public function findBySession(string $sessionId): ?Contact $contact = null; if (($result = $statement->fetch(\PDO::FETCH_ASSOC)) !== false) { $contact = $this->createContact($result); - $this->findAndAddRules($contact); + $this->addActionRules($contact); + $this->addTopologyRules($contact); } return $contact; } + /** + * @param Contact $contact + */ + private function addTopologyRules(Contact $contact): void + { + $request = + 'SELECT topology.topology_name, topology.topology_page, + topology.topology_parent, access.access_right + FROM `:db`.topology + LEFT JOIN ( + SELECT topology.topology_id, acltr.access_right + FROM `:db`.contact contact + LEFT JOIN `:db`.contactgroup_contact_relation cgcr + ON cgcr.contact_contact_id = contact.contact_id + LEFT JOIN `:db`.acl_group_contactgroups_relations gcgr + ON gcgr.cg_cg_id = cgcr.contactgroup_cg_id + LEFT JOIN `:db`.acl_group_contacts_relations gcr + ON gcr.contact_contact_id = contact.contact_id + LEFT JOIN `:db`.acl_group_topology_relations agtr + ON agtr.acl_group_id = gcr.acl_group_id + OR agtr.acl_group_id = gcgr.acl_group_id + LEFT JOIN `:db`.acl_topology_relations acltr + ON acltr.acl_topo_id = agtr.acl_topology_id + INNER JOIN `:db`.topology + ON topology.topology_id = acltr.topology_topology_id + WHERE contact.contact_id = :contact_id + AND topology.is_react = \'0\' + ) AS access + ON access.topology_id = topology.topology_id + WHERE topology.topology_page IS NOT NULL + ORDER BY topology.topology_page'; + + $prepare = $this->db->prepare( + $this->translateDbName($request) + ); + $prepare->bindValue(':contact_id', $contact->getId(), \PDO::PARAM_INT); + $prepare->execute(); + + + $topologies = []; + $rightsCounter = 0; + while ($row = $prepare->fetch(\PDO::FETCH_ASSOC)) { + $topologies[$row['topology_page']] = [ + 'name' => $row['topology_name'], + 'right' => (int) $row['access_right'] + ]; + if ($row['access_right'] !== null) { + $rightsCounter++; + } + } + + $nameOfTopologiesRules = []; + if ($rightsCounter > 0) { + foreach ($topologies as $topologyPage => $details) { + $originalTopologyPage = $topologyPage; + if ($details['right'] === 0 || strlen((string) $topologyPage) < 5) { + continue; + } + $ruleName = $lvl2Name = $lvl3Name = $lvl4Name = null; + if (strlen((string) $topologyPage) === 7) { + $lvl4Name = $topologies[$topologyPage]['name']; + $topologyPage = (int) substr((string) $topologyPage, 0, 5); + + // To avoid create entry for the parent menu + $nameOfTopologiesRules[$topologyPage] = null; + } + if (strlen((string) $topologyPage) === 5) { + if ($lvl4Name === null && array_key_exists($topologyPage, $nameOfTopologiesRules)) { + continue; + } + $lvl3Name = $topologies[$topologyPage]['name']; + $topologyPage = (int) substr((string) $topologyPage, 0, 3); + } + if (strlen((string) $topologyPage) === 3) { + $lvl2Name = $topologies[$topologyPage]['name']; + $topologyPage = (int) substr((string) $topologyPage, 0, 1); + } + if (strlen((string) $topologyPage) === 1) { + $ruleName = $topologies[$topologyPage]['name']; + } + if ($lvl2Name !== null) $ruleName .= '_' . $lvl2Name; + if ($lvl3Name !== null) $ruleName .= '_' . $lvl3Name; + if ($lvl4Name !== null) $ruleName .= '_' . $lvl4Name; + + $ruleName .= ($details['right'] === 2) ? '_R' : '_RW'; + + $nameOfTopologiesRules[$originalTopologyPage] = $ruleName; + } + foreach ($nameOfTopologiesRules as $page => $name) { + if ($name !== null ) { + $name = preg_replace(['/\s/', '/\W/'], ['_', ''], $name); + $name = strtoupper($name); + $contact->addTopology($name); + } + } + } + } + /** * Find and add all rules for a contact. * * @param Contact $contact Contact for which we want to find and add all rules */ - private function findAndAddRules(Contact $contact): void + private function addActionRules(Contact $contact): void { $request = 'SELECT DISTINCT rules.acl_action_name @@ -151,7 +252,7 @@ private function findAndAddRules(Contact $contact): void $statement->execute(); while ($result = $statement->fetch(\PDO::FETCH_ASSOC)) { - $this->addSpecificRule($contact, $result['acl_action_name']); + $this->addActionRule($contact, $result['acl_action_name']); } } @@ -178,12 +279,12 @@ private function createContact(array $contact): Contact } /** - * Add a specific rule to contact. + * Add an action rule to contact. * * @param Contact $contact Contact for which we want to add rule * @param string $ruleName Rule to add */ - private function addSpecificRule(Contact $contact, string $ruleName): void + private function addActionRule(Contact $contact, string $ruleName): void { switch ($ruleName) { case 'host_acknowledgement': diff --git a/src/Centreon/Infrastructure/Proxy/ProxyRepositoryRDB.php b/src/Centreon/Infrastructure/Proxy/ProxyRepositoryRDB.php new file mode 100644 index 00000000000..f71c194f9a4 --- /dev/null +++ b/src/Centreon/Infrastructure/Proxy/ProxyRepositoryRDB.php @@ -0,0 +1,92 @@ +db = $db; + } + + /** + * @inheritDoc + */ + public function updateProxy (Proxy $proxy): void + { + $request = + 'DELETE FROM `:db`.options + WHERE `key` IN (\'proxy_url\', \'proxy_port\', \'proxy_user\', \'proxy_password\')'; + + $request = $this->translateDbName($request); + + $this->db->query($request); + + $request = 'INSERT INTO `:db`.options (`key`,`value`) VALUES (:key, :value)'; + $request = $this->translateDbName($request); + $prepareStatement = $this->db->prepare($request); + + $data = [ + 'proxy_url' =>$proxy->getUrl(), + 'proxy_port' => $proxy->getPort(), + 'proxy_user' =>$proxy->getUser(), + 'proxy_password' =>$proxy->getPassword() + ]; + + foreach ($data as $key => $value) { + $prepareStatement->bindParam(':key', $key); + $prepareStatement->bindParam(':value', $value); + $prepareStatement->execute(); + } + } + + /** + * @inheritDoc + */ + public function getProxy (): Proxy + { + $request = $this->translateDbName( + 'SELECT * FROM `:db`.options WHERE `key` LIKE \'proxy_%\'' + ); + + $statement = $this->db->query($request); + $proxyDetails = $statement->fetchAll(\PDO::FETCH_KEY_PAIR); + + $proxy = new Proxy(); + if (!empty($proxyDetails)) { + $proxy->setUrl($proxyDetails['proxy_url'] ?? null); + $proxy->setPort(((int) $proxyDetails['proxy_port']) ?? null); + $proxy->setUser($proxyDetails['proxy_user'] ?? null); + $proxy->setPassword($proxyDetails['proxy_password'] ?? null); + } + + return $proxy; + } +} diff --git a/src/EventSubscriber/CentreonEventSubscriber.php b/src/EventSubscriber/CentreonEventSubscriber.php index 70b12b5e7ba..ab7dee06105 100644 --- a/src/EventSubscriber/CentreonEventSubscriber.php +++ b/src/EventSubscriber/CentreonEventSubscriber.php @@ -154,6 +154,8 @@ public function initRequestParameters(RequestEvent $request):void { $query = $request->getRequest()->query->all(); + + $limit = (int) ($query[RequestParameters::NAME_FOR_LIMIT] ?? RequestParameters::DEFAULT_LIMIT); $this->requestParameters->setLimit($limit); @@ -306,10 +308,16 @@ public function onKernelException(ExceptionEvent $event) * we create a custom error message. * If we don't do that a HTML error will appeared. */ - if ($errorIsBeforeController && $event->getException()->getCode() !== 403) { - $errorCode = $event->getException()->getCode() > 0 - ? $event->getException()->getCode() - : Response::HTTP_INTERNAL_SERVER_ERROR; + if ($errorIsBeforeController) { + if ($event->getException()->getCode() !== 403) { + $errorCode = $event->getException()->getCode() > 0 + ? $event->getException()->getCode() + : Response::HTTP_INTERNAL_SERVER_ERROR; + $statusCode = Response::HTTP_INTERNAL_SERVER_ERROR; + } else { + $errorCode = $event->getException()->getCode(); + $statusCode = Response::HTTP_FORBIDDEN; + } // Manage exception outside controllers $event->setResponse( @@ -318,7 +326,7 @@ public function onKernelException(ExceptionEvent $event) 'code' => $errorCode, 'message' => $event->getException()->getMessage() ]), - Response::HTTP_INTERNAL_SERVER_ERROR + $statusCode ) ); } elseif (!$errorIsBeforeController) { From 740c7ac6610c8f20a43196dbc862117ba1619aa5 Mon Sep 17 00:00:00 2001 From: Laurent Calvet Date: Thu, 12 Dec 2019 09:45:21 +0100 Subject: [PATCH 02/14] Fix PSR2 --- .../Application/Controller/ProxyController.php | 2 +- .../Proxy/Interfaces/ProxyServiceInterface.php | 2 +- src/Centreon/Domain/Proxy/Proxy.php | 16 ++++++++-------- src/Centreon/Domain/Proxy/ProxyService.php | 4 ++-- .../Contact/ContactRepositoryRDB.php | 14 ++++++++++---- .../Infrastructure/Proxy/ProxyRepositoryRDB.php | 7 +++---- 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/Centreon/Application/Controller/ProxyController.php b/src/Centreon/Application/Controller/ProxyController.php index 3ade165d2de..809eb34c955 100644 --- a/src/Centreon/Application/Controller/ProxyController.php +++ b/src/Centreon/Application/Controller/ProxyController.php @@ -47,7 +47,7 @@ class ProxyController extends AbstractFOSRestController */ private $proxyService; - public function __construct (ProxyServiceInterface $proxyService) + public function __construct(ProxyServiceInterface $proxyService) { $this->proxyService = $proxyService; } diff --git a/src/Centreon/Domain/Proxy/Interfaces/ProxyServiceInterface.php b/src/Centreon/Domain/Proxy/Interfaces/ProxyServiceInterface.php index 3db6f8baa1b..7b92fdff535 100644 --- a/src/Centreon/Domain/Proxy/Interfaces/ProxyServiceInterface.php +++ b/src/Centreon/Domain/Proxy/Interfaces/ProxyServiceInterface.php @@ -31,7 +31,7 @@ interface ProxyServiceInterface * * @param Proxy $proxy Proxy details */ - public function updateProxy (Proxy $proxy): void; + public function updateProxy(Proxy $proxy): void; /** * Get the proxy configuration. diff --git a/src/Centreon/Domain/Proxy/Proxy.php b/src/Centreon/Domain/Proxy/Proxy.php index f5693a5475e..284fa10886f 100644 --- a/src/Centreon/Domain/Proxy/Proxy.php +++ b/src/Centreon/Domain/Proxy/Proxy.php @@ -57,7 +57,7 @@ class Proxy /** * @return string|null */ - public function getUrl (): ?string + public function getUrl(): ?string { return $this->url; } @@ -66,7 +66,7 @@ public function getUrl (): ?string * @param string|null $url * @return Proxy */ - public function setUrl (?string $url): Proxy + public function setUrl(?string $url): Proxy { $this->url = $url; return $this; @@ -75,7 +75,7 @@ public function setUrl (?string $url): Proxy /** * @return int|null */ - public function getPort (): ?int + public function getPort(): ?int { return $this->port; } @@ -84,7 +84,7 @@ public function getPort (): ?int * @param int|null $port * @return Proxy */ - public function setPort (?int $port): Proxy + public function setPort(?int $port): Proxy { $this->port = $port; return $this; @@ -93,7 +93,7 @@ public function setPort (?int $port): Proxy /** * @return string|null */ - public function getUser (): ?string + public function getUser(): ?string { return $this->user; } @@ -102,7 +102,7 @@ public function getUser (): ?string * @param string|null $user * @return Proxy */ - public function setUser (?string $user): Proxy + public function setUser(?string $user): Proxy { $this->user = $user; return $this; @@ -111,7 +111,7 @@ public function setUser (?string $user): Proxy /** * @return string|null */ - public function getPassword (): ?string + public function getPassword(): ?string { return $this->password; } @@ -120,7 +120,7 @@ public function getPassword (): ?string * @param string|null $password * @return Proxy */ - public function setPassword (?string $password): Proxy + public function setPassword(?string $password): Proxy { $this->password = $password; return $this; diff --git a/src/Centreon/Domain/Proxy/ProxyService.php b/src/Centreon/Domain/Proxy/ProxyService.php index b29e02a72b8..ee90f46548f 100644 --- a/src/Centreon/Domain/Proxy/ProxyService.php +++ b/src/Centreon/Domain/Proxy/ProxyService.php @@ -44,7 +44,7 @@ class ProxyService implements ProxyServiceInterface * * @param ProxyRepositoryInterface $proxyRepository */ - public function __construct (ProxyRepositoryInterface $proxyRepository) + public function __construct(ProxyRepositoryInterface $proxyRepository) { $this->proxyRepository = $proxyRepository; } @@ -52,7 +52,7 @@ public function __construct (ProxyRepositoryInterface $proxyRepository) /** * @inheritDoc */ - public function getProxy (): Proxy + public function getProxy(): Proxy { return $this->proxyRepository->getProxy(); } diff --git a/src/Centreon/Infrastructure/Contact/ContactRepositoryRDB.php b/src/Centreon/Infrastructure/Contact/ContactRepositoryRDB.php index 409d51e36ab..3b2f6476c49 100644 --- a/src/Centreon/Infrastructure/Contact/ContactRepositoryRDB.php +++ b/src/Centreon/Infrastructure/Contact/ContactRepositoryRDB.php @@ -201,16 +201,22 @@ private function addTopologyRules(Contact $contact): void if (strlen((string) $topologyPage) === 1) { $ruleName = $topologies[$topologyPage]['name']; } - if ($lvl2Name !== null) $ruleName .= '_' . $lvl2Name; - if ($lvl3Name !== null) $ruleName .= '_' . $lvl3Name; - if ($lvl4Name !== null) $ruleName .= '_' . $lvl4Name; + if ($lvl2Name !== null) { + $ruleName .= '_' . $lvl2Name; + } + if ($lvl3Name !== null) { + $ruleName .= '_' . $lvl3Name; + } + if ($lvl4Name !== null) { + $ruleName .= '_' . $lvl4Name; + } $ruleName .= ($details['right'] === 2) ? '_R' : '_RW'; $nameOfTopologiesRules[$originalTopologyPage] = $ruleName; } foreach ($nameOfTopologiesRules as $page => $name) { - if ($name !== null ) { + if ($name !== null) { $name = preg_replace(['/\s/', '/\W/'], ['_', ''], $name); $name = strtoupper($name); $contact->addTopology($name); diff --git a/src/Centreon/Infrastructure/Proxy/ProxyRepositoryRDB.php b/src/Centreon/Infrastructure/Proxy/ProxyRepositoryRDB.php index f71c194f9a4..93801ce67d2 100644 --- a/src/Centreon/Infrastructure/Proxy/ProxyRepositoryRDB.php +++ b/src/Centreon/Infrastructure/Proxy/ProxyRepositoryRDB.php @@ -31,7 +31,7 @@ class ProxyRepositoryRDB extends AbstractRepositoryDRB implements ProxyRepositoryInterface { - public function __construct (DatabaseConnection $db) + public function __construct(DatabaseConnection $db) { $this->db = $db; } @@ -39,7 +39,7 @@ public function __construct (DatabaseConnection $db) /** * @inheritDoc */ - public function updateProxy (Proxy $proxy): void + public function updateProxy(Proxy $proxy): void { $request = 'DELETE FROM `:db`.options @@ -70,7 +70,7 @@ public function updateProxy (Proxy $proxy): void /** * @inheritDoc */ - public function getProxy (): Proxy + public function getProxy(): Proxy { $request = $this->translateDbName( 'SELECT * FROM `:db`.options WHERE `key` LIKE \'proxy_%\'' @@ -86,7 +86,6 @@ public function getProxy (): Proxy $proxy->setUser($proxyDetails['proxy_user'] ?? null); $proxy->setPassword($proxyDetails['proxy_password'] ?? null); } - return $proxy; } } From 9afd5dcd91ff2d294454c11508a677e9fae342b6 Mon Sep 17 00:00:00 2001 From: Laurent Calvet Date: Thu, 12 Dec 2019 09:58:44 +0100 Subject: [PATCH 03/14] Fix phpstan warning (lv7) --- .../Application/Controller/ProxyController.php | 8 +++++--- src/Centreon/Domain/Contact/Contact.php | 2 +- .../Contact/ContactRepositoryRDB.php | 2 +- .../Proxy/ProxyRepositoryRDB.php | 18 +++++++++--------- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Centreon/Application/Controller/ProxyController.php b/src/Centreon/Application/Controller/ProxyController.php index 809eb34c955..5ae4992c7d1 100644 --- a/src/Centreon/Application/Controller/ProxyController.php +++ b/src/Centreon/Application/Controller/ProxyController.php @@ -92,16 +92,18 @@ public function updateProxy( $errors = $entityValidator->validateEntity( Proxy::class, - json_decode($request->getContent(), true), + json_decode((string) $request->getContent(), true), ['Default'], false // We don't allow extra fields ); if ($errors->count() > 0) { throw new ValidationFailedException($errors); } - + /** + * @var Proxy $proxy + */ $proxy = $serializer->deserialize( - $request->getContent(), + (string)$request->getContent(), Proxy::class, 'json' ); diff --git a/src/Centreon/Domain/Contact/Contact.php b/src/Centreon/Domain/Contact/Contact.php index 16ca135aab2..d30585d08ec 100644 --- a/src/Centreon/Domain/Contact/Contact.php +++ b/src/Centreon/Domain/Contact/Contact.php @@ -352,7 +352,7 @@ public function getUsername() * This is important if, at any given point, sensitive information like * the plain-text password is stored on this object. */ - public function eraseCredentials() + public function eraseCredentials(): void { // Nothing to do. But we must to define this method } diff --git a/src/Centreon/Infrastructure/Contact/ContactRepositoryRDB.php b/src/Centreon/Infrastructure/Contact/ContactRepositoryRDB.php index 3b2f6476c49..284a63150ae 100644 --- a/src/Centreon/Infrastructure/Contact/ContactRepositoryRDB.php +++ b/src/Centreon/Infrastructure/Contact/ContactRepositoryRDB.php @@ -265,7 +265,7 @@ private function addActionRules(Contact $contact): void /** * Create a contact based on the data. * - * @param array $contact Array of values representing the contact informations + * @param mixed[] $contact Array of values representing the contact information * @return Contact Returns a new instance of contact */ private function createContact(array $contact): Contact diff --git a/src/Centreon/Infrastructure/Proxy/ProxyRepositoryRDB.php b/src/Centreon/Infrastructure/Proxy/ProxyRepositoryRDB.php index 93801ce67d2..c5eda838d69 100644 --- a/src/Centreon/Infrastructure/Proxy/ProxyRepositoryRDB.php +++ b/src/Centreon/Infrastructure/Proxy/ProxyRepositoryRDB.php @@ -75,16 +75,16 @@ public function getProxy(): Proxy $request = $this->translateDbName( 'SELECT * FROM `:db`.options WHERE `key` LIKE \'proxy_%\'' ); - - $statement = $this->db->query($request); - $proxyDetails = $statement->fetchAll(\PDO::FETCH_KEY_PAIR); - $proxy = new Proxy(); - if (!empty($proxyDetails)) { - $proxy->setUrl($proxyDetails['proxy_url'] ?? null); - $proxy->setPort(((int) $proxyDetails['proxy_port']) ?? null); - $proxy->setUser($proxyDetails['proxy_user'] ?? null); - $proxy->setPassword($proxyDetails['proxy_password'] ?? null); + $statement = $this->db->query($request); + if ($statement !== false) { + $proxyDetails = $statement->fetchAll(\PDO::FETCH_KEY_PAIR); + if (!empty($proxyDetails)) { + $proxy->setUrl($proxyDetails['proxy_url'] ?? null); + $proxy->setPort(((int) $proxyDetails['proxy_port']) ?? null); + $proxy->setUser($proxyDetails['proxy_user'] ?? null); + $proxy->setPassword($proxyDetails['proxy_password'] ?? null); + } } return $proxy; } From 8f1c06beebac5ecf6f6b639ade51a155cd760c18 Mon Sep 17 00:00:00 2001 From: Laurent Calvet Date: Thu, 12 Dec 2019 10:07:30 +0100 Subject: [PATCH 04/14] Remove unused imports --- src/Centreon/Application/Controller/ProxyController.php | 7 +++++-- .../Domain/Proxy/Interfaces/ProxyServiceInterface.php | 1 - src/Centreon/Domain/Proxy/ProxyService.php | 5 +---- src/Centreon/Infrastructure/Proxy/ProxyRepositoryRDB.php | 3 --- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Centreon/Application/Controller/ProxyController.php b/src/Centreon/Application/Controller/ProxyController.php index 5ae4992c7d1..de039b24272 100644 --- a/src/Centreon/Application/Controller/ProxyController.php +++ b/src/Centreon/Application/Controller/ProxyController.php @@ -21,11 +21,9 @@ namespace Centreon\Application\Controller; -use Centreon\Domain\Contact\Contact; use Centreon\Domain\Entity\EntityValidator; use Centreon\Domain\Proxy\Interfaces\ProxyServiceInterface; use Centreon\Domain\Proxy\Proxy; -use Centreon\Domain\Proxy\ProxyService; use FOS\RestBundle\Controller\AbstractFOSRestController; use FOS\RestBundle\View\View; use FOS\RestBundle\Controller\Annotations as Rest; @@ -47,6 +45,11 @@ class ProxyController extends AbstractFOSRestController */ private $proxyService; + /** + * ProxyController constructor. + * + * @param ProxyServiceInterface $proxyService + */ public function __construct(ProxyServiceInterface $proxyService) { $this->proxyService = $proxyService; diff --git a/src/Centreon/Domain/Proxy/Interfaces/ProxyServiceInterface.php b/src/Centreon/Domain/Proxy/Interfaces/ProxyServiceInterface.php index 7b92fdff535..5b014ed8653 100644 --- a/src/Centreon/Domain/Proxy/Interfaces/ProxyServiceInterface.php +++ b/src/Centreon/Domain/Proxy/Interfaces/ProxyServiceInterface.php @@ -25,7 +25,6 @@ interface ProxyServiceInterface { - /** * Update the proxy configuration. * diff --git a/src/Centreon/Domain/Proxy/ProxyService.php b/src/Centreon/Domain/Proxy/ProxyService.php index ee90f46548f..45dd87137d6 100644 --- a/src/Centreon/Domain/Proxy/ProxyService.php +++ b/src/Centreon/Domain/Proxy/ProxyService.php @@ -23,17 +23,14 @@ use Centreon\Domain\Proxy\Interfaces\ProxyRepositoryInterface; use Centreon\Domain\Proxy\Interfaces\ProxyServiceInterface; -use phpDocumentor\Reflection\Types\Boolean; /** - * This class is designed to manage proxy-related actions such as configuration or testing. + * This class is designed to manage proxy-related actions such as configuration. * * @package Centreon\Domain\Proxy */ class ProxyService implements ProxyServiceInterface { - const VALIDATION_GROUPS_PROXY = ['proxy']; - /** * @var ProxyRepositoryInterface */ diff --git a/src/Centreon/Infrastructure/Proxy/ProxyRepositoryRDB.php b/src/Centreon/Infrastructure/Proxy/ProxyRepositoryRDB.php index c5eda838d69..c5fe073bdbf 100644 --- a/src/Centreon/Infrastructure/Proxy/ProxyRepositoryRDB.php +++ b/src/Centreon/Infrastructure/Proxy/ProxyRepositoryRDB.php @@ -23,9 +23,6 @@ use Centreon\Domain\Proxy\Interfaces\ProxyRepositoryInterface; use Centreon\Domain\Proxy\Proxy; -use Centreon\Domain\TaskHandler\Interfaces\TaskHandlerServiceInterface; -use Centreon\Domain\TaskHandler\TaskHandlerResponse; -use Centreon\Domain\TaskHandler\TaskHandlerService; use Centreon\Infrastructure\DatabaseConnection; use Centreon\Infrastructure\Repository\AbstractRepositoryDRB; From c77537140316a5823cfc7ac13f11ee324d47c198 Mon Sep 17 00:00:00 2001 From: Laurent Calvet Date: Thu, 12 Dec 2019 11:36:14 +0100 Subject: [PATCH 05/14] Update documentation --- doc/API/centreon-api-v2.html | 59 +++++++++++++++++---------- doc/API/centreon-api-v2.yaml | 79 +++++++++++++++++++++++++++++++++++- 2 files changed, 116 insertions(+), 22 deletions(-) diff --git a/doc/API/centreon-api-v2.html b/doc/API/centreon-api-v2.html index bb992253bc2..b52f26ea617 100644 --- a/doc/API/centreon-api-v2.html +++ b/doc/API/centreon-api-v2.html @@ -308,7 +308,7 @@ -

Information

All dates are in ISO 8601 format

Authentication

There are two modes of authentication:

@@ -357,7 +358,7 @@

Responses

200

successful operation

403

Forbidden

500

Internal Server Error

-
get /acknowledgements/hosts
http://localhost/centreon/api/beta/acknowledgements/hosts

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result":
    [
    ],
  • "meta":
    {
    }
}

Adds an acknowledgement on host

Authorizations:
Request Body schema: application/json

Acknowledgment

+
get /acknowledgements/hosts
http://localhost/centreon/api/beta/acknowledgements/hosts

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result":
    [
    ],
  • "meta":
    {
    }
}

Adds an acknowledgement on host

Authorizations:
Request Body schema: application/json

Acknowledgment

comment
string

Short description of the acknowledgement

host_id
integer <int64>

Unique id of the host

is_notify_contacts
boolean

Indicates whether notification is send to the contacts linked to the host or service

@@ -377,7 +378,7 @@

Responses

200

successful operation

403

Forbidden

500

Internal Server Error

-
get /acknowledgements/services
http://localhost/centreon/api/beta/acknowledgements/services

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result":
    [
    ],
  • "meta":
    {
    }
}

Adds an acknowledgement on service

Authorizations:
Request Body schema: application/json

Acknowledgment

+
get /acknowledgements/services
http://localhost/centreon/api/beta/acknowledgements/services

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result":
    [
    ],
  • "meta":
    {
    }
}

Adds an acknowledgement on service

Authorizations:
Request Body schema: application/json

Acknowledgment

comment
string

Short description of the acknowledgement

host_id
integer <int64>

Unique id of the host

is_notify_contacts
boolean

Indicates whether notification is send to the contacts linked to the host or service

@@ -419,7 +420,23 @@

Responses

200

successful operation

403

Forbidden

500

Internal Server Error

-
get /configuration/monitoring-servers
http://localhost/centreon/api/beta/configuration/monitoring-servers

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result":
    [
    ],
  • "meta":
    {
    }
}

Downtime

This API allow to:

+
get /configuration/monitoring-servers
http://localhost/centreon/api/beta/configuration/monitoring-servers

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result":
    [
    ],
  • "meta":
    {
    }
}

Proxy

This API allow to:

+
    +
  • Show the default proxy configuration of Centreon
  • +
  • Update the default proxy configuration of Centreon
  • +
+

Display the default configuration of the Centreon proxy

Authorizations:

Responses

200

successful operation

+
403

Forbidden

+
500

Internal Server Error

+
get /configuration/proxy
http://localhost/centreon/api/beta/configuration/proxy

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "url": "string",
  • "port": 0,
  • "user": "string",
  • "password": "string"
}

Update the default configuration of the Centreon proxy

Authorizations:
Request Body schema: application/json

Proxy configuration

+
url
required
string

Url of the proxy

+
port
required
integer [ 0 .. 65535 ]

Port of the proxy

+
user
required
string

Login of the proxy

+
password
required
string

Password of the proxy

+

Responses

204

Command sent

+
403

Forbidden

+
500

Internal Server Error

+
post /configuration/proxy
http://localhost/centreon/api/beta/configuration/proxy

Request samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "url": "string",
  • "port": 0,
  • "user": "string",
  • "password": "string"
}

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "message": "string"
}

Downtime

This API allow to:

  • Show hosts and services downtimes
  • Add a downtime on host or service
  • @@ -454,7 +471,7 @@

Responses

200

successful operation

403

Forbidden

500

Internal Server Error

-
get /monitoring/hosts/downtimes
http://localhost/centreon/api/beta/monitoring/hosts/downtimes

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result":
    [
    ],
  • "meta":
    {
    }
}

List all downtimes of one host

List all downtimes of one host

+
get /monitoring/hosts/downtimes
http://localhost/centreon/api/beta/monitoring/hosts/downtimes

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result":
    [
    ],
  • "meta":
    {
    }
}

List all downtimes of one host

List all downtimes of one host

The available parameters to search / sort_by are:

  • id
  • @@ -480,7 +497,7 @@

Responses

200

successful operation

403

Forbidden

500

Internal Server Error

-
get /monitoring/hosts/{host_id}/downtimes
http://localhost/centreon/api/beta/monitoring/hosts/{host_id}/downtimes

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result":
    [
    ],
  • "meta":
    {
    }
}

Add a downtimes of one host

Authorizations:
path Parameters
host_id
required
integer <int64>

ID of host

+
get /monitoring/hosts/{host_id}/downtimes
http://localhost/centreon/api/beta/monitoring/hosts/{host_id}/downtimes

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result":
    [
    ],
  • "meta":
    {
    }
}

Add a downtimes of one host

Authorizations:
path Parameters
host_id
required
integer <int64>

ID of host

Request Body schema: application/json

Downtime

start_time
string <date-time>

Scheduled start date of the downtime (ISO8601)

end_time
string <date-time>

Scheduled end date of the downtime (ISO8601)

@@ -492,7 +509,7 @@

Responses

204

Command sent

403

Forbidden

500

Internal Server Error

-
post /monitoring/hosts/{host_id}/downtimes
http://localhost/centreon/api/beta/monitoring/hosts/{host_id}/downtimes

Request samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "start_time": "2019-12-10T12:19:38Z",
  • "end_time": "2019-12-10T12:19:38Z",
  • "is_fixed": true,
  • "duration": 0,
  • "author_id": 0,
  • "comment": "string",
  • "with_services": true
}

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "message": "string"
}

List all services downtimes

List all downtimes of services

+
post /monitoring/hosts/{host_id}/downtimes
http://localhost/centreon/api/beta/monitoring/hosts/{host_id}/downtimes

Request samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "start_time": "2019-12-12T10:35:04Z",
  • "end_time": "2019-12-12T10:35:04Z",
  • "is_fixed": true,
  • "duration": 0,
  • "author_id": 0,
  • "comment": "string",
  • "with_services": true
}

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "message": "string"
}

List all services downtimes

List all downtimes of services

The available parameters to search / sort_by are:

  • id
  • @@ -521,7 +538,7 @@

Responses

200

successful operation

403

Forbidden

500

Internal Server Error

-
get /monitoring/services/downtimes
http://localhost/centreon/api/beta/monitoring/services/downtimes

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result":
    [
    ],
  • "meta":
    {
    }
}

List all downtimes of one host-related service

List all downtimes of one host-related service

+
get /monitoring/services/downtimes
http://localhost/centreon/api/beta/monitoring/services/downtimes

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result":
    [
    ],
  • "meta":
    {
    }
}

List all downtimes of one host-related service

List all downtimes of one host-related service

The available parameters to search / sort_by are:

  • id
  • @@ -545,7 +562,7 @@

Responses

200

successful operation

403

Forbidden

500

Internal Server Error

-
get /monitoring/hosts/{host_id}/services/{service_id}/downtimes
http://localhost/centreon/api/beta/monitoring/hosts/{host_id}/services/{service_id}/downtimes

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result":
    [
    ],
  • "meta":
    {
    }
}

Add a downtime of one host-related service

Authorizations:
path Parameters
host_id
required
integer <int64>

ID of host

+
get /monitoring/hosts/{host_id}/services/{service_id}/downtimes
http://localhost/centreon/api/beta/monitoring/hosts/{host_id}/services/{service_id}/downtimes

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result":
    [
    ],
  • "meta":
    {
    }
}

Add a downtime of one host-related service

Authorizations:
path Parameters
host_id
required
integer <int64>

ID of host

service_id
required
integer <int64>

ID of service linked to the host

Request Body schema: application/json

Downtime

start_time
string <date-time>

Scheduled start date of the downtime (ISO8601)

@@ -557,7 +574,7 @@

Responses

204

Command sent

403

Forbidden

500

Internal Server Error

-
post /monitoring/hosts/{host_id}/services/{service_id}/downtimes
http://localhost/centreon/api/beta/monitoring/hosts/{host_id}/services/{service_id}/downtimes

Request samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "start_time": "2019-12-10T12:19:38Z",
  • "end_time": "2019-12-10T12:19:38Z",
  • "is_fixed": true,
  • "duration": 0,
  • "author_id": 0,
  • "comment": "string"
}

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "message": "string"
}

List all downtimes

List all downtimes

+
post /monitoring/hosts/{host_id}/services/{service_id}/downtimes
http://localhost/centreon/api/beta/monitoring/hosts/{host_id}/services/{service_id}/downtimes

Request samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "start_time": "2019-12-12T10:35:04Z",
  • "end_time": "2019-12-12T10:35:04Z",
  • "is_fixed": true,
  • "duration": 0,
  • "author_id": 0,
  • "comment": "string"
}

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "message": "string"
}

List all downtimes

List all downtimes

The available parameters to search / sort_by are:

  • id
  • @@ -586,15 +603,15 @@

Responses

200

successful operation

403

Forbidden

500

Internal Server Error

-
get /monitoring/downtimes
http://localhost/centreon/api/beta/monitoring/downtimes

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result":
    [
    ],
  • "meta":
    {
    }
}

Display one downtime

Authorizations:
path Parameters
downtime_id
required
integer <int64>

ID of downtime

+
get /monitoring/downtimes
http://localhost/centreon/api/beta/monitoring/downtimes

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result":
    [
    ],
  • "meta":
    {
    }
}

Display one downtime

Authorizations:
path Parameters
downtime_id
required
integer <int64>

ID of downtime

Responses

200

successful operation

403

Forbidden

500

Internal Server Error

-
get /monitoring/downtimes/{downtime_id}
http://localhost/centreon/api/beta/monitoring/downtimes/{downtime_id}

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "id": 0,
  • "author_id": 0,
  • "host_id": 0,
  • "comment": "string",
  • "duration": 0,
  • "entry_time": "2019-12-10T12:19:38Z",
  • "start_time": "2019-12-10T12:19:38Z",
  • "end_time": "2019-12-10T12:19:38Z",
  • "deletion_time": "2019-12-10T12:19:38Z",
  • "actual_start_time": "2019-12-10T12:19:38Z",
  • "actual_end_time": "2019-12-10T12:19:38Z",
  • "is_started": true,
  • "is_cancelled": true,
  • "is_fixed": true,
  • "service_id": 0
}

Cancel a downtime

Authorizations:
path Parameters
downtime_id
required
integer <int64>

ID of downtime

+
get /monitoring/downtimes/{downtime_id}
http://localhost/centreon/api/beta/monitoring/downtimes/{downtime_id}

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "id": 0,
  • "author_id": 0,
  • "host_id": 0,
  • "comment": "string",
  • "duration": 0,
  • "entry_time": "2019-12-12T10:35:04Z",
  • "start_time": "2019-12-12T10:35:04Z",
  • "end_time": "2019-12-12T10:35:04Z",
  • "deletion_time": "2019-12-12T10:35:04Z",
  • "actual_start_time": "2019-12-12T10:35:04Z",
  • "actual_end_time": "2019-12-12T10:35:04Z",
  • "is_started": true,
  • "is_cancelled": true,
  • "is_fixed": true,
  • "service_id": 0
}

Cancel a downtime

Authorizations:
path Parameters
downtime_id
required
integer <int64>

ID of downtime

Responses

204

Command sent

403

Forbidden

500

Internal Server Error

-
delete /monitoring/downtimes/{downtime_id}
http://localhost/centreon/api/beta/monitoring/downtimes/{downtime_id}

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "message": "string"
}

Monitoring

Real-time monitoring of the services and hosts

+
delete /monitoring/downtimes/{downtime_id}
http://localhost/centreon/api/beta/monitoring/downtimes/{downtime_id}

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "message": "string"
}

Monitoring

Real-time monitoring of the services and hosts

List all services grouped by host groups

Returns all services grouped by host groups.

The available parameters to search / sort_by are:

    @@ -623,7 +640,7 @@

    Information

Responses

200

successful operation

403

Forbidden

500

Internal Server Error

-
get /monitoring/hostgroups
http://localhost/centreon/api/beta/monitoring/hostgroups

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result":
    [
    ],
  • "meta":
    {
    }
}

List all hosts

Returns all hosts.

+
get /monitoring/hostgroups
http://localhost/centreon/api/beta/monitoring/hostgroups

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result":
    [
    ],
  • "meta":
    {
    }
}

List all hosts

Returns all hosts.

The available parameters to search / sort_by are:

  • host.id
  • @@ -647,13 +664,13 @@

    Information

Responses

200

successful operation

403

Forbidden

500

Internal Server Error

-
get /monitoring/hosts
http://localhost/centreon/api/beta/monitoring/hosts

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result":
    [
    ],
  • "meta":
    {
    }
}

Find host by ID

Retuns a single host with full details and some details about its services

+
get /monitoring/hosts
http://localhost/centreon/api/beta/monitoring/hosts

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result":
    [
    ],
  • "meta":
    {
    }
}

Find host by ID

Retuns a single host with full details and some details about its services

Authorizations:
path Parameters
hostId
required
integer <int64>

ID of host to return

Responses

200

successful operation

403

Forbidden

404

Host not found

500

Internal Server Error

-
get /monitoring/hosts/{hostId}
http://localhost/centreon/api/beta/monitoring/hosts/{hostId}

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "id": 0,
  • "alias": "string",
  • "display_name": "string",
  • "name": "string",
  • "state": 0,
  • "services":
    [
    ],
  • "poller_id": 0,
  • "acknowledged": true,
  • "address_ip": "192.168.0.1",
  • "check_attempt": 0,
  • "checked": true,
  • "execution_time": 0,
  • "icon_image": "string",
  • "icon_image_alt": "string",
  • "last_check": "2019-12-10T12:19:38Z",
  • "last_hard_state_change": "2019-12-10T12:19:38Z",
  • "last_state_change": "2019-12-10T12:19:38Z",
  • "last_time_down": "2019-12-10T12:19:38Z",
  • "last_time_unreachable": "2019-12-10T12:19:38Z",
  • "last_time_up": "2019-12-10T12:19:38Z",
  • "last_update": "2019-12-10T12:19:38Z",
  • "max_check_attempts": 0,
  • "output": "string",
  • "passive_checks": true,
  • "state_type": 0,
  • "timezone": ":Europe/Paris",
  • "active_checks": true,
  • "check_command": "string",
  • "check_interval": 0,
  • "check_period": "string",
  • "check_type": 0,
  • "last_hard_state": "2019-12-10T12:19:38Z",
  • "last_notification": "2019-12-10T12:19:38Z",
  • "latency": "string",
  • "next_check": "2019-12-10T12:19:38Z",
  • "next_host_notification": 0,
  • "notification_interval": 0,
  • "notification_number": 0,
  • "notify": true,
  • "notify_on_down": true,
  • "notify_on_downtime": true,
  • "notify_on_flapping": true,
  • "notify_on_recovery": true,
  • "notify_on_unreachable": true
}

Find host-related services

Returns all services associated with a host.

+
get /monitoring/hosts/{hostId}
http://localhost/centreon/api/beta/monitoring/hosts/{hostId}

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "id": 0,
  • "alias": "string",
  • "display_name": "string",
  • "name": "string",
  • "state": 0,
  • "services":
    [
    ],
  • "poller_id": 0,
  • "acknowledged": true,
  • "address_ip": "192.168.0.1",
  • "check_attempt": 0,
  • "checked": true,
  • "execution_time": 0,
  • "icon_image": "string",
  • "icon_image_alt": "string",
  • "last_check": "2019-12-12T10:35:04Z",
  • "last_hard_state_change": "2019-12-12T10:35:04Z",
  • "last_state_change": "2019-12-12T10:35:04Z",
  • "last_time_down": "2019-12-12T10:35:04Z",
  • "last_time_unreachable": "2019-12-12T10:35:04Z",
  • "last_time_up": "2019-12-12T10:35:04Z",
  • "last_update": "2019-12-12T10:35:04Z",
  • "max_check_attempts": 0,
  • "output": "string",
  • "passive_checks": true,
  • "state_type": 0,
  • "timezone": ":Europe/Paris",
  • "active_checks": true,
  • "check_command": "string",
  • "check_interval": 0,
  • "check_period": "string",
  • "check_type": 0,
  • "last_hard_state": "2019-12-12T10:35:04Z",
  • "last_notification": "2019-12-12T10:35:04Z",
  • "latency": "string",
  • "next_check": "2019-12-12T10:35:04Z",
  • "next_host_notification": 0,
  • "notification_interval": 0,
  • "notification_number": 0,
  • "notify": true,
  • "notify_on_down": true,
  • "notify_on_downtime": true,
  • "notify_on_flapping": true,
  • "notify_on_recovery": true,
  • "notify_on_unreachable": true
}

Find host-related services

Returns all services associated with a host.

The available parameters to search / sort_by are:

  • service.id
  • @@ -672,14 +689,14 @@

    Information

403

Forbidden

404

Host not found

500

Internal Server Error

-
get /monitoring/hosts/{hostId}/services
http://localhost/centreon/api/beta/monitoring/hosts/{hostId}/services

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result":
    [
    ],
  • "meta":
    {
    }
}

Find service by ID related to a host

Retuns a single host with full details

+
get /monitoring/hosts/{hostId}/services
http://localhost/centreon/api/beta/monitoring/hosts/{hostId}/services

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result":
    [
    ],
  • "meta":
    {
    }
}

Find service by ID related to a host

Retuns a single host with full details

Authorizations:
path Parameters
hostId
required
integer <int64>

Host Id for which service is associed

serviceId
required
integer <int64>

ID of service to return

Responses

200

successful operation

403

Forbidden

404

Host or service not found

500

Internal Server Error

-
get /monitoring/hosts/{hostId}/services/{serviceId}
http://localhost/centreon/api/beta/monitoring/hosts/{hostId}/services/{serviceId}

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "id": 0,
  • "description": "string",
  • "display_name": "string",
  • "state": 0,
  • "check_attempt": 0,
  • "icon_image": "string",
  • "icon_image_alt": "string",
  • "last_check": "2019-12-10T12:19:38Z",
  • "last_state_change": "2019-12-10T12:19:38Z",
  • "max_check_attempts": 0,
  • "output": "string",
  • "state_type": 0,
  • "check_command": "string",
  • "check_interval": 0,
  • "check_period": "string",
  • "check_type": 0,
  • "command_line": "string",
  • "execution_time": 0,
  • "is_acknowledged": true,
  • "is_active_check": true,
  • "is_checked": true,
  • "last_hard_state_change": "2019-12-10T12:19:38Z",
  • "last_notification": "2019-12-10T12:19:38Z",
  • "last_time_critical": "2019-12-10T12:19:38Z",
  • "last_time_ok": "2019-12-10T12:19:38Z",
  • "last_time_unknown": "2019-12-10T12:19:38Z",
  • "last_time_warning": "2019-12-10T12:19:38Z",
  • "last_update": "2019-12-10T12:19:38Z",
  • "latency": 0,
  • "next_check": "2019-12-10T12:19:38Z",
  • "performance_data": "string",
  • "scheduled_downtime_depth": 0
}

List all services grouped by service groups

Returns all services grouped by service groups.

+
get /monitoring/hosts/{hostId}/services/{serviceId}
http://localhost/centreon/api/beta/monitoring/hosts/{hostId}/services/{serviceId}

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "id": 0,
  • "description": "string",
  • "display_name": "string",
  • "state": 0,
  • "check_attempt": 0,
  • "icon_image": "string",
  • "icon_image_alt": "string",
  • "last_check": "2019-12-12T10:35:04Z",
  • "last_state_change": "2019-12-12T10:35:04Z",
  • "max_check_attempts": 0,
  • "output": "string",
  • "state_type": 0,
  • "check_command": "string",
  • "check_interval": 0,
  • "check_period": "string",
  • "check_type": 0,
  • "command_line": "string",
  • "execution_time": 0,
  • "is_acknowledged": true,
  • "is_active_check": true,
  • "is_checked": true,
  • "last_hard_state_change": "2019-12-12T10:35:04Z",
  • "last_notification": "2019-12-12T10:35:04Z",
  • "last_time_critical": "2019-12-12T10:35:04Z",
  • "last_time_ok": "2019-12-12T10:35:04Z",
  • "last_time_unknown": "2019-12-12T10:35:04Z",
  • "last_time_warning": "2019-12-12T10:35:04Z",
  • "last_update": "2019-12-12T10:35:04Z",
  • "latency": 0,
  • "next_check": "2019-12-12T10:35:04Z",
  • "performance_data": "string",
  • "scheduled_downtime_depth": 0
}

List all services grouped by service groups

Returns all services grouped by service groups.

The available parameters to search / sort_by are:

  • host.id
  • @@ -708,7 +725,7 @@

    Information

Responses

200

successful operation

403

Forbidden

500

Internal Server Error

-
get /monitoring/servicegroups
http://localhost/centreon/api/beta/monitoring/servicegroups

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result":
    [
    ],
  • "meta":
    {
    }
}

List all services

Returns all services.

+
get /monitoring/servicegroups
http://localhost/centreon/api/beta/monitoring/servicegroups

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result":
    [
    ],
  • "meta":
    {
    }
}

List all services

Returns all services.

The available parameters to search / sort_by are:

  • host.id
  • @@ -732,9 +749,9 @@

    Information

Responses

200

successful operation

403

Forbidden

500

Internal Server Error

-
get /monitoring/services
http://localhost/centreon/api/beta/monitoring/services

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result":
    [
    ],
  • "meta":
    {
    }
}
+
get /monitoring/services
http://localhost/centreon/api/beta/monitoring/services

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result":
    [
    ],
  • "meta":
    {
    }
}