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/Monitoring/Host.php | centreon/src/Centreon/Domain/Monitoring/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\Monitoring;
use Centreon\Domain\Acknowledgement\Acknowledgement;
use Centreon\Domain\Downtime\Downtime;
use Centreon\Domain\Service\EntityDescriptorMetadataInterface;
/**
* Class representing a record of a host in the repository.
*
* @package Centreon\Domain\Monitoring
*/
class Host implements EntityDescriptorMetadataInterface
{
// Groups for serilizing
public const SERIALIZER_GROUP_MIN = 'host_min';
public const SERIALIZER_GROUP_MAIN = 'host_main';
public const SERIALIZER_GROUP_FULL = 'host_full';
public const SERIALIZER_GROUP_WITH_SERVICES = 'host_with_services';
// Status options
public const STATUS_UP = 0;
public const STATUS_DOWN = 1;
public const STATUS_UNREACHABLE = 2;
/** @var int|null Id of host */
protected $id;
/** @var int Poller id */
protected $pollerId;
/** @var string Name of host */
protected $name;
/** @var bool|null */
protected $acknowledged;
/** @var bool|null */
protected $activeChecks;
/** @var string|null Ip address or domain name */
protected $addressIp;
/** @var string|null Alias of host */
protected $alias;
/** @var int|null */
protected $checkAttempt;
/** @var string|null */
protected $checkCommand;
/** @var float|null */
protected $checkInterval;
/** @var string|null */
protected $checkPeriod;
/** @var int|null */
protected $checkType;
/** @var bool|null */
protected $checked;
/** @var string|null */
protected $displayName;
/** @var bool */
protected $enabled;
/** @var float|null */
protected $executionTime;
/** @var string|null */
protected $iconImage;
/** @var string|null */
protected $iconImageAlt;
/** @var \DateTime|null */
protected $lastCheck;
/** @var int|null */
protected $lastHardState;
/** @var \DateTime|null */
protected $lastHardStateChange;
/** @var \DateTime|null */
protected $lastNotification;
/** @var \DateTime|null */
protected $lastStateChange;
/** @var \DateTime|null */
protected $lastTimeDown;
/** @var \DateTime|null */
protected $lastTimeUnreachable;
/** @var \DateTime|null */
protected $lastTimeUp;
/** @var \DateTime|null */
protected $lastUpdate;
/** @var float|null */
protected $latency;
/** @var int|null */
protected $maxCheckAttempts;
/** @var \DateTime|null */
protected $nextCheck;
/** @var int|null */
protected $nextHostNotification;
/** @var float|null */
protected $notificationInterval;
/** @var int|null */
protected $notificationNumber;
/** @var string|null */
protected $notificationPeriod;
/** @var bool|null */
protected $notify;
/** @var bool|null */
protected $notifyOnDown;
/** @var bool|null */
protected $notifyOnDowntime;
/** @var bool|null */
protected $notifyOnFlapping;
/** @var bool|null */
protected $notifyOnRecovery;
/** @var bool|null */
protected $notifyOnUnreachable;
/** @var string|null */
protected $output;
/** @var bool|null */
protected $passiveChecks;
/** @var Service[] */
protected $services = [];
/** @var int|null ['0' => 'UP', '1' => 'DOWN', '2' => 'UNREACHABLE', '4' => 'PENDING'] */
protected $state;
/** @var int|null */
protected $stateType;
/** @var string|null */
protected $timezone;
/** @var int|null */
protected $scheduledDowntimeDepth;
/** @var int|null */
protected $criticality;
/** @var bool|null */
protected $flapping;
/** @var float|null */
protected $percentStateChange;
/** @var Downtime[] */
protected $downtimes = [];
/** @var Acknowledgement|null */
protected $acknowledgement;
/** @var string|null */
protected $pollerName;
/**
* {@inheritDoc}
*/
public static function loadEntityDescriptorMetadata(): array
{
return [
'host_id' => 'setId',
'instance_id' => 'setPollerId',
'address' => 'setAddressIp',
'acknowledged' => 'setAcknowledged',
];
}
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @param int $id
* @return Host
*/
public function setId(int $id): Host
{
$this->id = $id;
return $this;
}
/**
* @return int
*/
public function getPollerId(): int
{
return $this->pollerId;
}
/**
* @param int $pollerId
* @return Host
*/
public function setPollerId(int $pollerId): Host
{
$this->pollerId = $pollerId;
return $this;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
* @return Host
*/
public function setName(string $name): Host
{
$this->name = $name;
return $this;
}
/**
* @return bool|null
*/
public function getAcknowledged(): ?bool
{
return $this->acknowledged;
}
/**
* @param bool|null $acknowledged
* @return Host
*/
public function setAcknowledged(?bool $acknowledged): Host
{
$this->acknowledged = $acknowledged;
return $this;
}
/**
* @return bool|null
*/
public function getActiveChecks(): ?bool
{
return $this->activeChecks;
}
/**
* @param bool|null $activeChecks
* @return Host
*/
public function setActiveChecks(?bool $activeChecks): Host
{
$this->activeChecks = $activeChecks;
return $this;
}
/**
* @return string|null
*/
public function getAddressIp(): ?string
{
return $this->addressIp;
}
/**
* @param string|null $addressIp
* @return Host
*/
public function setAddressIp(?string $addressIp): Host
{
$this->addressIp = $addressIp;
return $this;
}
/**
* @return string|null
*/
public function getAlias(): ?string
{
return $this->alias;
}
/**
* @param string|null $alias
* @return Host
*/
public function setAlias(?string $alias): Host
{
$this->alias = $alias;
return $this;
}
/**
* @return int|null
*/
public function getCheckAttempt(): ?int
{
return $this->checkAttempt;
}
/**
* @param int|null $checkAttempt
* @return Host
*/
public function setCheckAttempt(?int $checkAttempt): Host
{
$this->checkAttempt = $checkAttempt;
return $this;
}
/**
* @return string|null
*/
public function getCheckCommand(): ?string
{
return $this->checkCommand;
}
/**
* @param string|null $checkCommand
* @return Host
*/
public function setCheckCommand(?string $checkCommand): Host
{
$this->checkCommand = $checkCommand;
return $this;
}
/**
* @return float|null
*/
public function getCheckInterval(): ?float
{
return $this->checkInterval;
}
/**
* @param float|null $checkInterval
* @return Host
*/
public function setCheckInterval(?float $checkInterval): Host
{
$this->checkInterval = $checkInterval;
return $this;
}
/**
* @return string|null
*/
public function getCheckPeriod(): ?string
{
return $this->checkPeriod;
}
/**
* @param string|null $checkPeriod
* @return Host
*/
public function setCheckPeriod(?string $checkPeriod): Host
{
$this->checkPeriod = $checkPeriod;
return $this;
}
/**
* @return int|null
*/
public function getCheckType(): ?int
{
return $this->checkType;
}
/**
* @param int|null $checkType
* @return Host
*/
public function setCheckType(?int $checkType): Host
{
$this->checkType = $checkType;
return $this;
}
/**
* @return bool|null
*/
public function getChecked(): ?bool
{
return $this->checked;
}
/**
* @param bool|null $checked
* @return Host
*/
public function setChecked(?bool $checked): Host
{
$this->checked = $checked;
return $this;
}
/**
* @return string|null
*/
public function getDisplayName(): ?string
{
return $this->displayName;
}
/**
* @param string|null $displayName
* @return Host
*/
public function setDisplayName(?string $displayName): Host
{
$this->displayName = $displayName;
return $this;
}
/**
* @return bool
*/
public function isEnabled(): bool
{
return $this->enabled;
}
/**
* @param bool $enabled
* @return Host
*/
public function setEnabled(bool $enabled): Host
{
$this->enabled = $enabled;
return $this;
}
/**
* @return float|null
*/
public function getExecutionTime(): ?float
{
return $this->executionTime;
}
/**
* @param float|null $executionTime
* @return Host
*/
public function setExecutionTime(?float $executionTime): Host
{
$this->executionTime = $executionTime;
return $this;
}
/**
* @return string|null
*/
public function getIconImage(): ?string
{
return $this->iconImage;
}
/**
* @param string|null $iconImage
* @return Host
*/
public function setIconImage(?string $iconImage): Host
{
$this->iconImage = $iconImage;
return $this;
}
/**
* @return string|null
*/
public function getIconImageAlt(): ?string
{
return $this->iconImageAlt;
}
/**
* @param string|null $iconImageAlt
* @return Host
*/
public function setIconImageAlt(?string $iconImageAlt): Host
{
$this->iconImageAlt = $iconImageAlt;
return $this;
}
/**
* @return \DateTime|null
*/
public function getLastCheck(): ?\DateTime
{
return $this->lastCheck;
}
/**
* @param \DateTime|null $lastCheck
* @return Host
*/
public function setLastCheck(?\DateTime $lastCheck): Host
{
$this->lastCheck = $lastCheck;
return $this;
}
/**
* @return int|null
*/
public function getLastHardState(): ?int
{
return $this->lastHardState;
}
/**
* @param int|null $lastHardState
* @return Host
*/
public function setLastHardState(?int $lastHardState): Host
{
$this->lastHardState = $lastHardState;
return $this;
}
/**
* @return \DateTime|null
*/
public function getLastHardStateChange(): ?\DateTime
{
return $this->lastHardStateChange;
}
/**
* @param \DateTime|null $lastHardStateChange
* @return Host
*/
public function setLastHardStateChange(?\DateTime $lastHardStateChange): Host
{
$this->lastHardStateChange = $lastHardStateChange;
return $this;
}
/**
* @return \DateTime|null
*/
public function getLastNotification(): ?\DateTime
{
return $this->lastNotification;
}
/**
* @param \DateTime|null $lastNotification
* @return Host
*/
public function setLastNotification(?\DateTime $lastNotification): Host
{
$this->lastNotification = $lastNotification;
return $this;
}
/**
* @return \DateTime|null
*/
public function getLastStateChange(): ?\DateTime
{
return $this->lastStateChange;
}
/**
* @param \DateTime|null $lastStateChange
* @return Host
*/
public function setLastStateChange(?\DateTime $lastStateChange): Host
{
$this->lastStateChange = $lastStateChange;
return $this;
}
/**
* @return \DateTime|null
*/
public function getLastTimeDown(): ?\DateTime
{
return $this->lastTimeDown;
}
/**
* @param \DateTime|null $lastTimeDown
* @return Host
*/
public function setLastTimeDown(?\DateTime $lastTimeDown): Host
{
$this->lastTimeDown = $lastTimeDown;
return $this;
}
/**
* @return \DateTime|null
*/
public function getLastTimeUnreachable(): ?\DateTime
{
return $this->lastTimeUnreachable;
}
/**
* @param \DateTime|null $lastTimeUnreachable
* @return Host
*/
public function setLastTimeUnreachable(?\DateTime $lastTimeUnreachable): Host
{
$this->lastTimeUnreachable = $lastTimeUnreachable;
return $this;
}
/**
* @return \DateTime|null
*/
public function getLastTimeUp(): ?\DateTime
{
return $this->lastTimeUp;
}
/**
* @param \DateTime|null $lastTimeUp
* @return Host
*/
public function setLastTimeUp(?\DateTime $lastTimeUp): Host
{
$this->lastTimeUp = $lastTimeUp;
return $this;
}
/**
* @return \DateTime|null
*/
public function getLastUpdate(): ?\DateTime
{
return $this->lastUpdate;
}
/**
* @param \DateTime|null $lastUpdate
* @return Host
*/
public function setLastUpdate(?\DateTime $lastUpdate): Host
{
$this->lastUpdate = $lastUpdate;
return $this;
}
/**
* @return float|null
*/
public function getLatency(): ?float
{
return $this->latency;
}
/**
* @param float|null $latency
* @return Host
*/
public function setLatency(?float $latency): Host
{
$this->latency = $latency;
return $this;
}
/**
* @return int|null
*/
public function getMaxCheckAttempts(): ?int
{
return $this->maxCheckAttempts;
}
/**
* @param int|null $maxCheckAttempts
* @return Host
*/
public function setMaxCheckAttempts(?int $maxCheckAttempts): Host
{
$this->maxCheckAttempts = $maxCheckAttempts;
return $this;
}
/**
* @return \DateTime|null
*/
public function getNextCheck(): ?\DateTime
{
return $this->nextCheck;
}
/**
* @param \DateTime|null $nextCheck
* @return Host
*/
public function setNextCheck(?\DateTime $nextCheck): Host
{
$this->nextCheck = $nextCheck;
return $this;
}
/**
* @return int|null
*/
public function getNextHostNotification(): ?int
{
return $this->nextHostNotification;
}
/**
* @param int|null $nextHostNotification
* @return Host
*/
public function setNextHostNotification(?int $nextHostNotification): Host
{
$this->nextHostNotification = $nextHostNotification;
return $this;
}
/**
* @return float|null
*/
public function getNotificationInterval(): ?float
{
return $this->notificationInterval;
}
/**
* @param float|null $notificationInterval
* @return Host
*/
public function setNotificationInterval(?float $notificationInterval): Host
{
$this->notificationInterval = $notificationInterval;
return $this;
}
/**
* @return int|null
*/
public function getNotificationNumber(): ?int
{
return $this->notificationNumber;
}
/**
* @param int|null $notificationNumber
* @return Host
*/
public function setNotificationNumber(?int $notificationNumber): Host
{
$this->notificationNumber = $notificationNumber;
return $this;
}
/**
* @return string|null
*/
public function getNotificationPeriod(): ?string
{
return $this->notificationPeriod;
}
/**
* @param string|null $notificationPeriod
* @return Host
*/
public function setNotificationPeriod(?string $notificationPeriod): Host
{
$this->notificationPeriod = $notificationPeriod;
return $this;
}
/**
* @return bool|null
*/
public function getNotify(): ?bool
{
return $this->notify;
}
/**
* @param bool|null $notify
* @return Host
*/
public function setNotify(?bool $notify): Host
{
$this->notify = $notify;
return $this;
}
/**
* @return bool|null
*/
public function getNotifyOnDown(): ?bool
{
return $this->notifyOnDown;
}
/**
* @param bool|null $notifyOnDown
* @return Host
*/
public function setNotifyOnDown(?bool $notifyOnDown): Host
{
$this->notifyOnDown = $notifyOnDown;
return $this;
}
/**
* @return bool|null
*/
public function getNotifyOnDowntime(): ?bool
{
return $this->notifyOnDowntime;
}
/**
* @param bool|null $notifyOnDowntime
* @return Host
*/
public function setNotifyOnDowntime(?bool $notifyOnDowntime): Host
{
$this->notifyOnDowntime = $notifyOnDowntime;
return $this;
}
/**
* @return bool|null
*/
public function getNotifyOnFlapping(): ?bool
{
return $this->notifyOnFlapping;
}
/**
* @param bool|null $notifyOnFlapping
* @return Host
*/
public function setNotifyOnFlapping(?bool $notifyOnFlapping): Host
{
$this->notifyOnFlapping = $notifyOnFlapping;
return $this;
}
/**
* @return bool|null
*/
public function getNotifyOnRecovery(): ?bool
{
return $this->notifyOnRecovery;
}
/**
* @param bool|null $notifyOnRecovery
* @return Host
*/
public function setNotifyOnRecovery(?bool $notifyOnRecovery): Host
{
$this->notifyOnRecovery = $notifyOnRecovery;
return $this;
}
/**
* @return bool|null
*/
public function getNotifyOnUnreachable(): ?bool
{
return $this->notifyOnUnreachable;
}
/**
* @param bool|null $notifyOnUnreachable
* @return Host
*/
public function setNotifyOnUnreachable(?bool $notifyOnUnreachable): Host
{
$this->notifyOnUnreachable = $notifyOnUnreachable;
return $this;
}
/**
* @return string|null
*/
public function getOutput(): ?string
{
return $this->output;
}
/**
* @param string|null $output
* @return Host
*/
public function setOutput(?string $output): Host
{
$this->output = $output;
return $this;
}
/**
* @return bool|null
*/
public function getPassiveChecks(): ?bool
{
return $this->passiveChecks;
}
/**
* @param bool|null $passiveChecks
* @return Host
*/
public function setPassiveChecks(?bool $passiveChecks): Host
{
$this->passiveChecks = $passiveChecks;
return $this;
}
/**
* @return Service[]
*/
public function getServices(): array
{
return $this->services;
}
/**
* @param Service[] $services
* @return Host
*/
public function setServices(array $services): Host
{
$this->services = $services;
return $this;
}
/**
* @param Service $service
*/
public function addService(Service $service): void
{
$this->services[] = $service;
}
/**
* @return int|null
*/
public function getState(): ?int
{
return $this->state;
}
/**
* @param int|null $state
* @return Host
*/
public function setState(?int $state): Host
{
$this->state = $state;
return $this;
}
/**
* @return int|null
*/
public function getStateType(): ?int
{
return $this->stateType;
}
/**
* @param int|null $stateType
* @return Host
*/
public function setStateType(?int $stateType): Host
{
$this->stateType = $stateType;
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 Host
*/
public function setTimezone(?string $timezone): Host
{
$this->timezone = $timezone;
return $this;
}
/**
* @return int|null
*/
public function getScheduledDowntimeDepth(): ?int
{
return $this->scheduledDowntimeDepth;
}
/**
* @param int|null $scheduledDowntimeDepth
* @return Host
*/
public function setScheduledDowntimeDepth(?int $scheduledDowntimeDepth): Host
{
$this->scheduledDowntimeDepth = $scheduledDowntimeDepth;
return $this;
}
/**
* @return int|null
*/
public function getCriticality(): ?int
{
return $this->criticality;
}
/**
* @param int|null $criticality
* @return Host
*/
public function setCriticality(?int $criticality): Host
{
$this->criticality = $criticality;
return $this;
}
/**
* @return bool|null
*/
public function getFlapping(): ?bool
{
return $this->flapping;
}
/**
* @param bool|null $flapping
* @return Host
*/
public function setFlapping(?bool $flapping): Host
{
$this->flapping = $flapping;
return $this;
}
/**
* @return float|null
*/
public function getPercentStateChange(): ?float
{
return $this->percentStateChange;
}
/**
* @param float|null $percentStateChange
* @return Host
*/
public function setPercentStateChange(?float $percentStateChange): Host
{
$this->percentStateChange = $percentStateChange;
return $this;
}
/**
* @return Downtime[]
*/
public function getDowntimes(): array
{
return $this->downtimes;
}
/**
* @param Downtime[] $downtimes
* @return Host
*/
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 Host
*/
public function setAcknowledgement(?Acknowledgement $acknowledgement): self
{
$this->acknowledgement = $acknowledgement;
return $this;
}
/**
* @return string|null
*/
public function getPollerName(): ?string
{
return $this->pollerName;
}
/**
* @param string|null $pollerName
* @return self
*/
public function setPollerName(?string $pollerName): self
{
$this->pollerName = $pollerName;
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/Model/Comment.php | centreon/src/Centreon/Domain/Monitoring/Model/Comment.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\Model;
class Comment
{
/** @var int|null */
private $id;
/** @var \DateTime|null */
private $entryTime;
/** @var int|null */
private $hostId;
/** @var int|null */
private $serviceId;
/** @var string|null */
private $author;
/** @var string|null */
private $data;
/** @var \DateTime|null */
private $deletionTime;
/** @var int|null */
private $entryType;
/** @var \DateTime|null */
private $expireTime;
/** @var int|null */
private $expires;
/** @var int|null */
private $instanceId;
/** @var int|null */
private $internalId;
/** @var int|null */
private $persistent;
/** @var int|null */
private $source;
/** @var int|null */
private $type;
/**
* @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
*/
public function setEntryTime(?\DateTime $entryTime): void
{
$this->entryTime = $entryTime;
}
/**
* @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 null|string
*/
public function getAuthor(): ?string
{
return $this->author;
}
/**
* @param null|string $author
*/
public function setAuthor(?string $author): void
{
$this->author = $author;
}
/**
* @return null|string
*/
public function getData(): ?string
{
return $this->data;
}
/**
* @param null|string $data
*/
public function setData(?string $data): void
{
$this->data = $data;
}
/**
* @return \DateTime|null
*/
public function getDeletionTime(): ?\DateTime
{
return $this->deletionTime;
}
/**
* @param \DateTime|null $deletionTime
*/
public function setDeletionTime(?\DateTime $deletionTime): void
{
$this->deletionTime = $deletionTime;
}
/**
* @return int|null
*/
public function getEntryType(): ?int
{
return $this->entryType;
}
/**
* @param int|null $entryType
*/
public function setEntryType(?int $entryType): void
{
$this->entryType = $entryType;
}
/**
* @return \DateTime|null
*/
public function getExpireTime(): ?\DateTime
{
return $this->expireTime;
}
/**
* @param \DateTime|null $expireTime
*/
public function setExpireTime(?\DateTime $expireTime): void
{
$this->expireTime = $expireTime;
}
/**
* @return int|null
*/
public function getExpires(): ?int
{
return $this->expires;
}
/**
* @param int|null $expires
*/
public function setExpires(?int $expires): void
{
$this->expires = $expires;
}
/**
* @return int|null
*/
public function getInstanceId(): ?int
{
return $this->instanceId;
}
/**
* @param int|null $instanceId
*/
public function setInstanceId(?int $instanceId): void
{
$this->instanceId = $instanceId;
}
/**
* @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 getPersistent(): ?int
{
return $this->persistent;
}
/**
* @param int|null $persistent
*/
public function setPersistent(?int $persistent): void
{
$this->persistent = $persistent;
}
/**
* @return int|null
*/
public function getSource(): ?int
{
return $this->source;
}
/**
* @param int|null $source
*/
public function setSource(?int $source): void
{
$this->source = $source;
}
/**
* @return int|null
*/
public function getType(): ?int
{
return $this->type;
}
/**
* @param int|null $type
*/
public function setType(?int $type): void
{
$this->type = $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/Monitoring/MetaService/MetaServiceMetricService.php | centreon/src/Centreon/Domain/Monitoring/MetaService/MetaServiceMetricService.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\MetaService;
use Centreon\Domain\Contact\Interfaces\ContactInterface;
use Centreon\Domain\MetaServiceConfiguration\Interfaces\MetaServiceConfigurationServiceInterface;
use Centreon\Domain\MetaServiceConfiguration\Model\MetaServiceConfiguration;
use Centreon\Domain\Monitoring\MetaService\Exception\MetaServiceMetricException;
use Centreon\Domain\Monitoring\MetaService\Interfaces\MetaServiceMetric\MetaServiceMetricRepositoryInterface;
use Centreon\Domain\Monitoring\MetaService\Interfaces\MetaServiceMetric\MetaServiceMetricServiceInterface;
/**
* This class is designed to manage Meta Service Metrics.
*
* @package Centreon\Domain\Monitoring\MetaService
*/
class MetaServiceMetricService implements MetaServiceMetricServiceInterface
{
/** @var MetaServiceConfigurationServiceInterface */
private $metaServiceConfigurationService;
/** @var MetaServiceMetricRepositoryInterface */
private $repository;
/** @var ContactInterface */
private $contact;
/**
* @param MetaServiceMetricRepositoryInterface $repository
* @param MetaServiceConfigurationServiceInterface $metaServiceConfigurationService
* @param ContactInterface $contact
*/
public function __construct(
MetaServiceMetricRepositoryInterface $repository,
MetaServiceConfigurationServiceInterface $metaServiceConfigurationService,
ContactInterface $contact,
) {
$this->contact = $contact;
$this->repository = $repository;
$this->metaServiceConfigurationService = $metaServiceConfigurationService;
}
/**
* @inheritDoc
*/
public function findWithAcl(int $metaId): ?array
{
/**
* Find the Meta Service configuration and Metric selection mode
*/
$metaServiceConfiguration = $this->metaServiceConfigurationService->findWithAcl($metaId);
if (is_null($metaServiceConfiguration)) {
throw MetaServiceMetricException::findMetaServiceException($metaId);
}
$metaServiceMetricSelectionMode = $metaServiceConfiguration->getMetaSelectMode();
if ($metaServiceMetricSelectionMode === MetaServiceConfiguration::META_SELECT_MODE_LIST) {
try {
return $this->repository->findByMetaIdAndContact($metaId, $this->contact);
} catch (\Throwable $ex) {
throw MetaServiceMetricException::findMetaServiceMetricsException($ex, $metaId);
}
} elseif ($metaServiceMetricSelectionMode === MetaServiceConfiguration::META_SELECT_MODE_SQL_REGEXP) {
try {
return $this->repository->findByContactAndSqlRegexp(
$metaServiceConfiguration->getMetric(),
$metaServiceConfiguration->getRegexpString(),
$this->contact
);
} catch (\Throwable $ex) {
throw MetaServiceMetricException::findMetaServiceMetricsException($ex, $metaId);
}
} else {
throw MetaServiceMetricException::unknownMetaMetricSelectionMode($metaId);
}
}
/**
* @inheritDoc
*/
public function findWithoutAcl(int $metaId): ?array
{
/**
* Find the Meta Service configuration
*/
$metaServiceConfiguration = $this->metaServiceConfigurationService->findWithoutAcl($metaId);
if (is_null($metaServiceConfiguration)) {
throw MetaServiceMetricException::findMetaServiceException($metaId);
}
$metaServiceMetricSelectionMode = $metaServiceConfiguration->getMetaSelectMode();
if ($metaServiceMetricSelectionMode === MetaServiceConfiguration::META_SELECT_MODE_LIST) {
try {
return $this->repository->findByMetaId($metaId);
} catch (\Throwable $ex) {
throw MetaServiceMetricException::findMetaServiceMetricsException($ex, $metaId);
}
} elseif ($metaServiceMetricSelectionMode === MetaServiceConfiguration::META_SELECT_MODE_SQL_REGEXP) {
try {
return $this->repository->findBySqlRegexp(
$metaServiceConfiguration->getMetric(),
$metaServiceConfiguration->getRegexpString()
);
} catch (\Throwable $ex) {
throw MetaServiceMetricException::findMetaServiceMetricsException($ex, $metaId);
}
} else {
throw MetaServiceMetricException::unknownMetaMetricSelectionMode($metaId);
}
}
}
| 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/MetaService/Model/MetaServiceMetric.php | centreon/src/Centreon/Domain/Monitoring/MetaService/Model/MetaServiceMetric.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\MetaService\Model;
use Centreon\Domain\Common\Assertion\Assertion;
use Centreon\Domain\Monitoring\Resource as ResourceEntity;
/**
* This class is designed to represent a meta service metric.
*
* @package Centreon\Domain\Monitoring\MetaService\Model
*/
class MetaServiceMetric
{
public const MAX_METRIC_NAME_LENGTH = 255;
public const MIN_METRIC_NAME_LENGTH = 1;
public const MAX_METRIC_UNIT_NAME_LENGTH = 32;
/** @var int ID of the Metric */
private $id;
/** @var string Name of the Metric */
private $name;
/** @var string Name of the Metric Unit */
private $unit;
/** @var float Current value of the Metric in RealTime */
private $value;
/** @var ResourceEntity Resource on which Metric is attached */
private $resource;
/**
* Contructor of MetaServiceMetric entity
*
* @param string $name
*/
public function __construct(string $name)
{
$this->setName($name);
}
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @param int $id
* @return MetaServiceMetric
*/
public function setId(int $id): MetaServiceMetric
{
$this->id = $id;
return $this;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
* @throws \Assert\AssertionFailedException
* @return MetaServiceMetric
*/
public function setName(string $name): MetaServiceMetric
{
Assertion::maxLength($name, self::MAX_METRIC_NAME_LENGTH, 'MetaServiceMetric::name');
Assertion::minLength($name, self::MIN_METRIC_NAME_LENGTH, 'MetaServiceMetric::name');
$this->name = $name;
return $this;
}
/**
* @return string|null
*/
public function getUnit(): ?string
{
return $this->unit;
}
/**
* @param string|null $unit
* @throws \Assert\AssertionFailedException
* @return MetaServiceMetric
*/
public function setUnit(?string $unit): MetaServiceMetric
{
if (! is_null($unit)) {
Assertion::maxLength($unit, self::MAX_METRIC_UNIT_NAME_LENGTH, 'MetaServiceMetric::unit');
}
$this->unit = $unit;
return $this;
}
/**
* @return float
*/
public function getValue(): float
{
return $this->value;
}
/**
* @param float|null $value
* @return MetaServiceMetric
*/
public function setValue(?float $value): MetaServiceMetric
{
$this->value = $value;
return $this;
}
/**
* @return ResourceEntity|null
*/
public function getResource(): ?ResourceEntity
{
return $this->resource;
}
/**
* @param ResourceEntity|null $resource
* @return MetaServiceMetric
*/
public function setResource(?ResourceEntity $resource): MetaServiceMetric
{
$this->resource = $resource;
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/MetaService/UseCase/V21/MetaServiceMetric/FindMetaServiceMetrics.php | centreon/src/Centreon/Domain/Monitoring/MetaService/UseCase/V21/MetaServiceMetric/FindMetaServiceMetrics.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\MetaService\UseCase\V21\MetaServiceMetric;
use Centreon\Domain\Contact\Interfaces\ContactInterface;
use Centreon\Domain\Monitoring\MetaService\Exception\MetaServiceMetricException;
use Centreon\Domain\Monitoring\MetaService\Interfaces\MetaServiceMetric\MetaServiceMetricServiceInterface;
/**
* This class is designed to represent a use case to find all host categories.
*
* @package Centreon\Domain\Monitoring\MetaService\UseCase\V21
*/
class FindMetaServiceMetrics
{
/** @var MetaServiceMetricServiceInterface */
private $metaServiceMetricServiceInterface;
/** @var ContactInterface */
private $contact;
/**
* FindMetaServiceMetrics constructor.
*
* @param MetaServiceMetricServiceInterface $metaServiceMetricServiceInterface
* @param ContactInterface $contact
*/
public function __construct(
MetaServiceMetricServiceInterface $metaServiceMetricServiceInterface,
ContactInterface $contact,
) {
$this->metaServiceMetricServiceInterface = $metaServiceMetricServiceInterface;
$this->contact = $contact;
}
/**
* Execute the use case for which this class was designed.
* @param int $metaId
* @throws MetaServiceMetricException
* @return FindMetaServiceMetricsResponse
*/
public function execute(int $metaId): FindMetaServiceMetricsResponse
{
$response = new FindMetaServiceMetricsResponse();
$metaServiceMetrics = ($this->contact->isAdmin())
? $this->metaServiceMetricServiceInterface->findWithoutAcl($metaId)
: $this->metaServiceMetricServiceInterface->findWithAcl($metaId);
$response->setMetaServiceMetrics($metaServiceMetrics);
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/Monitoring/MetaService/UseCase/V21/MetaServiceMetric/FindMetaServiceMetricsResponse.php | centreon/src/Centreon/Domain/Monitoring/MetaService/UseCase/V21/MetaServiceMetric/FindMetaServiceMetricsResponse.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\MetaService\UseCase\V21\MetaServiceMetric;
use Centreon\Domain\Monitoring\MetaService\Model\MetaServiceMetric;
/**
* This class is a DTO for the FindMetaServiceMetrics use case.
*
* @package Centreon\Domain\Monitoring\MetaService\UseCase\V21\MetaServiceMetric
*/
class FindMetaServiceMetricsResponse
{
/** @var array<int, array<string, mixed>> */
private $metaServiceMetrics = [];
/**
* @param MetaServiceMetric[] $metaServiceMetrics
*/
public function setMetaServiceMetrics(array $metaServiceMetrics): void
{
foreach ($metaServiceMetrics as $metaServiceMetric) {
$this->metaServiceMetrics[] = [
'id' => $metaServiceMetric->getId(),
'name' => $metaServiceMetric->getName(),
'unit' => $metaServiceMetric->getUnit(),
'value' => $metaServiceMetric->getValue(),
'resource' => $metaServiceMetric->getResource(),
];
}
}
/**
* @return array<int, array<string, mixed>>
*/
public function getMetaServiceMetrics(): array
{
return $this->metaServiceMetrics;
}
}
| 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/MetaService/Interfaces/MetaServiceMetric/MetaServiceMetricServiceInterface.php | centreon/src/Centreon/Domain/Monitoring/MetaService/Interfaces/MetaServiceMetric/MetaServiceMetricServiceInterface.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\MetaService\Interfaces\MetaServiceMetric;
use Centreon\Domain\Monitoring\MetaService\Exception\MetaServiceMetricException;
use Centreon\Domain\Monitoring\MetaService\Model\MetaServiceMetric;
/**
* @package Centreon\Domain\Monitoring\MetaService\Interfaces\MetaServiceMetric
*/
interface MetaServiceMetricServiceInterface
{
/**
* Find all meta service metrics (for non admin user).
*
* @param int $metaId
* @throws MetaServiceMetricException
* @return MetaServiceMetric[]|null
*/
public function findWithoutAcl(int $metaId): ?array;
/**
* Find all meta service metrics (for admin user).
*
* @param int $metaId
* @throws MetaServiceMetricException
* @return MetaServiceMetric[]|null
*/
public function findWithAcl(int $metaId): ?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/Monitoring/MetaService/Interfaces/MetaServiceMetric/MetaServiceMetricRepositoryInterface.php | centreon/src/Centreon/Domain/Monitoring/MetaService/Interfaces/MetaServiceMetric/MetaServiceMetricRepositoryInterface.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\MetaService\Interfaces\MetaServiceMetric;
use Centreon\Domain\Contact\Interfaces\ContactInterface;
use Centreon\Domain\Monitoring\MetaService\Model\MetaServiceMetric;
/**
* This interface gathers all the reading operations on the meta service metric repository.
*
* @package Centreon\Domain\Monitoring\MetaService\Interfaces\MetaServiceMetric
*/
interface MetaServiceMetricRepositoryInterface
{
/**
* Find Meta Service Metrics for a non-admin user.
*
* @param int $metaId
* @param ContactInterface $contact
* @return MetaServiceMetric[]|null
*/
public function findByMetaIdAndContact(int $metaId, ContactInterface $contact): ?array;
/**
* Find Meta Service Metrics for a non-admin user using SQL regexp service search and metric.
*
* @param string $metricName
* @param string $regexpString
* @param ContactInterface $contact
* @return MetaServiceMetric[]|null
*/
public function findByContactAndSqlRegexp(
string $metricName,
string $regexpString,
ContactInterface $contact,
): ?array;
/**
* Find Meta Service Metrics for an admin user.
*
* @param int $metaId
* @return MetaServiceMetric[]|null
*/
public function findByMetaId(int $metaId): ?array;
/**
* Find Meta Service Metrics for an admin user using SQL regexp service search and metric.
* @param string $metricName
* @param string $regexpString
* @return MetaServiceMetric[]|null
*/
public function findBySqlRegexp(string $metricName, string $regexpString): ?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/Monitoring/MetaService/Exception/MetaServiceMetricException.php | centreon/src/Centreon/Domain/Monitoring/MetaService/Exception/MetaServiceMetricException.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\MetaService\Exception;
/**
* This class is designed to contain all exceptions for the context of the metaservice metrics
*
* @package Centreon\Domain\MetaService\Exception
*/
class MetaServiceMetricException extends \Exception
{
/**
* @param \Throwable $ex
* @return MetaServiceMetricException
*/
public static function findMetaServiceMetricsException(\Throwable $ex, int $metaId): self
{
return new self(
sprintf(_('Error when searching for the meta service (%d) metrics'), $metaId),
0,
$ex
);
}
/**
* Used when no meta service found
* @return self
*/
public static function findMetaServiceException(int $metaId): self
{
return new self(sprintf(_('Meta service with ID %d not found'), $metaId));
}
/**
* @param int $metaId
* @return self
*/
public static function unknownMetaMetricSelectionMode(int $metaId): self
{
return new self(sprintf(_('Unkown meta metrics selection mode provided for %d'), $metaId));
}
}
| 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/Interfaces/MonitoringServiceInterface.php | centreon/src/Centreon/Domain/Monitoring/Interfaces/MonitoringServiceInterface.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\Interfaces;
use Centreon\Domain\Contact\Interfaces\ContactFilterInterface;
use Centreon\Domain\Monitoring\Exception\MonitoringServiceException;
use Centreon\Domain\Monitoring\Host;
use Centreon\Domain\Monitoring\HostGroup;
use Centreon\Domain\Monitoring\Service;
use Centreon\Domain\Monitoring\ServiceGroup;
/**
* @package Centreon\Domain\Monitoring\Interfaces
*/
interface MonitoringServiceInterface extends ContactFilterInterface
{
/**
* Find all hosts.
*
* @param bool $withServices Indicates whether hosts must be completed with their services
* @throws \Exception
* @return Host[]
*/
public function findHosts(bool $withServices = false): array;
/**
* Find all host groups.
*
* @param bool $withHosts Indicates whether hosts groups must be completed with their hosts
* @param bool $withServices Indicates whether hosts must be completed with their services
* @param int|null $hostId Return only hostgroups for specific host null by default
* @throws \Exception
* @return HostGroup[]
*/
public function findHostGroups(bool $withHosts = false, bool $withServices = false, ?int $hostId = null): array;
/**
* Find a host based on his ID.
*
* @param int $hostId Id of the host to be found
* @throws \Exception
* @return Host|null
*/
public function findOneHost(int $hostId): ?Host;
/**
* Find a service based on his ID and a host ID.
*
* @param int $hostId Host ID for which the service belongs
* @param int $serviceId Service ID to find
* @throws \Exception
* @return Service|null
*/
public function findOneService(int $hostId, int $serviceId): ?Service;
/**
* Find a service based on its description
*
* @param string $description description of the service
* @throws \Exception
* @return Service|null
*/
public function findOneServiceByDescription(string $description): ?Service;
/**
* Find all service groups.
*
* @param bool $withHosts Indicates whether service groups must be completed with their hosts
* @param bool $withServices Indicates whether hosts must be completed with their services
* @throws \Exception
* @return ServiceGroup[]
*/
public function findServiceGroups(bool $withHosts = false, bool $withServices = false): array;
/**
* Find all services.
*
* @throws \Exception
* @return Service[]
*/
public function findServices(): array;
/**
* Find all services belonging to the host.
*
* @param int $hostId
* @throws \Exception
* @return Service[]
*/
public function findServicesByHost(int $hostId): array;
/**
* Indicates whether a host exists.
*
* @param int $hostId Host id to find
* @throws \Exception
* @return bool
*/
public function isHostExists(int $hostId): bool;
/**
* Indicates whether a service exists.
*
* @param int $hostId Host id to find
* @param int $serviceId Service id to find
* @throws \Exception
* @return bool
*/
public function isServiceExists(int $hostId, int $serviceId): bool;
/**
* Find all service groups by host and service ids.
*
* @param int $hostId
* @param int $serviceId
* @return ServiceGroup[]
*/
public function findServiceGroupsByHostAndService(int $hostId, int $serviceId): array;
/**
* Try to hide all macro password values of the host command line.
*
* @param Host $monitoringHost Monitoring host
* @param string $replacementValue Replacement value used instead of macro password value
* @throws \Exception
*/
public function hidePasswordInHostCommandLine(Host $monitoringHost, string $replacementValue = '***'): void;
/**
* Try to hide all macro password values of the service command line.
*
* @param Service $monitoringService Monitoring service
* @param string $replacementValue Replacement value used instead of macro password value
* @throws \Exception
*/
public function hidePasswordInServiceCommandLine(
Service $monitoringService,
string $replacementValue = '***',
): void;
/**
* Find the command line of a service.
*
* If a password exists, it will be hidden.
*
* @param int $hostId Host id associated to the service
* @param int $serviceId Service id
* @throws MonitoringServiceException
* @return string|null Return the command line if it exists
*/
public function findCommandLineOfService(int $hostId, int $serviceId): ?string;
}
| 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/Interfaces/EventObjectInterface.php | centreon/src/Centreon/Domain/Monitoring/Interfaces/EventObjectInterface.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\Interfaces;
interface EventObjectInterface
{
/**
* Make sure every implementation has a timestamp
* @return \DateTime|null
*/
public function getTimestamp(): ?\DateTime;
/**
* Make sure every implementation has a type
* @return string
*/
public function getEventType(): string;
/**
* Make sure every implementation has id
* @return string
*/
public function getEventId(): string;
}
| 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/Interfaces/ResourceServiceInterface.php | centreon/src/Centreon/Domain/Monitoring/Interfaces/ResourceServiceInterface.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\Interfaces;
interface ResourceServiceInterface
{
/**
* 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 ResourceServiceInterface
*/
public function filterByContact($contact);
}
| 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/Interfaces/MonitoringRepositoryInterface.php | centreon/src/Centreon/Domain/Monitoring/Interfaces/MonitoringRepositoryInterface.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\Interfaces;
use Centreon\Domain\Acknowledgement\Acknowledgement;
use Centreon\Domain\Contact\Interfaces\ContactInterface;
use Centreon\Domain\Downtime\Downtime;
use Centreon\Domain\Monitoring\Host;
use Centreon\Domain\Monitoring\HostGroup;
use Centreon\Domain\Monitoring\Service;
use Centreon\Domain\Monitoring\ServiceGroup;
use Core\Security\AccessGroup\Domain\Model\AccessGroup;
interface MonitoringRepositoryInterface
{
/**
* Sets the access groups that will be used to filter services and the host.
*
* @param AccessGroup[]|null $accessGroups
* @return self
*/
public function filterByAccessGroups(?array $accessGroups): self;
/**
* Find all real time hosts according to access group.
*
* @throws \Exception
* @return Host[]
*/
public function findHosts(): array;
/**
* Find the hosts of the hosts groups ids given.
*
* @param int[] $hostsGroupsIds List of hosts groups Ids for which we want to retrieve the hosts
* @throws \Exception
* @return array<int, array<int, Host>> [hostGroupId => hostId,...]
*/
public function findHostsByHostsGroups(array $hostsGroupsIds): array;
/**
* Find the hosts of the services groups ids given.
*
* @param int[] $servicesGroupsIds List of services groups Ids for which we want to retrieve the hosts
* @throws \Exception
* @return array<int, array<int, Host>> [serviceGroupId => hostId,...]
*/
public function findHostsByServiceGroups(array $servicesGroupsIds): array;
/**
* Find all hostgroups with option to provide host id
*
* @param int $hostId Id of host to filter hostgroups by
* @return HostGroup[]
*/
public function findHostGroups(?int $hostId): array;
/**
* Find one host based on its id and according to ACL.
*
* @param int $hostId Id of the host to be found
* @throws \Exception
* @return Host|null
*/
public function findOneHost(int $hostId): ?Host;
/**
* Find all hosts from an array of hostIds for a non admin user
*
* @param int[] $hostIds
* @return Host[]
*/
public function findHostsByIdsForNonAdminUser(array $hostIds): array;
/**
* Find all hosts from an array of hostIds for an admin user
*
* @param int[] $hostIds
* @return Host[]
*/
public function findHostsByIdsForAdminUser(array $hostIds): array;
/**
* Find one service based on its id and according to ACL.
*
* @param int $hostId Host id of the service
* @param int $serviceId Service Id
* @throws \Exception
* @return Service|null
*/
public function findOneService(int $hostId, int $serviceId): ?Service;
/**
* Find one service based on its id and according to ACL.
*
* @param string $serviceDescription
* @throws \Exception
* @return Service|null
*/
public function findOneServiceByDescription(string $serviceDescription): ?Service;
/**
* Find all services from an array of serviceIds for a non admin user
*
* @param array<int, array<string, int>> $serviceIds
* @return Service[]
*/
public function findServicesByIdsForNonAdminUser(array $serviceIds): array;
/**
* Find all services from an array of serviceIds for an admin user
*
* @param array<int, array<string, int>> $serviceIds
* @return Service[]
*/
public function findServicesByIdsForAdminUser(array $serviceIds): array;
/**
* Find all services grouped by service groups
*
* @throws \Exception
* @return ServiceGroup[]
*/
public function findServiceGroups(): array;
/**
* Find all real time services according to access group.
*
* @throws \Exception
* @return Service[]
*/
public function findServices(): array;
/**
* Retrieve all real time services according to ACL of contact and host id
* using request parameters (search, sort, pagination)
*
* @param int $hostId Host ID for which we want to find services
* @throws \Exception
* @return Service[]
*/
public function findServicesByHostWithRequestParameters(int $hostId): array;
/**
* Retrieve all real time services according to ACL of contact and host id
* without request parameters (no search, no sort, no pagination)
*
* @param int $hostId Host ID for which we want to find services
* @throws \Exception
* @return Service[]
*/
public function findServicesByHostWithoutRequestParameters(int $hostId): array;
/**
* Find services according to the host id and service ids given
*
* @param int $hostId Host id
* @param int[] $serviceIds Service Ids
* @throws \Exception
* @return Service[]
*/
public function findSelectedServicesByHost(int $hostId, array $serviceIds): array;
/**
* Finds services from a list of hosts.
*
* @param int[] $hostIds List of host for which we want to get services
* @return array<int, array<int, Service>> Return a list of services indexed by host
*/
public function findServicesByHosts(array $hostIds): array;
/**
* @param ContactInterface $contact
* @return MonitoringRepositoryInterface
*/
public function setContact(ContactInterface $contact): self;
/**
* @param int[] $serviceGroupIds
* @throws \Exception
* @return array<int, array<int, Service>>
*/
public function findServicesByServiceGroups(array $serviceGroupIds): array;
/**
* @param int $hostId
* @param int $serviceId
* @return ServiceGroup[]
*/
public function findServiceGroupsByHostAndService(int $hostId, int $serviceId): array;
/**
* Find downtimes for host or service
* @param int $hostId
* @param int $serviceId
* @return Downtime[]
*/
public function findDowntimes(int $hostId, int $serviceId): array;
/**
* Find acknowledgements for host or service
* @param int $hostId
* @param int $serviceId
* @return Acknowledgement[]
*/
public function findAcknowledgements(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/Monitoring/SubmitResult/SubmitResultService.php | centreon/src/Centreon/Domain/Monitoring/SubmitResult/SubmitResultService.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\SubmitResult;
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\SubmitResult\Interfaces\SubmitResultServiceInterface;
use Centreon\Domain\Service\AbstractCentreonService;
use Core\Security\AccessGroup\Application\Repository\ReadAccessGroupRepositoryInterface;
use JMS\Serializer\Exception\ValidationFailedException;
/**
* Monitoring class used to manage result submitting to services, hosts and resources
*
* @package Centreon\Domain\Monitoring\SubmitResult
*/
class SubmitResultService extends AbstractCentreonService implements SubmitResultServiceInterface
{
public const VALIDATION_GROUPS_HOST_SUBMIT_RESULT = ['submit_result_host'];
public const VALIDATION_GROUPS_SERVICE_SUBMIT_RESULT = ['submit_result_service'];
/** @var EngineServiceInterface used to send external commands to engine */
private $engineService;
/** @var EntityValidator */
private $validator;
/** @var MonitoringRepositoryInterface */
private $monitoringRepository;
/** @var ReadAccessGroupRepositoryInterface */
private $accessGroupRepository;
/**
* SubmitResultService 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 SubmitResultServiceInterface
*/
public function filterByContact($contact): SubmitResultServiceInterface
{
parent::filterByContact($contact);
$this->engineService->filterByContact($contact);
$accessGroups = $this->accessGroupRepository->findByContact($contact);
$this->monitoringRepository
->setContact($contact)
->filterByAccessGroups($accessGroups);
return $this;
}
/**
* @inheritDoc
*/
public function submitServiceResult(SubmitResult $result): void
{
// We validate the check instance
$errors = $this->validator->validate(
$result,
null,
self::VALIDATION_GROUPS_SERVICE_SUBMIT_RESULT
);
if ($errors->count() > 0) {
throw new ValidationFailedException($errors);
}
$host = $this->monitoringRepository->findOneHost($result->getParentResourceId());
if (is_null($host)) {
throw new EntityNotFoundException(
sprintf(
_('Host %d not found'),
$result->getParentResourceId()
)
);
}
$service = $this->monitoringRepository->findOneService(
$result->getParentResourceId(),
$result->getResourceId()
);
if (is_null($service)) {
throw new EntityNotFoundException(
sprintf(
_('Service %d not found'),
$result->getResourceId()
)
);
}
$service->setHost($host);
$this->engineService->submitServiceResult($result, $service);
}
/**
* @inheritDoc
*/
public function submitMetaServiceResult(SubmitResult $result): void
{
// We validate the check instance
$errors = $this->validator->validate(
$result,
null,
self::VALIDATION_GROUPS_SERVICE_SUBMIT_RESULT
);
if ($errors->count() > 0) {
throw new ValidationFailedException($errors);
}
$service = $this->monitoringRepository->findOneServiceByDescription('meta_' . $result->getResourceId());
if (is_null($service)) {
throw new EntityNotFoundException(
sprintf(
_('Meta Service %d not found'),
$result->getResourceId()
)
);
}
$host = $this->monitoringRepository->findOneHost($service->getHost()->getId());
if (is_null($host)) {
throw new EntityNotFoundException(
sprintf(
_('Meta Host %d not found'),
$service->getHost()->getId()
)
);
}
$service->setHost($host);
$this->engineService->submitServiceResult($result, $service);
}
/**
* @inheritDoc
*/
public function submitHostResult(SubmitResult $result): void
{
// We validate the SubmitResult instance instance
$errors = $this->validator->validate(
$result,
null,
self::VALIDATION_GROUPS_HOST_SUBMIT_RESULT
);
if ($errors->count() > 0) {
throw new ValidationFailedException($errors);
}
$host = $this->monitoringRepository->findOneHost($result->getResourceId());
if (is_null($host)) {
throw new EntityNotFoundException(
sprintf(
_('Host %d not found'),
$result->getResourceId()
)
);
}
$this->engineService->submitHostResult($result, $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/Monitoring/SubmitResult/SubmitResultException.php | centreon/src/Centreon/Domain/Monitoring/SubmitResult/SubmitResultException.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\SubmitResult;
class SubmitResultException 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/Monitoring/SubmitResult/SubmitResult.php | centreon/src/Centreon/Domain/Monitoring/SubmitResult/SubmitResult.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\SubmitResult;
class SubmitResult
{
public const STATUS_OK = 0;
public const STATUS_UP = 0;
public const STATUS_WARNING = 1;
public const STATUS_CRITICAL = 2;
public const STATUS_UNKNOWN = 3;
public const STATUS_DOWN = 1;
public const STATUS_UNREACHABLE = 2;
/** @var int Resource ID */
public $resourceId;
/** @var int submitted status */
public $status;
/** @var int|null Parent Resource ID */
private $parentResourceId;
/** @var string|null submitted output */
private $output;
/** @var string|null submitted performance data */
private $performanceData;
public function __construct(int $resourceId, int $status)
{
$this->resourceId = $resourceId;
$this->setStatus($status);
}
/**
* @return int
*/
public function getResourceId(): int
{
return $this->resourceId;
}
/**
* @param int $resourceId
* @return SubmitResult
*/
public function setResourceId(int $resourceId): SubmitResult
{
$this->resourceId = $resourceId;
return $this;
}
/**
* @return int
*/
public function getParentResourceId(): ?int
{
return $this->parentResourceId;
}
/**
* @param int|null $parentResourceId
* @return SubmitResult
*/
public function setParentResourceId(?int $parentResourceId): SubmitResult
{
$this->parentResourceId = $parentResourceId;
return $this;
}
/**
* Get submitted status
*
* @return int
*/
public function getStatus(): int
{
return $this->status;
}
/**
* Set submitted status
*
* @param int $status submitted status
* @return SubmitResult
*/
public function setStatus(int $status): SubmitResult
{
$allowedStatuses = [
self::STATUS_OK,
self::STATUS_WARNING,
self::STATUS_CRITICAL,
self::STATUS_UNKNOWN,
self::STATUS_UP,
self::STATUS_DOWN,
self::STATUS_UNREACHABLE,
];
if (! in_array($status, $allowedStatuses)) {
throw new \InvalidArgumentException(
sprintf(
_('Status provided %d is invalid'),
$status
)
);
}
$this->status = $status;
return $this;
}
/**
* Get submitted perfData
*
* @return string|null
*/
public function getPerformanceData(): ?string
{
return $this->performanceData;
}
/**
* Set submitted performance data
*
* @param string|null $performanceData submitted performance data
* @return SubmitResult
*/
public function setPerformanceData(?string $performanceData): SubmitResult
{
$this->performanceData = $performanceData;
return $this;
}
/**
* Get submitted output
*
* @return string|null
*/
public function getOutput(): ?string
{
return $this->output;
}
/**
* Set submitted output
*
* @param string|null $output submitted output
* @return SubmitResult
*/
public function setOutput(?string $output): SubmitResult
{
$this->output = $output;
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/SubmitResult/Interfaces/SubmitResultServiceInterface.php | centreon/src/Centreon/Domain/Monitoring/SubmitResult/Interfaces/SubmitResultServiceInterface.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\SubmitResult\Interfaces;
use Centreon\Domain\Contact\Interfaces\ContactFilterInterface;
use Centreon\Domain\Monitoring\Host;
use Centreon\Domain\Monitoring\Service;
use Centreon\Domain\Monitoring\SubmitResult\SubmitResult;
interface SubmitResultServiceInterface extends ContactFilterInterface
{
/**
* Function allowing user to submit a result to a service
*
* @param SubmitResult $result
* @return void
*/
public function submitServiceResult(SubmitResult $result): void;
/**
* Function allowing user to submit a result to a meta service
*
* @param SubmitResult $result
* @return void
*/
public function submitMetaServiceResult(SubmitResult $result): void;
/**
* Function allowing user to submit a result to a host
*
* @param SubmitResult $result
* @return void
*/
public function submitHostResult(SubmitResult $result): 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/Monitoring/Timeline/TimelineService.php | centreon/src/Centreon/Domain/Monitoring/Timeline/TimelineService.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\Timeline;
use Centreon\Domain\Monitoring\Host;
use Centreon\Domain\Monitoring\Service;
use Centreon\Domain\Monitoring\Timeline\Interfaces\TimelineRepositoryInterface;
use Centreon\Domain\Monitoring\Timeline\Interfaces\TimelineServiceInterface;
use Centreon\Domain\Service\AbstractCentreonService;
use Core\Security\AccessGroup\Application\Repository\ReadAccessGroupRepositoryInterface;
/**
* Monitoring class used to manage the real time services and hosts
*
* @package Centreon\Domain\Monitoring\Timeline
*/
class TimelineService extends AbstractCentreonService implements TimelineServiceInterface
{
/** @var TimelineRepositoryInterface */
private $timelineRepository;
/** @var ReadAccessGroupRepositoryInterface */
private $accessGroupRepository;
/**
* @param TimelineRepositoryInterface $timelineRepository
* @param ReadAccessGroupRepositoryInterface $accessGroupRepository
*/
public function __construct(
TimelineRepositoryInterface $timelineRepository,
ReadAccessGroupRepositoryInterface $accessGroupRepository,
) {
$this->timelineRepository = $timelineRepository;
$this->accessGroupRepository = $accessGroupRepository;
}
/**
* @inheritDoc
*/
public function filterByContact($contact)
{
parent::filterByContact($contact);
$this->timelineRepository
->setContact($this->contact)
->filterByAccessGroups($this->accessGroupRepository->findByContact($contact));
return $this;
}
/**
* @inheritDoc
*/
public function findTimelineEventsByHost(Host $host): array
{
return $this->timelineRepository->findTimelineEventsByHost($host);
}
/**
* @inheritDoc
*/
public function findTimelineEventsByService(Service $service): array
{
return $this->timelineRepository->findTimelineEventsByService($service);
}
}
| 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/Timeline/TimelineContact.php | centreon/src/Centreon/Domain/Monitoring/Timeline/TimelineContact.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\Timeline;
class TimelineContact
{
/** @var int|null Id of contact */
private $id;
/** @var string Name of contact */
private $name;
/**
* @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
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
* @return self
*/
public function setName(string $name): self
{
$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/Timeline/TimelineEvent.php | centreon/src/Centreon/Domain/Monitoring/Timeline/TimelineEvent.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\Timeline;
use Centreon\Domain\Monitoring\ResourceStatus;
use DateTime;
/**
* Class TimelineEvent
* @package Centreon\Domain\Monitoring\Timeline
*/
class TimelineEvent
{
/** @var int|null */
private $id;
/** @var string|null */
private $type;
/** @var DateTime|null */
private $date;
/** @var DateTime|null */
private $startDate;
/** @var DateTime|null */
private $endDate;
/** @var string|null */
private $content;
/** @var TimelineContact|null */
private $contact;
/** @var ResourceStatus|null */
private $status;
/** @var int|null */
private $tries;
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @param int|null $id
* @return TimelineEvent
*/
public function setId(?int $id): TimelineEvent
{
$this->id = $id;
return $this;
}
/**
* @return string|null
*/
public function getType(): ?string
{
return $this->type;
}
/**
* @param string|null $type
* @return TimelineEvent
*/
public function setType(?string $type): TimelineEvent
{
$this->type = $type;
return $this;
}
/**
* @return DateTime|null
*/
public function getDate(): ?DateTime
{
return $this->date;
}
/**
* @param DateTime|null $date
* @return TimelineEvent
*/
public function setDate(?DateTime $date): TimelineEvent
{
$this->date = $date;
return $this;
}
/**
* @return DateTime|null
*/
public function getStartDate(): ?DateTime
{
return $this->startDate;
}
/**
* @param DateTime|null $startDate
* @return TimelineEvent
*/
public function setStartDate(?DateTime $startDate): TimelineEvent
{
$this->startDate = $startDate;
return $this;
}
/**
* @return DateTime|null
*/
public function getEndDate(): ?DateTime
{
return $this->endDate;
}
/**
* @param DateTime|null $endDate
* @return TimelineEvent
*/
public function setEndDate(?DateTime $endDate): TimelineEvent
{
$this->endDate = $endDate;
return $this;
}
/**
* @return string|null
*/
public function getContent(): ?string
{
return $this->content;
}
/**
* @param string|null $content
* @return TimelineEvent
*/
public function setContent(?string $content): TimelineEvent
{
$this->content = $content;
return $this;
}
/**
* @return TimelineContact|null
*/
public function getContact(): ?TimelineContact
{
return $this->contact;
}
/**
* @param TimelineContact|null $contact
* @return TimelineEvent
*/
public function setContact(?TimelineContact $contact): TimelineEvent
{
$this->contact = $contact;
return $this;
}
/**
* @return ResourceStatus|null
*/
public function getStatus(): ?ResourceStatus
{
return $this->status;
}
/**
* @param ResourceStatus|null $status
* @return TimelineEvent
*/
public function setStatus(?ResourceStatus $status): TimelineEvent
{
$this->status = $status;
return $this;
}
/**
* @return int|null
*/
public function getTries(): ?int
{
return $this->tries;
}
/**
* @param int|null $tries
* @return TimelineEvent
*/
public function setTries(?int $tries): TimelineEvent
{
$this->tries = $tries;
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/Timeline/Interfaces/TimelineServiceInterface.php | centreon/src/Centreon/Domain/Monitoring/Timeline/Interfaces/TimelineServiceInterface.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\Timeline\Interfaces;
use Centreon\Domain\Contact\Interfaces\ContactFilterInterface;
use Centreon\Domain\Monitoring\Host;
use Centreon\Domain\Monitoring\Service;
use Centreon\Domain\Monitoring\Timeline\TimelineEvent;
interface TimelineServiceInterface extends ContactFilterInterface
{
/**
* Find all timeline events for given host
*
* @param Host $host
* @return TimelineEvent[]
*/
public function findTimelineEventsByHost(Host $host): array;
/**
* Find all timeline events for given service
*
* @param Service $service
* @return TimelineEvent[]
*/
public function findTimelineEventsByService(Service $service): 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/Monitoring/Timeline/Interfaces/TimelineRepositoryInterface.php | centreon/src/Centreon/Domain/Monitoring/Timeline/Interfaces/TimelineRepositoryInterface.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\Timeline\Interfaces;
use Centreon\Domain\Contact\Interfaces\ContactInterface;
use Centreon\Domain\Monitoring\Host;
use Centreon\Domain\Monitoring\Service;
use Centreon\Domain\Monitoring\Timeline\TimelineEvent;
use Core\Security\AccessGroup\Domain\Model\AccessGroup;
interface TimelineRepositoryInterface
{
/**
* Sets the access groups that will be used to filter services and the host.
*
* @param AccessGroup[]|null $accessGroups
* @return self
*/
public function filterByAccessGroups(?array $accessGroups): TimelineRepositoryInterface;
/**
* @param ContactInterface $contact
* @return self
*/
public function setContact(ContactInterface $contact): TimelineRepositoryInterface;
/**
* Find timeline events for given host
*
* @param Host $host
* @return TimelineEvent[]
*/
public function findTimelineEventsByHost(Host $host): array;
/**
* Find timeline events for given service
*
* @param Service $service
* @return TimelineEvent[]
*/
public function findTimelineEventsByService(Service $service): 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/Monitoring/Metric/MetricService.php | centreon/src/Centreon/Domain/Monitoring/Metric/MetricService.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\Metric;
use Centreon\Domain\Contact\Contact;
use Centreon\Domain\Monitoring\Interfaces\MonitoringRepositoryInterface;
use Centreon\Domain\Monitoring\Metric\Interfaces\MetricRepositoryInterface;
use Centreon\Domain\Monitoring\Metric\Interfaces\MetricServiceInterface;
use Centreon\Domain\Monitoring\Service;
use Centreon\Domain\Service\AbstractCentreonService;
use Core\Security\AccessGroup\Application\Repository\ReadAccessGroupRepositoryInterface;
/**
* Monitoring class used to manage the real time services and hosts
*
* @package Centreon\Domain\Monitoring
*/
class MetricService extends AbstractCentreonService implements MetricServiceInterface
{
/** @var MonitoringRepositoryInterface */
private $monitoringRepository;
/** @var MetricRepositoryInterface */
private $metricRepository;
/** @var ReadAccessGroupRepositoryInterface */
private $accessGroupRepository;
/**
* @param MonitoringRepositoryInterface $monitoringRepository
* @param MetricRepositoryInterface $metricRepository
* @param ReadAccessGroupRepositoryInterface $accessGroupRepository
*/
public function __construct(
MonitoringRepositoryInterface $monitoringRepository,
MetricRepositoryInterface $metricRepository,
ReadAccessGroupRepositoryInterface $accessGroupRepository,
) {
$this->monitoringRepository = $monitoringRepository;
$this->metricRepository = $metricRepository;
$this->accessGroupRepository = $accessGroupRepository;
}
/**
* {@inheritDoc}
* @param Contact $contact
* @return self
*/
public function filterByContact($contact): self
{
parent::filterByContact($contact);
$accessGroups = $this->accessGroupRepository->findByContact($contact);
$this->monitoringRepository
->setContact($this->contact)
->filterByAccessGroups($accessGroups);
$this->metricRepository->setContact($this->contact);
return $this;
}
/**
* @inheritDoc
*/
public function findMetricsByService(Service $service, \DateTime $start, \DateTime $end): array
{
return $this->metricRepository->findMetricsByService($service, $start, $end);
}
/**
* @inheritDoc
*/
public function findStatusByService(Service $service, \DateTime $start, \DateTime $end): array
{
return $this->metricRepository->findStatusByService($service, $start, $end);
}
}
| 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/Metric/Interfaces/MetricRepositoryInterface.php | centreon/src/Centreon/Domain/Monitoring/Metric/Interfaces/MetricRepositoryInterface.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\Metric\Interfaces;
use Centreon\Domain\Contact\Interfaces\ContactInterface;
use Centreon\Domain\Monitoring\Service;
interface MetricRepositoryInterface
{
/**
* Find metrics data linked to a service.
*
* @param Service $service
* @param \DateTimeInterface $start start date
* @param \DateTimeInterface $end end date
* @throws \Exception
* @return array
*/
public function findMetricsByService(Service $service, \DateTimeInterface $start, \DateTimeInterface $end): array;
/**
* Find status data linked to a service.
*
* @param Service $service
* @param \DateTimeInterface $start start date
* @param \DateTimeInterface $end end date
* @throws \Exception
* @return array
*/
public function findStatusByService(Service $service, \DateTimeInterface $start, \DateTimeInterface $end): array;
/**
* @param ContactInterface $contact
* @return self
*/
public function setContact(ContactInterface $contact): self;
}
| 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/Metric/Interfaces/MetricServiceInterface.php | centreon/src/Centreon/Domain/Monitoring/Metric/Interfaces/MetricServiceInterface.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\Metric\Interfaces;
use Centreon\Domain\Contact\Interfaces\ContactFilterInterface;
use Centreon\Domain\Monitoring\Service;
interface MetricServiceInterface extends ContactFilterInterface
{
/**
* Find metrics data linked to a service.
*
* @param Service $service
* @param \DateTime $start start date
* @param \DateTime $end end date
* @throws \Exception
* @return array
*/
public function findMetricsByService(Service $service, \DateTime $start, \DateTime $end): array;
/**
* Find status data linked to a service.
*
* @param Service $service
* @param \DateTime $start start date
* @param \DateTime $end end date
* @throws \Exception
* @return array
*/
public function findStatusByService(Service $service, \DateTime $start, \DateTime $end): 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/Monitoring/ServiceGroup/ServiceGroupException.php | centreon/src/Centreon/Domain/Monitoring/ServiceGroup/ServiceGroupException.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\ServiceGroup;
class ServiceGroupException 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/Monitoring/ServiceGroup/ServiceGroupService.php | centreon/src/Centreon/Domain/Monitoring/ServiceGroup/ServiceGroupService.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\ServiceGroup;
use Centreon\Domain\Monitoring\ServiceGroup\Interfaces\ServiceGroupRepositoryInterface;
use Centreon\Domain\Monitoring\ServiceGroup\Interfaces\ServiceGroupServiceInterface;
use Centreon\Domain\Service\AbstractCentreonService;
use Core\Security\AccessGroup\Application\Repository\ReadAccessGroupRepositoryInterface;
final class ServiceGroupService extends AbstractCentreonService implements ServiceGroupServiceInterface
{
/** @var ServiceGroupRepositoryInterface */
private $serviceGroupRepository;
/** @var ReadAccessGroupRepositoryInterface */
private $accessGroupRepository;
/**
* @param ServiceGroupRepositoryInterface $serviceGroupRepository
* @param ReadAccessGroupRepositoryInterface $accessGroupRepository
*/
public function __construct(
ServiceGroupRepositoryInterface $serviceGroupRepository,
ReadAccessGroupRepositoryInterface $accessGroupRepository,
) {
$this->serviceGroupRepository = $serviceGroupRepository;
$this->accessGroupRepository = $accessGroupRepository;
}
/**
* @inheritDoc
*/
public function filterByContact($contact): ServiceGroupServiceInterface
{
parent::filterByContact($contact);
$this->serviceGroupRepository
->setContact($this->contact)
->filterByAccessGroups($this->accessGroupRepository->findByContact($this->contact));
return $this;
}
/**
* @inheritDoc
*/
public function findServiceGroupsByIds(array $serviceGroupIds): array
{
try {
return $this->serviceGroupRepository->findServiceGroupsByIds($serviceGroupIds);
} catch (\Throwable $e) {
throw new ServiceGroupException(_('Error when searching servicegroups'), 0, $e);
}
}
/**
* @inheritDoc
*/
public function findServiceGroupsByNames(array $serviceGroupNames): array
{
try {
return $this->serviceGroupRepository->findServiceGroupsByNames($serviceGroupNames);
} catch (\Throwable $e) {
throw new ServiceGroupException(_('Error when searching servicegroups'), 0, $e);
}
}
}
| 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/Interfaces/ServiceGroupRepositoryInterface.php | centreon/src/Centreon/Domain/Monitoring/ServiceGroup/Interfaces/ServiceGroupRepositoryInterface.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\ServiceGroup\Interfaces;
use Centreon\Domain\Contact\Interfaces\ContactInterface;
use Centreon\Domain\Monitoring\ServiceGroup;
interface ServiceGroupRepositoryInterface
{
/**
* Retrieve servicegroups from their ids
*
* @param int[] $serviceGroupIds
* @return ServiceGroup[]
*/
public function findServiceGroupsByIds(array $serviceGroupIds): array;
/**
* Retrieve servicegroups from their names
*
* @param string[] $serviceGroupNames
* @return ServiceGroup[]
*/
public function findServiceGroupsByNames(array $serviceGroupNames): array;
/**
* @param ContactInterface $contact
* @return ServiceGroupRepositoryInterface
*/
public function setContact(ContactInterface $contact): ServiceGroupRepositoryInterface;
/**
* Sets the access groups that will be used to filter.
*
* @param \Core\Security\AccessGroup\Domain\Model\AccessGroup[]|null $accessGroups
* @return ServiceGroupRepositoryInterface
*/
public function filterByAccessGroups(?array $accessGroups): ServiceGroupRepositoryInterface;
}
| 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/Interfaces/ServiceGroupServiceInterface.php | centreon/src/Centreon/Domain/Monitoring/ServiceGroup/Interfaces/ServiceGroupServiceInterface.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\ServiceGroup\Interfaces;
use Centreon\Domain\Monitoring\ServiceGroup;
use Centreon\Domain\Monitoring\ServiceGroup\ServiceGroupException;
interface ServiceGroupServiceInterface
{
/**
* 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 ServiceGroupServiceInterface
*/
public function filterByContact($contact): ServiceGroupServiceInterface;
/**
* Retrieve servicegroups from their ids
*
* @param int[] $serviceGroupIds
* @throws ServiceGroupException
* @return ServiceGroup[]
*/
public function findServiceGroupsByIds(array $serviceGroupIds): array;
/**
* Retrieve servicegroups from their ids
*
* @param string[] $serviceGroupNames
* @throws ServiceGroupException
* @return ServiceGroup[]
*/
public function findServiceGroupsByNames(array $serviceGroupNames): 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/Monitoring/Comment/CommentException.php | centreon/src/Centreon/Domain/Monitoring/Comment/CommentException.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\Comment;
class CommentException 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/Monitoring/Comment/CommentService.php | centreon/src/Centreon/Domain/Monitoring/Comment/CommentService.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\Comment;
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\Comment\Interfaces\CommentServiceInterface;
use Centreon\Domain\Monitoring\Host;
use Centreon\Domain\Monitoring\Interfaces\MonitoringRepositoryInterface;
use Centreon\Domain\Monitoring\Interfaces\MonitoringServiceInterface;
use Centreon\Domain\Monitoring\Service;
use Centreon\Domain\Service\AbstractCentreonService;
use Core\Security\AccessGroup\Application\Repository\ReadAccessGroupRepositoryInterface;
use JMS\Serializer\Exception\ValidationFailedException;
/**
* Monitoring class used to manage result submitting to services, hosts and resources
*
* @package Centreon\Domain\Monitoring\SubmitResult
*/
class CommentService extends AbstractCentreonService implements CommentServiceInterface
{
public const VALIDATION_GROUPS_HOST_ADD_COMMENT = ['add_host_comment'];
public const VALIDATION_GROUPS_SERVICE_ADD_COMMENT = ['add_service_comment'];
/** @var EngineServiceInterface used to send external commands to engine */
private $engineService;
/** @var EntityValidator */
private $validator;
/** @var MonitoringRepositoryInterface */
private $monitoringRepository;
/** @var ReadAccessGroupRepositoryInterface */
private $accessGroupRepository;
/** @var MonitoringServiceInterface */
private $monitoringService;
/**
* CommentService constructor.
*
* @param ReadAccessGroupRepositoryInterface $accessGroupRepository
* @param MonitoringRepositoryInterface $monitoringRepository
* @param EngineServiceInterface $engineService
* @param MonitoringServiceInterface $monitoringService
* @param EntityValidator $validator
*/
public function __construct(
ReadAccessGroupRepositoryInterface $accessGroupRepository,
MonitoringRepositoryInterface $monitoringRepository,
EngineServiceInterface $engineService,
MonitoringServiceInterface $monitoringService,
EntityValidator $validator,
) {
$this->accessGroupRepository = $accessGroupRepository;
$this->monitoringRepository = $monitoringRepository;
$this->engineService = $engineService;
$this->monitoringService = $monitoringService;
$this->validator = $validator;
}
/**
* {@inheritDoc}
* @param Contact $contact
* @return CommentServiceInterface
*/
public function filterByContact($contact): CommentServiceInterface
{
parent::filterByContact($contact);
$this->engineService->filterByContact($contact);
$accessGroups = $this->accessGroupRepository->findByContact($contact);
$this->monitoringRepository
->setContact($contact)
->filterByAccessGroups($accessGroups);
return $this;
}
/**
* @inheritDoc
*/
public function addServiceComment(Comment $comment, Service $service): void
{
// We validate the comment entity sent
$errors = $this->validator->validate(
$comment,
null,
self::VALIDATION_GROUPS_SERVICE_ADD_COMMENT
);
if ($errors->count() > 0) {
throw new ValidationFailedException($errors);
}
$hostComment = $this->monitoringService
->filterByContact($this->contact)
->findOneHost($service->getHost()->getId());
if (is_null($hostComment)) {
throw new EntityNotFoundException(
sprintf(
_('Host %d not found'),
$service->getHost()->getId()
)
);
}
$serviceComment = $this->monitoringService
->filterByContact($this->contact)
->findOneService($hostComment->getId(), $service->getId());
if (is_null($serviceComment)) {
throw new EntityNotFoundException(
sprintf(
_('Service %d not found'),
$service->getId()
)
);
}
$serviceComment->setHost($hostComment);
$this->engineService->addServiceComment($comment, $serviceComment);
}
/**
* @inheritDoc
*/
public function addMetaServiceComment(Comment $comment, Service $metaService): void
{
// We validate the comment entity sent
$errors = $this->validator->validate(
$comment,
null,
self::VALIDATION_GROUPS_SERVICE_ADD_COMMENT
);
if ($errors->count() > 0) {
throw new ValidationFailedException($errors);
}
$hostComment = $this->monitoringService
->filterByContact($this->contact)
->findOneHost($metaService->getHost()->getId());
if (is_null($hostComment)) {
throw new EntityNotFoundException(
sprintf(
_('Meta host %d not found'),
$metaService->getHost()->getId()
)
);
}
$metaService->setHost($hostComment);
$this->engineService->addServiceComment($comment, $metaService);
}
/**
* @inheritDoc
*/
public function addHostComment(Comment $comment, Host $host): void
{
// We validate the comment entity sent
$errors = $this->validator->validate(
$comment,
null,
self::VALIDATION_GROUPS_HOST_ADD_COMMENT
);
if ($errors->count() > 0) {
throw new ValidationFailedException($errors);
}
$hostComment = $this->monitoringService
->filterByContact($this->contact)
->findOneHost($host->getId());
if (is_null($hostComment)) {
throw new EntityNotFoundException(
sprintf(
_('Host %d not found'),
$host->getId()
)
);
}
$this->engineService->addHostComment($comment, $hostComment);
}
/**
* @inheritDoc
*/
public function addResourcesComment(array $comments, array $resourceIds): void
{
/**
* @var Host[] $hosts
*/
$hosts = [];
/**
* @var Service[] $services
*/
$services = [];
/**
* @var Service[] $metaServices
*/
$metaServices = [];
/**
* Retrieving at this point all the host and services entities linked to
* the resource ids provided
*/
if ($this->contact->isAdmin()) {
if (! empty($resourceIds['host'])) {
try {
$hosts = $this->monitoringRepository->findHostsByIdsForAdminUser($resourceIds['host']);
} catch (\Throwable $ex) {
throw new CommentException(_('Error when searching for hosts'), 0, $ex);
}
}
if (! empty($resourceIds['service'])) {
try {
$services = $this->monitoringRepository->findServicesByIdsForAdminUser($resourceIds['service']);
} catch (\Throwable $ex) {
throw new CommentException(_('Error when searching for services'), 0, $ex);
}
}
if (! empty($resourceIds['metaservice'])) {
try {
foreach ($resourceIds['metaservice'] as $resourceId) {
$metaServices[$resourceId['service_id']] = $this->monitoringRepository
->findOneServiceByDescription('meta_' . $resourceId['service_id']);
}
} catch (\Throwable $ex) {
throw new CommentException(_('Error when searching for services'), 0, $ex);
}
}
} else {
$accessGroups = $this->accessGroupRepository->findByContact($this->contact);
if (! empty($resourceIds['host'])) {
try {
$hosts = $this->monitoringRepository
->filterByAccessGroups($accessGroups)
->findHostsByIdsForNonAdminUser($resourceIds['host']);
} catch (\Throwable $ex) {
throw new CommentException(_('Error when searching for hosts'), 0, $ex);
}
}
if (! empty($resourceIds['service'])) {
try {
$services = $this->monitoringRepository
->filterByAccessGroups($accessGroups)
->findServicesByIdsForNonAdminUser($resourceIds['service']);
} catch (\Throwable $ex) {
throw new CommentException(_('Error when searching for services'), 0, $ex);
}
}
if (! empty($resourceIds['metaservice'])) {
try {
foreach ($resourceIds['metaservice'] as $resourceId) {
$metaServices[$resourceId['service_id']] = $this->monitoringRepository
->filterByAccessGroups($accessGroups)
->findOneServiceByDescription('meta_' . $resourceId['service_id']);
}
} catch (\Throwable $ex) {
throw new CommentException(_('Error when searching for meta services'), 0, $ex);
}
}
}
foreach ($hosts as $host) {
$this->addHostComment($comments[$host->getId()], $host);
}
foreach ($services as $service) {
$this->addServiceComment($comments[$service->getId()], $service);
}
foreach ($metaServices as $metaId => $metaService) {
$this->addMetaServiceComment($comments[$metaId], $metaService);
}
}
}
| 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/Comment/Comment.php | centreon/src/Centreon/Domain/Monitoring/Comment/Comment.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\Comment;
class Comment
{
/** @var int Resource ID */
public $resourceId;
/** @var string added comment */
public $comment;
/**
* Date of the comment
*
* @var \DateTime|null
*/
public $date;
/** @var int|null Parent Resource ID */
private $parentResourceId;
public function __construct(int $resourceId, string $comment)
{
$this->resourceId = $resourceId;
$this->setComment($comment);
}
/**
* @return int
*/
public function getResourceId(): int
{
return $this->resourceId;
}
/**
* @param int $resourceId
* @return Comment
*/
public function setResourceId(int $resourceId): Comment
{
$this->resourceId = $resourceId;
return $this;
}
/**
* @return int|null
*/
public function getParentResourceId(): ?int
{
return $this->parentResourceId;
}
/**
* @param int|null $parentResourceId
* @return Comment
*/
public function setParentResourceId(?int $parentResourceId): Comment
{
$this->parentResourceId = $parentResourceId;
return $this;
}
/**
* Get added comment
*
* @return string
*/
public function getComment(): string
{
return $this->comment;
}
/**
* Set added comment
*
* @param string $comment added comment
* @return Comment
*/
public function setComment(string $comment): Comment
{
$comment = trim($comment);
if (empty($comment)) {
throw new \InvalidArgumentException(
'Comment can not be empty'
);
}
$this->comment = $comment;
return $this;
}
/**
* Get date of the comment
*
* @return \DateTime|null
*/
public function getDate(): ?\DateTime
{
return $this->date;
}
/**
* Set date of the comment
*
* @param \DateTime $date Date of the comment
* @return Comment
*/
public function setDate(\DateTime $date)
{
$this->date = $date;
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/Comment/Interfaces/CommentServiceInterface.php | centreon/src/Centreon/Domain/Monitoring/Comment/Interfaces/CommentServiceInterface.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\Comment\Interfaces;
use Centreon\Domain\Contact\Interfaces\ContactFilterInterface;
use Centreon\Domain\Monitoring\Comment\Comment;
use Centreon\Domain\Monitoring\Host;
use Centreon\Domain\Monitoring\Service;
interface CommentServiceInterface extends ContactFilterInterface
{
/**
* Function allowing contact to add a comment to a service
*
* @param Comment $comment Comment to add to the service
* @param Service $service Service that will receive the comment
*/
public function addServiceComment(Comment $comment, Service $service): void;
/**
* Function allowing contact to add a comment to a service
*
* @param Comment $comment Comment to add to the service
* @param Service $metaService Meta service that will receive the comment
*/
public function addMetaServiceComment(Comment $comment, Service $metaService): void;
/**
* Function allowing contact to add a comment to a host
*
* @param Comment $comment Comment to add to the host
* @param Host $host Host that will receive the comment
* @return void
*/
public function addHostComment(Comment $comment, Host $host): void;
/**
* Function allowing contact to add multiple comments to multiple resources
*
* @param Comment[] $comments Comments added for each resources
* @param array $resourceIds IDs of the resources
* @return void
*/
public function addResourcesComment(array $comments, array $resourceIds): 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/Monitoring/Exception/MonitoringServiceException.php | centreon/src/Centreon/Domain/Monitoring/Exception/MonitoringServiceException.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\Exception;
class MonitoringServiceException extends \Exception
{
/**
* @return self
*/
public static function hostIdNotNull(): self
{
return new self(_('Host id cannot be null'));
}
/**
* @return self
*/
public static function serviceIdNotNull(): self
{
return new self(_('Service id cannot be null'));
}
/**
* @return self
*/
public static function configurationHasChanged(): self
{
return new self(_('Configuration has changed'));
}
/**
* @return self
*/
public static function macroPasswordNotDetected(): self
{
return new self(_('Macro passwords cannot be detected'));
}
/**
* @return self
*/
public static function configurationCommandNotSplitted(): self
{
return new self(_('Configuration command cannot be splitted by macros'));
}
}
| 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/Exception/ResourceException.php | centreon/src/Centreon/Domain/Monitoring/Exception/ResourceException.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\Exception;
class ResourceException 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/Monitoring/HostGroup/HostGroupException.php | centreon/src/Centreon/Domain/Monitoring/HostGroup/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\Monitoring\HostGroup;
class HostGroupException 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/Monitoring/HostGroup/HostGroupService.php | centreon/src/Centreon/Domain/Monitoring/HostGroup/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\Monitoring\HostGroup;
use Centreon\Domain\Monitoring\HostGroup\Interfaces\HostGroupRepositoryInterface;
use Centreon\Domain\Monitoring\HostGroup\Interfaces\HostGroupServiceInterface;
use Centreon\Domain\Service\AbstractCentreonService;
use Core\Security\AccessGroup\Application\Repository\ReadAccessGroupRepositoryInterface;
final class HostGroupService extends AbstractCentreonService implements HostGroupServiceInterface
{
/** @var HostGroupRepositoryInterface */
private $hostGroupRepository;
/** @var ReadAccessGroupRepositoryInterface */
private $accessGroupRepository;
/**
* @param HostGroupRepositoryInterface $hostGroupRepository
* @param ReadAccessGroupRepositoryInterface $accessGroupRepository
*/
public function __construct(
HostGroupRepositoryInterface $hostGroupRepository,
ReadAccessGroupRepositoryInterface $accessGroupRepository,
) {
$this->hostGroupRepository = $hostGroupRepository;
$this->accessGroupRepository = $accessGroupRepository;
}
/**
* @inheritDoc
*/
public function filterByContact($contact): HostGroupServiceInterface
{
parent::filterByContact($contact);
$this->hostGroupRepository
->setContact($this->contact)
->filterByAccessGroups($this->accessGroupRepository->findByContact($this->contact));
return $this;
}
/**
* @inheritDoc
*/
public function findHostGroupsByIds(array $hostGroupIds): array
{
try {
return $this->hostGroupRepository->findHostGroupsByIds($hostGroupIds);
} catch (\Throwable $e) {
throw new HostGroupException(_('Error when searching hostgroups'), 0, $e);
}
}
/**
* @inheritDoc
*/
public function findHostGroupsByNames(array $hostGroupNames): array
{
try {
return $this->hostGroupRepository->findHostGroupsByNames($hostGroupNames);
} catch (\Throwable $e) {
throw new HostGroupException(_('Error when searching hostgroups'), 0, $e);
}
}
}
| 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/Interfaces/HostGroupRepositoryInterface.php | centreon/src/Centreon/Domain/Monitoring/HostGroup/Interfaces/HostGroupRepositoryInterface.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\HostGroup\Interfaces;
use Centreon\Domain\Contact\Interfaces\ContactInterface;
use Centreon\Domain\Monitoring\HostGroup;
interface HostGroupRepositoryInterface
{
/**
* Retrieve hostgroups from their ids
*
* @param int[] $hostGroupIds
* @return HostGroup[]
*/
public function findHostGroupsByIds(array $hostGroupIds): array;
/**
* Retrieve hostgroups from their names
*
* @param string[] $hostGroupNames
* @return HostGroup[]
*/
public function findHostGroupsByNames(array $hostGroupNames): array;
/**
* @param ContactInterface $contact
* @return HostGroupRepositoryInterface
*/
public function setContact(ContactInterface $contact): HostGroupRepositoryInterface;
/**
* Sets the access groups that will be used to filter.
*
* @param \Core\Security\AccessGroup\Domain\Model\AccessGroup[]|null $accessGroups
* @return HostGroupRepositoryInterface
*/
public function filterByAccessGroups(?array $accessGroups): HostGroupRepositoryInterface;
}
| 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/Interfaces/HostGroupServiceInterface.php | centreon/src/Centreon/Domain/Monitoring/HostGroup/Interfaces/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\Monitoring\HostGroup\Interfaces;
use Centreon\Domain\Monitoring\HostGroup;
use Centreon\Domain\Monitoring\HostGroup\HostGroupException;
interface HostGroupServiceInterface
{
/**
* 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 HostGroupServiceInterface
*/
public function filterByContact($contact): HostGroupServiceInterface;
/**
* Retrieve hostgroups from their ids
*
* @param int[] $hostGroupIds
* @throws HostGroupException
* @return HostGroup[]
*/
public function findHostGroupsByIds(array $hostGroupIds): array;
/**
* Retrieve hostgroups from their names
*
* @param string[] $hostGroupNames
* @throws HostGroupException
* @return HostGroup[]
*/
public function findHostGroupsByNames(array $hostGroupNames): 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/Exception/EntityNotFoundException.php | centreon/src/Centreon/Domain/Exception/EntityNotFoundException.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\Exception;
use Throwable;
class EntityNotFoundException extends \Exception
{
public function __construct(string $message = '', int $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/Exception/ContactDisabledException.php | centreon/src/Centreon/Domain/Exception/ContactDisabledException.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
*
*/
namespace Centreon\Domain\Exception;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
class ContactDisabledException extends AuthenticationException
{
public function getMessageKey(): string
{
return 'Contact disabled.';
}
}
| 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/Exception/ExpiredTokenException.php | centreon/src/Centreon/Domain/Exception/ExpiredTokenException.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
*
*/
namespace Centreon\Domain\Exception;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
class ExpiredTokenException extends AuthenticationException
{
public function getMessageKey(): string
{
return 'Token expired.';
}
}
| 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/Exception/TimeoutException.php | centreon/src/Centreon/Domain/Exception/TimeoutException.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\Exception;
/**
* @package Centreon\Domain\Exception
*/
class TimeoutException 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/PlatformInformation/PlatformInformationService.php | centreon/src/Centreon/Domain/PlatformInformation/PlatformInformationService.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\PlatformInformation;
use Centreon\Domain\PlatformInformation\Exception\PlatformInformationException;
use Centreon\Domain\PlatformInformation\Interfaces\PlatformInformationReadRepositoryInterface;
use Centreon\Domain\PlatformInformation\Interfaces\PlatformInformationServiceInterface;
use Centreon\Domain\PlatformInformation\Model\PlatformInformation;
/**
* Service intended to use rest API on 'information' specific configuration data
*
* @package Centreon\Domain\PlatformInformation
*/
class PlatformInformationService implements PlatformInformationServiceInterface
{
/** @var PlatformInformationReadRepositoryInterface */
private $platformInformationRepository;
public function __construct(
PlatformInformationReadRepositoryInterface $platformInformationRepository,
) {
$this->platformInformationRepository = $platformInformationRepository;
}
/**
* @inheritDoc
*/
public function getInformation(): ?PlatformInformation
{
$foundPlatformInformation = null;
try {
$foundPlatformInformation = $this->platformInformationRepository->findPlatformInformation();
} catch (\InvalidArgumentException $ex) {
throw $ex;
} catch (\Exception $ex) {
throw new PlatformInformationException(
_("Unable to retrieve platform information's data.")
);
}
return $foundPlatformInformation;
}
}
| 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/PlatformInformation/Model/PlatformInformationFactory.php | centreon/src/Centreon/Domain/PlatformInformation/Model/PlatformInformationFactory.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\PlatformInformation\Model;
use Security\Encryption;
class PlatformInformationFactory
{
/**
* Credentials encryption second key
*/
public const ENCRYPT_SECOND_KEY = 'api_remote_credentials';
/** @var string|null */
private $encryptionFirstKey;
public function __construct(?string $encryptionFirstKey)
{
$this->encryptionFirstKey = $encryptionFirstKey;
}
/**
* @param array<string, mixed> $information
* @throws \Exception
* @return PlatformInformation
*/
public function createRemoteInformation(array $information): PlatformInformation
{
$isRemote = true;
$platformInformation = new PlatformInformation($isRemote);
foreach ($information as $key => $value) {
switch ($key) {
case 'address':
$platformInformation->setAddress($value);
break;
case 'centralServerAddress':
$platformInformation->setCentralServerAddress($value);
break;
case 'apiUsername':
$platformInformation->setApiUsername($value);
break;
case 'apiCredentials':
$platformInformation->setApiCredentials($value);
$passwordEncrypted = $this->encryptApiCredentials($value);
$platformInformation->setEncryptedApiCredentials($passwordEncrypted);
break;
case 'apiScheme':
$platformInformation->setApiScheme($value);
break;
case 'apiPort':
$platformInformation->setApiPort($value);
break;
case 'apiPath':
$platformInformation->setApiPath($value);
break;
case 'peerValidation':
$platformInformation->setApiPeerValidation($value);
break;
case 'platformName':
$platformInformation->setPlatformName($value);
break;
}
}
return $platformInformation;
}
/**
* Create a PlatformInformation with isRemote false and other information are null.
*
* @return PlatformInformation
*/
public function createCentralInformation(): PlatformInformation
{
$isRemote = false;
return new PlatformInformation($isRemote);
}
/**
* encrypt the Central API Password
*
* @param string $password
* @throws \Exception
* @return string
*/
private function encryptApiCredentials(string $password): string
{
if ($this->encryptionFirstKey === null) {
throw new \InvalidArgumentException(
_('Unable to find the encryption key.')
);
}
$secondKey = base64_encode(self::ENCRYPT_SECOND_KEY);
$centreonEncryption = new Encryption();
$centreonEncryption->setFirstKey($this->encryptionFirstKey)->setSecondKey($secondKey);
return $centreonEncryption->crypt($password);
}
}
| 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/PlatformInformation/Model/PlatformInformationDtoValidator.php | centreon/src/Centreon/Domain/PlatformInformation/Model/PlatformInformationDtoValidator.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\PlatformInformation\Model;
use Centreon\Domain\PlatformInformation\Interfaces\DtoValidatorInterface;
use JsonSchema\Constraints\Constraint;
use JsonSchema\Validator;
class PlatformInformationDtoValidator implements DtoValidatorInterface
{
/** @var string */
private $jsonSchemaPath;
public function __construct(string $jsonSchemaPath)
{
$this->jsonSchemaPath = $jsonSchemaPath;
}
/**
* @inheritDoc
*/
public function validateOrFail(array $dto): void
{
$request = Validator::arrayToObjectRecursive($dto);
$validator = new Validator();
$file = 'file://' . $this->jsonSchemaPath;
$validator->validate(
$request,
(object) ['$ref' => $file],
Constraint::CHECK_MODE_VALIDATE_SCHEMA
);
if (! $validator->isValid()) {
$message = '';
foreach ($validator->getErrors() as $error) {
$message .= sprintf('[%s] %s' . PHP_EOL, $error['property'], $error['message']);
}
throw new \InvalidArgumentException($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/PlatformInformation/Model/Information.php | centreon/src/Centreon/Domain/PlatformInformation/Model/Information.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\PlatformInformation\Model;
use Centreon\Domain\Common\Assertion\Assertion;
/**
* Class designed to retrieve servers' specific information
*/
class Information
{
public const MAX_KEY_LENGTH = 25;
public const MAX_VALUE_LENGTH = 1024;
public const MIN_KEY_LENGTH = 1;
public const MIN_VALUE_LENGTH = 1;
/**
* Information key
*
* @var string
*/
private $key;
/**
* Information value
*
* @var mixed|null
*/
private $value;
/**
* Undocumented function
*
* @return string
*/
public function getKey(): string
{
return $this->key;
}
/**
* @param string $key
* @throws \Assert\AssertionFailedException
* @return self
*/
public function setKey(string $key): self
{
Assertion::minLength($key, self::MIN_KEY_LENGTH, 'Information::key');
Assertion::maxLength($key, self::MAX_KEY_LENGTH, 'Information::key');
$this->key = $key;
return $this;
}
/**
* @return string|array<string,mixed>|int|bool|null
*/
public function getValue()
{
return $this->value;
}
/**
* @param mixed $value
* @throws \Assert\AssertionFailedException
* @return self
*/
public function setValue($value): self
{
if ($value !== null && is_string($value)) {
Assertion::minLength($value, self::MIN_VALUE_LENGTH, 'Information::value');
Assertion::maxLength($value, self::MAX_VALUE_LENGTH, 'Information::value');
}
$this->value = $value;
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/PlatformInformation/Model/PlatformInformation.php | centreon/src/Centreon/Domain/PlatformInformation/Model/PlatformInformation.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\PlatformInformation\Model;
require_once __DIR__ . '/../../../../../www/class/HtmlAnalyzer.php';
use Centreon\Domain\PlatformInformation\Exception\PlatformInformationException;
/**
* Class designed to retrieve servers' specific information
*/
class PlatformInformation
{
/** @var bool platform type */
private $isRemote;
/** @var string|null */
private $platformName;
/** @var string server address */
private string $address = '127.0.0.1';
/** @var string|null central's address */
private $centralServerAddress;
/** @var string|null */
private $apiUsername;
/** @var string|null */
private $encryptedApiCredentials;
/** @var string|null */
private $apiCredentials;
/** @var string|null */
private $apiScheme;
/** @var int|null */
private $apiPort;
/** @var string|null */
private $apiPath;
/** @var bool SSL peer validation */
private $apiPeerValidation = false;
public function __construct(bool $isRemote)
{
$this->isRemote = $isRemote;
}
/**
* @return bool
*/
public function isRemote(): bool
{
return $this->isRemote;
}
/**
* @param bool $isRemote
* @return $this
*/
public function setRemote(bool $isRemote): self
{
$this->isRemote = $isRemote;
return $this;
}
/**
* @return string|null
*/
public function getPlatformName(): ?string
{
return $this->platformName;
}
/**
* @param string|null $name
* @return self
*/
public function setPlatformName(?string $name): self
{
$this->platformName = \HtmlAnalyzer::sanitizeAndRemoveTags($name);
if (empty($this->platformName)) {
throw new \InvalidArgumentException(_("Platform name can't be empty"));
}
return $this;
}
/**
* @return string
*/
public function getAddress(): string
{
return $this->address;
}
/**
* @param string $address
* @return $this
*/
public function setAddress(string $address): self
{
$this->address = $address;
return $this;
}
/**
* @return string|null
*/
public function getCentralServerAddress(): ?string
{
return $this->centralServerAddress;
}
/**
* @param string|null $address
* @return $this
*/
public function setCentralServerAddress(?string $address): self
{
$this->centralServerAddress = $address;
return $this;
}
/**
* @return string|null
*/
public function getApiUsername(): ?string
{
return $this->apiUsername;
}
/**
* @param string|null $username
* @return $this
*/
public function setApiUsername(?string $username): self
{
$this->apiUsername = $username;
return $this;
}
/**
* @return string|null
*/
public function getApiCredentials(): ?string
{
return $this->apiCredentials;
}
/**
* @param string|null $apiCredentials
* @return $this
*/
public function setApiCredentials(?string $apiCredentials): self
{
$this->apiCredentials = $apiCredentials;
return $this;
}
/**
* @return string|null
*/
public function getEncryptedApiCredentials(): ?string
{
return $this->encryptedApiCredentials;
}
/**
* Undocumented function
*
* @param string|null $encryptedKey
* @return self
*/
public function setEncryptedApiCredentials(?string $encryptedKey): self
{
$this->encryptedApiCredentials = $encryptedKey;
return $this;
}
/**
* @return string|null
*/
public function getApiScheme(): ?string
{
return $this->apiScheme;
}
/**
* @param string|null $schema
* @return $this
*/
public function setApiScheme(?string $schema): self
{
if ($schema !== null) {
$schema = (trim($schema, '/') === 'https' ? 'https' : 'http');
}
$this->apiScheme = $schema;
return $this;
}
/**
* @return int|null
*/
public function getApiPort(): ?int
{
return $this->apiPort;
}
/**
* @param int|null $port
* @throws PlatformInformationException
* @return $this
*/
public function setApiPort(?int $port): self
{
$this->apiPort = $port !== null ? $this->checkPortConsistency($port) : $port;
return $this;
}
/**
* @return string|null
*/
public function getApiPath(): ?string
{
return $this->apiPath;
}
/**
* @param string|null $path
* @throws PlatformInformationException
* @return $this
*/
public function setApiPath(?string $path): self
{
if ($path !== null) {
$path = trim(\HtmlAnalyzer::sanitizeAndRemoveTags($path), '/');
if (empty($path)) {
throw PlatformInformationException::inconsistentDataException();
}
}
$this->apiPath = $path;
return $this;
}
/**
* @return bool
*/
public function hasApiPeerValidation(): bool
{
return $this->apiPeerValidation;
}
/**
* @param bool $status
* @return $this
*/
public function setApiPeerValidation(bool $status): self
{
$this->apiPeerValidation = $status;
return $this;
}
/**
* @param int $port
* @throws PlatformInformationException
* @return int
*/
private function checkPortConsistency(int $port): int
{
if ($port < 1 || $port > 65535) {
throw PlatformInformationException::inconsistentDataException();
}
return $port;
}
}
| 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/PlatformInformation/Model/InformationFactory.php | centreon/src/Centreon/Domain/PlatformInformation/Model/InformationFactory.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\PlatformInformation\Model;
class InformationFactory
{
/**
* @param array<string,mixed> $request
* @throws \Assert\AssertionFailedException
* @return array<Information>
*/
public static function createFromDto(array $request): array
{
$information = [];
foreach ($request as $key => $value) {
$newInformation = (new Information())
->setKey($key)
->setValue($value);
$information[] = $newInformation;
}
return $information;
}
}
| 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/PlatformInformation/UseCase/V20/UpdatePartiallyPlatformInformation.php | centreon/src/Centreon/Domain/PlatformInformation/UseCase/V20/UpdatePartiallyPlatformInformation.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\PlatformInformation\UseCase\V20;
use Centreon\Domain\Contact\Contact;
use Centreon\Domain\Contact\Interfaces\ContactInterface;
use Centreon\Domain\PlatformInformation\Exception\PlatformInformationException;
use Centreon\Domain\PlatformInformation\Interfaces\DtoValidatorInterface;
use Centreon\Domain\PlatformInformation\Interfaces\PlatformInformationReadRepositoryInterface;
use Centreon\Domain\PlatformInformation\Interfaces\PlatformInformationWriteRepositoryInterface;
use Centreon\Domain\PlatformInformation\Model\Information;
use Centreon\Domain\PlatformInformation\Model\InformationFactory;
use Centreon\Domain\PlatformInformation\Model\PlatformInformation;
use Centreon\Domain\PlatformInformation\Model\PlatformInformationFactory;
use Centreon\Domain\PlatformTopology\Interfaces\PlatformTopologyServiceInterface;
use Centreon\Domain\Proxy\Interfaces\ProxyServiceInterface;
use Centreon\Domain\Proxy\Proxy;
use Centreon\Domain\RemoteServer\Interfaces\RemoteServerServiceInterface;
use Centreon\Domain\RemoteServer\RemoteServerException;
class UpdatePartiallyPlatformInformation
{
/**
* Array of all available validators for this use case.
*
* @var array<DtoValidatorInterface>
*/
private $validators = [];
/** @var string|null */
private $encryptionFirstKey;
public function __construct(
private PlatformInformationWriteRepositoryInterface $writeRepository,
private PlatformInformationReadRepositoryInterface $readRepository,
private ProxyServiceInterface $proxyService,
private RemoteServerServiceInterface $remoteServerService,
private PlatformTopologyServiceInterface $platformTopologyService,
private ContactInterface $user,
) {
$this->writeRepository = $writeRepository;
$this->readRepository = $readRepository;
$this->proxyService = $proxyService;
$this->remoteServerService = $remoteServerService;
$this->platformTopologyService = $platformTopologyService;
}
public function setEncryptionFirstKey(?string $encryptionFirstKey): void
{
$this->encryptionFirstKey = $encryptionFirstKey;
}
/**
* @param array<DtoValidatorInterface> $validators
*/
public function addValidators(array $validators): void
{
foreach ($validators as $validator) {
$this->addValidator($validator);
}
}
/**
* Execute the use case for which this class was designed.
*
* @param array<string,mixed> $request
*
* @throws \Throwable|PlatformInformationException
*/
public function execute(array $request): void
{
if (
! $this->user->isAdmin()
&& ! (
$this->user->hasTopologyRole(Contact::ROLE_CONFIGURATION_MONITORING_SERVER_READ_WRITE)
&& $this->user->hasRole(Contact::ROLE_CREATE_EDIT_POLLER_CFG)
)
) {
throw PlatformInformationException::noRights();
}
foreach ($this->validators as $validator) {
$validator->validateOrFail($request);
}
/**
* Create Information from Factory to be able to access them independently
* and validate the length of each value.
*/
$informationList = InformationFactory::createFromDto($request);
$currentPlatformInformation = $this->readRepository->findPlatformInformation();
$platformInformationFactory = new PlatformInformationFactory($this->encryptionFirstKey);
/**
* Take account if the isRemote request key is provided to create the PlatformInformation and trigger
* the conversion.
* If this key is not provided in the request, we dont want to convert the platform
* and just update the informations.
*/
if (
(isset($request['isRemote']) && $request['isRemote'] === true)
|| (! isset($request['isRemote']) && $currentPlatformInformation->isRemote() === true)
) {
$platformInformationToUpdate = $platformInformationFactory->createRemoteInformation($request);
} else {
$platformInformationToUpdate = $platformInformationFactory->createCentralInformation();
}
if (isset($request['isRemote'])) {
$this->updateRemoteOrCentralType($platformInformationToUpdate, $currentPlatformInformation);
}
foreach ($informationList as $information) {
if ($information->getKey() === 'proxy') {
$this->updateProxyOptions($information, $platformInformationToUpdate->getCentralServerAddress());
}
}
$this->writeRepository->updatePlatformInformation($platformInformationToUpdate);
}
/**
* @param DtoValidatorInterface $dtoValidator
*/
private function addValidator(DtoValidatorInterface $dtoValidator): void
{
$this->validators[] = $dtoValidator;
}
/**
* Update Proxy Options.
*
* @param Information $proxyInformation
* @param string|null $centralServerAddress
* @throws \InvalidArgumentException
*/
private function updateProxyOptions(Information $proxyInformation, ?string $centralServerAddress): void
{
/**
* Verify that proxy address and central address are different before continue the update.
*/
$proxyOptions = $proxyInformation->getValue();
if ($centralServerAddress !== null && isset($proxyOptions['host'])) {
$this->validateCentralServerAddressOrFail(
$centralServerAddress,
$proxyOptions['host']
);
}
$proxy = new Proxy();
if (isset($proxyOptions['host'])) {
$proxy->setUrl($proxyOptions['host']);
}
if (isset($proxyOptions['scheme'])) {
$proxy->setProtocol($proxyOptions['scheme']);
}
if (isset($proxyOptions['port'])) {
$proxy->setPort($proxyOptions['port']);
}
if (isset($proxyOptions['user'])) {
$proxy->setUser($proxyOptions['user']);
if (isset($proxyOptions['password'])) {
$proxy->setPassword($proxyOptions['password']);
}
}
$this->proxyService->updateProxy($proxy);
}
/**
* Update the Platform Type
*
* @param PlatformInformation $platformInformationToUpdate
* @param PlatformInformation $currentPlatformInformation
* @throws RemoteServerException
*/
private function updateRemoteOrCentralType(
PlatformInformation $platformInformationToUpdate,
PlatformInformation $currentPlatformInformation,
): void {
if ($platformInformationToUpdate->isRemote()) {
$this->convertCentralToRemote($platformInformationToUpdate, $currentPlatformInformation);
} elseif ($platformInformationToUpdate->isRemote() === false && $currentPlatformInformation->isRemote()) {
/**
* Use the current information
* as they contains all the information required to remove the Remote to its Parent
*/
$this->remoteServerService->convertRemoteToCentral($currentPlatformInformation);
}
}
/**
* This method verify the existing and updated type before sending information to Remote Server Service.
*
* @param PlatformInformation $platformInformationToUpdate
* @param PlatformInformation $currentPlatformInformation
* @throws RemoteServerException
* @return void
*/
private function convertCentralToRemote(
PlatformInformation $platformInformationToUpdate,
PlatformInformation $currentPlatformInformation,
): void {
/**
* If some parameters required fort registering the Remote Server are missing,
* populate them with existing values.
*/
$platformInformationToUpdate = $this->populateMissingInformationValues(
$platformInformationToUpdate,
$currentPlatformInformation
);
$this->remoteServerService->convertCentralToRemote(
$platformInformationToUpdate
);
}
/**
* Validate that central server address is not already in used by another platform or by the proxy.
*
* @param string $centralServerAddress
* @param string|null $proxyAddress
* @throws PlatformInformationException
*/
private function validateCentralServerAddressOrFail(
string $centralServerAddress,
?string $proxyAddress = null,
): void {
$platforms = $this->platformTopologyService->getPlatformTopology();
foreach ($platforms as $platform) {
if ($centralServerAddress === $platform->getAddress()) {
throw new PlatformInformationException(
sprintf(
_('the address %s is already used in the topology and can\'t '
. 'be provided as Central Server Address'),
$centralServerAddress
)
);
}
}
if ($centralServerAddress === $proxyAddress) {
throw new PlatformInformationException(
sprintf(
_('the address %s is already used has proxy address and can\'t '
. 'be provided as Central Server Address'),
$centralServerAddress
)
);
}
}
/**
* Populate the PlatformInformation missing values.
* This method is useful if some properties are already existing in data storage.
*
* @param PlatformInformation $platformInformationToUpdate
* @param PlatformInformation $currentPlatformInformation
* @return PlatformInformation
*/
private function populateMissingInformationValues(
PlatformInformation $platformInformationToUpdate,
PlatformInformation $currentPlatformInformation,
): PlatformInformation {
if ($platformInformationToUpdate->getCentralServerAddress() !== null) {
$this->validateCentralServerAddressOrFail($platformInformationToUpdate->getCentralServerAddress());
}
if ($platformInformationToUpdate->getCentralServerAddress() === null) {
$platformInformationToUpdate->setCentralServerAddress(
$currentPlatformInformation->getCentralServerAddress()
);
}
if ($platformInformationToUpdate->getApiCredentials() === null) {
$platformInformationToUpdate->setApiCredentials(
$currentPlatformInformation->getApiCredentials()
);
}
if ($platformInformationToUpdate->getApiUsername() === null) {
$platformInformationToUpdate->setApiUsername(
$currentPlatformInformation->getApiUsername()
);
}
if ($platformInformationToUpdate->getApiPath() === null) {
$platformInformationToUpdate->setApiPath(
$currentPlatformInformation->getApiPath()
);
}
if ($platformInformationToUpdate->getApiScheme() === null) {
$platformInformationToUpdate->setApiScheme(
$currentPlatformInformation->getApiScheme()
);
}
if ($platformInformationToUpdate->getApiPort() === null) {
$platformInformationToUpdate->setApiPort(
$currentPlatformInformation->getApiPort()
);
}
return $platformInformationToUpdate;
}
}
| 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/PlatformInformation/Interfaces/PlatformInformationServiceInterface.php | centreon/src/Centreon/Domain/PlatformInformation/Interfaces/PlatformInformationServiceInterface.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\PlatformInformation\Interfaces;
use Centreon\Domain\PlatformInformation\Exception\PlatformInformationException;
use Centreon\Domain\PlatformInformation\Model\PlatformInformation;
interface PlatformInformationServiceInterface
{
/**
* Get monitoring server data.
*
* @throws PlatformInformationException|\InvalidArgumentException
* @return PlatformInformation|null
*/
public function getInformation(): ?PlatformInformation;
}
| 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/PlatformInformation/Interfaces/DtoValidatorInterface.php | centreon/src/Centreon/Domain/PlatformInformation/Interfaces/DtoValidatorInterface.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\PlatformInformation\Interfaces;
interface DtoValidatorInterface
{
/**
* Validate the request DTO.
*
* @param array<string,mixed> $dto
* @throws \Throwable
*/
public function validateOrFail(array $dto): 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/PlatformInformation/Interfaces/PlatformInformationRepositoryInterface.php | centreon/src/Centreon/Domain/PlatformInformation/Interfaces/PlatformInformationRepositoryInterface.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\PlatformInformation\Interfaces;
interface PlatformInformationRepositoryInterface extends
PlatformInformationReadRepositoryInterface,
PlatformInformationWriteRepositoryInterface
{
}
| 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/PlatformInformation/Interfaces/PlatformInformationWriteRepositoryInterface.php | centreon/src/Centreon/Domain/PlatformInformation/Interfaces/PlatformInformationWriteRepositoryInterface.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\PlatformInformation\Interfaces;
use Centreon\Domain\PlatformInformation\Model\PlatformInformation;
interface PlatformInformationWriteRepositoryInterface
{
/**
* Update the platform information.
*
* @param PlatformInformation $platformInformation
* @throws \Exception
*/
public function updatePlatformInformation(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/PlatformInformation/Interfaces/PlatformInformationReadRepositoryInterface.php | centreon/src/Centreon/Domain/PlatformInformation/Interfaces/PlatformInformationReadRepositoryInterface.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\PlatformInformation\Interfaces;
use Centreon\Domain\PlatformInformation\Model\PlatformInformation;
interface PlatformInformationReadRepositoryInterface
{
/**
* Find all platform information.
*
* @throws \Exception
* @return PlatformInformation|null
*/
public function findPlatformInformation(): ?PlatformInformation;
/**
* set the Encryption first key.
*
* @param string|null $encryptionFirstKey
* @return void
*/
public function setEncryptionFirstKey(?string $encryptionFirstKey): 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/PlatformInformation/Exception/PlatformInformationException.php | centreon/src/Centreon/Domain/PlatformInformation/Exception/PlatformInformationException.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\PlatformInformation\Exception;
/**
* This class is designed to represent a business exception in the 'Platform information' context.
*
* @package Centreon\Domain\PlatformInformation
*/
class PlatformInformationException extends \Exception
{
public const CODE_FORBIDDEN = 1;
/**
* @return PlatformInformationException
*/
public static function inconsistentDataException(): self
{
return new self(_("Central platform's API data is not consistent. Please check the 'Remote Access' form."));
}
public static function noRights(): self
{
return new self(_('You do not have sufficent rights for this action.'), self::CODE_FORBIDDEN);
}
}
| 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/Option/OptionService.php | centreon/src/Centreon/Domain/Option/OptionService.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\Option;
use Centreon\Domain\Option\Interfaces\OptionRepositoryInterface;
use Centreon\Domain\Option\Interfaces\OptionServiceInterface;
/**
* This class is designed to manage the configuration options of Centreon
*
* @package Centreon\Domain\Option
*/
class OptionService implements OptionServiceInterface
{
/** @var OptionRepositoryInterface */
private $repository;
/**
* @param OptionRepositoryInterface $repository
*/
public function __construct(OptionRepositoryInterface $repository)
{
$this->repository = $repository;
}
/**
* @inheritDoc
*/
public function findSelectedOptions(array $optionsToFind): array
{
try {
$optionsFound = $this->repository->findAllOptions();
} catch (\Throwable $ex) {
throw new \Exception(_('Error when retrieving selected options'), 0, $ex);
}
$requestedOptions = [];
foreach ($optionsFound as $option) {
if (in_array($option->getName(), $optionsToFind)) {
$requestedOptions[] = $option;
}
}
return $requestedOptions;
}
/**
* @inheritDoc
*/
public function findAllOptions(bool $useCache): array
{
return $this->repository->findAllOptions($useCache);
}
}
| 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/Option/OptionException.php | centreon/src/Centreon/Domain/Option/OptionException.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\Option;
class OptionException 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/Option/Option.php | centreon/src/Centreon/Domain/Option/Option.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\Option;
/**
* Class Option
*
* @package Centreon\Domain\Option
*/
class Option
{
/** @var string Option name */
private $name;
/** @var string|null Option value */
private $value;
/**
* @return string
* @see Option::$name
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
* @return Option
* @see Option::$name
*/
public function setName(string $name): Option
{
$this->name = $name;
return $this;
}
/**
* @return string|null
* @see Option::$value
*/
public function getValue(): ?string
{
return $this->value;
}
/**
* @param string|null $value
* @return Option
* @see Option::$value
*/
public function setValue(?string $value): Option
{
$this->value = $value;
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/Option/Interfaces/OptionServiceInterface.php | centreon/src/Centreon/Domain/Option/Interfaces/OptionServiceInterface.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\Option\Interfaces;
use Centreon\Domain\Option\Option;
/**
* Interface OptionServiceInterface
*
* @package Centreon\Domain\Option\Interfaces
*/
interface OptionServiceInterface
{
/**
* Find options using key name.
*
* <code>
* $selectedOptions = $optionService->findSelectedOptions(['snmp_version', 'session_expire']);
* </code>
*
* @param string[] $optionsToFind Keys of the options to find
* @throws \Exception
* @return Option[] Options list corresponding to the options requested
*/
public function findSelectedOptions(array $optionsToFind): array;
/**
* Find all options.
*
* @param bool $useCache Indicates whether we should use the cache system or not (TRUE by default)
* @throws \Exception
* @return Option[] Returns all available options
*/
public function findAllOptions(bool $useCache): 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/Option/Interfaces/OptionRepositoryInterface.php | centreon/src/Centreon/Domain/Option/Interfaces/OptionRepositoryInterface.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\Option\Interfaces;
use Centreon\Domain\Option\Option;
/**
* Interface OptionRepositoryInterface
*
* @package Centreon\Domain\Option\Interfaces
*/
interface OptionRepositoryInterface
{
/**
* Find all options.
*
* @param bool $useCache Indicates whether we should use the cache system or not (TRUE by default)
* @return Option[] Returns all available options
*/
public function findAllOptions(bool $useCache = true): 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/Gorgone/GorgoneException.php | centreon/src/Centreon/Domain/Gorgone/GorgoneException.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\Gorgone;
/**
* This class is designed to represent a business exception in the 'Gorgone' context.
*
* @package Centreon\Domain\Gorgone
*/
class GorgoneException 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/Gorgone/ActionLog.php | centreon/src/Centreon/Domain/Gorgone/ActionLog.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\Gorgone;
/**
* This class is designed to represent a action log received by the Gorgone server.
*
* A command can produce more than one action log.
*
* @package Centreon\Domain\Gorgone
*/
class ActionLog
{
/** @var \DateTime Creation time of the response */
private $creationTime;
/** @var \DateTime Event time of the response */
private $eventTime;
/** @var int Id of the action log */
private $id;
/** @var string Token of the response */
private $token;
/**
* @var int Status code of the response
* @see ResponseInterface::STATUS_BEGIN for code when action begin
* @see ResponseInterface::STATUS_ERROR for code when there is an error
* @see ResponseInterface::STATUS_OK for code when the last action log has been received and its statut is OK
*/
private $code;
/** @var string Response data */
private $data;
/**
* @param string $token
* @see ActionLog::$token
*/
public function __construct(string $token)
{
$this->token = $token;
}
/**
* Factory to create a action log based on the Gorgone response.
*
* @param array<string, string> $details Details used to create an action log
* @throws \Exception
* @return ActionLog
*/
public static function create(array $details): ActionLog
{
if (empty($details['token'])) {
throw new \LogicException('Token can not empty, null or not defined');
}
return (new ActionLog($details['token']))
->setId((int) ($details['id'] ?? 0))
->setCode((int) ($details['code'] ?? 0))
->setCreationTime((new \DateTime())->setTimestamp((int) ($details['ctime'] ?? 0)))
->setEventTime((new \DateTime())->setTimestamp((int) ($details['etime'] ?? 0)))
->setData($details['data'] ?? '{}');
}
/**
* @return \DateTime
* @see ActionLog::$creationTime
*/
public function getCreationTime(): \DateTime
{
return $this->creationTime;
}
/**
* @param \DateTime $creationTime
* @return ActionLog
* @see ActionLog::$creationTime
*/
public function setCreationTime(\DateTime $creationTime): ActionLog
{
$this->creationTime = $creationTime;
return $this;
}
/**
* @return \DateTime
* @see ActionLog::$eventTime
*/
public function getEventTime(): \DateTime
{
return $this->eventTime;
}
/**
* @param \DateTime $eventTime
* @return ActionLog
* @see ActionLog::$eventTime
*/
public function setEventTime(\DateTime $eventTime): ActionLog
{
$this->eventTime = $eventTime;
return $this;
}
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @param int $id
* @return ActionLog
*/
public function setId(int $id): ActionLog
{
$this->id = $id;
return $this;
}
/**
* @return string
* @see ActionLog::$token
*/
public function getToken(): string
{
return $this->token;
}
/**
* @return int
* @see ActionLog::$code
*/
public function getCode(): int
{
return $this->code;
}
/**
* @param int $code
* @return ActionLog
*/
public function setCode(int $code): ActionLog
{
$this->code = $code;
return $this;
}
/**
* @return string
* @see ActionLog::$data
*/
public function getData(): string
{
return $this->data;
}
/**
* @param string $data
* @return ActionLog
* @see ActionLog::$data
*/
public function setData(string $data): ActionLog
{
$this->data = $data;
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/Gorgone/GorgoneService.php | centreon/src/Centreon/Domain/Gorgone/GorgoneService.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\Gorgone;
use Centreon\Domain\Gorgone\Command\EmptyCommand;
use Centreon\Domain\Gorgone\Interfaces\CommandInterface;
use Centreon\Domain\Gorgone\Interfaces\CommandRepositoryInterface;
use Centreon\Domain\Gorgone\Interfaces\GorgoneServiceInterface;
use Centreon\Domain\Gorgone\Interfaces\ResponseInterface;
use Centreon\Domain\Gorgone\Interfaces\ResponseRepositoryInterface;
use Centreon\Infrastructure\Gorgone\CommandRepositoryException;
/**
* This class is designed to send a command to the Gorgone server and retrieve the associated responses.
*
* @package Centreon\Domain\Gorgone
*/
class GorgoneService implements GorgoneServiceInterface
{
/** @var CommandRepositoryInterface */
private $commandRepository;
/**
* @param ResponseRepositoryInterface $responseRepository
* @param CommandRepositoryInterface $commandRepository
*/
public function __construct(
ResponseRepositoryInterface $responseRepository,
CommandRepositoryInterface $commandRepository,
) {
$this->commandRepository = $commandRepository;
Response::setRepository($responseRepository);
}
/**
* @inheritDoc
*/
public function send(CommandInterface $command): ResponseInterface
{
try {
$responseToken = $this->commandRepository->send($command);
} catch (CommandRepositoryException $ex) {
throw new GorgoneException($ex->getMessage(), 0, $ex);
} catch (\Throwable $ex) {
throw new GorgoneException(_('Error when connecting to the Gorgone server'), 0, $ex);
}
$command->setToken($responseToken);
return Response::create($command);
}
/**
* @inheritDoc
*/
public function getResponseFromToken(int $monitoringInstanceId, string $token): ResponseInterface
{
$emptyCommand = new EmptyCommand($monitoringInstanceId);
$emptyCommand->setToken($token);
return Response::create($emptyCommand);
}
}
| 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/Gorgone/ConfigurationLoader.php | centreon/src/Centreon/Domain/Gorgone/ConfigurationLoader.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\Gorgone;
use Centreon\Domain\Option\Interfaces\OptionServiceInterface;
use Centreon\Infrastructure\Gorgone\Interfaces\ConfigurationLoaderApiInterface;
/**
* This class is designed to allow repositories to retrieve their configuration parameters.
*
* @package Centreon\Domain\Gorgone
*/
class ConfigurationLoader implements ConfigurationLoaderApiInterface
{
private const DEFAULT_TIMEOUT = 2;
private const GORGONE_API_ADDRESS = 'gorgone_api_address';
private const GORGONE_API_PORT = 'gorgone_api_port';
private const GORGONE_API_USERNAME = 'gorgone_api_username';
private const GORGONE_API_PASSWORD = 'gorgone_api_password';
private const GORGONE_API_SSL = 'gorgone_api_ssl';
private const GORGONE_API_CERTIFICATE_SELF_SIGNED = 'gorgone_api_allow_self_signed';
private const GORGONE_COMMAND_TIMEOUT = 'gorgone_cmd_timeout';
/** @var OptionServiceInterface */
private $optionService;
/** @var array<string, string|null> Parameters of the Gorgone server */
private $gorgoneParameters;
/** @var bool Indicates whether options are already loaded or not */
private $isOptionsLoaded = false;
/**
* @param OptionServiceInterface $optionService
*/
public function __construct(OptionServiceInterface $optionService)
{
$this->optionService = $optionService;
}
/**
* @inheritDoc
*/
public function getApiIpAddress(): ?string
{
if (! $this->isOptionsLoaded) {
$this->loadConfiguration();
}
return $this->gorgoneParameters[self::GORGONE_API_ADDRESS] ?? null;
}
/**
* @inheritDoc
*/
public function getApiPort(): ?int
{
if (! $this->isOptionsLoaded) {
$this->loadConfiguration();
}
return isset($this->gorgoneParameters[self::GORGONE_API_PORT])
? (int) $this->gorgoneParameters[self::GORGONE_API_PORT]
: null;
}
/**
* @inheritDoc
*/
public function getApiUsername(): ?string
{
if (! $this->isOptionsLoaded) {
$this->loadConfiguration();
}
return $this->gorgoneParameters[self::GORGONE_API_USERNAME] ?? null;
}
/**
* @inheritDoc
*/
public function getApiPassword(): ?string
{
if (! $this->isOptionsLoaded) {
$this->loadConfiguration();
}
return $this->gorgoneParameters[self::GORGONE_API_PASSWORD] ?? null;
}
/**
* @inheritDoc
*/
public function isApiConnectionSecure(): bool
{
if (! $this->isOptionsLoaded) {
$this->loadConfiguration();
}
return (bool) ($this->gorgoneParameters[self::GORGONE_API_SSL] ?? false);
}
/**
* @inheritDoc
*/
public function isSecureConnectionSelfSigned(): bool
{
if (! $this->isOptionsLoaded) {
$this->loadConfiguration();
}
return (bool) ($this->gorgoneParameters[self::GORGONE_API_CERTIFICATE_SELF_SIGNED] ?? false);
}
/**
* @inheritDoc
*/
public function getCommandTimeout(): int
{
if (! $this->isOptionsLoaded) {
$this->loadConfiguration();
}
$timeout = (int) ($this->gorgoneParameters[self::GORGONE_COMMAND_TIMEOUT] ?? self::DEFAULT_TIMEOUT);
// Do not use a timeout at 0
return $timeout > 0 ? $timeout : 1;
}
/**
* Loads configuration of the Gorgone server
*
* @throws \Exception
*/
private function loadConfiguration(): void
{
try {
$options = $this->optionService->findSelectedOptions([
self::GORGONE_API_ADDRESS,
self::GORGONE_API_PORT,
self::GORGONE_API_USERNAME,
self::GORGONE_API_PASSWORD,
self::GORGONE_API_SSL,
self::GORGONE_API_CERTIFICATE_SELF_SIGNED,
self::GORGONE_COMMAND_TIMEOUT,
]);
foreach ($options as $option) {
$this->gorgoneParameters[$option->getName()] = $option->getValue();
}
$this->isOptionsLoaded = true;
} catch (\Exception $ex) {
$this->isOptionsLoaded = false;
throw $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/Gorgone/Response.php | centreon/src/Centreon/Domain/Gorgone/Response.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\Gorgone;
use Centreon\Domain\Gorgone\Interfaces\CommandInterface;
use Centreon\Domain\Gorgone\Interfaces\ResponseInterface;
use Centreon\Domain\Gorgone\Interfaces\ResponseRepositoryInterface;
/**
* This class is design to represent a response of the Gorgone server and can be used to retrieve all action logs
* based on the command sent.
*
* @package Centreon\Domain\Gorgone
*/
class Response implements ResponseInterface
{
/** @var CommandInterface Command sent to the Gorgone server */
private $command;
/** @var string|null Error message */
private $error;
/** @var string|null Message received by the Gorgone server based on the command sent */
private $message;
/**
* @var string|null token assigned by the Gorgone server to this response which must be equal to the
* associated command
*/
private $token;
/** @var ActionLog[] action logs based on the command sent to the Gorgone server */
private $actionLogs = [];
/** @var ResponseRepositoryInterface */
private static $staticResponseRepository;
/** @var ResponseRepositoryInterface */
private $responseRepository;
public function __construct(
ResponseRepositoryInterface $responseRepository,
CommandInterface $command,
) {
$this->command = $command;
$this->responseRepository = $responseRepository;
}
/**
* @param ResponseRepositoryInterface $responseRepository
*/
public static function setRepository(ResponseRepositoryInterface $responseRepository): void
{
self::$staticResponseRepository = $responseRepository;
}
/**
* Create a Gorgone server response.
*
* The response and associated action logs will be retrieved when calling
* the getLastActionLog method.
*
* @param CommandInterface $command Command sent to the Gorgone server
* @return ResponseInterface
* @see ResponseInterface::getActionLogs()
*/
public static function create(CommandInterface $command): ResponseInterface
{
return new Response(self::$staticResponseRepository, $command);
}
/**
* @return CommandInterface|null
*/
public function getCommand(): ?CommandInterface
{
return $this->command;
}
/**
* @return string|null
*/
public function getMessage(): ?string
{
return $this->message;
}
/**
* @throws \Exception
* @return ActionLog[]
* @see Response::$actionLogs
*/
public function getActionLogs(): array
{
$this->actionLogs = [];
$rawResponse = $this->responseRepository->getResponse($this->command);
$jsonResponse = json_decode($rawResponse, true);
$this->error = $jsonResponse['error'] ?? null;
$this->token = (string) $jsonResponse['token'];
if ($this->error === null) {
foreach ($jsonResponse['data'] as $key => $responseData) {
$this->actionLogs[$key] = ActionLog::create($responseData);
}
}
$this->message = isset($jsonResponse['message']) ? (string) $jsonResponse['message'] : null;
return $this->actionLogs;
}
/**
* @throws \Exception
* @return ActionLog|null
*/
public function getLastActionLog(): ?ActionLog
{
$this->getActionLogs();
return $this->actionLogs[count($this->actionLogs) - 1] ?? null;
}
/**
* @inheritDoc
* @see Response::$token
*/
public function getToken(): ?string
{
return $this->token;
}
/**
* @inheritDoc
* @see Response::$error
*/
public function getError(): ?string
{
return $this->error;
}
}
| 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/Gorgone/Interfaces/CommandInterface.php | centreon/src/Centreon/Domain/Gorgone/Interfaces/CommandInterface.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\Gorgone\Interfaces;
interface CommandInterface
{
public const METHOD_GET = 'GET';
public const METHOD_POST = 'POST';
public const METHOD_PATCH = 'PATCH';
public const METHOD_PUT = 'PUT';
public const METHOD_DELETE = 'DELETE';
/**
* Returns the token assigned by Gorgone for this command.
*
* @return string Token
*/
public function getToken(): string;
/**
* Defines the token assigned for this command.
*
* @param string $token Token
*/
public function setToken(string $token): void;
/**
* Returns the uri associated to this command.
*
* @return string Uri of the command
*/
public function getUriRequest(): string;
/**
* Returns the body of the request that will be sent to the Gorgone server.
*
* @return string|null Body of the request
*/
public function getBodyRequest(): ?string;
/**
* Returns the monitoring instance id for which this command is intended.
*
* @return int Monitoring instance id
*/
public function getMonitoringInstanceId(): int;
/**
* Retrieve the internal name of the command.
*
* @return string Name of the command
*/
public function getName(): string;
/**
* @return string
*/
public function getMethod(): string;
}
| 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/Gorgone/Interfaces/ResponseInterface.php | centreon/src/Centreon/Domain/Gorgone/Interfaces/ResponseInterface.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\Gorgone\Interfaces;
use Centreon\Domain\Gorgone\ActionLog;
/**
* This interface is design to represent a response received by the Gorgone server.
*
* @package Centreon\Domain\Gorgone\Interfaces
*/
interface ResponseInterface
{
public const STATUS_BEGIN = 0;
public const STATUS_ERROR = 1;
public const STATUS_OK = 2;
/**
* Return the command of this response.
*
* @return CommandInterface|null
*/
public function getCommand(): ?CommandInterface;
/**
* Return the message of the response.
*
* @return string|null
*/
public function getMessage(): ?string;
/**
* Returns all the action logs received by the Gorgone server according to the command sent.
*
* To be sure that all actions logs have been received, the code of the last action log must be different to
* GorgoneResponseInterface::STATUS_OK.
*
* @return ActionLog[]
* @see ResponseInterface::STATUS_BEGIN for code when action begin
* @see ResponseInterface::STATUS_ERROR for code when there is an error
* @see ResponseInterface::STATUS_OK for code when the last action log has been received and its statut is OK
*/
public function getActionLogs(): array;
/**
* Get the last action log received by the Gorgone server according to the command sent.
*
* When this method is called and the last action log has not been received,
* a call is perform to the Gorgone server to retrieve the action logs.
*
* @return ActionLog|null
*/
public function getLastActionLog(): ?ActionLog;
/**
* Get the token assigned by the Gorgone server to this response.
*
* @return string|null
*/
public function getToken(): ?string;
/**
* Get the error message of the Gorgone server
*
* @return string|null
*/
public function getError(): ?string;
}
| 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/Gorgone/Interfaces/CommandRepositoryInterface.php | centreon/src/Centreon/Domain/Gorgone/Interfaces/CommandRepositoryInterface.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\Gorgone\Interfaces;
use Centreon\Infrastructure\Gorgone\CommandRepositoryException;
/**
* Interface CommandRepositoryInterface
* Describes management of external commands sent to gorgone
*
* @package Centreon\Domain\Gorgone\Interfaces
*/
interface CommandRepositoryInterface
{
/**
* Send a command to the Gorgone server.
*
* @param CommandInterface $command Command to send
* @throws CommandRepositoryException
* @throws \Exception
* @return string Returns a token that will be used to retrieve the response
*/
public function send(CommandInterface $command): string;
}
| 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/Gorgone/Interfaces/ResponseRepositoryInterface.php | centreon/src/Centreon/Domain/Gorgone/Interfaces/ResponseRepositoryInterface.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\Gorgone\Interfaces;
/**
* Interface ResponseRepositoryInterface
*
* @package Centreon\Domain\Gorgone\Interfaces
*/
interface ResponseRepositoryInterface
{
/**
* Returns the response of the command sent.
*
* The command must have been sent because we will use the command token to retrieve the message.
*
* @param CommandInterface $command Command sent to the Gorgone server
* @throws \Exception
* @return string Response message in JSON format
*/
public function getResponse(CommandInterface $command): string;
}
| 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/Gorgone/Interfaces/GorgoneServiceInterface.php | centreon/src/Centreon/Domain/Gorgone/Interfaces/GorgoneServiceInterface.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\Gorgone\Interfaces;
use Centreon\Domain\Gorgone\GorgoneException;
/**
* Interface GorgoneServiceInterface
*
* @package Centreon\Domain\Gorgone\Interfaces
*/
interface GorgoneServiceInterface
{
/**
* Send a command to the Gorgone server and retrieve an instance of the
* response which allow to get all action logs.
*
* @param CommandInterface $command Command to send
* @throws GorgoneException
* @return ResponseInterface returns a response containing the command sent
*/
public function send(CommandInterface $command): ResponseInterface;
/**
* Retrieve the response according to the command token and the poller id.
*
* @param int $monitoringInstanceId Id of the poller for which the command was intended
* @param string $token Token of the command returned by the Gorgone server
* @return ResponseInterface
*/
public function getResponseFromToken(int $monitoringInstanceId, string $token): ResponseInterface;
}
| 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/Gorgone/Command/Command.php | centreon/src/Centreon/Domain/Gorgone/Command/Command.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\Gorgone\Command;
use Centreon\Domain\Gorgone\Interfaces\CommandInterface;
/**
* This class is designed to send command of action type to the Gorgone server.
*
* @package Centreon\Domain\Gorgone\Command
*/
final class Command extends AbstractCommand implements CommandInterface
{
private const NAME = 'action::command';
/**
* @inheritDoc
*/
public function getUriRequest(): string
{
return 'nodes/' . $this->getMonitoringInstanceId() . '/core/action/command';
}
/**
* @inheritDoc
*/
public function getName(): string
{
return self::NAME;
}
public function getMethod(): string
{
return self::METHOD_POST;
}
}
| 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/Gorgone/Command/EmptyCommand.php | centreon/src/Centreon/Domain/Gorgone/Command/EmptyCommand.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\Gorgone\Command;
use Centreon\Domain\Gorgone\GorgoneService;
use Centreon\Domain\Gorgone\Interfaces\CommandInterface;
/**
* This class is designed to be injected into a Gorgone response.
*
* @see GorgoneService::getResponseFromToken()
*
* @package Centreon\Domain\Gorgone\Command
*/
class EmptyCommand extends AbstractCommand implements CommandInterface
{
private const NAME = 'basic';
/**
* @inheritDoc
*/
public function getUriRequest(): string
{
return '';
}
/**
* @inheritDoc
*/
public function getBodyRequest(): string
{
return '';
}
/**
* @inheritDoc
*/
public function getName(): string
{
return self::NAME;
}
public function getMethod(): string
{
return '';
}
}
| 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/Gorgone/Command/Thumbprint.php | centreon/src/Centreon/Domain/Gorgone/Command/Thumbprint.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\Gorgone\Command;
use Centreon\Domain\Gorgone\Interfaces\CommandInterface;
/**
* This class is designed to send thumbprint command of internal type to the Gorgone server.
*
* @package Centreon\Domain\Gorgone\Command
*/
final class Thumbprint extends AbstractCommand implements CommandInterface
{
// Internal name of this command
private const NAME = 'internal::thumbprint';
/**
* @inheritDoc
*/
public function getUriRequest(): string
{
return 'nodes/' . $this->getMonitoringInstanceId() . '/internal/thumbprint';
}
/**
* @inheritDoc
*/
public function getName(): string
{
return self::NAME;
}
public function getMethod(): string
{
return self::METHOD_GET;
}
}
| 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/Gorgone/Command/AbstractCommand.php | centreon/src/Centreon/Domain/Gorgone/Command/AbstractCommand.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\Gorgone\Command;
use Centreon\Domain\Gorgone\Interfaces\CommandInterface;
abstract class AbstractCommand
{
/** @var string token of the command assigned by the Gorgone server */
private $token;
/** @var int Poller id */
private $monitoringInstanceId;
/** @var string|null Body of the request that will be send in case of request of type POST, PUT or PATCH */
private $bodyRequest;
/**
* We create a command for a specific poller.
*
* @param int $monitoringServer Id of the monitoring server for which this command is intended
* @param string|null $bodyRequest Body of the request
*/
public function __construct(int $monitoringServer, ?string $bodyRequest = null)
{
$this->monitoringInstanceId = $monitoringServer;
$this->bodyRequest = $bodyRequest;
}
/**
* @return int
* @see CommandInterface::getMonitoringInstanceId()
*/
public function getMonitoringInstanceId(): int
{
return $this->monitoringInstanceId;
}
/**
* @return string
* @see CommandInterface::getToken()
*/
public function getToken(): string
{
return $this->token;
}
/**
* @param string $token
* @see CommandInterface::setToken()
*/
public function setToken(string $token): void
{
$this->token = $token;
}
/**
* Returns the body of the request that will be sent to the Gorgone server.
*
* @return string|null Body of the request
*/
public function getBodyRequest(): ?string
{
return $this->bodyRequest;
}
}
| 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/RequestParameters/RequestParameters.php | centreon/src/Centreon/Domain/RequestParameters/RequestParameters.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\RequestParameters;
use Centreon\Domain\RequestParameters\Interfaces\RequestParametersInterface;
/**
* @package Centreon\Domain\RequestParameters
*/
class RequestParameters implements RequestParametersInterface
{
public const NAME_FOR_LIMIT = 'limit';
public const NAME_FOR_PAGE = 'page';
public const NAME_FOR_SEARCH = 'search';
public const NAME_FOR_SORT = 'sort_by';
public const NAME_FOR_TOTAL = 'total';
public const ORDER_ASC = 'ASC';
public const ORDER_DESC = 'DESC';
public const DEFAULT_ORDER = self::ORDER_ASC;
public const DEFAULT_LIMIT = 10;
public const DEFAULT_PAGE = 1;
public const DEFAULT_SEARCH_OPERATOR = self::OPERATOR_EQUAL;
public const OPERATOR_EQUAL = '$eq';
public const OPERATOR_NOT_EQUAL = '$neq';
public const OPERATOR_LESS_THAN = '$lt';
public const OPERATOR_LESS_THAN_OR_EQUAL = '$le';
public const OPERATOR_GREATER_THAN = '$gt';
public const OPERATOR_GREATER_THAN_OR_EQUAL = '$ge';
public const OPERATOR_LIKE = '$lk';
public const OPERATOR_NOT_LIKE = '$nk';
public const OPERATOR_REGEXP = '$rg';
public const OPERATOR_IN = '$in';
public const OPERATOR_NOT_IN = '$ni';
public const LIST_SEARCH_OPERATORS = [
self::OPERATOR_EQUAL,
self::OPERATOR_NOT_EQUAL,
self::OPERATOR_LESS_THAN,
self::OPERATOR_LESS_THAN_OR_EQUAL,
self::OPERATOR_GREATER_THAN,
self::OPERATOR_GREATER_THAN_OR_EQUAL,
self::OPERATOR_LIKE,
self::OPERATOR_NOT_LIKE,
self::OPERATOR_REGEXP,
self::OPERATOR_IN,
self::OPERATOR_NOT_IN,
];
public const AGGREGATE_OPERATOR_OR = '$or';
public const AGGREGATE_OPERATOR_AND = '$and';
public const LIST_AGGREGATE_OPERATORS = [
self::AGGREGATE_OPERATOR_AND,
self::AGGREGATE_OPERATOR_OR,
];
public const CONCORDANCE_MODE_NO_STRICT = 0;
public const CONCORDANCE_MODE_STRICT = 1;
public const CONCORDANCE_ERRMODE_SILENT = 0;
public const CONCORDANCE_ERRMODE_EXCEPTION = 1;
private $authorizedOrders = [self::ORDER_ASC, self::ORDER_DESC];
private $extraParameters = [];
/**
* @var int Indicates whether we should consider only known search parameters.
* Used in the data repository classes.
*/
private $concordanceStrictMode = self::CONCORDANCE_MODE_NO_STRICT;
/** @var int indicates error behaviour when there unknown search parameters in strict mode */
private $concordanceErrorMode = self::CONCORDANCE_ERRMODE_EXCEPTION;
/** @var array Array representing fields to search for */
private $search = [];
/** @var array Field to order */
private $sort = [];
/** @var int Number of the page */
private $page = 1;
/** @var int Number of records per page */
private $limit = 10;
/** @var int Total of lines founds without limit */
private $total = 0;
/**
* @inheritDoc
*/
public function addExtraParameter(string $parameterName, $value): void
{
$this->extraParameters[$parameterName] = $value;
}
/**
* @inheritDoc
*/
public function getExtraParameter(string $parameterName)
{
if (array_key_exists($parameterName, $this->extraParameters)) {
return $this->extraParameters[$parameterName];
}
return null;
}
/**
* @inheritDoc
*/
public function getConcordanceStrictMode(): int
{
return $this->concordanceStrictMode;
}
/**
* {@inheritDoc}
* @return RequestParameters
*/
public function setConcordanceStrictMode(int $concordanceStrictMode): self
{
$this->concordanceStrictMode = $concordanceStrictMode;
return $this;
}
/**
* @inheritDoc
*/
public function getConcordanceErrorMode(): int
{
return $this->concordanceErrorMode;
}
/**
* {@inheritDoc}
* @return RequestParameters
*/
public function setConcordanceErrorMode(int $concordanceErrorMode): self
{
$this->concordanceErrorMode = $concordanceErrorMode;
return $this;
}
/**
* @inheritDoc
*/
public function hasSearchParameter(string $keyToFind, ?array $parameters = null): bool
{
foreach ($parameters ?? $this->search as $key => $value) {
if ($key === $keyToFind) {
return true;
}
if (\is_array($value) || \is_object($value)) {
$value = (array) $value;
if ($this->hasSearchParameter($keyToFind, $value)) {
return true;
}
}
}
return false;
}
/**
* @inheritDoc
*
* Return an array of search names.
* If $withValueAndOperator is true, the array will contain associative arrays as: [<operator> => <value>]
*/
public function extractSearchNames(bool $withValueAndOperator = false): array
{
$notAllowedKeys = array_merge(self::LIST_SEARCH_OPERATORS, self::LIST_AGGREGATE_OPERATORS);
$names = [];
$searchIn = function ($data) use (&$searchIn, &$names, $notAllowedKeys, $withValueAndOperator): void {
foreach ($data as $key => $value) {
if (! in_array($key, $names) && ! in_array($key, $notAllowedKeys) && ! is_int($key)) {
if ($withValueAndOperator) {
$names[$key] = $value;
} else {
$names[] = $key;
}
}
if (is_object($value) || is_array($value)) {
$searchIn((array) $value);
}
}
};
$searchIn($this->search);
return $names;
}
/**
* @inheritDoc
*/
public function toArray(): array
{
return [
self::NAME_FOR_PAGE => $this->page,
self::NAME_FOR_LIMIT => $this->limit,
self::NAME_FOR_SEARCH => $this->search !== []
? json_decode(json_encode($this->search), true)
: new \stdClass(),
self::NAME_FOR_SORT => $this->sort !== []
? json_decode(json_encode($this->sort), true)
: new \stdClass(),
self::NAME_FOR_TOTAL => $this->total,
];
}
/**
* @inheritDoc
*/
public function unsetSearchParameter(string $parameterToExtract): void
{
$parameters = $this->search;
$extractFunction = function (string $parameterToExtract, &$parameters) use (&$extractFunction): void {
foreach ($parameters as $key => &$value) {
if ($key === $parameterToExtract) {
unset($parameters[$key]);
} elseif (is_array($value) || is_object($value)) {
$value = (array) $value;
$extractFunction($parameterToExtract, $value);
}
}
};
$extractFunction($parameterToExtract, $parameters);
$this->search = $parameters;
}
/**
* @inheritDoc
*/
public function getLimit(): int
{
return $this->limit;
}
/**
* @inheritDoc
*/
public function setLimit(int $limit): void
{
$this->limit = $limit;
}
/**
* @inheritDoc
*/
public function getPage(): int
{
return $this->page;
}
/**
* @inheritDoc
*/
public function setPage(int $page): void
{
$this->page = $page;
}
/**
* @inheritDoc
*/
public function getSearch(): array
{
return $this->search;
}
/**
* @inheritDoc
*/
public function getSearchAsString(): string
{
return (string) json_encode($this->search);
}
/**
* @inheritDoc
*/
public function setSearch(string $search): void
{
$search = json_decode($search ?: '{}', true);
$this->search = (array) $search;
$this->fixSchema();
}
/**
* @inheritDoc
* @return array<mixed>
*/
public function getSort(): array
{
return $this->sort;
}
/**
* @inheritDoc
*/
public function setSort(string $sortRequest): void
{
$sortRequestToAnalyze = json_decode($sortRequest ?: self::DEFAULT_SEARCH_OPERATOR, true);
if (! is_array($sortRequestToAnalyze)) {
if (! empty($sortRequest) && $sortRequest[0] != '{') {
$this->sort = [$sortRequest => self::DEFAULT_ORDER];
} else {
throw new \RestBadRequestException('Bad format for the sort request parameter');
}
} else {
foreach ($sortRequestToAnalyze as $name => $order) {
$isMatched = preg_match(
'/^([a-zA-Z0-9_.-]*)$/i',
$name,
$sortFound,
PREG_OFFSET_CAPTURE
);
if (! $isMatched || ! in_array(strtoupper($order), $this->authorizedOrders)) {
unset($sortRequestToAnalyze[$name]);
} else {
$sortRequestToAnalyze[$name] = strtoupper($order);
}
}
$this->sort = $sortRequestToAnalyze;
}
}
/**
* @inheritDoc
*/
public function getTotal(): int
{
return $this->total;
}
/**
* @inheritDoc
*/
public function setTotal(int $total): void
{
$this->total = $total;
}
/**
* @inheritDoc
*/
public function unsetSearch(): void
{
$this->search = [];
}
/**
* Try to fix the schema in case of bad structure
*
* @throws \Exception
*/
private function fixSchema(): void
{
$search = $this->search;
if (! empty($search)) {
if (
(
! isset($search[RequestParameters::AGGREGATE_OPERATOR_AND])
&& ! isset($search[RequestParameters::AGGREGATE_OPERATOR_OR])
)
|| (count($this->search) > 1)
) {
$newSearch[RequestParameters::AGGREGATE_OPERATOR_AND] = $search;
$this->search = $newSearch;
}
}
}
}
| 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/RequestParameters/RequestParametersException.php | centreon/src/Centreon/Domain/RequestParameters/RequestParametersException.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\RequestParameters;
/**
* This class is designed to contain all exceptions for the context of the request parameters.
*
* @package Centreon\Domain\RequestParameters
*/
class RequestParametersException extends \InvalidArgumentException
{
/**
* @param string $parameterName
* @return RequestParametersException
*/
public static function integer(string $parameterName): self
{
return new self(sprintf(_('The parameter "%s" must be an integer'), $parameterName));
}
}
| 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/RequestParameters/Interfaces/RequestParametersInterface.php | centreon/src/Centreon/Domain/RequestParameters/Interfaces/RequestParametersInterface.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\RequestParameters\Interfaces;
use Centreon\Domain\RequestParameters\RequestParameters;
/**
* @package Centreon\Domain\RequestParameters\Interfaces
*/
interface RequestParametersInterface
{
/**
* Converts search array to string
*
* @return string
*/
public function getSearchAsString(): string;
/**
* Add an extra parameter.
*
* @param string $parameterName Parameter name
* @param mixed $value Parameter value
*/
public function addExtraParameter(string $parameterName, $value): void;
/**
* Check if a search parameter exists.
*
* @param string $keyToFind Name of the search parameter
* @param null|array $parameters List of parameters
* @return bool Returns true if the parameter exists
*/
public function hasSearchParameter(string $keyToFind, ?array $parameters = null): bool;
/**
* @return int
*/
public function getConcordanceStrictMode(): int;
/**
* @param int $concordanceStrictMode
*/
public function setConcordanceStrictMode(int $concordanceStrictMode);
/**
* @return int
*/
public function getConcordanceErrorMode(): int;
/**
* Set error mode (exception or silent)
* @param int $concordanceErrorMode
*/
public function setConcordanceErrorMode(int $concordanceErrorMode);
/**
* Returns the value of the extra parameter.
*
* @param string $parameterName Parameter name
* @return mixed Returns the value or null
*/
public function getExtraParameter(string $parameterName);
/**
* @see Pagination::$limit
* @return int
*/
public function getLimit(): int;
/**
* @see RequestParameters::$page
* @return int
*/
public function getPage(): int;
/**
* @return array
*/
public function getSearch(): array;
/**
* @return array
*/
public function getSort(): array;
/**
* @return int
*/
public function getTotal(): int;
/**
* @param int $limit Number of records per page
*/
public function setLimit(int $limit): void;
/**
* @param int $page Number of the page
*/
public function setPage(int $page): void;
/**
* @param string $search
* @throws \Exception
*/
public function setSearch(string $search): void;
/**
* @param string $sortRequest
* @throws \Exception
*/
public function setSort(string $sortRequest): void;
/**
* @param int $total
*/
public function setTotal(int $total): void;
/**
* Converts this requestParameter instance into an array allowing its
* encoding in JSON format.
*
* @return array ['sort_by' => ..., 'limit' => ..., 'total' => ..., ...]
*/
public function toArray(): array;
/**
* Re-initialize the search set previously
*
* @return void
*/
public function unsetSearch(): void;
/**
* Remove a search parameter.
*
* @param string $parameterToExtract Parameter to remove
* @throws \Exception
*/
public function unsetSearchParameter(string $parameterToExtract);
/**
* @param bool $withValueAndOperator
*
* @return array
*/
public function extractSearchNames(bool $withValueAndOperator = false): 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/AccessControlList/Interfaces/AccessControlListRepositoryInterface.php | centreon/src/Centreon/Domain/AccessControlList/Interfaces/AccessControlListRepositoryInterface.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\AccessControlList\Interfaces;
use Centreon\Domain\Contact\Interfaces\ContactInterface;
use Core\Security\AccessGroup\Domain\Model\AccessGroup;
interface AccessControlListRepositoryInterface
{
/**
* @param ContactInterface $contact
* @return $this
*/
public function setContact(ContactInterface $contact);
/**
* Sets the access groups that will be used to filter services and the host.
*
* @param AccessGroup[] $accessGroups
* @return $this
*/
public function filterByAccessGroups(array $accessGroups);
}
| 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/Engine/EngineConfiguration.php | centreon/src/Centreon/Domain/Engine/EngineConfiguration.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\Engine;
use Centreon\Domain\Common\Assertion\Assertion;
class EngineConfiguration
{
public const NOTIFICATIONS_OPTION_DISABLED = 0;
public const NOTIFICATIONS_OPTION_ENABLED = 1;
public const NOTIFICATIONS_OPTION_DEFAULT = 2;
private const AVAILABLE_NOTIFICATION_OPTIONS = [
self::NOTIFICATIONS_OPTION_DISABLED,
self::NOTIFICATIONS_OPTION_ENABLED,
self::NOTIFICATIONS_OPTION_DEFAULT,
];
/** @var int|null */
private $id;
/** @var string|null Illegal object name characters */
private $illegalObjectNameCharacters;
/** @var int|null Monitoring server id */
private $monitoringServerId;
/** @var string|null Engine configuration name */
private $name;
/** @var int */
private $notificationsEnabledOption = self::NOTIFICATIONS_OPTION_ENABLED;
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @param int|null $id
* @return EngineConfiguration
*/
public function setId(?int $id): EngineConfiguration
{
$this->id = $id;
return $this;
}
/**
* @return string|null
*/
public function getIllegalObjectNameCharacters(): ?string
{
return $this->illegalObjectNameCharacters;
}
/**
* @param string|null $illegalObjectNameCharacters
* @return EngineConfiguration
*/
public function setIllegalObjectNameCharacters(?string $illegalObjectNameCharacters): EngineConfiguration
{
$this->illegalObjectNameCharacters = $illegalObjectNameCharacters;
return $this;
}
/**
* @return int|null
*/
public function getMonitoringServerId(): ?int
{
return $this->monitoringServerId;
}
/**
* @param int|null $monitoringServerId
* @return EngineConfiguration
*/
public function setMonitoringServerId(?int $monitoringServerId): EngineConfiguration
{
$this->monitoringServerId = $monitoringServerId;
return $this;
}
/**
* @return string|null
*/
public function getName(): ?string
{
return $this->name;
}
/**
* @param string|null $name
* @return EngineConfiguration
*/
public function setName(?string $name): EngineConfiguration
{
$this->name = $name;
return $this;
}
/**
* Remove all illegal characters from the given string.
*
* @param string $stringToAnalyse String for which we want to remove illegal characters
* @return string Return the string without illegal characters
*/
public function removeIllegalCharacters(string $stringToAnalyse): string
{
if ($this->illegalObjectNameCharacters === null || $this->illegalObjectNameCharacters === '') {
return $stringToAnalyse;
}
return str_replace(str_split($this->illegalObjectNameCharacters), '', $stringToAnalyse);
}
/**
* Find if the given string has an illegal character in it.
*
* @param string $stringToCheck String to analyse
* @return bool Return true if illegal characters have been found
*/
public function hasIllegalCharacters(string $stringToCheck): bool
{
return $stringToCheck !== $this->removeIllegalCharacters($stringToCheck);
}
/**
* @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/Engine/EngineService.php | centreon/src/Centreon/Domain/Engine/EngineService.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\Engine;
use Centreon\Domain\Acknowledgement\Acknowledgement;
use Centreon\Domain\Check\Check;
use Centreon\Domain\Common\Assertion\Assertion;
use Centreon\Domain\Downtime\Downtime;
use Centreon\Domain\Downtime\DowntimeService;
use Centreon\Domain\Engine\Exception\EngineConfigurationException;
use Centreon\Domain\Engine\Interfaces\EngineConfigurationRepositoryInterface;
use Centreon\Domain\Engine\Interfaces\EngineConfigurationServiceInterface;
use Centreon\Domain\Engine\Interfaces\EngineRepositoryInterface;
use Centreon\Domain\Engine\Interfaces\EngineServiceInterface;
use Centreon\Domain\Entity\EntityValidator;
use Centreon\Domain\Monitoring\Comment\Comment;
use Centreon\Domain\Monitoring\Comment\CommentService;
use Centreon\Domain\Monitoring\Host;
use Centreon\Domain\Monitoring\Service;
use Centreon\Domain\Monitoring\SubmitResult\SubmitResult;
use Centreon\Domain\Monitoring\SubmitResult\SubmitResultService;
use Centreon\Domain\MonitoringServer\MonitoringServer;
use Centreon\Domain\Service\AbstractCentreonService;
use JMS\Serializer\Exception\ValidationFailedException;
/**
* This class is designed to send external command for Engine
*
* @package Centreon\Domain\Engine
* @todo Replace the ValidationFailedException with a domain exception to avoid depending on the framework
*/
class EngineService extends AbstractCentreonService implements
EngineServiceInterface,
EngineConfigurationServiceInterface
{
private const ACKNOWLEDGEMENT_WITH_STICKY_OPTION = 2;
private const ACKNOWLEDGEMENT_WITH_NO_STICKY_OPTION = 0;
/** @var EngineRepositoryInterface */
private $engineRepository;
/** @var EntityValidator */
private $validator;
/** @var EngineConfigurationRepositoryInterface */
private $engineConfigurationRepository;
/**
* CentCoreService constructor.
*
* @param EngineRepositoryInterface $engineRepository
* @param EngineConfigurationRepositoryInterface $engineConfigurationRepository
* @param EntityValidator $validator
*/
public function __construct(
EngineRepositoryInterface $engineRepository,
EngineConfigurationRepositoryInterface $engineConfigurationRepository,
EntityValidator $validator,
) {
$this->engineRepository = $engineRepository;
$this->validator = $validator;
$this->engineConfigurationRepository = $engineConfigurationRepository;
}
/**
* @inheritDoc
*/
public function addHostAcknowledgement(Acknowledgement $acknowledgement, Host $host): void
{
if (empty($this->contact->getAlias())) {
throw new EngineException('The contact alias is empty');
}
if (empty($host->getName())) {
throw new EngineException('Host name can not be empty');
}
/**
* Specificity of the engine.
* We do consider that an acknowledgement is sticky when value 2 is sent.
* 0 or 1 is considered as a normal acknowledgement.
*/
$preCommand = sprintf(
'ACKNOWLEDGE_HOST_PROBLEM;%s;%d;%d;%d;%s;%s',
$host->getName(),
$acknowledgement->isSticky()
? self::ACKNOWLEDGEMENT_WITH_STICKY_OPTION
: self::ACKNOWLEDGEMENT_WITH_NO_STICKY_OPTION,
(int) $acknowledgement->isNotifyContacts(),
(int) $acknowledgement->isPersistentComment(),
$this->contact->getAlias(),
$acknowledgement->getComment()
);
$commandToSend = str_replace(['"', "\n"], ['', '<br/>'], $preCommand);
$commandFull = $this->createCommandHeader($host->getPollerId()) . $commandToSend;
$this->engineRepository->sendExternalCommand($commandFull);
}
/**
* @inheritDoc
*/
public function addServiceAcknowledgement(Acknowledgement $acknowledgement, Service $service): void
{
if (empty($this->contact->getAlias())) {
throw new EngineException('The contact alias is empty');
}
if (empty($service->getHost())) {
throw new EngineException('The host of service is not defined');
}
/**
* Specificity of the engine.
* We do consider that an acknowledgement is sticky when value 2 is sent.
* 0 or 1 is considered as a normal acknowledgement.
*/
$preCommand = sprintf(
'ACKNOWLEDGE_SVC_PROBLEM;%s;%s;%d;%d;%d;%s;%s',
$service->getHost()->getName(),
$service->getDescription(),
$acknowledgement->isSticky()
? self::ACKNOWLEDGEMENT_WITH_STICKY_OPTION
: self::ACKNOWLEDGEMENT_WITH_NO_STICKY_OPTION,
(int) $acknowledgement->isNotifyContacts(),
(int) $acknowledgement->isPersistentComment(),
$this->contact->getAlias(),
$acknowledgement->getComment()
);
$commandToSend = str_replace(['"', "\n"], ['', '<br/>'], $preCommand);
$commandFull = $this->createCommandHeader($service->getHost()->getPollerId()) . $commandToSend;
$this->engineRepository->sendExternalCommand($commandFull);
}
/**
* @inheritDoc
*/
public function disacknowledgeHost(Host $host): void
{
if (empty($host->getName())) {
throw new EngineException('Host name can not be empty');
}
$preCommand = sprintf(
'REMOVE_HOST_ACKNOWLEDGEMENT;%s',
$host->getName()
);
$commandToSend = str_replace(['"', "\n"], ['', '<br/>'], $preCommand);
$commandFull = $this->createCommandHeader($host->getPollerId()) . $commandToSend;
$this->engineRepository->sendExternalCommand($commandFull);
}
/**
* @inheritDoc
*/
public function disacknowledgeService(Service $service): void
{
if (empty($service->getHost()) || empty($service->getHost()->getName())) {
throw new EngineException('The host of service is not defined');
}
$preCommand = sprintf(
'REMOVE_SVC_ACKNOWLEDGEMENT;%s;%s',
$service->getHost()->getName(),
$service->getDescription()
);
$commandToSend = str_replace(['"', "\n"], ['', '<br/>'], $preCommand);
$commandFull = $this->createCommandHeader($service->getHost()->getPollerId()) . $commandToSend;
$this->engineRepository->sendExternalCommand($commandFull);
}
/**
* @inheritDoc
*/
public function addHostDowntime(Downtime $downtime, Host $host): void
{
if (empty($this->contact->getAlias())) {
throw new EngineException(_('The contact alias is empty'));
}
if (empty($host->getName())) {
throw new EngineException(_('Host name can not be empty'));
}
if ($this->validator->hasValidatorFor(Downtime::class)) {
// We validate the downtime instance
$errors = $this->validator->getValidator()->validate(
$downtime,
null,
DowntimeService::VALIDATION_GROUPS_ADD_HOST_DOWNTIME
);
if ($errors->count() > 0) {
throw new ValidationFailedException($errors);
}
}
$commandNames = ['SCHEDULE_HOST_DOWNTIME'];
if ($downtime->isWithServices()) {
$commandNames[] = 'SCHEDULE_HOST_SVC_DOWNTIME';
}
$commands = [];
foreach ($commandNames as $commandName) {
$preCommand = sprintf(
'%s;%s;%d;%d;%d;0;%d;%s;%s',
$commandName,
$host->getName(),
$downtime->getStartTime()->getTimestamp(),
$downtime->getEndTime()->getTimestamp(),
(int) $downtime->isFixed(),
$downtime->getDuration(),
$this->contact->getAlias(),
$downtime->getComment()
);
$commandToSend = str_replace(['"', "\n"], ['', '<br/>'], $preCommand);
$commands[] = $this->createCommandHeader($host->getPollerId()) . $commandToSend;
}
$this->engineRepository->sendExternalCommands($commands);
}
/**
* @inheritDoc
*/
public function addServiceDowntime(Downtime $downtime, Service $service): void
{
if (empty($this->contact->getAlias())) {
throw new EngineException(_('The contact alias is empty'));
}
if ($this->validator->hasValidatorFor(Downtime::class)) {
// We validate the downtime instance
$errors = $this->validator->getValidator()->validate(
$downtime,
null,
DowntimeService::VALIDATION_GROUPS_ADD_SERVICE_DOWNTIME
);
if ($errors->count() > 0) {
throw new ValidationFailedException($errors);
}
}
if ($service->getHost() == null) {
throw new EngineException(
sprintf(_('The host of service (id: %d) is not defined'), $service->getId())
);
}
if (empty($service->getHost()->getName())) {
throw new EngineException(
sprintf(_('Host name of service (id: %d) can not be empty'), $service->getId())
);
}
if (empty($service->getDescription())) {
throw new EngineException(
sprintf(_('The description of service (id: %d) can not be empty'), $service->getId())
);
}
$preCommand = sprintf(
'SCHEDULE_SVC_DOWNTIME;%s;%s;%d;%d;%d;0;%d;%s;%s',
$service->getHost()->getName(),
$service->getDescription(),
$downtime->getStartTime()->getTimestamp(),
$downtime->getEndTime()->getTimestamp(),
(int) $downtime->isFixed(),
$downtime->getDuration(),
$this->contact->getAlias(),
$downtime->getComment()
);
$commandToSend = str_replace(['"', "\n"], ['', '<br/>'], $preCommand);
$command = $this->createCommandHeader($service->getHost()->getPollerId()) . $commandToSend;
$this->engineRepository->sendExternalCommand($command);
}
/**
* @inheritDoc
*/
public function findEngineConfigurationByMonitoringServer(MonitoringServer $monitoringServer): ?EngineConfiguration
{
try {
Assertion::notNull($monitoringServer->getId(), 'MonitoringServer::id');
return $this->engineConfigurationRepository->findEngineConfigurationByMonitoringServerId(
$monitoringServer->getId()
);
} catch (\Throwable $ex) {
throw EngineConfigurationException::findEngineConfigurationException(
$ex,
['id' => $monitoringServer->getId()]
);
}
}
/**
* @inheritDoc
*/
public function findCentralEngineConfiguration(): ?EngineConfiguration
{
try {
return $this->engineConfigurationRepository->findCentralEngineConfiguration();
} catch (\Throwable $ex) {
throw new EngineException(
_('Error when searching for the central engine configuration'),
0,
$ex
);
}
}
/**
* @inheritDoc
*/
public function findEngineConfigurationByHost(\Centreon\Domain\HostConfiguration\Host $host): ?EngineConfiguration
{
if ($host->getId() === null) {
throw new EngineException(_('The host id cannot be null'));
}
try {
return $this->engineConfigurationRepository->findEngineConfigurationByHost($host);
} catch (\Throwable $ex) {
throw new EngineException(
sprintf(_('Error when searching for the Engine configuration (%s)'), $host->getId()),
0,
$ex
);
}
}
/**
* @inheritDoc
*/
public function findEngineConfigurationByName(string $engineName): ?EngineConfiguration
{
try {
return $this->engineConfigurationRepository->findEngineConfigurationByName($engineName);
} catch (\Throwable $ex) {
throw new EngineException(
sprintf(_('Error when searching for the Engine configuration (%s)'), $engineName),
0,
$ex
);
}
}
/**
* @inheritDoc
*/
public function scheduleImmediateForcedServiceCheck(Service $service): void
{
if (empty($service->getHost()->getName())) {
throw new EngineException(_('Host name cannot be empty'));
}
if (empty($service->getDescription())) {
throw new EngineException(_('Service description cannot be empty'));
}
$command = sprintf(
'SCHEDULE_FORCED_SVC_CHECK;%s;%s;%d',
$service->getHost()->getName(),
$service->getDescription(),
(new \DateTime())->getTimestamp()
);
$commandFull = $this->createCommandHeader($service->getHost()->getPollerId()) . $command;
$this->engineRepository->sendExternalCommand($commandFull);
}
/**
* @inheritDoc
*/
public function scheduleForcedHostCheck(Host $host): void
{
if (empty($host->getName())) {
throw new EngineException(_('Host name can not be empty'));
}
$preCommand = sprintf(
'SCHEDULE_FORCED_HOST_CHECK;%s;%d',
$host->getName(),
(new \DateTime())->getTimestamp()
);
$commandToSend = str_replace(['"', "\n"], ['', '<br/>'], $preCommand);
$commandFull = $this->createCommandHeader($host->getPollerId()) . $commandToSend;
$this->engineRepository->sendExternalCommand($commandFull);
}
/**
* @inheritDoc
*/
public function cancelDowntime(Downtime $downtime, Host $host): void
{
if ($downtime->getServiceId() === null && $downtime->getHostId() === null) {
throw new EngineException(_('Host and service id can not be null at the same time'));
}
if ($downtime->getInternalId() === null) {
throw new EngineException(_('Downtime internal id can not be null'));
}
$suffix = (empty($downtime->getServiceId())) ? 'HOST' : 'SVC';
$preCommand = sprintf('DEL_%s_DOWNTIME;%d', $suffix, $downtime->getInternalId());
$commandToSend = str_replace(['"', "\n"], ['', '<br/>'], $preCommand);
$commandFull = $this->createCommandHeader($host->getPollerId()) . $commandToSend;
$this->engineRepository->sendExternalCommand($commandFull);
}
/**
* @inheritDoc
*/
public function scheduleHostCheck(Check $check, Host $host): 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);
}
if (empty($host->getName())) {
throw new EngineException(_('Host name can not be empty'));
}
$commandNames = [$check->isForced() ? 'SCHEDULE_FORCED_HOST_CHECK' : 'SCHEDULE_HOST_CHECK'];
if ($check->isWithServices()) {
$commandNames[] = $check->isForced() ? 'SCHEDULE_FORCED_HOST_SVC_CHECKS' : 'SCHEDULE_HOST_SVC_CHECKS';
}
$commands = [];
foreach ($commandNames as $commandName) {
$preCommand = sprintf(
'%s;%s;%d',
$commandName,
$host->getName(),
$check->getCheckTime()->getTimestamp()
);
$commandToSend = str_replace(['"', "\n"], ['', '<br/>'], $preCommand);
$commands[] = $this->createCommandHeader($host->getPollerId()) . $commandToSend;
}
$this->engineRepository->sendExternalCommands($commands);
}
/**
* @inheritDoc
*/
public function scheduleServiceCheck(Check $check, Service $service): 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);
}
if (empty($service->getHost()->getName())) {
throw new EngineException(_('Host name cannot be empty'));
}
if (empty($service->getDescription())) {
throw new EngineException(_('Service description cannot be empty'));
}
$commandName = $check->isForced() ? 'SCHEDULE_FORCED_SVC_CHECK' : 'SCHEDULE_SVC_CHECK';
$command = sprintf(
'%s;%s;%s;%d',
$commandName,
$service->getHost()->getName(),
$service->getDescription(),
$check->getCheckTime()->getTimestamp()
);
$commandFull = $this->createCommandHeader($service->getHost()->getPollerId()) . $command;
$this->engineRepository->sendExternalCommand($commandFull);
}
/**
* @inheritDoc
*/
public function submitHostResult(SubmitResult $result, Host $host): void
{
// We validate the SubmitResult instance (replace by the Validation of CHECK RESULT)
$errors = $this->validator->validate(
$result,
null,
SubmitResultService::VALIDATION_GROUPS_HOST_SUBMIT_RESULT
);
if ($errors->count() > 0) {
throw new ValidationFailedException($errors);
}
if (empty($host->getName())) {
throw new EngineException(_('Host name can not be empty'));
}
$commandName = 'PROCESS_HOST_CHECK_RESULT';
$command = sprintf(
'%s;%s;%d;%s|%s',
$commandName,
$host->getName(),
$result->getStatus(),
$result->getOutput(),
$result->getPerformanceData()
);
$commandFull = $this->createCommandHeader($host->getPollerId()) . $command;
$this->engineRepository->sendExternalCommand($commandFull);
}
/**
* @inheritDoc
*/
public function submitServiceResult(SubmitResult $result, Service $service): void
{
// We validate the check instance (replace by the Validation of CHECK RESULT)
$errors = $this->validator->validate(
$result,
null,
SubmitResultService::VALIDATION_GROUPS_SERVICE_SUBMIT_RESULT
);
if ($errors->count() > 0) {
throw new ValidationFailedException($errors);
}
if (empty($service->getHost()->getName())) {
throw new EngineException(_('Host name cannot be empty'));
}
if (empty($service->getDescription())) {
throw new EngineException(_('Service description cannot be empty'));
}
$commandName = 'PROCESS_SERVICE_CHECK_RESULT';
$command = sprintf(
'%s;%s;%s;%d;%s|%s',
$commandName,
$service->getHost()->getName(),
$service->getDescription(),
$result->getStatus(),
$result->getOutput(),
$result->getPerformanceData()
);
$commandFull = $this->createCommandHeader($service->getHost()->getPollerId()) . $command;
$this->engineRepository->sendExternalCommand($commandFull);
}
/**
* @inheritDoc
*/
public function addServiceComment(Comment $comment, Service $service): void
{
// We validate the comment instance
$errors = $this->validator->validate(
$comment,
null,
CommentService::VALIDATION_GROUPS_SERVICE_ADD_COMMENT
);
if ($errors->count() > 0) {
throw new ValidationFailedException($errors);
}
if (empty($this->contact->getAlias())) {
throw new EngineException(_('The contact alias is empty'));
}
if ($service->getHost() == null) {
throw new EngineException(
sprintf(_('The host of service (id: %d) is not defined'), $service->getId())
);
}
if (empty($service->getHost()->getName())) {
throw new EngineException(
sprintf(_('Host name of service (id: %d) can not be empty'), $service->getId())
);
}
if (empty($service->getDescription())) {
throw new EngineException(
sprintf(_('The description of service (id: %d) can not be empty'), $service->getId())
);
}
$preCommand = sprintf(
'ADD_SVC_COMMENT;%s;%s;1;%s;%s',
$service->getHost()->getName(),
$service->getDescription(),
$this->contact->getAlias(),
$comment->getComment()
);
$commandToSend = str_replace(['"', "\n"], ['', '<br/>'], $preCommand);
$command = $this->createCommandHeader($service->getHost()->getPollerId(), $comment->getDate()) . $commandToSend;
$this->engineRepository->sendExternalCommand($command);
}
/**
* @inheritDoc
*/
public function addHostComment(Comment $comment, Host $host): void
{
// We validate the comment instance
$errors = $this->validator->validate(
$comment,
null,
CommentService::VALIDATION_GROUPS_HOST_ADD_COMMENT
);
if ($errors->count() > 0) {
throw new ValidationFailedException($errors);
}
if (empty($this->contact->getAlias())) {
throw new EngineException(_('The contact alias is empty'));
}
if (empty($host->getName())) {
throw new EngineException(
sprintf(_('Host name can not be empty for host (id: %d)'), $host->getId())
);
}
$preCommand = sprintf(
'ADD_HOST_COMMENT;%s;1;%s;%s',
$host->getName(),
$this->contact->getAlias(),
$comment->getComment()
);
$commandToSend = str_replace(['"', "\n"], ['', '<br/>'], $preCommand);
$command = $this->createCommandHeader($host->getPollerId(), $comment->getDate()) . $commandToSend;
$this->engineRepository->sendExternalCommand($command);
}
/**
* Create the command header for external commands
*
* @param int $pollerId Id of the poller
* @param \DateTime|null $date date of the command
* @throws \Exception
* @return string Returns the new generated command header
*/
private function createCommandHeader(int $pollerId, ?\DateTime $date = null): string
{
return sprintf(
'%s:%d:[%d] ',
'EXTERNALCMD',
$pollerId,
$date ? $date->getTimestamp() : (new \DateTime())->getTimestamp()
);
}
}
| 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/Engine/EngineException.php | centreon/src/Centreon/Domain/Engine/EngineException.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\Engine;
class EngineException 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/Engine/Interfaces/EngineRepositoryInterface.php | centreon/src/Centreon/Domain/Engine/Interfaces/EngineRepositoryInterface.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\Engine\Interfaces;
use Centreon\Domain\Engine\EngineException;
interface EngineRepositoryInterface
{
/**
* Adds a command
*
* @param string $command Command to send
* @throws EngineException
*/
public function sendExternalCommand(string $command): void;
/**
* Adds commands
*
* @param string[] $commands List of commands to send
* @throws EngineException
*/
public function sendExternalCommands(array $commands): 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/Engine/Interfaces/EngineServiceInterface.php | centreon/src/Centreon/Domain/Engine/Interfaces/EngineServiceInterface.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\Engine\Interfaces;
use Centreon\Domain\Acknowledgement\Acknowledgement;
use Centreon\Domain\Check\Check;
use Centreon\Domain\Contact\Interfaces\ContactFilterInterface;
use Centreon\Domain\Downtime\Downtime;
use Centreon\Domain\Engine\EngineException;
use Centreon\Domain\Monitoring\Comment\Comment;
use Centreon\Domain\Monitoring\Host;
use Centreon\Domain\Monitoring\Service;
use Centreon\Domain\Monitoring\SubmitResult\SubmitResult;
use JMS\Serializer\Exception\ValidationFailedException;
interface EngineServiceInterface extends ContactFilterInterface
{
/**
* Acknowledge a host.
*
* @param Acknowledgement $acknowledgement Acknowledgement to add
* @param Host $host Host linked to the acknowledgement
* @throws EngineException
* @throws \Exception
* @throws ValidationFailedException
*/
public function addHostAcknowledgement(Acknowledgement $acknowledgement, Host $host);
/**
* Acknowledge a service.
*
* @param Acknowledgement $acknowledgement Acknowledgement to add
* @param Service $service Service linked to the acknowledgement
* @throws EngineException
* @throws \Exception
* @throws ValidationFailedException
*/
public function addServiceAcknowledgement(Acknowledgement $acknowledgement, Service $service);
/**
* Schedules a forced host check.
*
* @param Host $host Host for which we want to schedule a forced check
* @throws EngineException
* @throws \Exception
*/
public function scheduleForcedHostCheck(Host $host): void;
/**
* Schedules an immediate force check for a Service.
*
* @param Service $service
* @throws EngineException
* @throws \Exception
*/
public function scheduleImmediateForcedServiceCheck(Service $service): void;
/**
* Disacknowledge a host.
*
* @param Host $host Host to disacknowledge
* @throws EngineException
* @throws \Exception
*/
public function disacknowledgeHost(Host $host): void;
/**
* Disacknowledge a service.
*
* @param Service $service Service to disacknowledge
* @throws EngineException
* @throws \Exception
*/
public function disacknowledgeService(Service $service): void;
/**
* Add a downtime on multiple hosts.
*
* @param Downtime $downtime Downtime to add on the host
* @param Host $host Host for which we want to add the downtime
* @throws \Exception
*/
public function addHostDowntime(Downtime $downtime, Host $host): void;
/**
* Add a downtime on multiple services.
*
* @param Downtime $downtime Downtime to add
* @param Service $service Service for which we want to add a downtime
* @throws \Exception
*/
public function addServiceDowntime(Downtime $downtime, Service $service): void;
/**
* Cancel a downtime.
*
* @param Downtime $downtime Downtime to cancel
* @param Host $host Downtime-related host
* @throws \Exception
*/
public function cancelDowntime(Downtime $downtime, Host $host): void;
/**
* Schedule a host check.
*
* @param Check $check Check to schedule
* @param Host $host Host on which check is scheduled
* @throws \Exception
*/
public function scheduleHostCheck(Check $check, Host $host): void;
/**
* Schedule a service check.
*
* @param Check $check Check to schedule
* @param Service $service Service on which check is scheduled
* @throws \Exception
*/
public function scheduleServiceCheck(Check $check, Service $service): void;
/**
* Submit a result to a host.
*
* @param SubmitResult $result Result to submit
* @param Host $host Host on which to submit the result
* @throws \Exception
*/
public function submitHostResult(SubmitResult $result, Host $host): void;
/**
* Submit a result to a service.
*
* @param SubmitResult $result Result to submit
* @param Service $service Service on which to submit the result
* @throws \Exception
*/
public function submitServiceResult(SubmitResult $result, Service $service): void;
/**
* Add a comment to a monitored service
*
* @param Comment $comment
* @param Service $service
* @throws \Exception
*/
public function addServiceComment(Comment $comment, Service $service): void;
/**
* Add a comment to a monitored host
*
* @param Comment $comment
* @param Host $host
* @throws \Exception
*/
public function addHostComment(Comment $comment, 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/Engine/Interfaces/EngineConfigurationRepositoryInterface.php | centreon/src/Centreon/Domain/Engine/Interfaces/EngineConfigurationRepositoryInterface.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\Engine\Interfaces;
use Centreon\Domain\Engine\EngineConfiguration;
use Centreon\Domain\HostConfiguration\Host;
interface EngineConfigurationRepositoryInterface
{
/**
* Find the Engine configuration associated to the central poller.
*
* @return EngineConfiguration|null
*/
public function findCentralEngineConfiguration(): ?EngineConfiguration;
/**
* Find the Engine configuration associated to a host.
*
* @param Host $host Host for which we want to find the Engine configuration
* @return EngineConfiguration|null
*/
public function findEngineConfigurationByHost(Host $host): ?EngineConfiguration;
/**
* Find the Engine configuration based on the monitoring server id.
*
* @param int $monitoringServerId
* @throws \Throwable
* @return EngineConfiguration|null
*/
public function findEngineConfigurationByMonitoringServerId(int $monitoringServerId): ?EngineConfiguration;
/**
* Find the Engine configuration by its name.
*
* @param string $engineName Name of Engine configuration
* @return EngineConfiguration|null
*/
public function findEngineConfigurationByName(string $engineName): ?EngineConfiguration;
}
| 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/Engine/Interfaces/EngineConfigurationServiceInterface.php | centreon/src/Centreon/Domain/Engine/Interfaces/EngineConfigurationServiceInterface.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\Engine\Interfaces;
use Centreon\Domain\Engine\EngineConfiguration;
use Centreon\Domain\Engine\EngineException;
use Centreon\Domain\Engine\Exception\EngineConfigurationException;
use Centreon\Domain\HostConfiguration\Host;
use Centreon\Domain\MonitoringServer\MonitoringServer;
interface EngineConfigurationServiceInterface
{
/**
* Find the Engine configuration associated to the central poller.
*
* @throws EngineException
* @return EngineConfiguration|null
*/
public function findCentralEngineConfiguration(): ?EngineConfiguration;
/**
* Find the Engine configuration associated to a host.
*
* @param Host $host Host for which we want to find the Engine configuration
* @throws EngineException
* @return EngineConfiguration|null
*/
public function findEngineConfigurationByHost(Host $host): ?EngineConfiguration;
/**
* Find the Engine configuration linked to a monitoring server.
*
* @param MonitoringServer $monitoringServer
* @throws EngineConfigurationException
* @return EngineConfiguration|null
*/
public function findEngineConfigurationByMonitoringServer(MonitoringServer $monitoringServer): ?EngineConfiguration;
/**
* Find the Engine configuration by its name.
*
* @param string $engineName Name of Engine configuration
* @throws EngineException
* @return EngineConfiguration|null
*/
public function findEngineConfigurationByName(string $engineName): ?EngineConfiguration;
}
| 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/Engine/Exception/EngineConfigurationException.php | centreon/src/Centreon/Domain/Engine/Exception/EngineConfigurationException.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\Engine\Exception;
/**
* This class is designed to contain all exceptions for the Engine context.
*
* @package Centreon\Domain\Engine\Exception
*/
class EngineConfigurationException extends \Exception
{
/**
* @param \Throwable $ex
* @param array<string, mixed> $data
* @return self
*/
public static function findEngineConfigurationException(\Throwable $ex, array $data = []): self
{
return new self(
sprintf(_('Error when searching for the engine configuration (%s)'), $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/Repository/TopologyRepository.php | centreon/src/Centreon/Domain/Repository/TopologyRepository.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
*
*/
namespace Centreon\Domain\Repository;
use Centreon\Domain\Entity\Topology;
use Centreon\Infrastructure\CentreonLegacyDB\ServiceEntityRepository;
use Centreon\Infrastructure\CentreonLegacyDB\StatementCollector;
use CentreonUser;
use PDO;
class TopologyRepository extends ServiceEntityRepository
{
private const ACL_ACCESS_NONE = 0;
private const ACL_ACCESS_READ_WRITE = 1;
private const ACL_ACCESS_READ_ONLY = 2;
/**
* Disable Menus for a Master-to-Remote transition
*
* @return bool
*/
public function disableMenus(): bool
{
$sql = file_get_contents(__DIR__ . '/../../Infrastructure/Resources/sql/disablemenus.sql');
$stmt = $this->db->prepare($sql);
return $stmt->execute();
}
/**
* Enable Menus for a Remote-to-Master transition
*
* @return bool
*/
public function enableMenus(): bool
{
$sql = file_get_contents(__DIR__ . '/../../Infrastructure/Resources/sql/enablemenus.sql');
$stmt = $this->db->prepare($sql);
return $stmt->execute();
}
/**
* Get Topologies according to ACL for user
* @todo refactor this into function below it
* @param mixed $user
* @return mixed[]
*/
public function getReactTopologiesPerUserWithAcl($user)
{
if (empty($user)) {
return [];
}
$topologyUrls = [];
if ($user->admin) {
$sql = "SELECT topology_url FROM `topology` WHERE is_react = '1'";
$stmt = $this->db->prepare($sql);
$stmt->execute();
$topologyUrlsFromDB = $stmt->fetchAll();
foreach ($topologyUrlsFromDB as $topologyUrl) {
$topologyUrls[] = $topologyUrl['topology_url'];
}
} elseif (count($user->access->getAccessGroups()) > 0) {
$query = 'SELECT DISTINCT acl_group_topology_relations.acl_topology_id '
. 'FROM acl_group_topology_relations, acl_topology, acl_topology_relations '
. 'WHERE acl_topology_relations.acl_topo_id = acl_topology.acl_topo_id '
. "AND acl_topology.acl_topo_activate = '1' "
. 'AND acl_group_topology_relations.acl_group_id IN ('
. $user->access->getAccessGroupsString() . ') ';
$DBRESULT = $this->db->query($query);
if ($DBRESULT->rowCount()) {
$topology = [];
$tmp_topo_page = [];
$statement = $this->db->prepare(
'SELECT topology_topology_id, acl_topology_relations.access_right '
. 'FROM acl_topology_relations, acl_topology '
. "WHERE acl_topology.acl_topo_activate = '1' "
. 'AND acl_topology.acl_topo_id = acl_topology_relations.acl_topo_id '
. 'AND acl_topology_relations.acl_topo_id = :acl_topo_id '
);
while ($topo_group = $DBRESULT->fetchRow()) {
$statement->bindValue(':acl_topo_id', $topo_group['acl_topology_id'], PDO::PARAM_INT);
$statement->execute();
while ($topo_page = $statement->fetch(PDO::FETCH_ASSOC)) {
$topology[] = (int) $topo_page['topology_topology_id'];
if (! isset($tmp_topo_page[$topo_page['topology_topology_id']])) {
$tmp_topo_page[$topo_page['topology_topology_id']] = $topo_page['access_right'];
} elseif ($topo_page['access_right'] == self::ACL_ACCESS_READ_WRITE) {
$tmp_topo_page[$topo_page['topology_topology_id']] = $topo_page['access_right'];
} elseif ($topo_page['access_right'] == self::ACL_ACCESS_READ_ONLY
&& $tmp_topo_page[$topo_page['topology_topology_id']] == self::ACL_ACCESS_NONE
) {
$tmp_topo_page[$topo_page['topology_topology_id']]
= self::ACL_ACCESS_READ_ONLY;
}
}
$statement->closeCursor();
}
$DBRESULT->closeCursor();
if ($topology !== []) {
$query3 = 'SELECT topology_url '
. 'FROM topology FORCE INDEX (`PRIMARY`) '
. 'WHERE topology_url IS NOT NULL '
. "AND is_react = '1' "
. 'AND topology_id IN (' . implode(', ', $topology) . ') ';
$DBRESULT3 = $this->db->query($query3);
while ($topo_page = $DBRESULT3->fetchRow()) {
$topologyUrls[] = $topo_page['topology_url'];
}
$DBRESULT3->closeCursor();
}
}
}
return $topologyUrls ?: [];
}
/**
* Get list of topologies per user and filter by react pages if specified
* @param CentreonUser $user
* @return array<Topology>
*/
public function getTopologyList(CentreonUser $user)
{
$query = 'SELECT topology_id, topology_name, topology_page, topology_url, topology_url_opt, '
. 'topology_feature_flag, '
. 'topology_group, topology_order, topology_parent, is_react, readonly, topology_show, is_deprecated '
. 'FROM ' . Topology::TABLE;
$where = [];
if (! $user->access->admin) {
$where[] = '(topology_page IN (' . $user->access->getTopologyString() . ') OR topology_page IS NULL)';
}
if ($user->doesShowDeprecatedPages() === false) {
$where[] = '((topology_name IN ("Hosts", "Services") AND is_deprecated = "0") OR topology_name NOT IN ("Hosts", "Services"))';
}
if ($user->doesShowDeprecatedCustomViews() === false) {
$where[] = '(topology_name != "Custom Views" OR is_deprecated = "0")';
}
if ($where !== []) {
$query .= ' WHERE ' . implode(' AND ', $where);
}
$query .= ' ORDER BY topology_parent, topology_group, topology_order, topology_page';
$stmt = $this->db->prepare($query);
$stmt->execute();
$stmt->setFetchMode(PDO::FETCH_CLASS, Topology::class);
return $stmt->fetchAll() ?: [];
}
/**
* Find Topology entity by criteria
*
* @param mixed[] $params
* @return Topology|null
*/
public function findOneBy($params = []): ?Topology
{
$sql = static::baseSqlQueryForEntity();
$collector = new StatementCollector();
$isWhere = false;
foreach ($params as $column => $value) {
$key = ":{$column}Val";
$sql .= (! $isWhere ? 'WHERE ' : 'AND ') . "`{$column}` = {$key} ";
$collector->addValue($key, $value);
$isWhere = true;
}
$stmt = $this->db->prepare($sql);
$collector->bind($stmt);
$stmt->execute();
if (! $stmt->rowCount()) {
return null;
}
$stmt->setFetchMode(PDO::FETCH_CLASS, Topology::class);
$entity = $stmt->fetch();
return $entity;
}
/**
* Part of SQL for extracting of BusinessActivity entity
*
* @return string
*/
protected static function baseSqlQueryForEntity(): string
{
return 'SELECT * FROM topology ';
}
}
| 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/Repository/AclResourcesHostRelationsRepository.php | centreon/src/Centreon/Domain/Repository/AclResourcesHostRelationsRepository.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
*
*/
namespace Centreon\Domain\Repository;
use Centreon\Domain\Repository\Interfaces\AclResourceRefreshInterface;
use Centreon\Infrastructure\CentreonLegacyDB\ServiceEntityRepository;
class AclResourcesHostRelationsRepository extends ServiceEntityRepository implements AclResourceRefreshInterface
{
/**
* Refresh
*/
public function refresh(): void
{
$sql = 'DELETE FROM acl_resources_host_relations '
. 'WHERE host_host_id NOT IN (SELECT t2.host_id FROM host AS t2)';
$stmt = $this->db->prepare($sql);
$stmt->execute();
}
}
| 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/Repository/HostGroupHgRelationRepository.php | centreon/src/Centreon/Domain/Repository/HostGroupHgRelationRepository.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
*
*/
namespace Centreon\Domain\Repository;
use Centreon\Infrastructure\CentreonLegacyDB\ServiceEntityRepository;
class HostGroupHgRelationRepository extends ServiceEntityRepository
{
/**
* Export host's groups
*
* @param int[] $pollerIds
* @param array $templateChainList
* @return array
*/
public function export(array $pollerIds, ?array $templateChainList = null): array
{
// prevent SQL exception
if (! $pollerIds) {
return [];
}
$ids = join(',', $pollerIds);
$sql = <<<SQL
SELECT
hghgr.*
FROM hostgroup AS t
INNER JOIN hostgroup_hg_relation AS hghgr ON hghgr.hg_child_id = t.hg_id
INNER JOIN hostgroup_relation AS hg ON hg.hostgroup_hg_id = t.hg_id
LEFT JOIN ns_host_relation AS hr ON hr.host_host_id = hg.host_host_id
WHERE hr.nagios_server_id IN ({$ids})
SQL;
if ($templateChainList) {
$list = join(',', $templateChainList);
$sql .= <<<SQL
OR hg.host_host_id IN ({$list})
SQL;
}
$stmt = $this->db->prepare($sql);
$stmt->execute();
$result = [];
while ($row = $stmt->fetch()) {
$result[] = $row;
}
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/Repository/CommandArgDescriptionRepository.php | centreon/src/Centreon/Domain/Repository/CommandArgDescriptionRepository.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
*
*/
namespace Centreon\Domain\Repository;
use Centreon\Infrastructure\CentreonLegacyDB\ServiceEntityRepository;
class CommandArgDescriptionRepository extends ServiceEntityRepository
{
/**
* Export
*
* @param int[] $pollerIds
* @return array
*/
public function export(array $pollerIds): array
{
// prevent SQL exception
if (! $pollerIds) {
return [];
}
$ids = join(',', $pollerIds);
$sql = <<<SQL
SELECT
cad1.*
FROM command AS t1
INNER JOIN command_arg_description AS cad1 ON cad1.cmd_id = t1.command_id
INNER JOIN cfg_nagios AS cn1 ON
cn1.global_service_event_handler = t1.command_id OR
cn1.global_host_event_handler = t1.command_id
WHERE
cn1.nagios_id IN ({$ids})
GROUP BY cad1.cmd_id
UNION
SELECT
cad2.*
FROM command AS t2
INNER JOIN command_arg_description AS cad2 ON cad2.cmd_id = t2.connector_id
INNER JOIN poller_command_relations AS pcr2 ON pcr2.command_id = t2.command_id
WHERE
pcr2.poller_id IN ({$ids})
GROUP BY cad2.cmd_id
UNION
SELECT
cad3.*
FROM command AS t3
INNER JOIN command_arg_description AS cad3 ON cad3.cmd_id = t3.connector_id
INNER JOIN host AS h3 ON
h3.command_command_id = t3.command_id OR
h3.command_command_id2 = t3.command_id
INNER JOIN ns_host_relation AS nhr3 ON nhr3.host_host_id = h3.host_id
WHERE
nhr3.nagios_server_id IN ({$ids})
GROUP BY cad3.cmd_id
UNION
SELECT
cad4.*
FROM command AS t4
INNER JOIN command_arg_description AS cad4 ON cad4.cmd_id = t4.connector_id
INNER JOIN host AS h4 ON
h4.command_command_id = t4.command_id OR
h4.command_command_id2 = t4.command_id
INNER JOIN ns_host_relation AS nhr4 ON nhr4.host_host_id = h4.host_id
WHERE
nhr4.nagios_server_id IN ({$ids})
GROUP BY cad4.cmd_id
UNION
SELECT
cad.*
FROM command AS t
INNER JOIN command_arg_description AS cad ON cad.cmd_id = t.connector_id
INNER JOIN service AS s ON
s.command_command_id = t.command_id OR
s.command_command_id2 = t.command_id
INNER JOIN host_service_relation AS hsr ON
hsr.service_service_id = s.service_id
LEFT JOIN hostgroup_relation AS hgr ON hgr.hostgroup_hg_id = hsr.hostgroup_hg_id
LEFT JOIN ns_host_relation AS nhr ON
nhr.host_host_id = hsr.host_host_id OR
nhr.host_host_id = hgr.host_host_id
WHERE
nhr.nagios_server_id IN ({$ids})
GROUP BY cad.cmd_id
SQL;
$stmt = $this->db->prepare($sql);
$stmt->execute();
$result = [];
while ($row = $stmt->fetch()) {
$result[] = $row;
}
return $result;
}
/**
* Export
*
* @param int[] $list
* @return array
*/
public function exportList(array $list): array
{
// prevent SQL exception
if (! $list) {
return [];
}
$ids = join(',', $list);
$sql = <<<SQL
SELECT
t.*
FROM command AS t
WHERE
t.cmd_id IN ({$ids})
GROUP BY t.cmd_id
SQL;
$stmt = $this->db->prepare($sql);
$stmt->execute();
$result = [];
while ($row = $stmt->fetch()) {
$result[] = $row;
}
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/Repository/DowntimeCacheRepository.php | centreon/src/Centreon/Domain/Repository/DowntimeCacheRepository.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
*
*/
namespace Centreon\Domain\Repository;
use Centreon\Infrastructure\CentreonLegacyDB\ServiceEntityRepository;
class DowntimeCacheRepository extends ServiceEntityRepository
{
/**
* Export
*
* @param int[] $pollerIds
* @param array $hostTemplateChain
* @return array
*/
public function export(array $pollerIds, ?array $hostTemplateChain = null): array
{
// prevent SQL exception
if (! $pollerIds) {
return [];
}
$ids = join(',', $pollerIds);
$hostList = join(',', $hostTemplateChain ?? []);
$sqlFilterHostList = $hostList ? " OR t.host_id IN ({$hostList})" : '';
$sql = <<<SQL
SELECT
t.*
FROM downtime_cache AS t
WHERE t.host_id IN (SELECT t1a.host_host_id
FROM
ns_host_relation AS t1a
WHERE
t1a.nagios_server_id IN ({$ids})
GROUP BY t1a.host_host_id){$sqlFilterHostList}
SQL;
$stmt = $this->db->prepare($sql);
$stmt->execute();
$result = [];
while ($row = $stmt->fetch()) {
$result[] = $row;
}
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/Repository/AbstractRepositoryDRB.php | centreon/src/Centreon/Domain/Repository/AbstractRepositoryDRB.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\Repository;
use Adaptation\Database\Connection\ConnectionInterface;
use Centreon\Infrastructure\DatabaseConnection;
use Core\Common\Infrastructure\Repository\DatabaseRepository;
use Core\Security\AccessGroup\Domain\Model\AccessGroup;
/**
* Class
*
* @class AbstractRepositoryDRB
* @package Centreon\Domain\Repository
*
* @deprecated use {@see DatabaseRepository} instead
*/
class AbstractRepositoryDRB
{
/** @var DatabaseConnection */
protected ConnectionInterface $db;
/**
* Formats the access group ids in string. (values are separated by coma)
*
* @param AccessGroup[] $accessGroups
* @return string
*/
public function accessGroupIdToString(array $accessGroups): string
{
$ids = [];
foreach ($accessGroups as $accessGroup) {
$ids[] = $accessGroup->getId();
}
return implode(',', $ids);
}
/**
* Replace all instances of :dbstg and :db by the real db names.
* The table names of the database are defined in the services.yaml
* configuration file.
*
* @param string $request Request to translate
* @return string Request translated
*/
protected function translateDbName(string $request): string
{
return str_replace(
[':dbstg', ':db'],
[$this->db->getConnectionConfig()->getDatabaseNameRealTime(), $this->db->getConnectionConfig()->getDatabaseNameConfiguration()],
$request
);
}
}
| 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/Repository/NagiosServerRepository.php | centreon/src/Centreon/Domain/Repository/NagiosServerRepository.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
*
*/
namespace Centreon\Domain\Repository;
use Centreon\Domain\Entity\NagiosServer;
use Centreon\Domain\Repository\Traits\CheckListOfIdsTrait;
use Centreon\Infrastructure\CentreonLegacyDB\Interfaces\PaginationRepositoryInterface;
use Centreon\Infrastructure\CentreonLegacyDB\StatementCollector;
use Centreon\Infrastructure\DatabaseConnection;
use Core\Common\Infrastructure\Repository\AbstractRepositoryRDB;
class NagiosServerRepository extends AbstractRepositoryRDB implements PaginationRepositoryInterface
{
use CheckListOfIdsTrait;
private const CONCORDANCE_ARRAY = [
'id' => 'id',
'name' => 'name',
'localhost' => 'localhost',
'isDefault' => 'is_default',
'lastRestart' => 'last_restart',
'nsIpress' => 'ns_ip_ress',
'nsActivate' => 'ns_activate',
'engineStartCommand' => 'engine_start_command',
'engineStopCommand' => 'engine_stop_command',
'engineRestartCommand' => 'engine_restart_command',
'engineReloadCommand' => 'engine_reload_command',
'nagiosBin' => 'nagios_bin',
'nagiostatsBin' => 'nagiostats_bin',
'nagiosPerfdata' => 'nagios_perfdata',
'brokerReloadCommand' => 'broker_reload_command',
'centreonbrokerCfgPath' => 'centreonbroker_cfg_path',
'centreonbrokerModulePath' => 'centreonbroker_module_path',
'centreonconnectorPath' => 'centreonconnector_path',
'sshPort' => 'ssh_port',
'gorgoneCommunicationType' => 'gorgone_communication_type',
'gorgonePort' => 'gorgone_port',
'initScriptCentreontrapd' => 'init_script_centreontrapd',
'snmpTrapdPathConf' => 'snmp_trapd_path_conf',
'engineName' => 'engine_name',
'engineVersion' => 'engine_version',
'centreonbrokerLogsPath' => 'centreonbroker_logs_path',
'remoteId' => 'remote_id',
'remoteServerUseAsProxy' => 'remote_server_use_as_proxy',
];
/** @var int */
private int $resultCountForPagination = 0;
/**
* @param DatabaseConnection $db
*/
public function __construct(DatabaseConnection $db)
{
$this->db = $db;
}
/**
* Check list of IDs
*
* @return bool
*/
public function checkListOfIds(array $ids): bool
{
return $this->checkListOfIdsTrait($ids, NagiosServer::TABLE, NagiosServer::ENTITY_IDENTIFICATOR_COLUMN);
}
/**
* {@inheritDoc}
*/
public function getPaginationList($filters = null, ?int $limit = null, ?int $offset = null, $ordering = []): array
{
$collector = new StatementCollector();
$sql = 'SELECT SQL_CALC_FOUND_ROWS * FROM `:db`.`nagios_server`';
if ($filters !== null) {
$isWhere = false;
if ($filters['search'] ?? false) {
$sql .= ' WHERE `name` LIKE :search';
$collector->addValue(':search', "%{$filters['search']}%");
$isWhere = true;
}
if (
array_key_exists('ids', $filters)
&& is_array($filters['ids'])
&& $filters['ids'] !== []
) {
$idsListKey = [];
foreach ($filters['ids'] as $x => $id) {
$key = ":id{$x}";
$idsListKey[] = $key;
$collector->addValue($key, $id, \PDO::PARAM_INT);
unset($x, $id);
}
$sql .= $isWhere ? ' AND' : ' WHERE';
$sql .= ' `' . self::CONCORDANCE_ARRAY['id']
. '` IN (' . implode(',', $idsListKey) . ')';
}
}
if (! empty($ordering['field'])) {
$sql .= ' ORDER BY `' . self::CONCORDANCE_ARRAY[$ordering['field']] . '` '
. $ordering['order'];
} else {
$sql .= ' ORDER BY `name` ASC';
}
if ($limit !== null) {
$sql .= ' LIMIT :limit';
$collector->addValue(':limit', $limit, \PDO::PARAM_INT);
}
if ($offset !== null) {
$sql .= ' OFFSET :offset';
$collector->addValue(':offset', $offset, \PDO::PARAM_INT);
}
$statement = $this->db->prepare($this->translateDbName($sql));
$collector->bind($statement);
$statement->execute();
$foundRecords = $this->db->query('SELECT FOUND_ROWS()');
if ($foundRecords !== false && ($total = $foundRecords->fetchColumn()) !== false) {
$this->resultCountForPagination = $total;
}
$result = [];
while ($data = $statement->fetch(\PDO::FETCH_ASSOC)) {
$result[] = $this->createNagiosServerFromArray($data);
}
return $result;
}
/**
* {@inheritDoc}
*/
public function getPaginationListTotal(): int
{
return $this->resultCountForPagination;
}
/**
* Export poller's Nagios data
*
* @param int[] $pollerIds
* @return array
*/
public function export(array $pollerIds): array
{
// prevent SQL exception
if (! $pollerIds) {
return [];
}
$ids = join(',', $pollerIds);
$sql = "SELECT * FROM nagios_server WHERE id IN ({$ids})";
$stmt = $this->db->prepare($sql);
$stmt->execute();
$result = [];
while ($row = $stmt->fetch()) {
$result[] = $row;
}
return $result;
}
/**
* Truncate the data
*/
public function truncate(): void
{
$sql = <<<'SQL'
TRUNCATE TABLE `nagios_server`;
TRUNCATE TABLE `cfg_nagios`;
TRUNCATE TABLE `cfg_nagios_broker_module`
SQL;
$stmt = $this->db->prepare($sql);
$stmt->execute();
}
/**
* Sets poller as updated (shows that poller needs restarting)
*
* @param int $id id of poller
*/
public function setUpdated(int $id): void
{
$sql = "UPDATE `nagios_server` SET `updated` = '1' WHERE `id` = :id";
$stmt = $this->db->prepare($sql);
$stmt->bindParam(':id', $id, \PDO::PARAM_INT);
$stmt->execute();
}
/**
* Get Central Poller
*
* @return int|null
*/
public function getCentral(): ?int
{
$query = "SELECT id FROM nagios_server WHERE localhost = '1' LIMIT 1";
$stmt = $this->db->prepare($query);
$stmt->execute();
if (! $stmt->rowCount()) {
return null;
}
return (int) $stmt->fetch()['id'];
}
private function createNagiosServerFromArray(array $data): NagiosServer
{
$nagiosServer = new NagiosServer();
$nagiosServer->setId((int) $data['id']);
$nagiosServer->setName($data['name']);
$nagiosServer->setLocalhost($data['localhost']);
$nagiosServer->setIsDefault((int) $data['is_default']);
$nagiosServer->setLastRestart((int) $data['last_restart']);
$nagiosServer->setNsIpAddress($data['ns_ip_address']);
$nagiosServer->setNsActivate($data['ns_activate']);
$nagiosServer->setEngineStartCommand($data['engine_start_command']);
$nagiosServer->setEngineStopCommand($data['engine_stop_command']);
$nagiosServer->setEngineRestartCommand($data['engine_restart_command']);
$nagiosServer->setEngineReloadCommand($data['engine_reload_command']);
$nagiosServer->setNagiosBin($data['nagios_bin']);
$nagiosServer->setNagiostatsBin($data['nagiostats_bin']);
$nagiosServer->setNagiosPerfdata($data['nagios_perfdata']);
$nagiosServer->setBrokerReloadCommand($data['broker_reload_command']);
$nagiosServer->setCentreonbrokerCfgPath($data['centreonbroker_cfg_path']);
$nagiosServer->setCentreonbrokerModulePath($data['centreonbroker_module_path']);
$nagiosServer->setCentreonconnectorPath($data['centreonconnector_path']);
$nagiosServer->setSshPort((int) $data['ssh_port']);
$nagiosServer->setGorgoneCommunicationType((int) $data['gorgone_communication_type']);
$nagiosServer->setGorgonePort((int) $data['gorgone_port']);
$nagiosServer->setInitScriptCentreontrapd($data['init_script_centreontrapd']);
$nagiosServer->setSnmpTrapdPathConf($data['snmp_trapd_path_conf']);
$nagiosServer->setEngineName($data['engine_name']);
$nagiosServer->setEngineVersion($data['engine_version']);
$nagiosServer->setCentreonbrokerLogsPath($data['centreonbroker_logs_path']);
$nagiosServer->setRemoteId((int) $data['remote_id']);
$nagiosServer->setRemoteServerUseAsProxy($data['remote_server_use_as_proxy']);
return $nagiosServer;
}
}
| 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/Repository/TrapRepository.php | centreon/src/Centreon/Domain/Repository/TrapRepository.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
*
*/
namespace Centreon\Domain\Repository;
use Centreon\Infrastructure\CentreonLegacyDB\ServiceEntityRepository;
class TrapRepository extends ServiceEntityRepository
{
/**
* Export
*
* @param int[] $pollerIds
* @param array $templateChainList
* @return array
*/
public function export(array $pollerIds, ?array $templateChainList = null): array
{
// prevent SQL exception
if (! $pollerIds) {
return [];
}
$ids = join(',', $pollerIds);
$list = join(',', $templateChainList ?? []);
$sqlFilterList = $list ? " OR tsr.service_id IN ({$list})" : '';
$sqlFilter = static::exportFilterSql($pollerIds);
$sql = <<<SQL
SELECT
t.*
FROM traps AS t
INNER JOIN traps_service_relation AS tsr ON tsr.traps_id = t.traps_id AND
(tsr.service_id IN ({$sqlFilter}){$sqlFilterList})
GROUP BY t.traps_id
SQL;
$stmt = $this->db->prepare($sql);
$stmt->execute();
$result = [];
while ($row = $stmt->fetch()) {
$result[] = $row;
}
return $result;
}
public function truncate(): void
{
$sql = <<<'SQL'
TRUNCATE TABLE `traps_service_relation`;
TRUNCATE TABLE `traps_vendor`;
TRUNCATE TABLE `traps_preexec`;
TRUNCATE TABLE `traps_matching_properties`;
TRUNCATE TABLE `traps_group_relation`;
TRUNCATE TABLE `traps_group`;
TRUNCATE TABLE `traps`;
SQL;
$stmt = $this->db->prepare($sql);
$stmt->execute();
}
/**
* Export filter
*
* @param int[] $pollerIds
* @return string
*/
public static function exportFilterSql(array $pollerIds): string
{
$ids = join(',', $pollerIds);
return <<<SQL
SELECT
_t.service_service_id
FROM host_service_relation AS _t
LEFT JOIN hostgroup AS _hg ON _hg.hg_id = _t.hostgroup_hg_id
LEFT JOIN hostgroup_relation AS _hgr ON _hgr.hostgroup_hg_id = _hg.hg_id
INNER JOIN ns_host_relation AS _hr ON _hr.host_host_id = _t.host_host_id OR _hr.host_host_id = _hgr.host_host_id
WHERE _hr.nagios_server_id IN ({$ids})
GROUP BY _t.service_service_id
SQL;
}
}
| 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/Repository/AclResourcesServiceRelationsRepository.php | centreon/src/Centreon/Domain/Repository/AclResourcesServiceRelationsRepository.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
*
*/
namespace Centreon\Domain\Repository;
use Centreon\Domain\Repository\Interfaces\AclResourceRefreshInterface;
use Centreon\Infrastructure\CentreonLegacyDB\ServiceEntityRepository;
class AclResourcesServiceRelationsRepository extends ServiceEntityRepository implements AclResourceRefreshInterface
{
/**
* Refresh
*/
public function refresh(): void
{
$sql = 'DELETE FROM acl_resources_service_relations '
. 'WHERE service_service_id NOT IN (SELECT t2.service_id FROM service AS t2)';
$stmt = $this->db->prepare($sql);
$stmt->execute();
}
}
| 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/Repository/TrapPreexecRepository.php | centreon/src/Centreon/Domain/Repository/TrapPreexecRepository.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
*
*/
namespace Centreon\Domain\Repository;
use Centreon\Infrastructure\CentreonLegacyDB\ServiceEntityRepository;
class TrapPreexecRepository extends ServiceEntityRepository
{
/**
* Export
*
* @param int[] $pollerIds
* @param array $templateChainList
* @return array
*/
public function export(array $pollerIds, ?array $templateChainList = null): array
{
// prevent SQL exception
if (! $pollerIds) {
return [];
}
$ids = join(',', $pollerIds);
$list = join(',', $templateChainList ?? []);
$sqlFilterList = $list ? " OR tsr.service_id IN ({$list})" : '';
$sqlFilter = TrapRepository::exportFilterSql($pollerIds);
$sql = <<<SQL
SELECT
t.*
FROM traps_preexec AS t
INNER JOIN traps_service_relation AS tsr ON
tsr.traps_id = t.trap_id AND
(tsr.service_id IN ({$sqlFilter}){$sqlFilterList})
GROUP BY t.trap_id
SQL;
$stmt = $this->db->prepare($sql);
$stmt->execute();
$result = [];
while ($row = $stmt->fetch()) {
$result[] = $row;
}
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/Repository/HostTemplateRelationRepository.php | centreon/src/Centreon/Domain/Repository/HostTemplateRelationRepository.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
*
*/
namespace Centreon\Domain\Repository;
use Centreon\Infrastructure\CentreonLegacyDB\ServiceEntityRepository;
use PDO;
class HostTemplateRelationRepository extends ServiceEntityRepository
{
/**
* Export host's templates relation
*
* @param int[] $pollerIds
* @param array $templateChainList
* @return array
*/
public function export(array $pollerIds, ?array $templateChainList = null): array
{
// prevent SQL exception
if (! $pollerIds) {
return [];
}
$ids = join(',', $pollerIds);
$sql = <<<SQL
SELECT l.* FROM(
SELECT
t.*
FROM host_template_relation AS t
INNER JOIN ns_host_relation AS hr ON hr.host_host_id = t.host_host_id
WHERE hr.nagios_server_id IN ({$ids})
GROUP BY t.host_host_id, t.host_tpl_id
SQL;
if ($templateChainList) {
$list = join(',', $templateChainList);
$sql .= <<<SQL
UNION
SELECT
tt.*
FROM host_template_relation AS tt
WHERE tt.host_host_id IN ({$list})
GROUP BY tt.host_host_id, tt.host_tpl_id
SQL;
}
$sql .= <<<'SQL'
) AS l
GROUP BY l.host_host_id, l.host_tpl_id
SQL;
$stmt = $this->db->prepare($sql);
$stmt->execute();
$result = [];
while ($row = $stmt->fetch()) {
$result[] = $row;
}
return $result;
}
/**
* Get a chain of the related objects
*
* @param int[] $pollerIds
* @param int[] $ba
* @return array
*/
public function getChainByPoller(array $pollerIds, ?array $ba = null): array
{
// prevent SQL exception
if (! $pollerIds) {
return [];
}
$ids = join(',', $pollerIds);
$sql = <<<SQL
SELECT l.* FROM (
SELECT
t.host_tpl_id AS `id`
FROM host_template_relation AS t
INNER JOIN ns_host_relation AS hr ON hr.host_host_id = t.host_host_id
WHERE hr.nagios_server_id IN ({$ids})
GROUP BY t.host_tpl_id
SQL;
// Extract BA hosts
if ($ba) {
foreach ($ba as $key => $val) {
$ba[$key] = "'ba_{$val}'";
}
$ba = implode(',', $ba);
$sql .= ' UNION SELECT t2.host_host_id AS `id`'
. ' FROM host_service_relation AS t2'
. ' INNER JOIN service s2 ON s2.service_id = t2.service_service_id'
. " AND s2.service_description IN({$ba}) GROUP BY t2.host_host_id";
}
$sql .= ') AS l GROUP BY l.id';
$stmt = $this->db->prepare($sql);
$stmt->execute();
$result = [];
while ($row = $stmt->fetch()) {
$result[$row['id']] = $row['id'];
$this->getChainByParant($row['id'], $result);
}
return $result;
}
public function getChainByParant($id, &$result)
{
$sql = <<<'SQL'
SELECT
t.host_tpl_id AS `id`
FROM host_template_relation AS t
WHERE t.host_host_id = :id
GROUP BY t.host_tpl_id
SQL;
$stmt = $this->db->prepare($sql);
$stmt->bindValue(':id', $id, PDO::PARAM_INT);
$stmt->execute();
while ($row = $stmt->fetch()) {
$result[$row['id']] = $row['id'];
$this->getChainByParant($row['id'], $result);
}
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/Repository/MetaServiceRepository.php | centreon/src/Centreon/Domain/Repository/MetaServiceRepository.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
*
*/
namespace Centreon\Domain\Repository;
use Centreon\Infrastructure\CentreonLegacyDB\ServiceEntityRepository;
class MetaServiceRepository extends ServiceEntityRepository
{
/**
* Export
*
* @param int[] $pollerIds
* @param array $templateChainList
* @return array
*/
public function export(array $pollerIds, ?array $templateChainList = null): array
{
// prevent SQL exception
if (! $pollerIds) {
return [];
}
$ids = join(',', $pollerIds);
$sql = <<<SQL
SELECT l.* FROM(
SELECT
t.*
FROM meta_service AS t
INNER JOIN meta_service_relation AS msr ON msr.meta_id = t.meta_id
INNER JOIN ns_host_relation AS hr ON hr.host_host_id = msr.host_id
WHERE hr.nagios_server_id IN ({$ids})
GROUP BY t.meta_id
SQL;
if ($templateChainList) {
$list = join(',', $templateChainList);
$sql .= <<<SQL
UNION
SELECT
tt.*
FROM meta_service AS tt
INNER JOIN meta_service_relation AS _msr ON _msr.meta_id = tt.meta_id
WHERE _msr.host_id IN ({$list})
GROUP BY tt.meta_id
SQL;
}
$sql .= <<<'SQL'
) AS l
GROUP BY l.meta_id
SQL;
$stmt = $this->db->prepare($sql);
$stmt->execute();
$result = [];
while ($row = $stmt->fetch()) {
$result[] = $row;
}
return $result;
}
/**
* Export
*
* @param int[] $list
* @return array
*/
public function exportList(array $list): array
{
// prevent SQL exception
if (! $list) {
return [];
}
$ids = join(',', $list);
$sql = <<<SQL
SELECT
t.*
FROM meta_service AS t
WHERE t.meta_id IN ({$ids})
GROUP BY t.meta_id
SQL;
$stmt = $this->db->prepare($sql);
$stmt->execute();
$result = [];
while ($row = $stmt->fetch()) {
$result[] = $row;
}
return $result;
}
public function truncate(): void
{
$sql = <<<'SQL'
TRUNCATE TABLE `meta_service_relation`;
TRUNCATE TABLE `meta_service`;
SQL;
$stmt = $this->db->prepare($sql);
$stmt->execute();
}
}
| 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/Repository/HostServiceRelationRepository.php | centreon/src/Centreon/Domain/Repository/HostServiceRelationRepository.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
*
*/
namespace Centreon\Domain\Repository;
use Centreon\Infrastructure\CentreonLegacyDB\ServiceEntityRepository;
class HostServiceRelationRepository extends ServiceEntityRepository
{
/**
* Export
*
* @todo restriction by poller
*
* @param int[] $pollerIds
* @return array
*/
public function export(array $pollerIds, ?array $ba = null): array
{
// prevent SQL exception
if (! $pollerIds) {
return [];
}
$ids = join(',', $pollerIds);
$sql = <<<SQL
SELECT l.* FROM (
SELECT
t.*
FROM host_service_relation AS t
LEFT JOIN hostgroup AS hg ON hg.hg_id = t.hostgroup_hg_id
LEFT JOIN hostgroup_relation AS hgr ON hgr.hostgroup_hg_id = hg.hg_id
INNER JOIN ns_host_relation AS hr ON hr.host_host_id = t.host_host_id OR hr.host_host_id = hgr.host_host_id
WHERE hr.nagios_server_id IN ({$ids})
GROUP BY t.hsr_id
SQL;
// Extract BA services relations
if ($ba) {
foreach ($ba as $key => $val) {
$ba[$key] = "'ba_{$val}'";
}
$ba = implode(',', $ba);
$sql .= ' UNION SELECT t2.*'
. ' FROM host_service_relation AS t2'
. ' INNER JOIN service s2 ON s2.service_id = t2.service_service_id'
. " AND s2.service_description IN({$ba}) GROUP BY t2.service_service_id";
}
$sql .= ') AS l GROUP BY l.hsr_id';
$stmt = $this->db->prepare($sql);
$stmt->execute();
$result = [];
while ($row = $stmt->fetch()) {
$result[] = $row;
}
return $result;
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.