Compare commits
2 Commits
5f70bdea9f
...
747778571a
Author | SHA1 | Date |
---|---|---|
Benjamin Drieu | 747778571a | |
Benjamin Drieu | b9d8ef5727 |
11
extension.js
11
extension.js
|
@ -199,12 +199,7 @@ class Indicator extends PanelMenu.Button {
|
||||||
|
|
||||||
updateStatus ( )
|
updateStatus ( )
|
||||||
{
|
{
|
||||||
if ( ! this.serverLogic.refresh ( this ) )
|
this.serverLogic.refresh ( this );
|
||||||
{
|
|
||||||
this.warningBoxes[this.server].set_text ( '…' );
|
|
||||||
this.criticalBoxes[this.server].set_text ( '…' );
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setupTimeout ( );
|
this.setupTimeout ( );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,9 +297,11 @@ class Indicator extends PanelMenu.Button {
|
||||||
|
|
||||||
this._box.remove_all_children();
|
this._box.remove_all_children();
|
||||||
|
|
||||||
if ( this.serverLogic.error )
|
if ( this.serverLogic.error || ! this.serverLogic.status )
|
||||||
{
|
{
|
||||||
this._box.add_child ( new St.Label ( { style_class: 'monito-network-error', text: this.serverLogic.error } ) );
|
this._box.add_child ( new St.Label ( { style_class: 'monito-network-error', text: this.serverLogic.error } ) );
|
||||||
|
this.warningBoxes[this.server].set_text ( '…' );
|
||||||
|
this.criticalBoxes[this.server].set_text ( '…' );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,13 +73,13 @@ class GenericServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
authenticateAndSend ( message )
|
authenticateAndSend ( message, callback = this.handleMessage )
|
||||||
{
|
{
|
||||||
let auth = new Soup.AuthBasic()
|
let auth = new Soup.AuthBasic()
|
||||||
auth.authenticate ( this.username, this.password );
|
auth.authenticate ( this.username, this.password );
|
||||||
message.request_headers.append ( "Authorization", auth.get_authorization ( message ) );
|
message.request_headers.append ( "Authorization", auth.get_authorization ( message ) );
|
||||||
|
|
||||||
this._httpSession.queue_message ( message, Lang.bind (this, this.handleMessage ) );
|
this._httpSession.queue_message ( message, Lang.bind (this, callback ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -57,24 +57,28 @@ class Icinga extends GenericServer {
|
||||||
|
|
||||||
recheck ( entry )
|
recheck ( entry )
|
||||||
{
|
{
|
||||||
|
// TODO: perhaps use a better idea, like if the urlcgi param
|
||||||
|
// is a directory, then appendinstead of changing... use a method for that?
|
||||||
let cmdcgi = this.urlcgi.replace ( /status.cgi/, 'cmd.cgi' );
|
let cmdcgi = this.urlcgi.replace ( /status.cgi/, 'cmd.cgi' );
|
||||||
let params = { cmd_typ: '7',
|
let d = new Date ( Date.now() );
|
||||||
cmd_mod: '2',
|
var datestring = '%04d-%02d-%02d+%02d:%02d:%02d'.format ( d.getFullYear(), d.getMonth() + 1, d.getDate(),
|
||||||
hostservice: '%s^%s'.format ( entry.host_name, entry.service_description.replaceAll ( ' ', '+' ) ),
|
d.getHours(), d.getMinutes(), d.getSeconds() );
|
||||||
start_time: '2021-11-22%2018:13:48',
|
|
||||||
force_check: 'on',
|
|
||||||
btnSubmit: 'Commit',
|
|
||||||
};
|
|
||||||
let message = Soup.form_request_new_from_hash ( 'POST', cmdcgi, params );
|
|
||||||
log ( JSON.stringify ( params ) );
|
|
||||||
|
|
||||||
// message.request_headers.append ( 'Accept', 'application/json' );
|
// We have to do this manually since the default encoding of
|
||||||
this.authenticateAndSend ( message );
|
// Soup.form_request_new_from_hash is not understood by Icinga ... a shame!
|
||||||
// cmd_typ: 7
|
let params = 'cmd_typ=7&cmd_mod=2&host=%s&service=%s&start_time=%s&force_check=on&com_data=Recheck+by+Monito&btnSubmit=Commit' .
|
||||||
// cmd_mod: 2
|
format ( encodeURI ( entry.host_name ),
|
||||||
// start_time: '2021-11-22 17:21:12'
|
encodeURI ( entry.service_description ),
|
||||||
// hostservice: srv03^servicename (avec encodage + à la place des ' ')
|
encodeURI ( datestring ) );
|
||||||
// force_check: on
|
|
||||||
|
let message = Soup.form_request_new_from_hash ( 'POST', cmdcgi, { } );
|
||||||
|
message.request_body.truncate();
|
||||||
|
message.request_body.append ( params );
|
||||||
|
message.request_body.flatten();
|
||||||
|
|
||||||
|
// TODO: change button to spinner
|
||||||
|
|
||||||
|
this.authenticateAndSend ( message, this.handleCMDMessage );
|
||||||
}
|
}
|
||||||
|
|
||||||
handleMessage ( _httpSession, message )
|
handleMessage ( _httpSession, message )
|
||||||
|
@ -92,7 +96,7 @@ class Icinga extends GenericServer {
|
||||||
|
|
||||||
this.extension.refreshUI ( this );
|
this.extension.refreshUI ( this );
|
||||||
|
|
||||||
return this.status != { };
|
return ! this.error;
|
||||||
}
|
}
|
||||||
catch ( e )
|
catch ( e )
|
||||||
{
|
{
|
||||||
|
@ -101,4 +105,25 @@ class Icinga extends GenericServer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleCMDMessage ( _httpSession, message )
|
||||||
|
{
|
||||||
|
let _data;
|
||||||
|
try {
|
||||||
|
_data = super.handleMessage ( _httpSession, message );
|
||||||
|
if ( this.error )
|
||||||
|
log ( 'Parent error ' + this.error );
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// if error, grep for class='errorMessage'
|
||||||
|
// else grep for class='successBox'
|
||||||
|
log ( 'Cmd output ' + _data );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch ( e )
|
||||||
|
{
|
||||||
|
log ( e );
|
||||||
|
log ( _data );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ class Icinga2 extends GenericServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.extension.refreshUI ( this );
|
this.extension.refreshUI ( this );
|
||||||
return this.status != { };
|
return ! this.error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue