Make server add/remove working
This commit is contained in:
parent
ff5280f729
commit
dae2afd39d
51
extension.js
51
extension.js
|
@ -41,13 +41,17 @@ const Mainloop = imports.mainloop;
|
||||||
|
|
||||||
const { GObject, St, Clutter, Gio } = imports.gi;
|
const { GObject, St, Clutter, Gio } = imports.gi;
|
||||||
|
|
||||||
const SETTINGS_SCHEMA = "org.gnome.shell.extensions.monito@drieu.org";
|
const SETTINGS_SCHEMA = "org.gnome.shell.extensions.monito";
|
||||||
|
const SETTINGS_SCHEMA_ACCOUNT = "org.gnome.shell.extensions.monito.account";
|
||||||
|
const SETTINGS_SCHEMA_ACCOUNT_PATH = "/org/gnome/shell/extensions/monito/account";
|
||||||
|
|
||||||
const Convenience = Me.imports.convenience;
|
const Convenience = Me.imports.convenience;
|
||||||
const Preferences = Me.imports.prefs;
|
const Preferences = Me.imports.prefs;
|
||||||
const Icinga = Me.imports.servers.icinga.Icinga;
|
const Icinga = Me.imports.servers.icinga.Icinga;
|
||||||
const Icinga2 = Me.imports.servers.icinga2.Icinga2;
|
const Icinga2 = Me.imports.servers.icinga2.Icinga2;
|
||||||
|
|
||||||
let settings = Convenience.getSettings(SETTINGS_SCHEMA);
|
let settings = Convenience.getSettings(SETTINGS_SCHEMA);
|
||||||
|
let account_settings = [ ];
|
||||||
|
|
||||||
|
|
||||||
const Indicator = GObject.registerClass(
|
const Indicator = GObject.registerClass(
|
||||||
|
@ -55,9 +59,6 @@ class Indicator extends PanelMenu.Button {
|
||||||
_init() {
|
_init() {
|
||||||
super._init(0.0, _('Monito Checker'));
|
super._init(0.0, _('Monito Checker'));
|
||||||
|
|
||||||
let box = new St.BoxLayout ( { } );
|
|
||||||
this.add_child(box);
|
|
||||||
|
|
||||||
this.initStatus ( );
|
this.initStatus ( );
|
||||||
|
|
||||||
this.namesBoxes = { };
|
this.namesBoxes = { };
|
||||||
|
@ -65,10 +66,24 @@ class Indicator extends PanelMenu.Button {
|
||||||
this.criticalBoxes = { };
|
this.criticalBoxes = { };
|
||||||
this.unknownBoxes = { };
|
this.unknownBoxes = { };
|
||||||
|
|
||||||
|
this.initUI ( );
|
||||||
|
|
||||||
|
settings.connect("changed::servers", Lang.bind ( this, function(stgs, key) {
|
||||||
|
monitoLog ( this );
|
||||||
|
this.remove_all_children ( );
|
||||||
|
this.initUI ( );
|
||||||
|
} ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
initUI ( ) {
|
||||||
|
let box = new St.BoxLayout ( { } );
|
||||||
|
this.add_child(box);
|
||||||
|
|
||||||
for ( let _server of Preferences.getServersList() )
|
for ( let _server of Preferences.getServersList() )
|
||||||
{
|
{
|
||||||
log ( '> Server ' + _server );
|
monitoLog ( '> Server ' + _server );
|
||||||
let _account_settings = Preferences.getAccountSettings ( _server );
|
account_settings [ _server ] = Preferences.getAccountSettings ( _server );
|
||||||
|
let _account_settings = account_settings [ _server ];
|
||||||
|
|
||||||
let serverBox = new St.BoxLayout ( { style_class: 'monito-serverbox' } );
|
let serverBox = new St.BoxLayout ( { style_class: 'monito-serverbox' } );
|
||||||
box.add_child(serverBox);
|
box.add_child(serverBox);
|
||||||
|
@ -77,15 +92,20 @@ class Indicator extends PanelMenu.Button {
|
||||||
this.namesBoxes [ _server ] = new St.Label ( { text: _account_settings.get_string ( 'name' ) } );
|
this.namesBoxes [ _server ] = new St.Label ( { text: _account_settings.get_string ( 'name' ) } );
|
||||||
name_box.add_child ( this.namesBoxes [ _server ] );
|
name_box.add_child ( this.namesBoxes [ _server ] );
|
||||||
serverBox.add_child(name_box);
|
serverBox.add_child(name_box);
|
||||||
|
_account_settings.bind ( 'name', this.namesBoxes [ _server ], 'text', Gio.SettingsBindFlags.GET );
|
||||||
|
|
||||||
let warning_box = new St.BoxLayout({ style_class: 'monito-warning-box monito-box' });
|
let warning_box = new St.BoxLayout({ style_class: 'monito-warning-box monito-box' });
|
||||||
warning_box.set_style ( 'background-color: ' + _account_settings.get_string ( 'warning-color' ) );
|
warning_box.set_style ( 'background-color: ' + _account_settings.get_string ( 'warning-color' ) );
|
||||||
|
_account_settings.connect("changed::warning-color", Lang.bind ( { widget: warning_box }, setColor ) );
|
||||||
|
|
||||||
this.warningBoxes [ _server ] = new St.Label({ text: String(_status['WARNING']) })
|
this.warningBoxes [ _server ] = new St.Label({ text: String(_status['WARNING']) })
|
||||||
warning_box.add_child ( this.warningBoxes [ _server ] );
|
warning_box.add_child ( this.warningBoxes [ _server ] );
|
||||||
serverBox.add_child(warning_box);
|
serverBox.add_child(warning_box);
|
||||||
|
|
||||||
let critical_box = new St.BoxLayout({ style_class: 'monito-critical-box monito-box' });
|
let critical_box = new St.BoxLayout({ style_class: 'monito-critical-box monito-box' });
|
||||||
critical_box.set_style ( 'background-color: ' + _account_settings.get_string ( 'critical-color' ) );
|
critical_box.set_style ( 'background-color: ' + _account_settings.get_string ( 'critical-color' ) );
|
||||||
|
_account_settings.connect("changed::critical-color", Lang.bind ( { widget: critical_box }, setColor ) );
|
||||||
|
|
||||||
this.criticalBoxes [ _server ] = new St.Label({ text: String(_status['CRITICAL']) })
|
this.criticalBoxes [ _server ] = new St.Label({ text: String(_status['CRITICAL']) })
|
||||||
critical_box.add_child ( this.criticalBoxes [ _server ] );
|
critical_box.add_child ( this.criticalBoxes [ _server ] );
|
||||||
serverBox.add_child(critical_box);
|
serverBox.add_child(critical_box);
|
||||||
|
@ -143,7 +163,7 @@ class Indicator extends PanelMenu.Button {
|
||||||
|
|
||||||
setupTimeout ( )
|
setupTimeout ( )
|
||||||
{
|
{
|
||||||
log ( 'Setting up timeout of ' + settings.get_int ( "poll-delay" ) + ' secs' );
|
monitoLog ( 'Setting up timeout of ' + settings.get_int ( "poll-delay" ) + ' secs' );
|
||||||
if (this.timeout) {
|
if (this.timeout) {
|
||||||
Mainloop.source_remove(this.timeout);
|
Mainloop.source_remove(this.timeout);
|
||||||
}
|
}
|
||||||
|
@ -170,7 +190,7 @@ class Indicator extends PanelMenu.Button {
|
||||||
|
|
||||||
if ( ! urlcgi )
|
if ( ! urlcgi )
|
||||||
{
|
{
|
||||||
log ( 'Not updating monito because no URL configured' );
|
monitoLog ( 'Not updating monito because no URL configured' );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -180,10 +200,11 @@ class Indicator extends PanelMenu.Button {
|
||||||
else if ( type == 'Icinga2' )
|
else if ( type == 'Icinga2' )
|
||||||
_serverLogic = new Icinga2 ( _server );
|
_serverLogic = new Icinga2 ( _server );
|
||||||
|
|
||||||
if ( _serverLogic.refresh ( this ) )
|
if ( ! _serverLogic.refresh ( this ) )
|
||||||
{
|
{
|
||||||
this.warningBoxes[_server].set_text ( '…' );
|
this.warningBoxes[_server].set_text ( '…' );
|
||||||
this.criticalBoxes[_server].set_text ( '…' );
|
this.criticalBoxes[_server].set_text ( '…' );
|
||||||
|
// TODO: Add display of error if any
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -309,3 +330,15 @@ class Extension {
|
||||||
function init(meta) {
|
function init(meta) {
|
||||||
return new Extension(meta.uuid);
|
return new Extension(meta.uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function monitoLog ( msg )
|
||||||
|
{
|
||||||
|
log ( 'Monito: ' + msg );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function setColor (stgs, key) {
|
||||||
|
monitoLog ( stgs.get_string(key) );
|
||||||
|
this.widget.set_style ( 'background-color: ' + stgs.get_string(key) );
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "Monito",
|
"name": "Monito",
|
||||||
"description": "Checks various monitoring websites",
|
"description": "Checks for various monitoring servers (Icinga & Icinga2 at the moment)",
|
||||||
"uuid": "monito@drieu.org",
|
"uuid": "monito@drieu.org",
|
||||||
"shell-version": [
|
"shell-version": [
|
||||||
"3.38"
|
"3.38"
|
||||||
|
|
33
prefs.js
33
prefs.js
|
@ -38,9 +38,9 @@ const N_ = function (e) {
|
||||||
return e;
|
return e;
|
||||||
};
|
};
|
||||||
|
|
||||||
const SETTINGS_SCHEMA = "org.gnome.shell.extensions.monito@drieu.org";
|
const SETTINGS_SCHEMA = "org.gnome.shell.extensions.monito";
|
||||||
const SETTINGS_SCHEMA_ACCOUNT = "org.gnome.shell.extensions.monito@drieu.org.account";
|
const SETTINGS_SCHEMA_ACCOUNT = "org.gnome.shell.extensions.monito.account";
|
||||||
const SETTINGS_SCHEMA_ACCOUNT_PATH = "/org/gnome/shell/extensions/monito@drieu.org/account";
|
const SETTINGS_SCHEMA_ACCOUNT_PATH = "/org/gnome/shell/extensions/monito/account";
|
||||||
|
|
||||||
|
|
||||||
const prefs = [ { type: Gtk.Entry, label: _('Name'), key: 'name' },
|
const prefs = [ { type: Gtk.Entry, label: _('Name'), key: 'name' },
|
||||||
|
@ -57,10 +57,9 @@ const prefs = [ { type: Gtk.Entry, label: _('Name'), key: 'name' },
|
||||||
|
|
||||||
// Like 'extension.js' this is used for any one-time setup like translations.
|
// Like 'extension.js' this is used for any one-time setup like translations.
|
||||||
function init() {
|
function init() {
|
||||||
log('initializing ${Me.metadata.name} Preferences');
|
monitoLog('initializing ${Me.metadata.name} Preferences');
|
||||||
this.settings = ExtensionUtils.getSettings(SETTINGS_SCHEMA);
|
this.settings = ExtensionUtils.getSettings(SETTINGS_SCHEMA);
|
||||||
log ( Me );
|
monitoLog ( 'Foo: ' + Me.metadata );
|
||||||
log ( Me._indicator );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -249,7 +248,7 @@ function activateAccountRow ( ) {
|
||||||
this.createAccountWidgets ( true );
|
this.createAccountWidgets ( true );
|
||||||
|
|
||||||
let _row = this.accountsChooser.get_selected_row();
|
let _row = this.accountsChooser.get_selected_row();
|
||||||
log('Active:' + _row.server);
|
monitoLog('Active:' + _row.server);
|
||||||
let _account_settings = getAccountSettings ( _row.server );
|
let _account_settings = getAccountSettings ( _row.server );
|
||||||
|
|
||||||
if ( ! _account_settings )
|
if ( ! _account_settings )
|
||||||
|
@ -278,8 +277,8 @@ function activateAccountRow ( ) {
|
||||||
{
|
{
|
||||||
this.prefWidgets[prefEntry.key].set_active(_account_settings.get_enum('type'));
|
this.prefWidgets[prefEntry.key].set_active(_account_settings.get_enum('type'));
|
||||||
this.prefWidgets[prefEntry.key].connect('changed', Lang.bind(this, function (e) {
|
this.prefWidgets[prefEntry.key].connect('changed', Lang.bind(this, function (e) {
|
||||||
log ( e ) ;
|
monitoLog ( e ) ;
|
||||||
log('Active:' + this.prefWidgets['type'].get_active());
|
monitoLog('Active:' + this.prefWidgets['type'].get_active());
|
||||||
let _account_settings = getAccountSettings ( _row.server );
|
let _account_settings = getAccountSettings ( _row.server );
|
||||||
_account_settings.set_enum('type', this.prefWidgets['type'].get_active());
|
_account_settings.set_enum('type', this.prefWidgets['type'].get_active());
|
||||||
}));
|
}));
|
||||||
|
@ -290,7 +289,7 @@ function activateAccountRow ( ) {
|
||||||
|
|
||||||
function addAccountLine ( server_id )
|
function addAccountLine ( server_id )
|
||||||
{
|
{
|
||||||
log ( '> Add line ' + server_id );
|
monitoLog ( '> Add line ' + server_id );
|
||||||
let _account_settings = getAccountSettings ( server_id );
|
let _account_settings = getAccountSettings ( server_id );
|
||||||
let row = new Gtk.ListBoxRow ( { hexpand: true,
|
let row = new Gtk.ListBoxRow ( { hexpand: true,
|
||||||
halign: Gtk.Align.FILL } );
|
halign: Gtk.Align.FILL } );
|
||||||
|
@ -308,7 +307,7 @@ function addAccountLine ( server_id )
|
||||||
|
|
||||||
|
|
||||||
function createAccount ( ) {
|
function createAccount ( ) {
|
||||||
log ( '> Create Account' );
|
monitoLog ( '> Create Account' );
|
||||||
|
|
||||||
let _servers = this.getServersList ( );
|
let _servers = this.getServersList ( );
|
||||||
let _max = Math.max ( ..._servers );
|
let _max = Math.max ( ..._servers );
|
||||||
|
@ -325,11 +324,11 @@ function createAccount ( ) {
|
||||||
|
|
||||||
function removeAccount ( ) {
|
function removeAccount ( ) {
|
||||||
let _row = this.accountsChooser.get_selected_row();
|
let _row = this.accountsChooser.get_selected_row();
|
||||||
log('Active:' + _row.server);
|
monitoLog('Active:' + _row.server);
|
||||||
|
|
||||||
let _servers = this.getServersList ( );
|
let _servers = this.getServersList ( );
|
||||||
_servers.splice ( _servers.indexOf ( _row.server ), 1 );
|
_servers.splice ( _servers.indexOf ( _row.server ), 1 );
|
||||||
log ( _servers );
|
monitoLog ( _servers );
|
||||||
|
|
||||||
if ( ! _row )
|
if ( ! _row )
|
||||||
return;
|
return;
|
||||||
|
@ -341,7 +340,7 @@ function removeAccount ( ) {
|
||||||
|
|
||||||
function setColor ( color )
|
function setColor ( color )
|
||||||
{
|
{
|
||||||
log ( 'Color ' + + ': ' + color );
|
monitoLog ( 'Color ' + + ': ' + color );
|
||||||
let _output = '#%02x%02x%02x'.format(
|
let _output = '#%02x%02x%02x'.format(
|
||||||
255 * color.get_rgba().red,
|
255 * color.get_rgba().red,
|
||||||
255 * color.get_rgba().green,
|
255 * color.get_rgba().green,
|
||||||
|
@ -349,3 +348,9 @@ function setColor ( color )
|
||||||
this.settings.set_string('' + this.key, _output);
|
this.settings.set_string('' + this.key, _output);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function monitoLog ( msg )
|
||||||
|
{
|
||||||
|
log ( 'Monito: ' + msg );
|
||||||
|
}
|
||||||
|
|
|
@ -20,26 +20,26 @@
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<schemalist >
|
<schemalist >
|
||||||
<enum id="org.gnome.shell.extensions.monito@drieu.org.MonitoringType">
|
<enum id="org.gnome.shell.extensions.monito.MonitoringType">
|
||||||
<value value="0" nick="Icinga"/>
|
<value value="0" nick="Icinga"/>
|
||||||
<value value="1" nick="Icinga2"/>
|
<value value="1" nick="Icinga2"/>
|
||||||
</enum>
|
</enum>
|
||||||
|
|
||||||
<enum id="org.gnome.shell.extensions.monito@drieu.org.DisplayType">
|
<enum id="org.gnome.shell.extensions.monito.DisplayType">
|
||||||
<value value="0" nick="Short"/>
|
<value value="0" nick="Short"/>
|
||||||
<value value="1" nick="Long"/>
|
<value value="1" nick="Long"/>
|
||||||
</enum>
|
</enum>
|
||||||
|
|
||||||
<!-- Main Schema -->
|
<!-- Main Schema -->
|
||||||
<schema id="org.gnome.shell.extensions.monito@drieu.org" path="/org/gnome/shell/extensions/monito/">
|
<schema id="org.gnome.shell.extensions.monito" path="/org/gnome/shell/extensions/monito/">
|
||||||
|
|
||||||
<child name="account" schema="org.gnome.shell.extensions.monito@drieu.org.account"/>
|
<child name="account" schema="org.gnome.shell.extensions.monito.account"/>
|
||||||
|
|
||||||
<key name="servers" type="s">
|
<key name="servers" type="s">
|
||||||
<default>'0'</default>
|
<default>'0'</default>
|
||||||
</key>
|
</key>
|
||||||
|
|
||||||
<key name="display-type" enum="org.gnome.shell.extensions.monito@drieu.org.DisplayType">
|
<key name="display-type" enum="org.gnome.shell.extensions.monito.DisplayType">
|
||||||
<default>"Short"</default>
|
<default>"Short"</default>
|
||||||
</key>
|
</key>
|
||||||
|
|
||||||
|
@ -50,13 +50,13 @@
|
||||||
</schema>
|
</schema>
|
||||||
|
|
||||||
<!-- Account list -->
|
<!-- Account list -->
|
||||||
<schema id="org.gnome.shell.extensions.monito@drieu.org.account">
|
<schema id="org.gnome.shell.extensions.monito.account">
|
||||||
|
|
||||||
<key name="icon" type="s">
|
<key name="icon" type="s">
|
||||||
<default>''</default>
|
<default>''</default>
|
||||||
</key>
|
</key>
|
||||||
|
|
||||||
<key name="type" enum="org.gnome.shell.extensions.monito@drieu.org.MonitoringType">
|
<key name="type" enum="org.gnome.shell.extensions.monito.MonitoringType">
|
||||||
<default>"Icinga"</default>
|
<default>"Icinga"</default>
|
||||||
</key>
|
</key>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue