Added support for DNS resolving for SNMP traps image

This commit is contained in:
Alexey Pustovalov 2023-11-11 14:25:11 +09:00
parent 556cf9942d
commit ada69324de
28 changed files with 136 additions and 9 deletions

View File

@ -58,6 +58,23 @@ The Zabbix snmptraps log is available through Docker's container log:
$ docker logs some-zabbix-snmptraps
```
## Environment Variables
When you start the `zabbix-snmptraps` image, you can adjust the configuration by passing one or more environment variables on the `docker run` command line.
### `ZBX_SNMP_TRAP_DATE_FORMAT`
This variable is represent date and time format in the output `snmptraps.log` file. By default, value is `+%Y%m%d.%H%M%S`. Please, refer to `date` command man for more details about date and time format.
### `ZBX_SNMP_TRAP_FORMAT`
This variable is SNMP trap format in the output `snmptraps.log` file. By default, value is `\n`, in this case each new variable is placed on new line.
### `ZBX_SNMP_TRAP_USE_DNS`
This variable manages source network address representation. It can be IP address or DNS of SNMP trap sender. The variable works only when container command is modified and "-n" command argument is removed from argument list. By default, value is `false`.
## Allowed volumes for the Zabbix snmptraps container
### ``/var/lib/zabbix/snmptraps``

View File

@ -7,7 +7,8 @@ ARG ZBX_SOURCES=https://git.zabbix.com/scm/zbx/zabbix.git
ENV TERM=xterm \
ZBX_VERSION=${ZBX_VERSION} ZBX_SOURCES=${ZBX_SOURCES} \
MIBDIRS=/usr/share/snmp/mibs:/var/lib/zabbix/mibs MIBS=+ALL \
ZBX_SNMP_TRAP_DATE_FORMAT=+%Y%m%d.%H%M%S ZBX_SNMP_TRAP_FORMAT=" "
ZBX_SNMP_TRAP_DATE_FORMAT=+%Y%m%d.%H%M%S ZBX_SNMP_TRAP_FORMAT=" " \
ZBX_SNMP_TRAP_USE_DNS=false
LABEL org.opencontainers.image.authors="Alexey Pustovalov <alexey.pustovalov@zabbix.com>" \
org.opencontainers.image.description="Zabbix SNMP traps receiver" \

View File

@ -6,6 +6,8 @@ ZBX_SNMP_TRAP_DATE_FORMAT=${ZBX_SNMP_TRAP_DATE_FORMAT:-"+%Y%m%d.%H%M%S"}
ZBX_SNMP_TRAP_FORMAT=${ZBX_SNMP_TRAP_FORMAT:-" "}
ZBX_SNMP_TRAP_USE_DNS=${ZBX_SNMP_TRAP_USE_DNS:-"false"}
date=$(date "$ZBX_SNMP_TRAP_DATE_FORMAT")
# The name of the host that sent the notification, as determined by gethostbyaddr(3).
@ -40,4 +42,6 @@ done
! [ -z $trap_address ] && sender_addr=$trap_address
[[ "$ZBX_SNMP_TRAP_USE_DNS" == "true" ]] && ! [[ ${host} =~ \[(.*?)\].*\-\> ]] && sender_addr=$host
echo -e "$date ZBXTRAP $sender_addr$ZBX_SNMP_TRAP_FORMAT$sender$ZBX_SNMP_TRAP_FORMAT$vars" >> $ZABBIX_TRAPS_FILE

View File

@ -7,7 +7,8 @@ ARG ZBX_SOURCES=https://git.zabbix.com/scm/zbx/zabbix.git
ENV TERM=xterm \
ZBX_VERSION=${ZBX_VERSION} ZBX_SOURCES=${ZBX_SOURCES} \
MIBDIRS=/usr/share/snmp/mibs:/var/lib/zabbix/mibs MIBS=+ALL \
ZBX_SNMP_TRAP_DATE_FORMAT=+%Y%m%d.%H%M%S ZBX_SNMP_TRAP_FORMAT=" "
ZBX_SNMP_TRAP_DATE_FORMAT=+%Y%m%d.%H%M%S ZBX_SNMP_TRAP_FORMAT=" " \
ZBX_SNMP_TRAP_USE_DNS=false
LABEL org.opencontainers.image.authors="Alexey Pustovalov <alexey.pustovalov@zabbix.com>" \
org.opencontainers.image.description="Zabbix SNMP traps receiver" \

View File

@ -6,6 +6,8 @@ ZBX_SNMP_TRAP_DATE_FORMAT=${ZBX_SNMP_TRAP_DATE_FORMAT:-"+%Y%m%d.%H%M%S"}
ZBX_SNMP_TRAP_FORMAT=${ZBX_SNMP_TRAP_FORMAT:-" "}
ZBX_SNMP_TRAP_USE_DNS=${ZBX_SNMP_TRAP_USE_DNS:-"false"}
date=$(date "$ZBX_SNMP_TRAP_DATE_FORMAT")
# The name of the host that sent the notification, as determined by gethostbyaddr(3).
@ -40,4 +42,6 @@ done
! [ -z $trap_address ] && sender_addr=$trap_address
echo -e "$date ZBXTRAP $sender_addr$ZBX_SNMP_TRAP_FORMAT$vars" >> $ZABBIX_TRAPS_FILE
[[ "$ZBX_SNMP_TRAP_USE_DNS" == "true" ]] && ! [[ ${host} =~ \[(.*?)\].*\-\> ]] && sender_addr=$host
echo -e "$date ZBXTRAP $sender_addr$ZBX_SNMP_TRAP_FORMAT$sender$ZBX_SNMP_TRAP_FORMAT$vars" >> $ZABBIX_TRAPS_FILE

View File

@ -7,7 +7,8 @@ ARG ZBX_SOURCES=https://git.zabbix.com/scm/zbx/zabbix.git
ENV TERM=xterm \
ZBX_VERSION=${ZBX_VERSION} ZBX_SOURCES=${ZBX_SOURCES} \
MIBDIRS=/usr/share/snmp/mibs:/var/lib/zabbix/mibs MIBS=+ALL \
ZBX_SNMP_TRAP_DATE_FORMAT=+%Y%m%d.%H%M%S ZBX_SNMP_TRAP_FORMAT=" "
ZBX_SNMP_TRAP_DATE_FORMAT=+%Y%m%d.%H%M%S ZBX_SNMP_TRAP_FORMAT=" " \
ZBX_SNMP_TRAP_USE_DNS=false
LABEL org.opencontainers.image.authors="Alexey Pustovalov <alexey.pustovalov@zabbix.com>" \
org.opencontainers.image.description="Zabbix SNMP traps receiver" \

View File

@ -6,6 +6,8 @@ ZBX_SNMP_TRAP_DATE_FORMAT=${ZBX_SNMP_TRAP_DATE_FORMAT:-"+%Y%m%d.%H%M%S"}
ZBX_SNMP_TRAP_FORMAT=${ZBX_SNMP_TRAP_FORMAT:-"\n"}
ZBX_SNMP_TRAP_USE_DNS=${ZBX_SNMP_TRAP_USE_DNS:-"false"}
date=$(date "$ZBX_SNMP_TRAP_DATE_FORMAT")
# The name of the host that sent the notification, as determined by gethostbyaddr(3).
@ -40,4 +42,6 @@ done
! [ -z $trap_address ] && sender_addr=$trap_address
echo -e "$date ZBXTRAP $sender_addr$ZBX_SNMP_TRAP_FORMAT$vars" >> $ZABBIX_TRAPS_FILE
[[ "$ZBX_SNMP_TRAP_USE_DNS" == "true" ]] && ! [[ ${host} =~ \[(.*?)\].*\-\> ]] && sender_addr=$host
echo -e "$date ZBXTRAP $sender_addr$ZBX_SNMP_TRAP_FORMAT$sender$ZBX_SNMP_TRAP_FORMAT$vars" >> $ZABBIX_TRAPS_FILE

View File

@ -9,7 +9,8 @@ ARG ZBX_SOURCES=https://git.zabbix.com/scm/zbx/zabbix.git
ENV TERM=xterm \
ZBX_VERSION=${ZBX_VERSION} ZBX_SOURCES=${ZBX_SOURCES} \
MIBDIRS=/usr/share/snmp/mibs:/var/lib/zabbix/mibs MIBS=+ALL \
ZBX_SNMP_TRAP_DATE_FORMAT=+%Y%m%d.%H%M%S ZBX_SNMP_TRAP_FORMAT=" "
ZBX_SNMP_TRAP_DATE_FORMAT=+%Y%m%d.%H%M%S ZBX_SNMP_TRAP_FORMAT=" " \
ZBX_SNMP_TRAP_USE_DNS=false
LABEL description="Zabbix SNMP traps receiver" \
maintainer="alexey.pustovalov@zabbix.com" \

View File

@ -6,6 +6,8 @@ ZBX_SNMP_TRAP_DATE_FORMAT=${ZBX_SNMP_TRAP_DATE_FORMAT:-"+%Y%m%d.%H%M%S"}
ZBX_SNMP_TRAP_FORMAT=${ZBX_SNMP_TRAP_FORMAT:-"\n"}
ZBX_SNMP_TRAP_USE_DNS=${ZBX_SNMP_TRAP_USE_DNS:-"false"}
date=$(date "$ZBX_SNMP_TRAP_DATE_FORMAT")
# The name of the host that sent the notification, as determined by gethostbyaddr(3).
@ -40,4 +42,6 @@ done
! [ -z $trap_address ] && sender_addr=$trap_address
echo -e "$date ZBXTRAP $sender_addr$ZBX_SNMP_TRAP_FORMAT$vars" >> $ZABBIX_TRAPS_FILE
[[ "$ZBX_SNMP_TRAP_USE_DNS" == "true" ]] && ! [[ ${host} =~ \[(.*?)\].*\-\> ]] && sender_addr=$host
echo -e "$date ZBXTRAP $sender_addr$ZBX_SNMP_TRAP_FORMAT$sender$ZBX_SNMP_TRAP_FORMAT$vars" >> $ZABBIX_TRAPS_FILE

View File

@ -7,7 +7,8 @@ ARG ZBX_SOURCES=https://git.zabbix.com/scm/zbx/zabbix.git
ENV TERM=xterm \
ZBX_VERSION=${ZBX_VERSION} ZBX_SOURCES=${ZBX_SOURCES} \
MIBDIRS=/var/lib/snmp/mibs/ietf:/var/lib/snmp/mibs/iana:/usr/share/snmp/mibs:/var/lib/zabbix/mibs MIBS=+ALL \
ZBX_SNMP_TRAP_DATE_FORMAT=+%Y%m%d.%H%M%S ZBX_SNMP_TRAP_FORMAT=" "
ZBX_SNMP_TRAP_DATE_FORMAT=+%Y%m%d.%H%M%S ZBX_SNMP_TRAP_FORMAT=" " \
ZBX_SNMP_TRAP_USE_DNS=false
LABEL org.opencontainers.image.authors="Alexey Pustovalov <alexey.pustovalov@zabbix.com>" \
org.opencontainers.image.description="Zabbix SNMP traps receiver" \

View File

@ -6,6 +6,8 @@ ZBX_SNMP_TRAP_DATE_FORMAT=${ZBX_SNMP_TRAP_DATE_FORMAT:-"+%Y%m%d.%H%M%S"}
ZBX_SNMP_TRAP_FORMAT=${ZBX_SNMP_TRAP_FORMAT:-" "}
ZBX_SNMP_TRAP_USE_DNS=${ZBX_SNMP_TRAP_USE_DNS:-"false"}
date=$(date "$ZBX_SNMP_TRAP_DATE_FORMAT")
# The name of the host that sent the notification, as determined by gethostbyaddr(3).
@ -40,4 +42,6 @@ done
! [ -z $trap_address ] && sender_addr=$trap_address
echo -e "$date ZBXTRAP $sender_addr$ZBX_SNMP_TRAP_FORMAT$vars" >> $ZABBIX_TRAPS_FILE
[[ "$ZBX_SNMP_TRAP_USE_DNS" == "true" ]] && ! [[ ${host} =~ \[(.*?)\].*\-\> ]] && sender_addr=$host
echo -e "$date ZBXTRAP $sender_addr$ZBX_SNMP_TRAP_FORMAT$sender$ZBX_SNMP_TRAP_FORMAT$vars" >> $ZABBIX_TRAPS_FILE

View File

@ -358,6 +358,9 @@ services:
zabbix-snmptraps:
image: zabbix/zabbix-snmptraps:alpine-5.0-latest
# Override snmptrapd command arguments to receive SNMP traps by DNS
# It must be done with ZBX_SNMP_TRAP_USE_DNS=true environment variable
# command: /usr/sbin/snmptrapd -C -c /etc/snmp/snmptrapd.conf -Lo -A
profiles:
- full
- all
@ -373,6 +376,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:

View File

@ -444,6 +444,9 @@ services:
cache_from:
- alpine:3.14
image: zabbix-snmptraps:alpine-local
# Override snmptrapd command arguments to receive SNMP traps by DNS
# It must be done with ZBX_SNMP_TRAP_USE_DNS=true environment variable
# command: /usr/sbin/snmptrapd -C -c /etc/snmp/snmptrapd.conf -Lo -A
profiles:
- full
- all
@ -459,6 +462,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:

View File

@ -349,6 +349,9 @@ services:
zabbix-snmptraps:
image: zabbix/zabbix-snmptraps:alpine-5.0-latest
# Override snmptrapd command arguments to receive SNMP traps by DNS
# It must be done with ZBX_SNMP_TRAP_USE_DNS=true environment variable
# command: /usr/sbin/snmptrapd -C -c /etc/snmp/snmptrapd.conf -Lo -A
profiles:
- full
- all
@ -364,6 +367,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:

View File

@ -448,6 +448,9 @@ services:
cache_from:
- alpine:3.14
image: zabbix-snmptraps:alpine-local
# Override snmptrapd command arguments to receive SNMP traps by DNS
# It must be done with ZBX_SNMP_TRAP_USE_DNS=true environment variable
# command: /usr/sbin/snmptrapd -C -c /etc/snmp/snmptrapd.conf -Lo -A
profiles:
- full
- all
@ -463,6 +466,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:

View File

@ -358,6 +358,9 @@ services:
zabbix-snmptraps:
image: zabbix/zabbix-snmptraps:centos-5.0-latest
# Override snmptrapd command arguments to receive SNMP traps by DNS
# It must be done with ZBX_SNMP_TRAP_USE_DNS=true environment variable
# command: /usr/sbin/snmptrapd -C -c /etc/snmp/snmptrapd.conf -Lo -A
profiles:
- full
- all
@ -373,6 +376,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:

View File

@ -444,6 +444,9 @@ services:
cache_from:
- quay.io/centos/centos:stream8
image: zabbix-snmptraps:centos-local
# Override snmptrapd command arguments to receive SNMP traps by DNS
# It must be done with ZBX_SNMP_TRAP_USE_DNS=true environment variable
# command: /usr/sbin/snmptrapd -C -c /etc/snmp/snmptrapd.conf -Lo -A
profiles:
- full
- all
@ -459,6 +462,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:

View File

@ -349,6 +349,9 @@ services:
zabbix-snmptraps:
image: zabbix/zabbix-snmptraps:centos-5.0-latest
# Override snmptrapd command arguments to receive SNMP traps by DNS
# It must be done with ZBX_SNMP_TRAP_USE_DNS=true environment variable
# command: /usr/sbin/snmptrapd -C -c /etc/snmp/snmptrapd.conf -Lo -A
profiles:
- full
- all
@ -364,6 +367,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:

View File

@ -448,6 +448,9 @@ services:
cache_from:
- quay.io/centos/centos:stream8
image: zabbix-snmptraps:centos-local
# Override snmptrapd command arguments to receive SNMP traps by DNS
# It must be done with ZBX_SNMP_TRAP_USE_DNS=true environment variable
# command: /usr/sbin/snmptrapd -C -c /etc/snmp/snmptrapd.conf -Lo -A
profiles:
- full
- all
@ -463,6 +466,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:

View File

@ -358,6 +358,9 @@ services:
zabbix-snmptraps:
image: zabbix/zabbix-snmptraps:ol-5.0-latest
# Override snmptrapd command arguments to receive SNMP traps by DNS
# It must be done with ZBX_SNMP_TRAP_USE_DNS=true environment variable
# command: /usr/sbin/snmptrapd -C -c /etc/snmp/snmptrapd.conf -Lo -A
profiles:
- full
- all
@ -373,6 +376,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:

View File

@ -444,6 +444,9 @@ services:
cache_from:
- oraclelinux:8-slim
image: zabbix-snmptraps:ol-local
# Override snmptrapd command arguments to receive SNMP traps by DNS
# It must be done with ZBX_SNMP_TRAP_USE_DNS=true environment variable
# command: /usr/sbin/snmptrapd -C -c /etc/snmp/snmptrapd.conf -Lo -A
profiles:
- full
- all
@ -459,6 +462,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:

View File

@ -349,6 +349,9 @@ services:
zabbix-snmptraps:
image: zabbix/zabbix-snmptraps:ol-5.0-latest
# Override snmptrapd command arguments to receive SNMP traps by DNS
# It must be done with ZBX_SNMP_TRAP_USE_DNS=true environment variable
# command: /usr/sbin/snmptrapd -C -c /etc/snmp/snmptrapd.conf -Lo -A
profiles:
- full
- all
@ -364,6 +367,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:

View File

@ -448,6 +448,9 @@ services:
cache_from:
- oraclelinux:8-slim
image: zabbix-snmptraps:ol-local
# Override snmptrapd command arguments to receive SNMP traps by DNS
# It must be done with ZBX_SNMP_TRAP_USE_DNS=true environment variable
# command: /usr/sbin/snmptrapd -C -c /etc/snmp/snmptrapd.conf -Lo -A
profiles:
- full
- all
@ -463,6 +466,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:

View File

@ -350,6 +350,9 @@ services:
zabbix-snmptraps:
image: zabbix/zabbix-snmptraps:ubuntu-5.0-latest
# Override snmptrapd command arguments to receive SNMP traps by DNS
# It must be done with ZBX_SNMP_TRAP_USE_DNS=true environment variable
# command: /usr/sbin/snmptrapd -C -c /etc/snmp/snmptrapd.conf -Lo -A
profiles:
- full
- all
@ -365,6 +368,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:

View File

@ -438,6 +438,9 @@ services:
cache_from:
- ubuntu:focal
image: zabbix-snmptraps:ubuntu-local
# Override snmptrapd command arguments to receive SNMP traps by DNS
# It must be done with ZBX_SNMP_TRAP_USE_DNS=true environment variable
# command: /usr/sbin/snmptrapd -C -c /etc/snmp/snmptrapd.conf -Lo -A
profiles:
- full
- all
@ -453,6 +456,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:

View File

@ -343,6 +343,9 @@ services:
zabbix-snmptraps:
image: zabbix/zabbix-snmptraps:ubuntu-5.0-latest
# Override snmptrapd command arguments to receive SNMP traps by DNS
# It must be done with ZBX_SNMP_TRAP_USE_DNS=true environment variable
# command: /usr/sbin/snmptrapd -C -c /etc/snmp/snmptrapd.conf -Lo -A
profiles:
- full
- all
@ -358,6 +361,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:

View File

@ -442,6 +442,9 @@ services:
cache_from:
- ubuntu:focal
image: zabbix-snmptraps:ubuntu-local
# Override snmptrapd command arguments to receive SNMP traps by DNS
# It must be done with ZBX_SNMP_TRAP_USE_DNS=true environment variable
# command: /usr/sbin/snmptrapd -C -c /etc/snmp/snmptrapd.conf -Lo -A
profiles:
- full
- all
@ -457,6 +460,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:

5
env_vars/.env_snmptraps Normal file
View File

@ -0,0 +1,5 @@
ZBX_SNMP_TRAP_DATE_FORMAT=+%Y%m%d.%H%M%S
ZBX_SNMP_TRAP_FORMAT=\n
# To use DNS instead of sender IP override container's command: /usr/sbin/snmptrapd -C -c /etc/snmp/snmptrapd.conf -Lo -A
# Need to remove "-n" command argument
ZBX_SNMP_TRAP_USE_DNS=false