Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-10634

change logging "zabbix_trap_receiver.pl" from STDOUT to STDERR

XMLWordPrintable

      In zabbix_trap_receiver.pl (from zabbix sourcers) we have:

      print STDOUT "Loaded Zabbix SNMP trap receiver\n";
      

      in snmptthandler-embedded (from snmptt package) :

      print STDERR "Loaded the SNMPTT embedded snmptrapd handler\n";
      

      Note difference: STDOUT vs STDERR used.

      In the zabbix's script I suggest to change to STDERR as well, see why:

      On my Debian 8 host, when in the zabbix script it's STDOUT:

      # service snmptrapd status
      ? snmptrapd.service - LSB: SNMP Trap daemon
         Loaded: loaded (/etc/init.d/snmptrapd)
         Active: active (running) since Fri 2016-04-08 10:09:09 EEST; 2s ago
        Process: 16661 ExecStart=/etc/init.d/snmptrapd start (code=exited, status=0/SUCCESS)
         CGroup: /system.slice/snmptrapd.service
                 ??16664 /usr/sbin/snmptrapd -Lsd -p /run/snmptrapd.pid
      
      Apr 08 10:09:09 it0 snmptrapd[16663]: NET-SNMP version 5.7.2.1 AgentX subagent connected
      Apr 08 10:09:09 it0 snmptrapd[16664]: NET-SNMP version 5.7.2.1
      Apr 08 10:09:09 it0 snmptrapd[16661]: Starting SNMP trap services::  snmptrapd
      

      when it changed to STDERR:

      # service snmptrapd status
      ? snmptrapd.service - LSB: SNMP Trap daemon
         Loaded: loaded (/etc/init.d/snmptrapd)
         Active: active (running) since Fri 2016-04-08 10:11:05 EEST; 2s ago
        Process: 16807 ExecStart=/etc/init.d/snmptrapd start (code=exited, status=0/SUCCESS)
         CGroup: /system.slice/snmptrapd.service
                 ??16810 /usr/sbin/snmptrapd -Lsd -p /run/snmptrapd.pid
      
      Apr 08 10:11:05 it0 snmptrapd[16807]: Starting SNMP trap services::Loaded Zabbix SNMP trap receiver
      Apr 08 10:11:05 it0 snmptrapd[16809]: NET-SNMP version 5.7.2.1 AgentX subagent connected
      Apr 08 10:11:05 it0 snmptrapd[16810]: NET-SNMP version 5.7.2.1
      Apr 08 10:11:05 it0 snmptrapd[16807]: snmptrapd
      

      In syslog the lines look the same.

      Note how the message is missing/exists.
      The fact that in the snmptt the STDERR is used is also important and I believe it's a good point to be taken into account.

      So, suggested change will provide better logging.
      Note that logging mode for snmptrapd daemon "-Lsd" is default on popular distros like Debian, CentOS.
      "-Lsd" means log to syslog with "daemon" facility.

      Just in case, more examples when load both handlers (when both use STDERR), but with different orders in snmptrapd.conf:

      ORDER:
      perl do "/usr/lib/snmptt/snmptthandler-embedded";
      perl do "/zab/bin/zabbix_trap_receiver.pl";
      
      # service snmptrapd status
      ? snmptrapd.service - LSB: SNMP Trap daemon
         Loaded: loaded (/etc/init.d/snmptrapd)
         Active: active (running) since Fri 2016-04-08 11:17:39 EEST; 1s ago
        Process: 19195 ExecStart=/etc/init.d/snmptrapd start (code=exited, status=0/SUCCESS)
         CGroup: /system.slice/snmptrapd.service
                 ??19198 /usr/sbin/snmptrapd -Lsd -p /run/snmptrapd.pid
      
      Apr 08 11:17:39 it0 snmptrapd[19195]: Starting SNMP trap services::Loaded the SNMPTT embedded snmptrapd handler
      Apr 08 11:17:39 it0 snmptrapd[19195]: Loaded Zabbix SNMP trap receiver
      Apr 08 11:17:39 it0 snmptrapd[19197]: NET-SNMP version 5.7.2.1 AgentX subagent connected
      Apr 08 11:17:39 it0 snmptrapd[19198]: NET-SNMP version 5.7.2.1
      Apr 08 11:17:39 it0 snmptrapd[19195]: snmptrapd
      
      ORDER:
      perl do "/zab/bin/zabbix_trap_receiver.pl";
      perl do "/usr/lib/snmptt/snmptthandler-embedded";
      
      # service snmptrapd status
      ? snmptrapd.service - LSB: SNMP Trap daemon
         Loaded: loaded (/etc/init.d/snmptrapd)
         Active: active (running) since Fri 2016-04-08 10:17:30 EEST; 1s ago
        Process: 17281 ExecStart=/etc/init.d/snmptrapd start (code=exited, status=0/SUCCESS)
         CGroup: /system.slice/snmptrapd.service
                 ??17284 /usr/sbin/snmptrapd -Lsd -p /run/snmptrapd.pid
      
      Apr 08 10:17:30 it0 snmptrapd[17281]: Starting SNMP trap services::Loaded Zabbix SNMP trap receiver
      Apr 08 10:17:30 it0 snmptrapd[17281]: Loaded the SNMPTT embedded snmptrapd handler
      Apr 08 10:17:30 it0 snmptrapd[17283]: NET-SNMP version 5.7.2.1 AgentX subagent connected
      Apr 08 10:17:30 it0 snmptrapd[17284]: NET-SNMP version 5.7.2.1
      Apr 08 10:17:30 it0 snmptrapd[17281]: snmptrapd
      

      In syslog the lines look the same.
      A summary on that: first (or single) loaded handler is located in the same line with "Starting SNMP trap services::" prefix.

            Unassigned Unassigned
            zalex_ua Oleksii Zagorskyi
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: