2018-12-19 15:39:18 +01:00
|
|
|
// +build mage
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/magefile/mage/mg"
|
|
|
|
|
2021-09-22 16:58:34 +02:00
|
|
|
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"
|
2018-12-19 15:39:18 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-08-15 14:05:42 +02:00
|
|
|
devtools.SetBuildVariableSources(devtools.DefaultBeatBuildVariableSources)
|
2018-12-19 15:39:18 +01:00
|
|
|
|
2020-02-28 10:06:05 +01:00
|
|
|
devtools.BeatDescription = "Icingabeat fetches data from the Icinga 2 API and forwards it to Elasticsearch or Logstash."
|
2021-09-23 12:16:35 +02:00
|
|
|
devtools.BeatVendor = "Icinga GmbH"
|
2021-09-23 14:17:17 +02:00
|
|
|
devtools.BeatURL = "https://icinga.com/docs/icingabeat"
|
2021-09-22 16:58:34 +02:00
|
|
|
devtools.BeatProjectType = devtools.CommunityProject
|
|
|
|
devtools.CrossBuildMountModcache = true
|
2018-12-19 15:39:18 +01:00
|
|
|
}
|
|
|
|
|
2020-02-26 15:15:04 +01:00
|
|
|
// 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)) }()
|
2018-12-19 15:39:18 +01:00
|
|
|
|
2020-02-26 15:15:04 +01:00
|
|
|
devtools.UseCommunityBeatPackaging()
|
2022-06-01 14:39:33 +02:00
|
|
|
devtools.PackageKibanaDashboardsFromBuildDir()
|
2018-12-19 15:39:18 +01:00
|
|
|
|
2021-09-23 12:16:35 +02:00
|
|
|
mg.Deps(Update)
|
2020-02-26 15:15:04 +01:00
|
|
|
mg.Deps(build.CrossBuild, build.CrossBuildGoDaemon)
|
|
|
|
mg.SerialDeps(devtools.Package, pkg.PackageTest)
|
2018-12-19 15:39:18 +01:00
|
|
|
}
|
|
|
|
|
2021-09-23 12:16:35 +02:00
|
|
|
// Update updates the generated files (aka make update).
|
2022-06-01 14:39:33 +02:00
|
|
|
func Update() {
|
|
|
|
mg.SerialDeps(Fields, Dashboards, Config, includeList, fieldDocs)
|
2018-12-19 15:39:18 +01:00
|
|
|
}
|
|
|
|
|
2021-09-23 12:16:35 +02:00
|
|
|
// Fields generates a fields.yml for the Beat.
|
2020-02-26 15:15:04 +01:00
|
|
|
func Fields() error {
|
|
|
|
return devtools.GenerateFieldsYAML()
|
2018-12-19 15:39:18 +01:00
|
|
|
}
|
|
|
|
|
2021-09-23 12:16:35 +02:00
|
|
|
// 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, ".")
|
|
|
|
}
|
|
|
|
|
2022-06-01 14:39:33 +02:00
|
|
|
func includeList() error {
|
|
|
|
options := devtools.DefaultIncludeListOptions()
|
|
|
|
options.ImportDirs = []string{"protos/*"}
|
|
|
|
options.ModuleDirs = nil
|
|
|
|
return devtools.GenerateIncludeListGo(options)
|
|
|
|
}
|
|
|
|
|
2018-12-19 15:39:18 +01:00
|
|
|
// Clean cleans all generated files and build artifacts.
|
|
|
|
func Clean() error {
|
2019-08-15 14:05:42 +02:00
|
|
|
return devtools.Clean()
|
2018-12-19 15:39:18 +01:00
|
|
|
}
|
|
|
|
|
2020-02-26 15:15:04 +01:00
|
|
|
// Check formats code, updates generated content, check for common errors, and
|
|
|
|
// checks for any modified files.
|
|
|
|
func Check() {
|
|
|
|
common.Check()
|
2018-12-19 15:39:18 +01:00
|
|
|
}
|
|
|
|
|
2020-02-26 15:15:04 +01:00
|
|
|
// Fmt formats source code (.go and .py) and adds license headers.
|
|
|
|
func Fmt() {
|
|
|
|
common.Fmt()
|
2018-12-19 15:39:18 +01:00
|
|
|
}
|
|
|
|
|
2020-02-26 15:15:04 +01:00
|
|
|
// Test runs all available tests
|
|
|
|
func Test() {
|
|
|
|
mg.Deps(unittest.GoUnitTest)
|
2018-12-19 15:39:18 +01:00
|
|
|
}
|
|
|
|
|
2020-02-26 15:15:04 +01:00
|
|
|
// Build builds the Beat binary.
|
|
|
|
func Build() error {
|
|
|
|
return build.Build()
|
2018-12-19 15:39:18 +01:00
|
|
|
}
|
|
|
|
|
2020-02-26 15:15:04 +01:00
|
|
|
// CrossBuild cross-builds the beat for all target platforms.
|
|
|
|
func CrossBuild() error {
|
|
|
|
return build.CrossBuild()
|
2018-12-19 15:39:18 +01:00
|
|
|
}
|
|
|
|
|
2020-02-26 15:15:04 +01:00
|
|
|
// BuildGoDaemon builds the go-daemon binary (use crossBuildGoDaemon).
|
|
|
|
func BuildGoDaemon() error {
|
|
|
|
return build.BuildGoDaemon()
|
2019-08-15 14:05:42 +02:00
|
|
|
}
|
|
|
|
|
2020-02-26 15:15:04 +01:00
|
|
|
// GolangCrossBuild build the Beat binary inside of the golang-builder.
|
|
|
|
// Do not use directly, use crossBuild instead.
|
|
|
|
func GolangCrossBuild() error {
|
|
|
|
return build.GolangCrossBuild()
|
2020-02-28 10:06:05 +01:00
|
|
|
}
|
2022-06-01 14:39:33 +02:00
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|