1
0
Fork 0
mirror of https://github.com/librenms/docker.git synced 2026-01-23 02:14:48 +00:00

Create and enable a snmp trap handling container (#180)

This commit is contained in:
Anton Lundin 2021-08-01 07:26:12 +02:00 committed by GitHub
parent 1111095afe
commit b2d4ddb2c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 147 additions and 3 deletions

View file

@ -131,7 +131,7 @@ RUN apk --update --no-cache add -t build-dependencies \
COPY rootfs /
EXPOSE 8000 514 514/udp
EXPOSE 8000 514 514/udp 162 162/udp
VOLUME [ "/data" ]
ENTRYPOINT [ "/init" ]

View file

@ -26,6 +26,7 @@ If you are interested, [check out](https://hub.docker.com/r/crazymax/) my other
* Multi-platform image
* [Dispatcher service](doc/docker/environment-variables.md#dispatcher-service) as "sidecar" container
* Syslog-ng support through a ["sidecar" container](doc/docker/environment-variables.md#syslog-ng)
* Snmp-trap support through a ["sidecar" container](doc/docker/environment-variables.md#snmptrapd)
* Built-in LibreNMS [Weathermap plugin](https://docs.librenms.org/Extensions/Weathermap/)
* Ability to add custom Monitoring plugins (Nagios)
* Ability to add custom alert templates

View file

@ -35,6 +35,12 @@
* `SIDECAR_SYSLOGNG`: Set to `1` to enable sidecar syslog-ng mode for this container (default `0`)
### Snmptrapd
> :warning: Only used if you enable and run a [sidecar snmptrapd container](../notes/snmptrapd.md)
* `SIDECAR_SNMPTRAPD`: Set to `1` to enable sidecar snmptrapd mode for this container (default `0`)
### Database
* `DB_HOST`: MySQL database hostname / IP address

12
doc/notes/snmptrapd.md Normal file
View file

@ -0,0 +1,12 @@
## Snmptrapd
If you want to enable snmptrapd, you have to run a "sidecar" container (see snmptrapd service in [docker-compose.yml](../../examples/compose/docker-compose.yml) example) or run a simple container like this :
```bash
docker run -d --name librenms_snmptrapd \
--env-file $(pwd)/librenms.env \
-e SIDECAR_SNMPTRAPD=1 \
-p 162 -p 162/udp \
-v librenms:/data \
librenms/librenms:latest
```

View file

@ -138,3 +138,35 @@ services:
- "REDIS_DB=0"
- "SIDECAR_SYSLOGNG=1"
restart: always
snmptrapd:
image: librenms/librenms:latest
container_name: librenms_snmptrapd
hostname: librenms-snmptrapd
cap_add:
- NET_ADMIN
- NET_RAW
depends_on:
- librenms
ports:
- target: 162
published: 162
protocol: tcp
- target: 162
published: 162
protocol: udp
volumes:
- "./librenms:/data"
env_file:
- "./librenms.env"
environment:
- "TZ=${TZ}"
- "PUID=${PUID}"
- "PGID=${PGID}"
- "DB_HOST=db"
- "DB_NAME=${MYSQL_DATABASE}"
- "DB_USER=${MYSQL_USER}"
- "DB_PASSWORD=${MYSQL_PASSWORD}"
- "DB_TIMEOUT=60"
- "SIDECAR_SNNMPTRAPD=1"
restart: always

View file

@ -156,3 +156,35 @@ services:
- "REDIS_DB=0"
- "SIDECAR_SYSLOGNG=1"
restart: always
snmptrapd:
image: librenms/librenms:latest
container_name: librenms_snmptrapd
hostname: librenms-snmptrapd
cap_add:
- NET_ADMIN
- NET_RAW
depends_on:
- librenms
ports:
- target: 162
published: 162
protocol: tcp
- target: 162
published: 162
protocol: udp
volumes:
- "./librenms:/data"
env_file:
- "./librenms.env"
environment:
- "TZ=${TZ}"
- "PUID=${PUID}"
- "PGID=${PGID}"
- "DB_HOST=db"
- "DB_NAME=${MYSQL_DATABASE}"
- "DB_USER=${MYSQL_USER}"
- "DB_PASSWORD=${MYSQL_PASSWORD}"
- "DB_TIMEOUT=60"
- "SIDECAR_SNNMPTRAPD=1"
restart: always

View file

@ -167,3 +167,32 @@ services:
- "REDIS_DB=0"
- "SIDECAR_SYSLOGNG=1"
restart: always
snmptrapd:
image: librenms/librenms:latest
container_name: librenms_snmptrapd
hostname: librenms-snmptrapd
depends_on:
- librenms
ports:
- target: 162
published: 162
protocol: tcp
- target: 162
published: 162
protocol: udp
volumes:
- "./librenms:/data"
env_file:
- "./librenms.env"
environment:
- "TZ=${TZ}"
- "PUID=${PUID}"
- "PGID=${PGID}"
- "DB_HOST=db"
- "DB_NAME=${MYSQL_DATABASE}"
- "DB_USER=${MYSQL_USER}"
- "DB_PASSWORD=${MYSQL_PASSWORD}"
- "DB_TIMEOUT=60"
- "SIDECAR_SNNMPTRAPD=1"
restart: always

View file

@ -30,8 +30,9 @@ DB_TIMEOUT=${DB_TIMEOUT:-60}
SIDECAR_DISPATCHER=${SIDECAR_DISPATCHER:-0}
SIDECAR_SYSLOGNG=${SIDECAR_SYSLOGNG:-0}
SIDECAR_SNNMPTRAPD=${SIDECAR_SNNMPTRAPD:-0}
if [ "$SIDECAR_DISPATCHER" = "1" ] || [ "$SIDECAR_SYSLOGNG" = "1" ]; then
if [ "$SIDECAR_DISPATCHER" = "1" ] || [ "$SIDECAR_SYSLOGNG" = "1" ] || [ "$SIDECAR_SNNMPTRAPD" = "1" ]; then
exit 0
fi

View file

@ -8,8 +8,9 @@ LIBRENMS_DAILY_SCHEDULE="15 0 * * *"
SIDECAR_DISPATCHER=${SIDECAR_DISPATCHER:-0}
SIDECAR_SYSLOGNG=${SIDECAR_SYSLOGNG:-0}
SIDECAR_SNNMPTRAPD=${SIDECAR_SNNMPTRAPD:-0}
if [ "$SIDECAR_DISPATCHER" = "1" ] || [ "$SIDECAR_SYSLOGNG" = "1" ]; then
if [ "$SIDECAR_DISPATCHER" = "1" ] || [ "$SIDECAR_SYSLOGNG" = "1" ] || [ "$SIDECAR_SNNMPTRAPD" = "1" ]; then
exit 0
fi

View file

@ -0,0 +1,27 @@
#!/usr/bin/with-contenv sh
SIDECAR_SNNMPTRAPD=${SIDECAR_SNNMPTRAPD:-0}
LIBRENMS_SNMP_COMMUNITY=${LIBRENMS_SNMP_COMMUNITY:-librenmsdocker}
# Continue only if sidecar snmptrapd container
if [ "$SIDECAR_SNNMPTRAPD" != "1" ]; then
exit 0
fi
echo ">>"
echo ">> Sidecar snmptrapd container detected"
echo ">>"
mkdir -p /run/snmptrapd
chown -R librenms. /run/snmptrapd
sed -ie "s/@LIBRENMS_SNMP_COMMUNITY@/${LIBRENMS_SNMP_COMMUNITY}/" /etc/snmp/snmptrapd.conf
# Create service
mkdir -p /etc/services.d/snmptrapd
cat > /etc/services.d/snmptrapd/run <<EOL
#!/usr/bin/execlineb -P
with-contenv
/usr/sbin/snmptrapd -f -m ALL -M /opt/librenms/mibs:/opt/librenms/mibs/cisco udp:162 tcp:162
EOL
chmod +x /etc/services.d/snmptrapd/run

View file

@ -0,0 +1,3 @@
disableAuthorization yes
authCommunity log,execute,net @LIBRENMS_SNMP_COMMUNITY@
traphandle default /opt/librenms/snmptrap.php