Compare commits
2 Commits
886501cba2
...
d533f08e44
Author | SHA1 | Date | |
---|---|---|---|
d533f08e44 | |||
76319c11d5 |
26
extension.js
26
extension.js
@ -85,9 +85,9 @@ class Indicator extends PanelMenu.Button {
|
|||||||
|
|
||||||
let type = this.account_settings.get_string ( "type" );
|
let type = this.account_settings.get_string ( "type" );
|
||||||
if ( type == 'Icinga' )
|
if ( type == 'Icinga' )
|
||||||
this.serverlogic = new Icinga ( this.server );
|
this.serverLogic = new Icinga ( this.server );
|
||||||
else if ( type == 'Icinga2' )
|
else if ( type == 'Icinga2' )
|
||||||
this.serverlogic = new Icinga2 ( this.server );
|
this.serverLogic = new Icinga2 ( this.server );
|
||||||
|
|
||||||
this.initUI ( );
|
this.initUI ( );
|
||||||
}
|
}
|
||||||
@ -197,7 +197,7 @@ class Indicator extends PanelMenu.Button {
|
|||||||
|
|
||||||
updateStatus ( )
|
updateStatus ( )
|
||||||
{
|
{
|
||||||
if ( ! this.serverlogic.refresh ( this ) )
|
if ( ! this.serverLogic.refresh ( this ) )
|
||||||
{
|
{
|
||||||
this.warningBoxes[this.server].set_text ( '…' );
|
this.warningBoxes[this.server].set_text ( '…' );
|
||||||
this.criticalBoxes[this.server].set_text ( '…' );
|
this.criticalBoxes[this.server].set_text ( '…' );
|
||||||
@ -274,6 +274,8 @@ class Indicator extends PanelMenu.Button {
|
|||||||
y_align: Clutter.ActorAlign.CENTER,
|
y_align: Clutter.ActorAlign.CENTER,
|
||||||
can_focus: true,
|
can_focus: true,
|
||||||
} );
|
} );
|
||||||
|
_button.service = text;
|
||||||
|
_button.connect ( 'clicked', Lang.bind ( this, this._onRecheckButtonClick ) );
|
||||||
_button.child = new St.Icon ( {
|
_button.child = new St.Icon ( {
|
||||||
icon_name: 'view-refresh-symbolic',
|
icon_name: 'view-refresh-symbolic',
|
||||||
icon_size: 16,
|
icon_size: 16,
|
||||||
@ -298,9 +300,9 @@ class Indicator extends PanelMenu.Button {
|
|||||||
|
|
||||||
this._box.remove_all_children();
|
this._box.remove_all_children();
|
||||||
|
|
||||||
if ( this.serverlogic.error )
|
if ( this.serverLogic.error )
|
||||||
{
|
{
|
||||||
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 } ) );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,7 +328,7 @@ class Indicator extends PanelMenu.Button {
|
|||||||
});
|
});
|
||||||
scrollBox.add_actor(tableBox);
|
scrollBox.add_actor(tableBox);
|
||||||
|
|
||||||
for ( let entry of this.serverlogic.getProcessedStatus ( ) )
|
for ( let entry of this.serverLogic.getProcessedStatus ( ) )
|
||||||
{
|
{
|
||||||
_status [ entry.status ] ++;
|
_status [ entry.status ] ++;
|
||||||
if ( entry.status != 'OK' )
|
if ( entry.status != 'OK' )
|
||||||
@ -343,12 +345,12 @@ 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 [ _col ], column_definitions [ _col ] ) );
|
||||||
}
|
}
|
||||||
infoBox.add_child ( this.createBin ( entry.status, '', column_definitions [ 'actions' ] ) );
|
infoBox.add_child ( this.createBin ( entry.status, entry, column_definitions [ 'actions' ] ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.warningBoxes[this.serverlogic.server].set_text ( String(_status.WARNING) );
|
this.warningBoxes[this.server].set_text ( String(_status.WARNING) );
|
||||||
this.criticalBoxes[this.serverlogic.server].set_text ( String(_status.CRITICAL) );
|
this.criticalBoxes[this.server].set_text ( String(_status.CRITICAL) );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -386,6 +388,12 @@ class Indicator extends PanelMenu.Button {
|
|||||||
this.refreshUI ( );
|
this.refreshUI ( );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_onRecheckButtonClick ( e )
|
||||||
|
{
|
||||||
|
monitoLog ( JSON.stringify ( e.service ) );
|
||||||
|
this.serverLogic.recheck ( e.service );
|
||||||
|
}
|
||||||
|
|
||||||
_createButton ( icon, text, callback ) {
|
_createButton ( icon, text, callback ) {
|
||||||
let button = new St.Button({
|
let button = new St.Button({
|
||||||
x_align: Clutter.ActorAlign.END,
|
x_align: Clutter.ActorAlign.END,
|
||||||
|
@ -28,23 +28,88 @@ const Main = imports.ui.main;
|
|||||||
const Me = ExtensionUtils.getCurrentExtension();
|
const Me = ExtensionUtils.getCurrentExtension();
|
||||||
const Preferences = Me.imports.prefs;
|
const Preferences = Me.imports.prefs;
|
||||||
|
|
||||||
let _httpSession;
|
|
||||||
|
|
||||||
|
|
||||||
class GenericServer {
|
class GenericServer {
|
||||||
constructor ( _server, _serverType = 'Generic' )
|
constructor ( _server, _serverType = 'Generic' )
|
||||||
{
|
{
|
||||||
log ( '>>> New %s server #%s'.format ( _serverType, _server ) );
|
log ( '>>> New %s server #%s'.format ( _serverType, _server ) );
|
||||||
|
|
||||||
this.server = _server;
|
this._server = _server;
|
||||||
|
this._settings = Preferences.getAccountSettings ( this._server );
|
||||||
|
this._httpSession = null;
|
||||||
|
this._url = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getServer ( )
|
||||||
|
{
|
||||||
|
return this._server;
|
||||||
|
}
|
||||||
|
|
||||||
|
buildURL ( )
|
||||||
|
{
|
||||||
|
if ( ! this._settings )
|
||||||
|
this._settings = Preferences.getAccountSettings ( this._server );
|
||||||
|
|
||||||
|
this.type = this._settings.get_string ( "type" );
|
||||||
|
this.username = this._settings.get_string ( "username" );
|
||||||
|
this.name = this._settings.get_string ( "name" );
|
||||||
|
this.password = this._settings.get_string ( "password" );
|
||||||
|
this.urlcgi = this._settings.get_string ( "urlcgi" );
|
||||||
|
|
||||||
|
log ( 'monito server >>> ' + this._server );
|
||||||
|
log ( 'monito name >>> ' + this.name );
|
||||||
|
log ( 'monito type >>> ' + this.type );
|
||||||
|
log ( 'monito username >>> ' + this.username );
|
||||||
|
log ( 'monito urlcgi >>> ' + this.urlcgi );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
prepareHttp ( )
|
||||||
|
{
|
||||||
|
if ( this._httpSession == null ) {
|
||||||
|
this._httpSession = new Soup.Session();
|
||||||
|
this._httpSession.user_agent = Me.metadata.uuid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
authenticateAndSend ( message )
|
||||||
|
{
|
||||||
|
let auth = new Soup.AuthBasic()
|
||||||
|
auth.authenticate ( this.username, this.password );
|
||||||
|
message.request_headers.append ( "Authorization", auth.get_authorization ( message ) );
|
||||||
|
|
||||||
|
this._httpSession.queue_message ( message, Lang.bind (this, this.handleMessage ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 );
|
||||||
|
this.error = message.reason_phrase;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return message.response_body.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
getProcessedStatus ( )
|
getProcessedStatus ( )
|
||||||
{
|
{
|
||||||
let status = this.status.service_status;
|
let status = this.status.service_status;
|
||||||
|
|
||||||
this.columns = Preferences.getColumns(this.server);
|
this.columns = Preferences.getColumns(this._server);
|
||||||
this.sortOrder = Preferences.getSortOrder(this.server);
|
this.sortOrder = Preferences.getSortOrder(this._server);
|
||||||
|
|
||||||
log ( this.sortOrder );
|
log ( this.sortOrder );
|
||||||
status = status.sort ( Lang.bind ( this, this.compareServices ) );
|
status = status.sort ( Lang.bind ( this, this.compareServices ) );
|
||||||
@ -52,7 +117,7 @@ class GenericServer {
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
compareServices ( a, b )
|
compareServices ( a, b )
|
||||||
{
|
{
|
||||||
for ( let _comparison of this.sortOrder )
|
for ( let _comparison of this.sortOrder )
|
||||||
|
@ -38,57 +38,68 @@ class Icinga extends GenericServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
refresh ( extension ) {
|
refresh ( extension ) {
|
||||||
let _settings = Preferences.getAccountSettings ( this.server );
|
this.extension = extension;
|
||||||
log ( 'monito server >>> ' + this.server );
|
|
||||||
let type = _settings.get_string ( "type" );
|
|
||||||
let username = _settings.get_string ( "username" );
|
|
||||||
let name = _settings.get_string ( "name" );
|
|
||||||
let password = _settings.get_string ( "password" );
|
|
||||||
let urlcgi = _settings.get_string ( "urlcgi" );
|
|
||||||
|
|
||||||
log ( 'monito name >>> ' + name );
|
this.buildURL ( );
|
||||||
log ( 'monito type >>> ' + type );
|
this.prepareHttp ( );
|
||||||
log ( 'monito username >>> ' + username );
|
}
|
||||||
log ( 'monito urlcgi >>> ' + urlcgi );
|
|
||||||
|
|
||||||
urlcgi = urlcgi.replace ( /^(https?:\/\/)/, '$1' + username + ':' + password + '@' );
|
|
||||||
|
|
||||||
if (_httpSession === undefined) {
|
prepareHttp ( )
|
||||||
_httpSession = new Soup.Session();
|
{
|
||||||
_httpSession.user_agent = Me.metadata.uuid;
|
super.prepareHttp ( );
|
||||||
}
|
|
||||||
|
let message = Soup.form_request_new_from_hash ( 'GET', this.urlcgi, { 'jsonoutput': '' } );
|
||||||
|
message.request_headers.append ( 'Accept', 'application/json' );
|
||||||
|
|
||||||
|
this.authenticateAndSend ( message );
|
||||||
|
}
|
||||||
|
|
||||||
|
recheck ( entry )
|
||||||
|
{
|
||||||
|
let cmdcgi = this.urlcgi.replace ( /status.cgi/, 'cmd.cgi' );
|
||||||
|
let params = { cmd_typ: '7',
|
||||||
|
cmd_mod: '2',
|
||||||
|
hostservice: '%s^%s'.format ( entry.host_name, entry.service_description.replaceAll ( ' ', '+' ) ),
|
||||||
|
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' );
|
||||||
|
this.authenticateAndSend ( message );
|
||||||
|
// cmd_typ: 7
|
||||||
|
// cmd_mod: 2
|
||||||
|
// start_time: '2021-11-22 17:21:12'
|
||||||
|
// hostservice: srv03^servicename (avec encodage + à la place des ' ')
|
||||||
|
// force_check: on
|
||||||
|
}
|
||||||
|
|
||||||
|
handleMessage ( _httpSession, message )
|
||||||
|
{
|
||||||
|
let _data;
|
||||||
try {
|
try {
|
||||||
|
_data = super.handleMessage ( _httpSession, message );
|
||||||
|
if ( this.error )
|
||||||
|
log ( 'Parent error ' + this.error );
|
||||||
|
else
|
||||||
|
{
|
||||||
|
let json = JSON.parse ( _data );
|
||||||
|
this.status = json.status;
|
||||||
|
this.error = null;
|
||||||
|
}
|
||||||
|
|
||||||
let message = Soup.form_request_new_from_hash ( 'GET', urlcgi, { 'jsonoutput': '' } );
|
this.extension.refreshUI ( this );
|
||||||
|
|
||||||
_httpSession.queue_message(message, Lang.bind
|
return this.status != { };
|
||||||
(this, function(_httpSession, message)
|
|
||||||
{
|
|
||||||
if ( message.status_code != Soup.Status.OK )
|
|
||||||
{
|
|
||||||
log ( '>>> error: ' + message.reason_phrase );
|
|
||||||
Main.notify ( 'Monito: ' + name, message.reason_phrase );
|
|
||||||
this.status = null;
|
|
||||||
this.error = message.reason_phrase;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
let json = JSON.parse(message.response_body.data);
|
|
||||||
this.status = json.status;
|
|
||||||
this.error = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
extension.refreshUI ( this );
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
return this.status !== null;
|
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch ( e )
|
||||||
Main.notify(_('Zbeu!'));
|
{
|
||||||
log(e);
|
log ( e );
|
||||||
return false;
|
log ( _data );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,6 @@ const Me = ExtensionUtils.getCurrentExtension();
|
|||||||
const Preferences = Me.imports.prefs;
|
const Preferences = Me.imports.prefs;
|
||||||
const GenericServer = Me.imports.servers.genericserver.GenericServer;
|
const GenericServer = Me.imports.servers.genericserver.GenericServer;
|
||||||
|
|
||||||
let _httpSession;
|
|
||||||
|
|
||||||
|
|
||||||
class Icinga2 extends GenericServer {
|
class Icinga2 extends GenericServer {
|
||||||
constructor ( _server ) {
|
constructor ( _server ) {
|
||||||
@ -39,55 +37,29 @@ class Icinga2 extends GenericServer {
|
|||||||
|
|
||||||
refresh ( extension ) {
|
refresh ( extension ) {
|
||||||
this.extension = extension;
|
this.extension = extension;
|
||||||
this.settings = Preferences.getAccountSettings ( this.server );
|
|
||||||
log ( 'monito server >>> ' + this.server );
|
|
||||||
this.type = this.settings.get_string ( "type" );
|
|
||||||
this.username = this.settings.get_string ( "username" );
|
|
||||||
this.name = this.settings.get_string ( "name" );
|
|
||||||
this.password = this.settings.get_string ( "password" );
|
|
||||||
this.urlcgi = this.settings.get_string ( "urlcgi" );
|
|
||||||
|
|
||||||
log ( 'monito name >>> ' + this.name );
|
|
||||||
log ( 'monito type >>> ' + this.type );
|
|
||||||
log ( 'monito username >>> ' + this.username );
|
|
||||||
log ( 'monito urlcgi >>> ' + this.urlcgi );
|
|
||||||
|
|
||||||
|
this.buildURL ( );
|
||||||
this.prepareHttp ( );
|
this.prepareHttp ( );
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareHttp ( )
|
prepareHttp ( )
|
||||||
{
|
{
|
||||||
if (_httpSession === undefined) {
|
super.prepareHttp ( );
|
||||||
_httpSession = new Soup.Session();
|
|
||||||
_httpSession.user_agent = Me.metadata.uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
let message = Soup.form_request_new_from_hash ( 'GET', this.urlcgi, { 'format': 'json' } );
|
let message = Soup.form_request_new_from_hash ( 'GET', this.urlcgi, { 'format': 'json' } );
|
||||||
message.request_headers.append ( 'Accept', 'application/json' );
|
message.request_headers.append ( 'Accept', 'application/json' );
|
||||||
|
|
||||||
let auth = new Soup.AuthBasic()
|
this.authenticateAndSend ( message );
|
||||||
auth.authenticate ( this.username, this.password );
|
|
||||||
message.request_headers.append ( "Authorization", auth.get_authorization ( message ) );
|
|
||||||
|
|
||||||
_httpSession.queue_message ( message, Lang.bind (this, this.handleMessage ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleMessage ( _httpSession, message )
|
handleMessage ( _httpSession, message )
|
||||||
{
|
{
|
||||||
this.status = { };
|
let _data = super.handleMessage ( _httpSession, message );
|
||||||
this.status.service_status = [ ];
|
if ( this.error )
|
||||||
|
log ( 'Parent error ' + this.error );
|
||||||
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 );
|
|
||||||
this.error = message.reason_phrase;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
let json = JSON.parse(message.response_body.data);
|
let json = JSON.parse ( _data );
|
||||||
let _statuses = [ 'OK', 'WARNING', 'CRITICAL', 'UNKNOWN' ];
|
let _statuses = [ 'OK', 'WARNING', 'CRITICAL', 'UNKNOWN' ];
|
||||||
|
|
||||||
for ( var entry of json )
|
for ( var entry of json )
|
||||||
@ -104,7 +76,7 @@ class Icinga2 extends GenericServer {
|
|||||||
this.error = null;
|
this.error = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.extension.refreshUI ( this );
|
this.extension.refreshUI ( this );
|
||||||
return this.status != { };
|
return this.status != { };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user