Skip to content

Commit 7c4c0f8

Browse files
committed
Add generated blockchainbeat files
0 parents  commit 7c4c0f8

File tree

7,866 files changed

+1844283
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

7,866 files changed

+1844283
-0
lines changed

.editorconfig

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# See: http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
end_of_line = lf
7+
insert_final_newline = true
8+
trim_trailing_whitespace = true
9+
10+
[*.json]
11+
indent_size = 4
12+
indent_style = space
13+
14+
[*.py]
15+
indent_style = space
16+
indent_size = 4
17+
18+
[*.yml]
19+
indent_style = space
20+
indent_size = 2
21+
22+
[Makefile]
23+
indent_style = tab
24+
25+
[Vagrantfile]
26+
indent_size = 2
27+
indent_style = space

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/.idea
2+
/build
3+
4+
.DS_Store
5+
/blockchainbeat
6+
/blockchainbeat.test
7+
*.pyc

.travis.yml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
sudo: required
2+
dist: trusty
3+
services:
4+
- docker
5+
6+
language: go
7+
8+
go:
9+
- 1.10.3
10+
11+
os:
12+
- linux
13+
- osx
14+
15+
env:
16+
matrix:
17+
- TARGETS="check"
18+
- TARGETS="testsuite"
19+
20+
global:
21+
# Cross-compile for amd64 only to speed up testing.
22+
- GOX_FLAGS="-arch amd64"
23+
24+
addons:
25+
apt:
26+
packages:
27+
- python-virtualenv
28+
29+
before_install:
30+
- umask 022
31+
# Redo the travis setup but with the elastic/libbeat path. This is needed so the package path is correct
32+
- mkdir -p $HOME/gopath/src/github.com/opheelia/blockchainbeat/
33+
- rsync -az ${TRAVIS_BUILD_DIR}/ $HOME/gopath/src/github.com/opheelia/blockchainbeat/
34+
- export TRAVIS_BUILD_DIR=$HOME/gopath/src/github.com/opheelia/blockchainbeat/
35+
- cd $HOME/gopath/src/github.com/opheelia/blockchainbeat/
36+
37+
install:
38+
- true
39+
40+
script:
41+
- make $TARGETS
42+
43+
after_success:
44+
# Copy full.cov to coverage.txt because codecov.io requires this file

CONTRIBUTING.md

Whitespace-only changes.

LICENSE.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright (c) 2018 Ophelia Rey
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

Makefile

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
BEAT_NAME=blockchainbeat
2+
BEAT_PATH=github.com/opheelia/blockchainbeat
3+
BEAT_GOPATH=$(firstword $(subst :, ,${GOPATH}))
4+
SYSTEM_TESTS=false
5+
TEST_ENVIRONMENT=false
6+
ES_BEATS?=./vendor/github.com/elastic/beats
7+
GOPACKAGES=$(shell govendor list -no-status +local)
8+
GOBUILD_FLAGS=-i -ldflags "-X $(BEAT_PATH)/vendor/github.com/elastic/beats/libbeat/version.buildTime=$(NOW) -X $(BEAT_PATH)/vendor/github.com/elastic/beats/libbeat/version.commit=$(COMMIT_ID)"
9+
MAGE_IMPORT_PATH=${BEAT_PATH}/vendor/github.com/magefile/mage
10+
11+
# Path to the libbeat Makefile
12+
-include $(ES_BEATS)/libbeat/scripts/Makefile
13+
14+
# Initial beat setup
15+
.PHONY: setup
16+
setup: copy-vendor git-init update git-add
17+
18+
# Copy beats into vendor directory
19+
.PHONY: copy-vendor
20+
copy-vendor:
21+
mkdir -p vendor/github.com/elastic
22+
cp -R ${BEAT_GOPATH}/src/github.com/elastic/beats vendor/github.com/elastic/
23+
rm -rf vendor/github.com/elastic/beats/.git vendor/github.com/elastic/beats/x-pack
24+
mkdir -p vendor/github.com/magefile
25+
cp -R ${BEAT_GOPATH}/src/github.com/elastic/beats/vendor/github.com/magefile/mage vendor/github.com/magefile
26+
27+
.PHONY: git-init
28+
git-init:
29+
git init
30+
31+
.PHONY: git-add
32+
git-add:
33+
git add -A
34+
git commit -m "Add generated blockchainbeat files"
35+
36+
# Collects all dependencies and then calls update
37+
.PHONY: collect
38+
collect:

NOTICE.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
blockchainbeat
2+
Copyright 2018 Ophelia Rey
3+
4+
This product includes software developed by The Apache Software
5+
Foundation (http://www.apache.org/).

README.md

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Blockchainbeat
2+
3+
Welcome to Blockchainbeat.
4+
5+
Ensure that this folder is at the following location:
6+
`${GOPATH}/src/github.com/opheelia/blockchainbeat`
7+
8+
## Getting Started with Blockchainbeat
9+
10+
### Requirements
11+
12+
* [Golang](https://golang.org/dl/) 1.7
13+
14+
### Init Project
15+
To get running with Blockchainbeat and also install the
16+
dependencies, run the following command:
17+
18+
```
19+
make setup
20+
```
21+
22+
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.
23+
24+
To push Blockchainbeat in the git repository, run the following commands:
25+
26+
```
27+
git remote set-url origin https://github.com/opheelia/blockchainbeat
28+
git push origin master
29+
```
30+
31+
For further development, check out the [beat developer guide](https://www.elastic.co/guide/en/beats/libbeat/current/new-beat.html).
32+
33+
### Build
34+
35+
To build the binary for Blockchainbeat run the command below. This will generate a binary
36+
in the same directory with the name blockchainbeat.
37+
38+
```
39+
make
40+
```
41+
42+
43+
### Run
44+
45+
To run Blockchainbeat with debugging output enabled, run:
46+
47+
```
48+
./blockchainbeat -c blockchainbeat.yml -e -d "*"
49+
```
50+
51+
52+
### Test
53+
54+
To test Blockchainbeat, run the following command:
55+
56+
```
57+
make testsuite
58+
```
59+
60+
alternatively:
61+
```
62+
make unit-tests
63+
make system-tests
64+
make integration-tests
65+
make coverage-report
66+
```
67+
68+
The test coverage is reported in the folder `./build/coverage/`
69+
70+
### Update
71+
72+
Each beat has a template for the mapping in elasticsearch and a documentation for the fields
73+
which is automatically generated based on `fields.yml` by running the following command.
74+
75+
```
76+
make update
77+
```
78+
79+
80+
### Cleanup
81+
82+
To clean Blockchainbeat source code, run the following commands:
83+
84+
```
85+
make fmt
86+
make simplify
87+
```
88+
89+
To clean up the build directory and generated artifacts, run:
90+
91+
```
92+
make clean
93+
```
94+
95+
96+
### Clone
97+
98+
To clone Blockchainbeat from the git repository, run the following commands:
99+
100+
```
101+
mkdir -p ${GOPATH}/src/github.com/opheelia/blockchainbeat
102+
git clone https://github.com/opheelia/blockchainbeat ${GOPATH}/src/github.com/opheelia/blockchainbeat
103+
```
104+
105+
106+
For further development, check out the [beat developer guide](https://www.elastic.co/guide/en/beats/libbeat/current/new-beat.html).
107+
108+
109+
## Packaging
110+
111+
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:
112+
113+
```
114+
make release
115+
```
116+
117+
This will fetch and create all images required for the build process. The whole process to finish can take several minutes.

_meta/beat.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
################### Blockchainbeat Configuration Example #########################
2+
3+
############################# Blockchainbeat ######################################
4+
5+
blockchainbeat:
6+
# Defines how often an event is sent to the output
7+
period: 1s

_meta/fields.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
- key: blockchainbeat
2+
title: blockchainbeat
3+
description:
4+
fields:
5+
- name: counter
6+
type: long
7+
required: true
8+
description: >
9+
PLEASE UPDATE DOCUMENTATION

_meta/kibana.generated/5/index-pattern/blockchainbeat.json

+6
Large diffs are not rendered by default.

_meta/kibana.generated/6/index-pattern/blockchainbeat.json

+16
Large diffs are not rendered by default.

beater/blockchainbeat.go

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package beater
2+
3+
import (
4+
"fmt"
5+
"time"
6+
7+
"github.com/elastic/beats/libbeat/beat"
8+
"github.com/elastic/beats/libbeat/common"
9+
"github.com/elastic/beats/libbeat/logp"
10+
11+
"github.com/opheelia/blockchainbeat/config"
12+
)
13+
14+
// Blockchainbeat configuration.
15+
type Blockchainbeat struct {
16+
done chan struct{}
17+
config config.Config
18+
client beat.Client
19+
}
20+
21+
// New creates an instance of blockchainbeat.
22+
func New(b *beat.Beat, cfg *common.Config) (beat.Beater, error) {
23+
c := config.DefaultConfig
24+
if err := cfg.Unpack(&c); err != nil {
25+
return nil, fmt.Errorf("Error reading config file: %v", err)
26+
}
27+
28+
bt := &Blockchainbeat{
29+
done: make(chan struct{}),
30+
config: c,
31+
}
32+
return bt, nil
33+
}
34+
35+
// Run starts blockchainbeat.
36+
func (bt *Blockchainbeat) Run(b *beat.Beat) error {
37+
logp.Info("blockchainbeat is running! Hit CTRL-C to stop it.")
38+
39+
var err error
40+
bt.client, err = b.Publisher.Connect()
41+
if err != nil {
42+
return err
43+
}
44+
45+
ticker := time.NewTicker(bt.config.Period)
46+
counter := 1
47+
for {
48+
select {
49+
case <-bt.done:
50+
return nil
51+
case <-ticker.C:
52+
}
53+
54+
event := beat.Event{
55+
Timestamp: time.Now(),
56+
Fields: common.MapStr{
57+
"type": b.Info.Name,
58+
"counter": counter,
59+
},
60+
}
61+
bt.client.Publish(event)
62+
logp.Info("Event sent")
63+
counter++
64+
}
65+
}
66+
67+
// Stop stops blockchainbeat.
68+
func (bt *Blockchainbeat) Stop() {
69+
bt.client.Close()
70+
close(bt.done)
71+
}

0 commit comments

Comments
 (0)