Skip to content

Commit 91f71d2

Browse files
committed
Add NetFlow collector and Grafolean NetFlow bot
1 parent e0e929c commit 91f71d2

File tree

10 files changed

+419
-36
lines changed

10 files changed

+419
-36
lines changed

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
BACKEND_URL=https://grafolean.com/api
2+
BOT_TOKEN=
3+
JOBS_REFRESH_INTERVAL=60
4+
NETFLOW_PORT=2055

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.vscode
2+
.env

Dockerfile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
FROM python:3.6-slim-stretch as python-requirements
2+
COPY ./Pipfile ./Pipfile.lock /netflowbot/
3+
WORKDIR /netflowbot
4+
RUN \
5+
pip install pipenv && \
6+
pipenv lock -r > /requirements.txt
7+
8+
FROM python:3.6-slim-stretch as build-backend
9+
COPY ./ /netflowbot/
10+
WORKDIR /netflowbot
11+
RUN \
12+
find ./ ! -name '*.py' -type f -exec rm '{}' ';' && \
13+
rm -rf tests/ .vscode/ .pytest_cache/ __pycache__/ && \
14+
python3.6 -m compileall -b ./ && \
15+
find ./ -name '*.py' -exec rm '{}' ';'
16+
17+
18+
FROM python:3.6-slim-stretch
19+
ARG VERSION
20+
ARG VCS_REF
21+
ARG BUILD_DATE
22+
LABEL org.label-schema.vendor="Grafolean" \
23+
org.label-schema.url="https://grafolean.com/" \
24+
org.label-schema.name="Grafolean NetFlow bot" \
25+
org.label-schema.description="NetFlow collector and Grafolean NetFlow bot" \
26+
org.label-schema.version=$VERSION \
27+
org.label-schema.vcs-url="https://github.com/grafolean/grafolean-netflow-bot/" \
28+
org.label-schema.vcs-ref=$VCS_REF \
29+
org.label-schema.build-date=$BUILD_DATE \
30+
org.label-schema.docker.schema-version="1.0"
31+
COPY --from=python-requirements /requirements.txt /requirements.txt
32+
RUN \
33+
pip install --no-cache-dir -r /requirements.txt && \
34+
echo "alias l='ls -altr'" >> /root/.bashrc
35+
COPY --from=build-backend /netflowbot/ /netflowbot/
36+
WORKDIR /netflowbot
37+
# check for "fail" file and if it exists, remove it and fail the check:
38+
HEALTHCHECK --interval=10s --retries=1 CMD /bin/bash -c "[ ! -f /tmp/fail_health_check ] || ( rm /tmp/fail_health_check && exit 1 )"
39+
40+
# CAREFUL:
41+
# There are two entrypoints, both of which should be running:
42+
# - netflowcollector: gathering packets and writing statistics to Redis
43+
# - netflowbot: Grafolean bot for NetFlow - sending data to Grafolean according to configured sensors
44+
#CMD ["python", "-m", "netflowcollector"]
45+
CMD ["python", "-m", "netflowbot"]

Pipfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ pylint = "*"
1010
requests = "*"
1111
python-dotenv = "*"
1212
ansicolors = "*"
13+
grafoleancollector = "*"
14+
redis = "*"
1315

1416
[requires]
1517
python_version = "3.6"

Pipfile.lock

Lines changed: 54 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker-compose.dev.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: '2.1'
2+
services:
3+
4+
# Build a local Docker image. Usage:
5+
# $ docker-compose -f docker-compose.dev.yml build
6+
7+
grafolean-netflow-bot:
8+
image: grafolean/grafolean-netflow-bot
9+
container_name: grafolean-netflow-bot
10+
build:
11+
context: .
12+
dockerfile: Dockerfile

docker-compose.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
version: '2.1'
2+
services:
3+
4+
#
5+
# Welcome to Grafolean NetFlow bot!
6+
#
7+
# This file should be modified to suit your running environment. Please check the comments and change
8+
# the settings appropriately.
9+
#
10+
11+
netflowbot:
12+
# If you wish to load an explicit version, change the next line. For example:
13+
# image: grafolean/grafolean-netflow-bot:v1.0.0
14+
image: grafolean/grafolean-netflow-bot
15+
container_name: grafolean-netflow-bot
16+
environment:
17+
# Backend url must be set to the address of the Grafolean backend, for example this uses Grafolean hosted service:
18+
# - BACKEND_URL=https://grafolean.com/api
19+
# IMPORTANT: '127.0.0.1' and 'localhost' are _never_ correct addresses for Grafolean backend, because they translate
20+
# to container, not host.
21+
- BACKEND_URL=${BACKEND_URL}
22+
# To use NetFlow bot, a bot with the protocol "netflow" must be added via user interface, then the token needs to be copied here:
23+
- BOT_TOKEN=${BOT_TOKEN}
24+
# Interval between fetching information about jobs:
25+
- JOBS_REFRESH_INTERVAL=${JOBS_REFRESH_INTERVAL:-60}
26+
- REDIS_HOST=redis
27+
restart: always
28+
networks:
29+
- grafolean
30+
31+
32+
redis:
33+
image: redis:5-alpine
34+
container_name: grafolean-netflow-bot-redis
35+
restart: always
36+
networks:
37+
- grafolean
38+
39+
40+
netflowcollector:
41+
# This process collects NetFlow data:
42+
image: grafolean/grafolean-netflow-bot
43+
container_name: grafolean-netflow-collector
44+
environment:
45+
- REDIS_HOST=redis
46+
- NETFLOW_PORT=2055
47+
ports:
48+
- "${NETFLOW_PORT:-2055}:2055/udp"
49+
restart: always
50+
# CAREFUL: NetFlow collector uses the same docker image as bot
51+
# (grafolean/grafolean-netflow-bot), but specifies a different entrypoint:
52+
entrypoint:
53+
- python
54+
- -m
55+
- netflowcollector
56+
networks:
57+
- grafolean
58+
59+
60+
autoheal:
61+
# This container automatically restarts any container that fails its health check. Not a bullet-proof solution, but better than nothing.
62+
image: willfarrell/autoheal
63+
container_name: grafolean-netflow-bot-autoheal
64+
environment:
65+
- AUTOHEAL_CONTAINER_LABEL=all
66+
volumes:
67+
- /var/run/docker.sock:/var/run/docker.sock
68+
restart: always
69+
networks:
70+
- grafolean
71+
72+
73+
# If running on the same host, join the Grafolean network, so we can reach Grafolean
74+
# backend at address grafolean:80.
75+
networks:
76+
grafolean:
77+
name: grafolean

0 commit comments

Comments
 (0)