Skip to content

Commit

Permalink
Event and Incident History improvements (#166)
Browse files Browse the repository at this point in the history
resolves #157
  • Loading branch information
nilmerg authored May 8, 2024
2 parents 89cfdb8 + 25f723d commit e044065
Show file tree
Hide file tree
Showing 12 changed files with 234 additions and 108 deletions.
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
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
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
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
* @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
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

0 comments on commit e044065

Please sign in to comment.