Skip to content

Commit

Permalink
Add pending notifications incident history messages
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Apr 26, 2024
1 parent 0a3b06c commit 5c50f4b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 13 deletions.
25 changes: 23 additions & 2 deletions library/Notifications/Model/IncidentHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@

namespace Icinga\Module\Notifications\Model;

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

/**
* @property string $notification_state
* @property DateTime $sent_at
*/
class IncidentHistory extends Model
{
public function getTableName()
Expand Down Expand Up @@ -38,7 +43,9 @@ public function getColumns()
'old_severity',
'new_recipient_role',
'old_recipient_role',
'message'
'message',
'notification_state',
'sent_at'
];
}

Expand All @@ -64,7 +71,7 @@ public function getColumnDefinitions()

public function createBehaviors(Behaviors $behaviors)
{
$behaviors->add(new MillisecondTimestamp(['time']));
$behaviors->add(new MillisecondTimestamp(['time', 'sent_at']));
}

public function getDefaultSort()
Expand All @@ -84,4 +91,18 @@ public function createRelations(Relations $relations)
$relations->belongsTo('rule_escalation', RuleEscalation::class)->setJoinType('LEFT');
$relations->belongsTo('channel', Channel::class)->setJoinType('LEFT');
}

public static function translateNotificationState(string $state): string
{
switch ($state) {
case 'sent':
return t('sent', 'contact.notifications.state');
case 'failed':
return t('failed', 'contact.notifications.state');
case 'pending':
return t('pending', 'contact.notifications.state');
default:
return t('unknown', 'contact.notifications.state');
}
}
}
49 changes: 38 additions & 11 deletions library/Notifications/Widget/ItemList/IncidentHistoryListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,24 +157,51 @@ protected function buildMessage(): string
break;
case "notified":
if ($this->item->contactgroup_id) {
$message = sprintf(
t('Contact %s notified via %s as member of contact group %s'),
$this->item->contact->full_name,
$this->item->channel->type,
$this->item->contactgroup->name
);
if ($this->item->notification_state === 'sent') {
$message = sprintf(
t('Contact %s notified via %s as member of contact group %s'),
$this->item->contact->full_name,
$this->item->channel->type,
$this->item->contactgroup->name
);
} else {
$message = sprintf(
t('Contact %s notified via %s as member of contact group %s (%s)'),
$this->item->contact->full_name,
$this->item->channel->type,
$this->item->contactgroup->name,
IncidentHistory::translateNotificationState($this->item->notification_state)
);
}
} elseif ($this->item->schedule_id) {
if ($this->item->notfication_state === 'sent') {
$message = sprintf(
t('Contact %s notified via %s as member of schedule %s'),
$this->item->contact->full_name,
$this->item->channel->type,
$this->item->schedule->name
);
} else {
$message = sprintf(
t('Contact %s notified via %s as member of schedule %s (%s)'),
$this->item->contact->full_name,
$this->item->schedule->name,
$this->item->channel->type,
IncidentHistory::translateNotificationState($this->item->notification_state)
);
}
} elseif ($this->item->notification_state === 'sent') {
$message = sprintf(
t('Contact %s notified via %s as member of schedule %s'),
t('Contact %s notified via %s'),
$this->item->contact->full_name,
$this->item->channel->type,
$this->item->schedule->name
$this->item->channel->type
);
} else {
$message = sprintf(
t('Contact %s notified via %s'),
t('Contact %s notified via %s (%s)'),
$this->item->contact->full_name,
$this->item->channel->type
$this->item->channel->type,
IncidentHistory::translateNotificationState($this->item->notification_state)
);
}
break;
Expand Down

0 comments on commit 5c50f4b

Please sign in to comment.