Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: grafolean/grafolean-netflow-bot
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.0.3
Choose a base ref
...
head repository: grafolean/grafolean-netflow-bot
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
Showing with 834 additions and 382 deletions.
  1. +6 −0 .env.example
  2. +3 −1 .github/workflows/on_release.yml
  3. +1 −0 Dockerfile
  4. +57 −50 Pipfile.lock
  5. +84 −0 README.md
  6. +136 −26 dbutils.py
  7. +0 −12 docker-compose.dev.yml
  8. +14 −7 docker-compose.yml
  9. +316 −153 netflowbot.py
  10. +17 −97 netflowcollector.py
  11. +199 −35 netflowwriter.py
  12. +1 −1 pynetflow
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
BACKEND_URL=https://grafolean.com/api
BOT_TOKEN=
DB_DIR=
DB_HOST=
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
JOBS_REFRESH_INTERVAL=60
NETFLOW_PORT=2055

NAMED_PIPE_FILENAME=/tmp/netflow-named
4 changes: 3 additions & 1 deletion .github/workflows/on_release.yml
Original file line number Diff line number Diff line change
@@ -11,7 +11,9 @@ jobs:
steps:

- name: Checkout source code
uses: actions/checkout@v1
uses: actions/checkout@v2
with:
submodules: 'true'


- name: Deploy to Docker Hub
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ FROM python:3.6-slim-stretch as build-backend
COPY ./ /netflowbot/
WORKDIR /netflowbot
RUN \
ls pynetflow/netflow/__init__.py || (echo "Make sure you run 'git submodule update --init --recursive'!" && exit 1) && \
rm -rf .git/ tests/ .vscode/ .pytest_cache/ __pycache__/ && \
find ./ ! -name '*.py' -type f -exec rm '{}' ';' && \
python3.6 -m compileall -b ./ && \
107 changes: 57 additions & 50 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 84 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# About Grafolean NetFlow bot

This package is a NetFlow bot for Grafolean, an easy to use generic monitoring system.

The architecture of this bot is a bit unusual. The reason is a [Docker issue](https://github.com/moby/libnetwork/issues/1994) which prevents containers from determining the source IP of the NetFlow UDP packets. Because we need this information, we must put a single process outside the Docker network (*collector*), then pass every incoming packet via named pipe to another process inside the network (*writer*), which writes it to the database (PostgreSQL). The fourth process is a bot, waking up at regular intervals and sending aggregated data to Grafolean.

Note that the system holds the not-yet-aggregated data in PostgreSQL, so it might be possible to perform further analysis if any incidents occur in the network. The data is however not in its original form for storage capacity reasons (only the most important of the fields are saved).

Under the hood [python-netflow-v9-softflowd](https://github.com/bitkeks/python-netflow-v9-softflowd) is used. For local testing (NetFlow v5) [nflow-generator](https://github.com/nerdalert/nflow-generator) can be used.

Requirements:
- NetFlow exporters must be able to send data to the port where *collector* is listening (see `NETFLOW_PORT` environment variable description below)
- Grafolean must be accessible via HTTP(S)

Current limitations:
- only NetFlow v9 and v5 are supported

# License

License is Commons Clause license (on top of Apache 2.0) - source is available, you can use it for free (commercially too), modify and
share, but you can't sell it. See [LICENSE.md](https://github.com/grafolean/grafolean-netflow-bot/blob/master/LICENSE.md) for details.

If in doubt, please [open an issue](https://github.com/grafolean/grafolean-netflow-bot/issues) to get further clarification.

# Install

> **IMPORTANT**: these instructions are only useful if you wish to install a *remote* agent / bot. Please see Grafolean installation instructions if you only wish to enable a bot as part of default Grafolean installation.
Requirements: `docker` and `docker-compose`.

1) log in to Grafolean service (either self-hosted or https://grafolean.com/) and create a new `Bot`. Make sure that selected protocol is `NetFlow`. Copy the bot token.

2) save [docker-compose.yml](https://github.com/grafolean/grafolean-netflow-bot/raw/master/docker-compose.yml) to a local file:
```
$ mkdir ~/netflow
$ cd ~/netflow
$ curl https://github.com/grafolean/grafolean-netflow-bot/raw/master/docker-compose.yml > docker-compose.yml
```
3) save [.env.example](https://raw.githubusercontent.com/grafolean/grafolean-netflow-bot/master/.env.example) to `.env` and edit it:
```
$ curl https://raw.githubusercontent.com/grafolean/grafolean-netflow-bot/master/.env.example > .env
```
- mandatory: `BACKEND_URL` (set to the URL of Grafolean backend, for example `https://grafolean.com/api`),
- mandatory: `BOT_TOKEN` (set to the bot token from step 1),
- mandatory: `DB_DIR` (directory to which the database with non-aggregated results is saved),
- optional: `NETFLOW_PORT` (UDP port on which *collector* listens for incoming packets)
- optional: `JOBS_REFRESH_INTERVAL` (interval in seconds at which the jobs definitions will be updated)
4) run: `docker-compose up -d`
If you get no error, congratulations! Everything else is done from within the Grafolean UI. You can however check the status of container as usually by running `docker ps` and investigate logs by running `docker-compose logs -f` in the `~/netflow/` directory.
## Upgrade
1) `$ docker-compose pull`
2) `$ docker-compose down`
3) `$ docker-compose up -d`
## Debugging
Container logs can be checked by running:
```
$ docker logs --since 5m -f grafolean-netflow-bot
```
## Building locally
If you wish to build the Docker image locally (for debugging or for development purposes), you can use a custom docker-compose YAML file:
```
docker-compose -f docker-compose.dev.yml build
```
As before, `.env.example` can be copied to `.env` and all settings can be altered there.
## Issues
If you encounter any problems installing or running the software, please let us know in the [issues](https://github.com/grafolean/grafolean-netflow-bot/issues). Please make an effort when describing the issue. If we can reproduce the problem, we can also fix it much faster.
# Development
## Contributing
Please open an issue about the problem you are facing before submitting a pull request.
Loading