Unfuck
This commit is contained in:
parent
0e978af3d5
commit
c6c7c48319
98
extension.js
98
extension.js
@ -38,11 +38,14 @@ const Main = imports.ui.main;
|
|||||||
const PanelMenu = imports.ui.panelMenu;
|
const PanelMenu = imports.ui.panelMenu;
|
||||||
const PopupMenu = imports.ui.popupMenu;
|
const PopupMenu = imports.ui.popupMenu;
|
||||||
|
|
||||||
const { GObject, St, Soup, Clutter, Gio } = imports.gi;
|
const { GObject, St, Clutter, Gio } = imports.gi;
|
||||||
|
|
||||||
const SETTINGS_SCHEMA = "org.gnome.shell.extensions.monito@drieu.org";
|
const SETTINGS_SCHEMA = "org.gnome.shell.extensions.monito@drieu.org";
|
||||||
const Convenience = Me.imports.convenience;
|
const Convenience = Me.imports.convenience;
|
||||||
const Preferences = Me.imports.prefs;
|
const Preferences = Me.imports.prefs;
|
||||||
|
const Icinga = Me.imports.servers.icinga.Icinga;
|
||||||
|
const Icinga2 = Me.imports.servers.icinga2.Icinga2;
|
||||||
|
|
||||||
let settings = Convenience.getSettings(SETTINGS_SCHEMA);
|
let settings = Convenience.getSettings(SETTINGS_SCHEMA);
|
||||||
|
|
||||||
|
|
||||||
@ -147,22 +150,31 @@ class Indicator extends PanelMenu.Button {
|
|||||||
updateStatus ( ) {
|
updateStatus ( ) {
|
||||||
for ( let _server of Preferences.getServersList() )
|
for ( let _server of Preferences.getServersList() )
|
||||||
{
|
{
|
||||||
let account_settings = Preferences.getAccountSettings ( _server );
|
let _account_settings = Preferences.getAccountSettings ( _server );
|
||||||
|
|
||||||
let username = account_settings.get_string("username");
|
let type = _account_settings.get_string("type");
|
||||||
let password = account_settings.get_string("password");
|
let username = _account_settings.get_string("username");
|
||||||
let urlcgi = account_settings.get_string("urlcgi");
|
let password = _account_settings.get_string("password");
|
||||||
|
let urlcgi = _account_settings.get_string("urlcgi");
|
||||||
|
|
||||||
if ( ! urlcgi )
|
if ( ! urlcgi )
|
||||||
{
|
{
|
||||||
log ( 'Not updating monito because no URL configured' );
|
log ( 'Not updating monito because no URL configured' );
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
let _serverLogic;
|
||||||
|
if ( type == 'Icinga' )
|
||||||
|
_serverLogic = new Icinga ( _server );
|
||||||
|
else if ( type == 'Icinga2' )
|
||||||
|
_serverLogic = new Icinga ( _server );
|
||||||
|
|
||||||
urlcgi = urlcgi.replace ( /^(https?:\/\/)/, '$1' + username + ':' + password + '@' );
|
if ( _serverLogic.refresh ( this ) )
|
||||||
log ( 'monito >>> ' + urlcgi );
|
{
|
||||||
|
this.warningBoxes[_server].set_text ( '…' );
|
||||||
this.load_data_async ( _server, urlcgi, { 'jsonoutput': '' } );
|
this.criticalBoxes[_server].set_text ( '…' );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,72 +189,44 @@ class Indicator extends PanelMenu.Button {
|
|||||||
return _bin;
|
return _bin;
|
||||||
}
|
}
|
||||||
|
|
||||||
load_data_async ( server, url, params ) {
|
refreshUI ( serverLogic ) {
|
||||||
if (_httpSession === undefined) {
|
this.initStatus ( ); // Specialize !
|
||||||
_httpSession = new Soup.Session();
|
|
||||||
_httpSession.user_agent = Me.metadata.uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
let message = Soup.form_request_new_from_hash('GET', url, params);
|
|
||||||
|
|
||||||
_httpSession.queue_message(message, Lang.bind(this, function(_httpSession, message) {
|
|
||||||
// Main.notify(message.response_body.data);
|
|
||||||
log ( '>>> ' + message.response_body.data );
|
|
||||||
try {
|
|
||||||
// log ( message.response_body.data );
|
|
||||||
let json = JSON.parse(message.response_body.data);
|
|
||||||
|
|
||||||
this.initStatus ( );
|
|
||||||
|
|
||||||
this._box.remove_all_children();
|
this._box.remove_all_children();
|
||||||
|
|
||||||
for ( let i = 0 ; i < json.status.service_status.length ; i ++ )
|
for ( let i = 0 ; i < serverLogic.status.service_status.length ; i ++ )
|
||||||
{
|
{
|
||||||
_status [ json.status.service_status[i].status ] ++;
|
_status [ serverLogic.status.service_status[i].status ] ++;
|
||||||
if ( json.status.service_status[i].status != 'OK' )
|
if ( serverLogic.status.service_status[i].status != 'OK' )
|
||||||
{
|
{
|
||||||
let infoBox = new St.BoxLayout({
|
let infoBox = new St.BoxLayout({
|
||||||
style_class: 'monito-service-line monito-service-line-' + json.status.service_status[i].status,
|
style_class: 'monito-service-line monito-service-line-' + serverLogic.status.service_status[i].status,
|
||||||
hover: true,
|
hover: true,
|
||||||
x_expand: true
|
x_expand: true
|
||||||
});
|
});
|
||||||
this._box.add_child(infoBox);
|
this._box.add_child(infoBox);
|
||||||
|
|
||||||
infoBox.add_child ( this.createBin ( json.status.service_status[i].status,
|
infoBox.add_child ( this.createBin ( serverLogic.status.service_status[i].status,
|
||||||
json.status.service_status[i].host_name,
|
serverLogic.status.service_status[i].host_name,
|
||||||
0 ) );
|
0 ) );
|
||||||
infoBox.add_child ( this.createBin ( json.status.service_status[i].status,
|
infoBox.add_child ( this.createBin ( serverLogic.status.service_status[i].status,
|
||||||
json.status.service_status[i].service_display_name,
|
serverLogic.status.service_status[i].service_display_name,
|
||||||
1 ) );
|
1 ) );
|
||||||
infoBox.add_child ( this.createBin ( json.status.service_status[i].status,
|
infoBox.add_child ( this.createBin ( serverLogic.status.service_status[i].status,
|
||||||
json.status.service_status[i].last_check,
|
serverLogic.status.service_status[i].last_check,
|
||||||
2) );
|
2) );
|
||||||
infoBox.add_child ( this.createBin ( json.status.service_status[i].status,
|
infoBox.add_child ( this.createBin ( serverLogic.status.service_status[i].status,
|
||||||
json.status.service_status[i].attempts,
|
serverLogic.status.service_status[i].attempts,
|
||||||
3 ) );
|
3 ) );
|
||||||
infoBox.add_child ( this.createBin ( json.status.service_status[i].status,
|
infoBox.add_child ( this.createBin ( serverLogic.status.service_status[i].status,
|
||||||
json.status.service_status[i].status_information,
|
serverLogic.status.service_status[i].status_information,
|
||||||
4 ) );
|
4 ) );
|
||||||
|
|
||||||
// let url = 'https://xxx:xxx@host/cgi-bin/icinga/extinfo.cgi?type=2&host='+json.status.service_status[i].host_name+"&service="+json.status.service_status[i].service_description;
|
|
||||||
// activeLabel.connect('button-press-event', () => {
|
|
||||||
// Main.notify(url);
|
|
||||||
// Gtk.show_uri(null, url, global.get_current_time());
|
|
||||||
// } );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// _ok_text.set_text ( String(_status.OK) );
|
this.warningBoxes[serverLogic.server].set_text ( String(_status.WARNING) );
|
||||||
this.warningBoxes[server].set_text ( String(_status.WARNING) );
|
this.criticalBoxes[serverLogic.server].set_text ( String(_status.CRITICAL) );
|
||||||
this.criticalBoxes[server].set_text ( String(_status.CRITICAL) );
|
|
||||||
} catch (e) {
|
|
||||||
Main.notify(_('Zbeu!'));
|
|
||||||
this.warningBoxes[server].set_text ( '…' );
|
|
||||||
this.criticalBoxes[server].set_text ( '…' );
|
|
||||||
log(e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user