Ad Widget

Collapse

[5.4.6] SNMP traps with containerised Zabbix

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AdamR
    Junior Member
    • Oct 2021
    • 6

    #1

    [5.4.6] SNMP traps with containerised Zabbix

    I have turned to the hive for help as apart from being still a novice when it comes to Zabbix, I've been trying to figure this out for last couple of days.
    The SNMP traps are not showing in the GUI for some reason.

    I have deployed Zabbix-5.4.6 with podman on Rocky Linux 8 with:

    Code:
    podman pod create --name zabbix -p 80:8080 -p 10051:10051 -p 162:1162/udp -p 3000:3000
    
    podman run -d --name=grafana -p 3000:3000 docker.io/grafana/grafana-enterprise
    
    podman run --name zabbix-snmptraps -t \
    -v /zbx_instance/snmptraps:/var/lib/zabbix/snmptraps:rw \
    -v /var/lib/zabbix/mibs:/usr/share/snmp/mibs:ro \
    --pod=zabbix \
    --restart unless-stopped \
    -d docker.io/zabbix/zabbix-snmptraps:latest
    
    
    podman run --name zabbix-agent \
    -e ZBX_SERVER_HOST="127.0.0.1,localhost" \
    --restart=always \
    --pod=zabbix \
    -d docker.io/zabbix/zabbix-agent:latest
    
    
    podman run --name zabbix-server-pgsql -t \
    -e DB_SERVER_HOST="192.168.70.15" \
    -e POSTGRES_DATABASE="zabbix7" \
    -e POSTGRES_USER="zabbix7" \
    -e POSTGRES_PASSWORD="zabbix7" \
    -e ZBX_ENABLE_SNMP_TRAPS="true" \
    -v /zbx_instance/snmptraps:/var/lib/zabbix/snmptraps:rw \
    -v /var/lib/zabbix/mibs:/usr/share/snmp/mibs:ro \
    --restart=always \
    --pod=zabbix \
    -d docker.io/zabbix/zabbix-server-pgsql:latest
    
    podman run --name zabbix-web-nginx-pgsql -t \
    -e ZBX_SERVER_HOST="127.0.0.1" \
    -e DB_SERVER_HOST="192.168.70.15" \
    -e POSTGRES_DATABASE="zabbix7" \
    -e POSTGRES_USER="zabbix7" \
    -e POSTGRES_PASSWORD="zabbix7" \
    -e ZBX_ENABLE_SNMP_TRAPS="true" \
    --restart=always \
    --pod=zabbix \
    -d docker.io/zabbix/zabbix-web-nginx-pgsql:latest
    
    
    podman generate systemd --restart-policy=always -t 1 -f --name zabbix
    
    cp pod-zabbix.service container-zabbix-* /etc/systemd/system/
    
    systemctl enable --now pod-zabbix.service
    Had to disable Selinux as zabbix-smtptraps container couldn't write to /var/lib/zabbix/snmptraps. If someone knows solution please feel free to chip in.

    When I sent the trap with

    Code:
    [root@podman ~]# snmptrap -v 1 -c public 192.168.70.240 '.1.3.6.1.6.3.1.1.5.3' '0.0.0.0' 6 33 '55' .1.3.6.1.6.3.1.1.5.3 s "zmzmzmzmzmzmzmz"
    I can see the trap being received by zabbix-snmptraps container

    Code:
    2021-10-31 22:12:36 0.0.0.0(via UDP: [10.88.0.1]:49645->[10.88.0.14]:1162) TRAP, SNMP v1, community public
    iso.3.6.1.6.3.1.1.5.3 Enterprise Specific Trap (33) Uptime: 55
    iso.3.6.1.6.3.1.1.5.3 = STRING: "qpqpqpqpqpqpqpqpq"
    2021-10-31 22:14:26 0.0.0.0(via UDP: [10.88.0.1]:36369->[10.88.0.14]:1162) TRAP, SNMP v1, community public
    iso.3.6.1.6.3.1.1.5.3 Enterprise Specific Trap (33) Uptime: 55
    iso.3.6.1.6.3.1.1.5.3 = STRING: "zmzmzmzmzmzmzmz"
    2021-10-31 22:30:55 0.0.0.0(via UDP: [192.168.70.240]:44643->[10.88.0.14]:1162) TRAP, SNMP v1, community public
    iso.3.6.1.6.3.1.1.5.3 Enterprise Specific Trap (33) Uptime: 55
    iso.3.6.1.6.3.1.1.5.3 = STRING: "zmzmzmzmzmzmzmz"
    and read by the zabbix-server

    Code:
     190:20211031:223056.778 unmatched trap received from "192.168.70.240": 20211031.223055 UDP: [192.168.70.240]:44643->[10.88.0.14]:1162
    iso.3.6.1.2.1.1.3.0 = 55
    iso.3.6.1.6.3.1.1.4.1.0 = iso.3.6.1.6.3.1.1.5.3.0.33
    iso.3.6.1.6.3.1.1.5.3 = "zmzmzmzmzmzmzmz"
    iso.3.6.1.6.3.18.1.4.0 = "public"
    iso.3.6.1.6.3.1.1.4.3.0 = iso.3.6.1.6.3.1.1.5.3
    The snmptraps.log file contains the traps as expected.

    Zabbix is configured as follows:

    Click image for larger version

Name:	Screenshot 2021-10-31 at 22.38.15.png
Views:	2365
Size:	65.0 KB
ID:	433932

    Click image for larger version

Name:	Screenshot 2021-10-31 at 22.38.45.png
Views:	2500
Size:	111.4 KB
ID:	433931

    zabbix_server.conf from server container

    Code:
    ...
    ...
    ### Option: SNMPTrapperFile
    # Temporary file used for passing data from SNMP trap daemon to the server.
    # Must be the same as in zabbix_trap_receiver.pl or SNMPTT configuration file.
    #
    # Mandatory: no
    # Default:
    # SNMPTrapperFile=/tmp/zabbix_traps.tmp
    SNMPTrapperFile=/var/lib/zabbix/snmptraps/snmptraps.log
    
    ### Option: StartSNMPTrapper
    # If 1, SNMP trapper process is started.
    #
    # Mandatory: no
    # Range: 0-1
    # Default:
    # StartSNMPTrapper=0
    StartSNMPTrapper=1
    ...
    ...
    snmptrap.conf from zabbix-snmptraps container

    Code:
    bash-5.1$ cat /etc/snmp/snmptrapd.conf
    
    # A list of listening addresses, on which to receive incoming SNMP notifications
    
    snmpTrapdAddr udp:1162
    
    snmpTrapdAddr udp6:1162
    
    
    # Do not fork from the calling shell
    
    doNotFork yes
    
    # File in which to store the process ID of the notification receiver
    
    pidFile /tmp/snmptrapd.pid
    
    # Disables support for the NOTIFICATION-LOG-MIB
    
    doNotRetainNotificationLogs yes
    
    
    authCommunity log,execute,net public
    
    disableAuthorization yes
    
    ignoreAuthFailure yes
    
    
    # Specify the format used for trap handle location
    
    #format execute %B\n%b\n%V\n%v\n
    
    
    # o - Log messages to the standard output stream.
    
    # logOption o
    
    
    # S - Display the name of the MIB, as well as the object name (This is the default OID output format)
    
    # T - If values are printed as Hex strings, display a printable version as well
    
    # t - Display TimeTicks values as raw numbers
    
    # e - Removes the symbolic labels from enumeration values
    
    #
    
    outputOption STte
    
    
    # Invokes the specified program (with the given arguments) whenever a notification
    
    # is received that matches the OID token
    
    traphandle default /bin/bash /usr/sbin/zabbix_trap_handler.sh
    Could any one throw me a bone here and point me in the right direction please.


    Attached Files
  • AdamR
    Junior Member
    • Oct 2021
    • 6

    #2
    For those who end up in the same situation the answer is selinux context. You need to append "z" option to the shares that
    both zabbix server and snmp traps access together with couple minor changes to adjust docker instructions to podman accross all contaioners.

    So

    podman run --name zabbix-snmptraps -t \
    -v /zbx_instance/snmptraps:/var/lib/zabbix/snmptraps:rw \
    -v /var/lib/zabbix/mibs:/usr/share/snmp/mibs:ro \
    --network=zabbix-net \
    -p 162:1162/udp \
    --restart unless-stopped \
    -d zabbix/zabbix-snmptraps:alpine-5.4-latest


    podman run --name zabbix-server-pgsql -t \
    -e DB_SERVER_HOST="192.168.70.15" \
    -e POSTGRES_USER="zabbix" \
    -e POSTGRES_PASSWORD="zabbix" \
    -e POSTGRES_DB="zabbix2" \
    -e ZBX_ENABLE_SNMP_TRAPS="true" \
    --network=zabbix-net \
    -p 10051:10051 \
    --volumes-from zabbix-snmptraps \
    --restart unless-stopped \
    -d zabbix/zabbix-server-pgsql:alpine-5.4-latest

    becomes

    podman run --name zabbix-snmptraps -t \
    -v /zbx_instance/snmptraps:/var/lib/zabbix/snmptraps:z \
    -v /var/lib/zabbix/mibs:/usr/share/snmp/mibs:z \
    --pod=zabbix \
    --restart=always \
    -d zabbix/zabbix-snmptraps:alpine-5.4-latest


    podman run --name zabbix-server-pgsql -t \
    -e DB_SERVER_HOST="192.168.70.15" \
    -e POSTGRES_USER="zabbix" \
    -e POSTGRES_PASSWORD="zabbix" \
    -e POSTGRES_DB="zabbix2" \
    -e ZBX_ENABLE_SNMP_TRAPS="true" \
    --pod=zabbix \
    -v /zbx_instance/snmptraps:/var/lib/zabbix/snmptraps:z \
    -v /var/lib/zabbix/mibs:/usr/share/snmp/mibs:z \
    --restart=always \
    -d zabbix/zabbix-server-pgsql:alpine-5.4-latest

    Good luck

    Comment

    • lmonasterio
      Member
      • May 2021
      • 34

      #3
      Hi AdamR! As i understand, you need to modify snmptrapd.conf to accept communities other than public. But how can you do that if you need to persist that file? How can you edit it? Thanks!

      Comment

      • AdamR
        Junior Member
        • Oct 2021
        • 6

        #4
        Originally posted by lmonasterio
        Hi AdamR! As i understand, you need to modify snmptrapd.conf to accept communities other than public. But how can you do that if you need to persist that file? How can you edit it? Thanks!
        You need to redirect configs to your host aka create persistent volumes.

        Comment

        • lmonasterio
          Member
          • May 2021
          • 34

          #5
          Thanks AdamR ! And one more thing... The container does not come with snmtrap bin file. How can i test so?

          Comment

          Working...