diff --git a/extension.js b/extension.js index ec3c294..5226ad5 100644 --- a/extension.js +++ b/extension.js @@ -49,6 +49,7 @@ const Convenience = Me.imports.convenience; const GenericServer = Me.imports.servers.genericserver.GenericServer; const Icinga = Me.imports.servers.icinga.Icinga; const Icinga2 = Me.imports.servers.icinga2.Icinga2; +const Icinga2API = Me.imports.servers.icinga2api.Icinga2API; const Preferences = Me.imports.prefs; let settings = Convenience.getSettings(SETTINGS_SCHEMA); @@ -86,6 +87,8 @@ class Indicator extends PanelMenu.Button { this.serverLogic = new Icinga ( this.server ); else if ( type == 'Icinga2' ) this.serverLogic = new Icinga2 ( this.server ); + else if ( type == 'Icinga2API' ) + this.serverLogic = new Icinga2API ( this.server ); this.initUI ( ); } @@ -249,8 +252,11 @@ class Indicator extends PanelMenu.Button { createBin ( status, text, col ) { let _child; + if ( ! text ) + text = '…'; + if ( ! col [ 'special' ] ) - _child = new St.Label({ style_class: 'monito-label', text: text, }); + _child = new St.Label({ style_class: 'monito-label', text: text.toString(), }); else if ( col.special == 'actions' ) { _child = new St.BoxLayout ( { x_expand: true, @@ -291,17 +297,15 @@ class Indicator extends PanelMenu.Button { if ( row % 2 ) { - bgColor = this.lightenColor(bgColor, 16); - fgColor = this.lightenColor(fgColor, 16); + bgColor = this.lightenColor(bgColor, 12); + fgColor = this.lightenColor(fgColor, 12); } else { - bgColor = this.lightenColor(bgColor, -16); - fgColor = this.lightenColor(fgColor, -16); + bgColor = this.lightenColor(bgColor, -12); + fgColor = this.lightenColor(fgColor, -12); } - monitoLog ( 'background-color: %s; color: %s' . format ( bgColor, fgColor ) ); - return 'background-color: %s; color: %s' . format ( bgColor, fgColor ); } @@ -315,102 +319,108 @@ class Indicator extends PanelMenu.Button { } refreshUI ( ) { - this.initStatus ( ); + try { + this.initStatus ( ); - this._box.remove_all_children(); + this._box.remove_all_children(); - if ( this.serverLogic.error || ! this.serverLogic.status ) - { - this._box.add_child ( new St.Label ( { style_class: 'monito-network-error', text: this.serverLogic.error } ) ); - this.boxes['ok'].set_text ( '…' ); - this.boxes['warning'].set_text ( '…' ); - this.boxes['critical'].set_text ( '…' ); - return; - } - - let headerBox = new St.BoxLayout({ - hover: true, - x_expand: true - }); - this._box.add_child(headerBox); + if ( this.serverLogic.error || ! this.serverLogic.status ) + { + this._box.add_child ( new St.Label ( { style_class: 'monito-network-error', text: this.serverLogic.error } ) ); + this.boxes['ok'].set_text ( '…' ); + this.boxes['warning'].set_text ( '…' ); + this.boxes['critical'].set_text ( '…' ); + return; + } + + let headerBox = new St.BoxLayout({ + hover: true, + x_expand: true + }); + this._box.add_child(headerBox); - let _columns = Preferences.getColumns ( this.server ); - for ( let _col of _columns ) - headerBox.add_child ( this.createHeaderBin ( _col ) ); - headerBox.add_child ( this.createHeaderBin ( 'actions' ) ); + let _columns = Preferences.getColumns ( this.server ); + for ( let _col of _columns ) + headerBox.add_child ( this.createHeaderBin ( _col ) ); + headerBox.add_child ( this.createHeaderBin ( 'actions' ) ); - let scrollBox = new St.ScrollView ( { hscrollbar_policy: St.PolicyType.NEVER, - enable_mouse_scrolling: true, } ); - this._box.add_child(scrollBox); + let scrollBox = new St.ScrollView ( { hscrollbar_policy: St.PolicyType.NEVER, + enable_mouse_scrolling: true, } ); + this._box.add_child(scrollBox); - let tableBox = new St.BoxLayout({ - hover: true, - vertical: true, - x_expand: true, - }); - scrollBox.add_actor(tableBox); + let tableBox = new St.BoxLayout({ + hover: true, + vertical: true, + x_expand: true, + }); + scrollBox.add_actor(tableBox); - for ( let entryCount of this.serverLogic.getProcessedStatus ( ) ) - _status [ entryCount.status ] ++; + let processedStatus = this.serverLogic.getProcessedStatus ( ) + for ( let entryCount of processedStatus ) + _status [ entryCount.status ] ++; - let _row = 0; - for ( let entry of this.serverLogic.getProcessedStatus ( ) ) - { - if ( ( ! _status [ 'WARNING' ] && ! _status [ 'CRITICAL' ] && ! _status [ 'UNKNOWN' ] && entry.status == 'OK' ) || - ( ( _status [ 'WARNING' ] || _status [ 'CRITICAL' ] || _status [ 'UNKNOWN' ] ) && entry.status != 'OK' ) ) + let _row = 0; + for ( let entry of processedStatus ) { - monitoLog ( this.account_settings.get_string ( entry.status.toLowerCase() + '-color' ) ); + if ( ( ! _status [ 'WARNING' ] && ! _status [ 'CRITICAL' ] && ! _status [ 'UNKNOWN' ] && entry.status == 'OK' ) || + ( ( _status [ 'WARNING' ] || _status [ 'CRITICAL' ] || _status [ 'UNKNOWN' ] ) && entry.status != 'OK' ) ) + { + let _style = this.getStyleForRow ( entry.status.toLowerCase(), _row ); + let infoBox = new St.BoxLayout({ + style_class: 'monito-service-line', + style: _style, + track_hover: true, + x_expand: true, + }); + tableBox.add_child(infoBox); - let _style = this.getStyleForRow ( entry.status.toLowerCase(), _row ); - let infoBox = new St.BoxLayout({ - style_class: 'monito-service-line', - style: _style, - track_hover: true, - x_expand: true, - }); - tableBox.add_child(infoBox); + let _columns = Preferences.getColumns ( this.server ); + for ( let _col of _columns ) + { + if ( _col == 'host_name' && this.account_settings.get_string ( 'host-match' ) ) + entry [ _col ] = entry [ _col ] . replace ( new RegExp ( this.account_settings.get_string ( 'host-match' ), 'i' ), + this.account_settings.get_string ( 'host-replace' ) ); + else if ( _col == 'service_display_name' && this.account_settings.get_string ( 'service-match' ) ) + entry [ _col ] = entry [ _col ] . replace ( new RegExp ( this.account_settings.get_string ( 'service-match' ), 'i' ), + this.account_settings.get_string ( 'service-replace' ) ); + else if ( _col == 'status_information' && this.account_settings.get_string ( 'status-info-match' ) ) + entry [ _col ] = entry [ _col ] . replace ( new RegExp ( this.account_settings.get_string ( 'status-info-match' ), 'i' ), + this.account_settings.get_string ( 'status-info-replace' ) ); - let _columns = Preferences.getColumns ( this.server ); - for ( let _col of _columns ) - { - if ( _col == 'host_name' && this.account_settings.get_string ( 'host-match' ) ) - entry [ _col ] = entry [ _col ] . replace ( new RegExp ( this.account_settings.get_string ( 'host-match' ), 'i' ), - this.account_settings.get_string ( 'host-replace' ) ); - else if ( _col == 'service_display_name' && this.account_settings.get_string ( 'service-match' ) ) - entry [ _col ] = entry [ _col ] . replace ( new RegExp ( this.account_settings.get_string ( 'service-match' ), 'i' ), - this.account_settings.get_string ( 'service-replace' ) ); - else if ( _col == 'status_information' && this.account_settings.get_string ( 'status-info-match' ) ) - entry [ _col ] = entry [ _col ] . replace ( new RegExp ( this.account_settings.get_string ( 'status-info-match' ), 'i' ), - this.account_settings.get_string ( 'status-info-replace' ) ); + infoBox.add_child ( this.createBin ( entry.status, entry [ _col ], column_definitions [ _col ] ) ); + } + infoBox.add_child ( this.createBin ( entry.status, entry, column_definitions [ 'actions' ] ) ); - infoBox.add_child ( this.createBin ( entry.status, entry [ _col ], column_definitions [ _col ] ) ); - } - infoBox.add_child ( this.createBin ( entry.status, entry, column_definitions [ 'actions' ] ) ); - - _row ++; + _row ++; + } } - } - if ( _status.WARNING == 0 && _status.CRITICAL == 0 ) - { - this.boxes['ok'].set_text ( String(_status.OK) ); - this.boxes['ok'].get_parent().show ( ); - this.boxes['warning'].get_parent().hide ( ); - this.boxes['critical'].get_parent().hide ( ); - } - else - { - this.boxes['warning'].set_text ( String(_status.WARNING) ); - this.boxes['critical'].set_text ( String(_status.CRITICAL) ); - this.boxes['ok'].get_parent().hide ( ); - this.boxes['warning'].get_parent().show ( ); - this.boxes['critical'].get_parent().show ( ); - } + if ( _status.WARNING == 0 && _status.CRITICAL == 0 ) + { + this.boxes['ok'].set_text ( String(_status.OK) ); + this.boxes['ok'].get_parent().show ( ); + this.boxes['warning'].get_parent().hide ( ); + this.boxes['critical'].get_parent().hide ( ); + } + else + { + this.boxes['warning'].set_text ( String(_status.WARNING) ); + this.boxes['critical'].set_text ( String(_status.CRITICAL) ); + this.boxes['ok'].get_parent().hide ( ); + this.boxes['warning'].get_parent().show ( ); + this.boxes['critical'].get_parent().show ( ); + } - if ( _status.UNKNOWN != 0 ) + if ( _status.UNKNOWN != 0 ) + { + this.boxes['unknown'].set_text ( String(_status.UNKNOWN) ); + this.boxes['unkown'].get_parent().show ( ); + } + } + catch ( e ) { - this.boxes['unknown'].set_text ( String(_status.UNKNOWN) ); - this.boxes['unkown'].get_parent().show ( ); + monitoLog ( 'RefreshUI error: ' + e ); + monitoLog ( e.stack ); } return; @@ -430,8 +440,6 @@ class Indicator extends PanelMenu.Button { } _onSortColumnClick ( button ) { - monitoLog ( 'column >> ' + button.column ); - let _sortOrder = Preferences.getSortOrder ( this.server ); let _columns = Preferences.getColumns ( this.server );