Skip to content

Commit

Permalink
SendCommand: Check if backend has the object before creating an issue
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 committed Apr 12, 2024
1 parent 9c24aad commit d6dc7f2
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions application/clicommands/SendCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Icinga\Application\Icinga;
use Icinga\Application\Logger;
use Icinga\Application\Config;
use Icinga\Exception\IcingaException;
use Icinga\Module\Jira\IcingaCommandPipe;
use Icinga\Module\Jira\Cli\Command;
use Icinga\Module\Jira\IcingadbBackend;
Expand Down Expand Up @@ -66,12 +67,6 @@ public function problemAction()
$description = $p->shiftRequired('description');
$duedate = $p->shift('due-date');
$project = $p->shiftRequired('project');

$jira = $this->jira();
$issue = $jira->eventuallyGetLatestOpenIssueFor($project, $host, $service);

$config = Config::module('jira');

$mm = $this->app->getModuleManager();
if ($p->shift('icingadb') || ! $mm->hasEnabled('monitoring')) {
if (! $mm->hasEnabled('icingadb')) {
Expand All @@ -87,6 +82,23 @@ public function problemAction()

$info = $backend->getMonitoringInfo($host, $service);

if (! $info->hasObject()) {
if ($service !== null) {
throw new IcingaException(
'No service "%s" found on host "%s"',
$service,
$host
);
} else {
throw new IcingaException('No such host found: %s', $host);
}
}

$jira = $this->jira();
$issue = $jira->eventuallyGetLatestOpenIssueFor($project, $host, $service);

$config = Config::module('jira');

if ($issue === null) {
if (\in_array($status, ['UP', 'OK'])) {
// No existing issue, no problem, nothing to do
Expand Down

0 comments on commit d6dc7f2

Please sign in to comment.