Compare commits
4 Commits
64806075b6
...
07dc49fd13
Author | SHA1 | Date | |
---|---|---|---|
07dc49fd13 | |||
c4a9402e4e | |||
ffebd4d6a0 | |||
93d4e485ae |
186
extension.js
186
extension.js
@ -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,102 +319,108 @@ class Indicator extends PanelMenu.Button {
|
||||
}
|
||||
|
||||
refreshUI ( ) {
|
||||
this.initStatus ( );
|
||||
try {
|
||||
this.initStatus ( );
|
||||
|
||||
this._box.remove_all_children();
|
||||
this._box.remove_all_children();
|
||||
|
||||
if ( this.serverLogic.error || ! this.serverLogic.status )
|
||||
{
|
||||
this._box.add_child ( new St.Label ( { style_class: 'monito-network-error', text: this.serverLogic.error } ) );
|
||||
this.boxes['ok'].set_text ( '…' );
|
||||
this.boxes['warning'].set_text ( '…' );
|
||||
this.boxes['critical'].set_text ( '…' );
|
||||
return;
|
||||
}
|
||||
if ( this.serverLogic.error || ! this.serverLogic.status )
|
||||
{
|
||||
this._box.add_child ( new St.Label ( { style_class: 'monito-network-error', text: this.serverLogic.error } ) );
|
||||
this.boxes['ok'].set_text ( '…' );
|
||||
this.boxes['warning'].set_text ( '…' );
|
||||
this.boxes['critical'].set_text ( '…' );
|
||||
return;
|
||||
}
|
||||
|
||||
let headerBox = new St.BoxLayout({
|
||||
hover: true,
|
||||
x_expand: true
|
||||
});
|
||||
this._box.add_child(headerBox);
|
||||
let headerBox = new St.BoxLayout({
|
||||
hover: true,
|
||||
x_expand: true
|
||||
});
|
||||
this._box.add_child(headerBox);
|
||||
|
||||
let _columns = Preferences.getColumns ( this.server );
|
||||
for ( let _col of _columns )
|
||||
headerBox.add_child ( this.createHeaderBin ( _col ) );
|
||||
headerBox.add_child ( this.createHeaderBin ( 'actions' ) );
|
||||
let _columns = Preferences.getColumns ( this.server );
|
||||
for ( let _col of _columns )
|
||||
headerBox.add_child ( this.createHeaderBin ( _col ) );
|
||||
headerBox.add_child ( this.createHeaderBin ( 'actions' ) );
|
||||
|
||||
let scrollBox = new St.ScrollView ( { hscrollbar_policy: St.PolicyType.NEVER,
|
||||
enable_mouse_scrolling: true, } );
|
||||
this._box.add_child(scrollBox);
|
||||
let scrollBox = new St.ScrollView ( { hscrollbar_policy: St.PolicyType.NEVER,
|
||||
enable_mouse_scrolling: true, } );
|
||||
this._box.add_child(scrollBox);
|
||||
|
||||
let tableBox = new St.BoxLayout({
|
||||
hover: true,
|
||||
vertical: true,
|
||||
x_expand: true,
|
||||
});
|
||||
scrollBox.add_actor(tableBox);
|
||||
let tableBox = new St.BoxLayout({
|
||||
hover: true,
|
||||
vertical: true,
|
||||
x_expand: true,
|
||||
});
|
||||
scrollBox.add_actor(tableBox);
|
||||
|
||||
for ( let entryCount of this.serverLogic.getProcessedStatus ( ) )
|
||||
_status [ entryCount.status ] ++;
|
||||
let processedStatus = this.serverLogic.getProcessedStatus ( )
|
||||
for ( let entryCount of processedStatus )
|
||||
_status [ entryCount.status ] ++;
|
||||
|
||||
let _row = 0;
|
||||
for ( let entry of this.serverLogic.getProcessedStatus ( ) )
|
||||
{
|
||||
if ( ( ! _status [ 'WARNING' ] && ! _status [ 'CRITICAL' ] && ! _status [ 'UNKNOWN' ] && entry.status == 'OK' ) ||
|
||||
( ( _status [ 'WARNING' ] || _status [ 'CRITICAL' ] || _status [ 'UNKNOWN' ] ) && entry.status != 'OK' ) )
|
||||
let _row = 0;
|
||||
for ( let entry of processedStatus )
|
||||
{
|
||||
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 infoBox = new St.BoxLayout({
|
||||
style_class: 'monito-service-line',
|
||||
style: _style,
|
||||
track_hover: true,
|
||||
x_expand: true,
|
||||
});
|
||||
tableBox.add_child(infoBox);
|
||||
let _columns = Preferences.getColumns ( this.server );
|
||||
for ( let _col of _columns )
|
||||
{
|
||||
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' ) );
|
||||
|
||||
let _columns = Preferences.getColumns ( this.server );
|
||||
for ( let _col of _columns )
|
||||
{
|
||||
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 ] ) );
|
||||
}
|
||||
infoBox.add_child ( this.createBin ( entry.status, entry, column_definitions [ 'actions' ] ) );
|
||||
|
||||
infoBox.add_child ( this.createBin ( entry.status, entry [ _col ], column_definitions [ _col ] ) );
|
||||
}
|
||||
infoBox.add_child ( this.createBin ( entry.status, entry, column_definitions [ 'actions' ] ) );
|
||||
|
||||
_row ++;
|
||||
_row ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( _status.WARNING == 0 && _status.CRITICAL == 0 )
|
||||
{
|
||||
this.boxes['ok'].set_text ( String(_status.OK) );
|
||||
this.boxes['ok'].get_parent().show ( );
|
||||
this.boxes['warning'].get_parent().hide ( );
|
||||
this.boxes['critical'].get_parent().hide ( );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.boxes['warning'].set_text ( String(_status.WARNING) );
|
||||
this.boxes['critical'].set_text ( String(_status.CRITICAL) );
|
||||
this.boxes['ok'].get_parent().hide ( );
|
||||
this.boxes['warning'].get_parent().show ( );
|
||||
this.boxes['critical'].get_parent().show ( );
|
||||
}
|
||||
if ( _status.WARNING == 0 && _status.CRITICAL == 0 )
|
||||
{
|
||||
this.boxes['ok'].set_text ( String(_status.OK) );
|
||||
this.boxes['ok'].get_parent().show ( );
|
||||
this.boxes['warning'].get_parent().hide ( );
|
||||
this.boxes['critical'].get_parent().hide ( );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.boxes['warning'].set_text ( String(_status.WARNING) );
|
||||
this.boxes['critical'].set_text ( String(_status.CRITICAL) );
|
||||
this.boxes['ok'].get_parent().hide ( );
|
||||
this.boxes['warning'].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) );
|
||||
this.boxes['unkown'].get_parent().show ( );
|
||||
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 );
|
||||
|
||||
|
6
prefs.js
6
prefs.js
@ -277,8 +277,10 @@ function createPrefWidgets ( noteBook, type, isActive )
|
||||
}
|
||||
else if ( prefEntry.key == 'type' )
|
||||
{
|
||||
[ 'Icinga', 'Icinga2' ].forEach((item) => {
|
||||
this.prefWidgets[prefEntry.key].append_text(item);
|
||||
[ { name: 'Icinga', value: 'Icinga server' },
|
||||
{ name: 'Icinga2', value: 'Icinga2 server (without API)' },
|
||||
{ name: 'Icinga2API', value: 'Icinga2 server (with API)' } ].forEach((item) => {
|
||||
this.prefWidgets[prefEntry.key].insert ( -1, item.name, item.value );
|
||||
} );
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
<enum id="org.gnome.shell.extensions.monito.MonitoringType">
|
||||
<value value="0" nick="Icinga"/>
|
||||
<value value="1" nick="Icinga2"/>
|
||||
<value value="2" nick="Icinga2API"/>
|
||||
</enum>
|
||||
|
||||
<enum id="org.gnome.shell.extensions.monito.DisplayType">
|
||||
|
@ -56,11 +56,11 @@ class GenericServer {
|
||||
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 );
|
||||
// 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 );
|
||||
}
|
||||
|
||||
|
||||
@ -91,8 +91,8 @@ class GenericServer {
|
||||
|
||||
if ( message.status_code != Soup.Status.OK )
|
||||
{
|
||||
log ( '>>> error: ' + message.reason_phrase );
|
||||
log ( '>>> data: ' + message.data );
|
||||
log ( '>>> Error: ' + message.reason_phrase );
|
||||
log ( '>>> Data: ' + message.data );
|
||||
Main.notifyError ( 'Monito: ' + this.name,
|
||||
'URL: ' + this.urlcgi + "\n" +
|
||||
message.status_code + ': ' + message.reason_phrase );
|
||||
@ -113,7 +113,6 @@ class GenericServer {
|
||||
this.columns = Preferences.getColumns(this._server);
|
||||
this.sortOrder = Preferences.getSortOrder(this._server);
|
||||
|
||||
log ( this.sortOrder );
|
||||
status = status.sort ( Lang.bind ( this, this.compareServices ) );
|
||||
|
||||
return status;
|
||||
@ -128,6 +127,9 @@ class GenericServer {
|
||||
let _order = _comparison.substring ( _comparison.length - 1, _comparison.length );
|
||||
if ( _name && _order && _name in a && _name in b )
|
||||
{
|
||||
if ( ! a [ _name ] )
|
||||
return 1;
|
||||
|
||||
let _result = a [ _name ] . localeCompare ( b [ _name ] );
|
||||
if ( _result != 0 )
|
||||
{
|
||||
|
90
servers/icinga2api.js
Normal file
90
servers/icinga2api.js
Normal file
@ -0,0 +1,90 @@
|
||||
/* -*- 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 Lang = imports.lang;
|
||||
const Main = imports.ui.main;
|
||||
const Me = ExtensionUtils.getCurrentExtension();
|
||||
const Preferences = Me.imports.prefs;
|
||||
const GenericServer = Me.imports.servers.genericserver.GenericServer;
|
||||
|
||||
|
||||
class Icinga2API extends GenericServer {
|
||||
constructor ( _server ) {
|
||||
super(_server, 'Icinga2 API');
|
||||
}
|
||||
|
||||
refresh ( extension ) {
|
||||
this.extension = extension;
|
||||
|
||||
this.buildURL ( );
|
||||
this.prepareHttp ( );
|
||||
}
|
||||
|
||||
prepareHttp ( )
|
||||
{
|
||||
super.prepareHttp ( );
|
||||
|
||||
let message = Soup.form_request_new_from_hash ( 'GET', this.urlcgi, { 'format': 'json' } );
|
||||
message.request_headers.append ( 'Accept', 'application/json' );
|
||||
|
||||
this.authenticateAndSend ( message );
|
||||
}
|
||||
|
||||
handleMessage ( _httpSession, message )
|
||||
{
|
||||
let _data = super.handleMessage ( _httpSession, message );
|
||||
try
|
||||
{
|
||||
if ( this.error )
|
||||
log ( 'Parent error ' + this.error );
|
||||
else
|
||||
{
|
||||
let json = JSON.parse ( _data );
|
||||
let _statuses = [ 'OK', 'WARNING', 'CRITICAL', 'UNKNOWN' ];
|
||||
|
||||
for ( var entry of json.results )
|
||||
{
|
||||
this.status.service_status.push ( {
|
||||
status: _statuses [ entry.attrs.state ],
|
||||
host_name: entry.attrs.host_name,
|
||||
service_display_name: entry.attrs.display_name,
|
||||
attempts: '%d/%d'.format(entry.attrs.check_attempt,entry.attrs.max_check_attempts),
|
||||
status_information: entry.attrs.last_check_result.output,
|
||||
last_check: new Date ( entry.attrs.last_state_change * 1000 ) . toString(),
|
||||
} );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( e )
|
||||
{
|
||||
log ( '> ERROR: ' + e );
|
||||
log ( '> DATA: ' + _data );
|
||||
}
|
||||
|
||||
this.extension.refreshUI ( this );
|
||||
return ! this.error;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user