Implement real multi-indicators extension + some cleanup
This commit is contained in:
parent
33522a08f9
commit
49f4cbebb4
131
extension.js
131
extension.js
@ -56,9 +56,11 @@ let account_settings = [ ];
|
|||||||
|
|
||||||
const Indicator = GObject.registerClass(
|
const Indicator = GObject.registerClass(
|
||||||
class Indicator extends PanelMenu.Button {
|
class Indicator extends PanelMenu.Button {
|
||||||
_init() {
|
_init(server) {
|
||||||
super._init(0.0, _('Monito Checker'));
|
super._init(0.0, _('Monito Checker'));
|
||||||
|
|
||||||
|
this.server = server;
|
||||||
|
|
||||||
this.initStatus ( );
|
this.initStatus ( );
|
||||||
|
|
||||||
this.namesBoxes = { };
|
this.namesBoxes = { };
|
||||||
@ -67,53 +69,48 @@ class Indicator extends PanelMenu.Button {
|
|||||||
this.unknownBoxes = { };
|
this.unknownBoxes = { };
|
||||||
|
|
||||||
this.initUI ( );
|
this.initUI ( );
|
||||||
|
|
||||||
settings.connect("changed::servers", Lang.bind ( this, function(stgs, key) {
|
|
||||||
monitoLog ( this );
|
|
||||||
this.remove_all_children ( );
|
|
||||||
this.initUI ( );
|
|
||||||
} ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
initUI ( ) {
|
initUI ( ) {
|
||||||
let box = new St.BoxLayout ( { } );
|
let box = new St.BoxLayout ( { } );
|
||||||
this.add_child(box);
|
this.add_child(box);
|
||||||
|
|
||||||
for ( let _server of Preferences.getServersList() )
|
monitoLog ( '> Server ' + this.server );
|
||||||
{
|
account_settings [ this.server ] = Preferences.getAccountSettings ( this.server );
|
||||||
monitoLog ( '> Server ' + _server );
|
let _account_settings = account_settings [ this.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 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' ) } );
|
||||||
let name_box = new St.BoxLayout( { style_class: 'monito-namebox' } );
|
name_box.add_child ( this.namesBoxes [ this.server ] );
|
||||||
this.namesBoxes [ _server ] = new St.Label ( { text: _account_settings.get_string ( 'name' ) } );
|
serverBox.add_child(name_box);
|
||||||
name_box.add_child ( this.namesBoxes [ _server ] );
|
_account_settings.bind ( 'name', this.namesBoxes [ this.server ], 'text', Gio.SettingsBindFlags.GET );
|
||||||
serverBox.add_child(name_box);
|
|
||||||
_account_settings.bind ( 'name', this.namesBoxes [ _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' ) );
|
let warning_box = new St.BoxLayout({ style_class: 'monito-warning-box monito-box' });
|
||||||
_account_settings.connect("changed::warning-color", Lang.bind ( { widget: warning_box }, setColor ) );
|
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 ] );
|
this.warningBoxes [ this.server ] = new St.Label({ text: String(_status['WARNING']) })
|
||||||
serverBox.add_child(warning_box);
|
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' ) );
|
let critical_box = new St.BoxLayout({ style_class: 'monito-critical-box monito-box' });
|
||||||
_account_settings.connect("changed::critical-color", Lang.bind ( { widget: critical_box }, setColor ) );
|
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 ] );
|
this.criticalBoxes [ this.server ] = new St.Label({ text: String(_status['CRITICAL']) })
|
||||||
serverBox.add_child(critical_box);
|
critical_box.add_child ( this.criticalBoxes [ this.server ] );
|
||||||
|
serverBox.add_child(critical_box);
|
||||||
}
|
|
||||||
|
|
||||||
box.add_child(PopupMenu.arrowIcon(St.Side.BOTTOM));
|
box.add_child(PopupMenu.arrowIcon(St.Side.BOTTOM));
|
||||||
|
|
||||||
|
this.menu_new = new PopupMenu.PopupMenu(this, Clutter.ActorAlign.START, St.Side.TOP, 0);
|
||||||
|
|
||||||
// Menu
|
// Menu
|
||||||
this._buttonMenu = new PopupMenu.PopupBaseMenuItem({
|
this._buttonMenu = new PopupMenu.PopupBaseMenuItem({
|
||||||
reactive: false,
|
reactive: false,
|
||||||
@ -121,12 +118,6 @@ class Indicator extends PanelMenu.Button {
|
|||||||
});
|
});
|
||||||
this.menu.addMenuItem(this._buttonMenu);
|
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 _path = Me.path + '/img/monito.png';
|
||||||
let _icon = new St.Icon({
|
let _icon = new St.Icon({
|
||||||
gicon: Gio.icon_new_for_string(_path),
|
gicon: Gio.icon_new_for_string(_path),
|
||||||
@ -156,17 +147,22 @@ class Indicator extends PanelMenu.Button {
|
|||||||
x_expand: true
|
x_expand: true
|
||||||
});
|
});
|
||||||
_intermediate.actor.add_actor(this._box);
|
_intermediate.actor.add_actor(this._box);
|
||||||
|
this.menu_orig = this.menu;
|
||||||
|
|
||||||
this.updateStatus ( );
|
this.updateStatus ( );
|
||||||
this.setupTimeout ( );
|
this.setupTimeout ( );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cancelTimeout ( )
|
||||||
|
{
|
||||||
|
if (this.timeout)
|
||||||
|
Mainloop.source_remove(this.timeout);
|
||||||
|
}
|
||||||
|
|
||||||
setupTimeout ( )
|
setupTimeout ( )
|
||||||
{
|
{
|
||||||
monitoLog ( 'Setting up timeout of ' + settings.get_int ( "poll-delay" ) + ' secs' );
|
monitoLog ( 'Setting up timeout of ' + settings.get_int ( "poll-delay" ) + ' secs' );
|
||||||
if (this.timeout) {
|
this.cancelTimeout ( );
|
||||||
Mainloop.source_remove(this.timeout);
|
|
||||||
}
|
|
||||||
this.timeout = Mainloop.timeout_add ( settings.get_int ( "poll-delay" ) * 1000, Lang.bind(this, this.updateStatus ) );
|
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() )
|
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 type = _account_settings.get_string("type");
|
||||||
let username = _account_settings.get_string("username");
|
let username = _account_settings.get_string("username");
|
||||||
@ -196,14 +192,14 @@ class Indicator extends PanelMenu.Button {
|
|||||||
{
|
{
|
||||||
let _serverLogic;
|
let _serverLogic;
|
||||||
if ( type == 'Icinga' )
|
if ( type == 'Icinga' )
|
||||||
_serverLogic = new Icinga ( _server );
|
_serverLogic = new Icinga ( this.server );
|
||||||
else if ( type == 'Icinga2' )
|
else if ( type == 'Icinga2' )
|
||||||
_serverLogic = new Icinga2 ( _server );
|
_serverLogic = new Icinga2 ( this.server );
|
||||||
|
|
||||||
if ( ! _serverLogic.refresh ( this ) )
|
if ( ! _serverLogic.refresh ( this ) )
|
||||||
{
|
{
|
||||||
this.warningBoxes[_server].set_text ( '…' );
|
this.warningBoxes[this.server].set_text ( '…' );
|
||||||
this.criticalBoxes[_server].set_text ( '…' );
|
this.criticalBoxes[this.server].set_text ( '…' );
|
||||||
// TODO: Add display of error if any
|
// 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.warningBoxes[serverLogic.server].set_text ( String(_status.WARNING) );
|
||||||
this.criticalBoxes[serverLogic.server].set_text ( String(_status.CRITICAL) );
|
this.criticalBoxes[serverLogic.server].set_text ( String(_status.CRITICAL) );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,23 +337,32 @@ class Extension {
|
|||||||
constructor(uuid) {
|
constructor(uuid) {
|
||||||
this._uuid = uuid;
|
this._uuid = uuid;
|
||||||
|
|
||||||
|
settings.connect("changed::servers", Lang.bind ( this, function(stgs, key) {
|
||||||
|
this.disable ( );
|
||||||
|
this.enable ( );
|
||||||
|
} ) );
|
||||||
|
|
||||||
ExtensionUtils.initTranslations(GETTEXT_DOMAIN);
|
ExtensionUtils.initTranslations(GETTEXT_DOMAIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
enable() {
|
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() {
|
disable() {
|
||||||
this._indicator.destroy();
|
for ( var i of Object.keys(this._indicators) )
|
||||||
this._indicator = null;
|
{
|
||||||
|
this._indicators[i].cancelTimeout();
|
||||||
|
this._indicators[i].destroy();
|
||||||
|
}
|
||||||
|
|
||||||
if (_httpSession !== undefined)
|
this._indicators = { };
|
||||||
_httpSession.abort();
|
|
||||||
|
|
||||||
_httpSession = undefined;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,8 +65,6 @@ class Icinga {
|
|||||||
_httpSession.queue_message(message, Lang.bind
|
_httpSession.queue_message(message, Lang.bind
|
||||||
(this, function(_httpSession, message)
|
(this, function(_httpSession, message)
|
||||||
{
|
{
|
||||||
log ( '>>> ' + message.status_code );
|
|
||||||
|
|
||||||
if ( message.status_code != Soup.Status.OK )
|
if ( message.status_code != Soup.Status.OK )
|
||||||
{
|
{
|
||||||
log ( '>>> error: ' + message.reason_phrase );
|
log ( '>>> error: ' + message.reason_phrase );
|
||||||
|
@ -74,8 +74,6 @@ class Icinga2 {
|
|||||||
|
|
||||||
handleMessage ( _httpSession, message )
|
handleMessage ( _httpSession, message )
|
||||||
{
|
{
|
||||||
log ( '>>> ' + message.status_code );
|
|
||||||
|
|
||||||
if ( message.status_code != Soup.Status.OK )
|
if ( message.status_code != Soup.Status.OK )
|
||||||
{
|
{
|
||||||
log ( '>>> error: ' + message.reason_phrase );
|
log ( '>>> error: ' + message.reason_phrase );
|
||||||
@ -93,9 +91,6 @@ class Icinga2 {
|
|||||||
|
|
||||||
for ( var entry of json )
|
for ( var entry of json )
|
||||||
{
|
{
|
||||||
// if ( entry.status != 0 )
|
|
||||||
// log ( JSON.stringify(entry, null, 2) );
|
|
||||||
|
|
||||||
this.status.service_status.push ( {
|
this.status.service_status.push ( {
|
||||||
status: _statuses [ entry.service_state ],
|
status: _statuses [ entry.service_state ],
|
||||||
host_name: entry.host_name,
|
host_name: entry.host_name,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user