UDP (om_udp)

This module sends log messages as UDP datagrams to the address and port specified. UDP is the transport protocol of the legacy BSD Syslog standard as described in RFC 3164, so this module can be particularly useful to send messages to devices or Syslog daemons that do not support other transports.

Configuration

The om_udp module accepts the following directives in addition to the common module directives. The Host directive is required.

Required directives

The following directives are required for the module to start.

Host

The module connects to this IP address or hostname. If using a hostname, the module resolves the hostname to an IP address on each new connection.

You can define the port number by appending it to the IP address or hostname using a colon as a separator (host:port). The default port is 514.

IPv6 addresses must be enclosed in square brackets ([addr]:port). For example, [2001:0db8:85a3:0:0:8a2e:0370:7334]:514.

You can define this directive multiple times to connect to multiple hosts or ports in failover mode. Specify IPv4 and IPv6 addresses separately as needed. If you use a DNS name, you should keep the addresses or CNAMEs below 16 to avoid issues caused by DNS response size limits.

If the module is configured with multiple Host directives or a resolver, such as DNS, returns multiple addresses, the module will connect to the first reachable address. The module will remain connected to that address until it is stopped or the connection is severed. DNS changes are therefore not picked up by the module without intervention.

If the connection to an address fails, the module will attempt to connect to the next address until it reaches the end of the set of addresses for the same Host directive. Then, it performs a lookup on the next Host directive, if configured. Once all options are exhausted, the module will start over from the first address of the first Host directive until the connection can be re-established.

Because of the nature of the UDP protocol and how ICMP messages are handled by various network devices, the failover functionality in this module is considered a "best effort". Detecting hosts going offline is not supported. Detecting the receiving service being stopped - while the host stays up is supported.

Optional directives

LocalPort

This optional directive specifies the local port number of the connection. If this is not specified, a random high port number will be used, which is not always ideal in firewalled network environments.

Due to the required TIME-WAIT delay in closing connections, attempts to bind to LocalPort may fail. In such cases, the message Address already in use will be written to nxlog.log. If the situation persists, it could impede network performance.

OutputType

See the OutputType directive in the list of common module directives. If this directive is not specified, the default is Dgram.

Reconnect

This optional directive sets the reconnect interval in seconds. If it is set, the module attempts to reconnect in every defined second. If it is not set, the reconnect interval will start at 1 second and double with every attempt. If the duration of the successful connection is greater than the current reconnect interval, then the reconnect interval will be reset to 1 sec.

The Reconnect directive must be used with caution. If it is used on multiple systems, it can send reconnect requests simultaneously to the same destination, potentially overloading the destination system. It may also cause NXLog Agent to use unusually high system resources or cause NXLog Agent to become unresponsive.

ReconnectOnData

This optional directive defines the behavior when the connection with the remote host is lost. When set to TRUE, the module only attempts to reconnect when it has data to send. The default value is FALSE; it will always keep a connection open with the remote host.

SockBufSize

This optional directive sets the socket buffer size (SO_SNDBUF) to the value specified. If this is not set, the operating system default is used.

Procedures

The following procedures are exported by om_udp.

reconnect();

Force a reconnection. This can be used from a Schedule block to periodically reconnect to the server.

The reconnect() procedure must be used with caution. If configured, it can attempt to reconnect after every event sent, potentially overloading the destination system.

Examples

Example 1. Sending syslog over UDP

This configuration reads log messages from a socket and forwards them via UDP.

nxlog.conf
<Input uds>
    Module  im_uds
    UDS     /dev/log
</Input>

<Output udp>
    Module  om_udp
    Host    192.168.1.1:1514
</Output>

<Route uds_to_udp>
    Path    uds => udp
</Route>
Example 2. Sending logs over UDP with failover

This configuration sends logs via UDP in a failover configuration (multiple Hosts defined).

nxlog.conf
<Output udp>
    Module  om_udp
    Host    192.168.1.2:1514
    Host    192.168.1.3:1514
    Host    example.com:1234
</Output>