From 25a3f7a6e87c8d0c90d434b47a36aeb79cc71edc Mon Sep 17 00:00:00 2001 From: Benjamin Drieu Date: Thu, 18 Nov 2021 23:16:59 +0100 Subject: [PATCH] Better error handling --- extension.js | 6 ++++++ servers/icinga.js | 16 ++++++++++------ servers/icinga2.js | 39 +++++++++++++++++++++------------------ stylesheet.css | 5 +++++ 4 files changed, 42 insertions(+), 24 deletions(-) diff --git a/extension.js b/extension.js index 11ba4e2..5ca0547 100644 --- a/extension.js +++ b/extension.js @@ -244,6 +244,12 @@ class Indicator extends PanelMenu.Button { this.initStatus ( ); // Specialize ! this._box.remove_all_children(); + + if ( serverLogic.error ) + { + this._box.add_child ( new St.Label ( { style_class: 'monito-network-error', text: serverLogic.error } ) ); + return; + } let headerBox = new St.BoxLayout({ style_class: 'monito-service-line', diff --git a/servers/icinga.js b/servers/icinga.js index 45a5e02..ce056e4 100644 --- a/servers/icinga.js +++ b/servers/icinga.js @@ -69,17 +69,21 @@ class Icinga { { log ( '>>> error: ' + message.reason_phrase ); Main.notify ( 'Monito: ' + name, message.reason_phrase ); - return; + this.status = null; + this.error = message.reason_phrase; } - - let json = JSON.parse(message.response_body.data); - this.status = json.status; - + else + { + let json = JSON.parse(message.response_body.data); + this.status = json.status; + this.error = null; + } + extension.refreshUI ( this ); } ) ); - return true; + return this.status != null; } catch (e) { Main.notify(_('Zbeu!')); diff --git a/servers/icinga2.js b/servers/icinga2.js index 964a573..b78ea26 100644 --- a/servers/icinga2.js +++ b/servers/icinga2.js @@ -74,35 +74,38 @@ class Icinga2 { handleMessage ( _httpSession, message ) { + this.status = { }; + this.status.service_status = [ ]; + if ( message.status_code != Soup.Status.OK ) { log ( '>>> error: ' + message.reason_phrase ); Main.notifyError ( 'Monito: ' + this.name, 'URL: ' + this.urlcgi + "\n" + message.status_code + ': ' + message.reason_phrase ); - return; + this.error = message.reason_phrase; } - - let json = JSON.parse(message.response_body.data); - let _statuses = [ 'OK', 'WARNING', 'CRITICAL', 'UNKNOWN' ]; - - this.status = { }; - this.status.service_status = [ ]; - - for ( var entry of json ) + else { - 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) * 1000 ) . toString(), - } ); + let json = JSON.parse(message.response_body.data); + let _statuses = [ 'OK', 'WARNING', 'CRITICAL', 'UNKNOWN' ]; + + for ( var entry of json ) + { + 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) * 1000 ) . toString(), + } ); + } + this.error = null; } this.extension.refreshUI ( this ); - return true; + return this.status != { }; } } diff --git a/stylesheet.css b/stylesheet.css index 315a095..ee81b33 100644 --- a/stylesheet.css +++ b/stylesheet.css @@ -84,6 +84,11 @@ margin: 2px; } +.monito-network-error { + font-size: 150%; + font-weight: bold; +} + .monito-button-icon { padding: 0px; margin: 0px;