Skip to content
Open
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
30 changes: 17 additions & 13 deletions application/controllers/IncidentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@

use Icinga\Module\Notifications\Common\Auth;
use Icinga\Module\Notifications\Common\Database;
use Icinga\Module\Notifications\Hook\ObjectsRendererHook;
use Icinga\Module\Notifications\Model\Incident;
use Icinga\Module\Notifications\View\IncidentRenderer;
use Icinga\Module\Notifications\Web\Control\SearchBar\ObjectSuggestions;
use Icinga\Module\Notifications\Widget\ItemList\ObjectList;
use ipl\Web\Common\Controls;
use ipl\Web\Compat\CompatController;
use ipl\Web\Compat\SearchControls;
use ipl\Web\Control\LimitControl;
use ipl\Web\Control\SortControl;
use ipl\Web\Filter\QueryString;
use ipl\Web\Layout\DetailedItemLayout;
use ipl\Web\Layout\ItemLayout;
use ipl\Web\Layout\MinimalItemLayout;
use ipl\Web\Widget\ItemList;
use ipl\Web\Widget\ListItem;

class IncidentsController extends CompatController
{
use Auth;
use SearchControls;
use Controls;

public function indexAction(): void
{
Expand All @@ -45,11 +46,15 @@ public function indexAction(): void
);

$paginationControl = $this->createPaginationControl($incidents);
$viewModeSwitcher = $this->createViewModeSwitcher($this->params);
$searchBar = $this->createSearchBar($incidents, [
$limitControl->getLimitParam(),
$sortControl->getSortParam(),
]);

$this->applyViewModeLimit($limitControl, $paginationControl);
$this->handleControls($this->getServerRequest());

if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
if ($searchBar->hasBeenSubmitted()) {
$filter = QueryString::parse((string) $this->params);
Expand All @@ -68,18 +73,17 @@ public function indexAction(): void
$this->addControl($paginationControl);
$this->addControl($sortControl);
$this->addControl($limitControl);
$this->addControl($viewModeSwitcher);
$this->addControl($searchBar);

$incidentList = (new ObjectList($incidents, new IncidentRenderer()))
->setItemLayoutClass(MinimalItemLayout::class)
->on(ItemList::ON_ITEM_ADD, function (ListItem $item, Incident $data) {
ObjectsRendererHook::register($data->object);
})
->on(ItemList::ON_ASSEMBLED, function () {
ObjectsRendererHook::load();
});

$this->addContent($incidentList);
$this->addContent(
(new ObjectList($incidents, new IncidentRenderer()))
->setItemLayoutClass(match ($viewModeSwitcher->getViewMode()) {
'minimal' => MinimalItemLayout::class,
'detailed' => DetailedItemLayout::class,
'common' => ItemLayout::class
})
);

if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {
$this->sendMultipartUpdate();
Expand Down
15 changes: 15 additions & 0 deletions doc/03-Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ If you just installed Icinga Notifications Web, remember to activate it on your
| notifications/view/contacts | Allow to view contacts |
| notifications/api | Allow to modify configuration via API |

## General Configuration

There is currently one configurable option: the maximum number of characters of the incident
message shown in the incident detail view (default: 10000). It cannot be adjusted in the UI
directly, but has to be set in the configuration file `/etc/icingaweb2/modules/notifications/config.ini`.
Comment thread
sukhwinder33445 marked this conversation as resolved.

### Example

Setting the incident message character limit to 2500.

```
[settings]
incident_message_character_limit = 2500
```

## Database Configuration

Connection configuration for the database, which both,
Expand Down
6 changes: 1 addition & 5 deletions library/Notifications/Daemon/Daemon.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Evenement\EventEmitter;
use Icinga\Application\Logger;
use Icinga\Module\Notifications\Common\Database;
use Icinga\Module\Notifications\Hook\ObjectsRendererHook;
use Icinga\Module\Notifications\Model\BrowserSession;
use Icinga\Module\Notifications\Model\Daemon\Connection;
use Icinga\Module\Notifications\Model\Daemon\Event;
Expand Down Expand Up @@ -263,7 +262,6 @@ protected function processNotifications(): void
$notificationsToProcess = [];
foreach ($notifications as $notification) {
if ($notification->contact_id !== null && isset($connections[$notification->contact_id])) {
ObjectsRendererHook::register($notification->incident->object);
$notificationsToProcess[] = $notification;

++$numOfNotifications;
Expand All @@ -273,8 +271,6 @@ protected function processNotifications(): void
}

if ($numOfNotifications > 0) {
ObjectsRendererHook::load(false);

foreach ($notificationsToProcess as $notification) {
/** @var Incident $incident */
$incident = $notification->incident;
Expand All @@ -286,7 +282,7 @@ protected function processNotifications(): void
(object) [
'incident_id' => $notification->incident_id,
'severity' => $incident->severity->getValue(),
'title' => ObjectsRendererHook::getObjectNameAsString($incident->object),
'title' => $incident->object->name,
'message' => $notification->message
]
)
Expand Down
4 changes: 4 additions & 0 deletions library/Notifications/Hook/ObjectsRendererHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Generator;
use Icinga\Application\Hook;
use Icinga\Application\Logger;
use Icinga\Module\Notifications\Hook\V2\SourceHook;
use Icinga\Module\Notifications\Model\Objects;
use ipl\Html\Attributes;
use ipl\Html\BaseHtmlElement;
Expand All @@ -20,6 +21,9 @@

/**
* Base hook to prepare and render objects
*
* @deprecated For object name, use the db column `object.name`. To create object link, use
* {@see SourceHook::createObjectLink()} instead.
*/
Comment thread
sukhwinder33445 marked this conversation as resolved.
abstract class ObjectsRendererHook
{
Expand Down
10 changes: 10 additions & 0 deletions library/Notifications/Hook/V2/SourceHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace Icinga\Module\Notifications\Hook\V2;

use ipl\Html\ValidHtml;
use ipl\Stdlib\Filter\Chain;
use ipl\Stdlib\Filter\Condition;
use ipl\Web\Control\SearchBar\SearchException;
Expand Down Expand Up @@ -79,4 +80,13 @@ public function getValueSuggestions(string $column, string $searchTerm, Chain $s
* @return Traversable Provider for {@see SearchSuggestions::__construct}
*/
public function getColumnSuggestions(string $searchTerm): Traversable;

/**
* Create the object link using the given ID tags
*
* @param array $idTags
*
* @return ?ValidHtml
*/
public function createObjectLink(array $idTags): ?ValidHtml;
}
7 changes: 5 additions & 2 deletions library/Notifications/Model/Incident.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* @property ?DateTime $recovered_at
* @property Severity $severity
* @property ?string $mute_reason
* @property ?string $message
*
* @property Query|Objects $object
* @property Query|Contact $contact
Expand Down Expand Up @@ -54,7 +55,8 @@ public function getColumns(): array
'started_at',
'recovered_at',
'severity',
'mute_reason'
'mute_reason',
'message'
];
}

Expand All @@ -65,7 +67,8 @@ public function getColumnDefinitions(): array
'started_at' => t('Started At'),
'recovered_at' => t('Recovered At'),
'severity' => t('Severity'),
'mute_reason' => t('Mute Reason')
'mute_reason' => t('Mute Reason'),
'message' => t('Message')
];
}

Expand Down
7 changes: 0 additions & 7 deletions library/Notifications/Model/Objects.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
namespace Icinga\Module\Notifications\Model;

use Icinga\Module\Notifications\Common\Model;
use Icinga\Module\Notifications\Hook\ObjectsRendererHook;
use Icinga\Module\Notifications\Model\Behavior\IdTagAggregator;
use ipl\Html\ValidHtml;
use ipl\Orm\Behavior\Binary;
use ipl\Orm\Behaviors;
use ipl\Orm\Query;
Expand Down Expand Up @@ -79,9 +77,4 @@ public function createRelations(Relations $relations): void

$relations->belongsTo('source', Source::class)->setJoinType('LEFT');
}

public function getName(): ValidHtml
{
return ObjectsRendererHook::getObjectName($this);
}
}
Loading
Loading