This commit is contained in:
Benjamin Drieu 2022-03-22 22:19:07 +01:00
parent 4adb15ae7e
commit 24067018e8
6 changed files with 74 additions and 5 deletions

View File

@ -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') {
@ -586,11 +619,15 @@ class Extension {
this._indicators = { };
for ( let _server of Preferences.getServersList() )
{
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 ] );
}
}
}
disable() {
for ( var i of Object.keys(this._indicators) )

View File

@ -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 },

View File

@ -53,6 +53,10 @@
<!-- Account list -->
<schema id="org.gnome.shell.extensions.monito.account">
<key name="active" type="b">
<default>true</default>
</key>
<key name="icon" type="s">
<default>''</default>
</key>
@ -77,6 +81,10 @@
<default>''</default>
</key>
<key name="strict-ssl" type="b">
<default>true</default>
</key>
<key name="ok-color" type="s">
<default>'#00cc33'</default>
</key>

View File

@ -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 );

View File

@ -87,6 +87,8 @@ class Icinga2API extends GenericServer {
handlePollMessage ( _httpSession, message )
{
log ( 'handlePollMessage' );
let _data = super.handleMessage ( _httpSession, message );
try
{

View File

@ -91,7 +91,14 @@
margin: 0px;
}
.entry {
margin-right: 0px;
min-width: 256px;
padding: 12px !important;
}
.big-button {
margin-left: 0px;
padding: 12px !important;
}