Skip to content
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

Add Netflow dashboards based on Logstash Netflow #12857

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Add `google-pubsub` input type for consuming messages from a Google Cloud Pub/Sub topic subscription. {pull}12746[12746]
- Add module for ingesting Cisco IOS logs over syslog. {pull}12748[12748]
- Add module for ingesting Google Cloud VPC flow logs. {pull}12747[12747]
- Add netflow dashboards based on Logstash netflow. {pull}12857[12857]

*Heartbeat*

Expand Down
11 changes: 10 additions & 1 deletion dev-tools/cmd/dashboards/export_dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ import (
"io/ioutil"
"log"
"net/url"
"os"
"path/filepath"
"time"

"github.com/pkg/errors"

"github.com/elastic/beats/libbeat/dashboards"
"github.com/elastic/beats/libbeat/kibana"
)
Expand Down Expand Up @@ -84,6 +87,7 @@ func main() {
if err != nil {
log.Fatalf("Failed to export dashboards from YML file: %v", err)
}
log.Println("Done exporting dashboards from", *ymlFile)
return
}

Expand Down Expand Up @@ -121,9 +125,14 @@ func exportSingleDashboard(client *kibana.Client, dashboard, output string) erro
return fmt.Errorf("failed to export the dashboard: %+v", err)
}
result = dashboards.DecodeExported(result)

if err = os.MkdirAll(filepath.Dir(output), 0755); err != nil {
return errors.Wrap(err, "failed to create directory for dashboard")
}

err = ioutil.WriteFile(output, []byte(result.StringToPrint()), dashboards.OutputPermission)
if err != nil {
return fmt.Errorf("failed to save the dashboards: %+v", err)
return fmt.Errorf("failed to save the dashboard: %+v", err)
}
return nil
}
15 changes: 10 additions & 5 deletions dev-tools/mage/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,20 @@ func ExportDashboard() error {
return err
}

dashboardCmd := sh.RunCmd("go", "run", filepath.Join(beatsDir, "dev-tools/cmd/dashboards/export_dashboards.go"))

// TODO: This is currently hardcoded for KB 7, we need to figure out what we do for KB 8 if applicable
file := CWD("module", module, "_meta/kibana/7/dashboard", id+".json")

dashboardCmd := sh.RunCmd("go", "run",
filepath.Join(beatsDir, "dev-tools/cmd/dashboards/export_dashboards.go"),
"-output", file, "-dashboard", id,
)
args := []string{
"-output", file,
"-dashboard", id,
}
if kibanaURL := EnvOr("KIBANA_URL", ""); kibanaURL != "" {
args = append(args, "-kibana", kibanaURL)
}

return dashboardCmd()
return dashboardCmd(args...)
}

// ImportDashboards imports dashboards to Kibana using the Beat setup command.
Expand Down
5 changes: 3 additions & 2 deletions dev-tools/mage/target/dashboards/dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ func (Dashboards) Import() error {
// directory.
//
// Required environment variables:
// - MODULE: Name of the module
// - ID: Dashboard ID
// - KIBANA_URL: URL of Kibana
// - MODULE: Name of the module
// - ID: Dashboard ID
func (Dashboards) Export() error {
return devtools.ExportDashboard()
}
3 changes: 3 additions & 0 deletions libbeat/dashboards/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func ExportAllFromYml(client *kibana.Client, ymlPath string) ([]common.MapStr, L
if err != nil {
return nil, ListYML{}, errors.Wrap(err, "error reading the list of dashboards")
}
if len(list.Dashboards) == 0 {
return nil, ListYML{}, errors.Errorf("dashboards list is empty in file %v", ymlPath)
}

results, err := ExportAll(client, list)

Expand Down
Loading