Fix replacement bugs + implement correctly text-based filters
This commit is contained in:
parent
5a4ebbf486
commit
d7408fdf0a
@ -378,6 +378,7 @@ class Indicator extends PanelMenu.Button {
|
||||
let _columns = Preferences.getColumns ( this.server );
|
||||
for ( let _col of _columns )
|
||||
{
|
||||
entry [ 'real_' + _col ] = entry [ _col ];
|
||||
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' ) );
|
||||
@ -387,7 +388,7 @@ class Indicator extends PanelMenu.Button {
|
||||
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 ] ) );
|
||||
}
|
||||
if ( this.serverLogic.canRecheck )
|
||||
@ -419,6 +420,10 @@ class Indicator extends PanelMenu.Button {
|
||||
this.boxes['unknown'].set_text ( String(_status.UNKNOWN) );
|
||||
this.boxes['unknown'].get_parent().show ( );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.boxes['unknown'].get_parent().hide ( );
|
||||
}
|
||||
}
|
||||
catch ( e )
|
||||
{
|
||||
|
2
prefs.js
2
prefs.js
@ -59,8 +59,10 @@ const prefs = [
|
||||
{ type: Gtk.ColorButton, category: 'Colors', label: _('Unknown color'), key: 'unknown-fg', align: Gtk.Align.START },
|
||||
{ type: Gtk.Entry, category: 'Filters', label: _('Only display hosts matching'), key: 'host-grep' },
|
||||
{ type: Gtk.Entry, category: 'Filters', label: _('Only display services matching'), key: 'service-grep' },
|
||||
{ type: Gtk.Entry, category: 'Filters', label: _('Only display status info matching'), key: 'status-info-grep' },
|
||||
{ type: Gtk.Entry, category: 'Filters', label: _('Do <b>not</b> display hosts matching'), key: 'host-filter-out' },
|
||||
{ type: Gtk.Entry, category: 'Filters', label: _('Do <b>not</b> display services matching'), key: 'service-filter-out' },
|
||||
{ type: Gtk.Entry, category: 'Filters', label: _('Do <b>not</b> display status info matching'), key: 'status-info-filter-out' },
|
||||
{ type: Gtk.Entry, category: 'Replacements', label: _('Host regexp ...'), key: 'host-match' },
|
||||
{ type: Gtk.Entry, category: 'Replacements', label: _('... to replace with'), key: 'host-replace' },
|
||||
{ type: Gtk.Entry, category: 'Replacements', label: _('Service regexp ...'), key: 'service-match' },
|
||||
|
@ -125,6 +125,10 @@
|
||||
<default>''</default>
|
||||
</key>
|
||||
|
||||
<key name="status-info-grep" type="s">
|
||||
<default>''</default>
|
||||
</key>
|
||||
|
||||
<key name="host-filter-out" type="s">
|
||||
<default>''</default>
|
||||
</key>
|
||||
@ -133,6 +137,10 @@
|
||||
<default>''</default>
|
||||
</key>
|
||||
|
||||
<key name="status-info-filter-out" type="s">
|
||||
<default>''</default>
|
||||
</key>
|
||||
|
||||
<key name="host-match" type="s">
|
||||
<default>''</default>
|
||||
</key>
|
||||
|
@ -135,14 +135,57 @@ class GenericServer {
|
||||
{
|
||||
let status = this.status.service_status;
|
||||
|
||||
this.columns = Preferences.getColumns(this._server);
|
||||
this.sortOrder = Preferences.getSortOrder(this._server);
|
||||
this.columns = Preferences.getColumns ( this._server );
|
||||
this.sortOrder = Preferences.getSortOrder ( this._server );
|
||||
|
||||
status = this.filterStatus ( status );
|
||||
status = status.sort ( Lang.bind ( this, this.compareServices ) );
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
filterStatus ( status )
|
||||
{
|
||||
let filters = [ { prefKey: 'service-grep',
|
||||
entryKey: 'service_display_name',
|
||||
positive: true },
|
||||
{ prefKey: 'service-filter-out',
|
||||
entryKey: 'service_display_name',
|
||||
positive: false },
|
||||
{ prefKey: 'host-grep',
|
||||
entryKey: 'host_name',
|
||||
positive: true },
|
||||
{ prefKey: 'host-filter-out',
|
||||
entryKey: 'host_name',
|
||||
positive: false },
|
||||
{ prefKey: 'status-info-grep',
|
||||
entryKey: 'status_information',
|
||||
positive: true },
|
||||
{ prefKey: 'status-info-filter-out',
|
||||
entryKey: 'status_information',
|
||||
positive: false } ];
|
||||
|
||||
for ( var _filter of filters )
|
||||
_filter.value = this._settings.get_string ( _filter.prefKey );
|
||||
|
||||
entries: for ( var i = 0 ; i < status.length ; i ++ )
|
||||
{
|
||||
for ( var _filter of filters )
|
||||
{
|
||||
if ( _filter['value'] &&
|
||||
( status[i][_filter['entryKey']].match ( new RegExp ( _filter['value'], 'i' ) ) <= 0 ) == _filter['positive'] )
|
||||
{
|
||||
// log ( '> NOT MATCHING: %s =~ %s == %s ' . format ( status[i][_filter['entryKey']], _filter['value'], _filter['positive'] ) );
|
||||
status.splice ( i, 1 );
|
||||
i --; // This has been removed, so get back one step.
|
||||
continue entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
compareServices ( a, b )
|
||||
{
|
||||
|
@ -67,8 +67,8 @@ class Icinga extends GenericServer {
|
||||
// We have to do this manually since the default encoding of
|
||||
// Soup.form_request_new_from_hash is not understood by Icinga ... a shame!
|
||||
let params = 'cmd_typ=7&cmd_mod=2&host=%s&service=%s&start_time=%s&force_check=on&com_data=Recheck+by+Monito&btnSubmit=Commit' .
|
||||
format ( encodeURI ( entry.host_name ),
|
||||
encodeURI ( entry.service_description ),
|
||||
format ( encodeURI ( entry.real_host_name ),
|
||||
encodeURI ( entry.real_service_display_name ),
|
||||
encodeURI ( datestring ) );
|
||||
|
||||
let message = Soup.form_request_new_from_hash ( 'POST', cmdcgi, { } );
|
||||
|
@ -57,7 +57,7 @@ class Icinga2API extends GenericServer {
|
||||
{
|
||||
let message = Soup.form_request_new_from_hash ( 'POST', this.urlcgi + '/actions/reschedule-check', { } );
|
||||
|
||||
let params = '{ "type": "Service", "filter": "host.name==\\"%s\\" && service.name==\\"%s\\"", "force": true, "pretty": true }' . format ( encodeURI ( entry.host_name ), encodeURI ( entry.service_display_name ) );
|
||||
let params = '{ "type": "Service", "filter": "host.name==\\"%s\\" && service.name==\\"%s\\"", "force": true, "pretty": true }' . format ( encodeURI ( entry.real_host_name ), encodeURI ( entry.real_service_display_name ) );
|
||||
|
||||
message.request_body.truncate();
|
||||
message.request_body.append ( params );
|
||||
|
Loading…
Reference in New Issue
Block a user