Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 committed Feb 9, 2024
1 parent e00284f commit 29a90f6
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 22 deletions.
24 changes: 20 additions & 4 deletions application/controllers/IssuesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace Icinga\Module\Jira\Controllers;

use Icinga\Application\Icinga;
use Icinga\Application\Modules\Module;
use Icinga\Authentication\Auth;
use Icinga\Module\Jira\IcingadbBackend;
use Icinga\Module\Jira\IdoBackend;
use Icinga\Module\Jira\ProvidedHook\Icingadb\IcingadbSupport;
use Icinga\Module\Jira\Web\Controller;
use Icinga\Module\Jira\Web\Form\NewIssueForm;
use Icinga\Module\Jira\Web\Table\IssuesTable;
Expand Down Expand Up @@ -67,10 +68,25 @@ protected function showNewIssueForm()

protected function requireMonitoringInfo()
{
if (Module::exists('icingadb') && IcingadbSupport::useIcingaDbAsBackend()) {
$backendName = $this->params->get('backend');
if ($backendName === 'icingadb') {
$backend = new IcingadbBackend();
} else {
} elseif ($backendName === 'monitoring') {
$backend = new IdoBackend();
} else {
/* if (Module::exists('icingadb') && $this->hasPermission()) {
}*/
$auth = Auth::getInstance();
$authenticated = Icinga::app()->isWeb() && Auth::getInstance()->isAuthenticated();
if (
! Module::exists('monitoring')
|| ($authenticated && ! $auth->getUser()->can('module/monitoring'))

Check failure on line 84 in application/controllers/IssuesController.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 7.3 on ubuntu-latest

Cannot call method can() on Icinga\User|null.

Check failure on line 84 in application/controllers/IssuesController.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 8.0 on ubuntu-latest

Cannot call method can() on Icinga\User|null.

Check failure on line 84 in application/controllers/IssuesController.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 7.2 on ubuntu-latest

Cannot call method can() on Icinga\User|null.

Check failure on line 84 in application/controllers/IssuesController.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 8.1 on ubuntu-latest

Cannot call method can() on Icinga\User|null.

Check failure on line 84 in application/controllers/IssuesController.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 7.4 on ubuntu-latest

Cannot call method can() on Icinga\User|null.

Check failure on line 84 in application/controllers/IssuesController.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 8.2 on ubuntu-latest

Cannot call method can() on Icinga\User|null.
) {
$backend = new IcingadbBackend();
} else {
$backend = new IdoBackend();
}
}

return $backend->getMonitoringInfo(
Expand All @@ -91,7 +107,7 @@ protected function activateTab($name = null)
$tabs = $this->getTabs();

$params = [];
foreach (['host', 'service'] as $param) {
foreach (['host', 'service', 'backend'] as $param) {
if ($value = $this->params->get($param)) {
$params[$param] = $value;
}
Expand Down
5 changes: 3 additions & 2 deletions library/Jira/ProvidedHook/Icingadb/HostActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public function getActionsForObject(Host $host): array
Url::fromPath(
'jira/issues',
[
'host' => $host->name,
'all' => true
'host' => $host->name,
'all' => true,
'backend' => 'icingadb'
]
)
)
Expand Down
7 changes: 4 additions & 3 deletions library/Jira/ProvidedHook/Icingadb/ServiceActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ public function getActionsForObject(Service $service): array
Url::fromPath(
'jira/issues',
[
'service' => $service->name,
'host' => $service->host->name,
'all' => true
'service' => $service->name,
'host' => $service->host->name,
'all' => true,
'backend' => 'icingadb'
]
)
)
Expand Down
5 changes: 3 additions & 2 deletions library/Jira/ProvidedHook/Monitoring/HostActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public function getActionsForHost(Host $host)
'Jira Issues' => Url::fromPath(
'jira/issues',
[
'host' => $host->host_name,
'all' => true,
'host' => $host->host_name,
'all' => true,
'backend' => 'monitoring'
]
)
];
Expand Down
7 changes: 4 additions & 3 deletions library/Jira/ProvidedHook/Monitoring/ServiceActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ public function getActionsForService(Service $service)
'Jira Issues' => Url::fromPath(
'jira/issues',
[
'host' => $service->host_name,
'service' => $service->service_description,
'all' => true,
'host' => $service->host_name,
'service' => $service->service_description,
'all' => true,
'backend' => 'monitoring'
]
)
];
Expand Down
18 changes: 18 additions & 0 deletions library/Jira/Web/RenderingHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
namespace Icinga\Module\Jira\Web;

use Icinga\Application\Config;
use Icinga\Application\Icinga;
use Icinga\Application\Modules\Module;
use Icinga\Authentication\Auth;
use Icinga\Date\DateFormatter;
use Icinga\Module\Jira\IcingadbBackend;
use Icinga\Module\Jira\IdoBackend;
use Icinga\Module\Jira\ProvidedHook\Icingadb\IcingadbSupport;
use Icinga\Module\Jira\RestApi;
use ipl\Html\Html;
Expand Down Expand Up @@ -43,6 +47,20 @@ public function linkToMonitoringHost($host)
]);
}

protected function useIcingaDbAsBackend()

Check failure on line 50 in library/Jira/Web/RenderingHelper.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 7.3 on ubuntu-latest

Method Icinga\Module\Jira\Web\RenderingHelper::useIcingaDbAsBackend() has no return type specified.

Check failure on line 50 in library/Jira/Web/RenderingHelper.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 8.0 on ubuntu-latest

Method Icinga\Module\Jira\Web\RenderingHelper::useIcingaDbAsBackend() has no return type specified.

Check failure on line 50 in library/Jira/Web/RenderingHelper.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 7.2 on ubuntu-latest

Method Icinga\Module\Jira\Web\RenderingHelper::useIcingaDbAsBackend() has no return type specified.

Check failure on line 50 in library/Jira/Web/RenderingHelper.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 8.1 on ubuntu-latest

Method Icinga\Module\Jira\Web\RenderingHelper::useIcingaDbAsBackend() has no return type specified.

Check failure on line 50 in library/Jira/Web/RenderingHelper.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 7.4 on ubuntu-latest

Method Icinga\Module\Jira\Web\RenderingHelper::useIcingaDbAsBackend() has no return type specified.

Check failure on line 50 in library/Jira/Web/RenderingHelper.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 8.2 on ubuntu-latest

Method Icinga\Module\Jira\Web\RenderingHelper::useIcingaDbAsBackend() has no return type specified.
{
$auth = Auth::getInstance();
$authenticated = Icinga::app()->isWeb() && Auth::getInstance()->isAuthenticated();
if (
! Module::exists('monitoring')
|| ($authenticated && ! $auth->getUser()->can('module/monitoring'))

Check failure on line 56 in library/Jira/Web/RenderingHelper.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 7.3 on ubuntu-latest

Cannot call method can() on Icinga\User|null.

Check failure on line 56 in library/Jira/Web/RenderingHelper.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 8.0 on ubuntu-latest

Cannot call method can() on Icinga\User|null.

Check failure on line 56 in library/Jira/Web/RenderingHelper.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 7.2 on ubuntu-latest

Cannot call method can() on Icinga\User|null.

Check failure on line 56 in library/Jira/Web/RenderingHelper.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 8.1 on ubuntu-latest

Cannot call method can() on Icinga\User|null.

Check failure on line 56 in library/Jira/Web/RenderingHelper.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 7.4 on ubuntu-latest

Cannot call method can() on Icinga\User|null.

Check failure on line 56 in library/Jira/Web/RenderingHelper.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 8.2 on ubuntu-latest

Cannot call method can() on Icinga\User|null.
) {
return true;
}

return false;
}

public function linkToMonitoringService($host, $service)
{
if (Module::exists('icingadb') && IcingadbSupport::useIcingaDbAsBackend()) {
Expand Down
76 changes: 68 additions & 8 deletions library/Jira/Web/Table/IssueDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

use Icinga\Module\Jira\Web\RenderingHelper;
use ipl\Html\Html;
use ipl\Html\HtmlElement;
use ipl\Html\HtmlString;
use Icinga\Application\Config;
use ipl\Html\Table;
use ipl\I18n\Translation;
use ipl\Web\Widget\Icon;
use ipl\Web\Widget\Link;
use stdClass;

class IssueDetails extends Table
Expand All @@ -21,6 +23,18 @@ class IssueDetails extends Table

protected $issue;

/** @var ?string Host */
protected $host;

/** @var ?string Service */
protected $service;

/** @var ?HtmlElement Host link */
protected $hostLink;

/** @var ?HtmlElement Service link */
protected $serviceLink;

public function __construct($issue)
{
$this->helper = new RenderingHelper();
Expand All @@ -40,11 +54,11 @@ protected function assemble()

$icingaKey = preg_replace('/^BEGIN(.+)END$/', '$1', $fields->$keyField);
$parts = explode('!', $icingaKey);
$host = array_shift($parts);
$this->host = array_shift($parts);
if (empty($parts)) {
$service = null;
$this->service = null;
} else {
$service = array_shift($parts);
$this->service = array_shift($parts);
}
if (isset($fields->icingaUser)) {
$user = $fields->icingaUser;
Expand Down Expand Up @@ -74,16 +88,18 @@ protected function assemble()
$this->translate('Created') => $helper->shortTimeSince($fields->created, false),
]);

if ($host !== null) {
$hostLink = null;
$serviceLink = null;
if ($this->host !== null) {
$this->addNameValueRow(
$this->translate('Host'),
$helper->linkToMonitoringHost($host)
$hostLink
);
}
if ($service !== null) {
if ($this->service !== null) {
$this->addNameValueRow(
$this->translate('Service'),
$helper->linkToMonitoringService($host, $service)
$this->getLinkToMonitoringService()
);
}
if ($user !== null) {
Expand All @@ -93,12 +109,19 @@ protected function assemble()
);
}

$summary = $this->getSummary(

Check failure on line 112 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 7.3 on ubuntu-latest

Call to an undefined method Icinga\Module\Jira\Web\Table\IssueDetails::getSummary().

Check failure on line 112 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 8.0 on ubuntu-latest

Call to an undefined method Icinga\Module\Jira\Web\Table\IssueDetails::getSummary().

Check failure on line 112 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 7.2 on ubuntu-latest

Call to an undefined method Icinga\Module\Jira\Web\Table\IssueDetails::getSummary().

Check failure on line 112 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 8.1 on ubuntu-latest

Call to an undefined method Icinga\Module\Jira\Web\Table\IssueDetails::getSummary().

Check failure on line 112 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 7.4 on ubuntu-latest

Call to an undefined method Icinga\Module\Jira\Web\Table\IssueDetails::getSummary().

Check failure on line 112 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 8.2 on ubuntu-latest

Call to an undefined method Icinga\Module\Jira\Web\Table\IssueDetails::getSummary().

);

$this->addComments(array_reverse($fields->comment->comments));
$this->addComment(
$fields->summary,
$fields->created,
$fields->description
);

$hostLink = $this->getLinkToMonitoringHost();
$serviceLink = $this->getLinkToMonitoringService();
}

protected function addWideRow($content)
Expand Down Expand Up @@ -156,7 +179,24 @@ protected function formatBody($body)
protected function replaceLinks($string)
{
return \preg_replace_callback('/\[([^|]+)\|([^]]+)]/', function ($match) {
return Html::tag('a', ['href' => $match[2], 'target' => '_blank'], $match[1]);
$link = Html::tag('a', ['href' => $match[2], 'target' => '_blank'], $match[1]);
if ($this->service && $this->service === $match[1]) {
$serviceLink = $link;
$serviceLink->setContent([new Icon('cog'), $match[1]]);
$serviceLink->addAttributes(
['title' => t('Show Icinga Service State')]
);
$this->setLinkToMonitoringService($serviceLink);
} else {
$hostLink = $link;
$hostLink->setContent([new Icon('server'), $match[1]]);
$hostLink->addAttributes(
['title' => t('Show Icinga Host State')]
);
$this->setLinkToMonitoringHost($link);
}

return $link;
}, $string);
}

Expand Down Expand Up @@ -194,4 +234,24 @@ protected function addNameValuePairs($pairs)

return $this;
}

protected function setLinkToMonitoringService(HtmlElement $serviceLink)

Check failure on line 238 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 7.3 on ubuntu-latest

Method Icinga\Module\Jira\Web\Table\IssueDetails::setLinkToMonitoringService() has no return type specified.

Check failure on line 238 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 8.0 on ubuntu-latest

Method Icinga\Module\Jira\Web\Table\IssueDetails::setLinkToMonitoringService() has no return type specified.

Check failure on line 238 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 7.2 on ubuntu-latest

Method Icinga\Module\Jira\Web\Table\IssueDetails::setLinkToMonitoringService() has no return type specified.

Check failure on line 238 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 8.1 on ubuntu-latest

Method Icinga\Module\Jira\Web\Table\IssueDetails::setLinkToMonitoringService() has no return type specified.

Check failure on line 238 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 7.4 on ubuntu-latest

Method Icinga\Module\Jira\Web\Table\IssueDetails::setLinkToMonitoringService() has no return type specified.

Check failure on line 238 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 8.2 on ubuntu-latest

Method Icinga\Module\Jira\Web\Table\IssueDetails::setLinkToMonitoringService() has no return type specified.
{
$this->serviceLink = $serviceLink;
}

protected function setLinkToMonitoringHost(HtmlElement $hostLink)

Check failure on line 243 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 7.3 on ubuntu-latest

Method Icinga\Module\Jira\Web\Table\IssueDetails::setLinkToMonitoringHost() has no return type specified.

Check failure on line 243 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 8.0 on ubuntu-latest

Method Icinga\Module\Jira\Web\Table\IssueDetails::setLinkToMonitoringHost() has no return type specified.

Check failure on line 243 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 7.2 on ubuntu-latest

Method Icinga\Module\Jira\Web\Table\IssueDetails::setLinkToMonitoringHost() has no return type specified.

Check failure on line 243 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 8.1 on ubuntu-latest

Method Icinga\Module\Jira\Web\Table\IssueDetails::setLinkToMonitoringHost() has no return type specified.

Check failure on line 243 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 7.4 on ubuntu-latest

Method Icinga\Module\Jira\Web\Table\IssueDetails::setLinkToMonitoringHost() has no return type specified.

Check failure on line 243 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 8.2 on ubuntu-latest

Method Icinga\Module\Jira\Web\Table\IssueDetails::setLinkToMonitoringHost() has no return type specified.
{
$this->hostLink = $hostLink;
}

protected function getLinkToMonitoringHost()

Check failure on line 248 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 7.3 on ubuntu-latest

Method Icinga\Module\Jira\Web\Table\IssueDetails::getLinkToMonitoringHost() has no return type specified.

Check failure on line 248 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 8.0 on ubuntu-latest

Method Icinga\Module\Jira\Web\Table\IssueDetails::getLinkToMonitoringHost() has no return type specified.

Check failure on line 248 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 7.2 on ubuntu-latest

Method Icinga\Module\Jira\Web\Table\IssueDetails::getLinkToMonitoringHost() has no return type specified.

Check failure on line 248 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 8.1 on ubuntu-latest

Method Icinga\Module\Jira\Web\Table\IssueDetails::getLinkToMonitoringHost() has no return type specified.

Check failure on line 248 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 7.4 on ubuntu-latest

Method Icinga\Module\Jira\Web\Table\IssueDetails::getLinkToMonitoringHost() has no return type specified.

Check failure on line 248 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 8.2 on ubuntu-latest

Method Icinga\Module\Jira\Web\Table\IssueDetails::getLinkToMonitoringHost() has no return type specified.
{
return $this->hostLink;
}

protected function getLinkToMonitoringService()

Check failure on line 253 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 7.3 on ubuntu-latest

Method Icinga\Module\Jira\Web\Table\IssueDetails::getLinkToMonitoringService() has no return type specified.

Check failure on line 253 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 8.0 on ubuntu-latest

Method Icinga\Module\Jira\Web\Table\IssueDetails::getLinkToMonitoringService() has no return type specified.

Check failure on line 253 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 7.2 on ubuntu-latest

Method Icinga\Module\Jira\Web\Table\IssueDetails::getLinkToMonitoringService() has no return type specified.

Check failure on line 253 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 8.1 on ubuntu-latest

Method Icinga\Module\Jira\Web\Table\IssueDetails::getLinkToMonitoringService() has no return type specified.

Check failure on line 253 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 7.4 on ubuntu-latest

Method Icinga\Module\Jira\Web\Table\IssueDetails::getLinkToMonitoringService() has no return type specified.

Check failure on line 253 in library/Jira/Web/Table/IssueDetails.php

View workflow job for this annotation

GitHub Actions / Static analysis for php 8.2 on ubuntu-latest

Method Icinga\Module\Jira\Web\Table\IssueDetails::getLinkToMonitoringService() has no return type specified.
{
return $this->serviceLink;
}
}

0 comments on commit 29a90f6

Please sign in to comment.