Better error handling

This commit is contained in:
Benjamin Drieu 2021-11-18 23:16:59 +01:00
parent 6230b03cff
commit 4ce284d782
4 changed files with 42 additions and 24 deletions

View File

@ -245,6 +245,12 @@ class Indicator extends PanelMenu.Button {
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',
hover: true,

View File

@ -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;
}
else
{
let json = JSON.parse(message.response_body.data);
this.status = json.status;
this.error = null;
}
let json = JSON.parse(message.response_body.data);
this.status = json.status;
extension.refreshUI ( this );
}
)
);
return true;
return this.status != null;
}
catch (e) {
Main.notify(_('Zbeu!'));

View File

@ -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 != { };
}
}

View File

@ -84,6 +84,11 @@
margin: 2px;
}
.monito-network-error {
font-size: 150%;
font-weight: bold;
}
.monito-button-icon {
padding: 0px;
margin: 0px;