mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-29 00:34:05 +02:00
Monitoring/IcingadbBackend: Handle if $hostName or $serviceName is null
This commit is contained in:
parent
956cce84cb
commit
677f5dc72a
@ -16,47 +16,47 @@ interface BackendInterface
|
|||||||
/**
|
/**
|
||||||
* Whether the backend has the given host
|
* Whether the backend has the given host
|
||||||
*
|
*
|
||||||
* @param string $hostname
|
* @param ?string $hostName
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function hasHost(string $hostname): bool;
|
public function hasHost(?string $hostName): bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the backend has the given service of the specified host
|
* Whether the backend has the given service of the specified host
|
||||||
*
|
*
|
||||||
* @param string $hostname
|
* @param ?string $hostName
|
||||||
* @param string $service
|
* @param ?string $serviceName
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function hasService(string $hostname, string $service): bool;
|
public function hasService(?string $hostName, ?string $serviceName): bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether an authenticated user has the permission (is not restricted) to modify given host
|
* Whether an authenticated user has the permission (is not restricted) to modify given host
|
||||||
*
|
*
|
||||||
* @param string $hostName
|
* @param ?string $hostName
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function canModifyHost(string $hostName): bool;
|
public function canModifyHost(?string $hostName): bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether an authenticated user has the permission (is not restricted) to modify given service of specified host
|
* Whether an authenticated user has the permission (is not restricted) to modify given service of specified host
|
||||||
*
|
*
|
||||||
* @param string $hostName
|
* @param ?string $hostName
|
||||||
* @param string $serviceName
|
* @param ?string $serviceName
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function canModifyService(string $hostName, string $serviceName): bool;
|
public function canModifyService(?string $hostName, ?string $serviceName): bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the url of given host
|
* Get the url of given host
|
||||||
*
|
*
|
||||||
* @param string $hostname
|
* @param ?string $hostName
|
||||||
*
|
*
|
||||||
* @return Url
|
* @return Url
|
||||||
*/
|
*/
|
||||||
public function getHostUrl(string $hostname): Url;
|
public function getHostUrl(?string $hostName): ?Url;
|
||||||
}
|
}
|
||||||
|
@ -21,22 +21,30 @@ class IcingadbBackend implements BackendInterface
|
|||||||
return Module::exists('icingadb');
|
return Module::exists('icingadb');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasHost($hostname): bool
|
public function hasHost(?string $hostName): bool
|
||||||
{
|
{
|
||||||
|
if ($hostName === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$query = Host::on($this->getDb())
|
$query = Host::on($this->getDb())
|
||||||
->filter(Filter::equal('host.name', $hostname));
|
->filter(Filter::equal('host.name', $hostName));
|
||||||
|
|
||||||
$this->applyRestrictions($query);
|
$this->applyRestrictions($query);
|
||||||
|
|
||||||
return $query->first() !== null;
|
return $query->first() !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasService($hostname, $service): bool
|
public function hasService(?string $hostName, ?string $serviceName): bool
|
||||||
{
|
{
|
||||||
|
if ($hostName === null || $serviceName === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$query = Service::on($this->getDb())
|
$query = Service::on($this->getDb())
|
||||||
->filter(Filter::all(
|
->filter(Filter::all(
|
||||||
Filter::equal('service.name', $service),
|
Filter::equal('service.name', $serviceName),
|
||||||
Filter::equal('host.name', $hostname)
|
Filter::equal('host.name', $hostName)
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->applyRestrictions($query);
|
$this->applyRestrictions($query);
|
||||||
@ -44,19 +52,29 @@ class IcingadbBackend implements BackendInterface
|
|||||||
return $query->first() !== null;
|
return $query->first() !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getHostUrl(string $hostname): Url
|
public function getHostUrl(?string $hostName): ?Url
|
||||||
{
|
{
|
||||||
return Url::fromPath('icingadb/host', ['name' => $hostname]);
|
if ($hostName === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Url::fromPath('icingadb/host', ['name' => $hostName]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canModifyHost(string $hostName): bool
|
public function canModifyHost(?string $hostName): bool
|
||||||
{
|
{
|
||||||
|
if ($hostName === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// TODO: Implement canModifyService() method.
|
// TODO: Implement canModifyService() method.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canModifyService(string $hostName, string $serviceName): bool
|
public function canModifyService(?string $hostName, ?string $serviceName): bool
|
||||||
{
|
{
|
||||||
|
if ($hostName === null || $serviceName === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// TODO: Implement canModifyService() method.
|
// TODO: Implement canModifyService() method.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -33,38 +33,42 @@ class Monitoring implements BackendInterface
|
|||||||
return $this->backend !== null;
|
return $this->backend !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getHostUrl(string $hostname): Url
|
public function getHostUrl(?string $hostName): ?Url
|
||||||
{
|
{
|
||||||
return Url::fromPath('monitoring/host/show', ['host' => $hostname]);
|
if ($hostName === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Url::fromPath('monitoring/host/show', ['host' => $hostName]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasHost($hostname): bool
|
public function hasHost(?string $hostName): bool
|
||||||
{
|
{
|
||||||
if (! $this->isAvailable()) {
|
if ($hostName === null || ! $this->isAvailable()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return $this->selectHost($hostname)->fetchOne() === $hostname;
|
return $this->selectHost($hostName)->fetchOne() === $hostName;
|
||||||
} catch (Exception $_) {
|
} catch (Exception $_) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasService($hostname, $service): bool
|
public function hasService(?string $hostName, ?string $serviceName): bool
|
||||||
{
|
{
|
||||||
if (! $this->isAvailable()) {
|
if ($hostName === null || $serviceName === null || ! $this->isAvailable()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return $this->rowIsService($this->selectService($hostname, $service)->fetchRow(), $hostname, $service);
|
return $this->rowIsService($this->selectService($hostName, $serviceName)->fetchRow(), $hostName, $serviceName);
|
||||||
} catch (Exception $_) {
|
} catch (Exception $_) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canModifyService(string $hostName, string $serviceName): bool
|
public function canModifyService(?string $hostName, ?string $serviceName): bool
|
||||||
{
|
{
|
||||||
if (! $this->isAvailable() || $hostName === null || $serviceName === null) {
|
if (! $this->isAvailable() || $hostName === null || $serviceName === null) {
|
||||||
return false;
|
return false;
|
||||||
@ -84,9 +88,9 @@ class Monitoring implements BackendInterface
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canModifyHost(string $hostName): bool
|
public function canModifyHost(?string $hostName): bool
|
||||||
{
|
{
|
||||||
if ($this->isAvailable() && $this->auth->hasPermission(Permission::MONITORING_HOSTS)) {
|
if ($hostName !== null && $this->isAvailable() && $this->auth->hasPermission(Permission::MONITORING_HOSTS)) {
|
||||||
$restriction = null;
|
$restriction = null;
|
||||||
foreach ($this->auth->getRestrictions(Restriction::MONITORING_RW_OBJECT_FILTER) as $restriction) {
|
foreach ($this->auth->getRestrictions(Restriction::MONITORING_RW_OBJECT_FILTER) as $restriction) {
|
||||||
if ($this->hasHostWithFilter($hostName, Filter::fromQueryString($restriction))) {
|
if ($this->hasHostWithFilter($hostName, Filter::fromQueryString($restriction))) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user