Skip to content

Commit

Permalink
fix more index based filters
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Nov 12, 2024
1 parent 15b4536 commit 302f54a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 3 additions & 1 deletion pkg/lmd/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ func appendIndexHostsFromHostColumns(dStore *DataStore, uniqHosts map[string]boo

// name =~ <value>
case EqualNocase:
uniqHosts[fil.StrValue] = true
for _, key := range dStore.IndexLowerCase[strings.ToLower(fil.StrValue)] {
uniqHosts[key] = true
}
Expand All @@ -516,6 +517,7 @@ func appendIndexHostsFromHostColumns(dStore *DataStore, uniqHosts map[string]boo
switch fil.Operator {
// name == <value>
case Equal, EqualNocase:
uniqHosts[fil.StrValue] = true
for _, key := range dStore.IndexLowerCase[strings.ToLower(fil.StrValue)] {
uniqHosts[key] = true
}
Expand Down Expand Up @@ -584,7 +586,7 @@ func appendIndexHostsFromServiceColumns(dStore *DataStore, uniqHosts map[string]
case "host_name_lc":
switch fil.Operator {
// host_name ~~ <value>
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)) {
Expand Down
26 changes: 26 additions & 0 deletions pkg/lmd/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 302f54a

Please sign in to comment.