Skip to content

Commit

Permalink
Add skeleton x-pack Auditbeat module (#8252)
Browse files Browse the repository at this point in the history
This adds an skeleton x-pack module to Auditbeat. The module is only included in the Elastic licensed Auditbeat binary.

The config and fields.yml data are not yet included in the packaging. Additional updates are required.
  • Loading branch information
andrewkroh committed Sep 18, 2018
1 parent 06ae246 commit 4bd1205
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 4 deletions.
4 changes: 4 additions & 0 deletions auditbeat/_meta/fields.common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
description: >
The name of the module that generated the event.
- name: event.dataset
description: >
The name of the module's dataset that generated the event.
- name: event.action
type: keyword
example: logged-in
Expand Down
6 changes: 6 additions & 0 deletions auditbeat/core/eventmod.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ func AddDatasetToEvent(module, metricSet string, event *mb.Event) {
}

event.RootFields.Put("event.module", module)

// Modules without "datasets" should set their module and metricset names
// to the same value then this will omit the event.dataset field.
if module != metricSet {
event.RootFields.Put("event.dataset", metricSet)
}
}
8 changes: 8 additions & 0 deletions auditbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -2759,6 +2759,14 @@ Contains common fields available in all event types.
The name of the module that generated the event.
--
*`event.dataset`*::
+
--
The name of the module's dataset that generated the event.
--
*`event.action`*::
Expand Down
2 changes: 1 addition & 1 deletion auditbeat/include/fields.go

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions x-pack/auditbeat/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@

package cmd

import "github.com/elastic/beats/auditbeat/cmd"
import (
"github.com/elastic/beats/auditbeat/cmd"

// RootCmd to handle beats cli
// Register Auditbeat x-pack modules.
_ "github.com/elastic/beats/x-pack/auditbeat/include"
)

// RootCmd to handle beats CLI.
var RootCmd = cmd.RootCmd

func init() {
// TODO inject x-pack features
// TODO: Inject x-pack features.
}
11 changes: 11 additions & 0 deletions x-pack/auditbeat/include/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 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 include

import (
// Include all Auditbeat modules so that they register their
// factories with the global registry.
_ "github.com/elastic/beats/x-pack/auditbeat/module/sysinfo/host"
)
15 changes: 15 additions & 0 deletions x-pack/auditbeat/module/sysinfo/_meta/config.yml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{ if .Reference -}}
{{ end -}}
- module: sysinfo
{{ if eq .GOOS "darwin" -}}
metricsets:
- host
{{ else if eq .GOOS "windows" -}}
metricsets:
- host
{{ else -}}
metricsets:
- host
{{- end }}
{{ if .Reference }}
{{- end }}
22 changes: 22 additions & 0 deletions x-pack/auditbeat/module/sysinfo/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
== Sysinfo Module

The `sysinfo` module ... TODO.

The module is implemented for Linux, macOS (Darwin), and Windows.

[float]
=== How it works

TODO

[float]
=== Configuration options

TODO

[source,yaml]
----
- module: sysinfo
----

*`some_option`*:: TODO
4 changes: 4 additions & 0 deletions x-pack/auditbeat/module/sysinfo/_meta/fields.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- key: sysinfo
title: Sysinfo
description: These are the fields generated by the sysinfo module.
fields:
8 changes: 8 additions & 0 deletions x-pack/auditbeat/module/sysinfo/host/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
The Sysinfo `host` metricset provides ... TODO.

The module is implemented for Linux, macOS (Darwin), and Windows.

[float]
=== Configuration options

TODO
6 changes: 6 additions & 0 deletions x-pack/auditbeat/module/sysinfo/host/_meta/fields.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- name: host
type: group
description: >
`host` contains TODO.
release: experimental
fields:
17 changes: 17 additions & 0 deletions x-pack/auditbeat/module/sysinfo/host/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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 host

// Config defines the host metricset's configuration options.
type Config struct {
// TODO: Add config options.
}

// Validate validates the host metricset config.
func (c *Config) Validate() error {
return nil
}

var defaultConfig = Config{}
50 changes: 50 additions & 0 deletions x-pack/auditbeat/module/sysinfo/host/host.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 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 host

import (
"github.com/pkg/errors"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/cfgwarn"
"github.com/elastic/beats/metricbeat/mb"
)

const (
moduleName = "sysinfo"
metricsetName = "host"
)

func init() {
mb.Registry.MustAddMetricSet(moduleName, metricsetName, New,
mb.DefaultMetricSet(),
)
}

// MetricSet collects data about the host.
type MetricSet struct {
mb.BaseMetricSet
}

// New constructs a new MetricSet.
func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
cfgwarn.Experimental("The %v/%v dataset is experimental", moduleName, metricsetName)

config := defaultConfig
if err := base.Module().UnpackConfig(&config); err != nil {
return nil, errors.Wrapf(err, "failed to unpack the %v/%v config", moduleName, metricsetName)
}

return &MetricSet{base}, nil
}

// Fetch collects data about the host. It is invoked periodically.
func (ms *MetricSet) Fetch(report mb.ReporterV2) {
report.Event(mb.Event{
RootFields: common.MapStr{
"hello": "world",
},
})
}

0 comments on commit 4bd1205

Please sign in to comment.