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

Event and Incident History improvements #166

Merged
merged 12 commits into from
May 8, 2024
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
6 changes: 4 additions & 2 deletions library/Notifications/Common/Icons.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private function __construct()

public const USER_MANAGER = 'user-tie';

public const CLOSED = 'circle-check';
public const CLOSED = 'check';

public const OPENED = 'sun';

Expand All @@ -38,5 +38,7 @@ private function __construct()

public const NOTIFIED = 'paper-plane';

public const RULE_MATCHED = 'filter-check-circle';
public const RULE_MATCHED = 'filter';

public const UNDEFINED = 'notdef';
}
13 changes: 12 additions & 1 deletion library/Notifications/Model/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Icinga\Module\Notifications\Model;

use DateTime;
use Icinga\Module\Notifications\Common\Database;
use ipl\Orm\Behavior\Binary;
use ipl\Orm\Behavior\MillisecondTimestamp;
Expand All @@ -17,7 +18,17 @@
/**
* Event model
*
* @property Query|Incident $incident
* @property int $id
* @property DateTime $time
* @property string $object_id
* @property string $type
* @property ?string $severity
* @property ?string $message
* @property ?string $username
*
* @property Query | Objects $object
* @property Query | IncidentHistory $incident_history
* @property Query | Incident $incident
*/
class Event extends Model
{
Expand Down
21 changes: 17 additions & 4 deletions library/Notifications/Model/Incident.php
ncosta-ic marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Icinga\Module\Notifications\Model;

use DateTime;
use Icinga\Module\Notifications\Common\Database;
use ipl\Orm\Behavior\Binary;
use ipl\Orm\Behavior\MillisecondTimestamp;
Expand All @@ -18,6 +19,18 @@
* Incident Model
*
* @property int $id
* @property string $object_id
* @property DateTime $started_at
* @property ?DateTime $recovered_at
* @property string $severity
*
* @property Query | Objects $object
* @property Query | Event $event
* @property Query | Contact $contact
* @property Query | IncidentContact $incident_contact
* @property Query | IncidentHistory $incident_history
* @property Query | Rule $rule
* @property Query | RuleEscalation $rule_escalation
*/
class Incident extends Model
{
Expand All @@ -44,10 +57,10 @@ public function getColumns()
public function getColumnDefinitions()
{
return [
'object_id' => t('Object Id'),
'started_at' => t('Started At'),
'recovered_at' => t('Recovered At'),
'severity' => t('Severity')
'object_id' => t('Object Id'),
'started_at' => t('Started At'),
'recovered_at' => t('Recovered At'),
'severity' => t('Severity')
];
}

Expand Down
31 changes: 30 additions & 1 deletion library/Notifications/Model/IncidentHistory.php
ncosta-ic marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,40 @@

namespace Icinga\Module\Notifications\Model;

use DateTime;
use ipl\Orm\Behavior\MillisecondTimestamp;
use ipl\Orm\Behaviors;
use ipl\Orm\Model;
use ipl\Orm\Query;
use ipl\Orm\Relations;

/**
* IncidentHistory
*
* @property int $id
* @property int $incident_id
* @property ?int $event_id
* @property ?int $rule_id
* @property ?int $rule_escalation_id
* @property DateTime $time
* @property string $type
* @property ?int $contact_id
* @property ?int $channel_id
* @property ?string $new_severity
* @property ?string $old_severity
* @property ?string $new_recipient_role
* @property ?string $old_recipient_role
* @property ?string $message
*
* @property Query | Incident $incident
* @property Query | Event $event
* @property Query | Contact $contact
* @property Query | Contactgroup $contactgroup
* @property Query | Schedule $schedule
* @property Query | Rule $rule
* @property Query | RuleEscalation $rule_escalation
* @property Query | Channel $channel
*/
class IncidentHistory extends Model
{
public function getTableName()
Expand Down Expand Up @@ -69,7 +98,7 @@ public function createBehaviors(Behaviors $behaviors)

public function getDefaultSort()
{
return ['incident_history.time desc'];
return ['incident_history.time desc, incident_history.type desc'];
}

public function createRelations(Relations $relations)
Expand Down
16 changes: 16 additions & 0 deletions library/Notifications/Model/Objects.php
ncosta-ic marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,25 @@
use ipl\Orm\Behavior\Binary;
use ipl\Orm\Behaviors;
use ipl\Orm\Model;
use ipl\Orm\Query;
use ipl\Orm\Relations;

/**
* Object
*
* @property string $id
* @property int $source_id
* @property string $name
* @property string $host
* @property ?string $service
ncosta-ic marked this conversation as resolved.
Show resolved Hide resolved
* @property ?string $url
*
* @property Query | Event $event
* @property Query | Incident $incident
* @property Query | Tag $tag
* @property Query | ObjectExtraTag $object_extra_tag
* @property Query | ExtraTag $extra_tag
* @property Query | Source $source
* @property array<string, string> $id_tags
*/
class Objects extends Model
Expand Down
15 changes: 11 additions & 4 deletions library/Notifications/Widget/Detail/EventDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,17 @@ protected function createIncident(): ?array
/** @return ValidHtml[] */
protected function createSource(): array
{
return [
Html::tag('h2', t('Source')),
new EventSourceBadge($this->event->object->source)
];
$elements = [];
if ($this->event->type === 'internal') {
// return no source elements for internal events
return $elements;
}

$elements[] = Html::tag('h2', t('Source'));

$elements[] = new EventSourceBadge($this->event->object->source);

return $elements;
}

protected function assemble()
Expand Down
35 changes: 12 additions & 23 deletions library/Notifications/Widget/Detail/IncidentDetail.php
ncosta-ic marked this conversation as resolved.
Show resolved Hide resolved
ncosta-ic marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Icinga\Module\Notifications\Widget\Detail;

use Icinga\Module\Notifications\Common\Database;
use Icinga\Module\Notifications\Model\Incident;
use Icinga\Module\Notifications\Model\Objects;
use Icinga\Module\Notifications\Widget\EventSourceBadge;
Expand All @@ -15,8 +14,6 @@
use ipl\Html\Html;
use ipl\Html\HtmlElement;
use ipl\Html\Table;
use ipl\Orm\Query;
use ipl\Sql\Select;
use ipl\Web\Widget\Link;
use ipl\Web\Widget\StateBall;

Expand Down Expand Up @@ -93,28 +90,20 @@ protected function createRelatedObject()

protected function createHistory()
{
$history = $this->incident->incident_history
->with([
'event',
'incident.object',
'incident.object.source',
'contact',
'rule',
'rule_escalation',
'contactgroup',
'schedule',
'channel'
]);

$history
->withColumns('incident.object.id_tags')
->on(Query::ON_SELECT_ASSEMBLED, function (Select $select) use ($history) {
Database::registerGroupBy($history, $select);
});

return [
Html::tag('h2', t('Incident History')),
new IncidentHistoryList($history)
new IncidentHistoryList(
$this->incident->incident_history
->with([
'incident.object.source',
'contact',
'rule',
'rule_escalation',
'contactgroup',
'schedule',
'channel'
])
)
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function assembleUnsubscribeButton(): void
'unsubscribe',
[
'class' => ['control-button', 'spinner'],
'label' => [new Icon(Icons::UNSUBSCRIBED), t('Unubscribe')],
'label' => [new Icon(Icons::UNSUBSCRIBED), t('Unsubscribe')],
'title' => t('Unsubscribe from this incident')
]
);
Expand Down
25 changes: 25 additions & 0 deletions library/Notifications/Widget/IconBall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/* Icinga Notifications Web | (c) 2024 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Notifications\Widget;

use ipl\Html\BaseHtmlElement;
use ipl\Web\Widget\Icon;

class IconBall extends BaseHtmlElement
{
protected $tag = 'span';

protected $defaultAttributes = ['class' => ['icon-ball']];

public function __construct(string $name, ?string $style = 'fa-solid')
{
$icon = new Icon($name);
if ($style !== null) {
$icon->setStyle($style);
}

$this->addHtml($icon);
}
}
Loading
Loading