diff --git a/library/Icingadb/Common/TicketLinks.php b/library/Icingadb/Common/TicketLinks.php index 6cf7e7687..3fb01c60b 100644 --- a/library/Icingadb/Common/TicketLinks.php +++ b/library/Icingadb/Common/TicketLinks.php @@ -51,6 +51,6 @@ public function createTicketLinks($text): string return $tickets->createLinks($text); } - return $text; + return $text ?? ''; } } diff --git a/library/Icingadb/Compat/CompatObject.php b/library/Icingadb/Compat/CompatObject.php index 1d9657db8..8434ced72 100644 --- a/library/Icingadb/Compat/CompatObject.php +++ b/library/Icingadb/Compat/CompatObject.php @@ -61,7 +61,7 @@ public static function fromModel(Model $object) */ public function getName(): string { - return $this->object->name; + return $this->object->name ?? ''; } public function fetch(): bool diff --git a/library/Icingadb/Widget/Detail/EventDetail.php b/library/Icingadb/Widget/Detail/EventDetail.php index aaf76082f..232d5df62 100644 --- a/library/Icingadb/Widget/Detail/EventDetail.php +++ b/library/Icingadb/Widget/Detail/EventDetail.php @@ -126,7 +126,9 @@ protected function assembleNotificationEvent(NotificationHistory $notification) new HtmlElement('h2', null, Text::create(t('Event Info'))), new HorizontalKeyValue( t('Sent On'), - DateFormatter::formatDateTime($notification->send_time->getTimestamp()) + isset($notification->send_time) + ? DateFormatter::formatDateTime($notification->send_time->getTimestamp()) + : new EmptyState(t('n. a.')) ) ]; @@ -240,7 +242,9 @@ protected function assembleStateChangeEvent(StateHistory $stateChange) new HtmlElement('h2', null, Text::create(t('Event Info'))), new HorizontalKeyValue( t('Occurred On'), - DateFormatter::formatDateTime($stateChange->event_time->getTimestamp()) + isset($stateChange->event_time) + ? DateFormatter::formatDateTime($stateChange->event_time->getTimestamp()) + : new EmptyState(t('n. a.')) ), new HorizontalKeyValue(t('Scheduling Source'), $stateChange->scheduling_source), new HorizontalKeyValue(t('Check Source'), $stateChange->check_source) @@ -332,29 +336,41 @@ protected function assembleDowntimeEvent(DowntimeHistory $downtime) )); $eventInfo[] = new HorizontalKeyValue( t('Entered On'), - DateFormatter::formatDateTime($downtime->entry_time->getTimestamp()) + isset($downtime->entry_time) + ? DateFormatter::formatDateTime($downtime->entry_time->getTimestamp()) + : new EmptyState(t('n. a.')) ); $eventInfo[] = new HorizontalKeyValue(t('Author'), [new Icon('user'), $downtime->author]); // TODO: The following should be presented in a specific widget (maybe just like the downtime card) $eventInfo[] = new HorizontalKeyValue( t('Triggered On'), - DateFormatter::formatDateTime($downtime->trigger_time->getTimestamp()) + isset($downtime->trigger_time) + ? DateFormatter::formatDateTime($downtime->trigger_time->getTimestamp()) + : new EmptyState(t('n. a.')) ); $eventInfo[] = new HorizontalKeyValue( t('Scheduled Start'), - DateFormatter::formatDateTime($downtime->scheduled_start_time->getTimestamp()) + isset($downtime->scheduled_start_time) + ? DateFormatter::formatDateTime($downtime->scheduled_start_time->getTimestamp()) + : new EmptyState(t('n. a.')) ); $eventInfo[] = new HorizontalKeyValue( t('Actual Start'), - DateFormatter::formatDateTime($downtime->start_time->getTimestamp()) + isset($downtime->start_time) + ? DateFormatter::formatDateTime($downtime->start_time->getTimestamp()) + : new EmptyState(t('n. a.')) ); $eventInfo[] = new HorizontalKeyValue( t('Scheduled End'), - DateFormatter::formatDateTime($downtime->scheduled_end_time->getTimestamp()) + isset($downtime->scheduled_end_time) + ? DateFormatter::formatDateTime($downtime->scheduled_end_time->getTimestamp()) + : new EmptyState(t('n. a.')) ); $eventInfo[] = new HorizontalKeyValue( t('Actual End'), - DateFormatter::formatDateTime($downtime->end_time->getTimestamp()) + isset($downtime->end_time) + ? DateFormatter::formatDateTime($downtime->end_time->getTimestamp()) + : new EmptyState(t('n. a.')) ); if ($downtime->is_flexible) { @@ -410,7 +426,9 @@ protected function assembleCommentEvent(CommentHistory $comment) )); $eventInfo[] = new HorizontalKeyValue( t('Entered On'), - DateFormatter::formatDateTime($comment->entry_time->getTimestamp()) + isset($comment->entry_time) + ? DateFormatter::formatDateTime($comment->entry_time->getTimestamp()) + : new EmptyState(t('n. a.')) ); $eventInfo[] = new HorizontalKeyValue(t('Author'), [new Icon('user'), $comment->author]); $eventInfo[] = new HorizontalKeyValue( @@ -478,7 +496,9 @@ protected function assembleFlappingEvent(FlappingHistory $flapping) )), new HorizontalKeyValue( t('Started on'), - DateFormatter::formatDateTime($flapping->start_time->getTimestamp()) + isset($flapping->start_time) + ? DateFormatter::formatDateTime($flapping->start_time->getTimestamp()) + : new EmptyState(t('n. a.')) ) ]; if ($this->event->event_type === 'flapping_start') { @@ -520,7 +540,9 @@ protected function assembleAcknowledgeEvent(AcknowledgementHistory $acknowledgem new HtmlElement('h2', null, Text::create(t('Event Info'))), new HorizontalKeyValue( t('Set on'), - DateFormatter::formatDateTime($acknowledgement->set_time->getTimestamp()) + isset($acknowledgement->set_time) + ? DateFormatter::formatDateTime($acknowledgement->set_time->getTimestamp()) + : new EmptyState(t('n. a.')) ), new HorizontalKeyValue(t('Author'), $acknowledgement->author ? [new Icon('user'), $acknowledgement->author] @@ -546,8 +568,8 @@ protected function assembleAcknowledgeEvent(AcknowledgementHistory $acknowledgem $eventInfo[] = new HorizontalKeyValue( t('Expires On'), $acknowledgement->expire_time - ? DateFormatter::formatDateTime($acknowledgement->expire_time->getTimestamp()) - : new EmptyState(t('Never')) + ? DateFormatter::formatDateTime($acknowledgement->expire_time->getTimestamp()) + : new EmptyState(t('Never')) ); $eventInfo[] = new HorizontalKeyValue(t('Sticky'), isset($acknowledgement->is_sticky) ? ($acknowledgement->is_sticky ? t('Yes') : t('No')) @@ -559,7 +581,7 @@ protected function assembleAcknowledgeEvent(AcknowledgementHistory $acknowledgem $eventInfo[] = new HorizontalKeyValue( t('Cleared on'), DateFormatter::formatDateTime( - $acknowledgement->clear_time + $acknowledgement->clear_time !== null ? $acknowledgement->clear_time->getTimestamp() : $this->event->event_time->getTimestamp() ) diff --git a/library/Icingadb/Widget/Detail/ObjectDetail.php b/library/Icingadb/Widget/Detail/ObjectDetail.php index 4ba0e6984..4aacd46f9 100644 --- a/library/Icingadb/Widget/Detail/ObjectDetail.php +++ b/library/Icingadb/Widget/Detail/ObjectDetail.php @@ -111,7 +111,9 @@ protected function createPrintHeader() $info[] = new HorizontalKeyValue( t('Last State Change'), - DateFormatter::formatDateTime($this->object->state->last_state_change->getTimestamp()) + isset($this->object->state->last_state_change) + ? DateFormatter::formatDateTime($this->object->state->last_state_change) + : new EmptyState(t('n. a.')) ); return [ diff --git a/library/Icingadb/Widget/Detail/ServiceMetaInfo.php b/library/Icingadb/Widget/Detail/ServiceMetaInfo.php index cca723763..faca1f921 100644 --- a/library/Icingadb/Widget/Detail/ServiceMetaInfo.php +++ b/library/Icingadb/Widget/Detail/ServiceMetaInfo.php @@ -6,6 +6,8 @@ use Icinga\Date\DateFormatter; use Icinga\Module\Icingadb\Model\Service; +use ipl\I18n\Translation; +use ipl\Web\Widget\EmptyState; use ipl\Web\Widget\VerticalKeyValue; use ipl\Html\Attributes; use ipl\Html\BaseHtmlElement; @@ -15,6 +17,8 @@ class ServiceMetaInfo extends BaseHtmlElement { + use Translation; + protected $tag = 'div'; protected $defaultAttributes = ['class' => 'object-meta-info']; @@ -33,7 +37,9 @@ protected function assemble() new VerticalKeyValue('service.name', $this->service->name), new VerticalKeyValue( 'last_state_change', - DateFormatter::formatDateTime($this->service->state->last_state_change->getTimestamp()) + isset($this->service->state->last_state_change) + ? DateFormatter::formatDateTime($this->service->state->last_state_change->getTimestamp()) + : (new EmptyState($this->translate('n. a.')))->setTag('span') ) ); diff --git a/library/Icingadb/Widget/ItemList/BaseHistoryListItem.php b/library/Icingadb/Widget/ItemList/BaseHistoryListItem.php index 6999324d5..61da9fd1d 100644 --- a/library/Icingadb/Widget/ItemList/BaseHistoryListItem.php +++ b/library/Icingadb/Widget/ItemList/BaseHistoryListItem.php @@ -94,10 +94,12 @@ protected function assembleCaption(BaseHtmlElement $caption): void t('State Change Rate: %.2f%%; End Threshold: %.2f%%; Flapping for %s'), $this->item->flapping->percent_state_change_end, $this->item->flapping->flapping_threshold_low, - DateFormatter::formatDuration( - $this->item->flapping->end_time->getTimestamp() - - $this->item->flapping->start_time->getTimestamp() - ) + isset($this->item->flapping->end_time) + ? DateFormatter::formatDuration( + $this->item->flapping->end_time->getTimestamp() + - $this->item->flapping->start_time->getTimestamp() + ) + : t('n. a.') )) ->getAttributes() ->add('class', 'plugin-output'); @@ -345,10 +347,10 @@ protected function assembleTitle(BaseHtmlElement $title): void break; case 'notification': - $subjectLabel = sprintf( + $subjectLabel = isset($this->item->notification->type) ? sprintf( NotificationListItem::phraseForType($this->item->notification->type), ucfirst($this->item->object_type) - ); + ) : $this->item->event_type; break; case 'state_change': diff --git a/library/Icingadb/Widget/ItemTable/StateRowItem.php b/library/Icingadb/Widget/ItemTable/StateRowItem.php index 7ca93921c..410ec7e76 100644 --- a/library/Icingadb/Widget/ItemTable/StateRowItem.php +++ b/library/Icingadb/Widget/ItemTable/StateRowItem.php @@ -77,12 +77,20 @@ protected function assembleCell(BaseHtmlElement $cell, string $path, $value) case $path === 'state.last_update': case $path === 'state.last_state_change': $column = substr($path, 6); - $cell->addHtml(new TimeSince($this->item->state->$column->getTimestamp())); + $cell->addHtml( + isset($this->item->state->$column) + ? new TimeSince($this->item->state->$column->getTimestamp()) + : new EmptyState(t('n. a.')) + ); break; case $path === 'state.next_check': case $path === 'state.next_update': $column = substr($path, 6); - $cell->addHtml(new TimeUntil($this->item->state->$column->getTimestamp())); + $cell->addHtml( + isset($this->item->state->$column) + ? new TimeUntil($this->item->state->$column->getTimestamp()) + : new EmptyState(t('n. a.')) + ); break; case $path === 'state.performance_data': case $path === 'state.normalized_performance_data':