Implement Icinga/Icinga2 logic
This commit is contained in:
parent
c6c7c48319
commit
332e51b1bf
@ -167,7 +167,7 @@ class Indicator extends PanelMenu.Button {
|
||||
if ( type == 'Icinga' )
|
||||
_serverLogic = new Icinga ( _server );
|
||||
else if ( type == 'Icinga2' )
|
||||
_serverLogic = new Icinga ( _server );
|
||||
_serverLogic = new Icinga2 ( _server );
|
||||
|
||||
if ( _serverLogic.refresh ( this ) )
|
||||
{
|
||||
|
85
servers/icinga.js
Normal file
85
servers/icinga.js
Normal file
@ -0,0 +1,85 @@
|
||||
/* -*- mode: js; js-basic-offset: 4; indent-tabs-mode: nil -*- */
|
||||
/*
|
||||
Monito Gnome-Shell extension
|
||||
Copyright (C) 2021 Benjamin Drieu
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
const { Soup } = imports.gi;
|
||||
|
||||
const ExtensionUtils = imports.misc.extensionUtils;
|
||||
const Me = ExtensionUtils.getCurrentExtension();
|
||||
const Preferences = Me.imports.prefs;
|
||||
const Lang = imports.lang;
|
||||
const Main = imports.ui.main;
|
||||
|
||||
let _httpSession;
|
||||
|
||||
|
||||
class Icinga {
|
||||
constructor ( _server ) {
|
||||
log ( '>>> New Icinga' + _server );
|
||||
this.server = _server
|
||||
}
|
||||
|
||||
refresh ( extension ) {
|
||||
let _settings = Preferences.getAccountSettings ( this.server );
|
||||
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 );
|
||||
log ( 'monito type >>> ' + type );
|
||||
log ( 'monito username >>> ' + username );
|
||||
|
||||
urlcgi = urlcgi.replace ( /^(https?:\/\/)/, '$1' + username + ':' + password + '@' );
|
||||
log ( 'monito urlcgi >>> ' + urlcgi );
|
||||
|
||||
if (_httpSession === undefined) {
|
||||
_httpSession = new Soup.Session();
|
||||
_httpSession.user_agent = Me.metadata.uuid;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
let message = Soup.form_request_new_from_hash ( 'GET', urlcgi, { 'jsonoutput': '' } );
|
||||
|
||||
_httpSession.queue_message(message, Lang.bind
|
||||
(this, function(_httpSession, message)
|
||||
{
|
||||
log ( '>>> ' + message.response_body.data );
|
||||
let json = JSON.parse(message.response_body.data);
|
||||
|
||||
this.status = json.status;
|
||||
|
||||
extension.refreshUI ( this );
|
||||
}
|
||||
)
|
||||
);
|
||||
return true;
|
||||
}
|
||||
catch (e) {
|
||||
Main.notify(_('Zbeu!'));
|
||||
log(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
94
servers/icinga2.js
Normal file
94
servers/icinga2.js
Normal file
@ -0,0 +1,94 @@
|
||||
/* -*- mode: js; js-basic-offset: 4; indent-tabs-mode: nil -*- */
|
||||
/*
|
||||
Monito Gnome-Shell extension
|
||||
Copyright (C) 2021 Benjamin Drieu
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
const { Soup } = imports.gi;
|
||||
|
||||
const ExtensionUtils = imports.misc.extensionUtils;
|
||||
const Me = ExtensionUtils.getCurrentExtension();
|
||||
const Preferences = Me.imports.prefs;
|
||||
const Lang = imports.lang;
|
||||
const Main = imports.ui.main;
|
||||
|
||||
let _httpSession;
|
||||
|
||||
|
||||
class Icinga2 {
|
||||
constructor ( _server ) {
|
||||
log ( '>>> New Icinga2' + _server );
|
||||
this.server = _server
|
||||
}
|
||||
|
||||
refresh ( extension ) {
|
||||
let _settings = Preferences.getAccountSettings ( this.server );
|
||||
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 );
|
||||
log ( 'monito type >>> ' + type );
|
||||
log ( 'monito username >>> ' + username );
|
||||
|
||||
// urlcgi = urlcgi.replace ( /^(https?:\/\/)/, '$1' + username + ':' + password + '@' );
|
||||
log ( 'monito urlcgi >>> ' + urlcgi );
|
||||
|
||||
if (_httpSession === undefined) {
|
||||
_httpSession = new Soup.Session();
|
||||
_httpSession.user_agent = Me.metadata.uuid;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
let message = Soup.form_request_new_from_hash ( 'GET', urlcgi, { 'format': 'json' } );
|
||||
message.request_headers.append ( 'Accept', 'application/json' );
|
||||
|
||||
let auth = new Soup.AuthBasic()
|
||||
auth.authenticate ( username, password );
|
||||
message.request_headers.append ( "Authorization", auth.get_authorization ( message ) );
|
||||
|
||||
|
||||
_httpSession.queue_message(message, Lang.bind
|
||||
(this, function(_httpSession, message)
|
||||
{
|
||||
// TODO format this in the manner of icinga1
|
||||
log ( '>>> ' + message.response_body.data );
|
||||
let json = JSON.parse(message.response_body.data);
|
||||
|
||||
this.status = json.status;
|
||||
|
||||
extension.refreshUI ( this );
|
||||
}
|
||||
)
|
||||
);
|
||||
return true;
|
||||
}
|
||||
catch (e) {
|
||||
Main.notify(_('Zbeu!'));
|
||||
log(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user