file

package
v0.1.65 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAlertMethod added in v0.1.55

func NewAlertMethod(config *AlertMethodConfig) (alert.Method, error)

NewAlertMethod returns a new *AlertMethod or a non-nil error if there was an error.

Types

type AlertMethod added in v0.1.55

type AlertMethod struct {
	// contains filtered or unexported fields
}

AlertMethod implements the alert.AlertMethod interface for writing new alerts to a file.

func (*AlertMethod) Write added in v0.1.55

func (f *AlertMethod) Write(ctx context.Context, rule string, records []*alert.Record) error

Write creates JSON-formatted logs from the records and writes them to the file specified at the creation of the AlertMethod. If there was an error writing logs to disk, it returns a non-nil error.

Example
records := []*alert.Record{
	{
		Filter: "hits.hits._source",
		Text:   `Lorem ipsum dolor sit amet...`,
	},
	{
		Filter: "aggregation.hostname.buckets",
		Fields: []*alert.Field{
			{
				Key:   "foo",
				Count: 2,
			},
			{
				Key:   "bar",
				Count: 3,
			},
		},
	},
}

fm, err := NewAlertMethod(&AlertMethodConfig{
	OutputFilepath: "testdata/results.log",
})
if err != nil {
	fmt.Printf("error creating new *AlertMethod: %v", err)
	return
}

err = fm.Write(context.Background(), "Test Rule", records)
if err != nil {
	fmt.Printf("error writing data to file: %v", err)
	return
}

type AlertMethodConfig added in v0.1.55

type AlertMethodConfig struct {
	// OutputFilepath is the file where logs will be written
	OutputFilepath string `mapstructure:"file"`
}

AlertMethodConfig configures to what file alerts will be written.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL