Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directly link objects to their source #117

Merged
merged 7 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion application/controllers/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function indexAction(): void
$id = $this->params->getRequired('id');

$query = Event::on(Database::get())
->with(['source', 'object', 'source_object', 'incident', 'incident.object'])
->with(['object', 'object.source', 'incident', 'incident.object'])
->filter(Filter::equal('event.id', $id));

// ipl-orm doesn't detect dependent joins yet
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/EventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function indexAction(): void
$compact = $this->view->compact;

$events = Event::on(Database::get())
->with(['source', 'object', 'incident']);
->with(['object', 'object.source', 'incident']);

$limitControl = $this->createLimitControl();
$sortControl = $this->createSortControl(
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/IncidentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function indexAction(): void
$id = $this->params->getRequired('id');

$query = Incident::on(Database::get())
->with(['object'])
->with(['object', 'object.source'])
->filter(Filter::equal('incident.id', $id));

$this->applyRestrictions($query);
Expand Down
7 changes: 0 additions & 7 deletions library/Notifications/Model/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public function getColumns()
{
return [
'time',
'source_id',
'object_id',
'type',
'severity',
Expand All @@ -39,7 +38,6 @@ public function getColumnDefinitions()
{
return [
'time' => t('Received On'),
'source_id' => t('Source Id'),
'object_id' => t('Object Id'),
'type' => t('Type'),
'severity' => t('Severity'),
Expand All @@ -66,7 +64,6 @@ public function createBehaviors(Behaviors $behaviors)

public function createRelations(Relations $relations)
{
$relations->belongsTo('source', Source::class)->setJoinType('LEFT');
$relations->belongsTo('object', Objects::class)->setJoinType('LEFT');

$relations->hasOne('incident_history', IncidentHistory::class);
Expand All @@ -75,10 +72,6 @@ public function createRelations(Relations $relations)
->belongsToOne('incident', Incident::class)
->through('incident_event')
->setJoinType('LEFT');

$relations
->belongsTo('source_object', SourceObject::class)
->setCandidateKey(['source_id', 'object_id']);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions library/Notifications/Model/ObjectExtraTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ public function getTableName()

public function getKeyName()
{
return ['object_id', 'source_id', 'tag'];
return ['object_id', 'tag'];
}

public function getColumns()
{
return [
'object_id',
'source_id',
'tag',
'value'
];
Expand All @@ -38,7 +37,6 @@ public function createBehaviors(Behaviors $behaviors)

public function createRelations(Relations $relations)
{
$relations->belongsTo('source', Source::class);
$relations->belongsTo('object', Objects::class);
}
}
7 changes: 5 additions & 2 deletions library/Notifications/Model/Objects.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ public function getKeyName()
public function getColumns()
{
return [
'source_id',
'host',
'service'
'service',
'name',
'url'
];
}

Expand Down Expand Up @@ -56,7 +59,7 @@ public function createRelations(Relations $relations)
{
$relations->hasMany('event', Event::class);
$relations->hasMany('incident', Incident::class);
$relations->hasMany('source_object', SourceObject::class);
$relations->belongsTo('source', Source::class);
$relations->hasMany('object_extra_tag', ObjectExtraTag::class)
->setJoinType('LEFT');
}
Expand Down
5 changes: 1 addition & 4 deletions library/Notifications/Model/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ public function getDefaultSort()

public function createRelations(Relations $relations)
{
$relations->hasMany('event', Event::class);
$relations->hasMany('source_object', SourceObject::class);
$relations->hasMany('object_extra_tag', ObjectExtraTag::class)
->setJoinType('LEFT');
$relations->hasMany('object', Objects::class);
}

/**
Expand Down
54 changes: 0 additions & 54 deletions library/Notifications/Model/SourceObject.php

This file was deleted.

4 changes: 2 additions & 2 deletions library/Notifications/Widget/Detail/EventDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected function createRelatedObject(): array
{
//TODO(sd): This is just placeholder. Add hook implementation instead
$relatedObj = Html::tag('ul', ['class' => ['item-list', 'action-list'], 'data-base-target' => '_next']);
$obj = new Link($this->event->object->host, $this->event->source_object->url, ['class' => 'subject']);
$obj = new Link($this->event->object->host, $this->event->object->url, ['class' => 'subject']);

if ($this->event->object->service) {
$obj = Html::sprintf(
Expand Down Expand Up @@ -120,7 +120,7 @@ protected function createSource(): array
{
return [
Html::tag('h2', t('Source')),
new EventSourceBadge($this->event->source)
new EventSourceBadge($this->event->object->source)
];
}

Expand Down
87 changes: 27 additions & 60 deletions library/Notifications/Widget/Detail/IncidentDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
use Icinga\Module\Notifications\Common\Database;
use Icinga\Module\Notifications\Model\Incident;
use Icinga\Module\Notifications\Model\Source;
use Icinga\Module\Notifications\Model\SourceObject;
use Icinga\Module\Notifications\Widget\EventSourceBadge;
use Icinga\Module\Notifications\Widget\ItemList\IncidentContactList;
use Icinga\Module\Notifications\Widget\ItemList\IncidentHistoryList;
use Icinga\Module\Notifications\Widget\ItemList\ObjectLabelList;
use ipl\Html\Attributes;
use ipl\Html\BaseHtmlElement;
use ipl\Html\Html;
Expand Down Expand Up @@ -59,46 +57,35 @@ protected function createRelatedObject()
//TODO(sd): Add hook implementation
$list = Html::tag('ul', ['class' => ['item-list', 'minimal', 'action-list'], 'data-base-target' => '_next']);

$objects = [];
//TODO(sd): check sortby order
foreach ($this->incident->object->source_object as $sourceObj) {
$objects[] = new Link($this->incident->object->host, $sourceObj->url, ['class' => 'subject']);
}

if ($this->incident->object->service) {
$newObjects = [];
foreach ($objects as $object) {
$newObjects[] = Html::sprintf(
t('%s on %s', '<service> on <host>'),
$object->setContent($this->incident->object->service),
Html::tag('span', ['class' => 'subject'], $this->incident->object->host)
);
}

$objects = $newObjects;
$objectLink = Html::sprintf(
t('%s on %s', '<service> on <host>'),
new Link($this->incident->object->service, $this->incident->object->url, ['class' => 'subject']),
Html::tag('span', ['class' => 'subject'], $this->incident->object->host)
);
} else {
$objectLink = new Link($this->incident->object->host, $this->incident->object->url, ['class' => 'subject']);
}

foreach ($objects as $object) {
$list->add(Html::tag(
'li',
['class' => 'list-item', 'data-action-item' => true],
[ //TODO(sd): fix stateball
Html::tag(
'div',
['class' => 'visual'],
new StateBall('down', StateBall::SIZE_LARGE)
),
Html::tag(
'div',
['class' => 'main'],
Html::tag('header')->add(Html::tag('div', ['class' => 'title'], $object))
)
]
));
}
$list->add(Html::tag(
'li',
['class' => 'list-item', 'data-action-item' => true],
[ //TODO(sd): fix stateball
Html::tag(
'div',
['class' => 'visual'],
new StateBall('down', StateBall::SIZE_LARGE)
),
Html::tag(
'div',
['class' => 'main'],
Html::tag('header')->add(Html::tag('div', ['class' => 'title'], $objectLink))
)
]
));

return [
Html::tag('h2', t('Objects')),
Html::tag('h2', t('Object')),
$list
];
}
Expand All @@ -111,8 +98,8 @@ protected function createHistory()
$this->incident->incident_history
->with([
'event',
'event.source',
'event.object',
'event.object.source',
'contact',
'rule',
'rule_escalation',
Expand All @@ -126,15 +113,10 @@ protected function createHistory()
protected function createSource()
{
$list = new HtmlElement('ul', Attributes::create(['class' => 'source-list']));

$sources = Source::on(Database::get())
->filter(Filter::equal('event.incident.id', $this->incident->id));
foreach ($sources as $source) {
$list->addHtml(new HtmlElement('li', null, new EventSourceBadge($source)));
}
$list->addHtml(new HtmlElement('li', null, new EventSourceBadge($this->incident->object->source)));

return [
Html::tag('h2', t('Event Sources')),
Html::tag('h2', t('Event Source')),
$list
];
}
Expand All @@ -153,20 +135,6 @@ protected function createObjectTag()
];
}

protected function createObjectLabel()
{
$objectId = $this->incident->object->id;

$sourceObjects = SourceObject::on(Database::get())->with('source');

$sourceObjects->filter(Filter::equal('object_id', $objectId));

return [
Html::tag('h2', t('Object Labels')),
new ObjectLabelList($sourceObjects)
];
}

protected function assemble()
{
$this->add([
Expand All @@ -175,7 +143,6 @@ protected function assemble()
$this->createRelatedObject(),
$this->createSource(),
$this->createObjectTag(),
$this->createObjectLabel()
]);
}
}
2 changes: 1 addition & 1 deletion library/Notifications/Widget/ItemList/EventListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected function assembleHeader(BaseHtmlElement $header): void
['class' => 'meta'],
[
(new SourceIcon(SourceIcon::SIZE_BIG))
->addHtml($this->item->source->getIcon()),
->addHtml($this->item->object->source->getIcon()),
new TimeAgo($this->item->time->getTimestamp())
]
));
Expand Down
Loading