-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make -setup load the Beat dashboards #3506
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,9 @@ import ( | |
|
||
"github.com/elastic/beats/libbeat/cfgfile" | ||
"github.com/elastic/beats/libbeat/common" | ||
"github.com/elastic/beats/libbeat/dashboards/dashboards" | ||
"github.com/elastic/beats/libbeat/logp" | ||
"github.com/elastic/beats/libbeat/outputs/elasticsearch" | ||
"github.com/elastic/beats/libbeat/paths" | ||
"github.com/elastic/beats/libbeat/plugin" | ||
"github.com/elastic/beats/libbeat/processors" | ||
|
@@ -100,10 +102,12 @@ type BeatConfig struct { | |
Logging logp.Logging `config:"logging"` | ||
Processors processors.PluginConfig `config:"processors"` | ||
Path paths.Path `config:"path"` | ||
Dashboards *common.Config `config:"dashboards"` | ||
} | ||
|
||
var ( | ||
printVersion = flag.Bool("version", false, "Print the version and exit") | ||
setup = flag.Bool("setup", false, "Load the sample Kibana dashboards") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Load sampel Kibana dashboards, index template, patterns? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At the moment it only loads the dashboards, see the other answer. |
||
) | ||
|
||
var debugf = logp.MakeDebug("beat") | ||
|
@@ -209,6 +213,11 @@ func (b *Beat) launch(bt Creator) error { | |
|
||
svc.HandleSignals(beater.Stop) | ||
|
||
err = b.loadDashboards() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
logp.Info("%s start running.", b.Name) | ||
defer logp.Info("%s stopped.", b.Name) | ||
defer logp.LogTotalExpvars(&b.Config.Logging) | ||
|
@@ -285,6 +294,39 @@ func (b *Beat) configure() error { | |
return nil | ||
} | ||
|
||
func (b *Beat) loadDashboards() error { | ||
if *setup { | ||
// -setup implies dashboards.enabled=true | ||
if b.Config.Dashboards == nil { | ||
b.Config.Dashboards = common.NewConfig() | ||
} | ||
err := b.Config.Dashboards.SetBool("enabled", -1, true) | ||
if err != nil { | ||
return fmt.Errorf("Error setting dashboard.enabled=true: %v", err) | ||
} | ||
} | ||
|
||
if b.Config.Dashboards != nil && b.Config.Dashboards.Enabled() { | ||
esConfig := b.Config.Output["elasticsearch"] | ||
if esConfig == nil || !esConfig.Enabled() { | ||
return fmt.Errorf("Dashboard loading requested but the Elasticsearch output is not configured/enabled") | ||
} | ||
esClient, err := elasticsearch.NewConnectedClient(esConfig) | ||
if err != nil { | ||
return fmt.Errorf("Error creating ES client: %v", err) | ||
} | ||
defer esClient.Close() | ||
|
||
err = dashboards.ImportDashboards(b.Name, b.Version, esClient, b.Config.Dashboards) | ||
if err != nil { | ||
return fmt.Errorf("Error importing Kibana dashboards: %v", err) | ||
} | ||
logp.Info("Kibana dashboards successfully loaded.") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// handleError handles the given error by logging it and then returning the | ||
// error. If the err is nil or is a GracefulExit error then the method will | ||
// return nil without logging anything. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package dashboards | ||
|
||
type DashboardsConfig struct { | ||
Enabled bool `config:"enabled"` | ||
KibanaIndex string `config:"kibana_index"` | ||
Index string `config:"index"` | ||
Dir string `config:"directory"` | ||
File string `config:"file"` | ||
Beat string `config:"beat"` | ||
URL string `config:"url"` | ||
OnlyDashboards bool `config:"only_dashboards"` | ||
OnlyIndex bool `config:"only_index"` | ||
Snapshot bool `config:"snapshot"` | ||
SnapshotURL string `config:"snapshot_url"` | ||
} | ||
|
||
var defaultDashboardsConfig = DashboardsConfig{ | ||
KibanaIndex: ".kibana", | ||
} | ||
var ( | ||
defaultURLPattern = "https://artifacts.elastic.co/downloads/beats/beats-dashboards/beats-dashboards-%s.zip" | ||
snapshotURLPattern = "https://beats-nightlies.s3.amazonaws.com/dashboards/beats-dashboards-%s-SNAPSHOT.zip" | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a feature we already have in `import_dashboards" :)