Compare commits

...

2 Commits

Author SHA1 Message Date
Benjamin Drieu c4245fe199 Better multi-server implementation 2021-12-01 16:18:38 +01:00
Benjamin Drieu 42d4537b23 Implement recheck 2021-12-01 16:18:30 +01:00
5 changed files with 52 additions and 27 deletions

View File

@ -257,7 +257,7 @@ class Indicator extends PanelMenu.Button {
if ( ! col [ 'special' ] )
_child = new St.Label({ style_class: 'monito-label', text: text.toString(), });
else if ( col.special == 'actions' )
else if ( col.special == 'actions' && this.serverLogic.canRecheck )
{
_child = new St.BoxLayout ( { x_expand: true,
x_align: Clutter.ActorAlign.FILL,
@ -389,7 +389,8 @@ class Indicator extends PanelMenu.Button {
infoBox.add_child ( this.createBin ( entry.status, entry [ _col ], column_definitions [ _col ] ) );
}
infoBox.add_child ( this.createBin ( entry.status, entry, column_definitions [ 'actions' ] ) );
if ( this.serverLogic.canRecheck )
infoBox.add_child ( this.createBin ( entry.status, entry, column_definitions [ 'actions' ] ) );
_row ++;
}

View File

@ -29,7 +29,8 @@ const Me = ExtensionUtils.getCurrentExtension();
const Preferences = Me.imports.prefs;
class GenericServer {
class GenericServer {
constructor ( _server, _serverType = 'Generic' )
{
log ( '>>> New %s server #%s'.format ( _serverType, _server ) );
@ -38,6 +39,8 @@ class GenericServer {
this._settings = Preferences.getAccountSettings ( this._server );
this._httpSession = null;
this._url = null;
this.canRecheck = true;
}
getServer ( )
@ -105,6 +108,27 @@ class GenericServer {
}
}
handleCMDMessage ( _httpSession, message )
{
let _data;
try {
_data = this.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 );
}
}
getProcessedStatus ( )
{

View File

@ -104,26 +104,5 @@ class Icinga extends GenericServer {
log ( _data );
}
}
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 );
}
}
}

View File

@ -33,6 +33,8 @@ const GenericServer = Me.imports.servers.genericserver.GenericServer;
class Icinga2 extends GenericServer {
constructor ( _server ) {
super(_server, 'Icinga2');
this.canRecheck = false;
}
refresh ( extension ) {

View File

@ -31,6 +31,7 @@ const GenericServer = Me.imports.servers.genericserver.GenericServer;
class Icinga2API extends GenericServer {
constructor ( _server ) {
super(_server, 'Icinga2 API');
}
@ -46,13 +47,31 @@ class Icinga2API extends GenericServer {
{
super.prepareHttp ( );
let message = Soup.form_request_new_from_hash ( 'GET', this.urlcgi, { 'format': 'json' } );
let message = Soup.form_request_new_from_hash ( 'GET', this.urlcgi + '/objects/services', { } );
message.request_headers.append ( 'Accept', 'application/json' );
this.authenticateAndSend ( message );
this.authenticateAndSend ( message, this.handlePollMessage );
}
handleMessage ( _httpSession, message )
recheck ( entry )
{
let message = Soup.form_request_new_from_hash ( 'POST', this.urlcgi + '/actions/reschedule-check', { } );
let params = '{ "type": "Service", "filter": "host.name==\\"%s\\" && service.name==\\"%s\\"", "force": true, "pretty": true }' . format ( encodeURI ( entry.host_name ), encodeURI ( entry.service_display_name ) );
message.request_body.truncate();
message.request_body.append ( params );
message.request_body.flatten();
log ( '> Body: ' + message.request_body.data );
message.request_headers.append ( 'Accept', 'application/json' );
log ( message.request_headers );
this.authenticateAndSend ( message, this.handleCMDMessage );
}
handlePollMessage ( _httpSession, message )
{
let _data = super.handleMessage ( _httpSession, message );
try