From d5f975ce44eebd207ed26eb7b1586700dbe29be6 Mon Sep 17 00:00:00 2001 From: Benjamin Drieu Date: Fri, 17 Dec 2021 15:18:02 +0100 Subject: [PATCH] Add pending status + trim status info after first line --- extension.js | 5 +++-- prefs.js | 2 ++ ...rg.gnome.shell.extensions.monito@drieu.org.gschema.xml | 8 ++++++++ servers/icinga2api.js | 8 ++++---- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/extension.js b/extension.js index 7912370..948b17c 100644 --- a/extension.js +++ b/extension.js @@ -63,7 +63,7 @@ const column_definitions = { 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: false, }, - actions: { label: 'Actions', width: 120, expand: false, special: 'actions' }, + actions: { label: 'Actions', width: 50, expand: false, special: 'actions' }, }; @@ -328,6 +328,7 @@ class Indicator extends PanelMenu.Button { height: 24, can_focus: true, } ); + _button.prevIcon = 'system-run-symbolic'; _button.service = text; _button.connect ( 'clicked', Lang.bind ( this, this._onRecheckButtonClick ) ); _button.child = new St.Icon ( { @@ -445,7 +446,7 @@ class Indicator extends PanelMenu.Button { this.account_settings.get_string ( 'service-replace' ) ); 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' ) ); + this.account_settings.get_string ( 'status-info-replace' ) ) . replace ( new RegExp ( "\n.*" ), "" ); else if ( _col == 'has_been_acknowledged' ) { if ( entry [ _col ] ) diff --git a/prefs.js b/prefs.js index cd4803b..313d5f2 100644 --- a/prefs.js +++ b/prefs.js @@ -53,10 +53,12 @@ const prefs = [ { type: Gtk.ColorButton, category: 'Colors', label: _('Warning background color'), key: 'warning-color', align: Gtk.Align.START }, { type: Gtk.ColorButton, category: 'Colors', label: _('Critical background color'), key: 'critical-color', align: Gtk.Align.START }, { type: Gtk.ColorButton, category: 'Colors', label: _('Unknown background color'), key: 'unknown-color', align: Gtk.Align.START }, + { type: Gtk.ColorButton, category: 'Colors', label: _('Pending background color'), key: 'pending-color', align: Gtk.Align.START }, { type: Gtk.ColorButton, category: 'Colors', label: _('OK color'), key: 'ok-fg', align: Gtk.Align.START }, { 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.ColorButton, category: 'Colors', label: _('Pending color'), key: 'pending-fg', align: Gtk.Align.START }, { type: Gtk.Switch, category: 'Filters', label: _('Do not 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' }, diff --git a/schemas/org.gnome.shell.extensions.monito@drieu.org.gschema.xml b/schemas/org.gnome.shell.extensions.monito@drieu.org.gschema.xml index 45f9530..93aab33 100644 --- a/schemas/org.gnome.shell.extensions.monito@drieu.org.gschema.xml +++ b/schemas/org.gnome.shell.extensions.monito@drieu.org.gschema.xml @@ -93,6 +93,10 @@ '#e496f5' + + '#aaaaaa' + + '#ffffff' @@ -109,6 +113,10 @@ '#ffffff' + + '#ffffff' + + ['status','host_name','service_display_name','has_been_acknowledged','last_check','attempts','status_information'] diff --git a/servers/icinga2api.js b/servers/icinga2api.js index b884fa3..54ef4ad 100644 --- a/servers/icinga2api.js +++ b/servers/icinga2api.js @@ -95,19 +95,19 @@ class Icinga2API extends GenericServer { else { let json = JSON.parse ( _data ); - let _statuses = [ 'OK', 'WARNING', 'CRITICAL', 'UNKNOWN' ]; + let _statuses = [ 'OK', 'WARNING', 'CRITICAL', 'UNKNOWN', 'PENDING' ]; for ( var entry of json.results ) { // log ( JSON.stringify(entry) ); this.status.service_status.push ( { - status: _statuses [ entry.attrs.state ], + 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: this.formatDate(parseInt(entry.attrs.last_check)), + status_information: ( entry.attrs.last_check_result ? entry.attrs.last_check_result.output : _statuses[entry.attrs.state] ), + last_check: ( entry.attrs.last_check ? this.formatDate(parseInt(entry.attrs.last_check)) : '' ), } ); } }