diff --git a/extension.js b/extension.js index c9da8f7..11ba4e2 100644 --- a/extension.js +++ b/extension.js @@ -56,9 +56,11 @@ let account_settings = [ ]; const Indicator = GObject.registerClass( class Indicator extends PanelMenu.Button { - _init() { + _init(server) { super._init(0.0, _('Monito Checker')); + this.server = server; + this.initStatus ( ); this.namesBoxes = { }; @@ -67,53 +69,48 @@ class Indicator extends PanelMenu.Button { 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() ) - { - monitoLog ( '> Server ' + _server ); - account_settings [ _server ] = Preferences.getAccountSettings ( _server ); - let _account_settings = account_settings [ _server ]; - - let serverBox = new St.BoxLayout ( { style_class: 'monito-serverbox' } ); - box.add_child(serverBox); - - let name_box = new St.BoxLayout( { style_class: 'monito-namebox' } ); - this.namesBoxes [ _server ] = new St.Label ( { text: _account_settings.get_string ( 'name' ) } ); - name_box.add_child ( this.namesBoxes [ _server ] ); - 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' }); - 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']) }) - warning_box.add_child ( this.warningBoxes [ _server ] ); - serverBox.add_child(warning_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' ) ); - _account_settings.connect("changed::critical-color", Lang.bind ( { widget: critical_box }, setColor ) ); - - this.criticalBoxes [ _server ] = new St.Label({ text: String(_status['CRITICAL']) }) - critical_box.add_child ( this.criticalBoxes [ _server ] ); - serverBox.add_child(critical_box); - - } - + monitoLog ( '> Server ' + this.server ); + account_settings [ this.server ] = Preferences.getAccountSettings ( this.server ); + let _account_settings = account_settings [ this.server ]; + + let serverBox = new St.BoxLayout ( { style_class: 'monito-serverbox' } ); + box.add_child(serverBox); + + let name_box = new St.BoxLayout( { style_class: 'monito-namebox' } ); + this.namesBoxes [ this.server ] = new St.Label ( { text: _account_settings.get_string ( 'name' ) } ); + name_box.add_child ( this.namesBoxes [ this.server ] ); + serverBox.add_child(name_box); + _account_settings.bind ( 'name', this.namesBoxes [ this.server ], 'text', Gio.SettingsBindFlags.GET ); + + this.namesBoxes [ this.server ].connect ( 'button-press-event', Lang.bind ( this, function ( ) { this.setMenu ( this.menu ); } ) ); + + + 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' ) ); + _account_settings.connect("changed::warning-color", Lang.bind ( { widget: warning_box }, setColor ) ); + + this.warningBoxes [ this.server ] = new St.Label({ text: String(_status['WARNING']) }) + warning_box.add_child ( this.warningBoxes [ this.server ] ); + serverBox.add_child(warning_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' ) ); + _account_settings.connect("changed::critical-color", Lang.bind ( { widget: critical_box }, setColor ) ); + + this.criticalBoxes [ this.server ] = new St.Label({ text: String(_status['CRITICAL']) }) + critical_box.add_child ( this.criticalBoxes [ this.server ] ); + serverBox.add_child(critical_box); + box.add_child(PopupMenu.arrowIcon(St.Side.BOTTOM)); + this.menu_new = new PopupMenu.PopupMenu(this, Clutter.ActorAlign.START, St.Side.TOP, 0); + // Menu this._buttonMenu = new PopupMenu.PopupBaseMenuItem({ reactive: false, @@ -121,12 +118,6 @@ class Indicator extends PanelMenu.Button { }); this.menu.addMenuItem(this._buttonMenu); -// let item = new PopupMenu.PopupMenuItem(_('Reload')); -// item.connect('activate', () => { -// this.updateStatus ( ); -// }); -// this.menu.addMenuItem(item); - let _path = Me.path + '/img/monito.png'; let _icon = new St.Icon({ gicon: Gio.icon_new_for_string(_path), @@ -156,17 +147,22 @@ class Indicator extends PanelMenu.Button { x_expand: true }); _intermediate.actor.add_actor(this._box); + this.menu_orig = this.menu; this.updateStatus ( ); this.setupTimeout ( ); } + cancelTimeout ( ) + { + if (this.timeout) + Mainloop.source_remove(this.timeout); + } + setupTimeout ( ) { monitoLog ( 'Setting up timeout of ' + settings.get_int ( "poll-delay" ) + ' secs' ); - if (this.timeout) { - Mainloop.source_remove(this.timeout); - } + this.cancelTimeout ( ); this.timeout = Mainloop.timeout_add ( settings.get_int ( "poll-delay" ) * 1000, Lang.bind(this, this.updateStatus ) ); } @@ -181,7 +177,7 @@ class Indicator extends PanelMenu.Button { { for ( let _server of Preferences.getServersList() ) { - let _account_settings = Preferences.getAccountSettings ( _server ); + let _account_settings = Preferences.getAccountSettings ( this.server ); let type = _account_settings.get_string("type"); let username = _account_settings.get_string("username"); @@ -196,14 +192,14 @@ class Indicator extends PanelMenu.Button { { let _serverLogic; if ( type == 'Icinga' ) - _serverLogic = new Icinga ( _server ); + _serverLogic = new Icinga ( this.server ); else if ( type == 'Icinga2' ) - _serverLogic = new Icinga2 ( _server ); + _serverLogic = new Icinga2 ( this.server ); if ( ! _serverLogic.refresh ( this ) ) { - this.warningBoxes[_server].set_text ( '…' ); - this.criticalBoxes[_server].set_text ( '…' ); + this.warningBoxes[this.server].set_text ( '…' ); + this.criticalBoxes[this.server].set_text ( '…' ); // TODO: Add display of error if any } } @@ -294,7 +290,7 @@ class Indicator extends PanelMenu.Button { this.warningBoxes[serverLogic.server].set_text ( String(_status.WARNING) ); this.criticalBoxes[serverLogic.server].set_text ( String(_status.CRITICAL) ); - + return; } @@ -341,23 +337,32 @@ class Extension { constructor(uuid) { this._uuid = uuid; + settings.connect("changed::servers", Lang.bind ( this, function(stgs, key) { + this.disable ( ); + this.enable ( ); + } ) ); + ExtensionUtils.initTranslations(GETTEXT_DOMAIN); } enable() { - this._indicator = new Indicator(); + this._indicators = { }; - Main.panel.addToStatusArea(this._uuid, this._indicator); + for ( let _server of Preferences.getServersList() ) + { + this._indicators [ _server ] = new Indicator(_server); + Main.panel.addToStatusArea ( '%s-%d'.format ( this._uuid, _server), this._indicators [ _server ] ); + } } disable() { - this._indicator.destroy(); - this._indicator = null; + for ( var i of Object.keys(this._indicators) ) + { + this._indicators[i].cancelTimeout(); + this._indicators[i].destroy(); + } - if (_httpSession !== undefined) - _httpSession.abort(); - - _httpSession = undefined; + this._indicators = { }; } } diff --git a/servers/icinga.js b/servers/icinga.js index 5bdb4d9..45a5e02 100644 --- a/servers/icinga.js +++ b/servers/icinga.js @@ -65,8 +65,6 @@ class Icinga { _httpSession.queue_message(message, Lang.bind (this, function(_httpSession, message) { - log ( '>>> ' + message.status_code ); - if ( message.status_code != Soup.Status.OK ) { log ( '>>> error: ' + message.reason_phrase ); diff --git a/servers/icinga2.js b/servers/icinga2.js index 0be7a6e..964a573 100644 --- a/servers/icinga2.js +++ b/servers/icinga2.js @@ -74,8 +74,6 @@ class Icinga2 { handleMessage ( _httpSession, message ) { - log ( '>>> ' + message.status_code ); - if ( message.status_code != Soup.Status.OK ) { log ( '>>> error: ' + message.reason_phrase ); @@ -93,9 +91,6 @@ 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,