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 basic "import-beats" scripts #231

Merged
merged 6 commits into from
Mar 5, 2020
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
55 changes: 55 additions & 0 deletions dev/import-beats/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package main

import (
"flag"
"log"

"github.com/pkg/errors"
)

func main() {
// Beats repository directory
var beatsDir string
// Target public directory where the generated packages should end up in
var outputDir string

flag.StringVar(&beatsDir, "beatsDir", "", "Path to the beats repository")
flag.StringVar(&outputDir, "outputDir", "", "Path to the output directory ")
flag.Parse()

if beatsDir == "" || outputDir == "" {
log.Fatal("beatsDir and outputDir must be set")
}

if err := build(beatsDir, outputDir); err != nil {
log.Fatal(err)
}
}

// build method visits all beats in beatsDir to collect configuration data for modules.
// The package-registry groups integrations per target product not per module type. It's opposite to the beats project,
// where logs and metrics are distributed with different beats (oriented either on logs or metrics - metricbeat,
// filebeat, etc.).
func build(beatsDir, outputDir string) error {
packages := packageMap{}

for _, beatName := range logSources {
err := packages.loadFromSource(beatsDir, beatName, "logs")
if err != nil {
return errors.Wrap(err, "loading logs source failed")
}
}

for _, beatName := range metricSources {
err := packages.loadFromSource(beatsDir, beatName, "metrics")
if err != nil {
return errors.Wrap(err, "loading metrics source failed")
}
}

return packages.writePackages(outputDir)
}
73 changes: 73 additions & 0 deletions dev/import-beats/packages.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package main

import (
"io/ioutil"
"log"
"os"
"path/filepath"

"github.com/pkg/errors"
"gopkg.in/yaml.v2"

"github.com/elastic/package-registry/util"
)

type packageMap map[string]*util.Package

func (p packageMap) loadFromSource(beatsDir, beatName, packageType string) error {
path := filepath.Join(beatsDir, beatName, "module")
moduleDirs, err := ioutil.ReadDir(path)
if err != nil {
return errors.Wrapf(err, "cannot read directory '%s'", path)
}

for _, moduleDir := range moduleDirs {
if !moduleDir.IsDir() {
continue
}

log.Printf("Visit '%s:%s'\n", beatName, moduleDir.Name())

_, ok := p[moduleDir.Name()]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps worth a comment that this is needed because in packages logs and metrics modules are combined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment left.

if !ok {
p[moduleDir.Name()] = &util.Package{
FormatVersion: "1.0.0",
Name: moduleDir.Name(),
Version: "0.0.1", // TODO
Type: "integration",
Categories: []string{},
}
}

p[moduleDir.Name()].Categories = append(p[moduleDir.Name()].Categories, packageType)
}
return nil
}

func (p packageMap) writePackages(outputDir string) error {
for name, content := range p {
log.Printf("Writing package '%s' (version: %s)\n", name, content.Version)

path := filepath.Join(outputDir, name+"-"+content.Version)
err := os.MkdirAll(path, 0755)
if err != nil {
return errors.Wrapf(err, "cannot make directory '%s'", path)
}

m, err := yaml.Marshal(content)
if err != nil {
return errors.Wrapf(err, "marshaling package content failed (package name: %s)", name)
}

manifestFilePath := filepath.Join(path, "manifest.yml")
err = ioutil.WriteFile(manifestFilePath, m, 0644)
if err != nil {
return errors.Wrapf(err, "writing manifest file failed (path: %s)", manifestFilePath)
}
}
return nil
}
15 changes: 15 additions & 0 deletions dev/import-beats/sources.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package main

var metricSources = []string{
"metricbeat",
"x-pack/metricbeat",
}

var logSources = []string{
"filebeat",
"x-pack/filebeat",
}
11 changes: 11 additions & 0 deletions dev/package-beats/activemq-0.0.1/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
format_version: 1.0.0
name: activemq
version: 0.0.1
description: ""
type: integration
categories:
- logs
- metrics
requirement:
kibana:
versions: ""
10 changes: 10 additions & 0 deletions dev/package-beats/aerospike-0.0.1/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
format_version: 1.0.0
name: aerospike
version: 0.0.1
description: ""
type: integration
categories:
- metrics
requirement:
kibana:
versions: ""
11 changes: 11 additions & 0 deletions dev/package-beats/apache-0.0.1/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
format_version: 1.0.0
name: apache
version: 0.0.1
description: ""
type: integration
categories:
- logs
- metrics
requirement:
kibana:
versions: ""
10 changes: 10 additions & 0 deletions dev/package-beats/apache2-0.0.1/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
format_version: 1.0.0
name: apache2
version: 0.0.1
description: ""
type: integration
categories:
- logs
requirement:
kibana:
versions: ""
10 changes: 10 additions & 0 deletions dev/package-beats/appsearch-0.0.1/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
format_version: 1.0.0
name: appsearch
version: 0.0.1
description: ""
type: integration
categories:
- metrics
requirement:
kibana:
versions: ""
10 changes: 10 additions & 0 deletions dev/package-beats/auditd-0.0.1/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
format_version: 1.0.0
name: auditd
version: 0.0.1
description: ""
type: integration
categories:
- logs
requirement:
kibana:
versions: ""
11 changes: 11 additions & 0 deletions dev/package-beats/aws-0.0.1/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
format_version: 1.0.0
name: aws
version: 0.0.1
description: ""
type: integration
categories:
- logs
- metrics
requirement:
kibana:
versions: ""
11 changes: 11 additions & 0 deletions dev/package-beats/azure-0.0.1/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
format_version: 1.0.0
name: azure
version: 0.0.1
description: ""
type: integration
categories:
- logs
- metrics
requirement:
kibana:
versions: ""
10 changes: 10 additions & 0 deletions dev/package-beats/beat-0.0.1/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
format_version: 1.0.0
name: beat
version: 0.0.1
description: ""
type: integration
categories:
- metrics
requirement:
kibana:
versions: ""
10 changes: 10 additions & 0 deletions dev/package-beats/cef-0.0.1/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
format_version: 1.0.0
name: cef
version: 0.0.1
description: ""
type: integration
categories:
- logs
requirement:
kibana:
versions: ""
10 changes: 10 additions & 0 deletions dev/package-beats/ceph-0.0.1/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
format_version: 1.0.0
name: ceph
version: 0.0.1
description: ""
type: integration
categories:
- metrics
requirement:
kibana:
versions: ""
10 changes: 10 additions & 0 deletions dev/package-beats/cisco-0.0.1/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
format_version: 1.0.0
name: cisco
version: 0.0.1
description: ""
type: integration
categories:
- logs
requirement:
kibana:
versions: ""
10 changes: 10 additions & 0 deletions dev/package-beats/cloudfoundry-0.0.1/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
format_version: 1.0.0
name: cloudfoundry
version: 0.0.1
description: ""
type: integration
categories:
- metrics
requirement:
kibana:
versions: ""
10 changes: 10 additions & 0 deletions dev/package-beats/cockroachdb-0.0.1/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
format_version: 1.0.0
name: cockroachdb
version: 0.0.1
description: ""
type: integration
categories:
- metrics
requirement:
kibana:
versions: ""
10 changes: 10 additions & 0 deletions dev/package-beats/consul-0.0.1/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
format_version: 1.0.0
name: consul
version: 0.0.1
description: ""
type: integration
categories:
- metrics
requirement:
kibana:
versions: ""
11 changes: 11 additions & 0 deletions dev/package-beats/coredns-0.0.1/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
format_version: 1.0.0
name: coredns
version: 0.0.1
description: ""
type: integration
categories:
- logs
- metrics
requirement:
kibana:
versions: ""
10 changes: 10 additions & 0 deletions dev/package-beats/couchbase-0.0.1/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
format_version: 1.0.0
name: couchbase
version: 0.0.1
description: ""
type: integration
categories:
- metrics
requirement:
kibana:
versions: ""
10 changes: 10 additions & 0 deletions dev/package-beats/couchdb-0.0.1/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
format_version: 1.0.0
name: couchdb
version: 0.0.1
description: ""
type: integration
categories:
- metrics
requirement:
kibana:
versions: ""
10 changes: 10 additions & 0 deletions dev/package-beats/docker-0.0.1/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
format_version: 1.0.0
name: docker
version: 0.0.1
description: ""
type: integration
categories:
- metrics
requirement:
kibana:
versions: ""
10 changes: 10 additions & 0 deletions dev/package-beats/dropwizard-0.0.1/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
format_version: 1.0.0
name: dropwizard
version: 0.0.1
description: ""
type: integration
categories:
- metrics
requirement:
kibana:
versions: ""
11 changes: 11 additions & 0 deletions dev/package-beats/elasticsearch-0.0.1/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
format_version: 1.0.0
name: elasticsearch
version: 0.0.1
description: ""
type: integration
categories:
- logs
- metrics
requirement:
kibana:
versions: ""
11 changes: 11 additions & 0 deletions dev/package-beats/envoyproxy-0.0.1/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
format_version: 1.0.0
name: envoyproxy
version: 0.0.1
description: ""
type: integration
categories:
- logs
- metrics
requirement:
kibana:
versions: ""
Loading