repo
stringlengths
7
63
file_url
stringlengths
81
284
file_path
stringlengths
5
200
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:02:33
2026-01-05 05:24:06
truncated
bool
2 classes
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/RemoteServer/Interfaces/RemoteServerRepositoryInterface.php
centreon/src/Centreon/Domain/RemoteServer/Interfaces/RemoteServerRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\RemoteServer\Interfaces; interface RemoteServerRepositoryInterface { /** * Delete a Remote Server. * * @param int $serverId */ public function deleteRemoteServerByServerId(int $serverId): void; /** * Delete an Additional Remote Server, for pollers linked to multiple Remote Servers. * * @param int $monitoringServerId */ public function deleteAdditionalRemoteServer(int $monitoringServerId): void; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/RemoteServer/Interfaces/RemoteServerLocalConfigurationRepositoryInterface.php
centreon/src/Centreon/Domain/RemoteServer/Interfaces/RemoteServerLocalConfigurationRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\RemoteServer\Interfaces; /** * This inteface is designed to configure the local instance mode of the platform. */ interface RemoteServerLocalConfigurationRepositoryInterface { /** * Update the platform instance mode to Central. */ public function updateInstanceModeCentral(): void; /** * Update the platform instance mode to Remote. */ public function updateInstanceModeRemote(): void; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/RemoteServer/Interfaces/RemoteServerServiceInterface.php
centreon/src/Centreon/Domain/RemoteServer/Interfaces/RemoteServerServiceInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\RemoteServer\Interfaces; use Centreon\Domain\Exception\EntityNotFoundException; use Centreon\Domain\Menu\MenuException; use Centreon\Domain\PlatformInformation\Model\PlatformInformation; use Centreon\Domain\PlatformTopology\Exception\PlatformTopologyException; use Centreon\Domain\PlatformTopology\Interfaces\PlatformTopologyRepositoryExceptionInterface; interface RemoteServerServiceInterface { /** * Convert a Central into a Remote Server * @param PlatformInformation $platformInformation * @throws PlatformTopologyException * @throws EntityNotFoundException * @throws MenuException * @throws PlatformTopologyException * @throws PlatformTopologyRepositoryExceptionInterface */ public function convertCentralToRemote(PlatformInformation $platformInformation): void; /** * Convert a Remote Server into a Central * @param PlatformInformation $platformInformation * @throws PlatformTopologyException * @throws EntityNotFoundException * @throws MenuException * @throws PlatformTopologyException * @throws PlatformTopologyRepositoryExceptionInterface */ public function convertRemoteToCentral(PlatformInformation $platformInformation): void; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Common/Assertion/Assertion.php
centreon/src/Centreon/Domain/Common/Assertion/Assertion.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Common\Assertion; /** * This class is designed to allow the translation of error messages and provide them with a unique format. */ class Assertion { /** * Assert that string value is not longer than $maxLength characters. * * @param string $value Value to test * @param int $maxLength Maximum length of the expected value in characters * @param string|null $propertyPath Property's path (ex: Host::name) * * @throws \Assert\AssertionFailedException */ public static function maxLength(string $value, int $maxLength, ?string $propertyPath = null): void { $length = \mb_strlen($value, 'utf8'); if ($length > $maxLength) { throw AssertionException::maxLength($value, $length, $maxLength, $propertyPath); } } /** * Assert that a string is at least $minLength characters long. * * @param string $value Value to test * @param int $minLength Minimum length of the expected value in characters * @param string|null $propertyPath Property's path (ex: Host::name) * * @throws \Assert\AssertionFailedException */ public static function minLength(string $value, int $minLength, ?string $propertyPath = null): void { $length = \mb_strlen($value, 'utf8'); if ($length < $minLength) { throw AssertionException::minLength($value, $length, $minLength, $propertyPath); } } /** * Assert that a value is at least an integer > 0. * * @param int $value Value to test * @param string|null $propertyPath Property's path (ex: Host::maxCheckAttempts) * * @throws \Assert\AssertionFailedException */ public static function positiveInt(int $value, ?string $propertyPath = null): void { self::min($value, 1, $propertyPath); } /** * Assert that a value is at least as big as a given limit. * * Same as {@see self::greaterOrEqualThan()} but with a different message. * * @param int $value Value to test * @param int $minValue Minimum value * @param string|null $propertyPath Property's path (ex: Host::maxCheckAttempts) * * @throws \Assert\AssertionFailedException */ public static function min(int $value, int $minValue, ?string $propertyPath = null): void { if ($value < $minValue) { throw AssertionException::min($value, $minValue, $propertyPath); } } /** * Assert that a number is smaller as a given limit. * * @param int $value Value to test * @param int $maxValue Maximum value * @param string|null $propertyPath Property's path (ex: Host::maxCheckAttempts) * * @throws \Assert\AssertionFailedException */ public static function max(int $value, int $maxValue, ?string $propertyPath = null): void { if ($value > $maxValue) { throw AssertionException::max($value, $maxValue, $propertyPath); } } /** * Assert that a string respects email format. * * @param string $value Value to test * @param string|null $propertyPath Property's path (ex: User::email) * * @throws \Assert\AssertionFailedException */ public static function email(string $value, ?string $propertyPath = null): void { if (! \filter_var($value, FILTER_VALIDATE_EMAIL)) { throw AssertionException::email($value, $propertyPath); } } /** * Assert that a date is smaller as a given limit. * * @param \DateTimeInterface $value * @param \DateTimeInterface $maxDate * @param string|null $propertyPath * * @throws \Assert\AssertionFailedException */ public static function maxDate( \DateTimeInterface $value, \DateTimeInterface $maxDate, ?string $propertyPath = null, ): void { if ($value->getTimestamp() > $maxDate->getTimestamp()) { throw AssertionException::maxDate($value, $maxDate, $propertyPath); } } /** * Assert that a date is bigger as a given limit. * * @param \DateTimeInterface $value * @param \DateTimeInterface $minDate * @param string|null $propertyPath * * @throws \Assert\AssertionFailedException */ public static function minDate( \DateTimeInterface $value, \DateTimeInterface $minDate, ?string $propertyPath = null, ): void { if ($value->getTimestamp() < $minDate->getTimestamp()) { throw AssertionException::minDate($value, $minDate, $propertyPath); } } /** * Determines if the value is greater or equal than given limit. * * Same as {@see self::min()} but with a different message. * * @param int $value Value to test * @param int $limit Limit value (>=) * @param string|null $propertyPath Property's path (ex: Host::maxCheckAttempts) * * @throws \Assert\AssertionFailedException */ public static function greaterOrEqualThan(int $value, int $limit, ?string $propertyPath = null): void { if ($value < $limit) { throw AssertionException::greaterOrEqualThan($value, $limit, $propertyPath); } } /** * Assert that value is not empty. * * This is bound to the native php {@see https://www.php.net/manual/en/function.empty.php} function. * * Use it carefully for strings as '0' is considered empty by PHP ! * * @param mixed $value Value to test * @param string|null $propertyPath Property's path (ex: Host::name) * * @throws \Assert\AssertionFailedException */ public static function notEmpty(mixed $value, ?string $propertyPath = null): void { if (empty($value)) { throw AssertionException::notEmpty($propertyPath); } } /** * Assert that a string is not NULL or an empty string ''. * * This method is specifically done for strings to manage the php case `empty('0')` which is `TRUE`. * * @param ?string $value Value to test * @param string|null $propertyPath Property's path (ex: Host::name) * * @throws \Assert\AssertionFailedException */ public static function notEmptyString(?string $value, ?string $propertyPath = null): void { if ($value === null || $value === '') { throw AssertionException::notEmptyString($propertyPath); } } /** * Assert that value is not null. * * @param mixed $value Value to test * @param string|null $propertyPath Property's path (ex: Host::name) * * @throws \Assert\AssertionFailedException */ public static function notNull(mixed $value, ?string $propertyPath = null): void { if ($value === null) { throw AssertionException::notNull($propertyPath); } } /** * Assert that value is in array. * * @param mixed $value * @param mixed[] $choices * @param string|null $propertyPath * * @throws \Assert\AssertionFailedException */ public static function inArray(mixed $value, array $choices, ?string $propertyPath = null): void { if (! \in_array($value, $choices, true)) { throw AssertionException::inArray($value, $choices, $propertyPath); } } /** * Assert that the value is in range. * * @param int|float $value * @param int|float $minValue * @param int|float $maxValue * @param string|null $propertyPath * * @throws \Assert\AssertionFailedException */ public static function range( int|float $value, int|float $minValue, int|float $maxValue, ?string $propertyPath = null, ): void { if ($value < $minValue || $value > $maxValue) { throw AssertionException::range($value, $minValue, $maxValue, $propertyPath); } } /** * Assert that a value match a regex. * * @param mixed $value * @param string $pattern * @param string|null $propertyPath * * @throws \Assert\AssertionFailedException */ public static function regex(mixed $value, string $pattern, ?string $propertyPath = null): void { if (! \is_string($value) || ! \preg_match($pattern, $value)) { throw AssertionException::matchRegex(self::stringify($value), $pattern, $propertyPath); } } /** * Assert that value is a valid IP or Domain name. * * @param string $value * @param string|null $propertyPath * * @throws \Assert\AssertionFailedException */ public static function ipOrDomain(string $value, ?string $propertyPath = null): void { if ( filter_var($value, FILTER_VALIDATE_IP) === false && filter_var($value, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) === false ) { throw AssertionException::ipOrDomain($value, $propertyPath); } } /** * Assert that value is a valid IP. * * @param mixed $value * @param string|null $propertyPath * * @throws \Assert\AssertionFailedException */ public static function ipAddress(mixed $value, ?string $propertyPath = null): void { if (! \is_string($value) || filter_var($value, FILTER_VALIDATE_IP) === false) { throw AssertionException::ipAddressNotValid(self::stringify($value), $propertyPath); } } /** * Assert that value is a valid URL, IP or domain. * * @param mixed $value * @param string|null $propertyPath * * @throws \Assert\AssertionFailedException */ public static function urlOrIpOrDomain(mixed $value, ?string $propertyPath = null): void { if (! \is_string($value) || ( filter_var($value, FILTER_VALIDATE_IP) === false && filter_var($value, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) === false && filter_var($value, FILTER_VALIDATE_URL) === false ) ) { throw AssertionException::urlOrIpOrDomain(self::stringify($value), $propertyPath); } } /** * @param object $value * @param class-string $className * @param string|null $propertyPath * * @throws \Assert\AssertionFailedException */ public static function isInstanceOf(mixed $value, string $className, ?string $propertyPath = null): void { if (! ($value instanceof $className)) { throw AssertionException::badInstanceOfObject( get_debug_type($value), $className, $propertyPath ); } } /** * Assert that string value is a valid JSON string. * * @param string $value Value to test * @param string|null $propertyPath Property's path (ex: Host::name) * * @throws \Assert\AssertionFailedException */ public static function jsonString(string $value, ?string $propertyPath = null): void { try { json_decode($value, true, 512, JSON_THROW_ON_ERROR); } catch (\JsonException) { throw AssertionException::invalidJsonString($propertyPath); } } /** * Assert that the value can be encoded to a valid JSON string. * * @param mixed $value Value to test * @param string|null $propertyPath Property's path (ex: Host::name) * @param int|null $maxLength * * @throws AssertionException */ public static function jsonEncodable(mixed $value, ?string $propertyPath = null, ?int $maxLength = null): void { try { $json = json_encode($value, JSON_THROW_ON_ERROR | JSON_PRESERVE_ZERO_FRACTION); if ($maxLength !== null) { $length = \mb_strlen($json, 'utf8'); if ($length > $maxLength) { throw AssertionException::maxLength('<JSON>', $length, $maxLength, $propertyPath); } } } catch (\JsonException) { throw AssertionException::notJsonEncodable($propertyPath); } } /** * @param string $value Value to test * @param string $unauthorizedCharacters List of non-authorized characters * @param string|null $propertyPath Property's path (ex: Host::name) * * @throws \Assert\AssertionFailedException */ public static function unauthorizedCharacters( string $value, string $unauthorizedCharacters, ?string $propertyPath = null, ): void { if ($unauthorizedCharacters !== '' && $value !== '') { $unauthorizedCharactersFound = array_unique( array_intersect( mb_str_split($value), mb_str_split($unauthorizedCharacters) ) ); if ($unauthorizedCharactersFound !== []) { throw AssertionException::unauthorizedCharacters( $value, implode('', $unauthorizedCharactersFound), $propertyPath ); } } } /** * Validate that the values of array are correct type * * @param 'string'|'float'|'int' $type * @param array<mixed> $values * * @throws AssertionException */ public static function arrayOfTypeOrNull(string $type, array $values, string $propertyPath): void { try { switch ($type) { case 'string': (fn (?string ...$items): array => $items)(...$values); break; case 'float': (fn (?float ...$items): array => $items)(...$values); break; case 'int': (fn (?int ...$items): array => $items)(...$values); break; } } catch (\TypeError) { throw AssertionException::invalidTypeInArray($type, $propertyPath); } } /** * Make a string version of a value. * * Copied from {@see \Assert\Assertion::stringify()}. * * @param mixed $value */ private static function stringify(mixed $value): string { $result = \gettype($value); if (\is_bool($value)) { $result = $value ? '<TRUE>' : '<FALSE>'; } elseif (\is_scalar($value)) { $val = (string) $value; if (\mb_strlen($val) > 100) { $val = \mb_substr($val, 0, 97) . '...'; } $result = $val; } elseif (\is_array($value)) { $result = '<ARRAY>'; } elseif (\is_object($value)) { $result = \get_debug_type($value); } elseif (\is_resource($value)) { $result = \get_resource_type($value); } elseif ($value === null) { $result = '<NULL>'; } return $result; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Common/Assertion/AssertionException.php
centreon/src/Centreon/Domain/Common/Assertion/AssertionException.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Common\Assertion; use Assert\Assertion as Assert; /** * This class is designed to contain all assertion exceptions. */ class AssertionException extends \Assert\InvalidArgumentException { public const INVALID_EMAIL = Assert::INVALID_EMAIL; public const INVALID_GREATER_OR_EQUAL = Assert::INVALID_GREATER_OR_EQUAL; public const INVALID_INSTANCE_OF = Assert::INVALID_INSTANCE_OF; public const INVALID_IP = Assert::INVALID_IP; public const INVALID_JSON_STRING = Assert::INVALID_JSON_STRING; public const INVALID_MAX = Assert::INVALID_MAX; public const INVALID_MAX_LENGTH = Assert::INVALID_MAX_LENGTH; public const INVALID_MIN = Assert::INVALID_MIN; public const INVALID_MIN_LENGTH = Assert::INVALID_MIN_LENGTH; public const INVALID_RANGE = Assert::INVALID_RANGE; public const INVALID_REGEX = Assert::INVALID_REGEX; public const INVALID_CHOICE = Assert::INVALID_CHOICE; public const VALUE_EMPTY = Assert::VALUE_EMPTY; public const VALUE_NULL = Assert::VALUE_NULL; // Error codes of Centreon assertion start from 1000 public const INVALID_MAX_DATE = 1001; public const INVALID_IP_OR_DOMAIN = 1002; public const INVALID_CHARACTERS = 1003; public const INVALID_ARRAY_JSON_ENCODABLE = 1004; public const INVALID_MIN_DATE = 1005; public const INVALID_URL_IP_OR_DOMAIN = 1006; /** * The extended constructor is here only to enforce the types used * and set a default `int $code = 0` for child classes. * * @param string $message * @param int $code * @param string|null $propertyPath * @param mixed|null $value * @param array<string, mixed> $constraints */ public function __construct( string $message, int $code = 0, ?string $propertyPath = null, mixed $value = null, array $constraints = [], ) { parent::__construct($message, $code, $propertyPath, $value, $constraints); } /** * Exception when the value contains unauthorized characters. * * @param string $value Tested value * @param string $unauthorizedCharacters List of unauthorized characters found in the value * @param string|null $propertyPath Property's path (ex: Host::name) * * @return self */ public static function unauthorizedCharacters( string $value, string $unauthorizedCharacters, ?string $propertyPath = null, ): self { return new self( sprintf( _('[%s] The value contains unauthorized characters: %s'), $propertyPath, $unauthorizedCharacters, ), self::INVALID_CHARACTERS, $propertyPath, $value ); } /** * Exception when the value of the string is longer than the expected number of characters. * * @param string $value Tested value * @param int $valueLength Length of the tested value * @param int $maxLength Maximum length of the expected value in characters * @param string|null $propertyPath Property's path (ex: Host::name) * * @return self */ public static function maxLength( string $value, int $valueLength, int $maxLength, ?string $propertyPath = null, ): self { return new self( sprintf( _( '[%s] The value "%s" is too long, it should have no more than %d characters,' . ' but has %d characters' ), $propertyPath, $value, $maxLength, $valueLength ), self::INVALID_MAX_LENGTH, $propertyPath, $value ); } /** * Exception when the value of the string is smaller than the expected number of characters. * * @param string $value Tested value * @param int $valueLength Length of the tested value * @param int $minLength Minimum length of the expected value in characters * @param string|null $propertyPath Property's path (ex: Host::name) * * @return self */ public static function minLength( string $value, int $valueLength, int $minLength, ?string $propertyPath = null, ): self { return new self( sprintf( _( '[%s] The value "%s" is too short, it should have at least %d characters,' . ' but only has %d characters' ), $propertyPath, $value, $minLength, $valueLength ), self::INVALID_MIN_LENGTH, $propertyPath, $value ); } /** * Exception when the value of the integer is < 1. * * @param positive-int $value Tested value * @param string|null $propertyPath Property's path (ex: Host::maxCheckAttempts) * * @return self */ public static function positiveInt(int $value, ?string $propertyPath = null): self { return self::min($value, 1, $propertyPath); } /** * Exception when the value of the integer is less than the expected value. * * Same as {@see self::greaterOrEqualThan()} but with a different message. * * @param int $value Tested value * @param int $minValue Minimum value * @param string|null $propertyPath Property's path (ex: Host::maxCheckAttempts) * * @return self */ public static function min(int $value, int $minValue, ?string $propertyPath = null): self { return new self( sprintf( _('[%s] The value "%d" was expected to be at least %d'), $propertyPath, $value, $minValue ), self::INVALID_MIN, $propertyPath, $value ); } /** * Exception when the value of the integer is higher than the expected value. * * @param int $value Tested value * @param int $maxValue Maximum value * @param string|null $propertyPath Property's path (ex: Host::maxCheckAttempts) * * @return self */ public static function max(int $value, int $maxValue, ?string $propertyPath = null): self { return new self( sprintf( _('[%s] The value "%d" was expected to be at most %d'), $propertyPath, $value, $maxValue ), self::INVALID_MAX, $propertyPath, $value ); } /** * Exception when the value does not respect email format. * * @param string $value Tested value * @param string|null $propertyPath Property's path (ex: Host::maxCheckAttempts) * * @return self */ public static function email(string $value, ?string $propertyPath = null): self { return new self( sprintf( _('[%s] The value "%s" was expected to be a valid e-mail address'), $propertyPath, $value ), self::INVALID_EMAIL, $propertyPath, $value ); } /** * Exception when the value of the date is higher than the expected date. * * @param \DateTimeInterface $date Tested date * @param \DateTimeInterface $maxDate Maximum date * @param string|null $propertyPath Property's path (ex: Host::maxCheckAttempts) * * @return self */ public static function maxDate( \DateTimeInterface $date, \DateTimeInterface $maxDate, ?string $propertyPath = null, ): self { $value = $date->format('c'); return new self( sprintf( _('[%s] The date "%s" was expected to be at most %s'), $propertyPath, $value, $maxDate->format('c') ), self::INVALID_MAX_DATE, $propertyPath, $value ); } /** * Exception when the value of the date is lower than the expected date. * * @param \DateTimeInterface $date Tested date * @param \DateTimeInterface $minDate Minimum date * @param string|null $propertyPath Property's path (ex: Host::maxCheckAttempts) * * @return self */ public static function minDate( \DateTimeInterface $date, \DateTimeInterface $minDate, ?string $propertyPath = null, ): self { $value = $date->format('c'); return new self( sprintf( _('[%s] The date "%s" was expected to be at least %s'), $propertyPath, $value, $minDate->format('c') ), self::INVALID_MIN_DATE, $propertyPath, $value ); } /** * Exception when the value of the integer is less than the expected value. * * Same as {@see self::min()} but with a different message. * * @param int $value Tested value * @param int $limit Limit value * @param string|null $propertyPath Property's path (ex: Host::maxCheckAttempts) * * @return self */ public static function greaterOrEqualThan(int $value, int $limit, ?string $propertyPath = null): self { return new self( sprintf( _('[%s] The value "%d" is not greater or equal than %d'), $propertyPath, $value, $limit ), self::INVALID_GREATER_OR_EQUAL, $propertyPath, $value ); } /** * Exception when the value is empty. * * @param string|null $propertyPath Property's path (ex: Host::name) * * @return self */ public static function notEmpty(?string $propertyPath = null): self { return new self( sprintf( _('[%s] The value is empty, but non empty value was expected'), $propertyPath ), self::VALUE_EMPTY, $propertyPath ); } /** * Exception when the string is empty. * * @param string|null $propertyPath Property's path (ex: Host::name) * * @return self */ public static function notEmptyString(?string $propertyPath = null): self { return new self( sprintf( _('[%s] The string is empty, but non empty string was expected'), $propertyPath ), self::VALUE_EMPTY, $propertyPath ); } /** * Exception when the value is null. * * @param string|null $propertyPath Property's path (ex: Host::name) * * @return self */ public static function notNull(?string $propertyPath = null): self { return new self( sprintf( _('[%s] The value is null, but non null value was expected'), $propertyPath ), self::VALUE_NULL, $propertyPath ); } /** * Exception when the value is not expected. * * @param mixed $value * @param mixed[] $expectedValues * @param string|null $propertyPath Property's path (ex: Host::name) * * @return self */ public static function inArray(mixed $value, array $expectedValues, ?string $propertyPath = null): self { return new self( sprintf( _('[%s] The value provided (%s) was not expected. Possible values %s'), $propertyPath, $value, implode('|', $expectedValues) ), self::INVALID_CHOICE, $propertyPath, $value ); } /** * Exception when the value is not in the range. * * @param int|float $value * @param int|float $minValue * @param int|float $maxValue * @param string|null $propertyPath * * @return self */ public static function range( int|float $value, int|float $minValue, int|float $maxValue, ?string $propertyPath = null, ): self { return new self( sprintf( _('Number "%s" was expected to be at least "%d" and at most "%d"'), $value, $minValue, $maxValue ), self::INVALID_RANGE, $propertyPath, $value ); } /** * Exception when the value does not respect ip format. * * @param string $value Tested value * @param string|null $propertyPath Property's path (ex: Host::maxCheckAttempts) * * @return self */ public static function ipOrDomain(string $value, ?string $propertyPath = null): self { return new self( sprintf( _('[%s] The value "%s" was expected to be a valid ip address or domain name'), $propertyPath, $value ), self::INVALID_IP_OR_DOMAIN, $propertyPath, $value ); } /** * Exception when the value doesn't match a regex. * * @param string $value * @param string $pattern * @param string|null $propertyPath * * @return self */ public static function matchRegex(string $value, string $pattern, ?string $propertyPath = null): self { return new self( sprintf( _("[%s] The value (%s) doesn't match the regex '%s'"), $propertyPath, $value, $pattern ), self::INVALID_REGEX, $propertyPath, $value ); } /** * Exception when the object is not of the correct class type. * * @param string $objectInstanceName * @param string $instanceNameRequired * @param string|null $propertyPath * * @return self */ public static function badInstanceOfObject( string $objectInstanceName, string $instanceNameRequired, ?string $propertyPath = null, ): self { return new self( sprintf( _("[%s] (%s) was expected to be an instance of the class '%s'"), $propertyPath, $objectInstanceName, $instanceNameRequired ), self::INVALID_INSTANCE_OF, $propertyPath, $objectInstanceName ); } /** * Exception when the value does not respect ip format. * * @param string $value Tested value * @param string|null $propertyPath Property's path (ex: Host::maxCheckAttempts) * * @return self */ public static function ipAddressNotValid(string $value, ?string $propertyPath = null): self { return new self( sprintf( _("[%s] The value '%s' was expected to be a valid ip address"), $propertyPath, $value ), self::INVALID_IP, $propertyPath, $value ); } /** * Exception when the value is not a valid JSON string. * * @param string|null $propertyPath Property's path (ex: Host::name) * * @return self */ public static function invalidJsonString(?string $propertyPath = null): self { return new self( sprintf( _('[%s] The value is not a valid JSON string'), $propertyPath ), self::INVALID_JSON_STRING, $propertyPath ); } /** * Exception when the value is not encodable to a valid JSON string. * * @param string|null $propertyPath Property's path (ex: Host::name) * * @return self */ public static function notJsonEncodable(?string $propertyPath = null): self { return new self( sprintf( _('[%s] The value cannot be encoded to a valid JSON string'), $propertyPath ), self::INVALID_ARRAY_JSON_ENCODABLE, $propertyPath ); } public static function invalidTypeInArray(string $type, string $propertyPath): self { return new self(sprintf('values type in the array are not [%s]', $type), self::INVALID_CHOICE, $propertyPath); } /** * Exception when the value does not respect URL, IP address or domain format. * * @param string $value Tested value * @param string|null $propertyPath Property's path (ex: Host::maxCheckAttempts) * * @return self */ public static function urlOrIpOrDomain(string $value, ?string $propertyPath = null): self { return new self( sprintf( _('[%s] The value "%s" was expected to be a valid URL, IP address or domain'), $propertyPath, $value ), self::INVALID_URL_IP_OR_DOMAIN, $propertyPath, $value ); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Common/Exception/FactoryException.php
centreon/src/Centreon/Domain/Common/Exception/FactoryException.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Common\Exception; /** * This class is designed to contain all entity factory exceptions. * * @package Centreon\Domain\Common\Exception */ class FactoryException extends \Exception { /** * @param string $className * @return FactoryException */ public static function mandatoryDataNotFound(string $className): self { return new self( sprintf(_('Mandatory data to create the entity \'%s\' is missing'), $className) ); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Downtime/DowntimeException.php
centreon/src/Centreon/Domain/Downtime/DowntimeException.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Downtime; class DowntimeException extends \Exception { public function __construct($message = '', $code = 0, ?\Throwable $previous = null) { parent::__construct($message, $code, $previous); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Downtime/DowntimeService.php
centreon/src/Centreon/Domain/Downtime/DowntimeService.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Downtime; use Centreon\Domain\Contact\Contact; use Centreon\Domain\Downtime\Interfaces\DowntimeRepositoryInterface; use Centreon\Domain\Downtime\Interfaces\DowntimeServiceInterface; use Centreon\Domain\Engine\Interfaces\EngineServiceInterface; use Centreon\Domain\Exception\EntityNotFoundException; use Centreon\Domain\Monitoring\Host; use Centreon\Domain\Monitoring\Interfaces\MonitoringRepositoryInterface; use Centreon\Domain\Monitoring\Resource as ResourceEntity; use Centreon\Domain\Monitoring\ResourceService; use Centreon\Domain\Monitoring\Service; use Centreon\Domain\Service\AbstractCentreonService; use Core\Security\AccessGroup\Application\Repository\ReadAccessGroupRepositoryInterface; use Core\Security\AccessGroup\Domain\Model\AccessGroup; /** * This class is designed to add/delete/find downtimes on hosts and services. * * @package Centreon\Domain\Downtime */ class DowntimeService extends AbstractCentreonService implements DowntimeServiceInterface { public const VALIDATION_GROUPS_ADD_HOST_DOWNTIME = ['Default', 'downtime_host', 'downtime_host_add']; public const VALIDATION_GROUPS_ADD_SERVICE_DOWNTIME = ['Default', 'downtime_service']; /** @var ReadAccessGroupRepositoryInterface */ private $accessGroupRepository; /** @var EngineServiceInterface For all downtimes requests except reading */ private $engineService; /** @var DowntimeRepositoryInterface */ private $downtimeRepository; /** @var AccessGroup[] Access groups of contact */ private $accessGroups; /** @var MonitoringRepositoryInterface */ private $monitoringRepository; /** * DowntimeService constructor. * * @param ReadAccessGroupRepositoryInterface $accessGroupRepository * @param EngineServiceInterface $engineService * @param DowntimeRepositoryInterface $downtimeRepository * @param MonitoringRepositoryInterface $monitoringRepository */ public function __construct( ReadAccessGroupRepositoryInterface $accessGroupRepository, EngineServiceInterface $engineService, DowntimeRepositoryInterface $downtimeRepository, MonitoringRepositoryInterface $monitoringRepository, ) { $this->accessGroupRepository = $accessGroupRepository; $this->engineService = $engineService; $this->downtimeRepository = $downtimeRepository; $this->monitoringRepository = $monitoringRepository; } /** * {@inheritDoc} * @param Contact $contact * @return DowntimeServiceInterface */ public function filterByContact($contact): DowntimeServiceInterface { parent::filterByContact($contact); $this->engineService->filterByContact($contact); $this->accessGroups = $this->accessGroupRepository->findByContact($contact); $this->monitoringRepository ->setContact($this->contact) ->filterByAccessGroups($this->accessGroups); return $this; } /** * @inheritDoc */ public function addHostDowntime(Downtime $downtime, Host $host): void { $this->engineService->addHostDowntime($downtime, $host); } /** * @inheritDoc */ public function addServiceDowntime(Downtime $downtime, Service $service): void { $this->engineService->addServiceDowntime($downtime, $service); } /** * @inheritDoc */ public function findHostDowntimes(): array { if ($this->contact->isAdmin()) { return $this->downtimeRepository->findHostDowntimesForAdminUser(); } return $this->downtimeRepository ->forAccessGroups($this->accessGroups) ->findHostDowntimesForNonAdminUser(); } /** * @inheritDoc */ public function findServicesDowntimes(): array { if ($this->contact->isAdmin()) { return $this->downtimeRepository->findServicesDowntimesForAdminUser(); } return $this->downtimeRepository ->forAccessGroups($this->accessGroups) ->findServicesDowntimesForNonAdminUser(); } /** * @inheritDoc */ public function findDowntimesByService(int $hostId, int $serviceId): array { if ($this->contact->isAdmin()) { return $this->downtimeRepository->findDowntimesByServiceForAdminUser($hostId, $serviceId); } return $this->downtimeRepository ->forAccessGroups($this->accessGroups) ->findDowntimesByServiceForNonAdminUser($hostId, $serviceId); } /** * @inheritDoc */ public function findDowntimesByMetaService(int $metaId): array { $service = $this->monitoringRepository->findOneServiceByDescription('meta_' . $metaId); if (is_null($service)) { throw new EntityNotFoundException(_('Meta service not found')); } if ($this->contact->isAdmin()) { return $this->downtimeRepository->findDowntimesByServiceForAdminUser( $service->getHost()->getId(), $service->getId() ); } return $this->downtimeRepository ->forAccessGroups($this->accessGroups) ->findDowntimesByServiceForNonAdminUser( $service->getHost()->getId(), $service->getId() ); } /** * @inheritDoc */ public function findDowntimesByHost(int $hostId, bool $withServices): array { if ($this->contact->isAdmin()) { return $this->downtimeRepository->findDowntimesByHostForAdminUser($hostId, $withServices); } return $this->downtimeRepository ->forAccessGroups($this->accessGroups) ->findDowntimesByHostForNonAdminUser($hostId, $withServices); } /** * @inheritDoc */ public function findDowntimes(): array { if ($this->contact->isAdmin()) { return $this->downtimeRepository->findDowntimesForAdminUser(); } return $this->downtimeRepository ->forAccessGroups($this->accessGroups) ->findDowntimesForNonAdminUser(); } /** * @inheritDoc */ public function findOneDowntime(int $downtimeId): ?Downtime { if ($this->contact->isAdmin()) { return $this->downtimeRepository->findOneDowntimeForAdminUser($downtimeId); } return $this->downtimeRepository ->forAccessGroups($this->accessGroups) ->findOneDowntimeForNonAdminUser($downtimeId); } /** * @inheritDoc */ public function cancelDowntime(int $downtimeId, Host $host): void { $downtime = null; if ($this->contact->isAdmin()) { $downtime = $this->downtimeRepository->findOneDowntimeForAdminUser($downtimeId); } else { $downtime = $this->downtimeRepository ->forAccessGroups($this->accessGroups) ->findOneDowntimeForNonAdminUser($downtimeId); } if ($downtime === null) { throw new EntityNotFoundException(_('Downtime not found')); } $downtimeType = (empty($downtime->getServiceId())) ? 'host' : 'service'; if (! is_null($downtime->getDeletionTime())) { throw new DowntimeException( sprintf(_('Downtime already cancelled for this %s'), $downtimeType) ); } $this->engineService->cancelDowntime($downtime, $host); } /** * @inheritDoc */ public function addResourceDowntime(ResourceEntity $resource, Downtime $downtime): void { switch ($resource->getType()) { case ResourceEntity::TYPE_HOST: $host = $this->monitoringRepository->findOneHost(ResourceService::generateHostIdByResource($resource)); if (is_null($host)) { throw new EntityNotFoundException(_('Host not found')); } $this->addHostDowntime($downtime, $host); break; case ResourceEntity::TYPE_SERVICE: $host = $this->monitoringRepository->findOneHost(ResourceService::generateHostIdByResource($resource)); if (is_null($host)) { throw new EntityNotFoundException(_('Host not found')); } $service = $this->monitoringRepository->findOneService( (int) $resource->getParent()->getId(), (int) $resource->getId() ); if (is_null($service)) { throw new EntityNotFoundException(_('Service not found')); } $service->setHost($host); $this->addServiceDowntime($downtime, $service); break; case ResourceEntity::TYPE_META: $service = $this->monitoringRepository->findOneServiceByDescription('meta_' . $resource->getId()); if (is_null($service)) { throw new EntityNotFoundException(_('Service not found')); } $host = $this->monitoringRepository->findOneHost($service->getHost()->getId()); if (is_null($host)) { throw new EntityNotFoundException(_('Host not found')); } $service->setHost($host); $this->addServiceDowntime($downtime, $service); break; default: throw new \Exception(_('Incorrect Resource Type')); } } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Downtime/Downtime.php
centreon/src/Centreon/Domain/Downtime/Downtime.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Downtime; use Centreon\Domain\Common\Assertion\Assertion; use Centreon\Domain\Service\EntityDescriptorMetadataInterface; /** * This class is designed to represent the downtime of a resource. * * @package Centreon\Domain\Downtime */ class Downtime implements EntityDescriptorMetadataInterface { public const DOWNTIME_YEAR_MAX = 2100; // Groups for serialization public const SERIALIZER_GROUPS_MAIN = ['Default', 'downtime_host']; public const SERIALIZER_GROUPS_SERVICE = ['Default', 'downtime_service']; public const SERIALIZER_GROUPS_RESOURCE_DOWNTIME = ['resource_dt']; // Groups for validation public const VALIDATION_GROUP_DT_RESOURCE = ['resource_dt']; // Types public const TYPE_HOST_DOWNTIME = 0; public const TYPE_SERVICE_DOWNTIME = 1; /** @var int|null Unique id */ private $id; /** @var \DateTime|null Creation date */ private $entryTime; /** @var int|null Author id who sent this downtime */ private $authorId; /** @var string|null Author name who sent this downtime */ private $authorName; /** @var int|null Host id linked to this downtime */ private $hostId; /** @var int|null Service id linked to this downtime */ private $serviceId; /** @var int Resource id */ private $resourceId; /** @var int|null Parent resource id */ private $parentResourceId; /** @var bool Indicates if this downtime have been cancelled */ private $isCancelled; /** @var string|null Comments */ private $comment; /** @var \DateTime|null Date when this downtime have been deleted */ private $deletionTime; /** @var int|null Duration of the downtime corresponding to endTime - startTime (in seconds) */ private $duration; /** @var \DateTime|null End date of the downtime */ private $endTime; /** @var int|null (used to cancel a downtime) */ private $internalId; /** @var bool Indicates either the downtime is fixed or not */ private $isFixed; /** @var int|null Poller id */ private $pollerId; /** @var \DateTime|null Start date of the downtime */ private $startTime; /** @var \DateTime|null Actual start date of the downtime */ private $actualStartTime; /** @var \DateTime|null Actual end date of the downtime */ private $actualEndTime; /** @var bool Indicates if this downtime have started */ private $isStarted; /** @var bool Indicates if this downtime should be applied to linked services */ private $withServices = false; /** @var \DateTime */ private $maxDate; /** * @throws \Exception */ public function __construct() { $this->maxDate = (new \DateTime('', new \DateTimeZone('UTC'))) ->setDate(self::DOWNTIME_YEAR_MAX, 1, 1) ->setTime(0, 0) ->modify('- 1 minute'); } /** * {@inheritDoc} */ public static function loadEntityDescriptorMetadata(): array { return [ 'author' => 'setAuthorName', 'downtime_id' => 'setId', 'cancelled' => 'setCancelled', 'comment_data' => 'setComment', 'fixed' => 'setFixed', 'instance_id' => 'setPollerId', 'started' => 'setStarted', ]; } /** * @return int|null */ public function getId(): ?int { return $this->id; } /** * @param int|null $id */ public function setId(?int $id): void { $this->id = $id; } /** * @return \DateTime|null */ public function getEntryTime(): ?\DateTime { return $this->entryTime; } /** * @param \DateTime|null $entryTime * @throws \Centreon\Domain\Common\Assertion\AssertionException * @throws \Exception */ public function setEntryTime(?\DateTime $entryTime): void { if ($entryTime !== null) { Assertion::maxDate($entryTime, $this->maxDate, 'Downtime::entryTime'); } $this->entryTime = $entryTime; } /** * @return int|null */ public function getAuthorId(): ?int { return $this->authorId; } /** * @param int|null $authorId */ public function setAuthorId(?int $authorId): void { $this->authorId = $authorId; } /** * @return string|null */ public function getAuthorName(): ?string { return $this->authorName; } /** * @param string|null $authorName */ public function setAuthorName(?string $authorName): void { $this->authorName = $authorName; } /** * @return int|null */ public function getHostId(): ?int { return $this->hostId; } /** * @param int|null $hostId */ public function setHostId(?int $hostId): void { $this->hostId = $hostId; } /** * @return int|null */ public function getServiceId(): ?int { return $this->serviceId; } /** * @param int|null $serviceId */ public function setServiceId(?int $serviceId): void { $this->serviceId = $serviceId; } /** * @return int */ public function getResourceId(): int { return $this->resourceId; } /** * @param int $resourceId * @return Downtime */ public function setResourceId(int $resourceId): Downtime { $this->resourceId = $resourceId; return $this; } /** * @return int|null */ public function getParentResourceId(): ?int { return $this->parentResourceId; } /** * @param int|null $parentResourceId * @return Downtime */ public function setParentResourceId(?int $parentResourceId): Downtime { $this->parentResourceId = $parentResourceId; return $this; } /** * @return bool */ public function isCancelled(): bool { return $this->isCancelled; } /** * @param bool $isCancelled */ public function setCancelled(bool $isCancelled): void { $this->isCancelled = $isCancelled; } /** * @return string|null */ public function getComment(): ?string { return $this->comment; } /** * @param string|null $comment */ public function setComment(?string $comment): void { $this->comment = $comment; } /** * @return \DateTime|null */ public function getDeletionTime(): ?\DateTime { return $this->deletionTime; } /** * @param \DateTime|null $deletionTime * @throws \Centreon\Domain\Common\Assertion\AssertionException * @throws \Exception */ public function setDeletionTime(?\DateTime $deletionTime): void { if ($deletionTime !== null) { Assertion::maxDate($deletionTime, $this->maxDate, 'Downtime::deletionTime'); } $this->deletionTime = $deletionTime; } /** * @return int|null */ public function getDuration(): ?int { return $this->duration; } /** * @param int|null $duration */ public function setDuration(?int $duration): void { $this->duration = $duration; } /** * @return \DateTime|null */ public function getEndTime(): ?\DateTime { return $this->endTime; } /** * @param \DateTime|null $endTime * @throws \Centreon\Domain\Common\Assertion\AssertionException * @throws \Exception */ public function setEndTime(?\DateTime $endTime): void { if ($endTime !== null) { Assertion::maxDate($endTime, $this->maxDate, 'Downtime::endTime'); } $this->endTime = $endTime; } /** * @return bool */ public function isFixed(): bool { return $this->isFixed; } /** * @param bool $isFixed */ public function setFixed(bool $isFixed): void { $this->isFixed = $isFixed; } /** * @return int|null */ public function getInternalId(): ?int { return $this->internalId; } /** * @param int|null $internalId */ public function setInternalId(?int $internalId): void { $this->internalId = $internalId; } /** * @return int|null */ public function getPollerId(): ?int { return $this->pollerId; } /** * @param int|null $pollerId */ public function setPollerId(?int $pollerId): void { $this->pollerId = $pollerId; } /** * @return \DateTime|null */ public function getStartTime(): ?\DateTime { return $this->startTime; } /** * @param \DateTime|null $startTime * @throws \Centreon\Domain\Common\Assertion\AssertionException * @throws \Exception */ public function setStartTime(?\DateTime $startTime): void { if ($startTime !== null) { Assertion::maxDate($startTime, $this->maxDate, 'Downtime::startTime'); } $this->startTime = $startTime; } /** * @return \DateTime|null */ public function getActualStartTime(): ?\DateTime { return $this->actualStartTime; } /** * @param \DateTime|null $actualStartTime * @throws \Centreon\Domain\Common\Assertion\AssertionException * @throws \Exception */ public function setActualStartTime(?\DateTime $actualStartTime): void { if ($actualStartTime !== null) { Assertion::maxDate($actualStartTime, $this->maxDate, 'Downtime::actualStartTime'); } $this->actualStartTime = $actualStartTime; } /** * @return \DateTime|null */ public function getActualEndTime(): ?\DateTime { return $this->actualEndTime; } /** * @param \DateTime|null $actualEndTime * @throws \Centreon\Domain\Common\Assertion\AssertionException * @throws \Exception */ public function setActualEndTime(?\DateTime $actualEndTime): void { if ($actualEndTime !== null) { Assertion::maxDate($actualEndTime, $this->maxDate, 'Downtime::actualEndTime'); } $this->actualEndTime = $actualEndTime; } /** * @return bool */ public function isStarted(): bool { return $this->isStarted; } /** * @param bool $isStarted */ public function setStarted(bool $isStarted): void { $this->isStarted = $isStarted; } /** * @return bool */ public function isWithServices(): bool { return $this->withServices; } /** * @param bool $withServices */ public function setWithServices(bool $withServices): void { $this->withServices = $withServices; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Downtime/Interfaces/DowntimeRepositoryInterface.php
centreon/src/Centreon/Domain/Downtime/Interfaces/DowntimeRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Downtime\Interfaces; use Centreon\Domain\Downtime\Downtime; use Core\Security\AccessGroup\Domain\Model\AccessGroup; interface DowntimeRepositoryInterface { /** * Sets the access groups that will be used to filter downtime. * * @param AccessGroup[] $accessGroups * @return self */ public function forAccessGroups(array $accessGroups): DowntimeRepositoryInterface; /** * Find downtime of all hosts **taking into account** the ACLs of user. * * @throws \Exception * @return Downtime[] */ public function findHostDowntimesForNonAdminUser(): array; /** * Find downtime of all hosts **without taking into account** the ACLs of user. * * @throws \Exception * @return Downtime[] */ public function findHostDowntimesForAdminUser(): array; /** * Find one downtime linked to a host **without taking into account** the ACLs of user. * * @param int $downtimeId Downtime id * @throws \Exception * @return Downtime|null Return NULL if the downtime has not been found */ public function findOneDowntimeForAdminUser(int $downtimeId): ?Downtime; /** * Find one downtime linked to a host **taking into account** the ACLs of user. * * @param int $downtimeId Downtime id * @throws \Exception * @return Downtime|null Return NULL if the downtime has not been found */ public function findOneDowntimeForNonAdminUser(int $downtimeId): ?Downtime; /** * Find all downtimes **without taking into account** the ACLs of user. * * @throws \Exception * @return Downtime[] Return the downtimes found */ public function findDowntimesForAdminUser(): array; /** * Find all downtimes **taking into account** the ACLs of user. * * @throws \Exception * @return Downtime[] Return the downtimes found */ public function findDowntimesForNonAdminUser(): array; /** * Find all downtimes for a host **taking into account** the ACLs of user. * * @param int $hostId Host id for which we want to find downtimes * @param bool $withServices Display downtimes of host-related services also * @throws \Exception * @return Downtime[] */ public function findDowntimesByHostForAdminUser(int $hostId, bool $withServices): array; /** * Find all downtimes for a host **without taking into account** the ACLs of user. * * @param int $hostId Host id for which we want to find downtimes * @param bool $withServices Display downtimes of host-related services also * @throws \Exception * @return Downtime[] */ public function findDowntimesByHostForNonAdminUser(int $hostId, bool $withServices): array; /** * Find all downtimes of all services **taking into account** the ACLs of user. * * @throws \Exception * @return Downtime[] */ public function findServicesDowntimesForNonAdminUser(): array; /** * Find all downtimes of all services **without taking into account** the ACLs of user. * * @throws \Exception * @return Downtime[] */ public function findServicesDowntimesForAdminUser(): array; /** * Find all downtimes for a service (linked to a host) **taking into account** the ACLs of user. * * @param int $hostId Host id linked to this service * @param int $serviceId Service id for which we want to find downtimes * @throws \Exception * @return Downtime[] */ public function findDowntimesByServiceForNonAdminUser(int $hostId, int $serviceId): array; /** * Find all downtimes for a service (linked to a host) **without taking into account** the ACLs of user. * * @param int $hostId Host id linked to this service * @param int $serviceId Service id for which we want to find downtimes * @throws \Exception * @return Downtime[] */ public function findDowntimesByServiceForAdminUser(int $hostId, int $serviceId): array; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Downtime/Interfaces/DowntimeServiceInterface.php
centreon/src/Centreon/Domain/Downtime/Interfaces/DowntimeServiceInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Downtime\Interfaces; use Centreon\Domain\Downtime\Downtime; use Centreon\Domain\Monitoring\Host; use Centreon\Domain\Monitoring\Resource as ResourceEntity; use Centreon\Domain\Monitoring\Service; interface DowntimeServiceInterface { /** * Used to filter requests according to a contact. * If the filter is defined, all requests will use the ACL of the contact * to fetch data. * * @param mixed $contact Contact to use as a ACL filter * @throws \Exception * @return self */ public function filterByContact($contact): self; /** * Find downtime of all hosts. * * @throws \Exception * @return Downtime[] */ public function findHostDowntimes(): array; /** * Find one downtime linked to a host. * * @param int $downtimeId Downtime id * @throws \Exception * @return Downtime|null Return NULL if the downtime has not been found */ public function findOneDowntime(int $downtimeId): ?Downtime; /** * Find all downtimes. * * @throws \Exception * @return Downtime[] */ public function findDowntimes(): array; /** * Find all downtimes linked to a host. * * @param int $hostId Host id for which we want to find host * @param bool $withServices Display downtimes of host-related services also * @throws \Exception * @return Downtime[] */ public function findDowntimesByHost(int $hostId, bool $withServices): array; /** * Find downtime of all services. * * @throws \Exception * @return Downtime[] */ public function findServicesDowntimes(): array; /** * Find all downtimes for a service (linked to a host). * * @param int $hostId Host id linked to this service * @param int $serviceId Service id for which we want to find downtimes * @throws \Exception * @return Downtime[] */ public function findDowntimesByService(int $hostId, int $serviceId): array; /** * Find all downtimes for a metaservice. * * @param int $metaId ID of the metaservice * @throws \Exception * @return Downtime[] */ public function findDowntimesByMetaService(int $metaId): array; /** * Add a downtime on multiple hosts. * * @param Downtime $downtime Downtime to add * @param Host $host Host to add a downtime * @throws \Exception */ public function addHostDowntime(Downtime $downtime, Host $host): void; /** * Add a downtime on multiple services. * * @param Downtime $downtime Downtime to add for each service * @param Service $service Service (the host property of each service must to be correctly defined) * @throws \Exception */ public function addServiceDowntime(Downtime $downtime, Service $service): void; /** * Cancel one downtime. * * @param int $downtimeId Downtime id to cancel * @param Host $host Downtime-related host * @throws \Exception */ public function cancelDowntime(int $downtimeId, Host $host): void; /** * @param ResourceEntity $resource * @param Downtime $downtime * @throws \Exception */ public function addResourceDowntime(ResourceEntity $resource, Downtime $downtime): void; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/HostMacro.php
centreon/src/Centreon/Domain/HostConfiguration/HostMacro.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration; use Centreon\Domain\Annotation\EntityDescriptor; use Centreon\Domain\Macro\Interfaces\MacroInterface; class HostMacro implements MacroInterface { /** @var int|null */ private $id; /** @var string|null Macro name */ private $name; /** @var string|null Macro value */ private $value; /** * @var bool Indicates whether this macro contains a password * @EntityDescriptor(column="is_password", modifier="setPassword") */ private $isPassword = false; /** @var string|null Macro description */ private $description; /** @var int|null */ private $order; /** @var int|null */ private $hostId; /** * @return int|null */ public function getId(): ?int { return $this->id; } /** * @param int|null $id * @return self */ public function setId(?int $id): self { $this->id = $id; return $this; } /** * @return string|null */ public function getName(): ?string { return $this->name; } /** * @param string|null $name * @return self */ public function setName(?string $name): self { if ($name !== null) { if (! str_starts_with($name, '$_HOST')) { $name = '$_HOST' . $name; if ($name[-1] !== '$') { $name .= '$'; } } $this->name = strtoupper($name); } else { $this->name = null; } return $this; } /** * @return string|null */ public function getValue(): ?string { return $this->value; } /** * @param string|null $value * @return self */ public function setValue(?string $value): self { $this->value = $value; return $this; } /** * @return bool */ public function isPassword(): bool { return $this->isPassword; } /** * @param bool $isPassword * @return self */ public function setPassword(bool $isPassword): self { $this->isPassword = $isPassword; return $this; } /** * @return string|null */ public function getDescription(): ?string { return $this->description; } /** * @param string|null $description * @return self */ public function setDescription(?string $description): self { $this->description = $description; return $this; } /** * @return int|null */ public function getOrder(): ?int { return $this->order; } /** * @param int|null $order * @return self */ public function setOrder(?int $order): self { $this->order = $order; return $this; } /** * @return int|null */ public function getHostId(): ?int { return $this->hostId; } /** * @param int|null $hostId * @return self */ public function setHostId(?int $hostId): self { $this->hostId = $hostId; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/HostConfigurationService.php
centreon/src/Centreon/Domain/HostConfiguration/HostConfigurationService.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration; use Centreon\Domain\ActionLog\ActionLog; use Centreon\Domain\ActionLog\Interfaces\ActionLogServiceInterface; use Centreon\Domain\Common\Assertion\Assertion; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\Engine\Interfaces\EngineConfigurationServiceInterface; use Centreon\Domain\HostConfiguration\Exception\HostConfigurationServiceException; use Centreon\Domain\HostConfiguration\Interfaces\HostCategory\HostCategoryServiceInterface; use Centreon\Domain\HostConfiguration\Interfaces\HostConfigurationRepositoryInterface; use Centreon\Domain\HostConfiguration\Interfaces\HostConfigurationServiceInterface; use Centreon\Domain\HostConfiguration\Interfaces\HostGroup\HostGroupServiceInterface; use Centreon\Domain\HostConfiguration\Interfaces\HostMacro\HostMacroServiceInterface; use Centreon\Domain\HostConfiguration\Model\HostCategory; use Centreon\Domain\HostConfiguration\Model\HostGroup; use Centreon\Domain\Log\LoggerTrait; use Centreon\Domain\Repository\Interfaces\DataStorageEngineInterface; /** * @package Centreon\Domain\HostConfiguration */ class HostConfigurationService implements HostConfigurationServiceInterface { use LoggerTrait; /** @var HostConfigurationRepositoryInterface */ private $hostConfigurationRepository; /** @var EngineConfigurationServiceInterface */ private $engineConfigurationService; /** @var ActionLogServiceInterface */ private $actionLogService; /** @var DataStorageEngineInterface */ private $dataStorageEngine; /** @var HostMacroServiceInterface */ private $hostMacroService; /** @var HostCategoryServiceInterface */ private $hostCategoryService; /** @var HostGroupServiceInterface */ private $hostGroupService; /** @var ContactInterface */ private $contact; /** * @param HostConfigurationRepositoryInterface $hostConfigurationRepository * @param ActionLogServiceInterface $actionLogService * @param EngineConfigurationServiceInterface $engineConfigurationService * @param HostMacroServiceInterface $hostMacroService * @param HostCategoryServiceInterface $hostCategoryService * @param HostGroupServiceInterface $hostGroupService * @param DataStorageEngineInterface $dataStorageEngine * @param ContactInterface $contact */ public function __construct( HostConfigurationRepositoryInterface $hostConfigurationRepository, ActionLogServiceInterface $actionLogService, EngineConfigurationServiceInterface $engineConfigurationService, HostMacroServiceInterface $hostMacroService, HostCategoryServiceInterface $hostCategoryService, HostGroupServiceInterface $hostGroupService, DataStorageEngineInterface $dataStorageEngine, ContactInterface $contact, ) { $this->hostConfigurationRepository = $hostConfigurationRepository; $this->actionLogService = $actionLogService; $this->engineConfigurationService = $engineConfigurationService; $this->hostMacroService = $hostMacroService; $this->hostCategoryService = $hostCategoryService; $this->hostGroupService = $hostGroupService; $this->dataStorageEngine = $dataStorageEngine; $this->contact = $contact; } /** * {@inheritDoc] * @throws \Assert\AssertionFailedException */ public function addHost(Host $host): void { $this->info('Add host'); Assertion::notEmpty($host->getName(), 'Host::name'); Assertion::notEmpty($host->getIpAddress(), 'Host::ipAddress'); if ($host->getMonitoringServer() === null || $host->getMonitoringServer()->getName() === null) { throw HostConfigurationServiceException::monitoringServerNotCorrectlyDefined(); } $this->debug( 'Host details', ['host_name' => $host->getName(), 'monitoring_server' => $host->getMonitoringServer()->getName()] ); $transactionAlreadyStarted = $this->dataStorageEngine->isAlreadyinTransaction(); try { $this->checkIllegalCharactersInHostName($host); if ($this->hostConfigurationRepository->hasHostWithSameName($host->getName())) { throw HostConfigurationServiceException::hostNameAlreadyExists(); } try { if ($transactionAlreadyStarted === false) { $this->debug('Start transaction'); $this->dataStorageEngine->startTransaction(); } /** * Create all the entities that will be associated with the host and that * must exist beforehand and provided that their identifier is defined. */ $this->createHostCategoriesBeforeLinking($host->getCategories()); $this->createHostGroupsBeforeLinking($host->getGroups()); $this->debug('Adding host'); $this->hostConfigurationRepository->addHost($host); /** * Create all the entities that will be associated with the host that must be created first. */ $newMacroOrder = 0; // by default we initialize the order of the macros foreach ($host->getMacros() as $macro) { $this->debug('Add macro ' . $macro->getName()); if ($macro->getOrder() === null) { $macro->setOrder($newMacroOrder); } $this->hostMacroService->addMacroToHost($host, $macro); $newMacroOrder++; } if ($transactionAlreadyStarted === false) { $this->debug('Commit transaction'); $this->dataStorageEngine->commitTransaction(); } } catch (\Throwable $ex) { if ($transactionAlreadyStarted === false) { $this->debug('Rollback transaction'); $this->dataStorageEngine->rollbackTransaction(); } throw HostConfigurationServiceException::errorOnAddingAHost($ex); } if ($host->getId() !== null) { $this->addActionLog($host, ActionLog::ACTION_TYPE_ADD); } } catch (HostConfigurationServiceException $ex) { throw $ex; } catch (\Exception $ex) { throw HostConfigurationServiceException::errorOnAddingAHost($ex); } } /** * {@inheritDoc} * @throws HostConfigurationServiceException * @throws \Throwable */ public function updateHost(Host $host): void { $this->info('Update host'); if (empty($host->getName())) { throw HostConfigurationServiceException::hostNameCanNotBeEmpty(); } if (empty($host->getIpAddress())) { throw HostConfigurationServiceException::ipAddressCanNotBeEmpty(); } if ($host->getMonitoringServer() === null || $host->getMonitoringServer()->getName() === null) { throw HostConfigurationServiceException::monitoringServerNotCorrectlyDefined(); } $transactionAlreadyStarted = $this->dataStorageEngine->isAlreadyinTransaction(); try { $this->checkIllegalCharactersInHostName($host); if ($transactionAlreadyStarted === false) { $this->debug('Start transaction'); $this->dataStorageEngine->startTransaction(); } $this->debug('Updating host'); $this->hostConfigurationRepository->updateHost($host); $this->addAndUpdateHostMacros($host); if ($transactionAlreadyStarted === false) { $this->debug('Commit transaction'); $this->dataStorageEngine->commitTransaction(); } } catch (\Throwable $ex) { if ($transactionAlreadyStarted === false) { $this->debug('Rollback transaction'); $this->dataStorageEngine->rollbackTransaction(); } throw HostConfigurationServiceException::errorOnUpdatingAHost($ex); } } /** * @inheritDoc */ public function findHostTemplatesRecursively(Host $host): array { try { return $this->hostConfigurationRepository->findHostTemplatesRecursively($host); } catch (\Throwable $ex) { throw new HostConfigurationException(_('Error when searching for host templates'), 0, $ex); } } /** * @inheritDoc */ public function findHost(int $hostId): ?Host { try { return $this->hostConfigurationRepository->findHost($hostId); } catch (\Throwable $ex) { throw new HostConfigurationException(_('Error while searching for the host'), 0, $ex); } } /** * @inheritDoc */ public function getNumberOfHosts(): int { try { return $this->hostConfigurationRepository->getNumberOfHosts(); } catch (\Throwable $ex) { throw new HostConfigurationException(_('Error while searching for the number of host'), 0, $ex); } } /** * @inheritDoc */ public function findCommandLine(int $hostId): ?string { try { return $this->hostConfigurationRepository->findCommandLine($hostId); } catch (\Throwable $ex) { throw new HostConfigurationException(_('Error while searching for the command of host'), 0, $ex); } } /** * @inheritDoc */ public function findOnDemandHostMacros(int $hostId, bool $isUsingInheritance = false): array { try { return $this->hostConfigurationRepository->findOnDemandHostMacros($hostId, $isUsingInheritance); } catch (\Throwable $ex) { throw new HostConfigurationException(_('Error while searching for the host macros'), 0, $ex); } } /** * @inheritDoc */ public function findHostMacrosFromCommandLine(int $hostId, string $command): array { $hostMacros = []; if (preg_match_all('/(\$_HOST\S+?\$)/', $command, $matches)) { $matchedMacros = $matches[0]; foreach ($matchedMacros as $matchedMacroName) { // snmp macros are not custom macros if (in_array($matchedMacroName, ['$_HOSTSNMPCOMMUNITY$', '$_HOSTSNMPVERSION$']) === false) { $hostMacros[$matchedMacroName] = (new HostMacro()) ->setName($matchedMacroName) ->setValue(''); } } $linkedHostMacros = $this->findOnDemandHostMacros($hostId, true); foreach ($linkedHostMacros as $linkedHostMacro) { if (in_array($linkedHostMacro->getName(), $matchedMacros)) { $hostMacros[$linkedHostMacro->getName()] = $linkedHostMacro; } } } return array_values($hostMacros); } /** * @inheritDoc */ public function changeActivationStatus(Host $host, bool $shouldBeActivated): void { try { if ($host->getId() === null) { throw new HostConfigurationException(_('Host id cannot be null')); } if ($host->getName() === null) { throw new HostConfigurationException(_('Host name cannot be null')); } $loadedHost = $this->findHost($host->getId()); if ($loadedHost === null) { throw new HostConfigurationException(sprintf(_('Host %d not found'), $host->getId())); } if ($loadedHost->getId() === null) { throw new HostConfigurationException(_('Host id cannot be null')); } $this->hostConfigurationRepository->changeActivationStatus($loadedHost->getId(), $shouldBeActivated); $this->actionLogService->addAction( // The userId is set to 0 because it is not yet possible to determine who initiated the action. // We will see later how to get it back. new ActionLog( 'host', $host->getId(), $host->getName(), $shouldBeActivated ? ActionLog::ACTION_TYPE_ENABLE : ActionLog::ACTION_TYPE_DISABLE, 0 ) ); } catch (HostConfigurationException $ex) { throw $ex; } catch (\Throwable $ex) { throw new HostConfigurationException( sprintf( _('Error when changing host status (%d to %s)'), $host->getId(), $shouldBeActivated ? 'true' : 'false' ), 0, $ex ); } } /** * @inheritDoc */ public function findHostNamesAlreadyUsed(array $namesToCheck): array { try { return $this->hostConfigurationRepository->findHostNamesAlreadyUsed($namesToCheck); } catch (\Throwable $ex) { throw new HostConfigurationException(_('Error when searching for already used host names')); } } /** * @inheritDoc */ public function findHostTemplatesByHost(Host $host): array { try { return $this->hostConfigurationRepository->findHostTemplatesByHost($host); } catch (\Throwable $ex) { throw new HostConfigurationException(_('Error when searching for host templates'), 0, $ex); } } /** * @inheritDoc */ public function findHostByName(string $hostName): ?Host { try { return $this->hostConfigurationRepository->findHostByName($hostName); } catch (\Throwable $ex) { throw new HostConfigurationException(_('Error while searching for the host'), 0, $ex); } } /** * {@inheritDoc} * @throws HostConfigurationException */ public function findHostTemplate(int $hostTemplateId): ?Host { try { return $this->hostConfigurationRepository->findHostTemplate($hostTemplateId); } catch (\Throwable $ex) { $message = sprintf( _('Error while searching for the host template %d'), $hostTemplateId ); $this->error( $message, ['message' => $ex->getMessage()] ); throw new HostConfigurationException($message, 0, $ex); } } /** * Create host categories if they don't exist, otherwise we initialise the ids with the existing categories. * * @param HostCategory[] $categories Host categories to be created * @throws Exception\HostCategoryException */ private function createHostCategoriesBeforeLinking(array $categories): void { $this->info('Create host categories before linking'); $namesToCheckBeforeCreation = []; foreach ($categories as $category) { if ($category->getId() === null) { $namesToCheckBeforeCreation[] = $category->getName(); } } $categoriesAlreadyCreated = $this->hostCategoryService->findByNamesWithoutAcl($namesToCheckBeforeCreation); $categoriesToBeCreated = []; foreach ($categories as $category) { if ($category->getId() !== null) { continue; } $found = false; foreach ($categoriesAlreadyCreated as $categoryAlreadyCreated) { if ($category->getName() == $categoryAlreadyCreated->getName()) { $found = true; break; } } if ($found === false) { $categoriesToBeCreated[] = $category; } } foreach ($categoriesToBeCreated as $categoryToBeCreated) { $this->hostCategoryService->addCategory($categoryToBeCreated); } /* * We retrieve the id of already created or newly created categories and associate them with the list of * original categories so that they can be linked to the host. */ foreach ($categories as $category) { if ($category->getId() === null) { foreach ($categoriesToBeCreated as $categoryCreated) { if ( $category->getName() === $categoryCreated->getName() && $categoryCreated->getId() !== null ) { $category->setId($categoryCreated->getId()); } } foreach ($categoriesAlreadyCreated as $categoryAlreadyCreated) { if ( $category->getName() === $categoryAlreadyCreated->getName() && $categoryAlreadyCreated->getId() !== null ) { $category->setId($categoryAlreadyCreated->getId()); } } } } } /** * Create host groups if they don't exist, otherwise we initialise the ids with the existing host groups. * * @param HostGroup[] $groups Host groups to be created * @throws Exception\HostGroupException */ private function createHostGroupsBeforeLinking(array $groups): void { $this->info('Create host groups before linking'); $namesToCheckBeforeCreation = []; foreach ($groups as $group) { if ($group->getId() === null) { $namesToCheckBeforeCreation[] = $group->getName(); } } // We search for them as if we were an admin user $groupsAlreadyCreated = $this->hostGroupService->findByNamesWithoutAcl($namesToCheckBeforeCreation); $groupsToBeCreated = []; foreach ($groups as $group) { if ($group->getId() !== null) { continue; } $found = false; foreach ($groupsAlreadyCreated as $groupAlreadyCreated) { if ($group->getName() == $groupAlreadyCreated->getName()) { $found = true; break; } } if ($found === false) { $groupsToBeCreated[] = $group; } } foreach ($groupsToBeCreated as $groupToBeCreated) { $this->hostGroupService->addGroup($groupToBeCreated); } /* * We retrieve the id of already created or newly created groups and associate them with the list of original * groups so that they can be linked to the host. */ foreach ($groups as $group) { if ($group->getId() === null) { foreach ($groupsToBeCreated as $groupCreated) { if ( $group->getName() === $groupCreated->getName() && $groupCreated->getId() !== null ) { $group->setId($groupCreated->getId()); } } foreach ($groupsAlreadyCreated as $groupCreated) { if ( $group->getName() === $groupCreated->getName() && $groupCreated->getId() !== null ) { $group->setId($groupCreated->getId()); } } } } } /** * The host name is checked to remove any illegal characters that monitoring server cannot accept. * * @param Host $host * @throws HostConfigurationException * @throws \Centreon\Domain\Engine\EngineException */ private function checkIllegalCharactersInHostName(Host $host): void { $this->info('Check illegal characters in host name'); $engineConfiguration = $this->engineConfigurationService->findEngineConfigurationByName( $host->getMonitoringServer()->getName() ); if ($engineConfiguration === null) { throw HostConfigurationServiceException::engineConfigurationNotFound(); } $this->debug( 'Engine configuration', ['id' => $engineConfiguration->getId(), 'name' => $engineConfiguration->getName()] ); $safedHostName = $engineConfiguration->removeIllegalCharacters($host->getName()); if (empty($safedHostName)) { throw HostConfigurationServiceException::hostNameCanNotBeEmpty(); } $this->debug('Safed host name: ' . $safedHostName); $host->setName($safedHostName); if ($host->getExtendedHost() === null) { $host->setExtendedHost(new ExtendedHost()); $this->debug('ExtendedHost created'); } if ($host->getMonitoringServer()->getId() === null) { $host->getMonitoringServer()->setId($engineConfiguration->getMonitoringServerId()); $this->debug('Monitoring server id defined #' . $engineConfiguration->getMonitoringServerId()); } } /** * @throws \Centreon\Domain\ActionLog\ActionLogException */ private function addActionLog(Host $host, string $action): void { $defaultStatus = 'Default'; // We create the list of changes concerning the creation of the host $actionsDetails = [ 'Host name' => $host->getName() ?? '', 'Host alias' => $host->getAlias() ?? '', 'Host IP address' => $host->getIpAddress() ?? '', 'Monitoring server name' => $host->getMonitoringServer()->getName() ?? '', 'Create services linked to templates' => 'true', 'Is activated' => $host->isActivated() ? 'true' : 'false', // We don't have these properties in the host object yet, so we display these default values 'Active checks enabled' => $defaultStatus, 'Passive checks enabled' => $defaultStatus, 'Notifications enabled' => $defaultStatus, 'Obsess over host' => $defaultStatus, 'Check freshness' => $defaultStatus, 'Flap detection enabled' => $defaultStatus, 'Retain status information' => $defaultStatus, 'Retain nonstatus information' => $defaultStatus, 'Event handler enabled' => $defaultStatus, ]; if (empty($host->getTemplates()) === false) { $templateNames = []; foreach ($host->getTemplates() as $template) { if (empty($template->getName()) === false) { $templateNames[] = $template->getName(); } } $actionsDetails = array_merge( $actionsDetails, ['Templates selected' => implode(', ', $templateNames)] ); } if (empty($host->getMacros()) === false) { $macroDetails = []; foreach ($host->getMacros() as $macro) { if (empty($macro->getName()) === false) { // We remove the symbol characters in the macro name $macroDetails[substr($macro->getName(), 2, strlen($macro->getName()) - 3)] = $macro->isPassword() ? '*****' : $macro->getValue() ?? ''; } } $actionsDetails = array_merge( $actionsDetails, [ 'Macro names' => implode(', ', array_keys($macroDetails)), 'Macro values' => implode(', ', array_values($macroDetails)), ] ); } $this->actionLogService->addAction( new ActionLog('host', $host->getId(), $host->getName(), $action, $this->contact->getId()), $actionsDetails ); } /** * Add and update all host macros. * * @param Host $host * @throws Exception\HostMacroServiceException */ private function addAndUpdateHostMacros(Host $host): void { $this->debug('Add and update host macros'); $existingHostMacros = $this->hostMacroService->findHostMacros($host); $this->updateHostMacros($host, $existingHostMacros); $this->addNewHostMacros($host, $existingHostMacros); } /** * Update all macros on the host that already exist. * We use the existing macros to identify which ones need to be updated in the host. * * @param Host $host * @param HostMacro[] $existingHostMacros * @throws Exception\HostMacroServiceException */ private function updateHostMacros(Host $host, array $existingHostMacros): void { $this->debug('Update existing host macros'); foreach ($host->getMacros() as $macroToUpdate) { foreach ($existingHostMacros as $existingHostMacro) { if ($macroToUpdate->getName() === $existingHostMacro->getName()) { $this->debug('Update macro ' . $macroToUpdate->getName()); $this->hostMacroService->updateMacro($macroToUpdate); break; } } } } /** * Add the host macros that does not exist. * The host macros added will be those that are not present in the $existingHostMacros list. * * @param Host $host * @param HostMacro[] $existingHostMacros * @throws Exception\HostMacroServiceException */ private function addNewHostMacros(Host $host, array $existingHostMacros): void { $this->debug('Add new host macros'); foreach ($host->getMacros() as $hostMacro) { $isHostMacroFound = false; foreach ($existingHostMacros as $existingHostMacro) { if ($hostMacro->getName() === $existingHostMacro->getName()) { $isHostMacroFound = true; break; } } if (! $isHostMacroFound) { $this->debug( 'Add new host macro', [], fn () => [ 'name' => $hostMacro->getName(), 'is_password' => $hostMacro->isPassword(), 'value' => (! $hostMacro->isPassword()) ? $hostMacro->getValue() : '*****', ] ); $this->hostMacroService->addMacroToHost($host, $hostMacro); } } } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/HostMacroService.php
centreon/src/Centreon/Domain/HostConfiguration/HostMacroService.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration; use Centreon\Domain\Common\Assertion\Assertion; use Centreon\Domain\HostConfiguration\Exception\HostMacroServiceException; use Centreon\Domain\HostConfiguration\Interfaces\HostMacro\HostMacroReadRepositoryInterface; use Centreon\Domain\HostConfiguration\Interfaces\HostMacro\HostMacroServiceInterface; use Centreon\Domain\HostConfiguration\Interfaces\HostMacro\HostMacroWriteRepositoryInterface; /** * This class is designed to manage all host macros. * * @package Centreon\Domain\HostConfiguration */ class HostMacroService implements HostMacroServiceInterface { /** * HostMacroService constructor. * * @param HostMacroWriteRepositoryInterface $writeRepository * @param HostMacroReadRepositoryInterface $readRepository */ public function __construct( private HostMacroWriteRepositoryInterface $writeRepository, private HostMacroReadRepositoryInterface $readRepository, ) { } /** * @inheritDoc */ public function addMacroToHost(Host $host, HostMacro $hostMacro): void { try { $this->writeRepository->addMacroToHost($host, $hostMacro); } catch (\Throwable $ex) { throw HostMacroServiceException::addMacroException($ex); } } /** * @inheritDoc */ public function findHostMacros(Host $host): array { try { Assertion::notNull($host->getId(), 'Host::id'); return $this->readRepository->findAllByHost($host); } catch (\Throwable $ex) { throw HostMacroServiceException::errorOnReadingHostMacros($ex); } } /** * @inheritDoc */ public function updateMacro(HostMacro $macro): void { try { Assertion::notNull($macro->getId(), 'HostMacro::id'); Assertion::notNull($macro->getHostId(), 'HostMacro::host_id'); $this->writeRepository->updateMacro($macro); } catch (\Throwable $ex) { throw HostMacroServiceException::errorOnUpdatingMacro($ex); } } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/HostGroupService.php
centreon/src/Centreon/Domain/HostConfiguration/HostGroupService.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\HostConfiguration\Exception\HostGroupException; use Centreon\Domain\HostConfiguration\Interfaces\HostGroup\HostGroupReadRepositoryInterface; use Centreon\Domain\HostConfiguration\Interfaces\HostGroup\HostGroupServiceInterface; use Centreon\Domain\HostConfiguration\Interfaces\HostGroup\HostGroupWriteRepositoryInterface; use Centreon\Domain\HostConfiguration\Model\HostGroup; use Centreon\Domain\Repository\RepositoryException; /** * This class is designed to manage the host groups. * * @package Centreon\Domain\HostConfiguration */ class HostGroupService implements HostGroupServiceInterface { /** @var HostGroupReadRepositoryInterface */ private $readRepository; /** @var ContactInterface */ private $contact; /** @var HostGroupWriteRepositoryInterface */ private $writeRepository; /** * @param HostGroupReadRepositoryInterface $readRepository * @param HostGroupWriteRepositoryInterface $writeRepository * @param ContactInterface $contact */ public function __construct( HostGroupReadRepositoryInterface $readRepository, HostGroupWriteRepositoryInterface $writeRepository, ContactInterface $contact, ) { $this->readRepository = $readRepository; $this->writeRepository = $writeRepository; $this->contact = $contact; } /** * @inheritDoc */ public function addGroup(HostGroup $group): void { try { $this->writeRepository->addGroup($group); } catch (\Throwable $ex) { throw HostGroupException::addGroupException($ex); } } /** * @inheritDoc */ public function findByNamesWithoutAcl(array $groupsName): array { try { return $this->readRepository->findByNames($groupsName); } catch (\Throwable $ex) { throw HostGroupException::findHostGroupsException($ex); } } /** * @inheritDoc */ public function findWithAcl(int $groupId): ?HostGroup { try { return $this->readRepository->findByIdAndContact($groupId, $this->contact); } catch (RepositoryException $ex) { throw $ex; } catch (\Exception $ex) { throw HostGroupException::findHostGroupException($ex, ['id' => $groupId]); } } /** * @inheritDoc */ public function findWithoutAcl(int $groupId): ?HostGroup { try { return $this->readRepository->findById($groupId); } catch (RepositoryException $ex) { throw $ex; } catch (\Exception $ex) { throw HostGroupException::findHostGroupException($ex, ['id' => $groupId]); } } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/HostSeverityService.php
centreon/src/Centreon/Domain/HostConfiguration/HostSeverityService.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\HostConfiguration\Exception\HostSeverityException; use Centreon\Domain\HostConfiguration\Interfaces\HostSeverity\HostSeverityReadRepositoryInterface; use Centreon\Domain\HostConfiguration\Interfaces\HostSeverity\HostSeverityServiceInterface; use Centreon\Domain\HostConfiguration\Model\HostSeverity; use Centreon\Domain\Repository\RepositoryException; /** * This class is designed to manage the host severities. * * @package Centreon\Domain\HostConfiguration */ class HostSeverityService implements HostSeverityServiceInterface { /** @var HostSeverityReadRepositoryInterface */ private $readRepository; /** @var ContactInterface */ private $contact; /** * @param HostSeverityReadRepositoryInterface $repository * @param ContactInterface $contact */ public function __construct( HostSeverityReadRepositoryInterface $repository, ContactInterface $contact, ) { $this->readRepository = $repository; $this->contact = $contact; } /** * @inheritDoc */ public function findWithAcl(int $severityId): ?HostSeverity { try { return $this->readRepository->findByIdAndContact($severityId, $this->contact); } catch (RepositoryException $ex) { throw $ex; } catch (\Exception $ex) { throw HostSeverityException::findHostSeverityException(['id' => $severityId], $ex); } } /** * @inheritDoc */ public function findWithoutAcl(int $severityId): ?HostSeverity { try { return $this->readRepository->findById($severityId); } catch (RepositoryException $ex) { throw $ex; } catch (\Exception $ex) { throw HostSeverityException::findHostSeverityException(['id' => $severityId], $ex); } } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/ExtendedHost.php
centreon/src/Centreon/Domain/HostConfiguration/ExtendedHost.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration; class ExtendedHost { /** @var int */ private $id; /** @var string|null */ private $notes; /** @var string|null */ private $notesUrl; /** @var string|null */ private $actionUrl; /** * @return int */ public function getId(): int { return $this->id; } /** * @param int $id * @return ExtendedHost */ public function setId(int $id): ExtendedHost { $this->id = $id; return $this; } /** * @return string|null */ public function getNotes(): ?string { return $this->notes; } /** * @param string|null $notes * @return ExtendedHost */ public function setNotes(?string $notes): ExtendedHost { $this->notes = $notes; return $this; } /** * @return string|null */ public function getNotesUrl(): ?string { return $this->notesUrl; } /** * @param string|null $notesUrl * @return ExtendedHost */ public function setNotesUrl(?string $notesUrl): ExtendedHost { $this->notesUrl = $notesUrl; return $this; } /** * @return string|null */ public function getActionUrl(): ?string { return $this->actionUrl; } /** * @param string|null $actionUrl * @return ExtendedHost */ public function setActionUrl(?string $actionUrl): ExtendedHost { $this->actionUrl = $actionUrl; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/HostConfigurationException.php
centreon/src/Centreon/Domain/HostConfiguration/HostConfigurationException.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration; class HostConfigurationException extends \Exception { }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/HostCategoryService.php
centreon/src/Centreon/Domain/HostConfiguration/HostCategoryService.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\HostConfiguration\Exception\HostCategoryException; use Centreon\Domain\HostConfiguration\Interfaces\HostCategory\HostCategoryReadRepositoryInterface; use Centreon\Domain\HostConfiguration\Interfaces\HostCategory\HostCategoryServiceInterface; use Centreon\Domain\HostConfiguration\Interfaces\HostCategory\HostCategoryWriteRepositoryInterface; use Centreon\Domain\HostConfiguration\Model\HostCategory; /** * This class is designed to manage the host categories. * * @package Centreon\Domain\HostConfiguration */ class HostCategoryService implements HostCategoryServiceInterface { /** @var HostCategoryReadRepositoryInterface */ private $readRepository; /** @var ContactInterface */ private $contact; /** @var HostCategoryWriteRepositoryInterface */ private $writeRepository; /** * @param HostCategoryReadRepositoryInterface $readRepository * @param HostCategoryWriteRepositoryInterface $writeRepository * @param ContactInterface $contact */ public function __construct( HostCategoryReadRepositoryInterface $readRepository, HostCategoryWriteRepositoryInterface $writeRepository, ContactInterface $contact, ) { $this->contact = $contact; $this->readRepository = $readRepository; $this->writeRepository = $writeRepository; } /** * @inheritDoc */ public function addCategory(HostCategory $category): void { try { $this->writeRepository->addCategory($category); } catch (\Throwable $ex) { HostCategoryException::addCategoryException($ex); } } /** * @inheritDoc */ public function findWithAcl(int $categoryId): ?HostCategory { try { return $this->readRepository->findByIdAndContact($categoryId, $this->contact); } catch (\Throwable $ex) { throw HostCategoryException::findHostCategoryException($ex, ['id' => $categoryId]); } } /** * @inheritDoc */ public function findWithoutAcl(int $categoryId): ?HostCategory { try { return $this->readRepository->findById($categoryId); } catch (\Throwable $ex) { throw HostCategoryException::findHostCategoryException($ex, ['id' => $categoryId]); } } /** * @inheritDoc */ public function findByNamesWithoutAcl(array $categoriesName): array { try { return $this->readRepository->findByNames($categoriesName); } catch (\Throwable $ex) { throw HostCategoryException::findHostCategoriesException($ex); } } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Host.php
centreon/src/Centreon/Domain/HostConfiguration/Host.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration; use Centreon\Domain\Annotation\EntityDescriptor; use Centreon\Domain\Common\Assertion\Assertion; use Centreon\Domain\HostConfiguration\Model\HostCategory; use Centreon\Domain\HostConfiguration\Model\HostGroup; use Centreon\Domain\HostConfiguration\Model\HostSeverity; use Centreon\Domain\MonitoringServer\MonitoringServer; /*** * This class is designed to represent a host configuration. * * @package Centreon\Domain\HostConfiguration */ class Host { public const OPTION_NO = 0; public const OPTION_YES = 1; public const OPTION_DEFAULT = 2; /** * Host template */ public const TYPE_HOST_TEMPLATE = 0; /** * Host */ public const TYPE_HOST = 1; /** * Host meta */ public const TYPE_META = 2; public const NOTIFICATIONS_OPTION_DISABLED = 0; public const NOTIFICATIONS_OPTION_ENABLED = 1; public const NOTIFICATIONS_OPTION_DEFAULT_ENGINE_VALUE = 2; private const AVAILABLE_NOTIFICATION_OPTIONS = [ self::NOTIFICATIONS_OPTION_DISABLED, self::NOTIFICATIONS_OPTION_ENABLED, self::NOTIFICATIONS_OPTION_DEFAULT_ENGINE_VALUE, ]; /** @var int|null */ private $id; /** @var MonitoringServer|null */ private $monitoringServer; /** @var string|null */ private $name; /** @var string|null */ private $alias; /** @var string|null Host display name */ private $displayName; /** @var string|null */ private $ipAddress; /** @var string|null */ private $comment; /** @var string|null */ private $geoCoords; /** * @var bool * @EntityDescriptor(column="is_activated", modifier="setActivated") */ private $isActivated = true; /** * @var int Host type * @see Host::TYPE_HOST_TEMPLATE (0) * @see Host::TYPE_HOST (1) * @see Host::TYPE_META (2) */ private $type = self::TYPE_HOST; /** @var ExtendedHost|null */ private $extendedHost; /** @var Host[] Host templates */ private $templates = []; /** @var HostMacro[] */ private $macros = []; /** @var HostCategory[] */ private $categories = []; /** @var HostGroup[] */ private $groups = []; /** @var HostSeverity|null */ private $severity; /** @var int */ private $notificationsEnabledOption = self::NOTIFICATIONS_OPTION_DEFAULT_ENGINE_VALUE; /** * @return int|null */ public function getId(): ?int { return $this->id; } /** * @param int|null $id * @return self */ public function setId(?int $id): self { $this->id = $id; return $this; } /** * @return string|null */ public function getName(): ?string { return $this->name; } /** * @param string|null $name * @return self */ public function setName(?string $name): self { $this->name = $name; return $this; } /** * @return string|null */ public function getAlias(): ?string { return $this->alias; } /** * @param string|null $alias * @return self */ public function setAlias(?string $alias): self { $this->alias = $alias; return $this; } /** * @return string|null */ public function getDisplayName(): ?string { return $this->displayName; } /** * @param string|null $displayName * @return self */ public function setDisplayName(?string $displayName): self { $this->displayName = $displayName; return $this; } /** * @return string|null */ public function getIpAddress(): ?string { return $this->ipAddress; } /** * @param string|null $ipAddress * @return self */ public function setIpAddress(?string $ipAddress): self { $this->ipAddress = $ipAddress; return $this; } /** * @return string|null */ public function getComment(): ?string { return $this->comment; } /** * @param string|null $comment * @return self */ public function setComment(?string $comment): self { $this->comment = $comment; return $this; } /** * @return string|null */ public function getGeoCoords(): ?string { return $this->geoCoords; } /** * @param string|null $geoCoords * @return self */ public function setGeoCoords(?string $geoCoords): self { $this->geoCoords = $geoCoords; return $this; } /** * @return bool */ public function isActivated(): bool { return $this->isActivated; } /** * @param bool $isActivated * @return self */ public function setActivated(bool $isActivated): self { $this->isActivated = $isActivated; return $this; } /** * @return ExtendedHost|null */ public function getExtendedHost(): ?ExtendedHost { return $this->extendedHost; } /** * @param ExtendedHost|null $extendedHost * @return self */ public function setExtendedHost(?ExtendedHost $extendedHost): self { $this->extendedHost = $extendedHost; return $this; } /** * @return MonitoringServer|null */ public function getMonitoringServer(): ?MonitoringServer { return $this->monitoringServer; } /** * @param MonitoringServer|null $monitoringServer * @return self */ public function setMonitoringServer(?MonitoringServer $monitoringServer): self { $this->monitoringServer = $monitoringServer; return $this; } /** * @return int */ public function getType(): int { return $this->type; } /** * @param int $type * @return self */ public function setType(int $type): self { $this->type = $type; return $this; } /** * @return Host[] */ public function getTemplates(): array { return $this->templates; } /** * Add a host template. * * @param Host $hostTemplate * @throws \InvalidArgumentException * @return self */ public function addTemplate(Host $hostTemplate): self { if ($hostTemplate->getType() !== Host::TYPE_HOST_TEMPLATE) { throw new \InvalidArgumentException(_('This host is not a host template')); } $this->templates[] = $hostTemplate; return $this; } /** * Clear and add all host templates. * * @param Host[] $hostTemplates * @throws \InvalidArgumentException * @return self */ public function setTemplates(array $hostTemplates): self { $this->clearTemplates(); foreach ($hostTemplates as $hostTemplate) { if ($hostTemplate->getType() !== Host::TYPE_HOST_TEMPLATE) { throw new \InvalidArgumentException(_('This host is not a host template')); } $this->templates[] = $hostTemplate; } return $this; } /** * Clear all templates. * * @return self */ public function clearTemplates(): self { $this->templates = []; return $this; } /** * @return HostMacro[] */ public function getMacros(): array { return $this->macros; } /** * @param HostMacro[] $macros * @return self */ public function setMacros(array $macros): self { $this->macros = $macros; return $this; } /** * Add a host macro. * * @param HostMacro $hostMacro Host macro to be added * @return self */ public function addMacro(HostMacro $hostMacro): self { $this->macros[] = $hostMacro; return $this; } /** * @param HostCategory $category * @return self */ public function addCategory(HostCategory $category): self { $this->categories[] = $category; return $this; } /** * @return HostCategory[] */ public function getCategories(): array { return $this->categories; } /** * @return self */ public function clearCategories(): self { $this->categories = []; return $this; } /** * @param HostGroup $hostGroup * @return self */ public function addGroup(HostGroup $hostGroup): self { $this->groups[] = $hostGroup; return $this; } /** * @return HostGroup[] */ public function getGroups(): array { return $this->groups; } /** * @return self */ public function clearGroups(): self { $this->groups = []; return $this; } /** * @param HostSeverity|null $hostSeverity * @return self */ public function setSeverity(?HostSeverity $hostSeverity): self { $this->severity = $hostSeverity; return $this; } /** * @return HostSeverity|null */ public function getSeverity(): ?HostSeverity { return $this->severity; } /** * @return int */ public function getNotificationsEnabledOption(): int { return $this->notificationsEnabledOption; } /** * @param int $notificationsEnabledOption * @return self */ public function setNotificationsEnabledOption(int $notificationsEnabledOption): self { Assertion::inArray( $notificationsEnabledOption, self::AVAILABLE_NOTIFICATION_OPTIONS, 'Engine::notificationsEnabledOption', ); $this->notificationsEnabledOption = $notificationsEnabledOption; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Model/HostSeverity.php
centreon/src/Centreon/Domain/HostConfiguration/Model/HostSeverity.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Model; use Centreon\Domain\Common\Assertion\Assertion; use Centreon\Domain\Media\Model\Image; /** * This class is designed to represent a host severity. * * @package Centreon\Domain\HostConfiguration\Model */ class HostSeverity { public const MAX_NAME_LENGTH = 200; public const MIN_NAME_LENGTH = 1; public const MAX_ALIAS_LENGTH = 200; public const MIN_ALIAS_LENGTH = 1; public const MAX_COMMENTS_LENGTH = 65535; public const MAX_LEVEL_NUMBER = 127; public const MIN_LEVEL_NUMBER = -128; /** @var int|null */ private $id; /** @var string Define a short name for this severity. It will be displayed with this name in the ACL configuration. */ private $name; /** @var string longer description of this severity */ private $alias; /** @var int priority */ private $level; /** @var Image define the image that should be associated with this severity */ private $icon; /** @var string|null comments regarding this severity */ private $comments; /** @var bool Indicates whether this host severity is enabled or not (TRUE by default) */ private $isActivated = true; /** * @param string $name * @param string $alias * @param int $level * @param Image $icon * @throws \Assert\AssertionFailedException */ public function __construct(string $name, string $alias, int $level, Image $icon) { $this->setName($name); $this->setAlias($alias); $this->setLevel($level); $this->setIcon($icon); } /** * @return int|null */ public function getId(): ?int { return $this->id; } /** * @param int $id * @return HostSeverity */ public function setId(int $id): HostSeverity { $this->id = $id; return $this; } /** * @return string */ public function getName(): string { return $this->name; } /** * @param string $name * @throws \Assert\AssertionFailedException * @return HostSeverity */ public function setName(string $name): HostSeverity { Assertion::maxLength($name, self::MAX_NAME_LENGTH, 'HostSeverity::name'); Assertion::minLength($name, self::MIN_NAME_LENGTH, 'HostSeverity::name'); $this->name = $name; return $this; } /** * @return string */ public function getAlias(): string { return $this->alias; } /** * @param string $alias * @throws \Assert\AssertionFailedException * @return HostSeverity */ public function setAlias(string $alias): HostSeverity { Assertion::maxLength($alias, self::MAX_ALIAS_LENGTH, 'HostSeverity::alias'); Assertion::minLength($alias, self::MIN_ALIAS_LENGTH, 'HostSeverity::alias'); $this->alias = $alias; return $this; } /** * @return bool */ public function isActivated(): bool { return $this->isActivated; } /** * @param bool $isActivated * @return HostSeverity */ public function setActivated(bool $isActivated): HostSeverity { $this->isActivated = $isActivated; return $this; } /** * @return int */ public function getLevel(): int { return $this->level; } /** * @param int $level * @throws \Assert\AssertionFailedException * @return HostSeverity */ public function setLevel(int $level): HostSeverity { Assertion::min($level, self::MIN_LEVEL_NUMBER, 'HostSeverity::level'); Assertion::max($level, self::MAX_LEVEL_NUMBER, 'HostSeverity::level'); $this->level = $level; return $this; } /** * @return Image */ public function getIcon(): Image { return $this->icon; } /** * @param Image $icon * @return $this */ public function setIcon(Image $icon): HostSeverity { $this->icon = $icon; return $this; } /** * @return string|null */ public function getComments(): ?string { return $this->comments; } /** * @param string|null $comments * @throws \Assert\AssertionFailedException * @return HostSeverity */ public function setComments(?string $comments): HostSeverity { if ($comments !== null) { Assertion::maxLength($comments, self::MAX_COMMENTS_LENGTH, 'HostSeverity::comments'); } $this->comments = $comments; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Model/HostGroup.php
centreon/src/Centreon/Domain/HostConfiguration/Model/HostGroup.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Model; use Centreon\Domain\Common\Assertion\Assertion; use Centreon\Domain\Media\Model\Image; /** * This class is designed to represent a host group. * * @package Centreon\Domain\HostConfiguration\Model */ class HostGroup { public const MAX_NAME_LENGTH = 200; public const MAX_ALIAS_LENGTH = 200; public const MAX_GEO_COORDS_LENGTH = 32; public const MAX_COMMENTS_LENGTH = 65535; /** @var int|null */ private $id; /** @var string */ private $name; /** @var string|null */ private $alias; /** * @var Image|null Define the image that should be associated with this host group. * This image will be displayed in the various places. The image will look best if it is 40x40 pixels in size. */ private $icon; /** * @var string|null Geographical coordinates use by Centreon Map module to position element on map. <br> * Define "Latitude,Longitude", for example for Paris coordinates set "48.51,2.20" */ private $geoCoords; /** @var string|null comments on this host group */ private $comment; /** @var bool indicates whether the host group is activated or not */ private $isActivated = true; /** * @param string $name Host Group name * @throws \Assert\AssertionFailedException */ public function __construct(string $name) { $this->setName($name); } /** * @return int|null */ public function getId(): ?int { return $this->id; } /** * @param int $id * @return HostGroup */ public function setId(int $id): HostGroup { $this->id = $id; return $this; } /** * @return string */ public function getName(): string { return $this->name; } /** * @param string $name * @throws \Assert\AssertionFailedException * @return HostGroup */ public function setName(string $name): HostGroup { Assertion::maxLength($name, self::MAX_NAME_LENGTH, 'HostGroup::name'); $this->name = $name; return $this; } /** * @return string|null */ public function getAlias(): ?string { return $this->alias; } /** * @param string|null $alias * @throws \Assert\AssertionFailedException * @return HostGroup */ public function setAlias(?string $alias): HostGroup { if ($alias !== null) { Assertion::maxLength($alias, self::MAX_ALIAS_LENGTH, 'HostGroup::alias'); } $this->alias = $alias; return $this; } /** * @return Image|null */ public function getIcon(): ?Image { return $this->icon; } /** * @param Image|null $icon * @return HostGroup */ public function setIcon(?Image $icon): HostGroup { $this->icon = $icon; return $this; } /** * @return string|null */ public function getGeoCoords(): ?string { return $this->geoCoords; } /** * @param string|null $geoCoords * @throws \Assert\AssertionFailedException * @return HostGroup */ public function setGeoCoords(?string $geoCoords): HostGroup { if ($geoCoords !== null) { Assertion::maxLength($geoCoords, self::MAX_GEO_COORDS_LENGTH, 'HostGroup::geoCoords'); } $this->geoCoords = $geoCoords; return $this; } /** * @return string|null */ public function getComment(): ?string { return $this->comment; } /** * @param string|null $comment * @throws \Assert\AssertionFailedException * @return HostGroup */ public function setComment(?string $comment): HostGroup { if ($comment !== null) { Assertion::maxLength($comment, self::MAX_COMMENTS_LENGTH, 'HostGroup::comment'); } $this->comment = $comment; return $this; } /** * @return bool */ public function isActivated(): bool { return $this->isActivated; } /** * @param bool $isActivated * @return HostGroup */ public function setActivated(bool $isActivated): HostGroup { $this->isActivated = $isActivated; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Model/HostTemplate.php
centreon/src/Centreon/Domain/HostConfiguration/Model/HostTemplate.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Model; use Centreon\Domain\Common\Assertion\Assertion; use Centreon\Domain\HostConfiguration\Exception\HostTemplateArgumentException; use Centreon\Domain\Media\Model\Image; /** * This class is designed to represent a host template. * * @package Centreon\Domain\HostConfiguration */ class HostTemplate { public const STATUS_ENABLE = 1; public const STATUS_DISABLE = 0; public const STATUS_DEFAULT = 2; public const NOTIFICATION_OPTION_DOWN = 1; public const NOTIFICATION_OPTION_UNREACHABLE = 2; public const NOTIFICATION_OPTION_RECOVERY = 4; public const NOTIFICATION_OPTION_FLAPPING = 8; public const NOTIFICATION_OPTION_DOWNTIME_SCHEDULED = 16; public const STALKING_OPTION_UP = 1; public const STALKING_OPTION_DOWN = 2; public const STALKING_OPTION_UNREACHABLE = 4; public const MAX_NAME_LENGTH = 200; public const MAX_ALIAS_LENGTH = 200; public const MAX_DISPLAY_NAME_LENGTH = 255; public const MAX_ADDRESS_LENGTH = 255; public const MAX_COMMENTS_LENGTH = 65535; public const MAX_SNMP_COMMUNITY_LENGTH = 255; public const MAX_ALTERNATIF_ICON_TEXT = 200; public const MAX_URL_NOTES = 65535; public const MAX_ACTION_URL = 65535; public const MAX_NOTES = 65535; public const MIN_CHECK_ATTEMPS = 1; public const MIN_CHECK_INTERVAL = 1; public const MIN_RETRY_CHECK_INTERVAL = 1; public const MIN_NOTIFICATION_INTERVAL = 0; public const MIN_FIRST_NOTIFICATION_DELAY = 0; public const MIN_RECOVERY_NOTIFICATION_DELAY = 0; private const AVAILABLE_STATUS = [ self::STATUS_ENABLE, self::STATUS_DISABLE, self::STATUS_DEFAULT, ]; /** @var int|null */ private $id; /** @var string|null */ private $name; /** @var string|null */ private $alias; /** @var string|null Display name */ private $displayName; /** @var string|null */ private $address; /** @var string|null */ private $comment; /** @var int[] Host template parent ids */ private $parentIds = []; /** @var bool indicates whether the host template is activated or not */ private $isActivated = true; /** @var bool indicates whether the configuration is locked for editing or not */ private $isLocked = false; /** @var int Enable or disable active checks. By default active host checks are enabled. */ private $activeChecksStatus = self::STATUS_DEFAULT; /** @var int Enable or disable passive checks here. When disabled submitted states will be not accepted. */ private $passiveChecksStatus = self::STATUS_DEFAULT; /** * @var int|null Number of checks before considering verified state (HARD).<br> * Define the number of times that monitoring engine will retry the host check command if it returns any non-OK * state.<br> * Setting this value to 1 will cause monitoring engine to generate an alert immediately.<br> * <b>Note: If you do not want to check the status of the host, you must still set this to a minimum value of 1. * <br> * To bypass the host check, just leave the check command option blank.</b> */ private $maxCheckAttempts; /** * @var int|null Define the number of "time units" between regularly scheduled checks of the host.<br> * With the default time unit of 60s, this number will mean multiples of 1 minute. */ private $checkInterval; /** * @var int|null Define the number of "time units" to wait before scheduling a re-check for this host after a * non-UP state was detected.<br> * With the default time unit of 60s, this number will mean multiples of 1 minute.<br> * Once the host has been retried max_check_attempts times without a change in its status, * it will revert to being scheduled at its "normal" check interval rate. */ private $retryCheckInterval; /** @var int specify whether or not notifications for this host are enabled */ private $notificationsStatus = self::STATUS_DEFAULT; /** * @var int|null Define the number of "time units" to wait before re-notifying a contact that this host is still * down or unreachable.<br> * With the default time unit of 60s, this number will mean multiples of 1 minute.<br> * A value of 0 disables re-notifications of contacts about problems for this host - only one problem notification * will be sent out. */ private $notificationInterval; /** * @var int|null Define the number of "time units" to wait before sending out the first problem notification when * this host enters a non-UP state.<br> * With the default time unit of 60s, this number will mean multiples of 1 minute.<br> * If you set this value to 0, monitoring engine will start sending out notifications immediately. */ private $firstNotificationDelay; /** * @var int|null Define the number of "time units" to wait before sending out the recovery notification when this * host enters an UP state.<br> * With the default time unit of 60s, this number will mean multiples of 1 minute.<br> * If you set this value to 0, monitoring engine will start sending out notifications immediately. */ private $recoveryNotificationDelay; /** * @var int Define the states of the host for which notifications should be sent out.<br> * If you specify None as an option, no host notifications will be sent out.<br> * If you do not specify any notification options, monitoring engine will assume that you want notifications to be * sent out for all possible states.<br> * <b>Sets to 0 to define not options.</b> * * @see HostTemplate::NOTIFICATION_OPTION_DOWN * @see HostTemplate::NOTIFICATION_OPTION_UNREACHABLE * @see HostTemplate::NOTIFICATION_OPTION_RECOVERY * @see HostTemplate::NOTIFICATION_OPTION_FLAPPING * @see HostTemplate::NOTIFICATION_OPTION_DOWNTIME_SCHEDULED */ private $notificationOptions = 0; /** @var string|null community of the SNMP agent */ private $snmpCommunity; /** @var string|null version of the SNMP agent */ private $snmpVersion; /** @var Image|null define the image that should be associated with this template */ private $icon; /** @var string|null define an optional string that is used in the alternative description of the icon image */ private $alternativeIcon; /** * @var Image|null define an image that should be associated with this host template in the statusmap CGI in * monitoring engine */ private $statusMapImage; /** * @var string|null Define an optional URL that can be used to provide more information about the host. * <br> * This can be very useful if you want to make detailed information on the host template, emergency contact methods, * etc. available to other support staff.<br> * Any valid URL can be used. */ private $urlNotes; /** @var string|null define an optional URL that can be used to provide more actions to be performed on the host */ private $actionUrl; /** @var string|null define an optional notes */ private $notes; /** * @var int this directive determines which host states "stalking" is enabled for * * @see HostTemplate::STALKING_OPTION_UP * @see HostTemplate::STALKING_OPTION_DOWN * @see HostTemplate::STALKING_OPTION_UNREACHABLE */ private $stalkingOptions = 0; /** * @return int|null */ public function getId(): ?int { return $this->id; } /** * @param int|null $id * @return self */ public function setId(?int $id): self { $this->id = $id; return $this; } /** * @return string|null */ public function getName(): ?string { return $this->name; } /** * @param string|null $name * @throws \Assert\AssertionFailedException * @return self */ public function setName(?string $name): self { if ($name !== null) { Assertion::maxLength($name, self::MAX_NAME_LENGTH, 'HostTemplate::name'); } $this->name = $name; return $this; } /** * @return string|null */ public function getAlias(): ?string { return $this->alias; } /** * @param string|null $alias * @throws \Assert\AssertionFailedException * @return self */ public function setAlias(?string $alias): self { if ($alias !== null) { Assertion::maxLength($alias, self::MAX_ALIAS_LENGTH, 'HostTemplate::alias'); } $this->alias = $alias; return $this; } /** * @return string|null */ public function getDisplayName(): ?string { return $this->displayName; } /** * @param string|null $displayName * @throws \Assert\AssertionFailedException * @return self */ public function setDisplayName(?string $displayName): self { if ($displayName !== null) { Assertion::maxLength($displayName, self::MAX_DISPLAY_NAME_LENGTH, 'HostTemplate::displayName'); } $this->displayName = $displayName; return $this; } /** * @return string|null */ public function getAddress(): ?string { return $this->address; } /** * @param string|null $address * @throws \Assert\AssertionFailedException * @return self */ public function setAddress(?string $address): self { if ($address !== null) { Assertion::maxLength($address, self::MAX_ADDRESS_LENGTH, 'HostTemplate::address'); } $this->address = $address; return $this; } /** * @return string|null */ public function getComment(): ?string { return $this->comment; } /** * @param string|null $comment * @throws \Assert\AssertionFailedException * @return self */ public function setComment(?string $comment): self { if ($comment !== null) { Assertion::maxLength($comment, self::MAX_COMMENTS_LENGTH, 'HostTemplate::comment'); } $this->comment = $comment; return $this; } /** * @return int[] */ public function getParentIds(): array { return $this->parentIds; } /** * @param string[]|int[] $parentIds * @return HostTemplate */ public function setParentIds(array $parentIds): HostTemplate { $parentIds = filter_var_array($parentIds, FILTER_VALIDATE_INT); if (is_array($parentIds)) { $this->parentIds = array_values( array_filter( $parentIds, function ($value) { return is_int($value); } ) ); } return $this; } /** * @return bool */ public function isActivated(): bool { return $this->isActivated; } /** * @param bool $isActivated * @return self */ public function setActivated(bool $isActivated): self { $this->isActivated = $isActivated; return $this; } /** * @return bool */ public function isLocked(): bool { return $this->isLocked; } /** * @param bool $isLocked * @return HostTemplate */ public function setLocked(bool $isLocked): HostTemplate { $this->isLocked = $isLocked; return $this; } /** * @return int */ public function getActiveChecksStatus(): int { return $this->activeChecksStatus; } /** * @param int $activeChecksStatus * @return HostTemplate */ public function setActiveChecksStatus(int $activeChecksStatus): HostTemplate { if (! in_array($activeChecksStatus, self::AVAILABLE_STATUS)) { throw HostTemplateArgumentException::badActiveChecksStatus($activeChecksStatus); } $this->activeChecksStatus = $activeChecksStatus; return $this; } /** * @return int */ public function getPassiveChecksStatus(): int { return $this->passiveChecksStatus; } /** * @param int $passiveChecksStatus * @return HostTemplate */ public function setPassiveChecksStatus(int $passiveChecksStatus): HostTemplate { if (! in_array($passiveChecksStatus, self::AVAILABLE_STATUS)) { throw HostTemplateArgumentException::badPassiveChecksStatus($passiveChecksStatus); } $this->passiveChecksStatus = $passiveChecksStatus; return $this; } /** * @return int|null */ public function getMaxCheckAttempts(): ?int { return $this->maxCheckAttempts; } /** * @param int|null $maxCheckAttempts * @throws \Assert\AssertionFailedException * @return HostTemplate */ public function setMaxCheckAttempts(?int $maxCheckAttempts): HostTemplate { if ($maxCheckAttempts !== null) { Assertion::min($maxCheckAttempts, self::MIN_CHECK_ATTEMPS, 'HostTemplate::maxCheckAttempts'); } $this->maxCheckAttempts = $maxCheckAttempts; return $this; } /** * @return int|null */ public function getCheckInterval(): ?int { return $this->checkInterval; } /** * @param int|null $checkInterval * @throws \Assert\AssertionFailedException * @return HostTemplate */ public function setCheckInterval(?int $checkInterval): HostTemplate { if ($checkInterval !== null) { Assertion::min($checkInterval, self::MIN_CHECK_INTERVAL, 'HostTemplate::checkInterval'); } $this->checkInterval = $checkInterval; return $this; } /** * @return int|null */ public function getRetryCheckInterval(): ?int { return $this->retryCheckInterval; } /** * @param int|null $retryCheckInterval * @throws \Assert\AssertionFailedException * @return HostTemplate */ public function setRetryCheckInterval(?int $retryCheckInterval): HostTemplate { if ($retryCheckInterval !== null) { Assertion::min($retryCheckInterval, self::MIN_RETRY_CHECK_INTERVAL, 'HostTemplate::retryCheckInterval'); } $this->retryCheckInterval = $retryCheckInterval; return $this; } /** * @return int */ public function getNotificationsStatus(): int { return $this->notificationsStatus; } /** * @param int $notificationsStatus * @return HostTemplate */ public function setNotificationsStatus(int $notificationsStatus): HostTemplate { if (! in_array($notificationsStatus, self::AVAILABLE_STATUS)) { HostTemplateArgumentException::badNotificationStatus($notificationsStatus); } $this->notificationsStatus = $notificationsStatus; return $this; } /** * @return int|null */ public function getNotificationInterval(): ?int { return $this->notificationInterval; } /** * @param int|null $notificationInterval * @throws \Assert\AssertionFailedException * @return HostTemplate */ public function setNotificationInterval(?int $notificationInterval): HostTemplate { if ($notificationInterval !== null) { Assertion::greaterOrEqualThan( $notificationInterval, self::MIN_NOTIFICATION_INTERVAL, 'HostTemplate::notificationInterval' ); } $this->notificationInterval = $notificationInterval; return $this; } /** * @return int|null */ public function getFirstNotificationDelay(): ?int { return $this->firstNotificationDelay; } /** * @param int|null $firstNotificationDelay * @throws \Assert\AssertionFailedException * @return HostTemplate */ public function setFirstNotificationDelay(?int $firstNotificationDelay): HostTemplate { if ($firstNotificationDelay !== null) { Assertion::greaterOrEqualThan( $firstNotificationDelay, self::MIN_FIRST_NOTIFICATION_DELAY, 'HostTemplate::firstNotificationDelay' ); } $this->firstNotificationDelay = $firstNotificationDelay; return $this; } /** * @return int|null */ public function getRecoveryNotificationDelay(): ?int { return $this->recoveryNotificationDelay; } /** * @param int|null $recoveryNotificationDelay * @throws \Assert\AssertionFailedException * @return HostTemplate */ public function setRecoveryNotificationDelay(?int $recoveryNotificationDelay): HostTemplate { if ($recoveryNotificationDelay !== null) { Assertion::greaterOrEqualThan( $recoveryNotificationDelay, self::MIN_RECOVERY_NOTIFICATION_DELAY, 'HostTemplate::recoveryNotificationDelay' ); } $this->recoveryNotificationDelay = $recoveryNotificationDelay; return $this; } /** * @return int */ public function getNotificationOptions(): int { return $this->notificationOptions; } /** * @param int $notificationOptions * @throws \InvalidArgumentException * @return HostTemplate */ public function setNotificationOptions(int $notificationOptions): HostTemplate { $sumOfAllOptions = HostTemplate::NOTIFICATION_OPTION_DOWN | HostTemplate::NOTIFICATION_OPTION_UNREACHABLE | HostTemplate::NOTIFICATION_OPTION_RECOVERY | HostTemplate::NOTIFICATION_OPTION_FLAPPING | HostTemplate::NOTIFICATION_OPTION_DOWNTIME_SCHEDULED; if ($notificationOptions < 0 || ($notificationOptions & $sumOfAllOptions) !== $notificationOptions) { throw HostTemplateArgumentException::badNotificationOptions($notificationOptions); } $this->notificationOptions = $notificationOptions; return $this; } /** * @return string|null */ public function getSnmpCommunity(): ?string { return $this->snmpCommunity; } /** * @param string|null $snmpCommunity * @throws \Assert\AssertionFailedException * @return HostTemplate */ public function setSnmpCommunity(?string $snmpCommunity): HostTemplate { if ($snmpCommunity !== null) { Assertion::maxLength($snmpCommunity, self::MAX_SNMP_COMMUNITY_LENGTH, 'HostTemplate::snmpCommunity'); } $this->snmpCommunity = $snmpCommunity; return $this; } /** * @return string|null */ public function getSnmpVersion(): ?string { return $this->snmpVersion; } /** * @param string|null $snmpVersion the SNMP versions available are 1, 2c and 3 * @throws \InvalidArgumentException * @return HostTemplate */ public function setSnmpVersion(?string $snmpVersion): HostTemplate { if ($snmpVersion !== null) { $this->snmpVersion = in_array($snmpVersion, ['1', '2c', '3']) ? $snmpVersion : null; } return $this; } /** * @return Image|null */ public function getIcon(): ?Image { return $this->icon; } /** * @param Image|null $icon * @return HostTemplate */ public function setIcon(?Image $icon): HostTemplate { $this->icon = $icon; return $this; } /** * @return string|null */ public function getAlternativeIcon(): ?string { return $this->alternativeIcon; } /** * @param string|null $alternativeIcon * @throws \Assert\AssertionFailedException * @return HostTemplate */ public function setAlternativeIcon(?string $alternativeIcon): HostTemplate { if ($alternativeIcon !== null) { Assertion::maxLength($alternativeIcon, self::MAX_ALTERNATIF_ICON_TEXT, 'HostTemplate::alternativeIcon'); } $this->alternativeIcon = $alternativeIcon; return $this; } /** * @return Image|null */ public function getStatusMapImage(): ?Image { return $this->statusMapImage; } /** * @param Image|null $statusMapImage * @return HostTemplate */ public function setStatusMapImage(?Image $statusMapImage): HostTemplate { $this->statusMapImage = $statusMapImage; return $this; } /** * @return string|null */ public function getUrlNotes(): ?string { return $this->urlNotes; } /** * @param string|null $urlNotes * @throws \Assert\AssertionFailedException * @return HostTemplate */ public function setUrlNotes(?string $urlNotes): HostTemplate { if ($urlNotes !== null) { Assertion::maxLength($urlNotes, self::MAX_URL_NOTES, 'HostTemplate::urlNotes'); } $this->urlNotes = $urlNotes; return $this; } /** * @return string|null */ public function getActionUrl(): ?string { return $this->actionUrl; } /** * @param string|null $actionUrl * @throws \Assert\AssertionFailedException * @return HostTemplate */ public function setActionUrl(?string $actionUrl): HostTemplate { if ($actionUrl !== null) { Assertion::maxLength($actionUrl, self::MAX_ACTION_URL, 'HostTemplate::actionUrl'); } $this->actionUrl = $actionUrl; return $this; } /** * @return string|null */ public function getNotes(): ?string { return $this->notes; } /** * @param string|null $notes * @throws \Assert\AssertionFailedException * @return HostTemplate */ public function setNotes(?string $notes): HostTemplate { if ($notes !== null) { Assertion::maxLength($notes, self::MAX_NOTES, 'HostTemplate::notes'); } $this->notes = $notes; return $this; } /** * @return int */ public function getStalkingOptions(): ?int { return $this->stalkingOptions; } /** * @param int $stalkingOptions * @throws \InvalidArgumentException * @return HostTemplate */ public function setStalkingOptions(int $stalkingOptions): HostTemplate { $sumOfAllOptions = HostTemplate::STALKING_OPTION_UP | HostTemplate::STALKING_OPTION_DOWN | HostTemplate::STALKING_OPTION_UNREACHABLE; if ($stalkingOptions < 0 || ($stalkingOptions & $sumOfAllOptions) !== $stalkingOptions) { throw HostTemplateArgumentException::badStalkingOptions($stalkingOptions); } $this->stalkingOptions = $stalkingOptions; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Model/HostCategory.php
centreon/src/Centreon/Domain/HostConfiguration/Model/HostCategory.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Model; use Centreon\Domain\Common\Assertion\Assertion; /** * This class is designed to represent a host category. * * @package Centreon\Domain\HostConfiguration\Model */ class HostCategory { public const MAX_NAME_LENGTH = 200; public const MIN_NAME_LENGTH = 1; public const MAX_ALIAS_LENGTH = 200; public const MIN_ALIAS_LENGTH = 1; public const MAX_COMMENTS_LENGTH = 65535; /** @var int|null */ private $id; /** @var string Define a short name for this category. It will be displayed with this name in the ACL configuration. */ private $name; /** @var string longer description of this category */ private $alias; /** @var string|null comments regarding this category */ private $comments; /** @var bool Indicates whether this host category is enabled or not (TRUE by default) */ private $isActivated = true; /** * @param string $name Name of the host category * @param string $alias Alias of the host category * @throws \Assert\AssertionFailedException */ public function __construct(string $name, string $alias) { $this->setName($name); $this->setAlias($alias); } /** * @return int|null */ public function getId(): ?int { return $this->id; } /** * @param int $id * @return HostCategory */ public function setId(int $id): HostCategory { $this->id = $id; return $this; } /** * @return string */ public function getName(): string { return $this->name; } /** * @param string $name * @throws \Assert\AssertionFailedException * @return HostCategory */ public function setName(string $name): HostCategory { Assertion::minLength($name, self::MIN_NAME_LENGTH, 'HostCategory::name'); Assertion::maxLength($name, self::MAX_NAME_LENGTH, 'HostCategory::name'); $this->name = $name; return $this; } /** * @return string */ public function getAlias(): string { return $this->alias; } /** * @param string $alias * @throws \Assert\AssertionFailedException * @return HostCategory */ public function setAlias(string $alias): HostCategory { Assertion::minLength($alias, self::MIN_ALIAS_LENGTH, 'HostCategory::alias'); Assertion::maxLength($alias, self::MAX_ALIAS_LENGTH, 'HostCategory::alias'); $this->alias = $alias; return $this; } /** * @return bool */ public function isActivated(): bool { return $this->isActivated; } /** * @param bool $isActivated * @return HostCategory */ public function setActivated(bool $isActivated): HostCategory { $this->isActivated = $isActivated; return $this; } /** * @return string|null */ public function getComments(): ?string { return $this->comments; } /** * @param string|null $comments * @throws \Assert\AssertionFailedException * @return HostCategory */ public function setComments(?string $comments): HostCategory { if ($comments !== null) { Assertion::maxLength($comments, self::MAX_COMMENTS_LENGTH, 'HostCategory::comments'); } $this->comments = $comments; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostConfigurationServiceInterface.php
centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostConfigurationServiceInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Interfaces; use Centreon\Domain\HostConfiguration\Exception\HostConfigurationServiceException; use Centreon\Domain\HostConfiguration\Host; use Centreon\Domain\HostConfiguration\HostConfigurationException; use Centreon\Domain\HostConfiguration\HostMacro; interface HostConfigurationServiceInterface { /** * Add a host. * * @param Host $host * @throws HostConfigurationServiceException */ public function addHost(Host $host): void; /** * Find a host. * * @param int $hostId Host Id to be found * @throws HostConfigurationException * @return Host|null Returns a host otherwise null */ public function findHost(int $hostId): ?Host; /** * Returns the number of host. * * @throws HostConfigurationException * @return int Number of host */ public function getNumberOfHosts(): int; /** * Find host templates recursively. * * **The priority order of host templates is maintained!** * * @param Host $host Host for which we want to find all host templates recursively * @throws HostConfigurationException * @return Host[] */ public function findHostTemplatesRecursively(Host $host): array; /** * Find the command of a host. * A recursive search will be performed in the inherited templates in the * case where the host does not have a command. * * @param int $hostId Host id * @throws HostConfigurationException * @return string|null Return the command if found */ public function findCommandLine(int $hostId): ?string; /** * Find all host macros for the host. * * @param int $hostId Id of the host * @param bool $isUsingInheritance Indicates whether to use inheritance to find host macros (FALSE by default) * @throws HostConfigurationException * @return HostMacro[] List of host macros found */ public function findOnDemandHostMacros(int $hostId, bool $isUsingInheritance = false): array; /** * Find all on-demand host macros needed for this command. * * @param int $hostId Host id * @param string $command Command to analyse * @throws HostConfigurationException * @return HostMacro[] List of host macros */ public function findHostMacrosFromCommandLine(int $hostId, string $command): array; /** * Change the activation status of host. * * @param Host $host Host for which we want to change the activation status * @param bool $shouldBeActivated TRUE to activate a host * @throws HostConfigurationException */ public function changeActivationStatus(Host $host, bool $shouldBeActivated): void; /** * Find host names already used by hosts. * * @param string[] $namesToCheck List of names to find * @throws HostConfigurationException * @return string[] Return the host names found */ public function findHostNamesAlreadyUsed(array $namesToCheck): array; /** * Update a host. * * @param Host $host * @throws HostConfigurationServiceException */ public function updateHost(Host $host): void; /** * Find host templates by host id (non recursive) * * **The priority order of host templates is maintained!** * * @param Host $host * @return Host[] */ public function findHostTemplatesByHost(Host $host): array; /** * Find a host by its name * * @param string $hostName Host name to be found * @throws HostConfigurationException * @return Host|null Returns a host otherwise null */ public function findHostByName(string $hostName): ?Host; /** * Find a host template by its id * * @param int $hostTemplateId * @return Host|null */ public function findHostTemplate(int $hostTemplateId): ?Host; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostConfigurationRepositoryInterface.php
centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostConfigurationRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Interfaces; /** * This interface gathers all the writing and reading operations on the repository * * @package Centreon\Domain\HostConfiguration\Interfaces */ interface HostConfigurationRepositoryInterface extends HostConfigurationReadRepositoryInterface, HostConfigurationWriteRepositoryInterface { }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostConfigurationReadRepositoryInterface.php
centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostConfigurationReadRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Interfaces; use Centreon\Domain\HostConfiguration\Host; use Centreon\Domain\HostConfiguration\HostMacro; /** * This interface gathers all the reading operations on the repository. * * @package Centreon\Domain\HostConfiguration\Interfaces */ interface HostConfigurationReadRepositoryInterface { /** * Find a host. * * @param int $hostId Host Id to be found * @throws \Throwable * @return Host|null Returns a host otherwise null */ public function findHost(int $hostId): ?Host; /** * Recursively find all host templates. * * **The priority order of host templates is maintained!** * * @param Host $host Host for which we want to find all host templates recursively * @throws \Throwable * @return Host[] */ public function findHostTemplatesRecursively(Host $host): array; /** * Indicates if a hostname is already in use. * * @param string $hostName Hostname to be found * @return bool True if the hostname is already in use */ public function hasHostWithSameName(string $hostName): bool; /** * Returns the number of hosts. * * @return int Number of hosts */ public function getNumberOfHosts(): int; /** * Find the command of a host. * * Recursively search in the inherited templates if no result found. * * @param int $hostId Host id * @throws \Throwable * @return string|null Return the command if found */ public function findCommandLine(int $hostId): ?string; /** * Find all host macros for the host. * * @param int $hostId Id of the host * @param bool $isUsingInheritance Indicates whether to use inheritance to find host macros (FALSE by default) * @throws \Throwable * @return array<HostMacro> List of host macros found */ public function findOnDemandHostMacros(int $hostId, bool $isUsingInheritance = false): array; /** * Find host names already used by hosts. * * @param string[] $namesToCheck List of names to find * @return string[] Return the host names found */ public function findHostNamesAlreadyUsed(array $namesToCheck): array; /** * Find a host regarding user ACL * * @param int $hostId * @param int[] $accessGroupIds * @throws \Throwable * @return Host|null */ public function findHostByAccessGroupIds(int $hostId, array $accessGroupIds): ?Host; /** * Find host templates linked to a host (non recursive) * * **The priority order of host templates is maintained!** * * @param Host $host * @return Host[] */ public function findHostTemplatesByHost(Host $host): array; /** * Find a host by its name. * * @param string $hostName Host Id to be found * @throws \Throwable * @return Host|null Returns a host otherwise null */ public function findHostByName(string $hostName): ?Host; /** * Find host template by its id * * @param int $hostTemplateId * @throws \Throwable * @return Host|null */ public function findHostTemplate(int $hostTemplateId): ?Host; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostConfigurationWriteRepositoryInterface.php
centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostConfigurationWriteRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Interfaces; use Centreon\Domain\HostConfiguration\Host; use Centreon\Domain\Repository\RepositoryException; /** * This interface gathers all the writing operations on the repository. * * @package Centreon\Domain\HostConfiguration\Interfaces */ interface HostConfigurationWriteRepositoryInterface { /** * Add a host * * @param Host $host Host to add * @throws RepositoryException * @throws \Throwable */ public function addHost(Host $host): void; /** * Update a host. * * @param Host $host * @throws \Throwable */ public function updateHost(Host $host): void; /** * Change the activation status of host. * * @param int $hostId Host id for which we want to change the activation status * @param bool $shouldBeActivated TRUE to activate a host */ public function changeActivationStatus(int $hostId, bool $shouldBeActivated): void; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostCategory/HostCategoryReadRepositoryInterface.php
centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostCategory/HostCategoryReadRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Interfaces\HostCategory; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\HostConfiguration\Host; use Centreon\Domain\HostConfiguration\Model\HostCategory; /** * This interface gathers all the reading operations on the host category repository. * * @package Centreon\Domain\HostConfiguration\Interfaces */ interface HostCategoryReadRepositoryInterface { /** * Find a host category by id. * * @param int $categoryId Id of the host category to be found * @throws \Throwable * @return HostCategory|null */ public function findById(int $categoryId): ?HostCategory; /** * Find a host category by id and contact. * * @param int $categoryId Id of the host category to be found * @param ContactInterface $contact Contact related to host category * @throws \Throwable * @return HostCategory|null */ public function findByIdAndContact(int $categoryId, ContactInterface $contact): ?HostCategory; /** * Find host categories by name (for admin user). * * @param string[] $categoriesName List of names of host categories to be found * @throws \Throwable * @return HostCategory[] */ public function findByNames(array $categoriesName): array; /** * Find host categories by host. * * @param Host $host * @return HostCategory[] */ public function findAllByHost(Host $host): array; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostCategory/HostCategoryWriteRepositoryInterface.php
centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostCategory/HostCategoryWriteRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Interfaces\HostCategory; use Centreon\Domain\HostConfiguration\Model\HostCategory; /** * This interface gathers all the writing operations on the host category repository. * * @package Centreon\Domain\HostConfiguration\Interfaces\HostCategory */ interface HostCategoryWriteRepositoryInterface { /** * Add a host category. * * @param HostCategory $category Host category to be added * @throws \Throwable */ public function addCategory(HostCategory $category): void; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostCategory/HostCategoryServiceInterface.php
centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostCategory/HostCategoryServiceInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Interfaces\HostCategory; use Centreon\Domain\HostConfiguration\Exception\HostCategoryException; use Centreon\Domain\HostConfiguration\Model\HostCategory; /** * @package Centreon\Domain\HostConfiguration\Interfaces\HostCategory */ interface HostCategoryServiceInterface { /** * Add a host category. * * @param HostCategory $category Host category to be added * @throws HostCategoryException */ public function addCategory(HostCategory $category): void; /** * Find a host category (for non admin user). * * @param int $categoryId Id of the host category to be found * @throws HostCategoryException * @return HostCategory|null */ public function findWithAcl(int $categoryId): ?HostCategory; /** * Find a host category (for admin user). * * @param int $categoryId Id of the host category to be found * @throws HostCategoryException * @return HostCategory|null */ public function findWithoutAcl(int $categoryId): ?HostCategory; /** * Find host categories by name (for admin user). * * @param string[] $categoriesName List of names of host categories to be found * @throws HostCategoryException * @return HostCategory[] */ public function findByNamesWithoutAcl(array $categoriesName): array; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostMacro/HostMacroReadRepositoryInterface.php
centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostMacro/HostMacroReadRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Interfaces\HostMacro; use Centreon\Domain\HostConfiguration\Host; use Centreon\Domain\HostConfiguration\HostMacro; /** * This interface gathers all the reading operations on the repository. * * @package Centreon\Domain\HostConfiguration\Interfaces\HostMacro */ interface HostMacroReadRepositoryInterface { /** * Find all macros linked to a host. * * @param Host $host * @return HostMacro[] */ public function findAllByHost(Host $host): array; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostMacro/HostMacroServiceInterface.php
centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostMacro/HostMacroServiceInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Interfaces\HostMacro; use Centreon\Domain\HostConfiguration\Exception\HostMacroServiceException; use Centreon\Domain\HostConfiguration\Host; use Centreon\Domain\HostConfiguration\HostMacro; /** * @package Centreon\Domain\HostConfiguration\Interfaces\HostMacro */ interface HostMacroServiceInterface { /** * Add a macro to a host. * * @param Host $host Host linked to host macro to be added * @param HostMacro $hostMacro Host macro to be added * @throws HostMacroServiceException */ public function addMacroToHost(Host $host, HostMacro $hostMacro): void; /** * find all macros of host. * * @param Host $host * @throws HostMacroServiceException * @return HostMacro[] */ public function findHostMacros(Host $host): array; /** * Update a host macro. * * @param HostMacro $macro * @throws HostMacroServiceException */ public function updateMacro(HostMacro $macro): void; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostMacro/HostMacroWriteRepositoryInterface.php
centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostMacro/HostMacroWriteRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Interfaces\HostMacro; use Centreon\Domain\HostConfiguration\Host; use Centreon\Domain\HostConfiguration\HostMacro; /** * This interface gathers all the writing operations on the repository. * * @package Centreon\Domain\HostConfiguration\Interfaces\HostMacro */ interface HostMacroWriteRepositoryInterface { /** * Add a host macro to a host. * * @param Host $host Host linked to host macro to be added * @param HostMacro $hostMacro Host macro to be added * @throws \Throwable */ public function addMacroToHost(Host $host, HostMacro $hostMacro): void; /** * Update a host macro. * * @param HostMacro $hostMacro * @throws \Throwable */ public function updateMacro(HostMacro $hostMacro): void; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostSeverity/HostSeverityServiceInterface.php
centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostSeverity/HostSeverityServiceInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Interfaces\HostSeverity; use Centreon\Domain\HostConfiguration\Exception\HostSeverityException; use Centreon\Domain\HostConfiguration\Model\HostSeverity; use Centreon\Domain\Repository\RepositoryException; /** * This interface gathers all the reading operations on the host severity repository. * * @package Centreon\Domain\HostConfiguration\Interfaces */ interface HostSeverityServiceInterface { /** * Find a host severity (for admin user). * * @param int $severityId Id of the host severity to be found * @throws HostSeverityException * @throws RepositoryException * @return HostSeverity|null */ public function findWithoutAcl(int $severityId): ?HostSeverity; /** * Find a host severity (for non admin user). * * @param int $severityId Id of the host severity to be found * @throws HostSeverityException * @throws RepositoryException * @return HostSeverity|null */ public function findWithAcl(int $severityId): ?HostSeverity; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostSeverity/HostSeverityReadRepositoryInterface.php
centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostSeverity/HostSeverityReadRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Interfaces\HostSeverity; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\HostConfiguration\Host; use Centreon\Domain\HostConfiguration\Model\HostSeverity; use Centreon\Domain\Repository\RepositoryException; /** * This interface gathers all the reading operations on the host severity repository. * * @package Centreon\Domain\HostConfiguration\Interfaces */ interface HostSeverityReadRepositoryInterface { /** * Find a host severity by id. * * @param int $hostSeverityId Id of the host severity to be found * @throws RepositoryException * @throws \Exception * @return HostSeverity|null */ public function findById(int $hostSeverityId): ?HostSeverity; /** * Find a host severity by id and contact. * * @param int $hostSeverityId Id of the host severity to be found * @param ContactInterface $contact Contact related to host severity * @throws RepositoryException * @throws \Exception * @return HostSeverity|null */ public function findByIdAndContact(int $hostSeverityId, ContactInterface $contact): ?HostSeverity; /** * Find a host severity by host * * @param Host $host * @return HostSeverity|null */ public function findByHost(Host $host): ?HostSeverity; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostGroup/HostGroupWriteRepositoryInterface.php
centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostGroup/HostGroupWriteRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Interfaces\HostGroup; use Centreon\Domain\HostConfiguration\Model\HostGroup; /** * This interface gathers all the writing operations on the host group repository. * * @package Centreon\Domain\HostConfiguration\Interfaces\HostGroup */ interface HostGroupWriteRepositoryInterface { /** * Add a host group. * * @param HostGroup $group Host group to be added */ public function addGroup(HostGroup $group): void; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostGroup/HostGroupServiceInterface.php
centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostGroup/HostGroupServiceInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Interfaces\HostGroup; use Centreon\Domain\HostConfiguration\Exception\HostGroupException; use Centreon\Domain\HostConfiguration\Model\HostGroup; use Centreon\Domain\Repository\RepositoryException; /** * @package Centreon\Domain\HostConfiguration\Interfaces\HostGroup */ interface HostGroupServiceInterface { /** * Add a host group. * * @param HostGroup $group * @throws HostGroupException */ public function addGroup(HostGroup $group): void; /** * Find host groups by name (for admin user). * * @param string[] $groupsName List of names of host groups to be found * @throws HostGroupException * @return HostGroup[] */ public function findByNamesWithoutAcl(array $groupsName): array; /** * Find a host group (for non admin user). * * @param int $groupId Id of the host group to be found * @throws HostGroupException * @throws RepositoryException * @return HostGroup|null */ public function findWithAcl(int $groupId): ?HostGroup; /** * Find a host group (for admin user). * * @param int $groupId Id of the host group to be found * @throws HostGroupException * @throws RepositoryException * @return HostGroup|null */ public function findWithoutAcl(int $groupId): ?HostGroup; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostGroup/HostGroupReadRepositoryInterface.php
centreon/src/Centreon/Domain/HostConfiguration/Interfaces/HostGroup/HostGroupReadRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Interfaces\HostGroup; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\HostConfiguration\Host; use Centreon\Domain\HostConfiguration\Model\HostGroup; use Centreon\Domain\Repository\RepositoryException; /** * This interface gathers all the reading operations on the host group repository. * * @package Centreon\Domain\HostConfiguration\Interfaces\HostGroup */ interface HostGroupReadRepositoryInterface { /** * Find all host groups linked to a host. * * @param Host $host * @throws \Throwable * @return HostGroup[] */ public function findAllByHost(Host $host): array; /** * Find a host group by id. * * @param int $hostGroupId Id of the host group to be found * @throws RepositoryException * @throws \Exception * @return HostGroup|null */ public function findById(int $hostGroupId): ?HostGroup; /** * Find a host group by id and contact. * * @param int $hostGroupId Id of the host group to be found * @param ContactInterface $contact Contact related to host group * @throws RepositoryException * @throws \Exception * @return HostGroup|null */ public function findByIdAndContact(int $hostGroupId, ContactInterface $contact): ?HostGroup; /** * Find host groups by name (for admin user). * * @param string[] $groupsName List of names of host groups to be found * @return HostGroup[] */ public function findByNames(array $groupsName): array; /** * Find all host groups. * * @return HostGroup[] */ public function findHostGroups(): array; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Exception/HostSeverityException.php
centreon/src/Centreon/Domain/HostConfiguration/Exception/HostSeverityException.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Exception; /** * This class is designed to contain all exceptions for the context of the host severity. * * @package Centreon\Domain\HostConfiguration\Exception */ class HostSeverityException extends \Exception { /** * @param \Throwable $ex * @return self */ public static function findHostSeveritiesException(\Throwable $ex): self { return new self(_('Error when searching for host severities'), 0, $ex); } /** * @param array<string, mixed> $data * @param \Throwable|null $ex * @return self */ public static function findHostSeverityException(array $data = [], ?\Throwable $ex = null): self { return new self( sprintf(_('Error when searching for the host severity (%s)'), $data['id'] ?? $data['name'] ?? null), 0, $ex ); } /** * @param array<string, mixed> $data * @param \Throwable|null $ex * @return self */ public static function notFoundException(array $data = [], ?\Throwable $ex = null): self { return new self( sprintf(_('Host severity (%s) not found'), $data['id'] ?? $data['name'] ?? null), 0, $ex ); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Exception/HostTemplateArgumentException.php
centreon/src/Centreon/Domain/HostConfiguration/Exception/HostTemplateArgumentException.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Exception; /** * This class is designed to contain all exceptions for the context of the host template. * * @package Centreon\Domain\HostConfiguration\Exception */ class HostTemplateArgumentException extends \InvalidArgumentException { /** * @param int $options * @return self */ public static function badNotificationOptions(int $options): self { return new self(sprintf(_('Invalid notification option (%d)'), $options)); } /** * @param int $options * @return self */ public static function badStalkingOptions(int $options): self { return new self(sprintf(_('Invalid stalking option (%d)'), $options)); } /** * @param string $snmpVersion * @return self */ public static function badSnmpVersion(string $snmpVersion): self { return new self(sprintf(_('This SNMP version (%s) is not allowed'), $snmpVersion)); } /** * @param int $activeChecksStatus * @return self */ public static function badActiveChecksStatus(int $activeChecksStatus): self { return new self(sprintf(_('This active checks status (%d) is not allowed'), $activeChecksStatus)); } /** * @param int $passiveChecksStatus * @return self */ public static function badPassiveChecksStatus(int $passiveChecksStatus): self { return new self(sprintf(_('This passive checks status (%d) is not allowed'), $passiveChecksStatus)); } /** * @param int $notificationStatus * @return self */ public static function badNotificationStatus(int $notificationStatus): self { return new self(sprintf(_('This notifications status (%d) is not allowed'), $notificationStatus)); } /** * @param int $notificationInterval * @return self */ public static function badNotificationInterval(int $notificationInterval): self { return new self( sprintf(_('The notification interval must be greater than or equal to 0'), $notificationInterval) ); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Exception/HostCategoryException.php
centreon/src/Centreon/Domain/HostConfiguration/Exception/HostCategoryException.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Exception; /** * This class is designed to contain all exceptions for the context of the host category. * * @package Centreon\Domain\HostConfiguration\Exception */ class HostCategoryException extends \Exception { /** * @param \Throwable $ex * @return HostCategoryException */ public static function addCategoryException(\Throwable $ex): self { return new self(_('Error when adding a host category'), 0, $ex); } /** * @param \Throwable $ex * @return self */ public static function findHostCategoriesException(\Throwable $ex): self { return new self(_('Error when searching for host categories'), 0, $ex); } /** * @param \Throwable $ex * @param array<string, mixed> $data * @return self */ public static function findHostCategoryException(\Throwable $ex, array $data = []): self { return new self( sprintf(_('Error when searching for the host category (%s)'), $data['id'] ?? $data['name'] ?? null), 0, $ex ); } /** * @param array<string, mixed> $data * @param \Throwable|null $ex * @return self */ public static function notFoundException(array $data = [], ?\Throwable $ex = null): self { return new self( sprintf(_('Host category (%s) not found'), $data['id'] ?? $data['name'] ?? null), 0, $ex ); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Exception/HostCommandException.php
centreon/src/Centreon/Domain/HostConfiguration/Exception/HostCommandException.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Exception; /** * This class is designed to contain all exceptions for the context of the host command. * * @package Centreon\Domain\HostConfiguration\Exception */ class HostCommandException extends \Exception { /** * @param int $hostId * @return self */ public static function notFound(int $hostId): self { return new self( sprintf(_('Check command of host id %d not found'), $hostId) ); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Exception/HostGroupException.php
centreon/src/Centreon/Domain/HostConfiguration/Exception/HostGroupException.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Exception; /** * This class is designed to contain all exceptions for the context of the host group. * * @package Centreon\Domain\HostConfiguration\Exception */ class HostGroupException extends \Exception { /** * @param \Throwable $ex * @return HostGroupException */ public static function addGroupException(\Throwable $ex) { return new self(_('Error when adding a host groups'), 0, $ex); } /** * @param \Throwable $ex * @return self */ public static function findHostGroupsException(\Throwable $ex): self { return new self(_('Error when searching for host groups'), 0, $ex); } /** * @param \Throwable $ex * @param array<string, mixed> $data * @return self */ public static function findHostGroupException(\Throwable $ex, array $data = []): self { return new self( sprintf(_('Error when searching for the host group (%s)'), $data['id'] ?? $data['name'] ?? null), 0, $ex ); } /** * @param array<string, mixed> $data * @param \Throwable|null $ex * @return self */ public static function notFoundException(array $data, ?\Throwable $ex = null): self { return new self( sprintf(_('Host group (%s) not found'), $data['id'] ?? $data['name'] ?? null), 0, $ex ); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Exception/HostTemplateFactoryException.php
centreon/src/Centreon/Domain/HostConfiguration/Exception/HostTemplateFactoryException.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Exception; /** * This class is designed to provide all exceptions for the HostTemplate entity factory. * * @package Centreon\Domain\HostConfiguration\Exception */ class HostTemplateFactoryException extends \Exception { public static function notificationOptionsNotAllowed(string $options): self { return new self(sprintf(_('Notification options not allowed (%s)'), $options)); } public static function stalkingOptionsNotAllowed(string $options): self { return new self(sprintf(_('Stalking options not allowed (%s)'), $options)); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Exception/HostConfigurationServiceException.php
centreon/src/Centreon/Domain/HostConfiguration/Exception/HostConfigurationServiceException.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Exception; /** * This class is designed to contain all exceptions for the context of the host configuration. */ class HostConfigurationServiceException extends \Exception { /** * @return self */ public static function monitoringServerNotCorrectlyDefined(): self { return new self(_('Monitoring server is not correctly defined')); } /** * @return self */ public static function hostNameAlreadyExists(): self { return new self(_('Host name already exists')); } /** * @return self */ public static function hostNameCanNotBeEmpty(): self { return new self(_('Host name can not be empty')); } /** * @return self */ public static function engineConfigurationNotFound(): self { return new self(_('Unable to find the Engine configuration')); } /** * @param \Throwable $ex * @return self */ public static function errorOnAddingAHost(\Throwable $ex): self { return new self(sprintf(_('Error on adding a host (Reason: %s)'), $ex->getMessage()), 0, $ex); } /** * @param \Throwable $ex * @return self */ public static function errorOnUpdatingAHost(\Throwable $ex): self { return new self(sprintf(_('Error on updating a host (Reason: %s)'), $ex->getMessage()), 0, $ex); } /** * @return self */ public static function ipAddressCanNotBeEmpty(): self { return new self(_('Ip address cannot be empty')); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/HostConfiguration/Exception/HostMacroServiceException.php
centreon/src/Centreon/Domain/HostConfiguration/Exception/HostMacroServiceException.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\HostConfiguration\Exception; /** * This class is designed to contain all exceptions for the context of the host macro. * * @package Centreon\Domain\HostConfiguration\Exception */ class HostMacroServiceException extends \Exception { /** * @param \Throwable $ex * @return self */ public static function addMacroException(\Throwable $ex): self { return new self(_('Error when adding a host macro'), 0, $ex); } /** * @param \Throwable $ex * @return self */ public static function errorOnReadingHostMacros(\Throwable $ex): self { return new self(sprintf(_('Error on reading host macros (Reason: %s)'), $ex->getMessage())); } /** * @param \Throwable $ex * @return self */ public static function errorOnUpdatingMacro(\Throwable $ex): self { return new self(sprintf(_('Error on updating a host macro (Reason: %s)'), $ex->getMessage()), 0, $ex); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/MonitoringServer/MonitoringServerResource.php
centreon/src/Centreon/Domain/MonitoringServer/MonitoringServerResource.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\MonitoringServer; /** * This class is designed to represent resources of monitoring servers. * * @package Centreon\Domain\MonitoringServer */ class MonitoringServerResource { /** @var int Resource id */ private $id; /** @var string Resource name */ private $name; /** @var string Resource comment */ private $comment; /** @var string Resource path */ private $path; /** @var bool Indicates whether this resource is activate or not */ private $isActivate; /** * @return int */ public function getId(): int { return $this->id; } /** * @param int $id * @return MonitoringServerResource */ public function setId(int $id): MonitoringServerResource { $this->id = $id; return $this; } /** * @return string */ public function getName(): string { return $this->name; } /** * @param string $name * @return MonitoringServerResource */ public function setName(string $name): MonitoringServerResource { $this->name = $name; return $this; } /** * @return string */ public function getComment(): string { return $this->comment; } /** * @param string $comment * @return MonitoringServerResource */ public function setComment(string $comment): MonitoringServerResource { $this->comment = $comment; return $this; } /** * @return string */ public function getPath(): string { return $this->path; } /** * @param string $path * @return MonitoringServerResource */ public function setPath(string $path): MonitoringServerResource { $this->path = $path; return $this; } /** * @return bool */ public function isActivate(): bool { return $this->isActivate; } /** * @param bool $isActivate * @return MonitoringServerResource */ public function setIsActivate(bool $isActivate): MonitoringServerResource { $this->isActivate = $isActivate; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/MonitoringServer/MonitoringServer.php
centreon/src/Centreon/Domain/MonitoringServer/MonitoringServer.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\MonitoringServer; use Centreon\Domain\Service\EntityDescriptorMetadataInterface; /** * This class is designed to represent a monitoring server entity. * * @package Centreon\Domain\MonitoringServer */ class MonitoringServer implements EntityDescriptorMetadataInterface { // Groups for serializing public const SERIALIZER_GROUP_MAIN = 'monitoringserver_main'; /** @var int|null Unique id of server */ private $id; /** @var string|null Name of server */ private $name; /** @var bool Indicates whether it's the localhost server */ private $isLocalhost = false; /** @var bool Indicates whether it's the default server */ private $isDefault = false; /** @var \DateTime|null Date of the last Engine restart request */ private $lastRestart; /** @var string|null IP address of server */ private $address; /** @var bool Indicates whether the server configuration is activated */ private $isActivate = true; /** @var string|null System start command for Engine */ private $engineStartCommand; /** @var string|null System stop command for Engine */ private $engineStopCommand; /** @var string|null System restart command for Engine */ private $engineRestartCommand; /** @var string|null System reload command for Engine */ private $engineReloadCommand; /** @var string|null Full path of the Engine binary */ private $nagiosBin; /** @var string|null Full path of the Engine statistics binary */ private $nagiostatsBin; /** @var string|null */ private $nagiosPerfdata; /** @var string|null System reload command for Broker */ private $brokerReloadCommand; /** @var string|null Full path of the Broker configuration */ private $centreonbrokerCfgPath; /** @var string|null Full path of the Broker module's libraries */ private $centreonbrokerModulePath; /** @var string|null Full path of the Engine connectors */ private $centreonconnectorPath; /** @var int SSH port SSH port of this server */ private $sshPort; /** @var string|null */ private $sshPrivateKey; /** @var string|null System name of Centreontrapd daemon */ private $initScriptCentreontrapd; /** @var string|null Full path of the Centreontrapd daemon configuration */ private $snmpTrapdPathConf; /** @var string|null */ private $engineName; /** @var string|null */ private $engineVersion; /** @var string|null Full path of the Broker logs */ private $centreonbrokerLogsPath; /** @var int|null Unique ID of the master Remote Server linked to the server */ private $remoteId; /** @var bool Indicates whether Remote Servers are used as SSH proxies */ private $remoteServerUseAsProxy = true; /** @var bool Indicates whether the monitoring configuration has changed since last restart */ private $isUpdated = false; /** * @inheritDoc */ public static function loadEntityDescriptorMetadata(): array { return [ 'localhost' => 'setLocalhost', 'ns_ip_address' => 'setAddress', 'ns_activate' => 'setActivate', ]; } /** * @return int|null */ public function getId(): ?int { return $this->id; } /** * @param int|null $id * @return MonitoringServer */ public function setId(?int $id): MonitoringServer { $this->id = $id; return $this; } /** * @return string|null */ public function getName(): ?string { return $this->name; } /** * @param string|null $name * @return MonitoringServer */ public function setName(?string $name): MonitoringServer { $this->name = $name; return $this; } /** * @return bool */ public function isLocalhost(): bool { return $this->isLocalhost; } /** * @param bool $isLocalhost * @return MonitoringServer */ public function setLocalhost(bool $isLocalhost): MonitoringServer { $this->isLocalhost = $isLocalhost; return $this; } /** * @return bool */ public function isDefault(): bool { return $this->isDefault; } /** * @param bool $isDefault * @return MonitoringServer */ public function setIsDefault(bool $isDefault): MonitoringServer { $this->isDefault = $isDefault; return $this; } /** * @return \DateTime|null */ public function getLastRestart(): ?\DateTime { return $this->lastRestart; } /** * @param \DateTime $lastRestart * @return MonitoringServer */ public function setLastRestart(?\DateTime $lastRestart): MonitoringServer { $this->lastRestart = $lastRestart; return $this; } /** * @return string|null */ public function getAddress(): ?string { return $this->address; } /** * @param string|null $address * @return MonitoringServer */ public function setAddress(?string $address): MonitoringServer { $this->address = $address; return $this; } /** * @return bool */ public function isActivate(): bool { return $this->isActivate; } /** * @param bool $isActivate * @return MonitoringServer */ public function setActivate(bool $isActivate): MonitoringServer { $this->isActivate = $isActivate; return $this; } /** * @return string|null */ public function getEngineStartCommand(): ?string { return $this->engineStartCommand; } /** * @param string|null $engineStartCommand * @return MonitoringServer */ public function setEngineStartCommand(?string $engineStartCommand): MonitoringServer { $this->engineStartCommand = $engineStartCommand; return $this; } /** * @return string|null */ public function getEngineStopCommand(): ?string { return $this->engineStopCommand; } /** * @param string|null $engineStopCommand * @return MonitoringServer */ public function setEngineStopCommand(?string $engineStopCommand): MonitoringServer { $this->engineStopCommand = $engineStopCommand; return $this; } /** * @return string|null */ public function getEngineRestartCommand(): ?string { return $this->engineRestartCommand; } /** * @param string|null $engineRestartCommand * @return MonitoringServer */ public function setEngineRestartCommand(?string $engineRestartCommand): MonitoringServer { $this->engineRestartCommand = $engineRestartCommand; return $this; } /** * @return string|null */ public function getEngineReloadCommand(): ?string { return $this->engineReloadCommand; } /** * @param string|null $engineReloadCommand * @return MonitoringServer */ public function setEngineReloadCommand(?string $engineReloadCommand): MonitoringServer { $this->engineReloadCommand = $engineReloadCommand; return $this; } /** * @return string|null */ public function getNagiosBin(): ?string { return $this->nagiosBin; } /** * @param string|null $nagiosBin * @return MonitoringServer */ public function setNagiosBin(?string $nagiosBin): MonitoringServer { $this->nagiosBin = $nagiosBin; return $this; } /** * @return string|null */ public function getNagiostatsBin(): ?string { return $this->nagiostatsBin; } /** * @param string|null $nagiostatsBin * @return MonitoringServer */ public function setNagiostatsBin(?string $nagiostatsBin): MonitoringServer { $this->nagiostatsBin = $nagiostatsBin; return $this; } /** * @return string|null */ public function getNagiosPerfdata(): ?string { return $this->nagiosPerfdata; } /** * @param string|null $nagiosPerfdata * @return MonitoringServer */ public function setNagiosPerfdata(?string $nagiosPerfdata): MonitoringServer { $this->nagiosPerfdata = $nagiosPerfdata; return $this; } /** * @return string|null */ public function getBrokerReloadCommand(): ?string { return $this->brokerReloadCommand; } /** * @param string|null $brokerReloadCommand * @return MonitoringServer */ public function setBrokerReloadCommand(?string $brokerReloadCommand): MonitoringServer { $this->brokerReloadCommand = $brokerReloadCommand; return $this; } /** * @return string|null */ public function getCentreonbrokerCfgPath(): ?string { return $this->centreonbrokerCfgPath; } /** * @param string|null $centreonbrokerCfgPath * @return MonitoringServer */ public function setCentreonbrokerCfgPath(?string $centreonbrokerCfgPath): MonitoringServer { $this->centreonbrokerCfgPath = $centreonbrokerCfgPath; return $this; } /** * @return string|null */ public function getCentreonbrokerModulePath(): ?string { return $this->centreonbrokerModulePath; } /** * @param string|null $centreonbrokerModulePath * @return MonitoringServer */ public function setCentreonbrokerModulePath(?string $centreonbrokerModulePath): MonitoringServer { $this->centreonbrokerModulePath = $centreonbrokerModulePath; return $this; } /** * @return string|null */ public function getCentreonconnectorPath(): ?string { return $this->centreonconnectorPath; } /** * @param string|null $centreonconnectorPath * @return MonitoringServer */ public function setCentreonconnectorPath(?string $centreonconnectorPath): MonitoringServer { $this->centreonconnectorPath = $centreonconnectorPath; return $this; } /** * @return int */ public function getSshPort(): int { return $this->sshPort; } /** * @param int $sshPort * @return MonitoringServer */ public function setSshPort(int $sshPort): MonitoringServer { $this->sshPort = $sshPort; return $this; } /** * @return string|null */ public function getSshPrivateKey(): ?string { return $this->sshPrivateKey; } /** * @param string|null $sshPrivateKey * @return MonitoringServer */ public function setSshPrivateKey(?string $sshPrivateKey): MonitoringServer { $this->sshPrivateKey = $sshPrivateKey; return $this; } /** * @return string|null */ public function getInitScriptCentreontrapd(): ?string { return $this->initScriptCentreontrapd; } /** * @param string|null $initScriptCentreontrapd * @return MonitoringServer */ public function setInitScriptCentreontrapd(?string $initScriptCentreontrapd): MonitoringServer { $this->initScriptCentreontrapd = $initScriptCentreontrapd; return $this; } /** * @return string|null */ public function getSnmpTrapdPathConf(): ?string { return $this->snmpTrapdPathConf; } /** * @param string|null $snmpTrapdPathConf * @return MonitoringServer */ public function setSnmpTrapdPathConf(?string $snmpTrapdPathConf): MonitoringServer { $this->snmpTrapdPathConf = $snmpTrapdPathConf; return $this; } /** * @return string|null */ public function getEngineName(): ?string { return $this->engineName; } /** * @param string|null $engineName * @return MonitoringServer */ public function setEngineName(?string $engineName): MonitoringServer { $this->engineName = $engineName; return $this; } /** * @return string|null */ public function getEngineVersion(): ?string { return $this->engineVersion; } /** * @param string|null $engineVersion * @return MonitoringServer */ public function setEngineVersion(?string $engineVersion): MonitoringServer { $this->engineVersion = $engineVersion; return $this; } /** * @return string|null */ public function getCentreonbrokerLogsPath(): ?string { return $this->centreonbrokerLogsPath; } /** * @param string|null $centreonbrokerLogsPath * @return MonitoringServer */ public function setCentreonbrokerLogsPath(?string $centreonbrokerLogsPath): MonitoringServer { $this->centreonbrokerLogsPath = $centreonbrokerLogsPath; return $this; } /** * @return int|null */ public function getRemoteId(): ?int { return $this->remoteId; } /** * @param int|null $remoteId * @return MonitoringServer */ public function setRemoteId(?int $remoteId): MonitoringServer { $this->remoteId = $remoteId; return $this; } /** * @return bool */ public function isRemoteServerUseAsProxy(): bool { return $this->remoteServerUseAsProxy; } /** * @param bool $remoteServerUseAsProxy * @return MonitoringServer */ public function setRemoteServerUseAsProxy(bool $remoteServerUseAsProxy): MonitoringServer { $this->remoteServerUseAsProxy = $remoteServerUseAsProxy; return $this; } /** * @return bool */ public function isUpdated(): bool { return $this->isUpdated; } /** * @param bool $isUpdated * @return MonitoringServer */ public function setUpdated(bool $isUpdated): MonitoringServer { $this->isUpdated = $isUpdated; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/MonitoringServer/MonitoringServerService.php
centreon/src/Centreon/Domain/MonitoringServer/MonitoringServerService.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\MonitoringServer; use Centreon\Domain\Contact\Contact; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\MonitoringServer\Exception\MonitoringServerException; use Centreon\Domain\MonitoringServer\Interfaces\MonitoringServerRepositoryInterface; use Centreon\Domain\MonitoringServer\Interfaces\MonitoringServerServiceInterface; use Core\Security\AccessGroup\Application\Repository\ReadAccessGroupRepositoryInterface; use Symfony\Component\Security\Core\Exception\AccessDeniedException; /** * This class is designed to manage monitoring servers and their associated resources. * * @package Centreon\Domain\MonitoringServer */ class MonitoringServerService implements MonitoringServerServiceInterface { /** * PollerService constructor. * * @param MonitoringServerRepositoryInterface $monitoringServerRepository * @param ReadAccessGroupRepositoryInterface $readAccessGroupsRepository * @param ContactInterface $contact */ public function __construct( private readonly MonitoringServerRepositoryInterface $monitoringServerRepository, private readonly ReadAccessGroupRepositoryInterface $readAccessGroupsRepository, private readonly ContactInterface $contact, ) { } /** * @inheritDoc */ public function findServers(): array { try { if ( ! $this->contact->hasTopologyRole(Contact::ROLE_CONFIGURATION_MONITORING_SERVER_READ) && ! $this->contact->hasTopologyRole(Contact::ROLE_CONFIGURATION_MONITORING_SERVER_READ_WRITE) ) { throw new AccessDeniedException(); } if ($this->contact->isAdmin()) { return $this->monitoringServerRepository->findServersWithRequestParameters(); } $accessGroups = $this->readAccessGroupsRepository->findByContact($this->contact); return $this->monitoringServerRepository->findServersWithRequestParametersAndAccessGroups( $accessGroups ); } catch (AccessDeniedException $ex) { throw new AccessDeniedException('You are not allowed to access this resource'); } catch (\Exception $ex) { throw new MonitoringServerException('Error when searching for monitoring servers', 0, $ex); } } /** * @inheritDoc */ public function findServer(int $monitoringServerId): ?MonitoringServer { try { return $this->monitoringServerRepository->findServer($monitoringServerId); } catch (\Exception $ex) { throw new MonitoringServerException( 'Error when searching for a monitoring server (' . $monitoringServerId . ')', 0, $ex ); } } /** * @inheritDoc */ public function findServerByName(string $monitoringServerName): ?MonitoringServer { try { return $this->monitoringServerRepository->findServerByName($monitoringServerName); } catch (\Exception $ex) { throw new MonitoringServerException( sprintf(_('Error when searching for a monitoring server %s'), $monitoringServerName), 0, $ex ); } } /** * @inheritDoc */ public function findResource(int $monitoringServerId, string $resourceName): ?MonitoringServerResource { try { return $this->monitoringServerRepository->findResource($monitoringServerId, $resourceName); } catch (\Exception $ex) { throw new MonitoringServerException('Error when searching for a resource of monitoring server', 0, $ex); } } /** * @inheritDoc */ public function findLocalServer(): ?MonitoringServer { try { return $this->monitoringServerRepository->findLocalServer(); } catch (\Exception $ex) { 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); } } /** * @inheritDoc */ public function deleteServer(int $monitoringServerId): void { try { $this->monitoringServerRepository->deleteServer($monitoringServerId); } catch (\Exception $ex) { throw new MonitoringServerException('Error when deleting a monitoring server', 0, $ex); } } /** * @inheritDoc */ public function findRemoteServersIps(): array { try { return $this->monitoringServerRepository->findRemoteServersIps(); } catch (\Exception $ex) { throw new MonitoringServerException('Error when searching for remote servers IPs', 0, $ex); } } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/MonitoringServer/Model/RealTimeMonitoringServer.php
centreon/src/Centreon/Domain/MonitoringServer/Model/RealTimeMonitoringServer.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\MonitoringServer\Model; use Centreon\Domain\Common\Assertion\Assertion; /** * This class is designed to represent a RealTime Monitoring Server. * * @package Centreon\Domain\MonitoringServer\Model */ class RealTimeMonitoringServer { public const MAX_NAME_LENGTH = 255; public const MIN_NAME_LENGTH = 1; public const MAX_ADDRESS_LENGTH = 128; public const MAX_DESCRIPTION_LENGTH = 128; public const MAX_VERSION_LENGTH = 16; /** @var int defines the Monitoring Server id */ private $id; /** @var string defines a short name for the Monitoring Server */ private $name; /** @var string|null Defines the IP address of the Monitoring Server */ private $address; /** @var string|null Defines a short description of the Monitoring Server */ private $description; /** @var int|null Defines the last time when Monitoring Server was alive (timestamp) */ private $lastAlive; /** @var bool Defines whether or not the Monitoring Server is running */ private $isRunning = false; /** @var string|null Defines the version of the Monitoring Server (Centreon Engine version) */ private $version; /** * @param int $id ID of the Monitoring Server * @param string $name Name of the Monitoring Server * @throws \Assert\AssertionFailedException */ public function __construct(int $id, string $name) { $this->setId($id); $this->setName($name); } /** * @return int */ public function getId(): int { return $this->id; } /** * @param int $id * @return RealTimeMonitoringServer */ public function setId(int $id): RealTimeMonitoringServer { $this->id = $id; return $this; } /** * @return string */ public function getName(): string { return $this->name; } /** * @param string $name * @throws \Assert\AssertionFailedException * @return RealTimeMonitoringServer */ public function setName(string $name): RealTimeMonitoringServer { Assertion::minLength($name, self::MIN_NAME_LENGTH, 'RealTimeMonitoringServer::name'); Assertion::maxLength($name, self::MAX_NAME_LENGTH, 'RealTimeMonitoringServer::name'); $this->name = $name; return $this; } /** * @return string|null */ public function getAddress(): ?string { return $this->address; } /** * @param string|null $address * @throws \Assert\AssertionFailedException * @return RealTimeMonitoringServer */ public function setAddress(?string $address): RealTimeMonitoringServer { if ($address !== null) { Assertion::maxLength($address, self::MAX_ADDRESS_LENGTH, 'RealTimeMonitoringServer::address'); } $this->address = $address; return $this; } /** * @return int */ public function getLastAlive(): int { return $this->lastAlive; } /** * @param int|null $lastAlive * @return RealTimeMonitoringServer */ public function setLastAlive(?int $lastAlive): RealTimeMonitoringServer { $this->lastAlive = $lastAlive; return $this; } /** * @return bool */ public function isRunning(): bool { return $this->isRunning; } /** * @param bool $running * @return RealTimeMonitoringServer */ public function setRunning(bool $running): RealTimeMonitoringServer { $this->isRunning = $running; return $this; } /** * @return string|null */ public function getVersion(): ?string { return $this->version; } /** * @param string|null $version * @throws \Assert\AssertionFailedException * @return RealTimeMonitoringServer */ public function setVersion(?string $version): RealTimeMonitoringServer { if ($version !== null) { Assertion::maxLength($version, self::MAX_VERSION_LENGTH, 'RealTimeMonitoringServer::version'); } $this->version = $version; return $this; } /** * @return string|null */ public function getDescription(): ?string { return $this->description; } /** * @param string|null $description * @throws \Assert\AssertionFailedException * @return RealTimeMonitoringServer */ public function setDescription(?string $description): RealTimeMonitoringServer { if ($description !== null) { Assertion::maxLength($description, self::MAX_DESCRIPTION_LENGTH, 'RealTimeMonitoringServer::description'); } $this->description = $description; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/MonitoringServer/UseCase/GenerateAllConfigurations.php
centreon/src/Centreon/Domain/MonitoringServer/UseCase/GenerateAllConfigurations.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\MonitoringServer\UseCase; use Centreon\Domain\Contact\Contact; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\Exception\TimeoutException; use Centreon\Domain\Log\LoggerTrait; use Centreon\Domain\MonitoringServer\Exception\ConfigurationMonitoringServerException; use Centreon\Domain\MonitoringServer\Interfaces\MonitoringServerConfigurationRepositoryInterface; use Centreon\Domain\MonitoringServer\Interfaces\MonitoringServerRepositoryInterface; use Core\Security\AccessGroup\Application\Repository\ReadAccessGroupRepositoryInterface; use Symfony\Component\Security\Core\Exception\AccessDeniedException; /** * This class is designed to represent a use case to generate the monitoring server configurations. * * @package Centreon\Domain\MonitoringServer\UseCase */ class GenerateAllConfigurations { use LoggerTrait; /** * @param MonitoringServerRepositoryInterface $monitoringServerRepository * @param MonitoringServerConfigurationRepositoryInterface $configurationRepository * @param ReadAccessGroupRepositoryInterface $readAccessGroupRepositoryInterface * @param ContactInterface $contact */ public function __construct( private readonly MonitoringServerRepositoryInterface $monitoringServerRepository, private readonly MonitoringServerConfigurationRepositoryInterface $configurationRepository, private readonly ReadAccessGroupRepositoryInterface $readAccessGroupRepositoryInterface, private readonly ContactInterface $contact, ) { } /** * @throws ConfigurationMonitoringServerException * @throws TimeoutException */ public function execute(): void { try { if ($this->contact->isAdmin()) { $monitoringServers = $this->monitoringServerRepository->findServersWithoutRequestParameters(); } else { if ( ! $this->contact->hasTopologyRole(Contact::ROLE_CONFIGURATION_MONITORING_SERVER_READ) && ! $this->contact->hasTopologyRole(Contact::ROLE_CONFIGURATION_MONITORING_SERVER_READ_WRITE) ) { throw new AccessDeniedException( 'Insufficient rights (required: ROLE_CONFIGURATION_MONITORING_SERVER_READ or ' . 'ROLE_CONFIGURATION_MONITORING_SERVER_READ_WRITE)' ); } $accessGroups = $this->readAccessGroupRepositoryInterface->findByContact($this->contact); $monitoringServers = $this->monitoringServerRepository->findAllServersWithAccessGroups( $accessGroups ); } } catch (AccessDeniedException $ex) { throw new AccessDeniedException($ex->getMessage()); } catch (\Throwable $ex) { throw ConfigurationMonitoringServerException::errorRetrievingMonitoringServers($ex); } $lastMonitoringServerId = 0; try { foreach ($monitoringServers as $monitoringServer) { $lastMonitoringServerId = $monitoringServer->getId(); if ($lastMonitoringServerId === null) { $this->error('Monitoring server id from repository is null'); continue; } if ($monitoringServer->isActivate() === false) { $this->info('Monitoring server #' . $lastMonitoringServerId . ' is disabled'); continue; } $this->info('Generate configuration files for monitoring server #' . $lastMonitoringServerId); $this->configurationRepository->generateConfiguration($lastMonitoringServerId); $this->info('Move configuration files for monitoring server #' . $lastMonitoringServerId); $this->configurationRepository->moveExportFiles($lastMonitoringServerId); } } catch (TimeoutException $ex) { throw ConfigurationMonitoringServerException::timeout($lastMonitoringServerId, $ex->getMessage()); } catch (\Exception $ex) { throw ConfigurationMonitoringServerException::errorOnGeneration( $lastMonitoringServerId, $ex->getMessage() ); } } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/MonitoringServer/UseCase/ReloadAllConfigurations.php
centreon/src/Centreon/Domain/MonitoringServer/UseCase/ReloadAllConfigurations.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\MonitoringServer\UseCase; use Centreon\Domain\Contact\Contact; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\Exception\TimeoutException; use Centreon\Domain\Log\LoggerTrait; use Centreon\Domain\MonitoringServer\Exception\ConfigurationMonitoringServerException; use Centreon\Domain\MonitoringServer\Interfaces\MonitoringServerConfigurationRepositoryInterface; use Centreon\Domain\MonitoringServer\Interfaces\MonitoringServerRepositoryInterface; use Core\Security\AccessGroup\Application\Repository\ReadAccessGroupRepositoryInterface; use Symfony\Component\Security\Core\Exception\AccessDeniedException; /** * This class is designed to represent a use case to reload the monitoring server configurations. * * @package Centreon\Domain\MonitoringServer\UseCase */ class ReloadAllConfigurations { use LoggerTrait; /** * @param MonitoringServerRepositoryInterface $monitoringServerRepository * @param MonitoringServerConfigurationRepositoryInterface $configurationRepository * @param ReadAccessGroupRepositoryInterface $readAccessGroupRepositoryInterface * @param ContactInterface $contact */ public function __construct( private readonly MonitoringServerRepositoryInterface $monitoringServerRepository, private readonly MonitoringServerConfigurationRepositoryInterface $configurationRepository, private readonly ReadAccessGroupRepositoryInterface $readAccessGroupRepositoryInterface, private readonly ContactInterface $contact, ) { } /** * @throws ConfigurationMonitoringServerException * @throws TimeoutException */ public function execute(): void { try { if ($this->contact->isAdmin()) { $monitoringServers = $this->monitoringServerRepository->findServersWithoutRequestParameters(); } else { if ( ! $this->contact->hasTopologyRole(Contact::ROLE_CONFIGURATION_MONITORING_SERVER_READ) && ! $this->contact->hasTopologyRole(Contact::ROLE_CONFIGURATION_MONITORING_SERVER_READ_WRITE) ) { throw new AccessDeniedException( 'Insufficient rights (required: ROLE_CONFIGURATION_MONITORING_SERVER_READ or ' . 'ROLE_CONFIGURATION_MONITORING_SERVER_READ_WRITE)' ); } $accessGroups = $this->readAccessGroupRepositoryInterface->findByContact($this->contact); $monitoringServers = $this->monitoringServerRepository->findAllServersWithAccessGroups( $accessGroups ); } } catch (AccessDeniedException $ex) { throw new AccessDeniedException($ex->getMessage()); } catch (\Throwable $ex) { throw ConfigurationMonitoringServerException::errorRetrievingMonitoringServers($ex); } $lastMonitoringServerId = 0; try { foreach ($monitoringServers as $monitoringServer) { $lastMonitoringServerId = $monitoringServer->getId(); if ($lastMonitoringServerId !== null) { $this->info('Reload configuration for monitoring server #' . $lastMonitoringServerId); $this->configurationRepository->reloadConfiguration($lastMonitoringServerId); } else { $this->error('Monitoring server id from repository is null'); } } } catch (TimeoutException $ex) { throw ConfigurationMonitoringServerException::timeout($lastMonitoringServerId, $ex->getMessage()); } catch (\Exception $ex) { throw ConfigurationMonitoringServerException::errorOnReload( $lastMonitoringServerId, $ex->getMessage() ); } } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/MonitoringServer/UseCase/GenerateConfiguration.php
centreon/src/Centreon/Domain/MonitoringServer/UseCase/GenerateConfiguration.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\MonitoringServer\UseCase; use Centreon\Domain\Contact\Contact; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\Exception\EntityNotFoundException; use Centreon\Domain\Exception\TimeoutException; use Centreon\Domain\Log\LoggerTrait; use Centreon\Domain\MonitoringServer\Exception\ConfigurationMonitoringServerException; use Centreon\Domain\MonitoringServer\Interfaces\MonitoringServerConfigurationRepositoryInterface; use Centreon\Domain\MonitoringServer\Interfaces\MonitoringServerRepositoryInterface; use Core\Security\AccessGroup\Application\Repository\ReadAccessGroupRepositoryInterface; use Symfony\Component\Security\Core\Exception\AccessDeniedException; /** * This class is designed to represent a use case to generate a monitoring server configuration. * * @package Centreon\Domain\MonitoringServer\UseCase */ class GenerateConfiguration { use LoggerTrait; /** * @param MonitoringServerRepositoryInterface $monitoringServerRepository * @param MonitoringServerConfigurationRepositoryInterface $configurationRepository */ public function __construct( private readonly MonitoringServerRepositoryInterface $monitoringServerRepository, private readonly MonitoringServerConfigurationRepositoryInterface $configurationRepository, private readonly ReadAccessGroupRepositoryInterface $readAccessGroupRepositoryInterface, private readonly ContactInterface $contact, ) { } /** * @param int $monitoringServerId * @throws EntityNotFoundException * @throws ConfigurationMonitoringServerException * @throws TimeoutException */ public function execute(int $monitoringServerId): void { try { if ($this->contact->isAdmin()) { $monitoringServer = $this->monitoringServerRepository->findServer($monitoringServerId); } else { if ( ! $this->contact->hasTopologyRole(Contact::ROLE_CONFIGURATION_MONITORING_SERVER_READ) && ! $this->contact->hasTopologyRole(Contact::ROLE_CONFIGURATION_MONITORING_SERVER_READ_WRITE) ) { throw new AccessDeniedException( 'Insufficient rights (required: ROLE_CONFIGURATION_MONITORING_SERVER_READ or ' . 'ROLE_CONFIGURATION_MONITORING_SERVER_READ_WRITE)' ); } $accessGroups = $this->readAccessGroupRepositoryInterface->findByContact($this->contact); $monitoringServer = $this->monitoringServerRepository->findByIdAndAccessGroups( $monitoringServerId, $accessGroups ); } if ($monitoringServer === null) { throw ConfigurationMonitoringServerException::notFound($monitoringServerId); } if ($monitoringServer->isActivate() === false) { throw ConfigurationMonitoringServerException::disabled($monitoringServerId); } $this->info('Generate configuration files for monitoring server #' . $monitoringServerId); $this->configurationRepository->generateConfiguration($monitoringServerId); $this->info('Move configuration files for monitoring server #' . $monitoringServerId); $this->configurationRepository->moveExportFiles($monitoringServerId); } catch (AccessDeniedException $ex) { throw new AccessDeniedException($ex->getMessage()); } catch (EntityNotFoundException|TimeoutException $ex) { if ($ex instanceof TimeoutException) { throw ConfigurationMonitoringServerException::timeout($monitoringServerId, $ex->getMessage()); } throw $ex; } catch (\Exception $ex) { throw ConfigurationMonitoringServerException::errorOnGeneration( $monitoringServerId, $ex->getMessage(), $ex->getCode(), $ex, ); } } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/MonitoringServer/UseCase/ReloadConfiguration.php
centreon/src/Centreon/Domain/MonitoringServer/UseCase/ReloadConfiguration.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\MonitoringServer\UseCase; use Centreon\Domain\Contact\Contact; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\Exception\EntityNotFoundException; use Centreon\Domain\Exception\TimeoutException; use Centreon\Domain\Log\LoggerTrait; use Centreon\Domain\MonitoringServer\Exception\ConfigurationMonitoringServerException; use Centreon\Domain\MonitoringServer\Interfaces\MonitoringServerConfigurationRepositoryInterface; use Centreon\Domain\MonitoringServer\Interfaces\MonitoringServerRepositoryInterface; use Core\Security\AccessGroup\Application\Repository\ReadAccessGroupRepositoryInterface; use Symfony\Component\Security\Core\Exception\AccessDeniedException; /** * This class is designed to represent a use case to reload a monitoring server configuration. * @package Centreon\Domain\MonitoringServer\UseCase */ class ReloadConfiguration { use LoggerTrait; /** * @param MonitoringServerRepositoryInterface $monitoringServerRepository * @param MonitoringServerConfigurationRepositoryInterface $configurationRepository * @param ReadAccessGroupRepositoryInterface $readAccessGroupRepositoryInterface * @param ContactInterface $contact */ public function __construct( private readonly MonitoringServerRepositoryInterface $monitoringServerRepository, private readonly MonitoringServerConfigurationRepositoryInterface $configurationRepository, private readonly ReadAccessGroupRepositoryInterface $readAccessGroupRepositoryInterface, private readonly ContactInterface $contact, ) { } /** * @param int $monitoringServerId * @throws EntityNotFoundException * @throws ConfigurationMonitoringServerException * @throws TimeoutException */ public function execute(int $monitoringServerId): void { try { if ($this->contact->isAdmin()) { $monitoringServer = $this->monitoringServerRepository->findServer($monitoringServerId); } else { if ( ! $this->contact->hasTopologyRole(Contact::ROLE_CONFIGURATION_MONITORING_SERVER_READ) && ! $this->contact->hasTopologyRole(Contact::ROLE_CONFIGURATION_MONITORING_SERVER_READ_WRITE) ) { throw new AccessDeniedException( 'Insufficient rights (required: ROLE_CONFIGURATION_MONITORING_SERVER_READ or ' . 'ROLE_CONFIGURATION_MONITORING_SERVER_READ_WRITE)' ); } $accessGroups = $this->readAccessGroupRepositoryInterface->findByContact($this->contact); $monitoringServer = $this->monitoringServerRepository->findByIdAndAccessGroups( $monitoringServerId, $accessGroups ); } if ($monitoringServer === null) { throw ConfigurationMonitoringServerException::notFound($monitoringServerId); } $this->info('Reload configuration for monitoring server #' . $monitoringServerId); $this->configurationRepository->reloadConfiguration($monitoringServerId); } catch (AccessDeniedException $ex) { throw new AccessDeniedException($ex->getMessage()); } catch (EntityNotFoundException|TimeoutException $ex) { if ($ex instanceof TimeoutException) { throw ConfigurationMonitoringServerException::timeout($monitoringServerId, $ex->getMessage()); } throw $ex; } catch (\Exception $ex) { throw ConfigurationMonitoringServerException::errorOnReload( $monitoringServerId, $ex->getMessage() ); } } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/MonitoringServer/UseCase/RealTimeMonitoringServer/FindRealTimeMonitoringServers.php
centreon/src/Centreon/Domain/MonitoringServer/UseCase/RealTimeMonitoringServer/FindRealTimeMonitoringServers.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\MonitoringServer\UseCase\RealTimeMonitoringServer; use Centreon\Domain\Contact\Contact; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\Log\LoggerTrait; use Centreon\Domain\MonitoringServer\Exception\RealTimeMonitoringServerException; use Centreon\Infrastructure\MonitoringServer\Repository\RealTimeMonitoringServerRepositoryRDB; use Symfony\Component\Security\Core\Exception\AccessDeniedException; /** * This class is designed to represent a use case to find all monitoring servers. * * @package Centreon\Domain\MonitoringServer\UseCase\RealTimeMonitoringServer */ class FindRealTimeMonitoringServers { use LoggerTrait; /** * FindRealTimeMonitoringServers constructor. * * @param RealTimeMonitoringServerRepositoryRDB $realTimeMonitoringServerRepository * @param ContactInterface $contact */ public function __construct( readonly private RealTimeMonitoringServerRepositoryRDB $realTimeMonitoringServerRepository, readonly private ContactInterface $contact, ) { } /** * Execute the use case for which this class was designed. * * @throws RealTimeMonitoringServerException * @throws \Throwable * @return FindRealTimeMonitoringServersResponse */ public function execute(): FindRealTimeMonitoringServersResponse { $this->info('Find all realtime monitoring servers information.'); if (! $this->contact->hasTopologyRole(Contact::ROLE_MONITORING_RESOURCES_STATUS_RW)) { $this->error('User doesn\'t have sufficient rights to see realtime monitoring servers', [ 'user_id' => $this->contact->getId(), ]); throw new AccessDeniedException(); } $response = new FindRealTimeMonitoringServersResponse(); $realTimeMonitoringServers = []; if ($this->contact->isAdmin()) { try { $realTimeMonitoringServers = $this->realTimeMonitoringServerRepository->findAll(); } catch (\Throwable $ex) { throw RealTimeMonitoringServerException::findRealTimeMonitoringServersException($ex); } } else { $allowedMonitoringServers = $this->realTimeMonitoringServerRepository ->findAllowedMonitoringServers($this->contact); if ($allowedMonitoringServers !== []) { $allowedMonitoringServerIds = array_map( function ($allowedMonitoringServer) { return $allowedMonitoringServer->getId(); }, $allowedMonitoringServers ); $this->info( 'Find realtime monitoring servers information for following ids: ' . implode(',', $allowedMonitoringServerIds) ); try { $realTimeMonitoringServers = $this->realTimeMonitoringServerRepository ->findByIds($allowedMonitoringServerIds); } catch (\Throwable $ex) { throw RealTimeMonitoringServerException::findRealTimeMonitoringServersException($ex); } } else { $this->info( 'Cannot find realtime monitoring servers information because user does not have access to anyone.' ); } } $response->setRealTimeMonitoringServers($realTimeMonitoringServers); return $response; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/MonitoringServer/UseCase/RealTimeMonitoringServer/FindRealTimeMonitoringServersResponse.php
centreon/src/Centreon/Domain/MonitoringServer/UseCase/RealTimeMonitoringServer/FindRealTimeMonitoringServersResponse.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\MonitoringServer\UseCase\RealTimeMonitoringServer; use Centreon\Domain\MonitoringServer\Model\RealTimeMonitoringServer; /** * This class is a DTO for the FindRealTimeMonitoringServers use case. * * @package Centreon\Domain\MonitoringServer\UseCase\RealTimeMonitoringServer */ class FindRealTimeMonitoringServersResponse { /** @var array<int, array<string, mixed>> */ private $realTimeMonitoringServers = []; /** * @param RealTimeMonitoringServer[] $realTimeMonitoringServers */ public function setRealTimeMonitoringServers(array $realTimeMonitoringServers): void { foreach ($realTimeMonitoringServers as $realTimeMonitoringServer) { $this->realTimeMonitoringServers[] = [ 'id' => $realTimeMonitoringServer->getId(), 'name' => $realTimeMonitoringServer->getName(), 'address' => $realTimeMonitoringServer->getAddress(), 'description' => $realTimeMonitoringServer->getDescription(), 'last_alive' => $realTimeMonitoringServer->getLastAlive(), 'is_running' => $realTimeMonitoringServer->isRunning(), 'version' => $realTimeMonitoringServer->getVersion(), ]; } } /** * @return array<int, array<string, mixed>> */ public function getRealTimeMonitoringServers(): array { return $this->realTimeMonitoringServers; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/MonitoringServer/Interfaces/MonitoringServerConfigurationRepositoryInterface.php
centreon/src/Centreon/Domain/MonitoringServer/Interfaces/MonitoringServerConfigurationRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\MonitoringServer\Interfaces; use Centreon\Domain\Authentication\Exception\AuthenticationException; use Centreon\Domain\Exception\TimeoutException; use Centreon\Domain\Repository\RepositoryException; /** * @package Centreon\Domain\MonitoringServer\Interfaces */ interface MonitoringServerConfigurationRepositoryInterface { /** * @param int $monitoringServerId * @throws RepositoryException * @throws TimeoutException * @throws AuthenticationException */ public function generateConfiguration(int $monitoringServerId): void; /** * @param int $monitoringServerId * @throws RepositoryException * @throws TimeoutException * @throws AuthenticationException */ public function moveExportFiles(int $monitoringServerId): void; /** * @param int $monitoringServerId * @throws RepositoryException * @throws TimeoutException * @throws AuthenticationException */ public function reloadConfiguration(int $monitoringServerId): void; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/MonitoringServer/Interfaces/MonitoringServerServiceInterface.php
centreon/src/Centreon/Domain/MonitoringServer/Interfaces/MonitoringServerServiceInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\MonitoringServer\Interfaces; use Centreon\Domain\MonitoringServer\Exception\MonitoringServerException; use Centreon\Domain\MonitoringServer\MonitoringServer; use Centreon\Domain\MonitoringServer\MonitoringServerResource; use Symfony\Component\Security\Core\Exception\AccessDeniedException; /** * @package Centreon\Domain\MonitoringServer\Interfaces */ interface MonitoringServerServiceInterface { /** * Find pollers. * * @throws MonitoringServerException|AccessDeniedException * * @return MonitoringServer[] */ public function findServers(): array; /** * Find a resource of monitoring servers identified by his name. * * @param int $monitoringServerId Id of the monitoring server for which we want their resources * @param string $resourceName Resource name to find * @throws MonitoringServerException * @return MonitoringServerResource|null */ public function findResource(int $monitoringServerId, string $resourceName): ?MonitoringServerResource; /** * Find the local monitoring server. * * @throws MonitoringServerException * @return MonitoringServer|null */ 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; /** * Find a monitoring server. * * @param int $monitoringServerId id of the monitoring server to be found * @throws MonitoringServerException * @return MonitoringServer|null */ public function findServer(int $monitoringServerId): ?MonitoringServer; /** * Find a monitoring server by its name. * * @param string $monitoringServerName Name to find * @throws MonitoringServerException * @return MonitoringServer|null */ public function findServerByName(string $monitoringServerName): ?MonitoringServer; /** * Delete a monitoring server. * * @param int $monitoringServerId * @throws MonitoringServerException */ public function deleteServer(int $monitoringServerId): void; /** * Find remote monitoring servers IPs. * * @throws MonitoringServerException * @return string[] */ public function findRemoteServersIps(): array; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/MonitoringServer/Interfaces/MonitoringServerRepositoryInterface.php
centreon/src/Centreon/Domain/MonitoringServer/Interfaces/MonitoringServerRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\MonitoringServer\Interfaces; use Centreon\Domain\MonitoringServer\Exception\MonitoringServerException; use Centreon\Domain\MonitoringServer\MonitoringServer; use Centreon\Domain\MonitoringServer\MonitoringServerResource; use Core\Security\AccessGroup\Domain\Model\AccessGroup; /** * @package Centreon\Domain\MonitoringServer\Interfaces */ interface MonitoringServerRepositoryInterface { /** * Find monitoring servers taking into account the request parameters. * * @throws \Exception * @return MonitoringServer[] */ public function findServersWithRequestParameters(): array; /** * @param AccessGroup[] $accessGroups * * @throws \Throwable * * @return MonitoringServer[] */ public function findAllServersWithAccessGroups(array $accessGroups): array; /** * @param AccessGroup[] $accessGroups * * @throws \Throwable * * @return MonitoringServer[] */ public function findServersWithRequestParametersAndAccessGroups(array $accessGroups): array; /** * Find monitoring servers without taking into account the request parameters. * * @throws \Exception * @return MonitoringServer[] */ public function findServersWithoutRequestParameters(): array; /** * Find a resource of monitoring servers identified by his name. * * @param int $monitoringServerId Id of the monitoring server for which we want their resources * @param string $resourceName Resource name to find * @return MonitoringServerResource|null */ public function findResource(int $monitoringServerId, string $resourceName): ?MonitoringServerResource; /** * Find the local monitoring server. * * @throws \Exception * @return MonitoringServer|null */ 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; /** * Find a monitoring server. * * @param int $monitoringServerId Id of the monitoring server to be found * @throws \Exception * @return MonitoringServer|null */ public function findServer(int $monitoringServerId): ?MonitoringServer; /** * Find a monitoring server by id and access groups. * * @param int $monitoringServerId Id of the monitoring server to be found * @param AccessGroup[] $accessGroups * * @throws \Exception * * @return MonitoringServer|null */ public function findByIdAndAccessGroups(int $monitoringServerId, array $accessGroups): ?MonitoringServer; /** * Find a monitoring server by its name. * * @param string $monitoringServerName Name to find * @throws MonitoringServerException * @return MonitoringServer|null */ public function findServerByName(string $monitoringServerName): ?MonitoringServer; /** * Delete a monitoring server. * * @param int $monitoringServerId */ public function deleteServer(int $monitoringServerId): void; /** * Find remote servers IPs. * * @throws MonitoringServerException * @return string[] */ public function findRemoteServersIps(): array; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/MonitoringServer/Interfaces/RealTimeMonitoringServerRepositoryInterface.php
centreon/src/Centreon/Domain/MonitoringServer/Interfaces/RealTimeMonitoringServerRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\MonitoringServer\Interfaces; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\MonitoringServer\Model\RealTimeMonitoringServer; use Centreon\Domain\MonitoringServer\MonitoringServer; /** * This interface gathers all the reading operations on the realtime monitoring server repository. * * @package Centreon\Domain\MonitoringServer\Interfaces */ interface RealTimeMonitoringServerRepositoryInterface { /** * Find all Real Time Monitoring Servers. * * @throws \Throwable * @return RealTimeMonitoringServer[] */ public function findAll(): array; /** * Find all Real Time Monitoring Servers by ids. * * @param int[] $ids * @throws \Throwable * @return RealTimeMonitoringServer[] */ public function findByIds(array $ids): array; /** * Find all the Monitoring Servers that user is allowed to see. * * @param ContactInterface $contact Contact related to monitoring servers * @throws \Throwable * @return MonitoringServer[] */ public function findAllowedMonitoringServers(ContactInterface $contact): array; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/MonitoringServer/Exception/ConfigurationMonitoringServerException.php
centreon/src/Centreon/Domain/MonitoringServer/Exception/ConfigurationMonitoringServerException.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\MonitoringServer\Exception; use Centreon\Domain\Exception\EntityNotFoundException; use Centreon\Domain\Exception\TimeoutException; /** * This class is designed to contain all exceptions concerning the generation and reloading of the monitoring server * configuration. * * @package Centreon\Domain\MonitoringServer\Exception */ class ConfigurationMonitoringServerException extends \Exception { /** * @param int $monitoringServerId * @return EntityNotFoundException */ public static function notFound(int $monitoringServerId): EntityNotFoundException { return new EntityNotFoundException(sprintf(_('Monitoring server not found (#%d)'), $monitoringServerId)); } /** * @param int $monitoringServerId * @return self */ public static function disabled(int $monitoringServerId): self { return new self(sprintf(_('Monitoring server disabled (#%d)'), $monitoringServerId)); } /** * @param int $monitoringServerId * @param string $errorMessage * @return self */ public static function errorOnGeneration(int $monitoringServerId, string $errorMessage, int $code = 0, ?\Throwable $previous = null): self { return new self( sprintf(_('Generation error on monitoring server #%d: %s'), $monitoringServerId, $errorMessage), $code, $previous, ); } /** * @param int $monitoringServerId * @param string $errorMessage * @return self */ public static function errorOnReload(int $monitoringServerId, string $errorMessage): self { return new self(sprintf(_('Reloading error on monitoring server #%d: %s'), $monitoringServerId, $errorMessage)); } /** * @param \Throwable $ex * @return self */ public static function errorRetrievingMonitoringServers(\Throwable $ex): self { return new self(_('Error on retrieving monitoring servers')); } /** * @param string $message * @return TimeoutException */ public static function timeout(int $monitoringServerId, string $message): TimeoutException { return new TimeoutException(sprintf(_('Error on monitoring server #%d: %s'), $monitoringServerId, $message)); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/MonitoringServer/Exception/MonitoringServerException.php
centreon/src/Centreon/Domain/MonitoringServer/Exception/MonitoringServerException.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\MonitoringServer\Exception; /** * @package Centreon\Domain\MonitoringServer\Exception */ class MonitoringServerException extends \Exception { }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/MonitoringServer/Exception/RealTimeMonitoringServerException.php
centreon/src/Centreon/Domain/MonitoringServer/Exception/RealTimeMonitoringServerException.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\MonitoringServer\Exception; /** * This class is designed to contain all exceptions for the context of the real time monitoring server. * * @package Centreon\Domain\MonitoringServer\Exception */ class RealTimeMonitoringServerException extends \Exception { /** * @param \Throwable $ex * @return self */ public static function findRealTimeMonitoringServersException(\Throwable $ex): self { return new self(_('Error when searching for real time monitoring servers'), 0, $ex); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/ServiceConfiguration/ServiceMacro.php
centreon/src/Centreon/Domain/ServiceConfiguration/ServiceMacro.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\ServiceConfiguration; use Centreon\Domain\Annotation\EntityDescriptor; use Centreon\Domain\Macro\Interfaces\MacroInterface; class ServiceMacro implements MacroInterface { /** @var int|null */ private $id; /** @var string|null Macro name */ private $name; /** @var string|null Macro value */ private $value; /** * @var bool Indicates whether this macro contains a password * @EntityDescriptor(column="is_password", modifier="setPassword") */ private $isPassword = false; /** @var string|null Macro description */ private $description; /** @var int|null */ private $order; /** @var int|null */ private $serviceId; /** * @return int|null */ public function getId(): ?int { return $this->id; } /** * @param int|null $id * @return self */ public function setId(?int $id): self { $this->id = $id; return $this; } /** * @return string|null */ public function getName(): ?string { return $this->name; } /** * @param string|null $name * @return self */ public function setName(?string $name): self { $patternToBeFound = '$_SERVICE'; if ($name !== null) { if (! str_starts_with($name, $patternToBeFound)) { $name = $patternToBeFound . $name; if ($name[-1] !== '$') { $name .= '$'; } } $this->name = strtoupper($name); } else { $this->name = null; } return $this; } /** * @return string|null */ public function getValue(): ?string { return $this->value; } /** * @param string|null $value * @return self */ public function setValue(?string $value): self { $this->value = $value; return $this; } /** * @return bool */ public function isPassword(): bool { return $this->isPassword; } /** * @param bool $isPassword * @return self */ public function setPassword(bool $isPassword): self { $this->isPassword = $isPassword; return $this; } /** * @return string|null */ public function getDescription(): ?string { return $this->description; } /** * @param string|null $description * @return self */ public function setDescription(?string $description): self { $this->description = $description; return $this; } /** * @return int|null */ public function getOrder(): ?int { return $this->order; } /** * @param int|null $order * @return self */ public function setOrder(?int $order): self { $this->order = $order; return $this; } /** * @return int|null */ public function getServiceId(): ?int { return $this->serviceId; } /** * @param int|null $serviceId * @return self */ public function setServiceId(?int $serviceId): self { $this->serviceId = $serviceId; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/ServiceConfiguration/ServiceConfigurationException.php
centreon/src/Centreon/Domain/ServiceConfiguration/ServiceConfigurationException.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\ServiceConfiguration; class ServiceConfigurationException extends \Exception { }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/ServiceConfiguration/Service.php
centreon/src/Centreon/Domain/ServiceConfiguration/Service.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\ServiceConfiguration; use Centreon\Domain\Annotation\EntityDescriptor; use Centreon\Domain\Common\Assertion\Assertion; /** * This class is designed to represent a service configuration. * * @package Centreon\Domain\ServiceConfiguration */ class Service { public const TYPE_TEMPLATE = 0; public const TYPE_SERVICE = 1; public const TYPE_META_SERVICE = 2; public const TYPE_BUSINESS_ACTIVITY = 2; public const TYPE_ANOMALY_DETECTION = 3; public const NOTIFICATIONS_OPTION_DISABLED = 0; public const NOTIFICATIONS_OPTION_ENABLED = 1; public const NOTIFICATIONS_OPTION_DEFAULT_ENGINE_VALUE = 2; private const AVAILABLE_NOTIFICATION_OPTIONS = [ self::NOTIFICATIONS_OPTION_DISABLED, self::NOTIFICATIONS_OPTION_ENABLED, self::NOTIFICATIONS_OPTION_DEFAULT_ENGINE_VALUE, ]; /** @var int|null */ private $id; /** @var int|null Template id */ private $templateId; /** @var int|null */ private $commandId; /** @var string|null Service alias */ private $alias; /** @var string|null Service description */ private $description; /** * @var bool Indicates whether or not this service is locked * @EntityDescriptor(column="is_locked", modifier="setLocked") */ private $isLocked = false; /** * @var int Service type * @see Service::TYPE_TEMPLATE (0) * @see Service::TYPE_SERVICE (1) * @see Service::TYPE_META_SERVICE (2) * @see Service::TYPE_BUSINESS_ACTIVITY (2) * @see Service::TYPE_ANOMALY_DETECTION (3) */ private $serviceType = self::TYPE_SERVICE; /** * @var bool Indicates whether or not this service is activated * @EntityDescriptor(column="is_activated", modifier="setActivated") */ private $isActivated = true; /** @var ExtendedService */ private $extendedService; /** @var int */ private $notificationsEnabledOption = self::NOTIFICATIONS_OPTION_DEFAULT_ENGINE_VALUE; public function __construct() { $this->extendedService = new ExtendedService(); } /** * @return int|null */ public function getId(): ?int { return $this->id; } /** * @param int|null $id * @return Service */ public function setId(?int $id): Service { $this->id = $id; return $this; } /** * @return int|null */ public function getTemplateId(): ?int { return $this->templateId; } /** * @param int|null $templateId * @return Service */ public function setTemplateId(?int $templateId): Service { $this->templateId = $templateId; return $this; } /** * @return int|null */ public function getCommandId(): ?int { return $this->commandId; } /** * @param int|null $commandId * @return Service */ public function setCommandId(?int $commandId): Service { $this->commandId = $commandId; return $this; } /** * @return string|null */ public function getAlias(): ?string { return $this->alias; } /** * @param string|null $alias * @return Service */ public function setAlias(?string $alias): Service { $this->alias = $alias; return $this; } /** * @return string|null */ public function getDescription(): ?string { return $this->description; } /** * @param string|null $description * @return Service */ public function setDescription(?string $description): Service { $this->description = $description; return $this; } /** * @return bool */ public function isLocked(): bool { return $this->isLocked; } /** * @param bool $isLocked * @return Service */ public function setLocked(bool $isLocked): Service { $this->isLocked = $isLocked; return $this; } /** * @return bool */ public function isActivated(): bool { return $this->isActivated; } /** * @param bool $isActivated * @return Service */ public function setActivated(bool $isActivated): Service { $this->isActivated = $isActivated; return $this; } /** * @return int */ public function getServiceType(): int { return $this->serviceType; } /** * @param int $serviceType * @throws \InvalidArgumentException When the service type is not recognized * @return $this * @see Service::serviceType */ public function setServiceType(int $serviceType): Service { $allowedServiceType = [ self::TYPE_TEMPLATE, self::TYPE_SERVICE, self::TYPE_META_SERVICE, self::TYPE_BUSINESS_ACTIVITY, self::TYPE_ANOMALY_DETECTION, ]; if (! in_array($serviceType, $allowedServiceType)) { throw new \InvalidArgumentException('This service type is not recognized'); } $this->serviceType = $serviceType; return $this; } /** * @return ExtendedService */ public function getExtendedService(): ExtendedService { return $this->extendedService; } /** * @param ExtendedService $extendedService * @return Service */ public function setExtendedService(ExtendedService $extendedService): Service { $this->extendedService = $extendedService; return $this; } /** * @return int */ public function getNotificationsEnabledOption(): int { return $this->notificationsEnabledOption; } /** * @param int $notificationsEnabledOption * @return self */ public function setNotificationsEnabledOption(int $notificationsEnabledOption): self { Assertion::inArray( $notificationsEnabledOption, self::AVAILABLE_NOTIFICATION_OPTIONS, 'Engine::notificationsEnabledOption', ); $this->notificationsEnabledOption = $notificationsEnabledOption; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/ServiceConfiguration/ServiceConfigurationService.php
centreon/src/Centreon/Domain/ServiceConfiguration/ServiceConfigurationService.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\ServiceConfiguration; use Centreon\Domain\Common\Assertion\Assertion; use Centreon\Domain\Engine\Interfaces\EngineConfigurationServiceInterface; use Centreon\Domain\HostConfiguration\Host; use Centreon\Domain\HostConfiguration\Interfaces\HostConfigurationServiceInterface; use Centreon\Domain\Log\LoggerTrait; use Centreon\Domain\Service\AbstractCentreonService; use Centreon\Domain\ServiceConfiguration\Exception\ServiceConfigurationServiceException; use Centreon\Domain\ServiceConfiguration\Interfaces\ServiceConfigurationRepositoryInterface; use Centreon\Domain\ServiceConfiguration\Interfaces\ServiceConfigurationServiceInterface; use Core\Security\AccessGroup\Application\Repository\ReadAccessGroupRepositoryInterface; class ServiceConfigurationService extends AbstractCentreonService implements ServiceConfigurationServiceInterface { use LoggerTrait; /** @var ServiceConfigurationRepositoryInterface */ private $serviceRepository; /** @var ReadAccessGroupRepositoryInterface */ private $accessGroupRepository; /** @var EngineConfigurationServiceInterface */ private $engineConfigurationService; /** @var HostConfigurationServiceInterface */ private $hostConfigurationService; /** * ServiceConfigurationService constructor. * * @param ServiceConfigurationRepositoryInterface $serviceConfigurationRepository * @param ReadAccessGroupRepositoryInterface $accessGroupRepository * @param HostConfigurationServiceInterface $hostConfigurationService * @param EngineConfigurationServiceInterface $engineConfigurationService */ public function __construct( ServiceConfigurationRepositoryInterface $serviceConfigurationRepository, ReadAccessGroupRepositoryInterface $accessGroupRepository, HostConfigurationServiceInterface $hostConfigurationService, EngineConfigurationServiceInterface $engineConfigurationService, ) { $this->serviceRepository = $serviceConfigurationRepository; $this->accessGroupRepository = $accessGroupRepository; $this->engineConfigurationService = $engineConfigurationService; $this->hostConfigurationService = $hostConfigurationService; } /** * {@inheritDoc} * @return ServiceConfigurationServiceInterface */ public function filterByContact($contact): ServiceConfigurationServiceInterface { parent::filterByContact($contact); $accessGroups = $this->accessGroupRepository->findByContact($contact); $this->serviceRepository ->setContact($contact) ->filterByAccessGroups($accessGroups); return $this; } /** * @inheritDoc */ public function applyServices(Host $host): void { $this->info('Apply services to host'); if ($host->getId() == null) { throw new ServiceConfigurationException(_('The host id cannot be null')); } $hostTemplates = $this->hostConfigurationService->findHostTemplatesRecursively($host); if (empty($hostTemplates)) { return; } $host->setTemplates($hostTemplates); /** * To avoid defining a service description with illegal characters, * we retrieve the engine configuration to retrieve the list of these characters. */ $engineConfiguration = $this->engineConfigurationService->findEngineConfigurationByHost($host); if ($engineConfiguration === null) { throw new ServiceConfigurationException(_('Unable to find the Engine configuration')); } /** * Find all host templates recursively and copy their id into the given list. * * **We only retrieve templates that are enabled.** * * @param Host $host host for which we will find all host template * @return int[] */ $extractHostTemplateIdsFromHost = function (Host $host) use (&$extractHostTemplateIdsFromHost): array { $hostTemplateIds = []; foreach ($host->getTemplates() as $hostTemplate) { if ($hostTemplate->isActivated() === false) { continue; } $hostTemplateIds[] = $hostTemplate->getId(); if (! empty($hostTemplate->getTemplates())) { // The recursive call here allow you to keep the priority orders of the host templates $hostTemplateIds = array_merge( $hostTemplateIds, $extractHostTemplateIdsFromHost($hostTemplate) ); } } return $hostTemplateIds; }; $hostTemplateIds = $extractHostTemplateIdsFromHost($host); /** * First, we will search for services already associated with the host to avoid creating a new one with * same service description. */ $serviceAlreadyExists = $this->findServicesByHost($host); /** * Then, we memorize the alias of service. * The service description is based on the alias of service template when it was created. */ $serviceAliasAlreadyUsed = []; foreach ($serviceAlreadyExists as $service) { $serviceAliasAlreadyUsed[] = $service->getDescription(); } /** * Then, we will search for all service templates associated with the host templates */ $hostTemplateServices = $this->findHostTemplateServices($hostTemplateIds); /** * Extract service templates associated to host template. * * **We retrieve service templates only from an enabled host template.** * * @param int $hostTemplateId Host template id for which we want to find the services templates * @return Service[] */ $extractServiceTemplatesByHostTemplate = function (int $hostTemplateId) use ($hostTemplateServices): array { $serviceTemplates = []; foreach ($hostTemplateServices as $hostTemplateService) { if ($hostTemplateService->getHostTemplate()->getId() === $hostTemplateId) { // Only if the host template is activated if ($hostTemplateService->getHostTemplate()->isActivated()) { $serviceTemplates[] = $hostTemplateService->getServiceTemplate(); } } } return $serviceTemplates; }; $servicesToBeCreated = []; /** * Then, we set aside the services to be created. * We must not have two services with the same description (alias of the service template). * The priority order is defined by the list of host templates. * We only retrieve the service templates that are activated. */ foreach ($hostTemplateIds as $hostTemplateId) { $serviceTemplates = $extractServiceTemplatesByHostTemplate($hostTemplateId); foreach ($serviceTemplates as $serviceTemplate) { if (! $serviceTemplate->isActivated()) { continue; } if ( $serviceTemplate->getAlias() !== null && ! in_array($serviceTemplate->getAlias(), $serviceAliasAlreadyUsed) ) { $serviceDescription = $engineConfiguration->removeIllegalCharacters($serviceTemplate->getAlias()); if (empty($serviceDescription)) { continue; } $serviceAliasAlreadyUsed[] = $serviceDescription; $serviceToBeCreated = (new Service()) ->setServiceType(Service::TYPE_SERVICE) ->setTemplateId($serviceTemplate->getId()) ->setDescription($serviceDescription) ->setActivated(true); $servicesToBeCreated[] = $serviceToBeCreated; } } } try { $this->debug('Service to be created', [], function () use ($servicesToBeCreated) { return array_map(function (Service $service) { return ['id' => $service->getId(), 'description' => $service->getDescription()]; }, $servicesToBeCreated); }); $this->serviceRepository->addServicesToHost($host, $servicesToBeCreated); } catch (\Throwable $ex) { $this->error($ex->getMessage()); throw new ServiceConfigurationException( sprintf( _('Error when adding services to the host %d'), $host->getId() ) ); } } /** * @inheritDoc */ public function findHostTemplateServices(array $hostTemplateIds): array { try { return $this->serviceRepository->findHostTemplateServices($hostTemplateIds); } catch (\Throwable $ex) { throw new ServiceConfigurationException( _('Error when searching for host and related service templates'), 0, $ex ); } } /** * @inheritDoc */ public function findService(int $serviceId): ?Service { try { return $this->serviceRepository->findService($serviceId); } catch (\Throwable $ex) { throw new ServiceConfigurationException(_('Error while searching for the service'), 0, $ex); } } /** * @inheritDoc */ public function findServicesByHost(Host $host): array { try { return $this->serviceRepository->findServicesByHost($host); } catch (\Throwable $ex) { throw new ServiceConfigurationException(_('Error when searching for services by host'), 0, $ex); } } /** * @inheritDoc */ public function findCommandLine(int $serviceId): ?string { try { return $this->serviceRepository->findCommandLine($serviceId); } catch (\Throwable $ex) { throw new ServiceConfigurationException(_('Error while searching for the command of service'), 0, $ex); } } /** * @inheritDoc */ public function findOnDemandServiceMacros(int $serviceId, bool $isUsingInheritance = false): array { try { return $this->serviceRepository->findOnDemandServiceMacros($serviceId, $isUsingInheritance); } catch (\Throwable $ex) { throw new ServiceConfigurationException(_('Error while searching for the service macros'), 0, $ex); } } /** * @inheritDoc */ public function findServiceMacrosFromCommandLine(int $serviceId, string $command): array { $serviceMacros = []; if (preg_match_all('/(\$_SERVICE\S+?\$)/', $command, $matches)) { $matchedMacros = $matches[0]; foreach ($matchedMacros as $matchedMacroName) { $hostMacros[$matchedMacroName] = (new ServiceMacro()) ->setName($matchedMacroName) ->setValue(''); } $linkedServiceMacros = $this->findOnDemandServiceMacros($serviceId, true); foreach ($linkedServiceMacros as $linkedServiceMacro) { if (in_array($linkedServiceMacro->getName(), $matchedMacros)) { $serviceMacros[$linkedServiceMacro->getName()] = $linkedServiceMacro; } } } return array_values($serviceMacros); } /** * @return HostConfigurationServiceInterface */ public function getHostConfigurationService(): HostConfigurationServiceInterface { return $this->hostConfigurationService; } /** * @param Host $host * @throws \Assert\AssertionFailedException * @throws ServiceConfigurationServiceException */ public function removeServices(Host $host): void { Assertion::notNull($host->getId(), 'Host::id'); try { $this->debug('Remove services from a host', ['host_id' => $host->getId()]); $this->serviceRepository->removeServicesOnHost($host->getId()); } catch (\Throwable $ex) { $this->error( sprintf( _('Error on removing services from the host #%d (Reason: %s)'), $host->getId(), $ex->getMessage() ) ); throw ServiceConfigurationServiceException::errorOnRemovingServicesFromHost($host->getId()); } } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/ServiceConfiguration/ExtendedService.php
centreon/src/Centreon/Domain/ServiceConfiguration/ExtendedService.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\ServiceConfiguration; /** * This class is designed to represent extended service information. * * @package Centreon\Domain\ServiceConfiguration * @see Service */ class ExtendedService { /** @var int|null */ private $id; /** @var string|null */ private $notes; /** @var string|null */ private $notesUrl; /** @var string|null */ private $actionUrl; /** @var int|null Icon id associated to service */ private $iconId; /** @var string|null */ private $iconAlternativeText; /** @var int|null */ private $graphId; /** * @return int|null */ public function getId(): ?int { return $this->id; } /** * @param int|null $id * @return ExtendedService */ public function setId(?int $id): ExtendedService { $this->id = $id; return $this; } /** * @return string|null */ public function getNotes(): ?string { return $this->notes; } /** * @param string|null $notes * @return ExtendedService */ public function setNotes(?string $notes): ExtendedService { $this->notes = $notes; return $this; } /** * @return string|null */ public function getNotesUrl(): ?string { return $this->notesUrl; } /** * @param string|null $notesUrl * @return ExtendedService */ public function setNotesUrl(?string $notesUrl): ExtendedService { $this->notesUrl = $notesUrl; return $this; } /** * @return string|null */ public function getActionUrl(): ?string { return $this->actionUrl; } /** * @param string|null $actionUrl * @return ExtendedService */ public function setActionUrl(?string $actionUrl): ExtendedService { $this->actionUrl = $actionUrl; return $this; } /** * @return int|null */ public function getIconId(): ?int { return $this->iconId; } /** * @param int|null $iconId * @return ExtendedService */ public function setIconId(?int $iconId): ExtendedService { $this->iconId = $iconId; return $this; } /** * @return string|null */ public function getIconAlternativeText(): ?string { return $this->iconAlternativeText; } /** * @param string|null $iconAlternativeText * @return ExtendedService */ public function setIconAlternativeText(?string $iconAlternativeText): ExtendedService { $this->iconAlternativeText = $iconAlternativeText; return $this; } /** * @return int|null */ public function getGraphId(): ?int { return $this->graphId; } /** * @param int|null $graphId * @return ExtendedService */ public function setGraphId(?int $graphId): ExtendedService { $this->graphId = $graphId; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/ServiceConfiguration/HostTemplateService.php
centreon/src/Centreon/Domain/ServiceConfiguration/HostTemplateService.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\ServiceConfiguration; use Centreon\Domain\HostConfiguration\Host; /** * This class is designed to represent a service template associated to a host template * * @package Centreon\Domain\ServiceConfiguration */ class HostTemplateService { /** @var Host */ private $hostTemplate; /** @var Service */ private $serviceTemplate; /** * @return Host */ public function getHostTemplate(): Host { return $this->hostTemplate; } /** * @param Host $hostTemplate * @return HostTemplateService */ public function setHostTemplate(Host $hostTemplate): HostTemplateService { if ($hostTemplate->getType() !== Host::TYPE_HOST_TEMPLATE) { throw new \InvalidArgumentException('This host is not a template'); } $this->hostTemplate = $hostTemplate; return $this; } /** * @return Service */ public function getServiceTemplate(): Service { return $this->serviceTemplate; } /** * @param Service $serviceTemplate * @return HostTemplateService */ public function setServiceTemplate(Service $serviceTemplate): HostTemplateService { if ($serviceTemplate->getServiceType() !== Service::TYPE_TEMPLATE) { throw new \InvalidArgumentException('This service is not a template'); } $this->serviceTemplate = $serviceTemplate; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/ServiceConfiguration/Interfaces/ServiceConfigurationRepositoryInterface.php
centreon/src/Centreon/Domain/ServiceConfiguration/Interfaces/ServiceConfigurationRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\ServiceConfiguration\Interfaces; use Centreon\Domain\AccessControlList\Interfaces\AccessControlListRepositoryInterface; use Centreon\Domain\HostConfiguration\Host; use Centreon\Domain\ServiceConfiguration\HostTemplateService; use Centreon\Domain\ServiceConfiguration\Service; use Centreon\Domain\ServiceConfiguration\ServiceMacro; interface ServiceConfigurationRepositoryInterface extends AccessControlListRepositoryInterface { /** * Add services to host. * * @param Host $host Host for which we want to add services * @param Service[] $servicesToBeCreated Services to be created * @throws \Throwable */ public function addServicesToHost(Host $host, array $servicesToBeCreated): void; /** * Find all service macros for the service. * * @param int $serviceId Id of the service * @param bool $isUsingInheritance Indicates whether to use inheritance to find service macros (FALSE by default) * @throws \Throwable * @return array<ServiceMacro> List of service macros found */ public function findOnDemandServiceMacros(int $serviceId, bool $isUsingInheritance = false): array; /** * Find the command of a service. * * A recursive search will be performed in the inherited templates in the * case where the service does not have a command. * * @param int $serviceId Service id * @throws \Throwable * @return string|null Return the command if found */ public function findCommandLine(int $serviceId): ?string; /** * Find all service templates associated with the given host templates. * * @param int[] $hostTemplateIds Ids of the host templates for which we want to find the service templates * @throws \Exception * @return HostTemplateService[] */ public function findHostTemplateServices(array $hostTemplateIds): array; /** * Find a service. * * @param int $serviceId Service id * @throws \Exception * @return Service|null */ public function findService(int $serviceId): ?Service; /** * Find all services associated to host. * * @param Host $host Host for which we want to find services * @throws \Exception * @return Service[] */ public function findServicesByHost(Host $host): array; /** * Removes all services related to a host. * * @param int $hostId * @throws \Exception */ public function removeServicesOnHost(int $hostId): void; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/ServiceConfiguration/Interfaces/ServiceConfigurationServiceInterface.php
centreon/src/Centreon/Domain/ServiceConfiguration/Interfaces/ServiceConfigurationServiceInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\ServiceConfiguration\Interfaces; use Centreon\Domain\Contact\Interfaces\ContactFilterInterface; use Centreon\Domain\Engine\EngineException; use Centreon\Domain\HostConfiguration\Host; use Centreon\Domain\HostConfiguration\HostConfigurationException; use Centreon\Domain\ServiceConfiguration\HostTemplateService; use Centreon\Domain\ServiceConfiguration\Service; use Centreon\Domain\ServiceConfiguration\ServiceConfigurationException; use Centreon\Domain\ServiceConfiguration\ServiceMacro; interface ServiceConfigurationServiceInterface extends ContactFilterInterface { /** * Applies the services according to the host templates associated with the given host and their priorities. * * @param Host $host Host for which we want to apply the services * @throws ServiceConfigurationException * @throws HostConfigurationException * @throws EngineException */ public function applyServices(Host $host): void; /** * Find all service templates associated with the given host templates. * * @param int[] $hostTemplateIds Ids of the host templates for which we want to find the service templates * @throws ServiceConfigurationException * @return HostTemplateService[] */ public function findHostTemplateServices(array $hostTemplateIds): array; /** * Find all service macros for the service. * * @param int $serviceId Id of the service * @param bool $isUsingInheritance Indicates whether to use inheritance to find service macros (FALSE by default) * @throws ServiceConfigurationException * @return ServiceMacro[] List of service macros found */ public function findOnDemandServiceMacros(int $serviceId, bool $isUsingInheritance = false): array; /** * Find a service. * * @param int $serviceId Service id * @throws ServiceConfigurationException * @return Service|null */ public function findService(int $serviceId): ?Service; /** * Find all services associated to host. * * @param Host $host Host for which we want to find services * @throws ServiceConfigurationException * @return Service[] */ public function findServicesByHost(Host $host): array; /** * Find all on-demand service macros needed for this command. * * @param int $serviceId Service id * @param string $command Command to analyse * @throws ServiceConfigurationException * @return ServiceMacro[] List of service macros */ public function findServiceMacrosFromCommandLine(int $serviceId, string $command): array; /** * Find the command of a service. * * @param int $serviceId Service id * @throws ServiceConfigurationException * @return string|null Return the command if found */ public function findCommandLine(int $serviceId): ?string; /** * Removes all services related to a host. * * @param Host $host * @throws ServiceConfigurationException * @throws \Assert\AssertionFailedException */ public function removeServices(Host $host): void; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/ServiceConfiguration/Exception/ServiceCommandException.php
centreon/src/Centreon/Domain/ServiceConfiguration/Exception/ServiceCommandException.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\ServiceConfiguration\Exception; /** * This class is designed to contain all exceptions for the context of the service command. * * @package Centreon\Domain\HostConfiguration\Exception */ class ServiceCommandException extends \Exception { /** * @param int $serviceId * @return self */ public static function notFound(int $serviceId): self { return new self( sprintf(_('Check command of service id %d not found'), $serviceId) ); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/ServiceConfiguration/Exception/ServiceConfigurationServiceException.php
centreon/src/Centreon/Domain/ServiceConfiguration/Exception/ServiceConfigurationServiceException.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\ServiceConfiguration\Exception; class ServiceConfigurationServiceException extends \Exception { /** * @param int $hostId * @return self */ public static function errorOnRemovingServicesFromHost(int $hostId): self { return new self(sprintf(_('Error on removing services from the host #%d'), $hostId)); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Check/CheckService.php
centreon/src/Centreon/Domain/Check/CheckService.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Check; use Centreon\Domain\Check\Interfaces\CheckServiceInterface; use Centreon\Domain\Contact\Contact; use Centreon\Domain\Engine\Interfaces\EngineServiceInterface; use Centreon\Domain\Entity\EntityValidator; use Centreon\Domain\Exception\EntityNotFoundException; use Centreon\Domain\Monitoring\Interfaces\MonitoringRepositoryInterface; use Centreon\Domain\Monitoring\Resource as ResourceEntity; use Centreon\Domain\Monitoring\ResourceService; use Centreon\Domain\Service\AbstractCentreonService; use Core\Security\AccessGroup\Application\Repository\ReadAccessGroupRepositoryInterface; use JMS\Serializer\Exception\ValidationFailedException; class CheckService extends AbstractCentreonService implements CheckServiceInterface { /** @var EngineServiceInterface used to send external commands to engine */ private $engineService; /** @var EntityValidator */ private $validator; /** @var MonitoringRepositoryInterface */ private $monitoringRepository; /** @var ReadAccessGroupRepositoryInterface */ private $accessGroupRepository; /** * CheckService constructor. * * @param ReadAccessGroupRepositoryInterface $accessGroupRepository * @param MonitoringRepositoryInterface $monitoringRepository * @param EngineServiceInterface $engineService * @param EntityValidator $validator */ public function __construct( ReadAccessGroupRepositoryInterface $accessGroupRepository, MonitoringRepositoryInterface $monitoringRepository, EngineServiceInterface $engineService, EntityValidator $validator, ) { $this->accessGroupRepository = $accessGroupRepository; $this->monitoringRepository = $monitoringRepository; $this->engineService = $engineService; $this->validator = $validator; } /** * {@inheritDoc} * @param Contact $contact * @return CheckServiceInterface */ public function filterByContact($contact): CheckServiceInterface { parent::filterByContact($contact); $this->engineService->filterByContact($contact); $accessGroups = $this->accessGroupRepository->findByContact($contact); $this->monitoringRepository ->setContact($contact) ->filterByAccessGroups($accessGroups); return $this; } /** * @inheritDoc */ public function checkHost(Check $check): void { // We validate the check instance $errors = $this->validator->validate( $check, null, Check::VALIDATION_GROUPS_HOST_CHECK ); if ($errors->count() > 0) { throw new ValidationFailedException($errors); } $host = $this->monitoringRepository->findOneHost($check->getResourceId()); if (is_null($host)) { throw new EntityNotFoundException(_('Host not found')); } $this->engineService->scheduleHostCheck($check, $host); } /** * @inheritDoc */ public function checkService(Check $check): void { // We validate the check instance $errors = $this->validator->validate( $check, null, Check::VALIDATION_GROUPS_SERVICE_CHECK ); if ($errors->count() > 0) { throw new ValidationFailedException($errors); } $host = $this->monitoringRepository->findOneHost($check->getParentResourceId()); if (is_null($host)) { throw new EntityNotFoundException(_('Host not found')); } $service = $this->monitoringRepository->findOneService($check->getParentResourceId(), $check->getResourceId()); if (is_null($service)) { throw new EntityNotFoundException(_('Service not found')); } $service->setHost($host); $this->engineService->scheduleServiceCheck($check, $service); } /** * @inheritDoc */ public function checkMetaService(Check $check): void { // We validate the check instance $errors = $this->validator->validate( $check, null, Check::VALIDATION_GROUPS_META_SERVICE_CHECK ); if ($errors->count() > 0) { throw new ValidationFailedException($errors); } $metaServiceDescription = 'meta_' . $check->getResourceId(); $service = $this->monitoringRepository->findOneServiceByDescription($metaServiceDescription); if (is_null($service)) { throw new EntityNotFoundException(_('Meta service not found')); } $host = $this->monitoringRepository->findOneHost($service->getHost()->getId()); if (is_null($host)) { throw new EntityNotFoundException(_('Host not found')); } $service->setHost($host); $this->engineService->scheduleServiceCheck($check, $service); } /** * @inheritDoc */ public function checkResource(Check $check, ResourceEntity $resource): void { switch ($resource->getType()) { case ResourceEntity::TYPE_HOST: $host = $this->monitoringRepository->findOneHost(ResourceService::generateHostIdByResource($resource)); if (is_null($host)) { throw new EntityNotFoundException( sprintf( _('Host %d not found'), $resource->getId() ) ); } $this->engineService->scheduleHostCheck($check, $host); break; case ResourceEntity::TYPE_SERVICE: $host = $this->monitoringRepository->findOneHost(ResourceService::generateHostIdByResource($resource)); $service = $this->monitoringRepository->findOneService( $resource->getParent()->getId(), $resource->getId() ); if (is_null($service)) { throw new EntityNotFoundException( sprintf( _('Service %d (parent: %d) not found'), $resource->getId(), $resource->getParent()->getId() ) ); } $service->setHost($host); $this->engineService->scheduleServiceCheck($check, $service); break; case ResourceEntity::TYPE_META: $service = $this->monitoringRepository->findOneServiceByDescription('meta_' . $resource->getId()); if (is_null($service)) { throw new EntityNotFoundException( sprintf( _('Service %d (parent: %d) not found'), $resource->getId(), $resource->getParent()->getId() ) ); } $host = $this->monitoringRepository->findOneHost($service->getHost()->getId()); $service->setHost($host); $this->engineService->scheduleServiceCheck($check, $service); break; default: throw new \InvalidArgumentException(sprintf(_('Incorrect Resource type: %s'), $resource->getType())); } } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Check/Check.php
centreon/src/Centreon/Domain/Check/Check.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Check; class Check { public const VALIDATION_GROUPS_HOST_CHECK = ['check_host']; public const VALIDATION_GROUPS_SERVICE_CHECK = ['check_service']; public const VALIDATION_GROUPS_META_SERVICE_CHECK = ['check_meta_service']; /** @var int Resource id */ private $resourceId; /** @var int|null Parent resource id */ private $parentResourceId; /** @var \DateTime */ private $checkTime; /** @var bool */ private $isForced = false; /** @var bool Indicates if this downtime should be applied to linked services */ private $withServices = false; /** * @return int */ public function getResourceId(): int { return $this->resourceId; } /** * @param int $resourceId * @return Check */ public function setResourceId(int $resourceId): Check { $this->resourceId = $resourceId; return $this; } /** * @return int */ public function getParentResourceId(): ?int { return $this->parentResourceId; } /** * @param int|null $parentResourceId * @return Check */ public function setParentResourceId(?int $parentResourceId): Check { $this->parentResourceId = $parentResourceId; return $this; } /** * @return \DateTime|null */ public function getCheckTime(): ?\DateTime { return $this->checkTime; } /** * @param \DateTime|null $checkTime * @return Check */ public function setCheckTime(?\DateTime $checkTime): Check { $this->checkTime = $checkTime; return $this; } /** * @return bool */ public function isForced(): bool { return $this->isForced; } /** * @param bool $isForced * @return Check */ public function setForced(bool $isForced): Check { $this->isForced = $isForced; return $this; } /** * @return bool */ public function isWithServices(): bool { return $this->withServices; } /** * @param bool $withServices */ public function setWithServices(bool $withServices): void { $this->withServices = $withServices; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Check/CheckException.php
centreon/src/Centreon/Domain/Check/CheckException.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Check; class CheckException extends \RuntimeException { }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Check/Interfaces/CheckServiceInterface.php
centreon/src/Centreon/Domain/Check/Interfaces/CheckServiceInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Check\Interfaces; use Centreon\Domain\Check\Check; use Centreon\Domain\Contact\Interfaces\ContactFilterInterface; use Centreon\Domain\Engine\EngineException; use Centreon\Domain\Exception\EntityNotFoundException; use Centreon\Domain\Monitoring\Resource as ResourceEntity; use JMS\Serializer\Exception\ValidationFailedException; interface CheckServiceInterface extends ContactFilterInterface { /** * Adds a host check. * * @param Check $check Host check to schedule * @throws EngineException * @throws EntityNotFoundException * @throws \Exception * @throws ValidationFailedException */ public function checkHost(Check $check): void; /** * Adds a service check. * * @param Check $check Service check to schedule * @throws EngineException * @throws EntityNotFoundException * @throws \Exception * @throws ValidationFailedException */ public function checkService(Check $check): void; /** * Adds a Meta service check. * * @param Check $check Meta Service check to schedule * @throws EngineException * @throws EntityNotFoundException * @throws \Exception * @throws ValidationFailedException */ public function checkMetaService(Check $check): void; /** * Adds a resource check. * * @param Check $check * @param ResourceEntity $resource * @throws EntityNotFoundException * @throws \Exception * @return void */ public function checkResource(Check $check, ResourceEntity $resource): void; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Menu/MenuService.php
centreon/src/Centreon/Domain/Menu/MenuService.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Menu; use Centreon\Domain\Menu\Interfaces\MenuRepositoryInterface; use Centreon\Domain\Menu\Interfaces\MenuServiceInterface; use Centreon\Domain\Menu\Model\Page; class MenuService implements MenuServiceInterface { /** @var MenuRepositoryInterface */ private $menuRepository; public function __construct(MenuRepositoryInterface $menuRepository) { $this->menuRepository = $menuRepository; } /** * @inheritDoc */ public function findPageByTopologyPageNumber(int $pageNumber): ?Page { return $this->menuRepository->findPageByTopologyPageNumber($pageNumber); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Menu/MenuException.php
centreon/src/Centreon/Domain/Menu/MenuException.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Menu; /** * This class is designed to represent a business exception in the 'Platform information' context. * * @package Centreon\Domain\PlatformInformation */ class MenuException extends \Exception { }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Menu/Model/Page.php
centreon/src/Centreon/Domain/Menu/Model/Page.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Menu\Model; class Page { public const LEGACY_PAGE_BASE_URI = '/main.php?p='; /** @var int */ private $id; /** @var string */ private $url; /** @var string|null */ private $urlOptions; /** @var int */ private $pageNumber; /** @var bool */ private $isReact; public function __construct(int $id, string $url, int $pageNumber, bool $isReact = false) { $this->id = $id; $this->url = $url; $this->pageNumber = $pageNumber; $this->isReact = $isReact; } /** * @return int */ public function getId(): int { return $this->id; } /** * @return string */ public function getUrl(): string { return $this->url; } /** * @return string|null */ public function getUrlOptions(): ?string { return $this->urlOptions; } /** * @param string|null $urlOptions * @return self */ public function setUrlOptions(?string $urlOptions): self { $this->urlOptions = $urlOptions; return $this; } /** * @return int */ public function getPageNumber(): int { return $this->pageNumber; } /** * @return bool */ public function isReact(): bool { return $this->isReact; } /** * Return the redirection uri of the page. * * @return string */ public function getRedirectionUri(): string { if ($this->isReact) { return $this->url; } $redirectionUri = self::LEGACY_PAGE_BASE_URI . $this->pageNumber; if ($this->urlOptions !== null) { $redirectionUri .= $this->urlOptions; } return $redirectionUri; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Menu/Interfaces/MenuServiceInterface.php
centreon/src/Centreon/Domain/Menu/Interfaces/MenuServiceInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Menu\Interfaces; use Centreon\Domain\Menu\Model\Page; interface MenuServiceInterface { /** * Find a Page by its topology Page Number * * @param int $pageNumber * @return Page|null */ public function findPageByTopologyPageNumber(int $pageNumber): ?Page; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Menu/Interfaces/MenuRepositoryInterface.php
centreon/src/Centreon/Domain/Menu/Interfaces/MenuRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Menu\Interfaces; use Centreon\Domain\Menu\Model\Page; interface MenuRepositoryInterface { /** * Disable Centreon Web Menu * * @return void */ public function disableCentralMenus(): void; /** * Enable Centreon Web Menu * * @return void */ public function enableCentralMenus(): void; /** * Find a Page by its topology page number. * * @param int $pageNumber * @return Page */ public function findPageByTopologyPageNumber(int $pageNumber): ?Page; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Monitoring/ResourceExternalLinks.php
centreon/src/Centreon/Domain/Monitoring/ResourceExternalLinks.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Monitoring; /** * Resource external Links model for resource repository * * @package Centreon\Domain\Monitoring */ class ResourceExternalLinks { /** @var string|null */ private $actionUrl; /** @var Notes|null */ private $notes; /** * @return string|null */ public function getActionUrl(): ?string { return $this->actionUrl; } /** * @param string|null $actionUrl * @return self */ public function setActionUrl(?string $actionUrl): self { $this->actionUrl = $actionUrl; return $this; } /** * @return Notes|null */ public function getNotes(): ?Notes { return $this->notes; } /** * @param Notes|null $notes * @return self */ public function setNotes(?Notes $notes): self { $this->notes = $notes; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Monitoring/ResourceFilter.php
centreon/src/Centreon/Domain/Monitoring/ResourceFilter.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Monitoring; /** * Filter model for resource repository. */ class ResourceFilter { public const TYPE_SERVICE = 'service'; public const TYPE_HOST = 'host'; public const TYPE_META = 'metaservice'; /** * Non-ok status in hard state , not acknowledged & not in downtime. */ public const STATE_UNHANDLED_PROBLEMS = 'unhandled_problems'; /** * Non-ok status in hard state. */ public const STATE_RESOURCES_PROBLEMS = 'resources_problems'; /** * Resources in downtime. */ public const STATE_IN_DOWNTIME = 'in_downtime'; /** * Acknowledged resources. */ public const STATE_ACKNOWLEDGED = 'acknowledged'; public const STATE_IN_FLAPPING = 'in_flapping'; /** * All status & resources. */ public const STATE_ALL = 'all'; public const STATUS_OK = 'OK'; public const STATUS_UP = 'UP'; public const STATUS_WARNING = 'WARNING'; public const STATUS_DOWN = 'DOWN'; public const STATUS_CRITICAL = 'CRITICAL'; public const STATUS_UNREACHABLE = 'UNREACHABLE'; public const STATUS_UNKNOWN = 'UNKNOWN'; public const STATUS_PENDING = 'PENDING'; /** * Available state types. */ public const HARD_STATUS_TYPE = 'hard'; public const SOFT_STATUS_TYPE = 'soft'; public const MAP_STATUS_SERVICE = [ self::STATUS_OK => 0, self::STATUS_WARNING => 1, self::STATUS_CRITICAL => 2, self::STATUS_UNKNOWN => 3, self::STATUS_PENDING => 4, ]; public const MAP_STATUS_HOST = [ self::STATUS_UP => 0, self::STATUS_DOWN => 1, self::STATUS_UNREACHABLE => 2, self::STATUS_PENDING => 4, ]; public const MAP_STATUS_TYPES = [ self::HARD_STATUS_TYPE => 1, self::SOFT_STATUS_TYPE => 0, ]; /** @var string[] */ private $types = []; /** @var string[] */ private $states = []; /** @var string[] */ private $statuses = []; /** @var string[] */ private $hostgroupNames = []; /** @var string[] */ private $servicegroupNames = []; /** @var string[] */ private $monitoringServerNames = []; /** @var string[] */ private $serviceCategoryNames = []; /** @var string[] */ private $hostCategoryNames = []; /** @var int[] */ private $hostIds = []; /** @var int[] */ private $serviceIds = []; /** @var int[] */ private $metaServiceIds = []; /** @var bool */ private $onlyWithPerformanceData = false; /** @var string[] */ private $statusTypes = []; /** @var string[] */ private array $serviceSeverityNames = []; /** @var string[] */ private array $hostSeverityNames = []; /** @var int[] */ private array $serviceSeverityLevels = []; /** @var int[] */ private array $hostSeverityLevels = []; /** * Dedicated to open-tickets. * * @var int|null */ private ?int $ruleId = null; /** * Dedicated to open-tickets. * * @var bool */ private bool $onlyWithTicketsOpened = false; /** * Transform result by map. * * @param array<mixed, mixed> $list * @param array<mixed, mixed> $map * * @return array<int, mixed> */ public static function map(array $list, array $map): array { $result = []; foreach ($list as $value) { if (! array_key_exists($value, $map)) { continue; } $result[] = $map[$value]; } return $result; } /** * @param string $type * * @return bool */ public function hasType(string $type): bool { return in_array($type, $this->types, true); } /** * @return string[] */ public function getTypes(): array { return $this->types; } /** * @param string[] $types * * @return ResourceFilter */ public function setTypes(array $types): self { $this->types = $types; return $this; } /** * @param string $state * * @return bool */ public function hasState(string $state): bool { return in_array($state, $this->states, true); } /** * @return string[] */ public function getStates(): array { return $this->states; } /** * @param string[] $states * * @return ResourceFilter */ public function setStates(array $states): self { $this->states = $states; return $this; } /** * @param string $status * * @return bool */ public function hasStatus(string $status): bool { return in_array($status, $this->statuses, true); } /** * @return string[] */ public function getStatuses(): array { return $this->statuses; } /** * @param string[] $statuses * * @return ResourceFilter */ public function setStatuses(array $statuses): self { $this->statuses = $statuses; return $this; } /** * @return string[] */ public function getHostgroupNames(): array { return $this->hostgroupNames; } /** * @param string[] $hostgroupNames * * @return ResourceFilter */ public function setHostgroupNames(array $hostgroupNames): self { $this->hostgroupNames = $hostgroupNames; return $this; } /** * @return string[] */ public function getMonitoringServerNames(): array { return $this->monitoringServerNames; } /** * @param string[] $monitoringServerNames * * @return ResourceFilter */ public function setMonitoringServerNames(array $monitoringServerNames): self { $this->monitoringServerNames = $monitoringServerNames; return $this; } /** * @return string[] */ public function getServicegroupNames(): array { return $this->servicegroupNames; } /** * @param string[] $servicegroupNames * * @return ResourceFilter */ public function setServicegroupNames(array $servicegroupNames): self { $this->servicegroupNames = $servicegroupNames; return $this; } /** * @return int[] */ public function getHostIds(): array { return $this->hostIds; } /** * @param int[] $hostIds * * @return ResourceFilter */ public function setHostIds(array $hostIds): self { foreach ($hostIds as $hostId) { if (! is_int($hostId)) { throw new \InvalidArgumentException('Host ids must be an array of integers'); } } $this->hostIds = $hostIds; return $this; } /** * @return int[] */ public function getServiceIds(): array { return $this->serviceIds; } /** * @param int[] $serviceIds * * @return ResourceFilter */ public function setServiceIds(array $serviceIds): self { foreach ($serviceIds as $serviceId) { if (! is_int($serviceId)) { throw new \InvalidArgumentException('Service ids must be an array of integers'); } } $this->serviceIds = $serviceIds; return $this; } /** * @return int[] */ public function getMetaServiceIds(): array { return $this->metaServiceIds; } /** * @param int[] $metaServiceIds * * @return ResourceFilter */ public function setMetaServiceIds(array $metaServiceIds): self { foreach ($metaServiceIds as $metaServiceId) { if (! is_int($metaServiceId)) { throw new \InvalidArgumentException('Meta Service ids must be an array of integers'); } } $this->metaServiceIds = $metaServiceIds; return $this; } /** * @param bool $onlyWithPerformanceData * * @return ResourceFilter */ public function setOnlyWithPerformanceData(bool $onlyWithPerformanceData): self { $this->onlyWithPerformanceData = $onlyWithPerformanceData; return $this; } /** * @return bool */ public function getOnlyWithPerformanceData(): bool { return $this->onlyWithPerformanceData; } /** * @return string[] */ public function getStatusTypes(): array { return $this->statusTypes; } /** * @param string[] $statusTypes * * @return self */ public function setStatusTypes(array $statusTypes): self { $this->statusTypes = $statusTypes; return $this; } /** * @param string[] $serviceCategoryNames * * @return self */ public function setServiceCategoryNames(array $serviceCategoryNames): self { $this->serviceCategoryNames = $serviceCategoryNames; return $this; } /** * @param string[] $serviceSeverityNames * * @return self */ public function setServiceSeverityNames(array $serviceSeverityNames): self { $this->serviceSeverityNames = $serviceSeverityNames; return $this; } /** * @return string[] */ public function getServiceCategoryNames(): array { return $this->serviceCategoryNames; } /** * @param string[] $hostCategoryNames * * @return self */ public function setHostCategoryNames(array $hostCategoryNames): self { $this->hostCategoryNames = $hostCategoryNames; return $this; } /** * @return array<int, string> */ public function getServiceSeverityNames(): array { return $this->serviceSeverityNames; } /** * @param string[] $hostSeverityNames * * @return self */ public function setHostSeverityNames(array $hostSeverityNames): self { $this->hostSeverityNames = $hostSeverityNames; return $this; } /** * @return string[] */ public function getHostCategoryNames(): array { return $this->hostCategoryNames; } /** * @return string[] */ public function getHostSeverityNames(): array { return $this->hostSeverityNames; } /** * @param int[] $serviceSeverityLevels * * @return self */ public function setServiceSeverityLevels(array $serviceSeverityLevels): self { $this->serviceSeverityLevels = $serviceSeverityLevels; return $this; } /** * @return int[] */ public function getServiceSeverityLevels(): array { return $this->serviceSeverityLevels; } /** * @param int[] $hostSeverityLevels * * @return self */ public function setHostSeverityLevels(array $hostSeverityLevels): self { $this->hostSeverityLevels = $hostSeverityLevels; return $this; } /** * @return int[] */ public function getHostSeverityLevels(): array { return $this->hostSeverityLevels; } /** * @param null|int $ruleId * * @return self */ public function setRuleId(?int $ruleId): self { $this->ruleId = $ruleId; return $this; } /** * @return int|null */ public function getRuleId(): ?int { return $this->ruleId; } /** * @param bool $onlyWithTicketsOpened * * @return self */ public function setOnlyWithTicketsOpened(bool $onlyWithTicketsOpened): self { $this->onlyWithTicketsOpened = $onlyWithTicketsOpened; return $this; } /** * @return bool */ public function getOnlyWithTicketsOpened(): bool { return $this->onlyWithTicketsOpened; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Monitoring/ResourceLinksEndpoints.php
centreon/src/Centreon/Domain/Monitoring/ResourceLinksEndpoints.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Monitoring; /** * Resource Links Endpoints model for resource repository. */ class ResourceLinksEndpoints { /** @var string|null */ private ?string $details = null; /** @var string|null */ private ?string $timeline = null; /** @var string|null */ private ?string $statusGraph = null; /** @var string|null */ private ?string $performanceGraph = null; /** @var string|null */ private ?string $acknowledgement = null; /** @var string|null */ private ?string $downtime = null; /** @var string|null */ private ?string $metrics = null; /** @var string|null */ private ?string $notificationPolicy = null; /** @var string|null */ private ?string $check = null; /** @var string|null */ private ?string $forcedCheck = null; /** * @return string|null */ public function getDetails(): ?string { return $this->details; } /** * @param string|null $details * * @return self */ public function setDetails(?string $details): self { $this->details = $details; return $this; } /** * @return string|null */ public function getTimeline(): ?string { return $this->timeline; } /** * @param string|null $timeline * * @return self */ public function setTimeline(?string $timeline): self { $this->timeline = $timeline; return $this; } /** * @return string|null */ public function getStatusGraph(): ?string { return $this->statusGraph; } /** * @param string|null $statusGraph * * @return self */ public function setStatusGraph(?string $statusGraph): self { $this->statusGraph = $statusGraph; return $this; } /** * @return string|null */ public function getPerformanceGraph(): ?string { return $this->performanceGraph; } /** * @param string|null $performanceGraph * * @return self */ public function setPerformanceGraph(?string $performanceGraph): self { $this->performanceGraph = $performanceGraph; return $this; } /** * @return string|null */ public function getAcknowledgement(): ?string { return $this->acknowledgement; } /** * @param string|null $acknowledgement * * @return self */ public function setAcknowledgement(?string $acknowledgement): self { $this->acknowledgement = $acknowledgement; return $this; } /** * @return string|null */ public function getDowntime(): ?string { return $this->downtime; } /** * @param string|null $downtime * * @return self */ public function setDowntime(?string $downtime): self { $this->downtime = $downtime; return $this; } /** * @return string|null */ public function getMetrics(): ?string { return $this->metrics; } /** * @param string|null $metrics * * @return self */ public function setMetrics(?string $metrics): self { $this->metrics = $metrics; return $this; } /** * @return string|null */ public function getNotificationPolicy(): ?string { return $this->notificationPolicy; } /** * @param string|null $notificationPolicy * * @return self */ public function setNotificationPolicy(?string $notificationPolicy): self { $this->notificationPolicy = $notificationPolicy; return $this; } /** * @return string|null */ public function getCheck(): ?string { return $this->check; } /** * @param string|null $check * * @return self */ public function setCheck(?string $check): self { $this->check = $check; return $this; } /** * @return string|null */ public function getForcedCheck(): ?string { return $this->forcedCheck; } /** * @param string|null $forcedCheck * * @return self */ public function setForcedCheck(?string $forcedCheck): self { $this->forcedCheck = $forcedCheck; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Monitoring/Icon.php
centreon/src/Centreon/Domain/Monitoring/Icon.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Monitoring; /** * Class representing a record of a icon in the repository. * * @package Centreon\Domain\Monitoring */ class Icon { // Groups for serializing public const SERIALIZER_GROUP_MAIN = 'icon_main'; /** @var int|null */ private $id; /** @var string|null */ private $name; /** @var string|null */ private $url; /** * @return int|null */ public function getId(): ?int { return $this->id; } /** * @param int|null $id * @return self */ public function setId(?int $id): self { $this->id = $id; return $this; } /** * @return string|null */ public function getName(): ?string { return $this->name; } /** * @param string|null $name * @return Icon */ public function setName(?string $name): self { $this->name = $name; return $this; } /** * @return string|null */ public function getUrl(): ?string { return $this->url; } /** * @param string|null $url * @return Icon */ public function setUrl(?string $url): self { $this->url = $url; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Monitoring/ResourceGroup.php
centreon/src/Centreon/Domain/Monitoring/ResourceGroup.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Monitoring; /** * Resource group model for resource repository * * @package Centreon\Domain\Monitoring */ class ResourceGroup { /** * Id of the resource group * * @var int */ private $id; /** * Name of the resource group * * @var string */ private $name; /** * Redirection URI to group configuration * * @var string|null */ private $configurationUri; /** * Contructor for ResourceGroup entity * * @param int $resourceGroupId * @param string $resourceGroupName */ public function __construct(int $resourceGroupId, string $resourceGroupName) { $this->id = $resourceGroupId; $this->name = $resourceGroupName; } /** * Get resource group id. * * @return int */ public function getId(): int { return $this->id; } /** * Get the resource group name. * * @return string */ public function getName(): string { return $this->name; } /** * Set the resource group id. * * @param int $resourceGroupId * @return ResourceGroup */ public function setId(int $resourceGroupId): self { $this->id = $resourceGroupId; return $this; } /** * Set the resource group name. * * @param string $resourceGroupName * @return ResourceGroup */ public function setName(string $resourceGroupName): self { $this->name = $resourceGroupName; return $this; } /** * @return string|null */ public function getConfigurationUri(): ?string { return $this->configurationUri; } /** * @param string|null $configurationUri * @return self */ public function setConfigurationUri(?string $configurationUri): self { $this->configurationUri = $configurationUri; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Monitoring/ResourceService.php
centreon/src/Centreon/Domain/Monitoring/ResourceService.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Monitoring; use Centreon\Domain\Monitoring\Interfaces\ResourceServiceInterface; use Centreon\Domain\Monitoring\Resource as ResourceEntity; use Centreon\Domain\Service\AbstractCentreonService; /** * Service manage the resources in real-time monitoring : hosts and services. * * @package Centreon\Domain\Monitoring */ class ResourceService extends AbstractCentreonService implements ResourceServiceInterface { /** * Find host id by resource * @param ResourceEntity $resource * @return int|null */ public static function generateHostIdByResource(ResourceEntity $resource): ?int { $hostId = null; if ($resource->getType() === ResourceEntity::TYPE_HOST) { $hostId = (int) $resource->getId(); } elseif ( $resource->getParent() !== null && $resource->getType() === ResourceEntity::TYPE_SERVICE ) { $hostId = (int) $resource->getParent()->getId(); } return $hostId; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Monitoring/MonitoringService.php
centreon/src/Centreon/Domain/Monitoring/MonitoringService.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Monitoring; use Centreon\Domain\Contact\Contact; use Centreon\Domain\HostConfiguration\Exception\HostCommandException; use Centreon\Domain\HostConfiguration\Interfaces\HostConfigurationServiceInterface; use Centreon\Domain\Log\LoggerTrait; use Centreon\Domain\Macro\Interfaces\MacroInterface; use Centreon\Domain\Monitoring\Exception\MonitoringServiceException; use Centreon\Domain\Monitoring\Interfaces\MonitoringRepositoryInterface; use Centreon\Domain\Monitoring\Interfaces\MonitoringServiceInterface; use Centreon\Domain\Service\AbstractCentreonService; use Centreon\Domain\ServiceConfiguration\Exception\ServiceCommandException; use Centreon\Domain\ServiceConfiguration\Interfaces\ServiceConfigurationServiceInterface; use Core\Security\AccessGroup\Application\Repository\ReadAccessGroupRepositoryInterface; /** * Monitoring class used to manage the real time services and hosts * * @package Centreon\Domain\Monitoring */ class MonitoringService extends AbstractCentreonService implements MonitoringServiceInterface { use CommandLineTrait; use LoggerTrait; /** * @param MonitoringRepositoryInterface $monitoringRepository * @param ReadAccessGroupRepositoryInterface $accessGroupRepository * @param ServiceConfigurationServiceInterface $serviceConfiguration * @param HostConfigurationServiceInterface $hostConfiguration */ public function __construct( private readonly MonitoringRepositoryInterface $monitoringRepository, private readonly ReadAccessGroupRepositoryInterface $accessGroupRepository, private readonly ServiceConfigurationServiceInterface $serviceConfiguration, private readonly HostConfigurationServiceInterface $hostConfiguration, ) { } /** * {@inheritDoc} * @param Contact $contact * * @throws \Throwable * @return self */ public function filterByContact($contact): self { parent::filterByContact($contact); $accessGroups = $this->accessGroupRepository->findByContact($contact); $this->monitoringRepository ->setContact($this->contact) ->filterByAccessGroups($accessGroups); return $this; } /** * @inheritDoc */ public function findServices(): array { return $this->monitoringRepository->findServices(); } /** * @inheritDoc */ public function findServicesByHost(int $hostId): array { return $this->monitoringRepository->findServicesByHostWithRequestParameters($hostId); } /** * @inheritDoc */ public function findHosts(bool $withServices = false): array { $hosts = $this->monitoringRepository->findHosts(); if ($withServices && $hosts !== []) { $hosts = $this->completeHostsWithTheirServices($hosts); } return $hosts; } /** * @inheritDoc */ public function findHostGroups(bool $withHosts = false, bool $withServices = false, ?int $hostId = null): array { // Find hosts groups only $hostGroups = $this->monitoringRepository->findHostGroups($hostId); if ($hostGroups !== []) { $hostIds = []; if ($withHosts || $withServices) { // We will find hosts linked to hosts groups found $hostGroupIds = []; foreach ($hostGroups as $hostGroup) { $hostGroupIds[] = $hostGroup->getId(); } $hostsByHostsGroups = $this->monitoringRepository->findHostsByHostsGroups($hostGroupIds); foreach ($hostGroups as $hostGroup) { if (array_key_exists($hostGroup->getId(), $hostsByHostsGroups)) { $hostGroup->setHosts($hostsByHostsGroups[$hostGroup->getId()]); // We keep the host ids if we must to retrieve their services if ($withServices) { foreach ($hostGroup->getHosts() as $host) { if (! in_array($host->getId(), $hostIds)) { $hostIds[] = $host->getId(); } } } } } } if ($withServices) { // We will find services linked to hosts linked to host groups $servicesByHost = $this->monitoringRepository->findServicesByHosts($hostIds); foreach ($hostGroups as $hostGroup) { foreach ($hostGroup->getHosts() as $host) { if (array_key_exists($host->getId(), $servicesByHost)) { $host->setServices($servicesByHost[$host->getId()]); } } } } } return $hostGroups; } /** * @inheritDoc */ public function findOneHost(int $hostId): ?Host { $host = $this->monitoringRepository->findOneHost($hostId); if (! empty($host)) { $host = $this->completeHostsWithTheirServices([$host])[0]; } return $host; } /** * @inheritDoc * @throws \Throwable */ public function findOneService(int $hostId, int $serviceId): ?Service { return $this->monitoringRepository->findOneService($hostId, $serviceId); } /** * @inheritDoc */ public function findOneServiceByDescription(string $description): ?Service { return $this->monitoringRepository->findOneServiceByDescription($description); } /** * @inheritDoc */ public function findServiceGroups(bool $withHosts = false, bool $withServices = false): array { // Find hosts groups only $serviceGroups = $this->monitoringRepository->findServiceGroups(); if ($serviceGroups !== [] && ($withHosts || $withServices)) { // We will find hosts linked to hosts groups found $serviceGroupIds = []; foreach ($serviceGroups as $serviceGroup) { $serviceGroupIds[] = $serviceGroup->getId(); } $hostsByServicesGroups = $this->monitoringRepository->findHostsByServiceGroups($serviceGroupIds); foreach ($serviceGroups as $serviceGroup) { if (array_key_exists($serviceGroup->getId(), $hostsByServicesGroups)) { $serviceGroup->setHosts($hostsByServicesGroups[$serviceGroup->getId()]); } } if ($withServices) { // We will find services linked to hosts linked to service groups $servicesByServiceGroup = $this->monitoringRepository->findServicesByServiceGroups($serviceGroupIds); // First, we will sort services by service groups and hosts $servicesByServiceGroupAndHost = []; foreach ($servicesByServiceGroup as $serviceGroupId => $services) { foreach ($services as $service) { $hostId = $service->getHost()->getId(); $servicesByServiceGroupAndHost[$serviceGroupId][$hostId][] = $service; } } // Next, we will linked services to host foreach ($serviceGroups as $serviceGroup) { foreach ($serviceGroup->getHosts() as $host) { if ( array_key_exists($serviceGroup->getId(), $servicesByServiceGroupAndHost) && array_key_exists($host->getId(), $servicesByServiceGroupAndHost[$serviceGroup->getId()]) ) { $host->setServices( $servicesByServiceGroupAndHost[$serviceGroup->getId()][$host->getId()] ); } } } } } return $serviceGroups; } /** * @inheritDoc */ public function isHostExists(int $hostId): bool { return ! is_null($this->findOneHost($hostId)); } /** * @inheritDoc * @throws \Throwable */ public function isServiceExists(int $hostId, int $serviceId): bool { return ! is_null($this->findOneService($hostId, $serviceId)); } /** * @inheritDoc */ public function findServiceGroupsByHostAndService(int $hostId, int $serviceId): array { return $this->monitoringRepository->findServiceGroupsByHostAndService($hostId, $serviceId); } /** * @inheritDoc */ public function findCommandLineOfService(int $hostId, int $serviceId): ?string { try { $service = $this->findOneService($hostId, $serviceId); if ($service === null) { throw new MonitoringServiceException('Service not found'); } $this->hidePasswordInServiceCommandLine($service); return $service->getCommandLine(); } catch (MonitoringServiceException $ex) { throw $ex; } catch (\Throwable) { throw new MonitoringServiceException('Error when getting the command line'); } } /** * @inheritDoc */ public function hidePasswordInHostCommandLine(Host $monitoringHost, string $replacementValue = '***'): void { $monitoringCommand = $monitoringHost->getCheckCommand(); if (empty($monitoringCommand)) { return; } if ($monitoringHost->getId() === null) { throw MonitoringServiceException::hostIdNotNull(); } $configurationCommand = $this->hostConfiguration->findCommandLine($monitoringHost->getId()); if (empty($configurationCommand)) { throw HostCommandException::notFound($monitoringHost->getId()); } $hostMacros = $this->hostConfiguration->findHostMacrosFromCommandLine( $monitoringHost->getId(), $configurationCommand ); $builtCommand = $this->buildCommandLineFromConfiguration( $configurationCommand, $monitoringCommand, $hostMacros, $replacementValue ); if (! empty($builtCommand)) { $monitoringHost->setCheckCommand($builtCommand); } } /** * @inheritDoc */ public function hidePasswordInServiceCommandLine(Service $monitoringService, string $replacementValue = '***'): void { $monitoringCommand = $monitoringService->getCommandLine(); if (empty($monitoringCommand)) { return; } if ($monitoringService->getId() === null) { throw MonitoringServiceException::serviceIdNotNull(); } if ($monitoringService->getHost() === null || $monitoringService->getHost()->getId() === null) { throw MonitoringServiceException::hostIdNotNull(); } $configurationCommand = $this->serviceConfiguration->findCommandLine($monitoringService->getId()); if (empty($configurationCommand)) { // Meta Service case if (preg_match('/^meta_[0-9]+$/', $monitoringService->getDescription())) { // For META SERVICE we can define the configuration command line with the monitoring command line $monitoringService->setCommandLine($monitoringCommand); return; } // The service is not a META SERVICE throw ServiceCommandException::notFound($monitoringService->getId()); } $hostMacros = $this->hostConfiguration->findHostMacrosFromCommandLine( $monitoringService->getHost()->getId(), $configurationCommand ); $serviceMacros = $this->serviceConfiguration->findServiceMacrosFromCommandLine( $monitoringService->getId(), $configurationCommand ); /** * @var MacroInterface[] $macros */ $macros = array_merge($hostMacros, $serviceMacros); $builtCommand = $this->buildCommandLineFromConfiguration( $configurationCommand, $monitoringCommand, $macros, $replacementValue ); if (! empty($builtCommand)) { $monitoringService->setCommandLine($builtCommand); } } /** * Completes hosts with their services. * * @param Host[] $hosts Host list for which we want to complete with their services * @throws \Exception * @return Host[] Returns the host list with their services */ private function completeHostsWithTheirServices(array $hosts): array { $hostIds = []; foreach ($hosts as $host) { $hostIds[] = $host->getId(); } $services = $this->monitoringRepository->findServicesByHosts($hostIds); foreach ($hosts as $host) { if (array_key_exists($host->getId(), $services)) { $host->setServices($services[$host->getId()]); } } return $hosts; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Monitoring/ResourceStatus.php
centreon/src/Centreon/Domain/Monitoring/ResourceStatus.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Monitoring; /** * Class representing a record of a resource status in the repository. * * @package Centreon\Domain\Monitoring */ class ResourceStatus { // Groups for serializing public const SERIALIZER_GROUP_MAIN = 'resource_status_main'; public const SEVERITY_HIGH = 1; public const SEVERITY_MEDIUM = 2; public const SEVERITY_LOW = 3; public const SEVERITY_PENDING = 4; public const SEVERITY_OK = 5; public const STATUS_NAME_PENDING = 'PENDING'; public const STATUS_NAME_UP = 'UP'; public const STATUS_NAME_DOWN = 'DOWN'; public const STATUS_NAME_UNREACHABLE = 'UNREACHABLE'; public const STATUS_NAME_OK = 'OK'; public const STATUS_NAME_WARNING = 'WARNING'; public const STATUS_NAME_CRITICAL = 'CRITICAL'; public const STATUS_NAME_UNKNOWN = 'UNKNOWN'; /** @var int|null */ private $code; /** @var string|null */ private $name; /** @var int|null */ private $severityCode; /** * @return int|null */ public function getCode(): ?int { return $this->code; } /** * @param int|null $code * @return ResourceStatus */ public function setCode(?int $code): self { $this->code = $code; return $this; } /** * @return string|null */ public function getName(): ?string { return $this->name; } /** * @param string|null $name * @return ResourceStatus */ public function setName(?string $name): self { $this->name = $name; return $this; } /** * @return int|null */ public function getSeverityCode(): ?int { return $this->severityCode; } /** * @param int|null $severityCode * @return ResourceStatus */ public function setSeverityCode(?int $severityCode): self { $this->severityCode = $severityCode; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Monitoring/ResourceId.php
centreon/src/Centreon/Domain/Monitoring/ResourceId.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Monitoring; /** * Class representing a record of a resource id in the repository. * * @package Centreon\Domain\Monitoring */ class ResourceId { // Groups for serializing public const SERIALIZER_GROUP_MAIN = 'resource_id_main'; /** @var int */ private $id; /** @var int|null */ private $parentId; /** * @return int */ public function getId(): int { return $this->id; } /** * @param int $id * @return ResourceId */ public function setId(int $id): self { $this->id = $id; return $this; } /** * @return int|null */ public function getParentId(): ?int { return $this->parentId; } /** * @param int|null $parentId * @return ResourceId */ public function setParentId(?int $parentId): self { $this->parentId = $parentId; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Monitoring/HostGroup.php
centreon/src/Centreon/Domain/Monitoring/HostGroup.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Monitoring; use Centreon\Domain\Service\EntityDescriptorMetadataInterface; /** * Class representing a record of a host group in the repository. * * @package Centreon\Domain\Monitoring */ class HostGroup implements EntityDescriptorMetadataInterface { // Groups for serilizing public const SERIALIZER_GROUP_MAIN = 'hg_main'; public const SERIALIZER_GROUP_WITH_HOST = 'hg_with_host'; /** @var int */ private $id; /** @var Host[] */ private $hosts = []; /** @var string|null */ private $name; /** * {@inheritDoc} */ public static function loadEntityDescriptorMetadata(): array { return [ 'hostgroup_id' => 'setId', ]; } /** * @return int */ public function getId(): int { return $this->id; } /** * @param int $id * @return HostGroup */ public function setId(int $id): HostGroup { $this->id = $id; return $this; } /** * @return string|null */ public function getName(): ?string { return $this->name; } /** * @param string|null $name * @return HostGroup */ public function setName(?string $name): HostGroup { $this->name = $name; return $this; } /** * @param Host $host * @return HostGroup */ public function addHost(Host $host): HostGroup { $this->hosts[] = $host; return $this; } /** * @return Host[] */ public function getHosts(): array { return $this->hosts; } /** * Indicates if a host exists in this host group. * * @param int $hostId Host id to find * @return bool */ public function isHostExists(int $hostId): bool { foreach ($this->hosts as $host) { if ($host->getId() === $hostId) { return true; } } return false; } /** * @param Host[] $hosts * @return HostGroup */ public function setHosts(array $hosts): HostGroup { $this->hosts = $hosts; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Monitoring/ResourceLinks.php
centreon/src/Centreon/Domain/Monitoring/ResourceLinks.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Monitoring; use Centreon\Domain\Monitoring\ResourceExternalLinks as Externals; use Centreon\Domain\Monitoring\ResourceLinksEndpoints as Endpoints; use Centreon\Domain\Monitoring\ResourceLinksUris as Uris; /** * Resource Links model for resource repository * * @package Centreon\Domain\Monitoring */ class ResourceLinks { /** @var Uris */ private $uris; /** @var Endpoints */ private $endpoints; /** @var Externals */ private $externals; /** * ResourceLinks constructor. */ public function __construct() { $this->uris = new Uris(); $this->endpoints = new Endpoints(); $this->externals = new Externals(); } /** * @return Uris */ public function getUris(): Uris { return $this->uris; } /** * @param Uris $uris * @return self */ public function setUris(Uris $uris): self { $this->uris = $uris; return $this; } /** * @return Endpoints */ public function getEndpoints(): Endpoints { return $this->endpoints; } /** * @param Endpoints $endpoints * @return self */ public function setEndpoints(Endpoints $endpoints): self { $this->endpoints = $endpoints; return $this; } /** * @param Externals $externals * @return self */ public function setExternals(Externals $externals): self { $this->externals = $externals; return $this; } /** * @return Externals */ public function getExternals(): Externals { return $this->externals; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Monitoring/Service.php
centreon/src/Centreon/Domain/Monitoring/Service.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Monitoring; use Centreon\Domain\Acknowledgement\Acknowledgement; use Centreon\Domain\Downtime\Downtime; use Centreon\Domain\Service\EntityDescriptorMetadataInterface; use CentreonDuration; /** * Class representing a record of a service in the repository. * * @package Centreon\Domain\Monitoring */ class Service implements EntityDescriptorMetadataInterface { // Groups for serilizing public const SERIALIZER_GROUP_MIN = 'service_min'; public const SERIALIZER_GROUP_MAIN = 'service_main'; public const SERIALIZER_GROUP_FULL = 'service_full'; public const SERIALIZER_GROUP_WITH_HOST = 'service_with_host'; /** @var int|null Unique index */ protected $id; /** @var int */ protected $checkAttempt; /** @var string|null */ protected $checkCommand; /** @var float|null */ protected $checkInterval; /** @var string|null */ protected $checkPeriod; /** @var int|null */ protected $checkType; /** @var string|null */ protected $commandLine; /** @var string */ protected $description; /** @var string */ protected $displayName; /** @var float|null */ protected $executionTime; /** @var Host|null */ protected $host; /** @var string|null */ protected $iconImage; /** @var string|null */ protected $iconImageAlt; /** @var bool */ protected $isAcknowledged; /** @var bool */ protected $isActiveCheck; /** @var bool */ protected $isChecked; /** @var int|null */ protected $scheduledDowntimeDepth; /** @var \DateTime|null */ protected $lastCheck; /** @var \DateTime|null */ protected $lastHardStateChange; /** @var \DateTime|null */ protected $lastNotification; /** @var \DateTime|null */ protected $lastTimeCritical; /** @var \DateTime|null */ protected $lastTimeOk; /** @var \DateTime|null */ protected $lastTimeUnknown; /** @var \DateTime|null */ protected $lastTimeWarning; /** @var \DateTime|null */ protected $lastUpdate; /** @var \DateTime|null */ protected $lastStateChange; /** @var float|null */ protected $latency; /** @var int */ protected $maxCheckAttempts; /** @var \DateTime */ protected $nextCheck; /** @var string */ protected $output; /** @var string */ protected $performanceData; /** @var int ['0' => 'OK', '1' => 'WARNING', '2' => 'CRITICAL', '3' => 'UNKNOWN', '4' => 'PENDING'] */ protected $state; /** @var int ('1' => 'HARD', '0' => 'SOFT') */ protected $stateType; /** @var int|null */ protected $criticality; /** @var Downtime[] */ protected $downtimes = []; /** @var Acknowledgement|null */ protected $acknowledgement; /** @var bool|null */ protected $flapping; /** @var bool|null */ protected $notify; /** @var ResourceStatus|null */ private $status; /** * {@inheritDoc} */ public static function loadEntityDescriptorMetadata(): array { return [ 'service_id' => 'setId', 'acknowledged' => 'setAcknowledged', 'active_checks' => 'setActiveCheck', 'checked' => 'setChecked', 'perfdata' => 'setPerformanceData', ]; } /** * @return int|null */ public function getId(): ?int { return $this->id; } /** * @param int $id * @return Service */ public function setId(int $id): Service { $this->id = $id; return $this; } /** * @return string|null */ public function getCheckCommand(): ?string { return $this->checkCommand; } /** * @param string|null $checkCommand * @return Service */ public function setCheckCommand(?string $checkCommand): Service { $this->checkCommand = $checkCommand; return $this; } /** * @return float|null */ public function getCheckInterval(): ?float { return $this->checkInterval; } /** * @param float|null $checkInterval * @return Service */ public function setCheckInterval(?float $checkInterval): Service { $this->checkInterval = $checkInterval; return $this; } /** * @return string */ public function getCheckPeriod(): ?string { return $this->checkPeriod; } /** * @param string|null $checkPeriod * @return Service */ public function setCheckPeriod(?string $checkPeriod): Service { $this->checkPeriod = $checkPeriod; return $this; } /** * @return int|null */ public function getCheckType(): ?int { return $this->checkType; } /** * @param int|null $checkType * @return Service */ public function setCheckType(?int $checkType): Service { $this->checkType = $checkType; return $this; } /** * @return string|null */ public function getCommandLine(): ?string { return $this->commandLine; } /** * @param string|null $commandLine * @return Service */ public function setCommandLine(?string $commandLine): Service { $this->commandLine = $commandLine; return $this; } /** * @return string */ public function getDescription(): string { return $this->description; } /** * @param string $description * @return Service */ public function setDescription(string $description): Service { $this->description = $description; return $this; } /** * @return string */ public function getDisplayName(): string { return $this->displayName; } /** * @param string $displayName * @return Service */ public function setDisplayName(string $displayName): Service { $this->displayName = $displayName; return $this; } /** * @return float|null */ public function getExecutionTime(): ?float { return $this->executionTime; } /** * @param float|null $executionTime * @return Service */ public function setExecutionTime(?float $executionTime): Service { $this->executionTime = $executionTime; return $this; } /** * @return Host|null */ public function getHost(): ?Host { return $this->host; } /** * @param Host $host|null * @return Service */ public function setHost(?Host $host): Service { $this->host = $host; return $this; } /** * @return string|null */ public function getIconImage(): ?string { return $this->iconImage; } /** * @param string|null $iconImage * @return Service */ public function setIconImage(?string $iconImage): Service { $this->iconImage = $iconImage; return $this; } /** * @return string|null */ public function getIconImageAlt(): ?string { return $this->iconImageAlt; } /** * @param string|null $iconImageAlt */ public function setIconImageAlt(?string $iconImageAlt): void { $this->iconImageAlt = $iconImageAlt; } /** * @return bool */ public function isAcknowledged(): bool { return $this->isAcknowledged; } /** * @param bool $isAcknowledged * @return Service */ public function setAcknowledged(bool $isAcknowledged): Service { $this->isAcknowledged = $isAcknowledged; return $this; } /** * virtual property used by resource details endpoint * @return bool */ public function getActiveCheck(): bool { return $this->isActiveCheck; } /** * @return bool */ public function isActiveCheck(): bool { return $this->isActiveCheck; } /** * @param bool $isActiveCheck * @return Service */ public function setActiveCheck(bool $isActiveCheck): Service { $this->isActiveCheck = $isActiveCheck; return $this; } /** * @return int */ public function getCheckAttempt(): int { return $this->checkAttempt; } /** * @param int $checkAttempt * @return Service */ public function setCheckAttempt(int $checkAttempt): Service { $this->checkAttempt = $checkAttempt; return $this; } /** * @return bool */ public function isChecked(): bool { return $this->isChecked; } /** * @param bool $isChecked * @return Service */ public function setChecked(bool $isChecked): Service { $this->isChecked = $isChecked; return $this; } /** * @return int|null */ public function getScheduledDowntimeDepth(): ?int { return $this->scheduledDowntimeDepth; } /** * @param int $scheduledDowntimeDepth * @return Service */ public function setScheduledDowntimeDepth(int $scheduledDowntimeDepth): Service { $this->scheduledDowntimeDepth = $scheduledDowntimeDepth; return $this; } /** * @return int */ public function getState(): int { return $this->state; } /** * @param int $state * @return Service */ public function setState(int $state): Service { $this->state = $state; return $this; } /** * @return string */ public function getOutput(): string { return $this->output; } /** * @param string $output * @return Service */ public function setOutput(string $output): Service { $this->output = $output; return $this; } /** * @return string */ public function getPerformanceData(): string { return $this->performanceData; } /** * @param string $performanceData * @return Service */ public function setPerformanceData(string $performanceData): Service { $this->performanceData = $performanceData; return $this; } /** * @return \DateTime|null */ public function getLastCheck(): ?\DateTime { return $this->lastCheck; } /** * @param \DateTime|null $lastCheck * @return Service */ public function setLastCheck(?\DateTime $lastCheck): Service { $this->lastCheck = $lastCheck; return $this; } /** * @return \DateTime|null */ public function getNextCheck(): ?\DateTime { return $this->nextCheck; } /** * @param \DateTime|null $nextCheck * @return Service */ public function setNextCheck(?\DateTime $nextCheck): Service { $this->nextCheck = $nextCheck; return $this; } /** * @return \DateTime|null */ public function getLastUpdate(): ?\DateTime { return $this->lastUpdate; } /** * @param \DateTime|null $lastUpdate * @return Service */ public function setLastUpdate(?\DateTime $lastUpdate): Service { $this->lastUpdate = $lastUpdate; return $this; } /** * @return \DateTime|null */ public function getLastStateChange(): ?\DateTime { return $this->lastStateChange; } /** * @param \DateTime|null $lastStateChange * @return Service */ public function setLastStateChange(?\DateTime $lastStateChange): Service { $this->lastStateChange = $lastStateChange; return $this; } /** * @return float|null */ public function getLatency(): ?float { return $this->latency; } /** * @param float|null $latency * @return Service */ public function setLatency(?float $latency): Service { $this->latency = $latency; return $this; } /** * @return \DateTime|null */ public function getLastHardStateChange(): ?\DateTime { return $this->lastHardStateChange; } /** * @param \DateTime|null $lastHardStateChange * @return Service */ public function setLastHardStateChange(?\DateTime $lastHardStateChange): Service { $this->lastHardStateChange = $lastHardStateChange; return $this; } /** * @return \DateTime|null */ public function getLastNotification(): ?\DateTime { return $this->lastNotification; } /** * @param \DateTime|null $lastNotification * @return Service */ public function setLastNotification(?\DateTime $lastNotification): Service { $this->lastNotification = $lastNotification; return $this; } /** * @return \DateTime|null */ public function getLastTimeCritical(): ?\DateTime { return $this->lastTimeCritical; } /** * @param \DateTime|null $lastTimeCritical * @return Service */ public function setLastTimeCritical(?\DateTime $lastTimeCritical): Service { $this->lastTimeCritical = $lastTimeCritical; return $this; } /** * @return \DateTime|null */ public function getLastTimeOk(): ?\DateTime { return $this->lastTimeOk; } /** * @param \DateTime|null $lastTimeOk * @return Service */ public function setLastTimeOk(?\DateTime $lastTimeOk): Service { $this->lastTimeOk = $lastTimeOk; return $this; } /** * @return \DateTime|null */ public function getLastTimeUnknown(): ?\DateTime { return $this->lastTimeUnknown; } /** * @param \DateTime|null $lastTimeUnknown * @return Service */ public function setLastTimeUnknown(?\DateTime $lastTimeUnknown): Service { $this->lastTimeUnknown = $lastTimeUnknown; return $this; } /** * @return \DateTime|null */ public function getLastTimeWarning(): ?\DateTime { return $this->lastTimeWarning; } /** * @param \DateTime|null $lastTimeWarning * @return Service */ public function setLastTimeWarning(?\DateTime $lastTimeWarning): Service { $this->lastTimeWarning = $lastTimeWarning; return $this; } /** * @return int */ public function getMaxCheckAttempts(): int { return $this->maxCheckAttempts; } /** * @param int $maxCheckAttempts * @return Service */ public function setMaxCheckAttempts(int $maxCheckAttempts): Service { $this->maxCheckAttempts = $maxCheckAttempts; return $this; } /** * @return int */ public function getStateType(): int { return $this->stateType; } /** * @param int $stateType * @return Service */ public function setStateType(int $stateType): Service { $this->stateType = $stateType; return $this; } /** * @return int|null */ public function getCriticality(): ?int { return $this->criticality; } /** * @param int|null $criticality * @return Service */ public function setCriticality(?int $criticality): Service { $this->criticality = $criticality; return $this; } /** * @return Downtime[] */ public function getDowntimes(): array { return $this->downtimes; } /** * @param Downtime[] $downtimes * @return Service */ public function setDowntimes(array $downtimes): self { $this->downtimes = $downtimes; return $this; } /** * @return Acknowledgement|null */ public function getAcknowledgement(): ?Acknowledgement { return $this->acknowledgement; } /** * @param Acknowledgement|null $acknowledgement * @return Service */ public function setAcknowledgement(?Acknowledgement $acknowledgement): self { $this->acknowledgement = $acknowledgement; return $this; } /** * @return bool|null */ public function getFlapping(): ?bool { return $this->flapping; } /** * @param bool|null $flapping * @return Service */ public function setFlapping(?bool $flapping): self { $this->flapping = $flapping; return $this; } /** * @return ResourceStatus|null */ public function getStatus(): ?ResourceStatus { return $this->status; } /** * @param ResourceStatus|null $status * @return self */ public function setStatus(?ResourceStatus $status): self { $this->status = $status; return $this; } /** * @return string|null */ public function getDuration(): ?string { $duration = null; if ($this->getLastStateChange()) { $duration = CentreonDuration::toString(time() - $this->getLastStateChange()->getTimestamp()); } return $duration; } /** * @return bool|null */ public function getNotify(): ?bool { return $this->notify; } /** * @param bool|null $notify * @return Service */ public function setNotify(?bool $notify): self { $this->notify = $notify; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Monitoring/Resource.php
centreon/src/Centreon/Domain/Monitoring/Resource.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Monitoring; use Centreon\Domain\Acknowledgement\Acknowledgement; use Centreon\Domain\Downtime\Downtime; use CentreonDuration; use Core\Severity\RealTime\Domain\Model\Severity; /** * Class representing a record of a resource in the repository. * * @package Centreon\Domain\Monitoring */ class Resource { // Types public const TYPE_SERVICE = 'service'; public const TYPE_HOST = 'host'; public const TYPE_META = 'metaservice'; /** @var string|null */ protected $commandLine; /** @var int|null */ protected $criticality; /** @var int|null */ private $resourceId; /** @var int|null */ private $id; /** @var string|null */ private $type; /** @var string|null */ private $name; /** @var string|null */ private $alias; /** @var string|null */ private $fqdn; /** @var int|null */ private $hostId; /** @var int|null */ private $serviceId; /** @var Icon|null */ private $icon; /** @var string */ private $monitoringServerName; /** @var string|null */ private $timezone; /** @var \Centreon\Domain\Monitoring\Resource|null */ private $parent; /** @var ResourceStatus|null */ private $status; /** @var float|null */ private ?float $percentStateChange = null; /** @var bool */ private $inDowntime = false; /** @var bool */ private $acknowledged = false; /** @var bool */ private $activeChecks = true; /** @var bool */ private $passiveChecks = false; /** @var ResourceLinks */ private $links; /** @var string|null */ private $chartUrl; /** @var \DateTime|null */ private $lastStatusChange; /** @var \DateTime|null */ private $lastTimeWithNoIssue; /** @var \DateTime|null */ private $lastNotification; /** @var int|null */ private $notificationNumber; /** @var int */ private $stateType; /** @var string|null */ private $tries; /** @var \DateTime|null */ private $lastCheck; /** @var \DateTime|null */ private $nextCheck; /** @var string|null */ private $information; /** @var string */ private $performanceData; /** @var float|null */ private $executionTime; /** @var float|null */ private $latency; /** @var Downtime[] */ private $downtimes = []; /** @var Acknowledgement|null */ private $acknowledgement; /** * Groups to which belongs the resource * * @var ResourceGroup[] */ private $groups = []; /** * Calculation type of the Resource * * @var string|null */ private $calculationType; /** * Indicates if notifications are enabled for the Resource * * @var bool */ private $notificationEnabled = false; /** @var bool */ private $hasGraph = false; /** @var Severity|null */ private $severity; /** @var int|null */ private ?int $internalId = null; private bool $flapping = false; /** * Resource constructor. */ public function __construct() { $this->links = new ResourceLinks(); } /** * @return string|null */ public function getShortType(): ?string { return $this->type ? $this->type[0] : null; } /** * @return string|null */ public function getDuration(): ?string { $result = null; if ($this->getLastStatusChange() !== null) { $result = CentreonDuration::toString(time() - $this->getLastStatusChange()->getTimestamp()); $result = $result !== false ? $result : null; } return $result; } /** * @return string|null */ public function getLastCheckAsString(): ?string { $result = null; if ($this->getLastCheck() !== null) { $result = CentreonDuration::toString(time() - $this->getLastCheck()->getTimestamp()); $result = $result !== false ? $result : null; } return $result; } /** * @return string */ public function getUuid(): string { $uuid = ''; if ($this->getShortType() !== null && $this->getId() !== null) { $uuid = $this->getShortType() . $this->getId(); } if ($this->getParent() !== null) { $uuid = $this->getParent()->getUuid() . '-' . $uuid; } return $uuid; } /** * @return int|null */ public function getId(): ?int { return $this->id; } /** * @param int|null $id * @return \Centreon\Domain\Monitoring\Resource */ public function setId(?int $id): self { $this->id = $id; return $this; } /** * @return string|null */ public function getType(): ?string { return $this->type; } /** * @param string|null $type * @return \Centreon\Domain\Monitoring\Resource */ public function setType(?string $type): self { $this->type = $type; return $this; } /** * @return string|null */ public function getName(): ?string { return $this->name; } /** * @param string|null $name * @return \Centreon\Domain\Monitoring\Resource */ public function setName(?string $name): self { $this->name = $name; return $this; } /** * @return string|null */ public function getAlias(): ?string { return $this->alias; } /** * @param string|null $alias * @return \Centreon\Domain\Monitoring\Resource */ public function setAlias(?string $alias): self { $this->alias = $alias; return $this; } /** * @return string|null */ public function getFqdn(): ?string { return $this->fqdn; } /** * @return int|null */ public function getHostId(): ?int { return $this->hostId; } /** * @param int|null $hostId * @return \Centreon\Domain\Monitoring\Resource */ public function setHostId(?int $hostId): self { $this->hostId = $hostId; return $this; } /** * @return int|null */ public function getServiceId(): ?int { return $this->serviceId; } /** * @param int|null $serviceId * @return \Centreon\Domain\Monitoring\Resource */ public function setServiceId(?int $serviceId): self { $this->serviceId = $serviceId; return $this; } /** * @param string|null $fqdn * @return \Centreon\Domain\Monitoring\Resource */ public function setFqdn(?string $fqdn): self { $this->fqdn = $fqdn; return $this; } /** * @return Icon|null */ public function getIcon(): ?Icon { return $this->icon; } /** * @param Icon|null $icon * @return \Centreon\Domain\Monitoring\Resource */ public function setIcon(?Icon $icon): self { $this->icon = $icon; return $this; } /** * @return string|null */ public function getCommandLine(): ?string { return $this->commandLine; } /** * @param string|null $commandLine * @return self */ public function setCommandLine(?string $commandLine): self { $this->commandLine = $commandLine; return $this; } /** * @return string */ public function getMonitoringServerName(): string { return $this->monitoringServerName; } /** * @param string $monitoringServerName * @return self */ public function setMonitoringServerName(string $monitoringServerName): self { $this->monitoringServerName = $monitoringServerName; return $this; } /** * @return string|null */ public function getTimezone(): ?string { return $this->timezone; } /** * @return null|string */ public function getSanitizedTimezone(): ?string { return ($this->timezone !== null) ? preg_replace('/^:/', '', $this->timezone) : $this->timezone; } /** * @param string|null $timezone * @return self */ public function setTimezone(?string $timezone): self { $this->timezone = $timezone; return $this; } /** * @return \Centreon\Domain\Monitoring\Resource|null */ public function getParent(): ?Resource { return $this->parent; } /** * @param \Centreon\Domain\Monitoring\Resource|null $parent * @return \Centreon\Domain\Monitoring\Resource */ public function setParent(?Resource $parent): self { $this->parent = $parent; return $this; } /** * @return ResourceStatus|null */ public function getStatus(): ?ResourceStatus { return $this->status; } /** * @param ResourceStatus|null $status * @return \Centreon\Domain\Monitoring\Resource */ public function setStatus(?ResourceStatus $status): self { $this->status = $status; return $this; } /** * @return bool */ public function isInFlapping(): bool { return $this->flapping; } /** * @param bool $flapping * @return self */ public function setFlapping(bool $flapping): self { $this->flapping = $flapping; return $this; } /** * @return float|null */ public function getPercentStateChange(): ?float { return $this->percentStateChange; } /** * @param float|null $percentStateChange * @return self */ public function setPercentStateChange(?float $percentStateChange): self { $this->percentStateChange = $percentStateChange; return $this; } /** * @return int|null */ public function getCriticality(): ?int { return $this->criticality; } /** * @param int|null $criticality * @return self */ public function setCriticality(?int $criticality): self { $this->criticality = $criticality; return $this; } /** * @return bool */ public function getInDowntime(): bool { return $this->inDowntime; } /** * @param bool $inDowntime * @return \Centreon\Domain\Monitoring\Resource */ public function setInDowntime(bool $inDowntime): self { $this->inDowntime = $inDowntime; return $this; } /** * @return bool */ public function getAcknowledged(): bool { return $this->acknowledged; } /** * @param bool $acknowledged * @return \Centreon\Domain\Monitoring\Resource */ public function setAcknowledged(bool $acknowledged): self { $this->acknowledged = $acknowledged; return $this; } /** * @return bool */ public function getActiveChecks(): bool { return $this->activeChecks; } /** * @param bool $activeChecks * @return self */ public function setActiveChecks(bool $activeChecks): self { $this->activeChecks = $activeChecks; return $this; } /** * @return bool */ public function getPassiveChecks(): bool { return $this->passiveChecks; } /** * @param bool $passiveChecks * @return self */ public function setPassiveChecks(bool $passiveChecks): self { $this->passiveChecks = $passiveChecks; return $this; } /** * @return ResourceLinks */ public function getLinks(): ResourceLinks { return $this->links; } /** * @param ResourceLinks $links * @return self */ public function setLinks(ResourceLinks $links): self { $this->links = $links; return $this; } /** * @return string|null */ public function getChartUrl(): ?string { return $this->chartUrl; } /** * @param string|null $chartUrl * @return \Centreon\Domain\Monitoring\Resource */ public function setChartUrl(?string $chartUrl): self { $this->chartUrl = $chartUrl ?: null; return $this; } /** * @return \DateTime|null */ public function getLastStatusChange(): ?\DateTime { return $this->lastStatusChange; } /** * @param \DateTime|null $lastStatusChange * @return \Centreon\Domain\Monitoring\Resource */ public function setLastStatusChange(?\DateTime $lastStatusChange): self { $this->lastStatusChange = $lastStatusChange; return $this; } /** * @return \DateTime|null */ public function getLastTimeWithNoIssue(): ?\DateTime { return $this->lastTimeWithNoIssue; } /** * @param \DateTime|null $lastTimeWithNoIssue * @return self */ public function setLastTimeWithNoIssue(?\DateTime $lastTimeWithNoIssue): self { $this->lastTimeWithNoIssue = $lastTimeWithNoIssue; return $this; } /** * @return \DateTime|null */ public function getLastNotification(): ?\DateTime { return $this->lastNotification; } /** * @param \DateTime|null $lastNotification * @return self */ public function setLastNotification(?\DateTime $lastNotification): self { $this->lastNotification = $lastNotification; return $this; } /** * @return int|null */ public function getNotificationNumber(): ?int { return $this->notificationNumber; } /** * @param int|null $notificationNumber * @return self */ public function setNotificationNumber(?int $notificationNumber): self { $this->notificationNumber = $notificationNumber; return $this; } /** * @return int */ public function getStateType(): int { return $this->stateType; } /** * @param int $stateType * @return self */ public function setStateType(int $stateType): self { $this->stateType = $stateType; return $this; } /** * @return string|null */ public function getTries(): ?string { return $this->tries; } /** * @param string|null $tries * @return \Centreon\Domain\Monitoring\Resource */ public function setTries(?string $tries): self { $this->tries = $tries; return $this; } /** * @return \DateTime|null */ public function getLastCheck(): ?\DateTime { return $this->lastCheck; } /** * @param \DateTime|null $lastCheck * @return \Centreon\Domain\Monitoring\Resource */ public function setLastCheck(?\DateTime $lastCheck): self { $this->lastCheck = $lastCheck; return $this; } /** * @return \DateTime|null */ public function getNextCheck(): ?\DateTime { return $this->nextCheck; } /** * @param \DateTime|null $nextCheck * @return \Centreon\Domain\Monitoring\Resource */ public function setNextCheck(?\DateTime $nextCheck): self { $this->nextCheck = $nextCheck; return $this; } /** * @return string|null */ public function getInformation(): ?string { return $this->information; } /** * @param string|null $information * @return \Centreon\Domain\Monitoring\Resource */ public function setInformation(?string $information): self { $this->information = $information !== null ? trim($information) : null; return $this; } /** * @return string */ public function getPerformanceData(): string { return $this->performanceData; } /** * @param string $performanceData * @return self */ public function setPerformanceData(string $performanceData): self { $this->performanceData = $performanceData; return $this; } /** * @return float|null */ public function getExecutionTime(): ?float { return $this->executionTime; } /** * @param float|null $executionTime * @return self */ public function setExecutionTime(?float $executionTime): self { $this->executionTime = $executionTime; return $this; } /** * @return float|null */ public function getLatency(): ?float { return $this->latency; } /** * @param float|null $latency * @return self */ public function setLatency(?float $latency): self { $this->latency = $latency; return $this; } /** * @return Downtime[] */ public function getDowntimes(): array { return $this->downtimes; } /** * @param Downtime[] $downtimes * @return self */ public function setDowntimes(array $downtimes): self { $this->downtimes = $downtimes; return $this; } /** * @return Acknowledgement|null */ public function getAcknowledgement(): ?Acknowledgement { return $this->acknowledgement; } /** * @param Acknowledgement|null $acknowledgement * @return self */ public function setAcknowledgement(?Acknowledgement $acknowledgement): self { $this->acknowledgement = $acknowledgement; return $this; } /** * Get groups to which belongs the resource. * * @return ResourceGroup[] */ public function getGroups(): array { return $this->groups; } /** * Set groups to which belongs the resource * * @param ResourceGroup[] $groups * @throws \InvalidArgumentException * @return self */ public function setGroups(array $groups): self { foreach ($groups as $group) { if (! ($group instanceof ResourceGroup)) { throw new \InvalidArgumentException(_('One of the elements provided is not a ResourceGroup type')); } } $this->groups = $groups; return $this; } /** * @param string|null $calculationType * @return self */ public function setCalculationType(?string $calculationType): self { $this->calculationType = $calculationType; return $this; } /** * @return string|null */ public function getCalculationType(): ?string { return $this->calculationType; } // @return boolean public function isNotificationEnabled(): bool { return $this->notificationEnabled; } /** * @param bool $notificationEnabled * @return self */ public function setNotificationEnabled(bool $notificationEnabled): self { $this->notificationEnabled = $notificationEnabled; return $this; } /** * @param bool $hasGraph * @return self */ public function setHasGraph(bool $hasGraph): self { $this->hasGraph = $hasGraph; return $this; } /** * @return bool */ public function hasGraph(): bool { return $this->hasGraph; } /** * @param int|null $resourceId * @return self */ public function setResourceId(?int $resourceId): self { $this->resourceId = $resourceId; return $this; } /** * @return int|null */ public function getResourceId(): ?int { return $this->resourceId; } /** * @param Severity|null $severity * @return self */ public function setSeverity(?Severity $severity): self { $this->severity = $severity; return $this; } /** * @return Severity|null */ public function getSeverity(): ?Severity { return $this->severity; } /** * @return int|null */ public function getInternalId(): ?int { return $this->internalId; } /** * @param int|null $internalId * @return self */ public function setInternalId(?int $internalId): self { $this->internalId = $internalId; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Monitoring/ServiceGroup.php
centreon/src/Centreon/Domain/Monitoring/ServiceGroup.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Monitoring; use Centreon\Domain\Service\EntityDescriptorMetadataInterface; /** * Class representing a record of a service group in the repository. * * @package Centreon\Domain\Monitoring */ class ServiceGroup implements EntityDescriptorMetadataInterface { // Groups for serilizing public const SERIALIZER_GROUP_MAIN = 'sg_main'; public const SERIALIZER_GROUP_WITH_HOST = 'sg_with_host'; /** @var int */ private $id; /** @var Host[] */ private $hosts = []; /** @var string|null */ private $name; /** * {@inheritDoc} */ public static function loadEntityDescriptorMetadata(): array { return [ 'servicegroup_id' => 'setId', ]; } /** * @return int */ public function getId(): int { return $this->id; } /** * @param int $id * @return ServiceGroup */ public function setId(int $id): ServiceGroup { $this->id = $id; return $this; } /** * @param Host $host * @return ServiceGroup */ public function addHost(Host $host): ServiceGroup { $this->hosts[] = $host; return $this; } /** * @return Host[] */ public function getHosts(): array { return $this->hosts; } /** * @param Host[] $hosts * @return ServiceGroup */ public function setHosts(array $hosts): ServiceGroup { $this->hosts = $hosts; return $this; } /** * Indicates if a host exists in this service group. * * @param int $hostId Host id to find * @return bool */ public function isHostExists(int $hostId): bool { foreach ($this->hosts as $host) { if ($host->getId() === $hostId) { return true; } } return false; } /** * @return string|null */ public function getName(): ?string { return $this->name; } /** * @param string|null $name * @return ServiceGroup */ public function setName(?string $name): ServiceGroup { $this->name = $name; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Monitoring/Notes.php
centreon/src/Centreon/Domain/Monitoring/Notes.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Monitoring; /** * Class representing a record of a note in the repository. * * @package Centreon\Domain\Monitoring */ class Notes { /** @var string|null */ private $label; /** @var string|null */ private $url; /** * Get label * * @return string|null */ public function getLabel(): ?string { return $this->label; } /** * Set notes * * @param string|null $label * @return self */ public function setLabel(?string $label): self { $this->label = $label; return $this; } /** * Get url * * @return string|null */ public function getUrl(): ?string { return $this->url; } /** * Set url * * @param string|null $url * @return self */ public function setUrl(?string $url): self { $this->url = $url; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Monitoring/ResourceLinksUris.php
centreon/src/Centreon/Domain/Monitoring/ResourceLinksUris.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Monitoring; /** * Resource Links Uris model for resource repository * * @package Centreon\Domain\Monitoring */ class ResourceLinksUris { /** @var string|null */ private $configuration; /** @var string|null */ private $logs; /** @var string|null */ private $reporting; /** * @return string|null */ public function getConfiguration(): ?string { return $this->configuration; } /** * @param string|null $configuration * @return self */ public function setConfiguration(?string $configuration): self { $this->configuration = $configuration; return $this; } /** * @return string|null */ public function getLogs(): ?string { return $this->logs; } /** * @param string|null $logs * @return self */ public function setLogs(?string $logs): self { $this->logs = $logs; return $this; } /** * @return string|null */ public function getReporting(): ?string { return $this->reporting; } /** * @param string|null $reporting * @return self */ public function setReporting(?string $reporting): self { $this->reporting = $reporting; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Monitoring/CommandLineTrait.php
centreon/src/Centreon/Domain/Monitoring/CommandLineTrait.php
<?php /* * Copyright 2005 - 2025 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 * * https://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 * */ declare(strict_types=1); namespace Centreon\Domain\Monitoring; use Centreon\Domain\Macro\Interfaces\MacroInterface; use Centreon\Domain\Monitoring\Exception\MonitoringServiceException; trait CommandLineTrait { /** * Build command line by comparing monitoring & configuration commands * and by replacing macros in configuration command * * @param string $configurationCommand * @param string $monitoringCommand * @param MacroInterface[] $macros * @param string $replacementValue * @return string */ private function buildCommandLineFromConfiguration( string $configurationCommand, string $monitoringCommand, array $macros, string $replacementValue, ): string { // if the command line contains $$ after a macro (so $$$), delete one of them to match with // the command executed by centreon-engine $configurationCommand = str_replace('$$$', '$$', $configurationCommand); $macroPasswordNames = []; foreach ($macros as $macro) { if ($macro->isPassword()) { // if macro is a password, store its name and let macro in configuration command $macroPasswordNames[] = $macro->getName(); } elseif ($macro->getName() !== null && $macro->getValue() !== null) { // if macro is not a password, replace it by its configuration value $configurationCommand = str_replace($macro->getName(), trim($macro->getValue()), $configurationCommand); } } if ($macroPasswordNames === []) { return $monitoringCommand; } $foundMacroNames = $this->extractMacroNamesFromCommandLine($configurationCommand); $macroPattern = $this->generateCommandMacroPattern($configurationCommand); $macroLazyPattern = str_replace('(.*)', '(.*?)', $macroPattern); if (preg_match('/' . $macroPattern . '/', $monitoringCommand, $foundMacroValues)) { // lazy and greedy regex should return the same result // otherwise, it is not possible to know which section is the password if ( preg_match('/' . $macroLazyPattern . '/', $monitoringCommand, $foundMacroLazyValues) && $foundMacroLazyValues !== $foundMacroValues ) { throw MonitoringServiceException::macroPasswordNotDetected(); } array_shift($foundMacroValues); // remove global string matching // replace macros found in configuration command by matched value from monitoring command foreach ($foundMacroNames as $index => $foundMacroName) { $foundMacroValue = $foundMacroValues[$index]; // if macro is a password, we replace it by replacement value (usually ****) $macroValue = in_array($foundMacroName, $macroPasswordNames) ? $replacementValue : $foundMacroValue; $configurationCommand = str_replace($foundMacroName, $macroValue, $configurationCommand); } } else { // configuration and monitoring commands do not match // so last configuration has not been applied throw MonitoringServiceException::configurationHasChanged(); } return $configurationCommand; } /** * Extra macro names from configuration command line * example : ['$HOSTADDRESS$', '$_SERVICEPASSWORD$'] * * @param string $commandLine * @return string[] The list of macro names */ private function extractMacroNamesFromCommandLine(string $commandLine): array { $foundMacroNames = []; if (preg_match_all('/(\$\S+?\$)/', $commandLine, $matches)) { if ($matches !== []) { $foundMacroNames = $matches[0]; } } return $foundMacroNames; } /** * Build a regex to identify macro associated value * example : * - configuration command : $USER1$/check_icmp -H $HOSTADDRESS$ $_HOSTPASSWORD$ * - generated regex : ^(.*)\/check_icmp \-H (.*) (.*)$ * - monitoring : /usr/lib64/nagios/plugins/check_icmp -H 127.0.0.1 hiddenPassword * ==> matched values : [/usr/lib64/nagios/plugins/check_icmp, hiddenPassword] * * @param string $configurationCommand * @throws MonitoringServiceException * @return string */ private function generateCommandMacroPattern(string $configurationCommand): string { $countFoundMacros = 0; if (preg_match_all('/(\$\S+?\$)/', $configurationCommand, $matches)) { if ($matches !== []) { $countFoundMacros = count($matches[0]); } } $commandSplittedByMacros = preg_split('/(\$\S+?\$)/', $configurationCommand); if ($commandSplittedByMacros === false) { throw MonitoringServiceException::configurationCommandNotSplitted(); } $macroPattern = '^'; foreach ($commandSplittedByMacros as $index => $commandSection) { $macroMatcher = (($index + 1) <= $countFoundMacros) ? '(.*)' : ''; $macroPattern .= preg_quote($commandSection, '/') . $macroMatcher; } $macroPattern .= '$'; // if two macros are glued or separated by spaces, regex cannot detect properly password string if (preg_match('/\(\.\*\)\s*\(\.\*\)/', $macroPattern)) { throw MonitoringServiceException::macroPasswordNotDetected(); } return $macroPattern; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false