Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Suricata module to Filebeat #8693

Merged
merged 28 commits into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
33e7c59
Import suricata module from temp repo
Aug 23, 2018
a4da08b
Generated doc (no actual documentation for it the module yet)
Aug 24, 2018
3cfcc11
Update the kibana objects to the new format.
Aug 27, 2018
9652a66
Remove symlink to Suricata module and re-generate the doc
Aug 27, 2018
167aacf
Add a simple compatibility comment in the doc.
Aug 29, 2018
a1d05e0
Ooops, off by 3 error. Version 4.0.4 :-)
Aug 29, 2018
2ba9706
Package filebeat x-pack modules in the non-oss distribution
adriansr Sep 24, 2018
3ab125f
Add modules.d to filebeat's x-pack tree
adriansr Sep 24, 2018
0211eda
Fix build in feature-suricata branch (#8625)
adriansr Oct 16, 2018
4d60173
[Suricata] Update fields and paths (#8550)
adriansr Oct 16, 2018
69cce4c
Filebeat X-Pack Module Packaging (#8615)
andrewkroh Oct 17, 2018
2430239
Use naming conventions for the Suricata dashboards (#8675)
tsg Oct 22, 2018
c8d1ab7
Add ingest-user-agent to the required plugins list (#8674)
adriansr Oct 22, 2018
a4fbb4d
Add integration tests for suricata module (#8650)
adriansr Oct 23, 2018
3e2f40b
Merge branch 'master' of github.com:elastic/beats into feature-suricata
andrewkroh Oct 23, 2018
576bb2d
Format magefile.go for x-pack/filebeat
andrewkroh Oct 23, 2018
563a289
rely on go to resolve beats repo for goimports install
andrewkroh Oct 23, 2018
8033e99
Update CHANGELOG files
andrewkroh Oct 23, 2018
3a5ef22
Merge branch 'master' of github.com:elastic/beats into feature-suricata
andrewkroh Oct 23, 2018
0f33ff3
Clean-up module documentation
andrewkroh Oct 23, 2018
ed53c42
Update config file
andrewkroh Oct 23, 2018
96bc0f7
Fix xpack role on docs
andrewkroh Oct 23, 2018
73936dd
Merge branch 'master' of github.com:elastic/beats into feature-suricata
andrewkroh Oct 23, 2018
151572b
Fix heartbeat test
andrewkroh Oct 23, 2018
c239c8d
Remove system-test symlinks
andrewkroh Oct 24, 2018
b808dc0
Remove system-test symlinks - take 2
andrewkroh Oct 24, 2018
ab7266c
Fix permissions
andrewkroh Oct 24, 2018
9b4f8e8
Undo symlink deletion
andrewkroh Oct 24, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG-developer.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The list below covers the major changes between 6.3.0 and master only.
has a magefile.go with a fields target. The `FIELDS_FILE_PATH` make variable is no longer
used because the value is specified in magefile.go. {pull}7670[7670]
- Outputs must implement String. {pull}6404[6404]
- Renamed `-beat-name` CLI option used in `kibana_index_pattern.go` to `-beat` for consistency with other scripts in `dev-tools/cmd`. {pull}8615[8615]

==== Bugfixes

Expand All @@ -54,3 +55,9 @@ The list below covers the major changes between 6.3.0 and master only.
- Set current year in generator templates. {pull}8396[8396]
- You can now override default settings of libbeat by using instance.Settings. {pull}8449[8449]
- Add `-space-id` option to `export_dashboards.go` script to support Kibana Spaces {pull}7942[7942]
- Add `-name` option to `asset.go` script to explicitly name the asset rather than using its filename. {pull}8693[8693]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was at first surprised by this long dev changelog but it seems all of these actually go into this PR.

- Add `-out` option to `kibana_index_pattern.go` to control the output dir to make it possible to write the generated output to `build/kibana` instead of `_meta/kibana.generated` (but the output dir remains unchanged at this point). {pull}8615[8615]
- Add `module_fields.go` for generated `fields.go` files for modules. {pull}8615[8615]
- Add `mage.GenerateModuleReferenceConfig` for generating reference config files that include configuration sections from the module directory. {pull}8615[8615]
- Add `mage.GenerateFieldsGo` for generating fields.go files. {pull}8615[8615]
- Add `mage.KibanaDashboards` for collecting Kibana dashboards and generating index patterns. {pull}8615[8615]
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ https://github.com/elastic/beats/compare/v6.4.0...master[Check the HEAD diff]
- Keep unparsed user agent information in user_agent.original. {pull}8537[8537]
- Better tracking of number of open file descriptors. {pull}7986[7986]
- Added default and TCP parsing formats to HAproxy module {issue}8311[8311] {pull}8637[8637]
- Add Suricata IDS/IDP/NSM module. {issue}8153[8153] {pull}8693[8693]
- Allow to force CRI format parsing for better performance {pull}8424[8424]

*Heartbeat*
Expand Down
7 changes: 6 additions & 1 deletion dev-tools/cmd/asset/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (
pkg string
input string
output string
name string
license = "ASL2"
)

Expand All @@ -45,6 +46,7 @@ func init() {
flag.StringVar(&input, "in", "-", "Source of input. \"-\" means reading from stdin")
flag.StringVar(&output, "out", "-", "Output path. \"-\" means writing to stdout")
flag.StringVar(&license, "license", "ASL2", "License header for generated file.")
flag.StringVar(&name, "name", "", "Asset name")
}

func main() {
Expand Down Expand Up @@ -94,9 +96,12 @@ func main() {
os.Exit(1)
}
var buf bytes.Buffer
if name == "" {
name = file
}
asset.Template.Execute(&buf, asset.Data{
Beat: beatName,
Name: file,
Name: name,
Data: encData,
License: licenseHeader,
Package: pkg,
Expand Down
68 changes: 45 additions & 23 deletions dev-tools/cmd/kibana_index_pattern/kibana_index_pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,51 +19,73 @@ package main

import (
"flag"
"fmt"
"os"
"log"
"path/filepath"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/kibana"
"github.com/elastic/beats/libbeat/version"
)

var usageText = `
Usage: kibana_index_pattern [flags]
kibana_index_pattern generates Kibana index patterns from the Beat's
fields.yml file. It will create a index pattern file that is usable with both
Kibana 5.x and 6.x.
Options:
`[1:]

var (
beatName string
beatVersion string
indexPattern string
fieldsYAMLFile string
outputDir string
)

func init() {
flag.StringVar(&beatName, "beat", "", "Name of the beat. (Required)")
flag.StringVar(&beatVersion, "version", version.GetDefaultVersion(), "Beat version. (Required)")
flag.StringVar(&indexPattern, "index", "", "Kibana index pattern. (Required)")
flag.StringVar(&fieldsYAMLFile, "fields", "fields.yml", "fields.yml file containing all fields used by the Beat.")
flag.StringVar(&outputDir, "out", "build/kibana", "Output dir.")
}

func main() {
index := flag.String("index", "", "The name of the index pattern. (required)")
beatName := flag.String("beat-name", "", "The name of the beat. (required)")
beatDir := flag.String("beat-dir", "", "The local beat directory. (required)")
beatVersion := flag.String("version", version.GetDefaultVersion(), "The beat version.")
log.SetFlags(0)
flag.Parse()

if *index == "" {
fmt.Fprint(os.Stderr, "The name of the index pattern must be set.")
os.Exit(1)
if beatName == "" {
log.Fatal("Name of the Beat must be set (-beat).")
}

if *beatName == "" {
fmt.Fprint(os.Stderr, "The name of the beat must be set.")
os.Exit(1)
if beatVersion == "" {
log.Fatal("Beat version must be set (-version).")
}

if *beatDir == "" {
fmt.Fprint(os.Stderr, "The beat directory must be set.")
os.Exit(1)
if indexPattern == "" {
log.Fatal("Index pattern must be set (-index).")
}

version5, _ := common.NewVersion("5.0.0")
version6, _ := common.NewVersion("6.0.0")
versions := []*common.Version{version5, version6}
versions := []common.Version{*version5, *version6}
for _, version := range versions {
indexPattern, err := kibana.NewGenerator(indexPattern, beatName, fieldsYAMLFile, outputDir, beatVersion, version)
if err != nil {
log.Fatal(err)
}

indexPatternGenerator, err := kibana.NewGenerator(*index, *beatName, *beatDir, *beatVersion, *version)
file, err := indexPattern.Generate()
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
log.Fatal(err)
}
pattern, err := indexPatternGenerator.Generate()

// Log output file location.
absFile, err := filepath.Abs(file)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
absFile = file
}
fmt.Fprintf(os.Stdout, "-- The index pattern was created under %v\n", pattern)
log.Printf(">> The index pattern was created under %v", absFile)
}
}
118 changes: 118 additions & 0 deletions dev-tools/cmd/module_fields/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package main

import (
"bytes"
"flag"
"fmt"
"go/format"
"io/ioutil"
"log"
"os"
"path"

"github.com/elastic/beats/libbeat/asset"
"github.com/elastic/beats/libbeat/generator/fields"
"github.com/elastic/beats/licenses"
)

var usageText = `
Usage: module_fields [flags] [module-dir]
module_fields generates a fields.go file containing a copy of the module's
field.yml data in a format that can be embedded in Beat's binary. module-dir
should be the directory containing modules (e.g. filebeat/module).
Options:
`[1:]

var (
beatName string
license string
)

func init() {
flag.StringVar(&beatName, "beat", "", "Name of the beat. (Required)")
flag.StringVar(&license, "license", "ASL2", "License header for generated file.")
flag.Usage = usageFlag
}

func main() {
log.SetFlags(0)
flag.Parse()

if beatName == "" {
log.Fatal("You must use -beat to specify the beat name.")
}

license, err := licenses.Find(license)
if err != nil {
log.Fatalf("Invalid license specifier: %v", err)
}

args := flag.Args()
if len(args) != 1 {
log.Fatal("module-dir must be passed as an argument.")
}
dir := args[0]

modules, err := fields.GetModules(dir)
if err != nil {
log.Fatalf("Error fetching modules: %v", err)
}

for _, module := range modules {
files, err := fields.CollectFiles(module, dir)
if err != nil {
log.Fatalf("Error fetching files for module %v: %v", module, err)
}

data, err := fields.GenerateFieldsYml(files)
if err != nil {
log.Fatalf("Error fetching files for module %v: %v", module, err)
}

encData, err := asset.EncodeData(string(data))
if err != nil {
log.Fatalf("Error encoding the data: %v", err)
}

var buf bytes.Buffer
asset.Template.Execute(&buf, asset.Data{
License: license,
Beat: beatName,
Name: module,
Data: encData,
Package: module,
})

bs, err := format.Source(buf.Bytes())
if err != nil {
log.Fatalf("Error creating golang file from template: %v", err)
}

err = ioutil.WriteFile(path.Join(dir, module, "fields.go"), bs, 0644)
if err != nil {
log.Fatalf("Error writing fields.go: %v", err)
}
}
}

func usageFlag() {
fmt.Fprintf(os.Stderr, usageText)
flag.PrintDefaults()
}
1 change: 1 addition & 0 deletions dev-tools/jenkins_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ cleanup() {
echo "Cleaning stopped docker containers and dangling images/networks/volumes..."
docker system prune -f || true
fi

echo "Cleanup complete."
}
trap cleanup EXIT
Expand Down
Loading