Beats: Extending beats for new outputs for new versions

Created on 2 Feb 2018  路  1Comment  路  Source: elastic/beats

As you are not accepting new output types, there is an issue of extending filebeats. There is a sample code given before which no longer works: https://github.com/elastic/beats/pull/1525#issuecomment-217651768

package main

import (
    "os"

        _ "github.com/myuser/customfilebeat/outputs/syslog"

    "github.com/elastic/beats/filebeat/beater"
    "github.com/elastic/beats/libbeat/beat"
)

func main() {
    if err := beat.Run("customfilebeat, "", beater.New()); err != nil {
        os.Exit(1)
    }
}

Because beater.New() has the following signature:

func New(b *beat.Beat, rawConfig *common.Config) (beat.Beater, error) {

Also there is no beat.Run() any more and we have the following signature:

type Beater interface {
    // The main event loop. This method should block until signalled to stop by an
    // invocation of the Stop() method.
    Run(b *Beat) error

    // Stop is invoked to signal that the Run method should finish its execution.
    // It will be invoked at most once.
    Stop()
}

I saw that filebeat has the code:

func main() {
    if err := cmd.RootCmd.Execute(); err != nil {
        os.Exit(1)
    }
}

Would using the above would be enough by registering my methods or should we have a different path?

question

Most helpful comment

If you building a copy of filebeat with a custom output then update your main.go to match the new format used in the main function of all Beats.

package main

import (
    "os"

    "github.com/elastic/beats/filebeat/cmd"

    // Register custom extensions.
    _ "github.com/myuser/customfilebeat/outputs/syslog"
)

func main() {
    if err := cmd.RootCmd.Execute(); err != nil {
        os.Exit(1)
    }
}

>All comments

If you building a copy of filebeat with a custom output then update your main.go to match the new format used in the main function of all Beats.

package main

import (
    "os"

    "github.com/elastic/beats/filebeat/cmd"

    // Register custom extensions.
    _ "github.com/myuser/customfilebeat/outputs/syslog"
)

func main() {
    if err := cmd.RootCmd.Execute(); err != nil {
        os.Exit(1)
    }
}
Was this page helpful?
0 / 5 - 0 ratings