Skip to content

Commit 338e90f

Browse files
author
Ruben van Vreeland
committed
Merge branch 'release/0.0.9'
2 parents 599ec7e + 9cac981 commit 338e90f

File tree

11 files changed

+109
-34
lines changed

11 files changed

+109
-34
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,5 @@ jspm_packages
7171
.node_repl_history
7272

7373
lib/
74+
*.pyc
7475
config/config.json

.gitlab-ci.yml

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
# Cache template
2+
.default-cache: &default-cache
3+
key: elastalert
4+
paths:
5+
- node_modules
6+
7+
.push-cache: &push-cache
8+
cache:
9+
<<: *default-cache
10+
policy: push
11+
12+
.pull-cache: &pull-cache
13+
cache:
14+
<<: *default-cache
15+
policy: pull
16+
17+
.node_test: &node-test
18+
<<: *pull-cache
19+
image: node:slim
20+
stage: test
21+
122
stages:
223
- build
324
- test
@@ -11,36 +32,30 @@ cache:
1132
policy: pull
1233

1334
build:
35+
<<: *push-cache
1436
image: node:slim
1537
stage: build
16-
cache:
17-
key: elastalert
18-
paths:
19-
- node_modules/
20-
policy: push
2138
script:
22-
- npm i -q
39+
- npm install --quiet
2340
- npm run build
2441

2542
test:
26-
image: node:slim
27-
stage: test
43+
<<: *node-test
2844
script:
29-
- npm i -q
45+
- npm install --quiet
3046
- npm test
3147

3248
lint:
33-
image: node:slim
34-
allow_failure: true
35-
stage: test
49+
<<: *node-test
3650
script:
37-
- npm i -q
51+
- npm install --quiet
3852
- ./node_modules/.bin/eslint .
3953

4054
deploy:npm:
4155
image: node:slim
4256
stage: deploy
4357
script:
58+
- npm install --quiet
4459
- scripts/update-authors.sh
4560
- npm publish --access public
4661
only:
@@ -82,3 +97,6 @@ mirror:github:
8297
- git remote add github https://$MIRROR_GITHUB_USER:$MIRROR_GITHUB_PASSWORD@$MIRROR_GITHUB_URL
8398
- git push -u github -q --mirror
8499
when: always
100+
only:
101+
- tags
102+
- develop

Dockerfile

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
FROM ivankrizsan/elastalert AS py-ea
2-
# Uses BitSensor's elastalert
3-
ENV ELASTALERT_URL https://github.com/bitsensor/yelp-elastalert/archive/master.zip
2+
# Uses BitSensor's elastalert, or yelp master if commented out
3+
# ENV ELASTALERT_URL https://github.com/bitsensor/yelp-elastalert/archive/master.zip
44

55
FROM node:alpine
66
MAINTAINER BitSensor <[email protected]>
77
EXPOSE 3030
8-
8+
99
RUN apk update && apk upgrade && apk add python2
1010

1111
COPY --from=py-ea /usr/lib/python2.7/site-packages /usr/lib/python2.7/site-packages
1212
COPY --from=py-ea /opt/elastalert /opt/elastalert
1313

1414
RUN mkdir server_data
15-
WORKDIR /opt/elastalert-server
16-
COPY . /opt/elastalert-server
17-
18-
RUN npm install --production --quiet
19-
COPY config/elastalert.yaml /opt/elastalert/config.yaml
20-
COPY config/config.json config/config.json
15+
WORKDIR /opt/elastalert-server
16+
COPY . /opt/elastalert-server
17+
18+
RUN npm install --production --quiet
19+
COPY config/elastalert.yaml /opt/elastalert/config.yaml
20+
COPY config/config.json config/config.json
2121
COPY rule_templates/ /opt/elastalert/rule_templates
22+
COPY elastalert_modules/ /opt/elastalert/elastalert_modules
2223

23-
ENTRYPOINT ["npm", "start"]
24+
ENTRYPOINT ["npm", "start"]

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ docker run -d -p 3030:3030 \
1818
-v `pwd`/config/config.json:/opt/elastalert-server/config/config.json \
1919
-v `pwd`/rules:/opt/elastalert/rules \
2020
-v `pwd`/rule_templates:/opt/elastalert/rule_templates \
21+
-v `pwd`/elastalert_modules:/opt/elastalert/elastalert_modules \
2122
--net="host" \
2223
--name elastalert elastalert:latest
2324
```
@@ -29,13 +30,16 @@ docker run -d -p 3030:3030 \
2930
-v (pwd)/config/config.json:/opt/elastalert-server/config/config.json \
3031
-v (pwd)/rules:/opt/elastalert/rules \
3132
-v (pwd)/rule_templates:/opt/elastalert/rule_templates \
33+
-v (pwd)/elastalert_modules:/opt/elastalert/elastalert_modules \
3234
--net="host" \
3335
--name elastalert elastalert:latest
3436
```
3537
### Configuration
3638
#### ElastAlert parameters
3739
ElastAlert supports additional arguments, that can be passed in the `config.json` file. An example is given in `config/config-historic-data-example.json`.
3840

41+
42+
3943
## Installation using npm and manual ElastAlert setup
4044

4145
### Requirements

config/elastalert.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ rules_folder: rules
1212
# How often ElastAlert will query elasticsearch
1313
# The unit can be anything from weeks to seconds
1414
run_every:
15-
seconds: 1
15+
seconds: 5
1616

1717
# ElastAlert will buffer results from the most recent
1818
# period of time, in case some log sources are not in real time
1919
buffer_time:
20-
minutes: 15
20+
minutes: 1
2121

2222
# Optional URL prefix for elasticsearch
2323
#es_url_prefix: elasticsearch

elastalert_modules/__init__.py

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from elastalert.enhancements import BaseEnhancement
2+
from util import convert_array_to_object
3+
from util import parse_detections
4+
5+
# For easier access to nested values in an array , this merges all items in array
6+
# within
7+
class AlertTextEnhancement(BaseEnhancement):
8+
# The enhancement is run against every match
9+
# The match is passed to the process function where it can be modified in any way
10+
# ElastAlert will do this for each enhancement linked to a rule
11+
def process(self, match):
12+
parsed_match = parse_detections(match)
13+
match.update(parsed_match)

elastalert_modules/util.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from itertools import chain
2+
3+
def convert_array_to_object(array):
4+
json = {}
5+
for idx in range(len(array)):
6+
json[str(idx)] = array[idx]
7+
return json
8+
9+
def parse_detections(match):
10+
key = 'detections'
11+
parsed = {key+'_parsed': {}}
12+
13+
if not isinstance(match[key], list):
14+
return parsed
15+
if len(match[key]) == 0:
16+
return parsed
17+
18+
# Converts array terms into objects
19+
# parsed[key + '_parsed'] = convert_array_to_object(match[key])
20+
21+
for sk, value in match[key][0].iteritems():
22+
value_array = []
23+
if isinstance(value, list):
24+
value_array = list(chain.from_iterable(sv for sv in (v[sk] for v in match[key]) if sv))
25+
else:
26+
value_array = [v[sk] for v in match[key]]
27+
unique_values = set(value_array)
28+
parsed[key + '_parsed'][sk] = ", ".join(str(va) for va in unique_values)
29+
30+
return parsed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bitsensor/elastalert",
3-
"version": "0.0.8",
3+
"version": "0.0.9",
44
"description": "A server that runs ElastAlert and exposes REST API's for manipulating rules and alerts.",
55
"license": "MIT",
66
"main": "index.js",

rule_templates/detection_template.yaml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,28 @@ include:
2424
- context.http.userAgent
2525
- context.ip
2626
- context.php.session.sessionId
27-
- detections.type
28-
- detections.name
27+
- detections
2928
- meta.user
3029

31-
alert_subject: "Detection on {}"
30+
31+
# Enhancement for converting 'detections' array into object, ex. get merged detection type by
32+
# 'detections_parsed.type' or get first detection type by 'detection_parsed.0.type'
33+
match_enhancements:
34+
- "elastalert_modules.bitsensor_enhancement.AlertTextEnhancement"
35+
run_enhancements_first: true
36+
37+
38+
alert_subject: ":exclamation: Detection on {}"
3239
alert_subject_args:
3340
- endpoint.name
3441

3542
alert_text_type: alert_text_only
36-
alert_text: "Detection triggered at {}\n\nAttacker:\nIP: {} \nUser-Agent: {}\n\n:Id: {}\nUser: {}"
43+
alert_text: "Triggered at _{}_\n\n*Attacker:*\nIP: {} \nUser-Agent: {}\nDetection: `{}`\n\n:Id: {}\nUser: {}"
3744
alert_text_args:
3845
- endpoint.localtime
3946
- context.ip
4047
- context.http.userAgent
48+
- detections_parsed.type
4149
- _id
4250
- meta.user
4351

0 commit comments

Comments
 (0)