-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from build-security/feature/ES-1811-kubeapi-fet…
…cher-generated-cleanup Feature/es 1811 kubeapi fetcher generated cleanup
- Loading branch information
Showing
31 changed files
with
17,109 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# See: http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.json] | ||
indent_size = 4 | ||
indent_style = space | ||
|
||
[*.py] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[*.yml] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[Makefile] | ||
indent_style = tab | ||
|
||
[Vagrantfile] | ||
indent_size = 2 | ||
indent_style = space |
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,7 @@ | ||
/.idea | ||
/build | ||
|
||
.DS_Store | ||
/kubebeat | ||
/kubebeat.test | ||
*.pyc |
Empty file.
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,13 @@ | ||
Copyright (c) {year} Eyal Kraft | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
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,20 @@ | ||
BEAT_NAME=kubebeat | ||
BEAT_PATH=github.com/elastic/beats/v7/kubebeat | ||
BEAT_GOPATH=$(firstword $(subst :, ,${GOPATH})) | ||
SYSTEM_TESTS=false | ||
TEST_ENVIRONMENT=false | ||
ES_BEATS_IMPORT_PATH=github.com/elastic/beats/v7 | ||
ES_BEATS?=$(shell go list -m -f '{{.Dir}}' ${ES_BEATS_IMPORT_PATH}) | ||
LIBBEAT_MAKEFILE=$(ES_BEATS)/libbeat/scripts/Makefile | ||
GOPACKAGES=$(shell go list ${BEAT_PATH}/... | grep -v /tools) | ||
GOBUILD_FLAGS=-i -ldflags "-X ${ES_BEATS_IMPORT_PATH}/libbeat/version.buildTime=$(NOW) -X ${ES_BEATS_IMPORT_PATH}/libbeat/version.commit=$(COMMIT_ID)" | ||
MAGE_IMPORT_PATH=github.com/magefile/mage | ||
NO_COLLECT=true | ||
CHECK_HEADERS_DISABLED=true | ||
|
||
# Path to the libbeat Makefile | ||
-include $(LIBBEAT_MAKEFILE) | ||
|
||
.PHONY: copy-vendor | ||
copy-vendor: | ||
mage vendorUpdate |
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,5 @@ | ||
kubebeat | ||
Copyright {year} Eyal Kraft | ||
|
||
This product includes software developed by The Apache Software | ||
Foundation (http://www.apache.org/). |
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,116 @@ | ||
# {Beat} | ||
|
||
Welcome to {Beat}. | ||
|
||
Ensure that this folder is at the following location: | ||
`${GOPATH}/src/github.com/elastic/beats/v7/kubebeat` | ||
|
||
## Getting Started with {Beat} | ||
|
||
### Requirements | ||
|
||
* [Golang](https://golang.org/dl/) 1.7 | ||
|
||
### Init Project | ||
To get running with {Beat} and also install the | ||
dependencies, run the following command: | ||
|
||
``` | ||
make update | ||
``` | ||
|
||
It will create a clean git history for each major step. Note that you can always rewrite the history if you wish before pushing your changes. | ||
|
||
To push {Beat} in the git repository, run the following commands: | ||
|
||
``` | ||
git remote set-url origin https://github.com/elastic/beats/v7/kubebeat | ||
git push origin master | ||
``` | ||
|
||
For further development, check out the [beat developer guide](https://www.elastic.co/guide/en/beats/libbeat/current/new-beat.html). | ||
|
||
### Build | ||
|
||
To build the binary for {Beat} run the command below. This will generate a binary | ||
in the same directory with the name kubebeat. | ||
|
||
``` | ||
make | ||
``` | ||
|
||
|
||
### Run | ||
|
||
To run {Beat} with debugging output enabled, run: | ||
|
||
``` | ||
./kubebeat -c kubebeat.yml -e -d "*" | ||
``` | ||
|
||
|
||
### Test | ||
|
||
To test {Beat}, run the following command: | ||
|
||
``` | ||
make testsuite | ||
``` | ||
|
||
alternatively: | ||
``` | ||
make unit-tests | ||
make system-tests | ||
make integration-tests | ||
make coverage-report | ||
``` | ||
|
||
The test coverage is reported in the folder `./build/coverage/` | ||
|
||
### Update | ||
|
||
Each beat has a template for the mapping in elasticsearch and a documentation for the fields | ||
which is automatically generated based on `fields.yml` by running the following command. | ||
|
||
``` | ||
make update | ||
``` | ||
|
||
|
||
### Cleanup | ||
|
||
To clean {Beat} source code, run the following command: | ||
|
||
``` | ||
make fmt | ||
``` | ||
|
||
To clean up the build directory and generated artifacts, run: | ||
|
||
``` | ||
make clean | ||
``` | ||
|
||
|
||
### Clone | ||
|
||
To clone {Beat} from the git repository, run the following commands: | ||
|
||
``` | ||
mkdir -p ${GOPATH}/src/github.com/elastic/beats/v7/kubebeat | ||
git clone https://github.com/elastic/beats/v7/kubebeat ${GOPATH}/src/github.com/elastic/beats/v7/kubebeat | ||
``` | ||
|
||
|
||
For further development, check out the [beat developer guide](https://www.elastic.co/guide/en/beats/libbeat/current/new-beat.html). | ||
|
||
|
||
## Packaging | ||
|
||
The beat frameworks provides tools to crosscompile and package your beat for different platforms. This requires [docker](https://www.docker.com/) and vendoring as described above. To build packages of your beat, run the following command: | ||
|
||
``` | ||
make release | ||
``` | ||
|
||
This will fetch and create all images required for the build process. The whole process to finish can take several minutes. |
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,2 @@ | ||
kubebeat: | ||
period: 1s |
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,7 @@ | ||
################### {Beat} Configuration Example ######################### | ||
|
||
############################# {Beat} ###################################### | ||
|
||
kubebeat: | ||
# Defines how often an event is sent to the output | ||
period: 1s |
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,7 @@ | ||
################### {Beat} Configuration Example ######################### | ||
|
||
############################# {Beat} ###################################### | ||
|
||
kubebeat: | ||
# Defines how often an event is sent to the output | ||
period: 1s |
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,9 @@ | ||
- key: kubebeat | ||
title: kubebeat | ||
description: | ||
fields: | ||
- name: counter | ||
type: long | ||
required: true | ||
description: > | ||
PLEASE UPDATE DOCUMENTATION |
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,71 @@ | ||
package beater | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/elastic/beats/v7/libbeat/beat" | ||
"github.com/elastic/beats/v7/libbeat/common" | ||
"github.com/elastic/beats/v7/libbeat/logp" | ||
|
||
"github.com/elastic/beats/v7/kubebeat/config" | ||
) | ||
|
||
// kubebeat configuration. | ||
type kubebeat struct { | ||
done chan struct{} | ||
config config.Config | ||
client beat.Client | ||
} | ||
|
||
// New creates an instance of kubebeat. | ||
func New(b *beat.Beat, cfg *common.Config) (beat.Beater, error) { | ||
c := config.DefaultConfig | ||
if err := cfg.Unpack(&c); err != nil { | ||
return nil, fmt.Errorf("Error reading config file: %v", err) | ||
} | ||
|
||
bt := &kubebeat{ | ||
done: make(chan struct{}), | ||
config: c, | ||
} | ||
return bt, nil | ||
} | ||
|
||
// Run starts kubebeat. | ||
func (bt *kubebeat) Run(b *beat.Beat) error { | ||
logp.Info("kubebeat is running! Hit CTRL-C to stop it.") | ||
|
||
var err error | ||
bt.client, err = b.Publisher.Connect() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ticker := time.NewTicker(bt.config.Period) | ||
counter := 1 | ||
for { | ||
select { | ||
case <-bt.done: | ||
return nil | ||
case <-ticker.C: | ||
} | ||
|
||
event := beat.Event{ | ||
Timestamp: time.Now(), | ||
Fields: common.MapStr{ | ||
"type": b.Info.Name, | ||
"counter": counter, | ||
}, | ||
} | ||
bt.client.Publish(event) | ||
logp.Info("Event sent") | ||
counter++ | ||
} | ||
} | ||
|
||
// Stop stops kubebeat. | ||
func (bt *kubebeat) Stop() { | ||
bt.client.Close() | ||
close(bt.done) | ||
} |
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,14 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/elastic/beats/v7/kubebeat/beater" | ||
|
||
cmd "github.com/elastic/beats/v7/libbeat/cmd" | ||
"github.com/elastic/beats/v7/libbeat/cmd/instance" | ||
) | ||
|
||
// Name of this beat | ||
var Name = "kubebeat" | ||
|
||
// RootCmd to handle beats cli | ||
var RootCmd = cmd.GenRootCmdWithSettings(beater.New, instance.Settings{Name: Name}) |
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,14 @@ | ||
// Config is put into a different package to prevent cyclic imports in case | ||
// it is needed in several locations | ||
|
||
package config | ||
|
||
import "time" | ||
|
||
type Config struct { | ||
Period time.Duration `config:"period"` | ||
} | ||
|
||
var DefaultConfig = Config{ | ||
Period: 1 * time.Second, | ||
} |
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,3 @@ | ||
// +build !integration | ||
|
||
package config |
Oops, something went wrong.