From d6dc7f203b03d4a18c0bab789e3fb312edd32de6 Mon Sep 17 00:00:00 2001 From: raviks789 <33730024+raviks789@users.noreply.github.com> Date: Tue, 13 Feb 2024 15:27:22 +0100 Subject: [PATCH] SendCommand: Check if backend has the object before creating an issue --- application/clicommands/SendCommand.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/application/clicommands/SendCommand.php b/application/clicommands/SendCommand.php index b2be309..0b06bcc 100644 --- a/application/clicommands/SendCommand.php +++ b/application/clicommands/SendCommand.php @@ -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; @@ -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')) { @@ -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