The mongodb()
driver sends messages to a MongoDB database. MongoDB is a schema-free, document-oriented database. For the list of available optional parameters, see the section called “mongodb() destination options”.
|
NOTE:
In order to use this destination, syslog-ng Premium Edition must run in server mode. Typically, only the central syslog-ng Premium Edition server uses this destination. For details on the server mode, see the section called “Server mode”. |
Declaration:
mongodb(parameters);
The mongodb()
driver does not support creating indexes, as that can be a very complex operation in MongoDB. If needed, the administrator of the MongoDB database must ensure that indexes are created on the collections.
The mongodb()
driver does not add the _id
field to the message: the MongoDB server will do that automatically, if none is present. If you want to override this field from syslog-ng PE, use the key()
parameter of the value-pairs()
option.
The syslog-ng PE mongodb()
driver is compatible with MongoDB server version 1.4 and newer.
|
NOTE:
By default, syslog-ng PE handles every message field as a string. For details on how to send selected fields as other types of data (for example, handle the PID as a number), see the section called “Specifying data types in value-pairs”. |
Example 7.19. Using the mongodb() driver
The following example creates a mongodb()
destination using only default values.
destination d_mongodb { mongodb(); };
The following example displays the default values, and is equivalent with the previous example.
destination d_mongodb { mongodb( servers("localhost:27017") database("syslog") collection("messages") value-pairs( scope("selected-macros" "nv-pairs" "sdata") ) ); };
Procedure 7.7. How syslog-ng PE connects the MongoDB server
When syslog-ng PE connects the MongoDB server during startup, it completes the following steps.
-
The syslog-ng PE application connects the first address listed in the
servers()
option. -
-
If the server is accessible and it is a master MongoDB server, syslog-ng PE authenticates on the server (if needed), then starts sending the log messages to the server.
-
If the server is not accessible, or it is not a master server in a MongoDB replicaset and it does not send the address of the master server, syslog-ng PE connects the next address listed in the
servers()
option. -
If the server is not a master server in a MongoDB replicaset, but it sends the address of the master server, syslog-ng PE connects the received address.
-
-
When syslog-ng PE connects the master MongoDB server, it retrieves the list of replicas (from the
replSet
option of the server), and appends this list to theservers()
option. -
The syslog-ng PE application attempts to connect another server if the
servers()
list contains at least two addresses, and one of the following events happens:-
The
safe-mode()
option is set tono
, and the MongoDB server becomes unreachable. -
The
safe-mode()
option is set toyes
, and syslog-ng PE cannot insert a log message into the database because of an error.
In such case, syslog-ng PE starts to connect the addresses in from the
servers()
list (starting from the first address) to find the new master server, authenticates on the new server (if needed), then continues to send the log messages to the new master server.During this failover step, one message can be lost if the
safe-mode()
option is disabled. -
-
If the original master becomes accessible again, syslog-ng PE will automatically connect to the original master.
The mongodb()
driver sends messages to a MongoDB database. MongoDB is a schema-free, document-oriented database.
|
NOTE:
In order to use this destination, syslog-ng Premium Edition must run in server mode. Typically, only the central syslog-ng Premium Edition server uses this destination. For details on the server mode, see the section called “Server mode”. |
The mongodb()
destination has the following options:
Type: | string |
Default: | messages |
Description: The name of the MongoDB collection where the log messages are stored (collections are similar to SQL tables). Note that the name of the collection must not start with a dollar sign ($), and that it may contain dot (.) characters.
|
Caution:
Hazard of data loss! The syslog-ng PE application does not verify that the specified collection name does not contain invalid characters. If you specify a collection with an invalid name, the log messages sent to the MongoDB database will be irrevocably lost without any warning. |
Type: | string |
Default: | syslog |
Description: The name of the MongoDB database where the log messages are stored. Note that the name of the database must not start with a dollar sign ($) and it cannot contain dot (.) characters.
|
Caution:
Hazard of data loss! The syslog-ng PE application does not verify that the specified database name does not contain invalid characters. If you specify a database with an invalid name, the log messages sent to the MongoDB database will be irrevocably lost without any warning. |
Description: This option enables putting outgoing messages into the disk buffer of the destination to avoid message loss in case of a system failure on the destination side. It has the following options:
reliable() | |
Type: | yes|no |
Default: | no |
Description: If set to |
disk-buf-size() | |
Type: | number (bytes) |
Default: | |
Description: This is a required option. The maximum size of the disk-buffer in bytes. The minimum value is 1048576 bytes. If you set a smaller value, the minimum value will be used automatically. It replaces the old log-disk-fifo-size() option. |
mem-buf-length() | |
Type: | number (messages) |
Default: | 10000 |
Description: Use this option if the option reliable() is set to no . This option contains the number of messages stored in overflow queue. It replaces the old log-fifo-size() option. It inherits the value of the global log-fifo-size() option if provided. If it is not provided, the default value is 10000 messages. Note that this option will be ignored if the option reliable() is set to yes . |
mem-buf-size() | |
Type: | number (bytes) |
Default: | 163840000 |
Description: Use this option if the option reliable() is set to yes . This option contains the size of the messages in bytes that is used in the memory part of the disk buffer. It replaces the old log-fifo-size() option. It does not inherit the value of the global log-fifo-size() option, even if it is provided. Note that this option will be ignored if the option reliable() is set to no . |
quot-size() | |
Type: | number (messages) |
Default: | 64 |
Description: The number of messages stored in the output buffer of the destination. |
Options reliable()
and disk-buf-size()
are required options.
Example 7.20. Examples for using disk-buffer()
In the following case reliable disk-buffer() is used.
destination d_demo { network( "127.0.0.1" port(3333) disk-buffer( mem-buf-size(10000) disk-buf-size(2000000) reliable(yes) dir("/tmp/disk-buffer") ) ); };
In the following case normal disk-buffer() is used.
destination d_demo { network( "127.0.0.1" port(3333) disk-buffer( mem-buf-length(10000) disk-buf-size(2000000) reliable(no) dir("/tmp/disk-buffer") ) ); };
Type: | number (digits of fractions of a second) |
Default: | Value of the global option (which defaults to 0) |
Description: The syslog-ng application can store fractions of a second in the timestamps according to the ISO8601 format. The frac-digits()
parameter specifies the number of digits stored. The digits storing the fractions are padded by zeros if the original timestamp of the message specifies only seconds. Fractions can always be stored for the time the message was received. Note that syslog-ng can add the fractions to non-ISO8601 timestamps as well.
Type: | name of the timezone, or the timezone offset |
Default: | The local timezone. |
Description: Sets the timezone used when expanding filename and tablename templates.
The timezone can be specified as using the name of the (for example time-zone("Europe/Budapest")
), or as the timezone offset in +/-HH:MM format (for example +01:00
). On Linux and UNIX platforms, the valid timezone names are listed under the /usr/share/zoneinfo
directory.
Type: | number (messages) |
Default: | Use global setting. |
Description: The number of messages that the output queue can store.
Accepted values: | drop-message|drop-property|fallback-to-string|silently-drop-message|silently-drop-property|silently-fallback-to-string |
Default: | Use the global setting (which defaults to drop-message ) |
Description: Controls what happens when type-casting fails and syslog-ng PE cannot convert some data to the specified type. By default, syslog-ng PE drops the entire message and logs the error. Currently the value-pairs()
option uses the settings of on-error()
.
-
drop-message
: Drop the entire message and log an error message to theinternal()
source. This is the default behavior of syslog-ng PE. -
drop-property
: Omit the affected property (macro, template, or message-field) from the log message and log an error message to theinternal()
source. -
fallback-to-string
: Convert the property to string and log an error message to theinternal()
source. -
silently-drop-message
: Drop the entire message silently, without logging the error. -
silently-drop-property
: Omit the affected property (macro, template, or message-field) silently, without logging the error. -
silently-fallback-to-string
: Convert the property to string silently, without logging the error.
Type: | string |
Default: | empty |
Description: If the path()
option is set, syslog-ng PE will connect to the database using the specified UNIX domain socket. Note that you cannot set the path()
and the servers()
options at the same time.
Type: | number (of attempts) |
Default: | 3 |
Description: The number of times syslog-ng PE attempts to send a message to this destination. If syslog-ng PE could not send a message, it will try again until the number of attempts reaches retries
, then drops the message.
For MongoDB operations, syslog-ng PE uses a one-minute timeout: if an operation times out, syslog-ng PE assumes the operation has failed.
Type: | yes or no |
Default: | yes |
Description: If safe-mode()
is enabled, syslog-ng PE performs an extra check after each insert to verify that the insert succeeded. The insert is successful only if this second check is successful.
Note that disabling this option increases the performance of the driver, but can result in message loss. Using safe-mode(yes)
is technically equivalent of using the RLTP™ protocol between syslog-ng PE and the MongoDB server. If you use the reliable(yes)
option of disk-buffer()
in your destinations, make sure that the safe-mode()
option of the mongodb()
destination is set to yes
.
Type: | list of hostname:port pairs |
Default: | 127.0.0.1:27017 |
Description: Specifies the hostname or IP address and the port number of the database server. When specifying an IP address, IPv4 (for example, 192.168.0.1
) or IPv6 (for example, [::1]
) can be used as well.
To send the messages to a MongoDB replicaset, specify the addresses of the database servers as a comma-separated list, for example: servers(192.168.1.1:27017,192.168.3.3:27017)
For details on how syslog-ng PE connects the MongoDB server, see Procedure 7.7, “How syslog-ng PE connects the MongoDB server”.
To connect to the server using a UNIX domain socket, use path option. Note that you cannot set the path()
and the servers()
options at the same time.
Type: | name of the timezone, or the timezone offset |
Default: | unspecified |
Description: Convert timestamps to the timezone specified by this option. If this option is not set, then the original timezone information in the message is used. Converting the timezone changes the values of all date-related macros derived from the timestamp, for example, HOUR
. For the complete list of such macros, see the section called “Date-related macros”.
The timezone can be specified as using the name of the (for example time-zone("Europe/Budapest")
), or as the timezone offset in +/-HH:MM format (for example +01:00
). On Linux and UNIX platforms, the valid timezone names are listed under the /usr/share/zoneinfo
directory.
Type: | string |
Default: | n/a |
Description: Name of the database user. Note that the mongodb()
driver currently does not support TLS-encrypted authentication.
Description: The value-pairs()
option creates structured name-value pairs from the data and metadata of the log message. For details on using value-pairs()
, see the section called “Structuring macros, metadata, and other value-pairs”.
|
NOTE:
Empty keys are not logged. |