Skip to content

Commit

Permalink
Try even harder to not fail badly if some results are missing
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg committed Jul 24, 2024
1 parent 7196c63 commit 8611fa5
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 26 deletions.
2 changes: 1 addition & 1 deletion library/Icingadb/Common/TicketLinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ public function createTicketLinks($text): string
return $tickets->createLinks($text);
}

return $text;
return $text ?? '';
}
}
2 changes: 1 addition & 1 deletion library/Icingadb/Compat/CompatObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 36 additions & 14 deletions library/Icingadb/Widget/Detail/EventDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'))
)
];

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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]
Expand All @@ -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'))
Expand All @@ -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()
)
Expand Down
4 changes: 3 additions & 1 deletion library/Icingadb/Widget/Detail/ObjectDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
8 changes: 7 additions & 1 deletion library/Icingadb/Widget/Detail/ServiceMetaInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,6 +17,8 @@

class ServiceMetaInfo extends BaseHtmlElement
{
use Translation;

protected $tag = 'div';

protected $defaultAttributes = ['class' => 'object-meta-info'];
Expand All @@ -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')
)
);

Expand Down
14 changes: 8 additions & 6 deletions library/Icingadb/Widget/ItemList/BaseHistoryListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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':
Expand Down
12 changes: 10 additions & 2 deletions library/Icingadb/Widget/ItemTable/StateRowItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down

0 comments on commit 8611fa5

Please sign in to comment.