Skip to content

Commit

Permalink
Add last state change time to issue description
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 committed Jan 11, 2023
1 parent 5955dc0 commit fb287da
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion library/Jira/MonitoringInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Icinga\Module\Jira;

use Icinga\Date\DateFormatter;
use Icinga\Exception\IcingaException;
use Icinga\Module\Icingadb\Model\CustomvarFlat;
use Icinga\Module\Monitoring\Object\Host;
Expand Down Expand Up @@ -121,6 +122,19 @@ public function getStateName()
return strtoupper($this->object->state->getStateText());
}

public function getLastStateChange()
{
if ($this->object instanceof MonitoredObject) {
if ($this->object instanceof Service) {
return DateFormatter::formatDateTime($this->object->last_state_change);
}

return DateFormatter::formatDateTime($this->object->last_state_change);
}

return DateFormatter::formatDateTime($this->object->state->last_state_change);
}

public function getOutput()
{
if ($this->object instanceof MonitoredObject) {
Expand All @@ -134,7 +148,7 @@ public function getOutput()
}

return $this->object->state->output . "\n"
. str_replace('\n', "\n", $this->object->state->long_output);
. str_replace('\n', "\n", $this->object->state->long_output ?? '');
}

public function hostVars()
Expand Down Expand Up @@ -213,6 +227,8 @@ public function getDescriptionHeader()

$description .= sprintf("Host: %s\n", $hostLink);

$description .= sprintf("Last icinga state change: %s\n", $this->getLastStateChange());

return $description;
}

Expand Down

0 comments on commit fb287da

Please sign in to comment.