From 5e8e660c7aba15eecce2980886310cf0ce752880 Mon Sep 17 00:00:00 2001 From: Benjamin Drieu Date: Tue, 22 Mar 2022 22:19:07 +0100 Subject: [PATCH] Updates --- extension.js | 47 +++++++++++++++++-- prefs.js | 2 + ...ll.extensions.monito@drieu.org.gschema.xml | 8 ++++ servers/genericserver.js | 13 +++++ servers/icinga2api.js | 2 + stylesheet.css | 7 +++ 6 files changed, 74 insertions(+), 5 deletions(-) diff --git a/extension.js b/extension.js index 948b17c..33892cb 100644 --- a/extension.js +++ b/extension.js @@ -147,12 +147,32 @@ class Indicator extends PanelMenu.Button { this._mainLabel = new St.Label ( { style_class: 'monito-title', text: _('Monito Checker'), x_expand: true } ); this._buttonMenu.actor.add_actor(this._mainLabel); + this._searchField = new St.Entry ( { + x_align: Clutter.ActorAlign.END, + y_align: Clutter.ActorAlign.CENTER, + reactive: true, + can_focus: true, + track_hover: true, + style_class: 'entry', + secondary_icon: new St.Icon ( { + style_class: 'monito-button-icon', + icon_name: 'edit-find-symbolic', + icon_size: 24, + width: 24, + height: 24, + } ), + }); + this._searchField.connect('secondary-icon-clicked', Lang.bind(this, this._onSearchFieldActivate ) ); + this._searchField.clutter_text.connect('activate', Lang.bind(this, this._onSearchFieldActivate ) ); + + this._buttonMenu.actor.add_child (this._searchField); + this._prefsButton = this._createButton ( 'preferences-system-symbolic', _('Preferences'), this._onPreferencesActivate ); this._buttonMenu.actor.add_child (this._prefsButton); if ( this.serverLogic && this.serverLogic.canRecheck ) { - this._recheckButton = this._createButton ( 'system-run-symbolic', _('Recheck all'), this.recheckAll ); + this._recheckButton = this._createButton ( 'mail-send-receive-symbolic', _('Recheck all'), this.recheckAll ); this._buttonMenu.actor.add_child (this._recheckButton ); } @@ -328,11 +348,11 @@ class Indicator extends PanelMenu.Button { height: 24, can_focus: true, } ); - _button.prevIcon = 'system-run-symbolic'; + _button.prevIcon = 'mail-send-receive-symbolic'; _button.service = text; _button.connect ( 'clicked', Lang.bind ( this, this._onRecheckButtonClick ) ); _button.child = new St.Icon ( { - icon_name: 'system-run-symbolic', + icon_name: 'mail-send-receive-symbolic', icon_size: 16, width: 16, height: 16, @@ -422,6 +442,12 @@ class Indicator extends PanelMenu.Button { let _row = 0; for ( let entry of processedStatus ) { + if ( this._searchString && + ! ( entry [ 'host_name' ].includes ( this._searchString ) || + entry [ 'service_display_name' ].includes ( this._searchString ) || + entry [ 'status_information' ].includes ( this._searchString ) ) ) + continue; + if ( ( ! _status [ 'WARNING' ] && ! _status [ 'CRITICAL' ] && ! _status [ 'UNKNOWN' ] && entry.status == 'OK' ) || ( ( _status [ 'WARNING' ] || _status [ 'CRITICAL' ] || _status [ 'UNKNOWN' ] ) && entry.status != 'OK' ) ) { @@ -502,6 +528,13 @@ class Indicator extends PanelMenu.Button { return; } + _onSearchFieldActivate ( e ) { + monitoLog ( 'Search: ' + e.text ); + this._searchString = e.text; + this.refreshUI ( ); + return; + } + _onPreferencesActivate ( ) { this.menu.actor.hide(); if (typeof ExtensionUtils.openPrefs === 'function') { @@ -587,8 +620,12 @@ class Extension { for ( let _server of Preferences.getServersList() ) { - this._indicators [ _server ] = new Indicator(_server); - Main.panel.addToStatusArea ( '%s-%d'.format ( this._uuid, _server), this._indicators [ _server ] ); + let _pref = Preferences.getAccountSettings ( _server ); + if ( _pref.get_boolean ( 'active' ) ) + { + this._indicators [ _server ] = new Indicator(_server); + Main.panel.addToStatusArea ( '%s-%d'.format ( this._uuid, _server), this._indicators [ _server ] ); + } } } diff --git a/prefs.js b/prefs.js index 313d5f2..5b424e6 100644 --- a/prefs.js +++ b/prefs.js @@ -44,11 +44,13 @@ const SETTINGS_SCHEMA_ACCOUNT_PATH = "/org/gnome/shell/extensions/monito/account const prefs = [ + { type: Gtk.Switch, category: 'Settings', label: _('Active (restart for effect)'), key: 'active', align: Gtk.Align.START }, { type: Gtk.Entry, category: 'Settings', label: _('Name'), key: 'name' }, { type: Gtk.ComboBoxText, category: 'Settings', label: _('Type'), key: 'type' }, { type: Gtk.Entry, category: 'Settings', label: _('Username'), key: 'username' }, { type: Gtk.Entry, category: 'Settings', label: _('Password'), key: 'password' }, { type: Gtk.Entry, category: 'Settings', label: _('URL CGI'), key: 'urlcgi' }, + { type: Gtk.Switch, category: 'Settings', label: _('Check SSL certificate'), key: 'strict-ssl', align: Gtk.Align.START }, { type: Gtk.ColorButton, category: 'Colors', label: _('OK background color'), key: 'ok-color', align: Gtk.Align.START }, { 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 }, 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 93aab33..dc45f34 100644 --- a/schemas/org.gnome.shell.extensions.monito@drieu.org.gschema.xml +++ b/schemas/org.gnome.shell.extensions.monito@drieu.org.gschema.xml @@ -53,6 +53,10 @@ + + true + + '' @@ -77,6 +81,10 @@ '' + + true + + '#00cc33' diff --git a/servers/genericserver.js b/servers/genericserver.js index 9375add..ceec9bf 100644 --- a/servers/genericserver.js +++ b/servers/genericserver.js @@ -53,6 +53,8 @@ class GenericServer { buildURL ( ) { // if ( ! this._settings ) + log ( 'monito build URL' ); + this._settings = Preferences.getAccountSettings ( this._server ); if ( this.type != this._settings.get_string ( "type" ) || @@ -69,6 +71,7 @@ class GenericServer { this.password = this._settings.get_string ( "password" ); this.urlcgi = this._settings.get_string ( "urlcgi" ); this._httpSession = null; + log ( 'Refreshing URL parameters' ); } // log ( 'monito server >>> ' + this._server ); @@ -82,6 +85,7 @@ class GenericServer { prepareHttp ( ) { if ( this._httpSession == null ) { + log ( 'Preparing new HTTP with strict SSL ' + this.strict_ssl ); this._httpSession = new Soup.Session(); this._httpSession.ssl_strict = this.strict_ssl; this._httpSession.user_agent = Me.metadata.uuid; @@ -95,6 +99,7 @@ class GenericServer { auth.authenticate ( this.username, this.password ); message.request_headers.append ( "Authorization", auth.get_authorization ( message ) ); + log ( 'Sending message' ); this._httpSession.queue_message ( message, Lang.bind (this, callback ) ); } @@ -105,6 +110,14 @@ class GenericServer { this.status.service_status = [ ]; this.error = null; + log ( message.status_code ); + log ( message.response_body ); + message.response_headers.foreach ((name, val) => { + log (name, val); + }); + log ( message.response_body.data ); + + if ( message.status_code != Soup.Status.OK ) { log ( '>>> Error: ' + message.reason_phrase ); diff --git a/servers/icinga2api.js b/servers/icinga2api.js index 54ef4ad..b460cd1 100644 --- a/servers/icinga2api.js +++ b/servers/icinga2api.js @@ -87,6 +87,8 @@ class Icinga2API extends GenericServer { handlePollMessage ( _httpSession, message ) { + log ( 'handlePollMessage' ); + let _data = super.handleMessage ( _httpSession, message ); try { diff --git a/stylesheet.css b/stylesheet.css index fd7d475..1a58019 100644 --- a/stylesheet.css +++ b/stylesheet.css @@ -91,7 +91,14 @@ margin: 0px; } +.entry { + margin-right: 0px; + min-width: 256px; + padding: 12px !important; +} + .big-button { + margin-left: 0px; padding: 12px !important; }