-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,58 +19,50 @@ class RenderingHelper | |
{ | ||
protected $api; | ||
|
||
/** @var ?Link Host link */ | ||
protected $hostLink; | ||
|
||
/** @var ?Link Service link */ | ||
protected $serviceLink; | ||
|
||
/** | ||
* Set the link of monitored host | ||
* | ||
* @param Link $hostLink | ||
* | ||
* @return $this | ||
*/ | ||
public function setHostLink(Link $hostLink): RenderingHelper | ||
{ | ||
$this->hostLink = $hostLink; | ||
|
||
return $this; | ||
} | ||
/** @var string Backend used for object link Host|Service */ | ||
private $backend; | ||
|
||
/** | ||
* Set the link of monitored service | ||
* Get the link of monitored host | ||
* | ||
* @param Link $serviceLink | ||
* @param $host | ||
* | ||
* @return $this | ||
* @return ?Url | ||
*/ | ||
public function setServiceLink(Link $serviceLink): RenderingHelper | ||
public function getHostLink(string $host): ?Link | ||
Check failure on line 32 in library/Jira/Web/RenderingHelper.php GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest
Check failure on line 32 in library/Jira/Web/RenderingHelper.php GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest
Check failure on line 32 in library/Jira/Web/RenderingHelper.php GitHub Actions / phpstan / Static analysis with phpstan and php 7.4 on ubuntu-latest
Check failure on line 32 in library/Jira/Web/RenderingHelper.php GitHub Actions / phpstan / Static analysis with phpstan and php 8.0 on ubuntu-latest
Check failure on line 32 in library/Jira/Web/RenderingHelper.php GitHub Actions / phpstan / Static analysis with phpstan and php 8.1 on ubuntu-latest
Check failure on line 32 in library/Jira/Web/RenderingHelper.php GitHub Actions / phpstan / Static analysis with phpstan and php 8.2 on ubuntu-latest
Check failure on line 32 in library/Jira/Web/RenderingHelper.php GitHub Actions / phpstan / Static analysis with phpstan and php 8.3 on ubuntu-latest
|
||
{ | ||
$this->serviceLink = $serviceLink; | ||
|
||
return $this; | ||
} | ||
if (Module::exists('icingadb') && IcingadbSupport::useIcingaDbAsBackend()) { | ||
return new Link( | ||
[new Icon('server'), $host], | ||
Url::fromPath('icingadb/host', ['name' => $host]) | ||
); | ||
} | ||
|
||
/** | ||
* Get the link of monitored host | ||
* | ||
* @return ?Link | ||
*/ | ||
public function getHostLink(): ?Link | ||
{ | ||
return $this->hostLink; | ||
return new Link( | ||
[new Icon('laptop'), $host], | ||
Url::fromPath('monitoring/host/show', ['host' => $host]) | ||
); | ||
} | ||
|
||
/** | ||
* Get the link of monitored service | ||
* | ||
* @return ?Link | ||
*/ | ||
public function getServiceLink(): ?Link | ||
public function getServiceLink(string $host, string $service): ?Link | ||
{ | ||
return $this->serviceLink; | ||
if (Module::exists('icingadb') && IcingadbSupport::useIcingaDbAsBackend()) { | ||
return new Link( | ||
[new Icon('cog'), $service], | ||
Url::fromPath('icingadb/service/show', ['name' => $service, 'host.name' => $host]), | ||
['icon' => new Icon('cog')] | ||
); | ||
} | ||
|
||
return new Link( | ||
[new Icon('cog'), $service], | ||
Url::fromPath('monitoring/host/show', ['host' => $host, 'service' => $service]) | ||
); | ||
} | ||
|
||
|
||
|
@@ -115,8 +107,7 @@ public function formatBody(string $body): HtmlString | |
$url = Url::fromPath($match[2]); | ||
$link = new Link( | ||
$match[1], | ||
$url, | ||
['target' => '_blank'] | ||
$url | ||
); | ||
|
||
if ($url->hasParam('service') || $url->hasParam('host.name')) { | ||
|
@@ -136,32 +127,17 @@ public function formatBody(string $body): HtmlString | |
['target' => '_blank'] | ||
); | ||
} | ||
|
||
$serviceLink = clone $link; | ||
$serviceLink->setContent([new Icon('cog'), $match[1]]) | ||
->addAttributes(['title' => t('Show Icinga Service State')]); | ||
$this->setServiceLink($serviceLink); | ||
} else { | ||
$icon = new Icon('server'); | ||
if (strpos($match[2], 'icingaweb2/monitoring') !== false) { | ||
if (Module::exists('icingadb') && IcingadbSupport::useIcingaDbAsBackend()) { | ||
$link = new Link( | ||
$match[1], | ||
Url::fromPath( | ||
'icingadb/host', | ||
['name' => $url->getParam('host')] | ||
), | ||
['target' => '_blank'] | ||
); | ||
} else { | ||
$icon = new Icon('laptop'); | ||
} | ||
} elseif (strpos($match[2], 'icingaweb2/monitoring') !== false) { | ||
if (Module::exists('icingadb') && IcingadbSupport::useIcingaDbAsBackend()) { | ||
$link = new Link( | ||
$match[1], | ||
Url::fromPath( | ||
'icingadb/host', | ||
['name' => $url->getParam('host')] | ||
), | ||
['target' => '_blank'] | ||
); | ||
} | ||
|
||
$hostLink = clone $link; | ||
$hostLink->setContent([$icon, $match[1]]) | ||
->addAttributes(['title' => t('Show Icinga Host State')]); | ||
$this->setHostLink($hostLink); | ||
} | ||
|
||
$urls[] = $link->render(); | ||
|