Skip to content

Commit d03800e

Browse files
committed
Merge branch 'feature/docker' into 'master'
Feature/docker See merge request grafolean/grafolean-collector-snmp!4
2 parents 7ce2884 + 6590fe7 commit d03800e

File tree

5 files changed

+183
-0
lines changed

5 files changed

+183
-0
lines changed

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.git
2+
.env*
3+
.vscode
4+
.pytest_cache
5+

.gitlab-ci.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
image: docker:stable
2+
3+
services:
4+
- docker:dind
5+
6+
variables:
7+
DOCKER_DRIVER: overlay2
8+
9+
stages:
10+
- test
11+
- deploy
12+
13+
pytest:
14+
stage: test
15+
image: python:3.6-slim-stretch
16+
before_script:
17+
- apt-get update
18+
- apt-get install --no-install-recommends -q -y libsnmp-dev build-essential
19+
- pip install --no-cache-dir pipenv
20+
- pipenv install --dev
21+
script:
22+
- pipenv run pytest -x test_snmpcollector.py
23+
24+
deploy to docker hub:
25+
stage: deploy
26+
when: manual
27+
only:
28+
variables:
29+
- $CI_COMMIT_TAG =~ /^v[0-9]+[.][0-9]+[.][0-9]+([.][^.]+)?$/
30+
variables:
31+
CI_REGISTRY_IMAGE: grafolean/grafolean-collector-snmp
32+
script:
33+
- apk add --no-cache git
34+
# check that we are deploying the latest version:
35+
- export LAST_KNOWN_VERSION=`git tag -l --sort=-version:refname "v*.*.*" | head -n 1 | tr -d '[:space:]'`
36+
- '[ "$LAST_KNOWN_VERSION" == "$CI_COMMIT_TAG" ] || (echo "Tag does not denote latest known version (which is $LAST_KNOWN_VERSION), aborting!" && exit 1)'
37+
- echo "Deploying..."
38+
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
39+
- docker build -t "docker.io/$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG" -t "docker.io/$CI_REGISTRY_IMAGE:latest" --build-arg VERSION=$CI_COMMIT_TAG --build-arg VCS_REF=$CI_COMMIT_SHA --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') .
40+
- docker push "docker.io/$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG"
41+
- docker push "docker.io/$CI_REGISTRY_IMAGE:latest"
42+
- docker rmi $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
43+
- docker rmi $CI_REGISTRY_IMAGE:latest

Dockerfile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
FROM python:3.6-slim-stretch as python-requirements
2+
COPY ./Pipfile ./Pipfile.lock /snmpcollector/
3+
WORKDIR /snmpcollector
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 ./ /snmpcollector/
10+
WORKDIR /snmpcollector
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 SNMP Collector" \
25+
org.label-schema.description="SNMP collector for Grafolean" \
26+
org.label-schema.version=$VERSION \
27+
org.label-schema.vcs-url="https://gitlab.com/grafolean/grafolean-collector-snmp/" \
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+
apt-get update && \
34+
apt-get install --no-install-recommends -q -y libsnmp-dev build-essential&& \
35+
pip install --no-cache-dir -r /requirements.txt && \
36+
apt-get purge -y build-essential && \
37+
apt-get clean autoclean && \
38+
apt-get autoremove --yes && \
39+
rm -rf /var/lib/{apt,dpkg,cache,log}/ && \
40+
echo "alias l='ls -altr'" >> /root/.bashrc
41+
COPY --from=build-backend /snmpcollector/ /snmpcollector/
42+
WORKDIR /snmpcollector
43+
CMD ["python", "-m", "snmpcollector"]

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# About Grafolean SNMP Collector
2+
3+
This package is a SNMP Collector for Grafolean, an easy to use generic monitoring system.
4+
5+
Once installed, all the configuration of SNMP sensors is done through Grafolean's web-based user interface. Depending on permissions,
6+
a single SNMP Collector instance can be fetching data for multiple accounts and entities. The fetching intervals can be specified with
7+
up to a second precision.
8+
9+
Under the hood it uses [net-snmp](http://net-snmp.sourceforge.net/) (via [easysnmp](https://easysnmp.readthedocs.io)), which means
10+
it should be compatible with any device that can respond to requests by `snmpget` and `snmpwalk`.
11+
12+
Requirements:
13+
- the devices that should be queried via SNMP must be accessible *from the container* (make sure SNMP Collector is installed in correct network and that there are no firewalls in between)
14+
- Grafolean must be accessible via HTTP(S)
15+
16+
Current limitations:
17+
- does not yet support out-of-order SNMP WALK responses
18+
- does not yet limit the maximum number of retrieved OIDs when doing SNMP WALK
19+
- BULK GET/WALK is not supported yet
20+
21+
# License
22+
23+
License is Commons Clause license (on top of Apache 2.0) - source is available, you can use it for free (commercially too), modify and
24+
share, but you can't sell it. See [LICENSE.md](https://gitlab.com/grafolean/grafolean-collector-snmp/blob/master/LICENSE.md) for details.
25+
26+
If in doubt, please [open an issue](https://gitlab.com/grafolean/grafolean-collector-snmp/issues) to get further clarification.
27+
28+
# Install (docker / docker-compose)
29+
30+
This is the easiest and currently the only officially supported way. However other installation methods should be straightforward by studying `Dockerfile`.
31+
32+
1) log in to Grafolean service (either https://grafolean.com/ or self-hosted), select an appropriate `Account` and create a new `Bot`. Make sure that selected protocol is `SNMP`. Copy the bot token.
33+
2) save [docker-compose.yml](https://gitlab.com/grafolean/grafolean-collector-snmp/raw/master/docker-compose.yml) to a local file
34+
3) edit `docker-compose.yml` and change:
35+
- mandatory: `BACKEND_URL` (set to the URL of Grafolean backend, for example `https://grafolean.com/api`),
36+
- mandatory: `BOT_TOKEN` (set to the bot token from step 1),
37+
- optional: `JOBS_REFRESH_INTERVAL` (interval in seconds at which the jobs definitions will be updated)
38+
Alternatively, you can also copy `.env.example` to `.env` and change settings there (leaving `docker-compose.yml` in original state).
39+
4) run: `docker-compose up -d`
40+
41+
## Upgrade
42+
43+
1) `docker-compose pull`
44+
2) `docker-compose down && docker-compose up -d`
45+
46+
## Debugging
47+
48+
Container logs can be checked by running:
49+
```
50+
$ docker logs grafolean-collector-snmp
51+
```
52+
53+
# Development
54+
55+
## Contributing
56+
57+
To contribute to this repository, CLA needs to be signed. Please open an issue about the problem you are facing before submitting a pull request.
58+
59+
## Issues
60+
61+
If you encounter any problems installing or running the software, please let us know in the [issues](https://gitlab.com/grafolean/grafolean-collector-snmp/issues). If possible, please make sure to describe the issue in a way that will allow us to reproduce it.

docker-compose.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
version: '2.1'
2+
services:
3+
4+
#
5+
# Welcome to Grafolean SNMP Collector!
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+
snmpcollector:
12+
# If you wish to load an explicit version, change the next line. For example:
13+
# image: grafolean/grafolean-collector-snmp:v1.0.0
14+
image: grafolean/grafolean-collector-snmp
15+
build:
16+
context: .
17+
dockerfile: Dockerfile
18+
container_name: grafolean-collector-snmp
19+
environment:
20+
# Backend url must be set to the address of the Grafolean backend, for example this uses Grafolean hosted service:
21+
# - BACKEND_URL=https://grafolean.com/api
22+
- BACKEND_URL=${BACKEND_URL}
23+
# To use SNMP Collector, a bot with the protocol "snmp" must be added via user interface, then the token needs to be copied here:
24+
- BOT_TOKEN=${BOT_TOKEN}
25+
# Interval between fetching information about jobs:
26+
- JOBS_REFRESH_INTERVAL=${JOBS_REFRESH_INTERVAL}
27+
restart: always
28+
# Grafolean backend must be accessible on BACKEND_URL *from the point of view of container*. If running
29+
# on the same host, '127.0.0.1' translates to container, not host - this directive changes network mode
30+
# so that Docker networking is bypassed.
31+
#network_mode: "host"

0 commit comments

Comments
 (0)