Skip to content

Commit

Permalink
Added support for DNS resolving for SNMP traps image
Browse files Browse the repository at this point in the history
  • Loading branch information
dotneft committed Nov 11, 2023
1 parent 7aee917 commit bcf0b16
Show file tree
Hide file tree
Showing 28 changed files with 136 additions and 9 deletions.
17 changes: 17 additions & 0 deletions Dockerfiles/snmptraps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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``
Expand Down
3 changes: 2 additions & 1 deletion Dockerfiles/snmptraps/alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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="\n"
ZBX_SNMP_TRAP_DATE_FORMAT=+%Y%m%d.%H%M%S ZBX_SNMP_TRAP_FORMAT="\n" \
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" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion Dockerfiles/snmptraps/centos/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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="\n"
ZBX_SNMP_TRAP_DATE_FORMAT=+%Y%m%d.%H%M%S ZBX_SNMP_TRAP_FORMAT="\n" \
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" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion Dockerfiles/snmptraps/ol/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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="\n"
ZBX_SNMP_TRAP_DATE_FORMAT=+%Y%m%d.%H%M%S ZBX_SNMP_TRAP_FORMAT="\n" \
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" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion Dockerfiles/snmptraps/rhel/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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="\n"
ZBX_SNMP_TRAP_DATE_FORMAT=+%Y%m%d.%H%M%S ZBX_SNMP_TRAP_FORMAT="\n" \
ZBX_SNMP_TRAP_USE_DNS=false

LABEL description="Zabbix SNMP traps receiver" \
maintainer="alexey.pustovalov@zabbix.com" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion Dockerfiles/snmptraps/ubuntu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/mibs/ietf:/var/lib/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="\n"
ZBX_SNMP_TRAP_DATE_FORMAT=+%Y%m%d.%H%M%S ZBX_SNMP_TRAP_FORMAT="\n" \
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" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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
5 changes: 5 additions & 0 deletions docker-compose_v3_alpine_mysql_latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ services:

zabbix-snmptraps:
image: zabbix/zabbix-snmptraps:alpine-trunk
# 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
Expand All @@ -377,6 +380,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:
Expand Down
5 changes: 5 additions & 0 deletions docker-compose_v3_alpine_mysql_local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@ services:
cache_from:
- alpine:3.18
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
Expand All @@ -462,6 +465,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:
Expand Down
5 changes: 5 additions & 0 deletions docker-compose_v3_alpine_pgsql_latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,9 @@ services:

zabbix-snmptraps:
image: zabbix/zabbix-snmptraps:alpine-trunk
# 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
Expand All @@ -368,6 +371,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:
Expand Down
5 changes: 5 additions & 0 deletions docker-compose_v3_alpine_pgsql_local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,9 @@ services:
cache_from:
- alpine:3.18
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
Expand All @@ -467,6 +470,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:
Expand Down
5 changes: 5 additions & 0 deletions docker-compose_v3_centos_mysql_latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ services:

zabbix-snmptraps:
image: zabbix/zabbix-snmptraps:centos-trunk
# 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
Expand All @@ -377,6 +380,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:
Expand Down
5 changes: 5 additions & 0 deletions docker-compose_v3_centos_mysql_local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ services:
cache_from:
- quay.io/centos/centos:stream9
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
Expand All @@ -463,6 +466,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:
Expand Down
5 changes: 5 additions & 0 deletions docker-compose_v3_centos_pgsql_latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,9 @@ services:

zabbix-snmptraps:
image: zabbix/zabbix-snmptraps:centos-trunk
# 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
Expand All @@ -368,6 +371,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:
Expand Down
5 changes: 5 additions & 0 deletions docker-compose_v3_centos_pgsql_local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,9 @@ services:
cache_from:
- quay.io/centos/centos:stream9
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
Expand All @@ -467,6 +470,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:
Expand Down
5 changes: 5 additions & 0 deletions docker-compose_v3_ol_mysql_latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ services:

zabbix-snmptraps:
image: zabbix/zabbix-snmptraps:ol-trunk
# 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
Expand All @@ -377,6 +380,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:
Expand Down
5 changes: 5 additions & 0 deletions docker-compose_v3_ol_mysql_local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ services:
cache_from:
- oraclelinux:9-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
Expand All @@ -463,6 +466,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:
Expand Down
5 changes: 5 additions & 0 deletions docker-compose_v3_ol_pgsql_latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,9 @@ services:

zabbix-snmptraps:
image: zabbix/zabbix-snmptraps:ol-trunk
# 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
Expand All @@ -368,6 +371,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:
Expand Down
5 changes: 5 additions & 0 deletions docker-compose_v3_ol_pgsql_local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,9 @@ services:
cache_from:
- oraclelinux:9-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
Expand All @@ -467,6 +470,8 @@ services:
reservations:
cpus: '0.25'
memory: 128M
env_file:
- ./env_vars/.env_snmptraps
networks:
zbx_net_frontend:
aliases:
Expand Down
Loading

0 comments on commit bcf0b16

Please sign in to comment.