file

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileAlertMethod

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

func NewFileAlertMethod

func NewFileAlertMethod(config *FileAlertMethodConfig) (*FileAlertMethod, error)

NewFileAlertMethod returns a new *FileAlertMethod or a non-nil error if there was an error.

func (*FileAlertMethod) Write

func (f *FileAlertMethod) 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 FileAlertMethod. If there was an error writing logs to disk, it returns a non-nil error.

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

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

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

type FileAlertMethodConfig

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

type OutputJSON

type OutputJSON struct {
	RuleName   string          `json:"rule_name"`
	ReceivedAt time.Time       `json:"received_at"`
	Records    []*alert.Record `json:"results"`
}

Jump to

Keyboard shortcuts

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