Some cleanup + add Icinga2 API server

This commit is contained in:
Benjamin Drieu 2021-12-01 15:27:25 +01:00 committed by Benjamin Drieu
parent 64806075b6
commit 93d4e485ae
1 changed files with 98 additions and 90 deletions

View File

@ -49,6 +49,7 @@ const Convenience = Me.imports.convenience;
const GenericServer = Me.imports.servers.genericserver.GenericServer;
const Icinga = Me.imports.servers.icinga.Icinga;
const Icinga2 = Me.imports.servers.icinga2.Icinga2;
const Icinga2API = Me.imports.servers.icinga2api.Icinga2API;
const Preferences = Me.imports.prefs;
let settings = Convenience.getSettings(SETTINGS_SCHEMA);
@ -86,6 +87,8 @@ class Indicator extends PanelMenu.Button {
this.serverLogic = new Icinga ( this.server );
else if ( type == 'Icinga2' )
this.serverLogic = new Icinga2 ( this.server );
else if ( type == 'Icinga2API' )
this.serverLogic = new Icinga2API ( this.server );
this.initUI ( );
}
@ -249,8 +252,11 @@ class Indicator extends PanelMenu.Button {
createBin ( status, text, col ) {
let _child;
if ( ! text )
text = '…';
if ( ! col [ 'special' ] )
_child = new St.Label({ style_class: 'monito-label', text: text, });
_child = new St.Label({ style_class: 'monito-label', text: text.toString(), });
else if ( col.special == 'actions' )
{
_child = new St.BoxLayout ( { x_expand: true,
@ -291,17 +297,15 @@ class Indicator extends PanelMenu.Button {
if ( row % 2 )
{
bgColor = this.lightenColor(bgColor, 16);
fgColor = this.lightenColor(fgColor, 16);
bgColor = this.lightenColor(bgColor, 12);
fgColor = this.lightenColor(fgColor, 12);
}
else
{
bgColor = this.lightenColor(bgColor, -16);
fgColor = this.lightenColor(fgColor, -16);
bgColor = this.lightenColor(bgColor, -12);
fgColor = this.lightenColor(fgColor, -12);
}
monitoLog ( 'background-color: %s; color: %s' . format ( bgColor, fgColor ) );
return 'background-color: %s; color: %s' . format ( bgColor, fgColor );
}
@ -315,6 +319,7 @@ class Indicator extends PanelMenu.Button {
}
refreshUI ( ) {
try {
this.initStatus ( );
this._box.remove_all_children();
@ -350,17 +355,16 @@ class Indicator extends PanelMenu.Button {
});
scrollBox.add_actor(tableBox);
for ( let entryCount of this.serverLogic.getProcessedStatus ( ) )
let processedStatus = this.serverLogic.getProcessedStatus ( )
for ( let entryCount of processedStatus )
_status [ entryCount.status ] ++;
let _row = 0;
for ( let entry of this.serverLogic.getProcessedStatus ( ) )
for ( let entry of processedStatus )
{
if ( ( ! _status [ 'WARNING' ] && ! _status [ 'CRITICAL' ] && ! _status [ 'UNKNOWN' ] && entry.status == 'OK' ) ||
( ( _status [ 'WARNING' ] || _status [ 'CRITICAL' ] || _status [ 'UNKNOWN' ] ) && entry.status != 'OK' ) )
{
monitoLog ( this.account_settings.get_string ( entry.status.toLowerCase() + '-color' ) );
let _style = this.getStyleForRow ( entry.status.toLowerCase(), _row );
let infoBox = new St.BoxLayout({
style_class: 'monito-service-line',
@ -412,6 +416,12 @@ class Indicator extends PanelMenu.Button {
this.boxes['unknown'].set_text ( String(_status.UNKNOWN) );
this.boxes['unkown'].get_parent().show ( );
}
}
catch ( e )
{
monitoLog ( 'RefreshUI error: ' + e );
monitoLog ( e.stack );
}
return;
}
@ -430,8 +440,6 @@ class Indicator extends PanelMenu.Button {
}
_onSortColumnClick ( button ) {
monitoLog ( 'column >> ' + button.column );
let _sortOrder = Preferences.getSortOrder ( this.server );
let _columns = Preferences.getColumns ( this.server );