// +build mage package main import ( "fmt" "time" "github.com/magefile/mage/mg" devtools "github.com/elastic/beats/v7/dev-tools/mage" "github.com/elastic/beats/v7/dev-tools/mage/target/build" "github.com/elastic/beats/v7/dev-tools/mage/target/common" "github.com/elastic/beats/v7/dev-tools/mage/target/pkg" "github.com/elastic/beats/v7/dev-tools/mage/target/unittest" ) func init() { devtools.SetBuildVariableSources(devtools.DefaultBeatBuildVariableSources) devtools.BeatDescription = "Icingabeat fetches data from the Icinga 2 API and forwards it to Elasticsearch or Logstash." devtools.BeatVendor = "Icinga GmbH" devtools.BeatURL = "https://icinga.com/docs/icingabeat" devtools.BeatProjectType = devtools.CommunityProject devtools.CrossBuildMountModcache = true } // Package packages the Beat for distribution. // Use SNAPSHOT=true to build snapshots. // Use PLATFORMS to control the target platforms. func Package() { start := time.Now() defer func() { fmt.Println("package ran for", time.Since(start)) }() devtools.UseCommunityBeatPackaging() devtools.PackageKibanaDashboardsFromBuildDir() mg.Deps(Update) mg.Deps(build.CrossBuild, build.CrossBuildGoDaemon) mg.SerialDeps(devtools.Package, pkg.PackageTest) } // Update updates the generated files (aka make update). func Update() { mg.SerialDeps(Fields, Dashboards, Config, includeList, fieldDocs) } // Fields generates a fields.yml for the Beat. func Fields() error { return devtools.GenerateFieldsYAML() } // Config generates both the short/reference/docker configs. func Config() error { p := devtools.DefaultConfigFileParams() p.Templates = append(p.Templates, "_meta/config/*.tmpl") return devtools.Config(devtools.AllConfigTypes, p, ".") } func includeList() error { options := devtools.DefaultIncludeListOptions() options.ImportDirs = []string{"protos/*"} options.ModuleDirs = nil return devtools.GenerateIncludeListGo(options) } // Clean cleans all generated files and build artifacts. func Clean() error { return devtools.Clean() } // Check formats code, updates generated content, check for common errors, and // checks for any modified files. func Check() { common.Check() } // Fmt formats source code (.go and .py) and adds license headers. func Fmt() { common.Fmt() } // Test runs all available tests func Test() { mg.Deps(unittest.GoUnitTest) } // Build builds the Beat binary. func Build() error { return build.Build() } // CrossBuild cross-builds the beat for all target platforms. func CrossBuild() error { return build.CrossBuild() } // BuildGoDaemon builds the go-daemon binary (use crossBuildGoDaemon). func BuildGoDaemon() error { return build.BuildGoDaemon() } // GolangCrossBuild build the Beat binary inside of the golang-builder. // Do not use directly, use crossBuild instead. func GolangCrossBuild() error { return build.GolangCrossBuild() } // Fields generates fields.yml and fields.go files for the Beat. func fieldDocs() error { return devtools.Docs.FieldDocs("fields.yml") } // Dashboards collects all the dashboards and generates index patterns. func Dashboards() error { return devtools.KibanaDashboards("protos") }