diff --git a/extension.js b/extension.js
index 81f92e6..5995e8a 100644
--- a/extension.js
+++ b/extension.js
@@ -37,6 +37,7 @@ const Me = ExtensionUtils.getCurrentExtension();
const Main = imports.ui.main;
const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu;
+const Mainloop = imports.mainloop;
const { GObject, St, Clutter, Gio } = imports.gi;
@@ -91,7 +92,6 @@ class Indicator extends PanelMenu.Button {
box.add_child(PopupMenu.arrowIcon(St.Side.BOTTOM));
-
// Menu
this._buttonMenu = new PopupMenu.PopupBaseMenuItem({
reactive: false,
@@ -99,7 +99,6 @@ class Indicator extends PanelMenu.Button {
});
this.menu.addMenuItem(this._buttonMenu);
-
// let item = new PopupMenu.PopupMenuItem(_('Reload'));
// item.connect('activate', () => {
// this.updateStatus ( );
@@ -117,7 +116,6 @@ 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._prefsButton = this._createButton ( 'preferences-system-symbolic', 'Preferences', this._onPreferencesActivate );
this._buttonMenu.actor.add_child (this._prefsButton);
@@ -138,6 +136,16 @@ class Indicator extends PanelMenu.Button {
_intermediate.actor.add_actor(this._box);
this.updateStatus ( );
+ this.setupTimeout ( );
+ }
+
+ setupTimeout ( )
+ {
+ log ( 'Setting up timeout of ' + settings.get_int ( "poll-delay" ) + ' secs' );
+ if (this.timeout) {
+ Mainloop.source_remove(this.timeout);
+ }
+ this.timeout = Mainloop.timeout_add ( settings.get_int ( "poll-delay" ) * 1000, Lang.bind(this, this.updateStatus ) );
}
initStatus ( ) {
@@ -147,7 +155,8 @@ class Indicator extends PanelMenu.Button {
'UNKNOWN': 0 };
}
- updateStatus ( ) {
+ updateStatus ( )
+ {
for ( let _server of Preferences.getServersList() )
{
let _account_settings = Preferences.getAccountSettings ( _server );
@@ -176,6 +185,8 @@ class Indicator extends PanelMenu.Button {
}
}
}
+
+ this.setupTimeout ( );
}
createBin ( status, text, col ) {
diff --git a/prefs.js b/prefs.js
index 7669d8d..340573a 100644
--- a/prefs.js
+++ b/prefs.js
@@ -23,12 +23,14 @@
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Gtk = imports.gi.Gtk;
+const Gdk = imports.gi.Gdk;
// It's common practice to keep GNOME API and JS imports in separate blocks
const Lang = imports.lang;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
+const Mainloop = imports.mainloop;
const Gettext = imports.gettext.domain('monito');
const _ = Gettext.gettext;
@@ -46,6 +48,10 @@ const prefs = [ { type: Gtk.Entry, label: _('Name'), key: 'name' },
{ type: Gtk.Entry, label: _('Username'), key: 'username' },
{ type: Gtk.Entry, label: _('Password'), key: 'password' },
{ type: Gtk.Entry, label: _('URL CGI'), key: 'urlcgi' },
+ { type: Gtk.ColorButton, label: _('OK color'), key: 'ok-color', align: Gtk.Align.START },
+ { type: Gtk.ColorButton, label: _('Warning color'), key: 'warning-color', align: Gtk.Align.START },
+ { type: Gtk.ColorButton, label: _('Critical color'), key: 'critical-color', align: Gtk.Align.START },
+ { type: Gtk.ColorButton, label: _('Unknown color'), key: 'unknown-color', align: Gtk.Align.START },
];
@@ -61,7 +67,7 @@ function init() {
function buildPrefsWidget() {
// Copy the same GSettings code from `extension.js`
-// this.settings = ExtensionUtils.getSettings(SETTINGS_SCHEMA);
+ this.settings = ExtensionUtils.getSettings(SETTINGS_SCHEMA);
let mainVbox = new Gtk.Box( { orientation: Gtk.Orientation.VERTICAL } );
@@ -84,6 +90,25 @@ function buildPrefsWidget() {
});
prefsWidget.attach(title, 0, 0, 2, 1);
+ let _label = new Gtk.Label({
+ label: 'Poll delay in seconds',
+ visible: true,
+ halign: Gtk.Align.START,
+ });
+ prefsWidget.attach ( _label, 0, 1, 1, 1 );
+
+ let _entry = new Gtk.SpinButton ({
+ numeric: true,
+ halign: Gtk.Align.FILL,
+ visible: true,
+ hexpand: true,
+ can_focus: true,
+ });
+ _entry.set_range ( 1, 1000 );
+ _entry.set_increments ( 1, 5 );
+ prefsWidget.attach ( _entry, 1, 1, 1, 1 );
+ this.settings.bind ( 'poll-delay', _entry, 'value', Gio.SettingsBindFlags.DEFAULT );
+
// Misc Settings (TBD)
mainWidget.append_page ( prefsWidget,
new Gtk.Label ( { label: 'General', } ) );
@@ -173,12 +198,12 @@ function createAccountWidgets ( isActive )
});
this._accountsWidget.attach ( _label, 0, y, 1, 1 );
- this.prefWidgets[prefEntry.key] = new prefEntry.type({
- halign: Gtk.Align.FILL,
+ this.prefWidgets[prefEntry.key] = new prefEntry.type ( {
+ halign: ( prefEntry.align ? prefEntry.align : Gtk.Align.FILL ),
visible: true,
hexpand: true,
can_focus: isActive,
- });
+ } );
let boundValue = 'text';
if ( prefEntry.key == 'password' )
@@ -239,6 +264,14 @@ function activateAccountRow ( ) {
Gio.SettingsBindFlags.DEFAULT
);
}
+ else if ( prefEntry.type == Gtk.ColorButton )
+ {
+ let _color = new Gdk.RGBA ( );
+ _color.parse (_account_settings.get_string(prefEntry.key) );
+ this.prefWidgets[prefEntry.key].set_use_alpha ( false );
+ this.prefWidgets[prefEntry.key].set_rgba ( _color );
+ this.prefWidgets[prefEntry.key].connect('color-set', Lang.bind ( { key: prefEntry.key }, setColor ) );
+ }
else if ( prefEntry.type == Gtk.ComboBoxText )
{
this.prefWidgets[prefEntry.key].set_active(_account_settings.get_enum('type'));
@@ -302,3 +335,14 @@ function removeAccount ( ) {
_row.destroy();
this.settings.set_string ( 'servers', _servers . join ( ',' ) );
}
+
+
+function setColor ( color )
+{
+ log ( 'Color ' + + ': ' + color );
+ let _output = '#%02x%02x%02x'.format(
+ 255 * color.get_rgba().red,
+ 255 * color.get_rgba().green,
+ 255 * color.get_rgba().blue );
+ _account_settings.set_string('' + this.key, _output);
+}
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 afdb052..ecb3f20 100644
--- a/schemas/org.gnome.shell.extensions.monito@drieu.org.gschema.xml
+++ b/schemas/org.gnome.shell.extensions.monito@drieu.org.gschema.xml
@@ -43,6 +43,10 @@
"Short"
+
+ 300
+
+
@@ -72,9 +76,22 @@
''
-
- 1
+
+ '#00cc33'
+
+ '#ffa500'
+
+
+
+ '#ff3300'
+
+
+
+ '#e496f5'
+
+
+
diff --git a/servers/icinga.js b/servers/icinga.js
index 45b0136..fe59257 100644
--- a/servers/icinga.js
+++ b/servers/icinga.js
@@ -33,7 +33,7 @@ let _httpSession;
class Icinga {
constructor ( _server ) {
- log ( '>>> New Icinga' + _server );
+ log ( '>>> New Icinga #' + _server );
this.server = _server
}
@@ -49,9 +49,9 @@ class Icinga {
log ( 'monito name >>> ' + name );
log ( 'monito type >>> ' + type );
log ( 'monito username >>> ' + username );
+ log ( 'monito urlcgi >>> ' + urlcgi );
urlcgi = urlcgi.replace ( /^(https?:\/\/)/, '$1' + username + ':' + password + '@' );
- log ( 'monito urlcgi >>> ' + urlcgi );
if (_httpSession === undefined) {
_httpSession = new Soup.Session();
@@ -65,7 +65,7 @@ class Icinga {
_httpSession.queue_message(message, Lang.bind
(this, function(_httpSession, message)
{
- log ( '>>> ' + message.response_body.data );
+// log ( '>>> ' + message.response_body.data );
let json = JSON.parse(message.response_body.data);
this.status = json.status;
diff --git a/servers/icinga2.js b/servers/icinga2.js
index 6980adc..c00b979 100644
--- a/servers/icinga2.js
+++ b/servers/icinga2.js
@@ -33,7 +33,7 @@ let _httpSession;
class Icinga2 {
constructor ( _server ) {
- log ( '>>> New Icinga2' + _server );
+ log ( '>>> New Icinga2 #' + _server );
this.server = _server
}
@@ -49,9 +49,9 @@ class Icinga2 {
log ( 'monito name >>> ' + name );
log ( 'monito type >>> ' + type );
log ( 'monito username >>> ' + username );
+ log ( 'monito urlcgi >>> ' + urlcgi );
// urlcgi = urlcgi.replace ( /^(https?:\/\/)/, '$1' + username + ':' + password + '@' );
- log ( 'monito urlcgi >>> ' + urlcgi );
if (_httpSession === undefined) {
_httpSession = new Soup.Session();
@@ -81,15 +81,17 @@ class Icinga2 {
for ( var entry of json )
{
+// if ( entry.status != 0 )
+// log ( JSON.stringify(entry, null, 2) );
+
this.status.service_status.push ( {
status: _statuses [ entry.service_state ],
host_name: entry.host_name,
service_display_name: entry.service_display_name,
attempts: entry.service_attempt,
status_information: entry.service_output,
- last_check: new Date(parseInt(entry.service_last_state_change)).toString(),
+ last_check: new Date ( parseInt(entry.service_last_state_change) * 1000 ) . toString(),
} );
- log ( 'date ' + new Date(parseInt(entry.service_last_state_change)) );
}
extension.refreshUI ( this );
diff --git a/stylesheet.css b/stylesheet.css
index 3dee789..315a095 100644
--- a/stylesheet.css
+++ b/stylesheet.css
@@ -50,7 +50,7 @@
}
.monito-critical-box, .monito-service-CRITICAL, .monito-service-line-CRITICAL {
- background-color: #FF3300;
+ background-color: #ff3300;
}
.monito-warning-box, .monito-service-WARNING, .monito-service-line-WARNING {
@@ -58,11 +58,11 @@
}
.monito-ok-box, .monito-service-OK, .monito-service-line-OK {
- background-color: #00CC33;
+ background-color: #00cc33;
}
.monito-unknown-box, .monito-service-UNKNOWN, .monito-service-line-UNKNOWN {
- background-color: purple;
+ background-color: #e496f5;
}
.monito-service-line {