Implement acked monitoring + filter out

This commit is contained in:
Benjamin Drieu 2021-12-02 19:05:44 +01:00 committed by Benjamin Drieu
parent d7408fdf0a
commit 8e952badff
7 changed files with 42 additions and 6 deletions

View File

@ -30,7 +30,7 @@ inside of the gnome-shell panel (this could not be developed).
Things I plan to add at some point or another:
* Buttons to operate on services à la nagstamon (recheck, connect via SSH, etc.)
* Filters to hide services (acked, handled, ...)
* Filters to hide services (handled, scheduled downtime, host down, ...)
* Support for other (as in free speech) monitoring servers
* Choose which columns are shown in services result
@ -38,3 +38,4 @@ Things I will be unlikely to add unless a patch is provided:
* Support for broken HTTPS certs
* Notification for new alerts
* Display list of down hosts (I am not interested in host monitoring but services)

View File

@ -59,6 +59,7 @@ const column_definitions = {
status: { label: _('Status'), width: 50, expand: false, },
host_name: { label: _('Host name'), width: 300, expand: false, },
service_display_name: { label: _('Service'), width: 300, expand: false, },
has_been_acknowledged: { label: _('Ack'), width: 50, expand: false, align: Clutter.ActorAlign.CENTER, style: 'font-weight:bold;' },
last_check: { label: _('Last check'), width: 200, expand: false, type: 'date' },
attempts: { label: _('Attempts'), width: 50, expand: false, },
status_information: { label: _('Information'), width: 600, expand: true, },
@ -253,11 +254,14 @@ class Indicator extends PanelMenu.Button {
createBin ( status, text, col ) {
let _child;
if ( ! text )
if ( text === undefined )
text = '…';
if ( ! col [ 'special' ] )
_child = new St.Label({ style_class: 'monito-label', text: text.toString(), });
_child = new St.Label ( { style_class: 'monito-label',
text: text.toString(),
x_align: ( col.align ? col.align : Clutter.ActorAlign.START ),
style: ( col.style ? col.style : '' ) } );
else if ( col.special == 'actions' && this.serverLogic.canRecheck )
{
_child = new St.BoxLayout ( { x_expand: false,
@ -388,6 +392,13 @@ class Indicator extends PanelMenu.Button {
else if ( _col == 'status_information' && this.account_settings.get_string ( 'status-info-match' ) )
entry [ _col ] = entry [ _col ] . replace ( new RegExp ( this.account_settings.get_string ( 'status-info-match' ), 'i' ),
this.account_settings.get_string ( 'status-info-replace' ) );
else if ( _col == 'has_been_acknowledged' )
{
if ( entry [ _col ] )
entry [ _col ] = '✔'; // … or ✅🗹 ?
else
entry [ _col ] = '';
}
infoBox.add_child ( this.createBin ( entry.status, entry [ _col ], column_definitions [ _col ] ) );
}

View File

@ -57,6 +57,7 @@ const prefs = [
{ type: Gtk.ColorButton, category: 'Colors', label: _('Warning color'), key: 'warning-fg', align: Gtk.Align.START },
{ type: Gtk.ColorButton, category: 'Colors', label: _('Critical color'), key: 'critical-fg', align: Gtk.Align.START },
{ type: Gtk.ColorButton, category: 'Colors', label: _('Unknown color'), key: 'unknown-fg', align: Gtk.Align.START },
{ type: Gtk.Switch, category: 'Filters', label: _('Do <b>not</b> display acknowledged services'), key: 'acknowledged-filter-out', align: Gtk.Align.START },
{ type: Gtk.Entry, category: 'Filters', label: _('Only display hosts matching'), key: 'host-grep' },
{ type: Gtk.Entry, category: 'Filters', label: _('Only display services matching'), key: 'service-grep' },
{ type: Gtk.Entry, category: 'Filters', label: _('Only display status info matching'), key: 'status-info-grep' },
@ -325,6 +326,15 @@ function activateAccountRow ( ) {
Gio.SettingsBindFlags.DEFAULT
);
}
else if ( prefEntry.type == Gtk.Switch )
{
_account_settings.bind (
prefEntry.key,
this.prefWidgets[prefEntry.key],
'active',
Gio.SettingsBindFlags.DEFAULT
);
}
else if ( prefEntry.type == Gtk.ColorButton )
{
let _color = new Gdk.RGBA ( );

View File

@ -110,7 +110,7 @@
</key>
<key name="columns" type="as">
<default>['status','host_name','service_display_name','last_check','attempts','status_information']</default>
<default>['status','host_name','service_display_name','has_been_acknowledged','last_check','attempts','status_information']</default>
</key>
<key name="columns-order" type="as">
@ -129,6 +129,10 @@
<default>''</default>
</key>
<key name="acknowledged-filter-out" type="b">
<default>false</default>
</key>
<key name="host-filter-out" type="s">
<default>''</default>
</key>

View File

@ -169,14 +169,22 @@ class GenericServer {
for ( var _filter of filters )
_filter.value = this._settings.get_string ( _filter.prefKey );
entries: for ( var i = 0 ; i < status.length ; i ++ )
entries:
for ( var i = 0 ; i < status.length ; i ++ )
{
if ( status[i]['has_been_acknowledged'] && this._settings.get_boolean ( 'acknowledged-filter-out' ) )
{
log ( '> ACKED:%s ' . format ( status[i]['service_display_name'] ) );
status.splice ( i, 1 );
i --; // This has been removed, so get back one step.
continue entries;
}
for ( var _filter of filters )
{
if ( _filter['value'] &&
( status[i][_filter['entryKey']].match ( new RegExp ( _filter['value'], 'i' ) ) <= 0 ) == _filter['positive'] )
{
// log ( '> NOT MATCHING: %s =~ %s == %s ' . format ( status[i][_filter['entryKey']], _filter['value'], _filter['positive'] ) );
status.splice ( i, 1 );
i --; // This has been removed, so get back one step.
continue entries;

View File

@ -71,6 +71,7 @@ class Icinga2 extends GenericServer {
host_name: entry.host_name,
service_display_name: entry.service_display_name,
attempts: entry.service_attempt,
has_been_acknowledged: parseInt(entry.service_acknowledged),
status_information: entry.service_output,
last_check: new Date ( parseInt(entry.service_last_state_change) * 1000 ) . toString(),
} );

View File

@ -89,6 +89,7 @@ class Icinga2API extends GenericServer {
status: _statuses [ entry.attrs.state ],
host_name: entry.attrs.host_name,
service_display_name: entry.attrs.display_name,
has_been_acknowledged: parseInt(entry.attrs.acknowledgement),
attempts: '%d/%d'.format(entry.attrs.check_attempt,entry.attrs.max_check_attempts),
status_information: entry.attrs.last_check_result.output,
last_check: new Date ( entry.attrs.last_state_change * 1000 ) . toString(),