Some cleanup + add Icinga2 API server
This commit is contained in:
parent
41c8def12c
commit
fd04906622
188
extension.js
188
extension.js
@ -49,6 +49,7 @@ const Convenience = Me.imports.convenience;
|
|||||||
const GenericServer = Me.imports.servers.genericserver.GenericServer;
|
const GenericServer = Me.imports.servers.genericserver.GenericServer;
|
||||||
const Icinga = Me.imports.servers.icinga.Icinga;
|
const Icinga = Me.imports.servers.icinga.Icinga;
|
||||||
const Icinga2 = Me.imports.servers.icinga2.Icinga2;
|
const Icinga2 = Me.imports.servers.icinga2.Icinga2;
|
||||||
|
const Icinga2API = Me.imports.servers.icinga2api.Icinga2API;
|
||||||
const Preferences = Me.imports.prefs;
|
const Preferences = Me.imports.prefs;
|
||||||
|
|
||||||
let settings = Convenience.getSettings(SETTINGS_SCHEMA);
|
let settings = Convenience.getSettings(SETTINGS_SCHEMA);
|
||||||
@ -86,6 +87,8 @@ class Indicator extends PanelMenu.Button {
|
|||||||
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 );
|
||||||
|
else if ( type == 'Icinga2API' )
|
||||||
|
this.serverLogic = new Icinga2API ( this.server );
|
||||||
|
|
||||||
this.initUI ( );
|
this.initUI ( );
|
||||||
}
|
}
|
||||||
@ -249,8 +252,11 @@ class Indicator extends PanelMenu.Button {
|
|||||||
createBin ( status, text, col ) {
|
createBin ( status, text, col ) {
|
||||||
let _child;
|
let _child;
|
||||||
|
|
||||||
|
if ( ! text )
|
||||||
|
text = '…';
|
||||||
|
|
||||||
if ( ! col [ 'special' ] )
|
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' )
|
else if ( col.special == 'actions' )
|
||||||
{
|
{
|
||||||
_child = new St.BoxLayout ( { x_expand: true,
|
_child = new St.BoxLayout ( { x_expand: true,
|
||||||
@ -291,17 +297,15 @@ class Indicator extends PanelMenu.Button {
|
|||||||
|
|
||||||
if ( row % 2 )
|
if ( row % 2 )
|
||||||
{
|
{
|
||||||
bgColor = this.lightenColor(bgColor, 16);
|
bgColor = this.lightenColor(bgColor, 12);
|
||||||
fgColor = this.lightenColor(fgColor, 16);
|
fgColor = this.lightenColor(fgColor, 12);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bgColor = this.lightenColor(bgColor, -16);
|
bgColor = this.lightenColor(bgColor, -12);
|
||||||
fgColor = this.lightenColor(fgColor, -16);
|
fgColor = this.lightenColor(fgColor, -12);
|
||||||
}
|
}
|
||||||
|
|
||||||
monitoLog ( 'background-color: %s; color: %s' . format ( bgColor, fgColor ) );
|
|
||||||
|
|
||||||
return 'background-color: %s; color: %s' . format ( bgColor, fgColor );
|
return 'background-color: %s; color: %s' . format ( bgColor, fgColor );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,102 +319,108 @@ class Indicator extends PanelMenu.Button {
|
|||||||
}
|
}
|
||||||
|
|
||||||
refreshUI ( ) {
|
refreshUI ( ) {
|
||||||
this.initStatus ( );
|
try {
|
||||||
|
this.initStatus ( );
|
||||||
|
|
||||||
this._box.remove_all_children();
|
this._box.remove_all_children();
|
||||||
|
|
||||||
if ( this.serverLogic.error || ! this.serverLogic.status )
|
if ( this.serverLogic.error || ! this.serverLogic.status )
|
||||||
{
|
{
|
||||||
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 } ) );
|
||||||
this.boxes['ok'].set_text ( '…' );
|
this.boxes['ok'].set_text ( '…' );
|
||||||
this.boxes['warning'].set_text ( '…' );
|
this.boxes['warning'].set_text ( '…' );
|
||||||
this.boxes['critical'].set_text ( '…' );
|
this.boxes['critical'].set_text ( '…' );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let headerBox = new St.BoxLayout({
|
let headerBox = new St.BoxLayout({
|
||||||
hover: true,
|
hover: true,
|
||||||
x_expand: true
|
x_expand: true
|
||||||
});
|
});
|
||||||
this._box.add_child(headerBox);
|
this._box.add_child(headerBox);
|
||||||
|
|
||||||
let _columns = Preferences.getColumns ( this.server );
|
let _columns = Preferences.getColumns ( this.server );
|
||||||
for ( let _col of _columns )
|
for ( let _col of _columns )
|
||||||
headerBox.add_child ( this.createHeaderBin ( _col ) );
|
headerBox.add_child ( this.createHeaderBin ( _col ) );
|
||||||
headerBox.add_child ( this.createHeaderBin ( 'actions' ) );
|
headerBox.add_child ( this.createHeaderBin ( 'actions' ) );
|
||||||
|
|
||||||
let scrollBox = new St.ScrollView ( { hscrollbar_policy: St.PolicyType.NEVER,
|
let scrollBox = new St.ScrollView ( { hscrollbar_policy: St.PolicyType.NEVER,
|
||||||
enable_mouse_scrolling: true, } );
|
enable_mouse_scrolling: true, } );
|
||||||
this._box.add_child(scrollBox);
|
this._box.add_child(scrollBox);
|
||||||
|
|
||||||
let tableBox = new St.BoxLayout({
|
let tableBox = new St.BoxLayout({
|
||||||
hover: true,
|
hover: true,
|
||||||
vertical: true,
|
vertical: true,
|
||||||
x_expand: true,
|
x_expand: true,
|
||||||
});
|
});
|
||||||
scrollBox.add_actor(tableBox);
|
scrollBox.add_actor(tableBox);
|
||||||
|
|
||||||
for ( let entryCount of this.serverLogic.getProcessedStatus ( ) )
|
let processedStatus = this.serverLogic.getProcessedStatus ( )
|
||||||
_status [ entryCount.status ] ++;
|
for ( let entryCount of processedStatus )
|
||||||
|
_status [ entryCount.status ] ++;
|
||||||
|
|
||||||
let _row = 0;
|
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' ) );
|
if ( ( ! _status [ 'WARNING' ] && ! _status [ 'CRITICAL' ] && ! _status [ 'UNKNOWN' ] && entry.status == 'OK' ) ||
|
||||||
|
( ( _status [ 'WARNING' ] || _status [ 'CRITICAL' ] || _status [ 'UNKNOWN' ] ) && entry.status != 'OK' ) )
|
||||||
|
{
|
||||||
|
let _style = this.getStyleForRow ( entry.status.toLowerCase(), _row );
|
||||||
|
let infoBox = new St.BoxLayout({
|
||||||
|
style_class: 'monito-service-line',
|
||||||
|
style: _style,
|
||||||
|
track_hover: true,
|
||||||
|
x_expand: true,
|
||||||
|
});
|
||||||
|
tableBox.add_child(infoBox);
|
||||||
|
|
||||||
let _style = this.getStyleForRow ( entry.status.toLowerCase(), _row );
|
let _columns = Preferences.getColumns ( this.server );
|
||||||
let infoBox = new St.BoxLayout({
|
for ( let _col of _columns )
|
||||||
style_class: 'monito-service-line',
|
{
|
||||||
style: _style,
|
if ( _col == 'host_name' && this.account_settings.get_string ( 'host-match' ) )
|
||||||
track_hover: true,
|
entry [ _col ] = entry [ _col ] . replace ( new RegExp ( this.account_settings.get_string ( 'host-match' ), 'i' ),
|
||||||
x_expand: true,
|
this.account_settings.get_string ( 'host-replace' ) );
|
||||||
});
|
else if ( _col == 'service_display_name' && this.account_settings.get_string ( 'service-match' ) )
|
||||||
tableBox.add_child(infoBox);
|
entry [ _col ] = entry [ _col ] . replace ( new RegExp ( this.account_settings.get_string ( 'service-match' ), 'i' ),
|
||||||
|
this.account_settings.get_string ( 'service-replace' ) );
|
||||||
|
else if ( _col == 'status_information' && this.account_settings.get_string ( 'status-info-match' ) )
|
||||||
|
entry [ _col ] = entry [ _col ] . replace ( new RegExp ( this.account_settings.get_string ( 'status-info-match' ), 'i' ),
|
||||||
|
this.account_settings.get_string ( 'status-info-replace' ) );
|
||||||
|
|
||||||
let _columns = Preferences.getColumns ( this.server );
|
infoBox.add_child ( this.createBin ( entry.status, entry [ _col ], column_definitions [ _col ] ) );
|
||||||
for ( let _col of _columns )
|
}
|
||||||
{
|
infoBox.add_child ( this.createBin ( entry.status, entry, column_definitions [ 'actions' ] ) );
|
||||||
if ( _col == 'host_name' && this.account_settings.get_string ( 'host-match' ) )
|
|
||||||
entry [ _col ] = entry [ _col ] . replace ( new RegExp ( this.account_settings.get_string ( 'host-match' ), 'i' ),
|
|
||||||
this.account_settings.get_string ( 'host-replace' ) );
|
|
||||||
else if ( _col == 'service_display_name' && this.account_settings.get_string ( 'service-match' ) )
|
|
||||||
entry [ _col ] = entry [ _col ] . replace ( new RegExp ( this.account_settings.get_string ( 'service-match' ), 'i' ),
|
|
||||||
this.account_settings.get_string ( 'service-replace' ) );
|
|
||||||
else if ( _col == 'status_information' && this.account_settings.get_string ( 'status-info-match' ) )
|
|
||||||
entry [ _col ] = entry [ _col ] . replace ( new RegExp ( this.account_settings.get_string ( 'status-info-match' ), 'i' ),
|
|
||||||
this.account_settings.get_string ( 'status-info-replace' ) );
|
|
||||||
|
|
||||||
infoBox.add_child ( this.createBin ( entry.status, entry [ _col ], column_definitions [ _col ] ) );
|
_row ++;
|
||||||
}
|
}
|
||||||
infoBox.add_child ( this.createBin ( entry.status, entry, column_definitions [ 'actions' ] ) );
|
|
||||||
|
|
||||||
_row ++;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ( _status.WARNING == 0 && _status.CRITICAL == 0 )
|
if ( _status.WARNING == 0 && _status.CRITICAL == 0 )
|
||||||
{
|
{
|
||||||
this.boxes['ok'].set_text ( String(_status.OK) );
|
this.boxes['ok'].set_text ( String(_status.OK) );
|
||||||
this.boxes['ok'].get_parent().show ( );
|
this.boxes['ok'].get_parent().show ( );
|
||||||
this.boxes['warning'].get_parent().hide ( );
|
this.boxes['warning'].get_parent().hide ( );
|
||||||
this.boxes['critical'].get_parent().hide ( );
|
this.boxes['critical'].get_parent().hide ( );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.boxes['warning'].set_text ( String(_status.WARNING) );
|
this.boxes['warning'].set_text ( String(_status.WARNING) );
|
||||||
this.boxes['critical'].set_text ( String(_status.CRITICAL) );
|
this.boxes['critical'].set_text ( String(_status.CRITICAL) );
|
||||||
this.boxes['ok'].get_parent().hide ( );
|
this.boxes['ok'].get_parent().hide ( );
|
||||||
this.boxes['warning'].get_parent().show ( );
|
this.boxes['warning'].get_parent().show ( );
|
||||||
this.boxes['critical'].get_parent().show ( );
|
this.boxes['critical'].get_parent().show ( );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( _status.UNKNOWN != 0 )
|
if ( _status.UNKNOWN != 0 )
|
||||||
|
{
|
||||||
|
this.boxes['unknown'].set_text ( String(_status.UNKNOWN) );
|
||||||
|
this.boxes['unkown'].get_parent().show ( );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch ( e )
|
||||||
{
|
{
|
||||||
this.boxes['unknown'].set_text ( String(_status.UNKNOWN) );
|
monitoLog ( 'RefreshUI error: ' + e );
|
||||||
this.boxes['unkown'].get_parent().show ( );
|
monitoLog ( e.stack );
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -430,8 +440,6 @@ class Indicator extends PanelMenu.Button {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_onSortColumnClick ( button ) {
|
_onSortColumnClick ( button ) {
|
||||||
monitoLog ( 'column >> ' + button.column );
|
|
||||||
|
|
||||||
let _sortOrder = Preferences.getSortOrder ( this.server );
|
let _sortOrder = Preferences.getSortOrder ( this.server );
|
||||||
let _columns = Preferences.getColumns ( this.server );
|
let _columns = Preferences.getColumns ( this.server );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user