diff --git a/Changes b/Changes index 24b0090..5360b1c 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ This file documents the revision history for the Livestatus Multitool Daemon (LMD) +next: + - fix more index based filters + 2.2.3 Wed Oct 23 14:32:15 CEST 2024 - fix index based filter using regex diff --git a/pkg/lmd/datastore.go b/pkg/lmd/datastore.go index 9306412..9db16da 100644 --- a/pkg/lmd/datastore.go +++ b/pkg/lmd/datastore.go @@ -504,6 +504,7 @@ func appendIndexHostsFromHostColumns(dStore *DataStore, uniqHosts map[string]boo // name =~ case EqualNocase: + uniqHosts[fil.StrValue] = true for _, key := range dStore.IndexLowerCase[strings.ToLower(fil.StrValue)] { uniqHosts[key] = true } @@ -516,6 +517,7 @@ func appendIndexHostsFromHostColumns(dStore *DataStore, uniqHosts map[string]boo switch fil.Operator { // name == case Equal, EqualNocase: + uniqHosts[fil.StrValue] = true for _, key := range dStore.IndexLowerCase[strings.ToLower(fil.StrValue)] { uniqHosts[key] = true } @@ -584,7 +586,7 @@ func appendIndexHostsFromServiceColumns(dStore *DataStore, uniqHosts map[string] case "host_name_lc": switch fil.Operator { // host_name ~~ - case RegexMatch, Contains, RegexNoCaseMatch, ContainsNoCase, EqualNocase: + case RegexMatch, Contains, RegexNoCaseMatch, ContainsNoCase, EqualNocase, Equal: store := dStore.DataSet.tables[TableHosts] for hostname := range store.Index { if fil.MatchString(strings.ToLower(hostname)) { diff --git a/pkg/lmd/request_test.go b/pkg/lmd/request_test.go index bc9ace7..5397f40 100644 --- a/pkg/lmd/request_test.go +++ b/pkg/lmd/request_test.go @@ -1395,6 +1395,19 @@ func TestIndexedHost(t *testing.T) { assert.Len(t, res, 1) assert.Equal(t, int64(1), meta.Total) assert.Equal(t, int64(1), meta.RowsScanned) + + res, meta, err = peer.QueryString("GET hosts\nColumns: name state alias\nOutputFormat: wrapped_json\nColumnHeaders: on\nFilter: name ~ ^testhost_1$\n\n") + require.NoError(t, err) + assert.Len(t, res, 1) + assert.Equal(t, int64(1), meta.Total) + assert.Equal(t, int64(1), meta.RowsScanned) + + res, meta, err = peer.QueryString("GET hosts\nColumns: name state alias\nOutputFormat: wrapped_json\nColumnHeaders: on\nFilter: name ~~ ^testhost_1$\n\n") + require.NoError(t, err) + assert.Len(t, res, 1) + assert.Equal(t, int64(1), meta.Total) + assert.Equal(t, int64(1), meta.RowsScanned) + if err = cleanup(); err != nil { t.Error(err) } @@ -1409,6 +1422,19 @@ func TestIndexedService(t *testing.T) { assert.Len(t, res, 1) assert.Equal(t, int64(1), meta.Total) assert.Equal(t, int64(1), meta.RowsScanned) + + res, meta, err = peer.QueryString("GET services\nColumns: host_name description state\nOutputFormat: wrapped_json\nColumnHeaders: on\nFilter: host_name ~ ^testhost_1$\n\n") + require.NoError(t, err) + assert.Len(t, res, 1) + assert.Equal(t, int64(1), meta.Total) + assert.Equal(t, int64(1), meta.RowsScanned) + + res, meta, err = peer.QueryString("GET services\nColumns: host_name description state\nOutputFormat: wrapped_json\nColumnHeaders: on\nFilter: host_name ~~ ^testhost_1$\n\n") + require.NoError(t, err) + assert.Len(t, res, 1) + assert.Equal(t, int64(1), meta.Total) + assert.Equal(t, int64(1), meta.RowsScanned) + if err = cleanup(); err != nil { t.Error(err) }