-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Osquerybeat: Add action responses data stream (#39143)
* Add action responses data stream * Add missing copyright header * Make linter happy * Linting * Fix the compatibility with older stack
- Loading branch information
Showing
17 changed files
with
1,173 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
|
||
"github.com/elastic/beats/v7/libbeat/common/reload" | ||
|
||
"github.com/elastic/elastic-agent-client/v7/pkg/client" | ||
"github.com/elastic/elastic-agent-client/v7/pkg/proto" | ||
|
||
"github.com/elastic/elastic-agent-libs/mapstr" | ||
) | ||
|
||
func TestOsquerybeatCfg(t *testing.T) { | ||
matches, err := filepath.Glob("testdata/osquerycfg/*.in.json") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
for _, match := range matches { | ||
dir := filepath.Dir(match) | ||
key := strings.TrimSuffix(filepath.Base(match), `.in.json`) | ||
|
||
out := filepath.Join(dir, key+".out.json") | ||
t.Run(key, func(in, out string) func(t *testing.T) { | ||
return func(t *testing.T) { | ||
var rawIn proto.UnitExpectedConfig | ||
err := readRawIn(in, &rawIn) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
want, err := readOut(out) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
cfg, err := osquerybeatCfg(&rawIn, &client.AgentInfo{ID: "abc7d0a8-ce04-4663-95da-ff6d537c268f", Version: "8.13.1"}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
got, err := cfgToArrMap(cfg) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
diff := cmp.Diff(want, got) | ||
if diff != "" { | ||
t.Fatal(diff) | ||
} | ||
} | ||
}(match, out)) | ||
} | ||
} | ||
|
||
func readRawIn(filename string, rawIn *proto.UnitExpectedConfig) error { | ||
b, err := os.ReadFile(filename) | ||
if err != nil { | ||
return err | ||
} | ||
err = json.Unmarshal(b, rawIn) | ||
return err | ||
} | ||
|
||
func readOut(filename string) (cfg []map[string]interface{}, err error) { | ||
b, err := os.ReadFile(filename) | ||
if err != nil { | ||
return nil, err | ||
} | ||
err = json.Unmarshal(b, &cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return cfg, err | ||
} | ||
|
||
func cfgToArrMap(cfg []*reload.ConfigWithMeta) ([]map[string]interface{}, error) { | ||
res := make([]map[string]interface{}, 0, len(cfg)) | ||
for _, c := range cfg { | ||
var m mapstr.M | ||
err := c.Config.Unpack(&m) | ||
if err != nil { | ||
return nil, err | ||
} | ||
res = append(res, map[string]interface{}(m)) | ||
} | ||
return res, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"source": { | ||
"data_stream": { | ||
"namespace": "default" | ||
}, | ||
"id": "74c7d0a8-ce04-4663-95da-ff6d537c268c", | ||
"meta": { | ||
"package": { | ||
"name": "osquery_manager", | ||
"version": "1.12.1" | ||
} | ||
}, | ||
"name": "osquery_manager-1", | ||
"package_policy_id": "74c7d0a8-ce04-4663-95da-ff6d537c268c", | ||
"policy": { | ||
"revision": 2 | ||
}, | ||
"revision": 1, | ||
"streams": [ | ||
], | ||
"type": "osquery" | ||
}, | ||
"id": "74c7d0a8-ce04-4663-95da-ff6d537c268c", | ||
"type": "osquery", | ||
"name": "osquery_manager-1", | ||
"revision": 1, | ||
"meta": { | ||
"source": { | ||
"package": { | ||
"name": "osquery_manager", | ||
"version": "1.12.1" | ||
} | ||
}, | ||
"package": { | ||
"source": { | ||
"name": "osquery_manager", | ||
"version": "1.12.1" | ||
}, | ||
"name": "osquery_manager", | ||
"version": "1.12.1" | ||
} | ||
}, | ||
"data_stream": { | ||
"source": { | ||
"namespace": "default" | ||
}, | ||
"namespace": "default" | ||
}, | ||
"streams": [ | ||
] | ||
} |
Oops, something went wrong.