Skip to content

Commit 38b46e5

Browse files
authored
Beta 0.2.0
1 parent 1deb328 commit 38b46e5

File tree

1,214 files changed

+46858
-17233
lines changed

Some content is hidden

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

1,214 files changed

+46858
-17233
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@
88
cloudflarebeat.local.yml
99
/cloudflarelogs.state
1010
*.state
11+
/bin/*
12+
sample_*
13+
cloudflare_logs_*
14+
NOTES.md
15+
*.bak

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Changelog
2+
3+
beta-0.1.0
4+
-----
5+
* First initial beta release.
6+
7+
beta-0.2.0
8+
-----
9+
* Added S3 state file storage option ([Issue #2](https://github.com/hartfordfive/cloudflarebeat/issues/2))
10+
* Fixed bug where nanosecond timestamp fields were not always received in scientific notiation, thus causing an error with the interface type conversion ([Iusse #4](https://github.com/hartfordfive/cloudflarebeat/issues/4))
11+
* Logs are now downloaded and stored in a gzip file, and then read sequentially in order to reduce memory requirement, which was previously higher due to all in-memory download and processing. ([Issue #9](https://github.com/hartfordfive/cloudflarebeat/issues/9))
12+
* Added new configuration options `state_file_path`, `state_file_name`, `delete_logfile_after_processing`, `processed_events_buffer_size`
13+
* Updated logic so that logs are downloaded immediately, without delay in the case where the process has stopped and the time elapsed is greater than the configured period.
14+
* Fixed Elasticsearch 5.x index template.
15+
* Explicitly closed log files handles upon completion as the *too many files open* error was begining to occur after the process was running for over a few days ([Issue #11](https://github.com/hartfordfive/cloudflarebeat/issues/11))
16+
* Added `BuildMapStr` function which builds the final event to be sent. This ensures that fields with types such as `ip` will simply be ommitted if they are an empty string, otherwise this used to cause a mapping exception.
17+
* Included the `zone_tag` in the state file name so that each Cloudflare zone will have its own state file.

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ ES_BEATS?=./vendor/github.com/elastic/beats
66
GOPACKAGES=$(shell glide novendor)
77
PREFIX?=.
88

9+
10+
GO_LDFLAGS=$(-ldflags "-X beat.buildDate=`date +%Y-%m-%d` beat.commitHash=`git rev-parse --verify HEAD`")
911
# Path to the libbeat Makefile
1012
-include $(ES_BEATS)/libbeat/scripts/Makefile
1113

README.md

Lines changed: 84 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,88 @@
11
# Cloudflarebeat
22

3-
Welcome to Cloudflarebeat.
3+
Custom beat to fetch Cloudflare logs via the Enterprise Log Share API.
44

55
Ensure that this folder is at the following location:
66
`${GOPATH}/github.com/hartfordfive`
77

8+
## Disclaimer
9+
10+
Cloudflarebeat is currently in beta therefore it likely has bugs and various optimizations that can be made.
11+
If you find any of these, please create an issue or even a pull request if you're familiar with development for beats library.
12+
13+
## Acknoledgements
14+
15+
Special thank you to [Lightspeed POS](http://www.lightspeedhq.com) for providing access to test data, feedback and suggestions.
16+
817
## Getting Started with Cloudflarebeat
918

19+
### Basic Overview of Application Design
20+
21+
1. API request is made to the Cloudflare ELS endpoint for logs within a specific time range, ending at the latest, 30 minutes AGO
22+
2. When the response is received, the gzip content is saved into a local file.
23+
3. Individual JSON log entries are read from the file one by one, individual fields are added into the event and then sent off to be published.
24+
4. Once all log entries in the file have been processed, the remaining log file is deleted, unless the user has specified the option to keep the original log files.
25+
1026
### Requirements
1127

1228
* [Golang](https://golang.org/dl/) 1.7
29+
* [goreq](https://github.com/franela/goreq)
30+
* [ffjson](https://github.com/pquerna/ffjson/ffjson)
31+
32+
### Cloudflarebeat specific configuration options
33+
34+
- `cloudflarebeat.period` : The period at which the cloudflare logs will be fetched. Regardless of the period, logs are always fetched from ***30 MINUTES AGO - PERIOD*** to ***30 MINUTES AGO***. (Default value of period is 1800s/30mins)
35+
- `cloudflarebeat.api_key` : The API key of the user account (mandatory)
36+
- `cloudflarebeat.email` : The email address of the user account (mandatory)
37+
- `cloudflarebeat.zone_tag` : The zone tag of the domain for which you want to access the enterpise logs (mandatory)
38+
- `cloudflarebeat.state_file_storage_type` : The type of storage for the state file, either `disk` or `s3`, which keeps track of the current progress. (Default: disk)
39+
- `cloudflarebeat.state_file_path` : The path in which the state file will be saved (applicable only with `disk` storage type)
40+
- `cloudflarebeat.state_file_name` : The name of the state file
41+
- `cloudflarebeat.aws_access_key` : The user AWS access key, if S3 storage selected.
42+
- `cloudflarebeat.aws_secret_access_key` : The user AWS secret access key, if S3 storage selected.
43+
- `cloudflarebeat.aws_s3_bucket_name` : The name of the S3 bucket where the state file will be stored
44+
- `cloudflarebeat.delete_logfile_after_processing` : Delete the log files once the processing is complete (default: true)
45+
- `cloudflarebeat.processed_events_buffer_size` : The capacity of the processed events buffer channel (default: 1000)
46+
- `cloudflarebeat.debug` : Enable verbose debug mode, which includes debugging the HTTP requests to the ELS API.
47+
48+
### Using S3 Storage for state file
49+
50+
For cloudflarebeat, it's probably best to create a seperate IAM user account, without a password and only this sample policy file. Best to limit the access of your user as a security practice.
51+
52+
Below is a sample of what the policy file would look like for the S3 storage. Please note you should replace `my-cloudflarebeat-bucket-name` with your bucket name that you've created in S3.
53+
54+
```
55+
{
56+
"Version": "2012-10-17",
57+
"Statement": [
58+
{
59+
"Effect": "Allow",
60+
"Action": [
61+
"s3:ListBucket"
62+
],
63+
"Resource": [
64+
"arn:aws:s3:::my-cloudflarebeat-bucket-name"
65+
]
66+
},
67+
{
68+
"Effect": "Allow",
69+
"Action": [
70+
"s3:PutObject",
71+
"s3:GetObject",
72+
"s3:DeleteObject"
73+
],
74+
"Resource": [
75+
"arn:aws:s3:::my-cloudflarebeat-bucket-name/*"
76+
]
77+
}
78+
]
79+
}
80+
```
81+
82+
### Filtering out specific logs and/or log properties
83+
84+
Please read the beats [documentation regarding processors](https://www.elastic.co/guide/en/beats/filebeat/master/configuration-processors.html). This will allow you to filter events by field values or even remove event fields.
85+
1386

1487
### Init Project
1588
To get running with Cloudflarebeat and also install the
@@ -39,7 +112,6 @@ in the same directory with the name cloudflarebeat.
39112
make
40113
```
41114

42-
43115
### Run
44116

45117
To run Cloudflarebeat with debugging output enabled, run:
@@ -53,20 +125,6 @@ For details of command line options, view the following links:
53125
- https://www.elastic.co/guide/en/beats/libbeat/master/config-file-format-cli.html
54126
- https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-command-line.html
55127

56-
57-
## Cloudflarebeat specific configuration options
58-
59-
- `cloudflarebeat.period` : The period at which the cloudflare logs will be fetched. (Default value is 1800s/30mins which is the default suggested by the Enterprise Log Share API documentation page.)
60-
- `cloudflarebeat.api_key` : The API key of the user account (mandatory)
61-
- `cloudflarebeat.email` : The email address of the user account (mandatory)
62-
- `cloudflarebeat.zone_tag` : The zone tag of the domain for which you want to access the enterpise logs (mandatory)
63-
- `cloudflarebeat.state_file_storage_type` : The type of storage for the state file, either `disk`, `s3`, or `consul`, which keeps track of the current progress. (Defau)
64-
- `cloudflarebeat.aws_access_key` : The user AWS access key, if S3 storage selected.
65-
- `cloudflarebeat.aws_secret_access_key` : The user AWS secret access key, if S3 storage selected.
66-
67-
## Filtering out specific logs and/or log properties
68-
69-
70128
### Test
71129

72130
To test Cloudflarebeat, run the following command:
@@ -135,3 +193,13 @@ make package
135193
```
136194

137195
This will fetch and create all images required for the build process. The hole process to finish can take several minutes.
196+
197+
198+
## Author
199+
200+
Alain Lefebvre <hartfordfive 'at' gmail.com>
201+
202+
## License
203+
204+
Covered under the Apache License, Version 2.0
205+
Copyright (c) 2016 Alain Lefebvre

0 commit comments

Comments
 (0)