The syslog-ng Open Source Edition 3.3 Administrator Guide

This guide is published under the Creative Commons Attribution-Noncommercial-No Derivative Works (by-nc-nd) 3.0 license. The latest version is always available at http://www.balabit.com/support/documentation.

This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit (http://www.openssl.org/). This product includes cryptographic software written by Eric Young (eay@cryptsoft.com)

This documentation and the product it describes are considered protected by copyright according to the applicable laws.

The Zorp™ name and the Zorp™ logo are registered trademarks of BalaBit.

The BalaBit Shell Control Box™ name and the BalaBit Shell Control Box™ logo are registered trademarks of BalaBit.

The syslog-ng™ name and the syslog-ng™ logo are registered trademarks of BalaBit.

The BalaBit™ name and the BalaBit™ logo are registered trademarks of BalaBit.

Linux™ is a registered trademark of Linus Torvalds.

Debian™ is a registered trademark of Software in the Public Interest Inc.

Windows™ 95, 98, ME, 2000, XP, Server 2003, Vista, Server 2008 and 7 are registered trademarks of Microsoft Corporation.

MySQL™ is a registered trademark of Oracle and/or its affiliates.

Oracle™, JD Edwards™, PeopleSoft™, and Siebel™ are registered trademarks of Oracle Corporation and/or its affiliates.

Red Hat™, Inc., Red HatEnterprise Linux™ and Red HatLinux™ are trademarks of Red Hat, Inc.

SUSE™ is a trademark of SUSE AG, a Novell business.

Solaris™ is a registered trademark of Sun Microsystems, Inc.

AIX™, AIX 5L™, AS/400™, BladeCenter™, eServer™, IBM™, the IBM™ logo, IBM System i™, IBM System i5™, IBM System x™, iSeries™, i5/OS™, Netfinity™, NetServer™, OpenPower™, OS/400™, PartnerWorld™, POWER™, ServerGuide™, ServerProven™, and xSeries™ are trademarks or registered trademarks of International Business Machines.

Alliance Log Agent for System i™ is a registered trademark of Patrick Townsend & Associates, Inc.

All other product names mentioned herein are the trademarks of their respective owners.

Some rights reserved.

DISCLAIMER

BalaBit is not responsible for any third-party Web sites mentioned in this document. BalaBit does not endorse and is not responsible or liable for any content, advertising, products, or other material on or available from such sites or resources. BalaBit will not be responsible or liable for any damage or loss caused or alleged to be caused by or in connection with use of or reliance on any such content, goods, or services that are available on or through any such sites or resources.

April 22, 2014

Abstract

This manual is the primary documentation of the syslog-ng Open Source Edition 3.3 application.


Table of Contents

Preface
1. Summary of contents
2. Target audience and prerequisites
3. Products covered in this guide
4. Typographical conventions
5. Contact and support information
5.1. Sales contact
5.2. Support contact
5.3. Training
6. About this document
6.1. Summary of changes
6.2. Feedback
6.3. Acknowledgments
1. Introduction to syslog-ng
1.1. What syslog-ng is
1.2. What syslog-ng is not
1.3. Why is syslog-ng needed?
1.4. What is new in syslog-ng Open Source Edition 3.3?
1.5. Who uses syslog-ng?
1.6. Supported platforms
2. The concepts of syslog-ng
2.1. The philosophy of syslog-ng
2.2. Logging with syslog-ng
2.2.1. The route of a log message in syslog-ng
2.3. Modes of operation
2.3.1. Client mode
2.3.2. Relay mode
2.3.3. Server mode
2.4. Global objects
2.5. Timezones and daylight saving
2.5.1. A note on timezones and timestamps
2.6. Stable and feature releases of syslog-ng OSE
2.7. The license of syslog-ng OSE
2.8. High availability support
2.9. The structure of a log message
2.9.1. BSD-syslog or legacy-syslog messages
2.9.2. IETF-syslog messages
2.9.3. Message representation in syslog-ng OSE
2.9.4. Structuring macros, metadata, and other value-pairs
3. Installing syslog-ng
3.1. Compiling syslog-ng from source
3.2. Uninstalling syslog-ng
3.3. Configuring Microsoft SQL Server to accept logs from syslog-ng
4. The syslog-ng OSE quick-start guide
4.1. Configuring syslog-ng on client hosts
4.2. Configuring syslog-ng on server hosts
4.3. Configuring syslog-ng relays
4.3.1. Configuring syslog-ng on relay hosts
4.3.2. How relaying log messages works
5. The syslog-ng OSE configuration file
5.1. Location of the syslog-ng configuration file
5.2. The configuration syntax in detail
5.3. Notes about the configuration syntax
5.4. Global and environmental variables
5.5. Loading modules
5.5.1. Loading modules
5.6. Managing complex syslog-ng configurations
5.6.1. Including configuration files
5.6.2. Reusing configuration blocks
6. Collecting log messages — sources and source drivers
6.1. How sources work
6.2. Collecting internal messages
6.2.1. internal() source options
6.3. Collecting messages from text files
6.3.1. Notes on reading kernel messages
6.3.2. file() source options
6.4. Collecting messages from named pipes
6.4.1. pipe() source options
6.5. Collecting process accounting logs on Linux
6.5.1. pacct() options
6.6. Receiving messages from external applications
6.6.1. program() source options
6.7. Collecting messages on Sun Solaris
6.7.1. sun-streams() source options
6.8. Collecting messages using the IETF syslog protocol
6.8.1. syslog() source options
6.9. Collecting the system-specific log messages of a platform
6.10. Collecting messages from remote hosts using the BSD syslog protocol
6.10.1. tcp(), tcp6(), udp() and udp6() source options
6.11. Collecting messages from UNIX domain sockets
6.11.1. unix-stream() and unix-dgram() source options
7. Sending and storing log messages — destinations and destination drivers
7.1. Storing messages in plain-text files
7.1.1. file() destination options
7.2. Storing messages in a MongoDB database
7.2.1. mongodb() destination options
7.3. Sending messages to named pipes
7.3.1. pipe() destination options
7.4. Sending messages to external applications
7.4.1. program() destination options
7.5. Storing messages in an SQL database
7.5.1. Using the sql() driver with an Oracle database
7.5.2. Using the sql() driver with a Microsoft SQL database
7.5.3. The way syslog-ng interacts with the database
7.5.4. sql() destination options
7.6. Sending messages to a remote logserver using the IETF-syslog protocol
7.6.1. syslog() destination options
7.7. Sending messages to a remote logserver using the legacy BSD-syslog protocol
7.7.1. tcp(), tcp6(), udp(), and udp6() destination options
7.8. Sending messages to UNIX domain sockets
7.8.1. unix-stream() and unix-dgram() destination options
7.9. Sending messages to a user terminal — usertty() destination
8. Routing messages: log paths and filters
8.1. Log paths
8.1.1. Embedded log statements
8.1.2. Log path flags
8.2. Managing incoming and outgoing messages with flow-control
8.2.1. Flow-control and multiple destinations
8.2.2. Configuring flow-control
8.3. Filters
8.3.1. Using filters
8.3.2. Combining filters with boolean operators
8.3.3. Comparing macro values in filters
8.3.4. Using wildcards, special characters, and regular expressions in filters
8.3.5. Tagging messages
8.3.6. Filter functions
8.4. Dropping messages
9. Global options of syslog-ng OSE
9.1. Configuring global syslog-ng options
9.2. Global options
10. TLS-encrypted message tranfer
10.1. Secure logging using TLS
10.2. Encrypting log messages with TLS
10.2.1. Configuring TLS on the syslog-ng clients
10.2.2. Configuring TLS on the syslog-ng server
10.3. Mutual authentication using TLS
10.3.1. Configuring TLS on the syslog-ng clients
10.3.2. Configuring TLS on the syslog-ng server
10.4. TLS options
11. Manipulating messages
11.1. Customizing message format
11.1.1. Formatting messages, filenames, directories, and tablenames
11.1.2. Templates and macros
11.1.3. Date-related macros
11.1.4. Hard vs. soft macros
11.1.5. Macros of syslog-ng OSE
11.1.6. Using template functions
11.1.7. Template functions of syslog-ng OSE
11.2. Modifying messages
11.2.1. Replacing message parts
11.2.2. Setting message fields to specific values
11.2.3. Creating custom SDATA fields
11.2.4. Conditional rewrites
11.3. Regular expressions
11.3.1. Types and options of regular expressions
11.3.2. Optimizing regular expressions
12. Parsing and segmenting structured messages
12.1. Parsing messages
12.1.1. Options of CSV parsers
13. Processing message content with a pattern database
13.1. Classifying log messages
13.1.1. The structure of the pattern database
13.1.2. How pattern matching works
13.1.3. Artificial ignorance
13.2. Using pattern databases
13.2.1. Using parser results in filters and templates
13.2.2. Downloading sample pattern databases
13.3. Correlating log messages
13.3.1. Referencing earlier messages of the context
13.4. Triggering actions for identified messages
13.4.1. Conditional actions
13.4.2. External actions
13.4.3. Actions and message correlation
13.5. Creating pattern databases
13.5.1. Using pattern parsers
13.5.2. What's new in the syslog-ng pattern database format V4
13.5.3. The syslog-ng pattern database format
14. Statistics of syslog-ng
15. Multithreading and scaling in syslog-ng OSE
15.1. Multithreading concepts of syslog-ng OSE
15.2. Configuring multithreading
15.3. Optimizing multithreaded performance
16. Troubleshooting syslog-ng
16.1. Possible causes of losing log messages
16.2. Creating syslog-ng core files
16.3. Collecting debugging information with strace, truss, or tusc
16.4. Running a failure script
16.5. Stopping syslog-ng
17. Best practices and examples
17.1. General recommendations
17.2. Handling lots of parallel connections
17.3. Handling large message load
17.4. Using name resolution in syslog-ng
17.4.1. Resolving hostnames locally
17.5. Collecting logs from chroot
1. The syslog-ng manual pages
loggen — Generate syslog messages at a specified rate
pdbtool — An application to test and convert syslog-ng pattern database rules
syslog-ng — syslog-ng system logger application
syslog-ng.conf — syslog-ng configuration file
syslog-ng-ctl — Display message statistics and enable verbose, debug and trace modes in syslog-ng Open Source Edition
2. GNU Lesser General Public License
2.1. Preamble
2.2. TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
2.2.1. Section 0
2.2.2. Section 1
2.2.3. Section 2
2.2.4. Section 3
2.2.5. Section 4
2.2.6. Section 5
2.2.7. Section 6
2.2.8. Section 7
2.2.9. Section 8
2.2.10. Section 9
2.2.11. Section 10
2.2.12. Section 11
2.2.13. Section 12
2.2.14. Section 13
2.2.15. Section 14
2.2.16. NO WARRANTY Section 15
2.2.17. Section 16
2.3. How to Apply These Terms to Your New Libraries
3. GNU General Public License
3.1. Preamble
3.2. TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
3.2.1. Section 0
3.2.2. Section 1
3.2.3. Section 2
3.2.4. Section 3
3.2.5. Section 4
3.2.6. Section 5
3.2.7. Section 6
3.2.8. Section 7
3.2.9. Section 8
3.2.10. Section 9
3.2.11. Section 10
3.2.12. NO WARRANTY Section 11
3.2.13. Section 12
3.3. How to Apply These Terms to Your New Programs
4. Creative Commons Attribution Non-commercial No Derivatives (by-nc-nd) License
Glossary
List of syslog-ng OSE parameters
Index

List of Examples

2.1. Using the value-pairs() option
4.1. The default configuration file of syslog-ng OSE
4.2. A simple configuration for clients
4.3. A simple configuration for servers
4.4. A simple configuration for relays
5.1. A simple configuration file
5.2. Using required and optional parameters
5.3. Using global variables
5.4. Reusing configuration blocks
5.5. Defining blocks with multiple elements
5.6. Passing arguments to blocks
5.7. Using arguments in blocks
6.1. A simple source statement
6.2. A source statement using two source drivers
6.3. Setting default priority and facility
6.4. Source statement on a Linux based operating system
6.5. Using the internal() driver
6.6. Using the file() driver
6.7. Tailing files
6.8. Initial window size of a connection
6.9. Using the pipe() driver
6.10. Initial window size of a connection
6.11. Using the program() driver
6.12. Initial window size of a connection
6.13. Using the sun-streams() driver
6.14. Initial window size of a connection
6.15. Using the syslog() driver
6.16. Initial window size of a connection
6.17. Using the udp() and tcp() drivers
6.18. Initial window size of a connection
6.19. Using the unix-stream() and unix-dgram() drivers
6.20. Initial window size of a connection
7.1. A simple destination statement
7.2. Using the file() driver
7.3. Using the file() driver with macros in the file name and a template for the message
7.4. Using the mongodb() driver
7.5. Using the pipe() driver
7.6. Using the program() destination driver
7.7. Using the sql() driver
7.8. Using the sql() driver with an Oracle database
7.9. Using the sql() driver with an MSSQL database
7.10. Setting flags for SQL destinations
7.11. Using SQL NULL values
7.12. Value: default
7.13. Using the syslog() driver
7.14. Using the tcp() driver
7.15. Using the unix-stream() driver
7.16. Using the usertty() driver
8.1. A simple log statement
8.2. Using embedded log paths
8.3. Using log path flags
8.4. Sizing parameters for flow-control
8.5. A simple filter statement
8.6. Comparing macro values in filters
8.7. Filtering with widcards
8.8. Adding tags and filtering messages with tags
8.9. Skipping messages
9.1. Using global options
10.1. A destination statement using TLS
10.2. A source statement using TLS
10.3. Disabling mutual authentication
10.4. A destination statement using mutual authentication
10.5. A source statement using TLS
11.1. Using templates and macros
11.2. Using SDATA macros
11.3. Using the format-json template function
11.4. Using the grep template function
11.5. Using pattern databases and the if template function
11.6. Using the indent-multi-line template function
11.7. Using substitution rules
11.8. Setting message fields to a particular value
11.9. Rewriting custom SDATA fields
11.10. Using conditional rewriting
11.11. Using Posix regular expressions
11.12. Using PCRE regular expressions
11.13. Optimizing regular expressions in filters
12.1. Segmenting hostnames separated with a dash
12.2. Parsing Apache log files
12.3. Segmenting a part of a message
12.4. Adding the end of the message to the last column
13.1. Defining pattern databases
13.2. Using classification results
13.3. Using classification results for filtering messages
13.4. Using pattern parsers as macros
13.5. How syslog-ng OSE calculates context-timeout
13.6. Using message correlation
13.7. Sending triggered messages to the internal() source
13.8. Generating messages for pattern database matches
13.9. Sending triggered messages to external applications
13.10. Pattern parser syntax
13.11. Using the STRING and ESTRING parsers
13.12. A V4 pattern database containing a single rule
15.1. Enabling multithreading
1.1. Using required and optional parameters

List of Procedures

2.2.1. The route of a log message in syslog-ng
3.1. Compiling syslog-ng from source
3.3. Configuring Microsoft SQL Server to accept logs from syslog-ng
4.1. Configuring syslog-ng on client hosts
4.2. Configuring syslog-ng on server hosts
4.3.1. Configuring syslog-ng on relay hosts
10.2.1. Configuring TLS on the syslog-ng clients
10.2.2. Configuring TLS on the syslog-ng server
10.3.1. Configuring TLS on the syslog-ng clients
10.3.2. Configuring TLS on the syslog-ng server
16.2. Creating syslog-ng core files
17.4.1. Resolving hostnames locally
17.5. Collecting logs from chroot

Preface

Welcome to the syslog-ng Open Source Edition 3.3 Administrator Guide!

This document describes how to configure and manage syslog-ng. Background information for the technology and concepts used by the product is also discussed.

1. Summary of contents

Chapter 1, Introduction to syslog-ng describes the main functionality and purpose of syslog-ng OSE.

Chapter 2, The concepts of syslog-ng discusses the technical concepts and philosophies behind syslog-ng OSE.

Chapter 3, Installing syslog-ng describes how to install syslog-ng OSE on various UNIX-based platforms using the precompiled binaries.

Chapter 4, The syslog-ng OSE quick-start guide provides a briefly explains how to perform the most common log collecting tasks with syslog-ng OSE.

Chapter 5, The syslog-ng OSE configuration file discusses the configuration file format and syntax in detail, and explains how to manage large-scale configurations using included files and reusable configuration snippets.

Chapter 6, Collecting log messages — sources and source drivers explains how to collect and receive log messages from various sources.

Chapter 7, Sending and storing log messages — destinations and destination drivers describes the different methods to store and forward log messages.

Chapter 8, Routing messages: log paths and filters explains how to route and sort log messages, and how to use filters to select specific messages.

Chapter 9, Global options of syslog-ng OSE lists the global options of syslog-ng OSE and explains how to use them.

Chapter 10, TLS-encrypted message tranfer shows how to secure and authenticate log transport using TLS encryption.

Chapter 11, Manipulating messages describes how to customize message format using templates and macros, how to rewrite and modify messages, and how to use regular expressions.

Chapter 12, Parsing and segmenting structured messages describes how to segment and process structured messages like comma-separated values.

Chapter 13, Processing message content with a pattern database explains how to identify and process log messages using a pattern database.

Chapter 14, Statistics of syslog-ng details the available statistics that syslog-ng OSE collects about the processed log messages.

Chapter 15, Multithreading and scaling in syslog-ng OSE describes how to configure syslog-ng OSE to use multiple processors, and how to optimize its performance.

Chapter 16, Troubleshooting syslog-ng offers tips to solving problems.

Chapter 17, Best practices and examples gives recommendations to configure special features of syslog-ng.

Appendix 1, The syslog-ng manual pages contains the manual pages of the syslog-ng OSE application.

Appendix 2, GNU Lesser General Public License includes the text of the LGPLv2.1 license applicable to the core of syslog-ng Open Source Edition.

Appendix 3, GNU General Public License includes the text of the GPLv2 license applicable to syslog-ng Open Source Edition.

Appendix 4, Creative Commons Attribution Non-commercial No Derivatives (by-nc-nd) License includes the text of the Creative Commons Attribution Non-commercial No Derivatives (by-nc-nd) License applicable to The syslog-ng Open Source Edition 3.3 Administrator Guide.

Glossary provides definitions of important terms used in this guide.

List of syslog-ng OSE parameters provides cross-references to the definitions of options, parameters, and macros available in syslog-ng OSE.

Index provides cross-references to important terms used in this guide.

2. Target audience and prerequisites

This guide is intended for system administrators and consultants responsible for designing and maintaining logging solutions and log centers. It is also useful for IT decision makers looking for a tool to implement centralized logging in heterogeneous environments.

The following skills and knowledge are necessary for a successful syslog-ng administrator:

  • At least basic system administration knowledge.

  • An understanding of networks, TCP/IP protocols, and general network terminology.

  • Working knowledge of the UNIX or Linux operating system.

  • In-depth knowledge of the logging process of various platforms and applications.

  • An understanding of the legacy syslog (BSD-syslog) protocol) and the new syslog (IETF-syslog) protocol) standard.

3. Products covered in this guide

This guide describes the use of the following syslog-ng version:

  • syslog-ng Open Source Edition (syslog-ng OSE) 3.3.0 and later

4. Typographical conventions

Before you start using this guide, it is important to understand the terms and typographical conventions used in the documentation. For more information on specialized terms and abbreviations used in the documentation, see the Glossary at the end of this document.

The following kinds of text formatting and icons identify special information in the document.

[Tip] Tip

Tips provide best practices and recommendations.

[Note] Note

Notes provide additional information on a topic, and emphasize important facts and considerations.

[Warning] Warning

Warnings mark situations where loss of data or misconfiguration of the device is possible if the instructions are not obeyed.

Command

Commands you have to execute.

Emphasis

Reference items, additional readings.

/path/to/file

File names.

Parameters

Parameter and attribute names.

Label

GUI output messages or dialog labels.

Menu

A submenu or menu item in the menu bar.

Button

Buttons in dialog windows.

5. Contact and support information

This product is developed and maintained by BalaBit IT Security Ltd. We are located in Budapest, Hungary. Our address is:


         BalaBit IT Security Ltd.
         2 Alíz Street
         H-1117 BudapestHungary
         Tel: +36 1 398-6700
         Fax: +36 1 208-0875
         E-mail: 
         Web: http://www.balabit.com/
       

5.1. Sales contact

You can directly contact us with sales related topics at the e-mail address , or leave us your contact information and we call you back.

5.2. Support contact

In case you experience a problem that is not covered in this guide, visit the syslog-ng wiki or post it on syslog-ng mailing list.

To report bugs found in syslog-ng OSE, visit this page.

Precompiled binary packages are available for free from various third-parties. Most of these are listed on the syslog-ng website.

[Note] Note

BalaBit offers a Premium Edition of syslog-ng and a log management appliance syslog-ng Store Box for which professional support is available. For more information on which syslog-ng product version meets your needs contact our sales department at .

For other products of BalaBit visit http://www.balabit.com/.

5.3. Training

BalaBit IT Security Ltd. holds courses on using its products for new and experienced users. For dates, details, and application forms, visit the http://www.balabit.com/support/trainings/ webpage.

6. About this document

This guide is a work-in-progress document with new versions appearing periodically.

The latest version of this document can be downloaded from the BalaBit website here.

6.1. Summary of changes

6.1.1. Version 3.3 -

Changes in documentation: 

6.1.2. Version 3.2 - 3.3

Changes in product: 

Changes in documentation: 

6.1.3. Version 3.1 - 3.2

Changes in product: 

Changes in documentation: 

  • The contents of the guide have been updated for syslog-ng Open Source Edition 3.3.

  • The structure of the document has changed significantly; several important topics and feature descriptions were moved to their own chapters. These chapters contain most (if not all) the information related to the feature, including concepts, configuration, and reference.

  • Many other clarifications, corrections, reordering of sections, and other changes too numerous to list.

6.2. Feedback

Any feedback is greatly appreciated. General comments, errors found in the text, and any suggestions about how to improve the documentation is welcome at .

6.3. Acknowledgments

BalaBit would like to express its gratitude to the syslog-ng users and the syslog-ng community for their invaluable help and support, including the community members listed at syslog-ng Community Page.

Chapter 1. Introduction to syslog-ng

This chapter introduces the syslog-ng Open Source Edition application in a non-technical manner, discussing how and why is it useful, and the benefits it offers to an existing IT infrastructure.

1.1. What syslog-ng is

The syslog-ng application is a flexible and highly scalable system logging application that is ideal for creating centralized and trusted logging solutions. The main features of syslog-ng are summarized below.

  • Reliable log transfer: The syslog-ng application enables you to send the log messages of your hosts to remote servers using the latest protocol standards. The logs of different servers can be collected and stored centrally on dedicated log servers. Transferring log messages using the TCP protocol ensures that no messages are lost.

  • Secure logging using TLS: Log messages may contain sensitive information that should not be accessed by third parties. Therefore, syslog-ng supports the Transport Layer Security (TLS) protocol to encrypt the communication. TLS also allows the mutual authentication of the host and the server using X.509 certificates.

  • Direct database access: Storing your log messages in a database allows you to easily search and query the messages and interoperate with log analyzing applications. The syslog-ng application supports the following databases: MSSQL, MySQL, Oracle, PostgreSQL, and SQLite.

  • Heterogeneous environments: The syslog-ng application is the ideal choice to collect logs in massively heterogeneous environments using several different operating systems and hardware platforms, including Linux, Unix, BSD, Sun Solaris, HP-UX, Tru64, and AIX.

  • Filter and classify: The syslog-ng application can sort the incoming log messages based on their content and various parameters like the source host, application, and priority. Directories, files, and database tables can be created dynamically using macros. Complex filtering using regular expressions and boolean operators offers almost unlimited flexibility to forward only the important log messages to the selected destinations.

  • Parse and rewrite: The syslog-ng application can segment log messages to named fields or columns, and also modify the values of these fields.

  • IPv4 and IPv6 support: The syslog-ng application can operate in both IPv4 and IPv6 network environments; it can receive and send messages to both types of networks.

1.2. What syslog-ng is not

The syslog-ng application is not log analysis software. It can filter log messages and select only the ones matching certain criteria. It can even convert the messages and restructure them to a predefined format, or parse the messages and segment them into different fields. But syslog-ng cannot interpret and analyze the meaning behind the messages, or recognize patterns in the occurrence of different messages.

1.3. Why is syslog-ng needed?

Log messages contain information about the events happening on the hosts. Monitoring system events is essential for security and system health monitoring reasons.

The original syslog protocol separates messages based on the priority of the message and the facility sending the message. These two parameters alone are often inadequate to consistently classify messages, as many applications might use the same facility — and the facility itself is not even included in the log message. To make things worse, many log messages contain unimportant information. The syslog-ng application helps you to select only the really interesting messages, and forward them to a central server.

Company policies or other regulations often require log messages to be archived. Storing the important messages in a central location greatly simplifies this process.

For details on how can you use syslog-ng to comply with various regulations, see the Regulatory compliance and system logging whitepaper available here

1.4. What is new in syslog-ng Open Source Edition 3.3?

Version 3.3 of syslog-ng Open Source Edition includes the following main features:

1.5. Who uses syslog-ng?

The syslog-ng application is used worldwide by companies and institutions who collect and manage the logs of several hosts, and want to store them in a centralized, organized way. Using syslog-ng is particularly advantageous for:

  • Internet Service Providers;

  • Financial institutions and companies requiring policy compliance;

  • Server, web, and application hosting companies;

  • Datacenters;

  • Wide area network (WAN) operators;

  • Server farm administrators.

The following is a list of public references — companies who use syslog-ng in their production environment:

1.6. Supported platforms

The syslog-ng Open Source Edition application is highly portable and is known to run on a wide range of hardware architectures (x86, x86_64, SUN Sparc, PowerPC 32 and 64, Alpha) and operating systems, including Linux, BSD, Solaris, IBM AIX, HP-UX, Mac OS X, Cygwin, Tru64, and others.

  • The source code of syslog-ng Open Source Edition is released under the GPLv2 license and is available here.

  • Precompiled binary packages provided by BalaBit are available for free for the supported Linux and BSD platforms here.

  • For syslog-ng Open Source Edition packages for Solaris 8-10, visit this page

  • For syslog-ng Open Source Edition packages for IBM AIX 5 and later, visit this page

  • For syslog-ng Open Source Edition packages for HP-UX, visit this page

  • For syslog-ng Open Source Edition packages for Mac OS X, visit this page

  • Packages for routers running OpenWRT or a similar embedded Linux distribution are available here

Chapter 2. The concepts of syslog-ng

This chapter discusses the technical concepts of syslog-ng.

2.1. The philosophy of syslog-ng

Typically, syslog-ng is used to manage log messages and implement centralized logging, where the aim is to collect the log messages of several devices on a single, central log server. The different devices — called syslog-ng clients — all run syslog-ng, and collect the log messages from the various applications, files, and other sources. The clients send all important log messages to the remote syslog-ng server, where the server sorts and stores them.

2.2. Logging with syslog-ng

The syslog-ng application reads incoming messages and forwards them to the selected destinations. The syslog-ng application can receive messages from files, remote hosts, and other sources.

Log messages enter syslog-ng in one of the defined sources, and are sent to one or more destinations.

Sources and destinations are independent objects; log paths define what syslog-ng does with a message, connecting the sources to the destinations. A log path consists of one or more sources and one or more destinations; messages arriving from a source are sent to every destination listed in the log path. A log path defined in syslog-ng is called a log statement.

Optionally, log paths can include filters. Filters are rules that select only certain messages, for example, selecting only messages sent by a specific application. If a log path includes filters, syslog-ng sends only the messages satisfying the filter rules to the destinations set in the log path.

Other optional elements that can appear in log statements are parsers and rewriting rules. Parsers segment messages into different fields to help processing the messages, while rewrite rules modify the messages by adding, replacing, or removing parts of the messages.

2.2.1. Procedure – The route of a log message in syslog-ng

Purpose: 

The following procedure illustrates the route of a log message from its source on the syslog-ng client to its final destination on the central syslog-ng server.

The route of a log message

Figure 2.1. The route of a log message


Steps: 

  1. A device or application sends a log message to a source on the syslog-ng client. For example, an Apache web server running on Linux enters a message into the /var/log/apache file.

  2. The syslog-ng client running on the web server reads the message from its /var/log/apache source.

  3. The syslog-ng client processes the first log statement that includes the /var/log/apache source.

  4. The syslog-ng client performs optional operations (message filtering, parsing, and rewriting) on the message; for example, it compares the message to the filters of the log statement (if any). If the message complies with all filter rules, syslog-ng sends the message to the destinations set in the log statement, for example, to the remote syslog-ng server.

    [Warning] Warning

    Message filtering, parsing, and rewriting is performed in the order that the operations appear in the log statement.

    [Note] Note

    The syslog-ng client sends a message to all matching destinations by default. As a result, a message may be sent to a destination more than once, if the destination is used in multiple log statements. To prevent such situations, use the final flag in the destination statements. For details, see Table 8.1, Log statement flags.

  5. The syslog-ng client processes the next log statement that includes the /var/log/apache source, repeating Steps 3-4.

  6. The message sent by the syslog-ng client arrives from a source set in the syslog-ng server.

  7. The syslog-ng server reads the message from its source and processes the first log statement that includes that source.

  8. The syslog-ng server performs optional operations (message filtering, parsing, and rewriting) on the message; for example, it compares the message to the filters of the log statement (if any). If the message complies with all filter rules, syslog-ng sends the message to the destinations set in the log statement.

    [Warning] Warning

    Message filtering, parsing, and rewriting is performed in the order that the operations appear in the log statement.

  9. The syslog-ng server processes the next log statement, repeating Steps 7-9.

[Note] Note

The syslog-ng application can stop reading messages from its sources if the destinations cannot process the sent messages. This feature is called flow-control and is detailed in Section 8.2, Managing incoming and outgoing messages with flow-control.

2.3. Modes of operation

The syslog-ng Open Source Edition application has three typical operation scenarios: Client, Server, and Relay.

2.3.1. Client mode

Client-mode operation

Figure 2.2. Client-mode operation


In client mode, syslog-ng collects the local logs generated by the host and forwards them through a network connection to the central syslog-ng server or to a relay. Clients often also log the messages locally into files.

2.3.2. Relay mode

Relay-mode operation

Figure 2.3. Relay-mode operation


In relay mode, syslog-ng receives logs through the network from syslog-ng clients and forwards them to the central syslog-ng server using a network connection. Relays also log the messages from the relay host into a local file, or forward these messages to the central syslog-ng server.

2.3.3. Server mode

Server-mode operation

Figure 2.4. Server-mode operation


In server mode, syslog-ng acts as a central log-collecting server. It receives messages from syslog-ng clients and relays over the network, and stores them locally in files, or passes them to other applications, for example log analyzers.

2.4. Global objects

The syslog-ng application uses the following objects:

  • Source driver: A communication method used to receive log messages. For example, syslog-ng can receive messages from a remote host via TCP/IP, or read the messages of a local application from a file.

  • Source: A named collection of configured source drivers.

  • Destination driver: A communication method used to send log messages. For example, syslog-ng can send messages to a remote host via TCP/IP, or write the messages into a file or database.

  • Destination: A named collection of configured destination drivers.

  • Filter: An expression to select messages. For example, a simple filter can select the messages received from a specific host.

  • Macro: An identifier that refers to a part of the log message. For example, the $HOST macro returns the name of the host that sent the message. Macros are often used in templates and filenames.

  • Parser: A rule that segments messages into separate columns at a predefined separator character (for example a comma). Every column has a unique name that can be used as a macro.

  • Rewrite rule: A rule modifies a part of the message, for example, replaces a string, or sets a field to a specified value.

  • Log paths: A combination of sources, destinations, and other objects like filters, parsers, and rewrite rules. The syslog-ng application sends messages arriving from the sources of the log paths to the defined destinations, and performs filtering, parsing, and rewriting of the messages. Log paths are also called log statements. Log statements can include other (embedded) log statements to create complex log paths.

  • Template: A template is a set of macros that can be used to restructure log messages or automatically generate file names. For example, a template can add the hostname and the date to the beginning of every log message.

  • Option: Options set global parameters of syslog-ng, like the parameters of name resolution and timezone handling.

For details on the above objects, see Section 5.2, The configuration syntax in detail.

2.5. Timezones and daylight saving

The syslog-ng application receives the timezone and daylight saving information from the operating system it is installed on. If the operating system handles daylight saving correctly, so does syslog-ng.

The syslog-ng application supports messages originating from different timezones. The original syslog protocol (RFC3164) does not include timezone information, but syslog-ng provides a solution by extending the syslog protocol to include the timezone in the log messages. The syslog-ng application also enables administrators to supply timezone information for legacy devices which do not support the protocol extension.

Timezone information is associated with messages entering syslog-ng is selected using the following algorithm:

  1. The sender application (for example the syslog-ng client) or host specifies the timezone of the messages. If the incoming message includes a timezone it is associated with the message. Otherwise, the local timezone is assumed.

  2. Specify the time_zone() parameter for the source driver that reads the message. This timezone will be associated with the messages only if no timezone is specified within the message itself. Each source defaults to the value of the recv_time_zone() global option. It is not possible to override only the timezone information of the incoming message; but setting the keep-timestamp() option to no allows syslog-ng OSE to replace the full timestamp (timezone included) with the time the message was received.

    [Note] Note

    When processing a message that does not contain timezone information, the syslog-ng OSE application will use the timezone and daylight-saving that was effective when the timestamp was generated. For example, the current time is 2011-03-11 (March 11, 2011) in the EU/Budapest timezone. When daylight-saving is active (summertime), the offset is +02:00. When daylight-saving is inactive (wintertime) the timezone offset is +01:00. If the timestamp of an incoming message is 2011-01-01, the timezone associated with the message will be +01:00, but the timestamp will be converted, because 2011-01-01 meant winter time when daylight saving is not active but the current timezone is +02:00.

  3. Specify the timezone in the destination driver using the time_zone() parameter. Each destination driver might have an associated timezone value; syslog-ng converts message timestamps to this timezone before sending the message to its destination (file or network socket). Each destination defaults to the value of the send_time_zone() global option.

    [Note] Note

    A message can be sent to multiple destination zones. The syslog-ng application converts the timezone information properly for every individual destination zone.

    [Warning] Warning

    If syslog-ng OSE sends the message is to the destination using the legacy-syslog protocol (RFC3164) which does not support timezone information in its timestamps, the timezone information cannot be encapsulated into the sent timestamp, so syslog-ng OSE will convert the hour:min values based on the explicitly specified timezone.

  4. If the timezone is not specified, the message is left unchanged.

  5. When macro expansions are used in the destination filenames, the local timezone is used.

2.5.1. A note on timezones and timestamps

If the clients run syslog-ng, then use the ISO timestamp, because it includes timezone information. That way you do not need to adjust the recv_time_zone() parameter of syslog-ng.

If you want syslog-ng to output timestamps in Unix (POSIX) time format, use the S_UNIXTIME and R_UNIXTIME macros. You do not need to change any of the timezone related parameters, because the timestamp information of incoming messages is converted to Unix time internally, and Unix time is a timezone-independent time representation. (Actually, Unix time measures the number of seconds elapsed since midnight of Coordinated Universal Time (UTC) January 1, 1970, but does not count leap seconds.)

2.6. Stable and feature releases of syslog-ng OSE

As of October 2009, the following release policy applies to syslog-ng Open Source Edition:

  • Stable versions, denoted by a two-digit version number ending with .0 (for example 2.0 or 3.0): Stable branches are supported for at least 1 year, but no more than 2 stable versions of a product are supported at a time. Maintenance releases to the stable branch contain only bugfixes.

  • Feature versions, denoted by two-digit version number ending with a non-zero version number (for example 3.1, 3.2 and onwards): Feature branches contain enhancements and new features, usually 1-3 new features per release. Only the last of the feature releases is supported (for example when a new feature release comes out, the last one becomes unsupported), and the last feature release becomes the new stable release.

[Note] Note

Releases of the feature branch are tested just like the stable releases; they are not "unstable" development snapshots. The difference between earlier major releases and current feature releases is the smaller number of features contained in a release, and the shorter support periods. If an unstable snapshot or alpha/beta/rc release is released for public testing, it is always marked explicitly as such.

[Warning] Warning

Downgrading from a feature release to an earlier (and thus unsupported) feature release, or to the stable release is officially not supported, but usually works as long as your syslog-ng OSE configuration file is appropriate for the old syslog-ng OSE version. However, persistent data like the position of the last processed message in a file source will be probably lost.

2.7. The license of syslog-ng OSE

Starting with version 3.2, the syslog-ng Open Source Edition application is licensed under a combined LGPL+GPL license. The core of syslog-ng OSE is licensed under the GNU Lesser General Public License Version 2.1 license, while the rest of the codebase is licensed under the GNU General Public License Version 2 license.

[Note] Note

Practically, the code stored under the lib directory of the source code package is under LGPL, the rest is GPL.

For details about the LGPL and GPL licenses, see Appendix 2, GNU Lesser General Public License and Appendix 3, GNU General Public License, respectively.

2.8. High availability support

Multiple syslog-ng servers can be run in fail-over mode. The syslog-ng application does not include any internal support for this, as clustering support must be implemented on the operating system level. A tool that can be used to create UNIX clusters is Heartbeat (for details, see this page).

2.9. The structure of a log message

The following sections describe the structure of log messages. Currently there are two standard syslog message formats:

2.9.1. BSD-syslog or legacy-syslog messages

This section describes the format of a syslog message, according to the legacy-syslog or BSD-syslog protocol). A syslog message consists of the following parts:

The total message cannot be longer than 1024 bytes.

The following is a sample syslog message: <133>Feb 25 14:09:07 webserver syslogd: restart. The message corresponds to the following format: <priority>timestamp hostname application: message. The different parts of the message are explained in the following sections.

[Note] Note

The syslog-ng application supports longer messages as well. For details, see the log_msg_size() option in Section 9.2, Global options. However, it is not recommended to enable messages larger than the packet size when using UDP destinations.

2.9.1.1. The PRI message part

The PRI part of the syslog message (known as Priority value) represents the Facility and Severity of the message. Facility represents the part of the system sending the message, while severity marks its importance. The Priority value is calculated by first multiplying the Facility number by 8 and then adding the numerical value of the Severity. The possible facility and severity values are presented below.

[Note] Note

Facility codes may slightly vary between different platforms. The syslog-ng application accepts facility codes as numerical values as well.

Numerical Code Facility
0 kernel messages
1 user-level messages
2 mail system
3 system daemons
4 security/authorization messages
5 messages generated internally by syslogd
6 line printer subsystem
7 network news subsystem
8 UUCP subsystem
9 clock daemon
10 security/authorization messages
11 FTP daemon
12 NTP subsystem
13 log audit
14 log alert
15 clock daemon
16-23 locally used facilities (local0-local7)

Table 2.1. syslog Message Facilities


The following table lists the severity values.

Numerical Code Severity
0 Emergency: system is unusable
1 Alert: action must be taken immediately
2 Critical: critical conditions
3 Error: error conditions
4 Warning: warning conditions
5 Notice: normal but significant condition
6 Informational: informational messages
7 Debug: debug-level messages

Table 2.2. syslog Message Severities


2.9.1.2. The HEADER message part

The HEADER part contains a timestamp and the hostname (without the domain name) or the IP address of the device. The timestamp field is the local time in the Mmm dd hh:mm:ss format, where:

  • Mmm is the English abbreviation of the month: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec.

  • dd is the day of the month on two digits. If the day of the month is less than 10, the first digit is replaced with a space. (For example Aug 7.)

  • hh:mm:ss is the local time. The hour (hh) is represented in a 24-hour format. Valid entries are between 00 and 23, inclusive. The minute (mm) and second (ss) entries are between 00 and 59 inclusive.

[Note] Note

The syslog-ng application supports other timestamp formats as well, like ISO, or the PIX extended format. For details, see the ts_format() option in Section 9.2, Global options.

2.9.1.3. The MSG message part

The MSG part contains the name of the program or process that generated the message, and the text of the message itself. The MSG part is usually in the following format: program[pid]: message text.

2.9.2. IETF-syslog messages

This section describes the format of a syslog message, according to the IETF-syslog protocol).A syslog message consists of the following parts:

The following is a sample syslog message:[1]

<34>1 2003-10-11T22:14:15.003Z mymachine.example.com su - ID47 - BOM'su root' failed for lonvick on /dev/pts/8

The message corresponds to the following format:

<priority>VERSION ISOTIMESTAMP HOSTNAME APPLICATION PID MESSAGEID STRUCTURED-DATA MSG

In this example, the Facility has the value of 4, severity is 2, so PRI is 34. The VERSION is 1. The message was created on 11 October 2003 at 10:14:15pm UTC, 3 milliseconds into the next second. The message originated from a host that identifies itself as "mymachine.example.com". The APP-NAME is "su" and the PROCID is unknown. The MSGID is "ID47". The MSG is "'su root' failed for lonvick...", encoded in UTF-8. The encoding is defined by the BOM[2]. There is no STRUCTURED-DATA present in the message, this is indicated by "-" in the STRUCTURED-DATA field. The MSG is "'su root' failed for lonvick...".

The HEADER part of the message must be in plain ASCII format, the parameter values of the STRUCTURED-DATA part must be in UTF-8, while the MSG part should be in UTF-8. The different parts of the message are explained in the following sections.

2.9.2.1. The PRI message part

The PRI part of the syslog message (known as Priority value) represents the Facility and Severity of the message. Facility represents the part of the system sending the message, while severity marks its importance. The Priority value is calculated by first multiplying the Facility number by 8 and then adding the numerical value of the Severity. The possible facility and severity values are presented below.

[Note] Note

Facility codes may slightly vary between different platforms. The syslog-ng application accepts facility codes as numerical values as well.

Numerical Code Facility
0 kernel messages
1 user-level messages
2 mail system
3 system daemons
4 security/authorization messages
5 messages generated internally by syslogd
6 line printer subsystem
7 network news subsystem
8 UUCP subsystem
9 clock daemon
10 security/authorization messages
11 FTP daemon
12 NTP subsystem
13 log audit
14 log alert
15 clock daemon
16-23 locally used facilities (local0-local7)

Table 2.3. syslog Message Facilities


The following table lists the severity values.

Numerical Code Severity
0 Emergency: system is unusable
1 Alert: action must be taken immediately
2 Critical: critical conditions
3 Error: error conditions
4 Warning: warning conditions
5 Notice: normal but significant condition
6 Informational: informational messages
7 Debug: debug-level messages

Table 2.4. syslog Message Severities


2.9.2.2. The HEADER message part

The HEADER part contains the following elements:

  • VERSION: Version number of the syslog protocol standard. Currently this can only be 1.

  • ISOTIMESTAMP: The time when the message was generated in the ISO 8601 compatible standard timestamp format (yyyy-mm-ddThh:mm:ss+-ZONE), for example: 2006-06-13T15:58:00.123+01:00.

  • HOSTNAME: The machine that originally sent the message.

  • APPLICATION: The device or application that generated the message

  • PID: The process name or process ID of the syslog application that sent the message. It is not necessarily the process ID of the application that generated the message.

  • MESSAGEID: The ID number of the message.

[Note] Note

The syslog-ng application supports other timestamp formats as well, like ISO, or the PIX extended format. The timestamp used in the IETF-syslog protocol is derived from RFC3339, which is based on ISO8601. For details, see the ts_format() option in Section 9.2, Global options.

The syslog-ng OSE application will truncate the following fields:

  • If APP-NAME is longer than 48 characters it will be truncated to 48 characters.

  • If PROC-ID is longer than 128 characters it will be truncated to 128 characters.

  • If MSGID is longer than 32 characters it will be truncated to 32 characters.

  • If HOSTNAME is longer than 255 characters it will be truncated to 255 characters.

2.9.2.3. The STRUCTURED-DATA message part

The STRUCTURED-DATA message part may contain meta- information about the syslog message, or application-specific information such as traffic counters or IP addresses. STRUCTURED-DATA consists of data blocks enclosed in brackets ([]). Every block includes the ID of the block, and one or more name=value pairs. The syslog-ng application automatically parses the STRUCTURED-DATA part of syslog messages, which can be referenced in macros (for details, see Section 11.1.5, Macros of syslog-ng OSE). An example STRUCTURED-DATA block looks like:

[exampleSDID@0 iut="3" eventSource="Application" eventID="1011"][examplePriority@0 class="high"]

2.9.2.4. The MSG message part

The MSG part contains the text of the message itself. The encoding of the text must be UTF-8 if the BOM[3] character is present in the message. If the message does not contain the BOM character, the encoding is treated as unknown. Usually messages arriving from legacy sources do not include the BOM character. CRLF characters will not be removed from the message.

2.9.3. Message representation in syslog-ng OSE

When the syslog-ng OSE application receives a message, it automatically parses the message. The syslog-ng OSE application can automatically parse log messages that conform to the RFC3164 (BSD or legacy-syslog) or the RFC5424 (IETF-syslog) message formats. If syslog-ng OSE cannot parse a message, it results in an error.

[Tip] Tip

In case you need to relay messages that cannot be parsed without any modifications or changes, use the flags(no-parse) option in the source definition, and a template containing only the $MSG macro in the destination definition.

A parsed message has the following parts.

  • Timestamps. Two timestamps are associated with every message: one is the timestamp contained within the message (that is, when the sender sent the message), the other is the time when syslog-ng OSE has actually received the message.

  • Severity. The severity of the message.

  • Facility. The facility that sent the message.

  • Tags. Custom text labels added to the message that are mainly used for filtering. None of the current message transport protocols adds tags to the log messages. Tags can be added to the log message only within syslog-ng OSE. The syslog-ng OSE application automatically adds the id of the source as a tag to the incoming messages. Other tags can be added to the message by the pattern database, or using the tags() option of the source.

  • IP address of the sender. The IP address of the host that sent the message. Note that the IP address of the sender is a hard macro and cannot be modified within syslog-ng OSE but the associated hostname can be modified, for example, using rewrite rules.

  • Hard macros. Hard macros contain data that is directly derived from the log message, for example, the $MONTH macro derives its value from the timestamp. The most important consideration with hard macros is that they are read-only, meaning they cannot be modified using rewrite rules or other means.

  • Soft macros. Soft macros (sometimes also called name-value pairs) are either built-in macros automatically generated from the log message (for example, $HOST), or custom user-created macros generated by using the syslog-ng pattern database or a CSV-parser. The SDATA fields of RFC5424-formatted log messages become soft macros as well. In contrast with hard macros, soft macros are writable and can be modified within syslog-ng OSE, for example, using rewrite rules.

    [Note] Note

    It is also possible to set the value of built-in soft macros using parsers, for example, to set the $HOST macro from the message using a column of a CSV-parser.

    The data extracted from the log messages using named pattern parsers in the pattern database are also soft macros.

    [Tip] Tip

    For the list of hard and soft macros, see Section 11.1.4, Hard vs. soft macros.

2.9.4. Structuring macros, metadata, and other value-pairs

Available in syslog-ng OSE 3.3 and later.

The syslog-ng OSE application allows you to select and construct name-value pairs from any information already available about the log message, or extracted from the message itself. This structured information can be used directly in a MongoDB database (see the value-pairs() option of the mongodb() destination in Section 7.2, Storing messages in a MongoDB database), or in other destinations using the format-json() template function (see Section format-json for details).

When using value-pairs, there are three ways to specify which information (that is, macros or other name-value pairs) to include in the selection.

  • Select groups of macros using the scope() parameter, and optionally remove certain macros from the group using the exclude() parameter.

  • List specific macros to include using the key() parameter.

  • Define new name-value pairs to include using the pair() parameter.

These parameters are detailed in Section value-pairs().

value-pairs()

Type: parameter list of the value-pairs() option
Default:
empty string

Description: The value-pairs() option allows you to select specific information about a message easily using predefined macro groups. The selected information is represented as name-value pairs and can be used formatted to JSON format, or directly used in a mongodb() destination.

[Example] Example 2.1. Using the value-pairs() option

The following example selects every available information about the log message, except for the date-related macros (R_* and S_*), selects the .SDATA.meta.sequenceId macro, and defines a new value-pair called MSGHDR that contains the program name and PID of the application that sent the log message.

value-pairs(

    scope(nv_pairs core syslog all_macros selected_macros everything)

    exclude("R_*")

    exclude("S_*")

    key(".SDATA.meta.sequenceId")

    pair("MSGHDR" "$PROGRAM[$PID]: ")

)

The following example selects the same information as the previous example, but converts it into JSON format.

$(format-json --scope nv_pairs,core,syslog,all_macros,selected_macros,everything \

  --exclude R_* --exclude S_* --key .SDATA.meta.sequenceId \

  --pair MSGHDR="$PROGRAM[$PID]: ")
[Note] Note

Every macro is included in the selection only once, but redundant information may appear if multiple macros include the same information (for example, including several date-related macros in the selection).

The value-pairs() option has the following parameters. The parameters are evaluated in the following order:

  1. scope()

  2. exclude()

  3. key()

  4. pair()

exclude()    
  Type: Space-separated list of macros to remove from the selection created using the scope() option.
  Default: empty string
  Description: This option removes the specified macros from the selection. Use it to remove unneeded macros selected using the scope() parameter.

For example, the following example removes the SDATA macros from the selection.

value-pairs(

        scope(rfc5424 selected_macros)

        exclude(".SDATA*")

    )

The name of the macro to remove can include glob expressions and wildcards (*, ?, [ab], {foo,bar}), as described in Section glob. Regular expressions are not supported.

key()    
  Type: Name of a single macro to be included in selection
  Default: empty string
  Description: This option selects the specified macros. The selected macros will be included as MACRONAME = MACROVALUE, that is using key("HOST") will result in HOST = $HOST.
[Note] Note

The name of the macro cannot contain wildcards.

For example:

value-pairs(

        scope(rfc3164)

        key("HOST"))
pair()    
  Type: name value pairs in "<NAME>" "<VALUE>"
  Default: empty string
  Description: This option defines a new name-value pair to be included in the message. The value part can include macros, templates, and template functions as well.

For example:

value-pairs(

        scope(rfc3164)

        pair("TIME" "$HOUR:$MIN")

        pair("MSGHDR" "$PROGRAM[$PID]: "))
scope()    
  Type: space-separated list of macro groups to include in selection
  Default: empty string
  Description: This option selects predefined groups of macros. The following groups are available:
  • soft-macros: Every soft macro associated with the message, except the ones that start with a dot (.) character. Macros starting with a dot character are generated within syslog-ng OSE and are not originally part of the message, therefore are not included in this group. The soft-macros group also has the following alias: nv-pairs.

  • dot-soft-macros: Every soft macro associated with the message which starts with a dot (.) character. For example, .classifier.rule_id and .sdata.*. Macros starting with a dot character are generated within syslog-ng OSE and are not originally part of the message. The dot-soft-macros group also has the following alias: dot-nv-pairs.

  • all-soft-macros: Include every soft macro (equivalent to using both soft-macros and dot-soft-macros). The all-soft-macros group also has the following alias: all-nv-pairs.

  • rfc3164: The macros that correspond to the RFC3164 (legacy or BSD-syslog) message format: $FACILITY, $PRIORITY, $HOST, $PROGRAM, $PID, $MESSAGE, and $R_DATE. The rfc3164 group also has the following aliases: core, base. Note that the value of $R_DATE will be listed under the DATE key.

  • rfc5424: The macros that correspond to the RFC5424 (IETF-syslog) message format: $FACILITY, $PRIORITY, $HOST, $PROGRAM, $PID, $MESSAGE, $MSGID, and $R_DATE. The rfc5424 group also has the following alias: syslog-proto. Note that the value of $R_DATE will be listed under the DATE key.

    The rfc5424 group does not contain any metadata about the message, only information that was present in the original message. To include the most commonly used metadata (for example, the $SOURCEIP macro), use the selected-macros group instead.

  • all-hard-macros: Include every hard macro. This group is mainly useful for debugging, as it contains redundant information (for example, the date-related macros include the date-related information several times in various formats).

  • selected-macros: Include the macros of the rfc5424 group and the most commonly used metadata about the log message: the $TAGS, $SOURCEIP, and $SEQNUM macros.

  • sdata: The metadata from the structured-data (SDATA) part of RFC5424-formatted messages, that is, every macro that starts with .SDATA.

  • everything: Include every hard and soft macros. This group is mainly useful for debugging, as it contains redundant information (for example, the date-related macros include the date-related information several times in various formats).

For example:

value-pairs(

        scope(rfc3164 selected_macros))


[1] Source: http://tools.ietf.org/html/rfc5424

[2] The byte order mark (BOM) is a Unicode character used to signal the byte-order of the message text.

[3] The byte order mark (BOM) is a Unicode character used to signal the byte-order of the message text.

Chapter 3. Installing syslog-ng

This chapter explains how to install syslog-ng Open Source Edition on various platforms.

  • You can install syslog-ng OSE on many platforms using the package manager and official repositories of the platform. For a list of third-party packages available for various Linux, UNIX, and other platforms, see third-party binaries page.

  • For instructions on compiling syslog-ng Open Source Edition from the source code, see Procedure 3.1, Compiling syslog-ng from source.

3.1. Procedure – Compiling syslog-ng from source

Purpose: 

To compile syslog-ng Open Source Edition (OSE) from the source code, complete the following steps. Alternatively, you can use precompiled binary packages on several platforms. For a list of third-party packages available for various Linux, UNIX, and other platforms, see third-party binaries page.

Steps: 

  1. Download the latest version of syslog-ng OSE from the BalaBit website or from GitHub. The source code is available as a tar.gz archive file.

  2. Download the latest version of the EventLog library here.

  3. Install the following packages that are required to compile syslog-ng. These packages are available for most UNIX/Linux systems. Alternatively, you can also download the sources and compile them.

    • A version of the gcc C compiler that properly supports Thread Local Storage (TLS), for example, version 4.5 (at least version. For building recent gcc versions on Solaris, see http://jblopen.com/node/16.

    • The GNU flex lexical analyser generator, available here.

    • The bison parser generator, available here.

    • The development files of the glib library, available here.

  4. If you want to use the spoof-source function of syslog-ng, install the development files of the libnet library, available here.

  5. If you want to use the /etc/hosts.deny and /etc/hosts.allow for TCP access, install the development files of the libwrap (also called TCP-wrappers) library, available here.

  6. Uncompress the eventlog archive using the

    $ tar xvfz eventlog-x.x.x.x.tar.gz

    or the

    $ gunzip -c eventlog-x.x.x.x.tar.gz | tar xvf -

    command. A new directory containing the source code of eventlog will be created.

  7. By default, eventlog creates a file used by the syslog-ng configure script in the /usr/local/lib/pkgconfig directory. Issue the following command to add this directory to your PKG_CONFIG_PATH:

    PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
  8. Enter the new directory and issue the following commands:

    $ ./configure
    
    $ make
    
    $ make install
  9. Uncompress the syslog-ng archive using the

    tar xvfz syslog-ng-x.xx.tar.gz

    or the

    unzip -c syslog-ng-x.xx.tar.gz | tar xvf -

    command. A new directory containing the source code of syslog-ng will be created.

  10. Enter the new directory and issue the following commands:

    $ ./configure
    
    $ make 
    
    $ make install

    These commands will build syslog-ng using its default options.

    [Note] Note

    On Solaris, use gmake (GNU make) instead of make.

  11. If needed, use the following options to change how syslog-ng is compiled using the following command syntax:

    $ ./configure --compile-time-option-name
    [Note] Note

    You can also use --disable options, to explicitly disable a feature and override autodetection. For example, to disable the TCP-wrapper support, use the --disable-tcp-wrapper option.

    [Warning] Warning

    Starting with syslog-ng Open Source Edition 3.0.2, default linking mode of syslog-ng is dynamic. This means that syslog-ng might not be able to start up if the /usr directory is on NFS. On platforms where syslog-ng is used as a system logger, the --enable-mixed-linking is preferred.

    • --enable-debug Include debug information.

    • --enable-dynamic-linking Compile syslog-ng as a completely dynamic binary. If not specified syslog-ng uses mixed linking (--enable-mixed-linking): it links dynamically to system libraries and statically to everything else.

    • --enable-ipv6 Enable IPv6 support.

    • --enable-json Enables JSON support (enabled automatically if the json-c or json-glib libraries are installed and detected).

    • --enable-linux-caps Enable support for capabilities on Linux.

    • --enable-mongodb Enable the mongodb destination (enabled by default). The source of the MongoDB client is included in the source code package of syslog-ng OSE. To use an external MongoDB client instead, use the --with-libmongo-client=system compiling option. For details on using this destination, see Section 7.2, Storing messages in a MongoDB database.

    • --enable-pcre Enable using PCRE-type regular expressions. Requires the libpcre library package.

    • --enable-spoof-source Enable spoof_source feature (disabled by default).

    • --enable-sun-door Enable Sun door support even if not detected (autodetected by default).

    • --enable-sun-streams Enable Sun STREAMS support even if not detected (autodetected by default).

    • --enable-systemd Enable systemd support on Linux platforms (autodetected by default).

    • --enable-tcp-wrapper Enable using /etc/hosts.deny and /etc/hosts.allow for TCP access (enabled automatically if the libwrap libraries are detected).

    • --with-ivykis Specifies which ivykis implementation to use (default value: internal). The source of ivykis is included in the source code package of syslog-ng OSE and is used by default. To use an external implementation instead, use the --with-ivykis=system compiling option.

    • --with-json Specifies which JSON implementation to use (determined automatically if json-c or json-glib is installed).

    • --with-libmongo-client Specifies which MongoDB client to use (default value: internal). The source of the mongodb client is included in the source code package of syslog-ng OSE and is used by default. To use an external MongoDB client instead, use the --with-libmongo-client=system compiling option. For details on using this destination, see Section 7.2, Storing messages in a MongoDB database.

    • --with-module-dir Specifies a single directory where the syslog-ng OSE Makefile will install the modules.

    • --with-module-path Specifies a colon-separated (:) list of directories, where the syslog-ng OSE binary will search for modules.

    • --with-timezone-dir Specifies the directory where syslog-ng looks for the timezone files to resolve the time_zone() and local_time_zone() options. If not specified, the /opt/syslog-ng/share/zoneinfo/ and /usr/share/zoneinfo/ directories are checked, respectively. Note that HP-UX uses a unique file format (tztab) to describe the timezone information; that format is currently not supported in syslog-ng. As a workaround, copy the zoneinfo files from another, non-HP-UX system to the /opt/syslog-ng/share/zoneinfo/ directory of your HP-UX system.

    • --without-compile-date Removes the compilation date from the binary. For example, as openSUSE checks if recompilation changes the binary to detect if dependent packages need to be rebuilt or not, and including the date changes the binary every time.

3.2. Uninstalling syslog-ng

If you need to uninstall syslog-ng for some reason, you have the following options:

  • If you have installed syslog-ng from a .deb package: Execute the dpkg -r syslog-ng command to remove syslog-ng; or the dpkg -P syslog-ng command to remove syslog-ng and the configuration files as well. Note that removing syslog-ng does not restore the syslog daemon used before syslog-ng.

  • If you have installed syslog-ng from an .rpm package: Execute the rpm -e syslog-ng command to remove syslog-ng. Note that removing syslog-ng does not restore the syslog daemon used before syslog-ng.

3.3. Procedure – Configuring Microsoft SQL Server to accept logs from syslog-ng

Purpose: 

Complete the following steps to configure your Microsoft SQL Server to enable remote logins and accept log messages from syslog-ng.

Steps: 

  1. Start the SQL Server Management Studio application. Select Start > Programs > Microsoft SQL Server 2005 > SQL Server Management Studio.

  2. Create a new database.

    1. Creating a new MSSQL database 1.

      Figure 3.1. Creating a new MSSQL database 1.


      In the Object Explorer, right-click on the Databases entry and select New Database.

    2. Creating a new MSSQL database 2.

      Figure 3.2. Creating a new MSSQL database 2.


      Enter the name of the new database (for example syslogng) into the Database name field and click OK.

  3. Create a new database user and associate it with the new database.

    1. Creating a new MSSQL user 1.

      Figure 3.3. Creating a new MSSQL user 1.


      In the Object Explorer, select Security, right-click on the Logins entry, then select New Login.

    2. Creating a new MSSQL user 2.

      Figure 3.4. Creating a new MSSQL user 2.


      Enter a name (for example syslog-ng) for the user into the Login name field.

    3. Select the SQL Server Authentication option and enter a password for the user.

    4. In the Default database field, select the database created in Step 2 (for example syslogng).

    5. In the Default language field, select the language of log messages that you want to store in the database, then click OK.

      [Warning] Warning

      Incorrect language settings may result in the database converting the messages to a different character-encoding format. That way the log messages may become unreadable, causing information loss.

    6. In the Object Explorer, select Security > Logins, then right-click on the new login created in the previous step, and select Properties.

    7. Associating database with the new user

      Figure 3.5. Associating database with the new user


      Select User Mapping. In the Users mapped to this login option, check the line corresponding to the new login (for example syslogng). In the Database role membership field, check the db_owner and public options.

  4. Associating database with the new user

    Figure 3.6. Associating database with the new user


    Enable remote logins for SQL users.

    In the Object Explorer right-click on your database server, and select Properties > Security, and set the Server Authentication option to SQL Server and Windows Authentication mode.

Chapter 4. The syslog-ng OSE quick-start guide

This chapter provides a very brief introduction into configuring the syslog-ng OSE application. For details on the format of the configuration file and how to configure sources, destinations, and other features, refer to the subsequent chapters.

4.1. Procedure – Configuring syslog-ng on client hosts

Purpose: 

To configure syslog-ng on a client host, complete the following steps.

Steps: 

  1. Install the syslog-ng application on the host. For details installing syslog-ng on specific operating systems, see Chapter 3, Installing syslog-ng.

  2. Configure the local sources to collect the log messages of the host. Starting with version 3.2, syslog-ng OSE automatically collects the log messages that use the native system logging method of the platform, for example, messages from /dev/log on Linux, or /dev/klog on FreeBSD. For a complete list of messages that are collected automatically, see Section 6.9, Collecting the system-specific log messages of a platform.

    Add sources to collect the messages from your log files. File sources look like this:

    source s_myfilesource { 
    
            file("/var/log/myapplication.log" follow_freq(1)); };

    Name every source uniquely. For details on configuring file sources, see Section 6.3, Collecting messages from text files.

    [Tip] Tip

    Many applications send log messages to logfiles by default (for example, the Roundcube webmail client, or the ProFTPD FTP server), but can be configured to send them to syslog instead. If possible, it is recommended to reconfigure the application that way.

    [Note] Note

    The default configuration file of syslog-ng OSE collects platform-specific log messages and the intenal log messages of syslog-ng OSE.

    source s_local {
    
            system();
    
            internal();
    
    };
  3. Create a network destination that points directly to the syslog-ng server, or to a local relay. The network destination greatly depends on the protocol that your logserver or relay accepts messages. Many systems still use the legacy BSD-syslog protocol (RFC3162) over the unreliable UDP transport:

    destination d_network { udp("10.1.2.3"); };

    However, if possible, use the much more reliable IETF-syslog protocol over TCP transport:

    destination d_network {syslog(ip("10.1.2.3") transport("tcp")); };
  4. Create a log statement connecting the local sources to the syslog-ng server or relay. For example:

    log { 
    
            source(s_local); destination(d_network); };
  5. If the logs will also be stored locally on the host, create local file destinations.

    [Note] Note

    The default configuration of syslog-ng OSE places the collected messages into the /var/log/messages file:

    destination d_local {
    
        file("/var/log/messages"); };
  6. Create a log statement connecting the local sources to the file destination.

    [Note] Note

    The default configuration of syslog-ng OSE has only one log statement:

    log {
    
        source(s_local); destination(d_local);
  7. Set filters, macros and other features and options (for example TLS encryption) as necessary.

[Example] Example 4.1. The default configuration file of syslog-ng OSE

The following is the default configuration file of syslog-ng OSE 3.2. It collects local log messages and the log messages of syslog-ng OSE and forwards them to a logserver using the IETF-syslog protocol.

@version: 3.3

@include "scl.conf"

source s_local { system(); internal(); };

destination d_local {

            file("/var/log/messages"); };

log { source(s_local); destination(d_local); };
[Example] Example 4.2. A simple configuration for clients

The following is a simple configuration file that collects local log messages to the /var/log/messages file.

@version: 3.3

@include "scl.conf"

source s_local { system(); internal(); };

destination d_syslog_tcp {

             syslog("192.168.1.1" transport("tcp") port(2010)); };

log { source(s_local);destination(d_syslog_tcp); };

4.2. Procedure – Configuring syslog-ng on server hosts

Purpose: 

To configure syslog-ng on a server host, complete the following steps.

Steps: 

  1. Install the syslog-ng application on the host. For details installing syslog-ng on specific operating systems, see Chapter 3, Installing syslog-ng.

  2. Starting with version 3.2, syslog-ng OSE automatically collects the log messages that use the native system logging method of the platform, for example, messages from /dev/log on Linux, or /dev/klog on FreeBSD. For a complete list of messages that are collected automatically, see Section 6.9, Collecting the system-specific log messages of a platform.

  3. Configure the network sources that collect the log messages sent by the clients and relays. How the network sources should be configured depends also on the capabilities of your client hosts: many older networking devices support only the legacy BSD-syslog protocol (RFC3164) using UDP transport:

    source s_network { syslog(ip(10.1.2.3) transport("udp")); };

    However, if possible, use the much more reliable TCP transport:

    source s_network { syslog(ip(10.1.2.3) transport("tcp")); };

    For other options, see Section 6.8, Collecting messages using the IETF syslog protocol and Section 6.10, Collecting messages from remote hosts using the BSD syslog protocol.

    [Note] Note

    Starting with syslog-ng OSE version 3.2, the syslog() source driver can handle both BSD-syslog (RFC 3164) and IETF-syslog (RFC 5424-28) messages.

  4. Create local destinations that will store the log messages, for example file- or program destinations. The default configuration of syslog-ng OSE places the collected messages into the /var/log/messages file:

    destination d_local {
    
        file("/var/log/messages"); };

    If you want to create separate logfiles for every client host, use the $HOST macro when specifying the filename, for example:

    destination d_local {
    
        file("/var/log/messages_$HOST"); };

    For details on further macros and how to use them, see Chapter 11, Manipulating messages.

  5. Create a log statement connecting the sources to the local destinations.

    log {
    
            source(s_local); source(s_network); destination(d_local);
  6. Set filters, options (for example TLS encryption) and other advanced features as necessary.

    [Note] Note

    By default, the syslog-ng server will treat the relayed messages as if they were created by the relay host, not the host that originally sent them to the relay. In order to use the original hostname on the syslog-ng server, use the keep_hostname(yes) option both on the syslog-ng relay and the syslog-ng server. This option can be set individually for every source if needed.

[Example] Example 4.3. A simple configuration for servers

The following is a simple configuration file for syslog-ng Open Source Edition that collects incoming log messages and stores them in a text file.

@version: 3.3

@include "scl.conf"

    options { 

        time_reap(30);

        mark_freq(10);

        keep_hostname(yes);

        };

    source s_local { system(); internal(); };

    source s_network {

        syslog(transport(tcp));

        };

    destination d_logs {

        file(

            "/var/log/syslog-ng/logs.txt"

            owner("root")

            group("root")

            perm(0777)

            ); };

    log { source(s_local); source(s_network); destination(d_logs); };

4.3. Configuring syslog-ng relays

4.3.1. Procedure – Configuring syslog-ng on relay hosts

Purpose: 

To configure syslog-ng on a relay host, complete the following steps:

Steps: 

  1. Install the syslog-ng application on the host. For details installing syslog-ng on specific operating systems, see Chapter 3, Installing syslog-ng.

  2. Configure the network sources that collect the log messages sent by the clients.

  3. Create a network destination that points to the syslog-ng server.

  4. Create a log statement connecting the network sources to the syslog-ng server.

  5. Configure the local sources that collect the log messages of the relay host.

  6. Create a log statement connecting the local sources to the syslog-ng server.

  7. Enable the keep_hostname() and disable the chain_hostnames() options.

    [Note] Note

    It is recommended to use these options on your syslog-ng OSE server as well.

  8. Set filters and options (for example TLS encryption) as necessary.

    [Note] Note

    By default, the syslog-ng server will treat the relayed messages as if they were created by the relay host, not the host that originally sent them to the relay. In order to use the original hostname on the syslog-ng server, use the keep_hostname(yes) option both on the syslog-ng relay and the syslog-ng server. This option can be set individually for every source if needed.

    If you are relaying log messages and want to resolve IP addresses to hostnames, configure the first relay to do the name resolution.

[Example] Example 4.4. A simple configuration for relays

The following is a simple configuration file that collects local and incoming log messages and forwards them to a logserver using the IETF-syslog protocol.

@version: @techversion;

@include "scl.conf"

    options { 

        time_reap(30);

        mark_freq(10);

        keep_hostname(yes);

        chain_hostnames(no);

        };

    source s_local { system(); internal(); };

    source s_network {

        syslog(transport(tcp));

        };

    destination d_syslog_tcp {

        syslog("192.168.1.5" transport("tcp") port(2010));

    };

    

    log { source(s_local); source(s_network); 

          destination(d_syslog_tcp); 

        };

4.3.2. How relaying log messages works

Depending on your exact needs about relaying log messages, there are many scenarios and syslog-ng OSE options that influence how the log message will look like on the logserver. Some of the most common cases are summarized in the following example[4].

Consider the following example: client-host > syslog-ng-relay > syslog-ng-server, where the IP address of client-host is 192.168.1.2. The client-host device sends a syslog message to syslog-ng-relay. Depending on the settings of syslog-ng-relay, the following can happen.

  • By default, the keep_hostname() option is disabled, so syslog-ng-relay writes the IP address of the sender host (in this case, 192.168.1.2) to the HOST field of the syslog message, discarding any IP address or hostname that was originally in the message.

  • If the keep_hostname() option is enabled on syslog-ng-relay, but name resolution is disabled (the use_dns() option is set to no), syslog-ng-relay uses the HOST field of the message as-is, which is probably 192.168.1.2.

  • To resolve the 192.168.1.2 IP address to a hostname on syslog-ng-relay using a DNS server, use the keep_hostname(no) and use_dns(yes) options. If the DNS server is properly configured and reverse DNS lookup is available for the 192.168.1.2 address, syslog-ng OSE will rewrite the HOST field of the log message to client-host.

    [Note] Note

    It is also possible to resolve IP addresses locally, without relying on the DNS server. For details on local name resolution, see Procedure 17.4.1, Resolving hostnames locally.

  • The above points apply to the syslog-ng OSE server (syslog-ng-server) as well, so if syslog-ng-relay is configured properly, use the keep_hostname(yes) option on syslog-ng-server to retain the proper HOST field. Setting on keep_hostname(no) on syslog-ng-server would result in syslog-ng OSE rewriting the HOST field to the address of the host that sent the message to syslog-ng-server, which is syslog-ng-relay in this case.

  • If you cannot or do not want to resolve the 192.168.1.2 IP address on syslog-ng-relay, but want to store your log messages on syslog-ng-server using the IP address of the original host (that is, client-host), you can enable the spoof_source() option on syslog-ng-relay. However, spoof_source() works only under the following conditions:

    • The syslog-ng OSE binary has been compiled with the --enable-spoof-source option.

    • The log messages are sent using the highly unreliable UDP transport protocol. (Extremely unrecommended.)



[4] Many thanks to Lance Laursen for his excellent post about this topic on the syslog-ng mailing list.

Chapter 5. The syslog-ng OSE configuration file

5.1. Location of the syslog-ng configuration file

The syslog-ng application is configured by editing the syslog-ng.conf file. Use any regular text editor application to modify the file. The location of the configuration file depends on how you installed syslog-ng OSE. Native packages of a platform (like the ones downloaded from Linux repositories) typically place the configuration file under the /etc/syslog-ng/ directory.

5.2. The configuration syntax in detail

Every syslog-ng configuration file must begin with a line containing the version information of syslog-ng. For syslog-ng version 3.3, this line looks like:

@version: 3.3

Versioning the configuration file was introduced in syslog-ng 3.0. If the configuration file does not contain the version information, syslog-ng assumes that the file is for syslog-ng version 2.x. In this case it interprets the configuration and sends warnings about the parts of the configuration that should be updated. Version 3.0 and later will correctly operate with configuration files of version 2.x, but the default values of certain parameters have changed since 3.0.

[Example] Example 5.1. A simple configuration file

The following is a very simple configuration file for syslog-ng: it collects the internal messages of syslog-ng and the messages from /dev/log into the /var/log/messages_syslog-ng.log file.

@version: 3.3



source s_local { unix-stream("/dev/log"); internal(); };



destination d_file {file("/var/log/messages_syslog-ng.log"); };



log { source(s_local); destination(d_file); };

As a syslog-ng user described on a mailing list:

 

Syslog-ng's config file format was written by programmers for programmers to be understood by programmers. That may not have been the stated intent, but it is how things turned out. The syntax is exactly that of C, all the way down to braces and statement terminators.

 
  --Alan McKinnon
  • The main body of the configuration file consists of object definitions: sources, destinations, logpaths define which log message are received and where they are sent. All identifiers, option names and attributes, and any other strings used in the syslog-ng configuration file are case sensitive. Objects must be defined before they are referenced in another statement. Object definitions (also called statements) have the following syntax:

    object_type object_id {<options>};
    • Type of the object: One of source, destination, log, filter, parser, rewrite rule, or template.

    • Identifier of the object: A unique name identifying the object. When using a reserved word as an identifier, enclose the identifier in quotation marks.

      [Tip] Tip

      Use identifiers that refer to the type of the object they identify. For example, prefix source objects with s_, destinations with d_, and so on.

    • Parameters: The parameters of the object, enclosed in braces {parameters}.

    • Semicolon: Object definitions end with a semicolon (;).

    For example, the following line defines a source and calls it s_internal.

    source s_internal { internal(); };

    The object can be later referenced in other statements using its ID, for example, the previous source is used as a parameter of the following log statement:

    log { source(s_internal); destination(d_file); };
  • The parameters and options within a statement are similar to function calls of the C programming language: the name of the option followed by a list of its parameters enclosed within brackets and terminated with a semicolon.

    option(parameter1, parameter2); option2(parameter1, parameter2);

    For example, the following source statement has three options; the first two options (file() and follow_freq()) have a single parameter, while the third one (flags()) has two parameters:

    source s_tail { file("/var/log/apache/access.log"
    
        follow_freq(1) flags(no-parse, validate-utf8)); };

    Objects may have required and optional parameters. Required parameters are positional, meaning that they must be specified in a defined order. Optional parameters can be specified in any order using the option(value) format. If a parameter (optional or required) is not specified, its default value is used. The parameters and their default values are listed in the reference section of the particular object.

    [Example] Example 5.2. Using required and optional parameters

    The unix-stream() source driver has a single required argument: the name of the socket to listen on. Optional parameters follow the socket name in any order, so the following source definitions have the same effect:

    source s_demo_stream1 {
    
            unix-stream("/dev/log" max-connections(10) group(log)); };
    
    source s_demo_stream2 {
    
            unix-stream("/dev/log" group(log) max-connections(10)); };
  • Some options are global options, or can be set globally, for example, whether syslog-ng OSE should use DNS resolution to resolve IP addresses. Global options are detailed in Chapter 9, Global options of syslog-ng OSE.

    options { use_dns(no); };
  • All identifiers, attributes, and any other strings used in the syslog-ng configuration file are case sensitive.

  • Objects can be used before definition.

  • To add comments to the configuration file, start a line with # and write your comments. These lines are ignored by syslog-ng.

    # Comment: This is a stream source
    
    source s_demo_stream {
    
            unix-stream("/dev/log" max-connections(10) group(log)); };
[Tip] Tip

Before activating a new configuration, check that your configuration file is syntactically correct using the syslog-ng --syntax-only command.

To activate the configuration, reload the configuration of syslog-ng using the /etc/init.d/syslog-ng reload command.

5.3. Notes about the configuration syntax

When you are editing the syslog-ng configuration file, note the following points:

  • When writing the names of options and parameters (or other reserved words), the hyphen (-) and underscore (_) characters are equivalent, for example max-connections(10) and max_connections(10) are both correct.

  • Number can be prefixed with + or - to indicate positive or negative values. Numbers beginning with zero (0) or 0x are treated as octal or hexadecimal numbers, respectively.

  • You can use commas (,) to separate options or other parameters for readability; syslog-ng completely ignores them. The following declarations are equivalent:

    source s_demo_stream {
    
            unix-stream("/dev/log" max-connections(10) group(log)); };
    source s_demo_stream {
    
            unix-stream("/dev/log", max-connections(10), group(log)); };
  • When enclosing object IDs (for example the name of a destination) between double-quotes ("mydestination"), the ID can include whitespace as well, for example:

    source "s demo stream" {
    
            unix-stream("/dev/log" max-connections(10) group(log)); };
  • For notes on using regular expressions, see Section 11.3, Regular expressions.

5.4. Global and environmental variables

Starting with syslog-ng OSE version 3.2, it is possible to define global variables in the configuration file. Global variables are actually name-value pairs; when syslog-ng processes the configuration file during startup, it automatically replaces `name` with value. To define a global variable, use the following syntax:

@define name "value"

The value can be any string, but special characters must be escaped.To use the variable, insert the name of the variable enclosed between backticks (`, similarly to using variables in Linux or UNIX shells) anywhere in the configuration file.

The value of the global variable can be also specified using the following methods:

  • Without any quotes, as long as the value does not contain any spaces or special characters. In other word, it contains only the following characters: a-zA-Z0-9_..

  • Between apostrophes, in case the value does not contain apostrophes.

  • Between double quotes, in which case special characters must be escaped using backslashes (\).

[Tip] Tip

The environmental variables of the host are automatically imported and can be used as global variables.

[Example] Example 5.3. Using global variables

For example, if an application is creating multiple log files in a directory, you can store the path in a global variable, and use it in your source definitions.

@define mypath "/opt/myapp/logs"

        source s_myapp_1 { file("`mypath`/access.log" follow_freq(1)); };

        source s_myapp_2 { file("`mypath`/error.log" follow_freq(1)); };

        source s_myapp_3 { file("`mypath`/debug.log" follow_freq(1)); };

The syslog-ng OSE application will interpret this as:

@define mypath "/opt/myapp/logs"

        source s_myapp_1 { file("/opt/myapp/logs/access.log" follow_freq(1)); };

        source s_myapp_2 { file("/opt/myapp/logs/error.log" follow_freq(1)); };

        source s_myapp_3 { file("/opt/myapp/logs/debug.log" follow_freq(1)); };

5.5. Loading modules

Starting with syslog-ng Open Source Edition version 3.3, syslog-ng OSE became modular to increase its flexibility and also to simplify the development of additional modules. Most of the functionality of syslog-ng OSE has been moved to separate modules. That way it becomes also possible to finetune the resource requirements of syslog-ng OSE for example, by loading only the modules that are actually used in the configuration, or simply omitting modules that are not used but require large amount of memory.

Each module contains one or more plugins, which add some functionality to syslog-ng OSE, for example, a destination or a source driver.

  • To display the list of available modules, execute the syslog-ng --version command.

  • To the description of the available modules, execute the syslog-ng --module-registry command.

  • To customize which modules are loaded automatically when syslog-ng OSE is started, use the --default-modules command-line option of syslog-ng OSE.

  • To request loading a module from the syslog-ng OSE configuration file, see Section 5.5.1, Loading modules.

For details on the command-line parameters of syslog-ng OSE mentioned in the previous list, see the syslog-ng OSE man page at syslog-ng(8).

5.5.1. Loading modules

The syslog-ng Open Source Edition application loads every available module during startup.

To load a module that is not loaded automatically, include the following statement in the syslog-ng OSE configuration file:

@module <module-name>

Note the following points about the @module statement:

  • The @module statement is a top-level statement, that is, it cannot be nested into any other statement. Usually it is used immediately after the @version statement.

  • Every @module statement loads a single module: loading multiple modules requires a separate @module statement for every module.

  • In the configuration file, the @module statement of a module must be earlier than the module is used.

5.6. Managing complex syslog-ng configurations

The following sections describe some methods that can be useful to simplify the management of large-scale syslog-ng installations.

5.6.1. Including configuration files

The syslog-ng application supports including external files in its configuration file, so parts of its configuration can be managed separately. To include the contents of a file in the syslog-ng configuration, use the following syntax

include "<filename>";

Where <filename> can be file name, path or even a directory (where all files are included, except files beginning with ~ (tilde) or . (dot)). Including a directory is not recursive.

This imports the entire file into the configuration of syslog-ng, at the location of the include statement. If you specify a directory, syslog-ng will try to include every file in alphabetic order. When including configuration files, consider the following points:

  • If an object is defined twice (for example the original syslog-ng configuration file and the file imported into this configuration file both define the same option, source, or other object), then the object that is defined later in the configuration file will be effective. For example, if you set a global option at the beginning of the configuration file, and later include a file that defines the same option with a different value, then the option defined in the imported file will be used.

  • Files can be embedded into each other: the included files can contain include statements as well, up to a maximum depth of 15 levels.

  • You cannot include complete configuration files into each other, only configuration snippets can be included. This means that the included file cannot have a @version statement.

  • Include statements can only be used at top level of the configuration file. For example, the following is correct:

    @version: 3.3
    
    include "example.conf";

    But the following is not:

    source s_example {
    
        include "example.conf"
    
         };
[Warning] Warning

The syslog-ng application will not start if it cannot find a file that is to be included in its configuration. Always double-check the filenames, paths, and access rights when including configuration files, and use the --syntax-only command-line option to check your configuration.

5.6.2. Reusing configuration blocks

Starting with syslog-ng OSE 3.2, parts of a configuration file can be easily reused, you have to define the block (for example, a source) once, and reference it later. Any syslog-ng object can be a block. Use the following syntax to define a block:

block type name() {<contents of the block>}

Type must be one of the following: destination, filter, log, parser, rewrite, root, source. The root blocks can be used in the "root" context of the configuration file, that is, outside any other statements.

Blocks may be nested into each other, so for example an SCL may be built from other blocks. Blocks are somewhat similar to C++ templates.

The type and name combination of each block must be unique, that is, two blocks can have the same name if their type is different.

To use a block in your configuration file, you have to do two things:

  • Include the file defining the block in the syslog-ng.conf file — or a file already included into syslog-ng.conf.

  • Reference the name of the block in your configuration file. This will insert the block into your configuration. For example, to use a block called myblock, include the following line in your configuration:

    myblock()

    Blocks may have parameters, but even if they do not, the reference must include opening and closing parentheses like in the previous example.

The contents of the block will be inserted into the configuration when syslog-ng OSE is started or reloaded.

[Example] Example 5.4. Reusing configuration blocks

Suppose you are running an application on your hosts that logs into the /opt/var/myapplication.log file. Create a file (for example, myblocks.conf) that stores a source describing this file and how it should be read:

block source myappsource() {

                file("/opt/var/myapplication.log" follow_freq(1) default-facility(syslog)); };

Include this file in your main syslog-ng configuration file,reference the block, and use it in a logpath:

@version: 3.3

include "<correct/path>/myblocks.conf";

source s_myappsource { myappsource(); }

...

log { source(s_myappsource); destination(…); };

To define a block that defines more than one object, use root as the type of the block, and reference the block from the main part of the syslog-ng OSE configuration file.

[Example] Example 5.5. Defining blocks with multiple elements

The following example defines a source, a destination, and a log path to connect them.

block root mylogs() {

        source s_file { file("/var/log/mylogs.log" follow_freq(1)); };

        destination d_local { file("/var/log/messages"); };

        log { source(s_file); destination(d_local); };

        };
[Tip] Tip

Since the block is inserted into the syslog-ng OSE configuration when syslog-ng OSE is started, the block can be generated dynamically using an external script if needed. This is useful when you are running syslog-ng OSE on different hosts and you want to keep the main configuration identical.

If you want to reuse more than a single configuration object, for example, a logpath and the definitions of its sources and destinations, use the include feature to reuse the entire snippet. For details, see Section 5.6.1, Including configuration files.

5.6.2.1. Passing arguments to configuration blocks

Configuration blocks can receive arguments as well. The parameters the block can receive must be specified when the block is defined, using the following syntax:

block type block_name(argument1(<default-value-of-the-argument>) argument2(<default-value-of-the-argument>) argument3())

If an argument does not have a default value, use empty parentheses after the name of the argument. To refer the value of the argument in the block, use the name of the argument between backticks (for example, `argument1`).

[Example] Example 5.6. Passing arguments to blocks

The following sample defines a file source block, which can receive the name of the file as a parameter. If no parameter is set, it reads messages from the /var/log/messages file.

block source s_logfile (filename("messages")) {

  file("/var/log/`filename`" );

};



source s_example {

  s_logfile(filename("logfile.log"));

};
[Example] Example 5.7. Using arguments in blocks

The following example is the code of the pacct() source driver, which is actually a block that can optionally receive two arguments.

block source pacct(file("/var/log/account/pacct") follow-freq(1)) {

@module pacctformat

        file("`file`" follow-freq(`follow-freq`) format("pacct") tags(".pacct"));

};

Chapter 6. Collecting log messages — sources and source drivers

6.1. How sources work

A source is where syslog-ng receives log messages. Sources consist of one or more drivers, each defining where and how messages are received.

To define a source, add a source statement to the syslog-ng configuration file using the following syntax:

source <identifier> { source-driver(params); source-driver(params); ... };

[Example] Example 6.1. A simple source statement

The following source statement receives messages on the TCP port 1999 of the interface having the 10.1.2.3 IP address.

source s_demo_tcp { tcp(ip(10.1.2.3) port(1999)); };
[Example] Example 6.2. A source statement using two source drivers

The following source statement receives messages on the 1999 TCP port and the 1999 UDP port of the interface having the 10.1.2.3 IP address.

source s_demo_two_drivers {

           tcp(ip(10.1.2.3) port(1999));

           udp(ip(10.1.2.3) port(1999)); };
[Example] Example 6.3. Setting default priority and facility

If the message received by the source does not have a proper syslog header, you can use the default-facility() and default-priority() options to set the facility and priority of the messages. Note that these values are applied only to messages that do not set these parameters in their header.

source headerless_messages { udp(default-facility(syslog) default-priority(emerg)); };

Define a source only once. The same source can be used in several log paths. Duplicating sources causes syslog-ng to open the source (TCP/IP port, file, and so on) more than once, which might cause problems. For example, include the /dev/log file source only in one source statement, and use this statement in more than one log path if needed.

[Note] Note

Sources and destinations are initialized only when they are used in a log statement. For example, syslog-ng OSE starts listening on a port or starts polling a file only if the source is used in a log statement. For details on creating log statements, see Chapter 8, Routing messages: log paths and filters.

To collect log messages on a specific platform, it is important to know how the native syslogd communicates on that platform. The following table summarizes the operation methods of syslogd on some of the tested platforms:

Platform Method
Linux A SOCK_STREAM unix socket named /dev/log; some of the distributions switched over to using SOCK_DGRAM, though applications still work with either method.
BSD flavors A SOCK_DGRAM unix socket named /var/run/log.
Solaris (2.5 or below) An SVR4 style STREAMS device named /dev/log.
Solaris (2.6 or above) In addition to the STREAMS device used in earlier versions, 2.6 uses a new multithreaded IPC method called door. By default the door used by syslogd is /etc/.syslog_door.
HP-UX 11 or later HP-UX uses a named pipe called /dev/log that is padded to 2048 bytes, for example source s_hp-ux {pipe ("/dev/log" pad_size(2048)}.
AIX 5.2 and 5.3 A SOCK_STREAM or SOCK_DGRAM unix socket called /dev/log.

Table 6.1. Communication methods used between the applications and syslogd


Each possible communication mechanism has a corresponding source driver in syslog-ng. For example, to open a unix socket with SOCK_DGRAM style communication use the driver unix-dgram. The same socket using the SOCK_STREAM style — as used under Linux — is called unix-stream.

[Example] Example 6.4. Source statement on a Linux based operating system

The following source statement collects the following log messages:

  • internal(): Messages generated by syslog-ng.

  • udp(ip(0.0.0.0) port(514)): Messages arriving to the 514/UDP port of any interface of the host.

  • unix-stream("/dev/log");: Messages arriving to the /dev/log socket.

source s_demo {

           internal();

           udp(ip(0.0.0.0) port(514));

           unix-stream("/dev/log"); };

The following table lists the source drivers available in syslog-ng.

Name Description
internal() Messages generated internally in syslog-ng.
file() Opens the specified file and reads messages.
pacct() Reads messages from the process accounting logs on Linux.
pipe() Opens the specified named pipe and reads messages.
program() Opens the specified application and reads messages from its standard output.
sun-stream(), sun-streams() Opens the specified STREAMS device on Solaris systems and reads incoming messages.
syslog() Listens for incoming messages using the new IETF-standard syslog protocol.
system() Automatically detects which platform syslog-ng OSE is running on, and collects the native log messages of that platform.
tcp(), tcp6() Listens on the specified TCP port for incoming messages using the BSD-syslog protocol over IPv4 and IPv6 networks, respectively.
udp(), udp6() Listens on the specified UDP port for incoming messages using the BSD-syslog protocol over IPv4 and IPv6 networks, respectively.
unix-dgram() Opens the specified unix socket in SOCK_DGRAM mode and listens for incoming messages.
unix-stream() Opens the specified unix socket in SOCK_STREAM mode and listens for incoming messages.

Table 6.2. Source drivers available in syslog-ng


6.2. Collecting internal messages

All messages generated internally by syslog-ng use this special source. To collect warnings, errors and notices from syslog-ng itself, include this source in one of your source statements.

internal()

The syslog-ng application will issue a warning upon startup if none of the defined log paths reference this driver.

[Example] Example 6.5. Using the internal() driver
source s_local { internal(); };

The syslog-ng OSE application sends the following message types from the internal() source: 

  • fatal: Priority value: critical (2); Facility value: syslog (5)

  • error: Priority value: error (3); Facility value: syslog (5)

  • warning: Priority value: warning (4); Facility value: syslog (5)

  • notice: Priority value: notice (5); Facility value: syslog (5)

  • info: Priority value: info (6); Facility value: syslog (5)

6.2.1. internal() source options

The internal() driver has the following options:

tags()

Type: string
Default:  

Description: Label the messages received from the source with custom tags. Tags must be unique, and enclosed between double quotes. When adding multiple tags, separate them with comma, for example tags("dmz", "router"). This option is available only in syslog-ng 3.1 and later.

6.3. Collecting messages from text files

Collects log messages from plain-text files, for example from the logfiles of an Apache webserver.

The syslog-ng application notices if a file is renamed or replaced with a new file, so it can correctly follow the file even if logrotation is used. When syslog-ng is restarted, it records the position of the last sent log message in the /opt/syslog-ng/var/syslog-ng.persist file, and continues to send messages from this position after the restart.

The file driver has a single required parameter specifying the file to open. For the list of available optional parameters, see Section 6.3.2, file() source options.

Declaration:

            file(filename);
[Example] Example 6.6. Using the file() driver
source s_file { file("/var/log/messages"); };
[Example] Example 6.7. Tailing files

The following source checks the access.log file every second for new messages.

source s_tail { file("/var/log/apache/access.log"

            follow_freq(1) flags(no-parse)); };
[Note] Note

If the message does not have a proper syslog header, syslog-ng treats messages received from files as sent by the kern facility. Use the default-facility and default-priority options in the source definition to assign a different facility if needed.

6.3.1. Notes on reading kernel messages

Note the following points when reading kernel messages on various platforms.

  • The kernel usually sends log messages to a special file (/dev/kmsg on BSDs, /proc/kmsg on Linux). The file() driver reads log messages from such files. The syslog-ng application can periodically check the file for new log messages if the follow_freq() option is set.

  • On Linux, the klogd daemon can be used in addition to syslog-ng to read kernel messages and forward them to syslog-ng. klogd used to preprocess kernel messages to resolve symbols and so on, but as this is deprecated by ksymoops there is really no point in running both klogd and syslog-ng in parallel. Also note that running two processes reading /proc/kmsg at the same time might result in dead-locks.

  • When using syslog-ng to read messages from the /proc/kmsg file, syslog-ng automatically disables the follow_freq() parameter to avoid blocking the file.

  • To read the kernel messages on HP-UX platforms, use the following options in the source statement:

    file("/dev/klog" program_override("kernel") flags(kernel) follow_freq(0));

6.3.2. file() source options

The file() driver has the following options:

default-facility()

Type: facility string
Default: kern

Description: This parameter assigns a facility value to the messages received from the file source, if the message does not specify one.

default-priority()

Type: priority string
Default:  

Description: This parameter assigns an emergency level to the messages received from the file source, if the message does not specify one.

file()

Type: filename with path
Default:  

Description: The file to read messages from.

encoding()

Type: string
Default:  

Description: Specifies the characterset (encoding, for example UTF-8) of messages using the legacy BSD-syslog protocol. To list the available character sets on a host, execute the iconv -l command.

flags()

Type: empty-lines, kernel, no-multi-line, no-parse, store-legacy-msghdr, syslog-protocol, validate-utf8
Default: empty set

Description: Specifies the log parsing options of the source.

  • empty-lines: Use the empty-lines flag to keep the empty lines of the messages. By default, syslog-ng OSE removes empty lines automatically.

  • expect-hostname: If the expect-hostname flag is enabled, syslog-ng OSE will assume that the log message contains a hostname and parse the message accordingly. This is the default behavior for TCP sources. Note that pipe sources use the no-hostname flag by default.

  • kernel: The kernel flag makes the source default to the LOG_KERN | LOG_CRIT priority if not specified otherwise.

  • no-hostname: Enable the no-hostname flag if the log message does not include the hostname of the sender host. That way syslog-ng OSE assumes that the first part of the message header is $PROGRAM instead of $HOST. For example:

    source s_dell { udp(port(2000) flags(no-hostname)); };
  • no-multi-line: The no-multi-line flag disables line-breaking in the messages; the entire message is converted to a single line. Note that this happens only if the underlying transport method actually supports multi-line messages. Currently the syslog, udp, unix-dgram drivers support multi-line messages; other drivers, for example, the tcp driver does not.

  • no-parse: By default, syslog-ng OSE parses incoming messages as syslog messages. The no-parse flag completely disables syslog message parsing and processes the complete line as the message part of a syslog message. The syslog-ng OSE application will generate a new syslog header (timestamp, host, and so on) automatically and put the entire incoming message into the MSG part of the syslog message. This flag is useful for parsing messages not complying to the syslog format.

  • store-legacy-msghdr: If the store-legacy-msghdr flag is enabled, syslog-ng stores the original incoming header of the log message. This is useful of the original format of a non-syslog-compliant message must be retained (syslog-ng automatically corrects minor header errors, for example, adds a whitespace before msg in the following message: Jan 22 10:06:11 host program:msg). Note that store-legacy-msghdr should be enabled when receiving messages from syslog-ng Agent for Windows clients that use the Snare-compatible mode.

  • syslog-protocol: The syslog-protocol flag specifies that incoming messages are expected to be formatted according to the new IETF syslog protocol standard (RFC5424), but without the frame header. Note that this flag is not needed for the syslog driver, which handles only messages that have a frame header.

  • validate-utf8: The validate-utf8 flag enables encoding-verification for messages formatted according to the new IETF syslog standard (for details, see Section 2.9.2, IETF-syslog messages). If the BOM[5] character is missing, but the message is otherwise UTF-8 compliant, syslog-ng automatically adds the BOM character to the message.

follow_freq()

Type: number
Default: 1

Description: Indicates that the source should be checked periodically. This is useful for files which always indicate readability, even though no new lines were appended. If this value is higher than zero, syslog-ng will not attempt to use poll() on the file, but checks whether the file changed every time the follow_freq() interval (in seconds) has elapsed. Floating-point numbers (for example 1.5) can be used as well.

keep_timestamp()

Type: yes or no
Default: yes

Description: Specifies whether syslog-ng should accept the timestamp received from the sending application or client. If disabled, the time of reception will be used instead. This option can be specified globally, and per-source as well. The local setting of the source overrides the global option if available.

log_fetch_limit()

Type: number
Default: The value specified by the global log_fetch_limit() option, which defaults to 10.

Description: The maximum number of messages fetched from a source during a single poll loop. The destination queues might fill up before flow-control could stop reading if log_fetch_limit() is too high.

log_iw_size()

Type: number
Default: 1000

Description: The size of the initial window, this value is used during flow control. If the max-connections() option is set, the log_iw_size() will be divided by the number of connections, otherwise log_iw_size() is divided by 10 (the default value of the max-connections() option). The resulting number is the initial window size of each connection.

[Example] Example 6.8. Initial window size of a connection

If log_iw_size(1000) and max-connections(10), then each connection will have an initial window size of 100.

log_msg_size()

Type: number
Default: Use the global log_msg_size() option, which defaults to 8192.

Description: Specifies the maximum length of incoming log messages. Uses the value of the global option if not specified.

log_prefix() (DEPRECATED)

Type: string
Default:  

Description: A string added to the beginning of every log message. It can be used to add an arbitrary string to any log source, though it is most commonly used for adding kernel: to the kernel messages on Linux. NOTE: This option is deprecated. Use program_override() instead.

optional()

Type: yes or no
Default:  

Description: Instruct syslog-ng to ignore the error if a specific source cannot be initialized. No other attempts to initialize the source will be made until the configuration is reloaded. This option currently applies to the pipe(), unix-dgram, and unix-stream drivers.

pad_size()

Type: number
Default: 0

Description: Specifies input padding. Some operating systems (such as HP-UX) pad all messages to block boundary. This option can be used to specify the block size. (HP-UX uses 2048 bytes). The syslog-ng OSE application will pad reads from the associated device to the number of bytes set in pad_size(). Mostly used on HP-UX where /dev/log is a named pipe and every write is padded to 2048 bytes. If pad_size was given and the incoming message does not fit into pad_size, syslog-ng will not read anymore from this pipe and displays the following error message:

Padding was set, and couldn't read enough bytes

program_override()

Type: string
Default:  

Description: Replaces the $PROGRAM part of the message with the parameter string. For example, to mark every message coming from the kernel, include the program_override("kernel") option in the source containing /proc/kmsg. NOTE: This option replaces the deprecated log_prefix() option.

tags()

Type: string
Default:  

Description: Label the messages received from the source with custom tags. Tags must be unique, and enclosed between double quotes. When adding multiple tags, separate them with comma, for example tags("dmz", "router"). This option is available only in syslog-ng 3.1 and later.

time_zone()

Type: timezone in +/-HH:MM format
Default:  

Description: The default timezone for messages read from the source. Applies only if no timezone is specified within the message itself.



[5] The byte order mark (BOM) is a Unicode character used to signal the byte-order of the message text.

6.4. Collecting messages from named pipes

The pipe driver opens a named pipe with the specified name and listens for messages. It is used as the native message delivery protocol on HP-UX.

The pipe driver has a single required parameter, specifying the filename of the pipe to open. For the list of available optional parameters, see Section 6.4.1, pipe() source options.

Declaration:

            pipe(filename);
[Note] Note

As of syslog-ng Open Source Edition 3.0.2, pipes are created automatically. In earlier versions, you had to create the pipe using the mkfifo(1) command.

Pipe is very similar to the file() driver, but there are a few differences, for example pipe() opens its argument in read-write mode, therefore it is not recommended to be used on special files like /proc/kmsg.

[Warning] Warning
  • It is not recommended to use pipe() on anything else than real pipes.

  • By default, syslog-ng OSE uses the flags(no-hostname) option for pipes, meaning that syslog-ng OSE assumes that the log messages received from the pipe do not contain the hostname field. If your messages do contain the hostname field, use flags(expect-hostname). For details, see Section flags().

[Example] Example 6.9. Using the pipe() driver
source s_pipe { pipe("/dev/pipe" pad_size(2048)); };

6.4.1. pipe() source options

The pipe driver has the following options:

flags()

Type: empty-lines, kernel, no-multi-line, no-parse, store-legacy-msghdr, syslog-protocol, validate-utf8
Default: empty set

Description: Specifies the log parsing options of the source.

  • empty-lines: Use the empty-lines flag to keep the empty lines of the messages. By default, syslog-ng OSE removes empty lines automatically.

  • expect-hostname: If the expect-hostname flag is enabled, syslog-ng OSE will assume that the log message contains a hostname and parse the message accordingly. This is the default behavior for TCP sources. Note that pipe sources use the no-hostname flag by default.

  • kernel: The kernel flag makes the source default to the LOG_KERN | LOG_CRIT priority if not specified otherwise.

  • no-hostname: Enable the no-hostname flag if the log message does not include the hostname of the sender host. That way syslog-ng OSE assumes that the first part of the message header is $PROGRAM instead of $HOST. For example:

    source s_dell { udp(port(2000) flags(no-hostname)); };
  • no-multi-line: The no-multi-line flag disables line-breaking in the messages; the entire message is converted to a single line. Note that this happens only if the underlying transport method actually supports multi-line messages. Currently the syslog, udp, unix-dgram drivers support multi-line messages; other drivers, for example, the tcp driver does not.

  • no-parse: By default, syslog-ng OSE parses incoming messages as syslog messages. The no-parse flag completely disables syslog message parsing and processes the complete line as the message part of a syslog message. The syslog-ng OSE application will generate a new syslog header (timestamp, host, and so on) automatically and put the entire incoming message into the MSG part of the syslog message. This flag is useful for parsing messages not complying to the syslog format.

  • store-legacy-msghdr: If the store-legacy-msghdr flag is enabled, syslog-ng stores the original incoming header of the log message. This is useful of the original format of a non-syslog-compliant message must be retained (syslog-ng automatically corrects minor header errors, for example, adds a whitespace before msg in the following message: Jan 22 10:06:11 host program:msg). Note that store-legacy-msghdr should be enabled when receiving messages from syslog-ng Agent for Windows clients that use the Snare-compatible mode.

  • syslog-protocol: The syslog-protocol flag specifies that incoming messages are expected to be formatted according to the new IETF syslog protocol standard (RFC5424), but without the frame header. Note that this flag is not needed for the syslog driver, which handles only messages that have a frame header.

  • validate-utf8: The validate-utf8 flag enables encoding-verification for messages formatted according to the new IETF syslog standard (for details, see Section 2.9.2, IETF-syslog messages). If the BOM[6] character is missing, but the message is otherwise UTF-8 compliant, syslog-ng automatically adds the BOM character to the message.

follow_freq()

Type: number
Default: 1

Description: Indicates that the source should be checked periodically. This is useful for files which always indicate readability, even though no new lines were appended. If this value is higher than zero, syslog-ng will not attempt to use poll() on the file, but checks whether the file changed every time the follow_freq() interval (in seconds) has elapsed. Floating-point numbers (for example 1.5) can be used as well.

keep_timestamp()

Type: yes or no
Default: yes

Description: Specifies whether syslog-ng should accept the timestamp received from the sending application or client. If disabled, the time of reception will be used instead. This option can be specified globally, and per-source as well. The local setting of the source overrides the global option if available.

log_fetch_limit()

Type: number
Default: The value specified by the global log_fetch_limit() option, which defaults to 10.

Description: The maximum number of messages fetched from a source during a single poll loop. The destination queues might fill up before flow-control could stop reading if log_fetch_limit() is too high.

log_iw_size()

Type: number
Default: 1000

Description: The size of the initial window, this value is used during flow control. If the max-connections() option is set, the log_iw_size() will be divided by the number of connections, otherwise log_iw_size() is divided by 10 (the default value of the max-connections() option). The resulting number is the initial window size of each connection.

[Example] Example 6.10. Initial window size of a connection

If log_iw_size(1000) and max-connections(10), then each connection will have an initial window size of 100.

log_msg_size()

Type: number
Default: Use the global log_msg_size() option, which defaults to 8192.

Description: Specifies the maximum length of incoming log messages. Uses the value of the global option if not specified.

log_prefix() (DEPRECATED)

Type: string
Default:  

Description: A string added to the beginning of every log message. It can be used to add an arbitrary string to any log source, though it is most commonly used for adding kernel: to the kernel messages on Linux. NOTE: This option is deprecated. Use program_override() instead.

optional()

Type: yes or no
Default:  

Description: Instruct syslog-ng to ignore the error if a specific source cannot be initialized. No other attempts to initialize the source will be made until the configuration is reloaded. This option currently applies to the pipe(), unix-dgram, and unix-stream drivers.

pad_size()

Type: number
Default: 0

Description: Specifies input padding. Some operating systems (such as HP-UX) pad all messages to block boundary. This option can be used to specify the block size. (HP-UX uses 2048 bytes). The syslog-ng OSE application will pad reads from the associated device to the number of bytes set in pad_size(). Mostly used on HP-UX where /dev/log is a named pipe and every write is padded to 2048 bytes. If pad_size was given and the incoming message does not fit into pad_size, syslog-ng will not read anymore from this pipe and displays the following error message:

Padding was set, and couldn't read enough bytes

pipe()

Type: filename with path
Default:  

Description: The filename of the pipe to read messages from.

program_override()

Type: string
Default:  

Description: Replaces the $PROGRAM part of the message with the parameter string. For example, to mark every message coming from the kernel, include the program_override("kernel") option in the source containing /proc/kmsg. NOTE: This option replaces the deprecated log_prefix() option.

tags()

Type: string
Default:  

Description: Label the messages received from the source with custom tags. Tags must be unique, and enclosed between double quotes. When adding multiple tags, separate them with comma, for example tags("dmz", "router"). This option is available only in syslog-ng 3.1 and later.

time_zone()

Type: timezone in +/-HH:MM format
Default:  

Description: The default timezone for messages read from the source. Applies only if no timezone is specified within the message itself.



[6] The byte order mark (BOM) is a Unicode character used to signal the byte-order of the message text.

6.5. Collecting process accounting logs on Linux

Starting with version 3.2, syslog-ng OSE can collect process accounting logs on Linux systems.Process accounting is the method of recording and summarizing commands executed on Linux, for example, the commands being run, the user who executed the command, CPU time used by the process, exit code, and so on. When process accounting (also called pacct) is enabled on a system, the kernel writes accounting records to the /var/log/account/pacct file (might vary between different Linux distributions).

To use the pacct() driver, the following conditions must be met:

  • The syslog-ng OSE application must be compiled with the --enable-pacct option. Execute the syslog-ng -V command to check if your binary supports process accounting.

  • The pacctformat plugin must be loaded. By default, syslog-ng OSE automatically loads the available modules.

  • The scl.conf file must be included in your syslog-ng configuration:

    @include "scl.conf"
  • Process accounting must be running on the host. You can enable it with the accton command.

The pacct() driver parses the fields of the accounting logs and transforms them into name-value pairs. The fields are defined in the manual page of the accounting log file (man acct), syslog-ng OSE prepends every field with the .pacct. prefix. For example, the ac_uid field that contains the id of the user who started the process will be available under the $.pacct.ac_uid name. These can be used as macros in templates, in filters to select specific messages, and so on.

To use the pacct() driver, use the following syntax.

@version: @techversion;

@include "scl.conf"

source s_pacct { pacct(); };

...

log { source(s_pacct); destination(...); };

6.5.1. pacct() options

The pacct() driver has the following options:

file

Type: filename with path
Default: /var/log/account/pacct

Description: The file where the process accounting logs are stored — syslog-ng OSE reads accounting messages from this file.

follow_freq()

Type: number
Default: 1

Description: Indicates that the source should be checked periodically. This is useful for files which always indicate readability, even though no new lines were appended. If this value is higher than zero, syslog-ng will not attempt to use poll() on the file, but checks whether the file changed every time the follow_freq() interval (in seconds) has elapsed. Floating-point numbers (for example 1.5) can be used as well.

6.6. Receiving messages from external applications

The program driver starts an external application and reads messages from the standard output (stdout) of the application. It is mainly useful to receive log messages from daemons that accept incoming messages and convert them to log messages.

The program driver has a single required parameter, specifying the name of the application to start.

Declaration:

program(filename);
[Example] Example 6.11. Using the program() driver
source s_program { program("/etc/init.d/mydaemon"); };
[Note] Note

The program is restarted automatically if it exits.

6.6.1. program() source options

The program driver has the following options:

flags()

Type: empty-lines, kernel, no-multi-line, no-parse, store-legacy-msghdr, syslog-protocol, validate-utf8
Default: empty set

Description: Specifies the log parsing options of the source.

  • empty-lines: Use the empty-lines flag to keep the empty lines of the messages. By default, syslog-ng OSE removes empty lines automatically.

  • expect-hostname: If the expect-hostname flag is enabled, syslog-ng OSE will assume that the log message contains a hostname and parse the message accordingly. This is the default behavior for TCP sources. Note that pipe sources use the no-hostname flag by default.

  • kernel: The kernel flag makes the source default to the LOG_KERN | LOG_CRIT priority if not specified otherwise.

  • no-hostname: Enable the no-hostname flag if the log message does not include the hostname of the sender host. That way syslog-ng OSE assumes that the first part of the message header is $PROGRAM instead of $HOST. For example:

    source s_dell { udp(port(2000) flags(no-hostname)); };
  • no-multi-line: The no-multi-line flag disables line-breaking in the messages; the entire message is converted to a single line. Note that this happens only if the underlying transport method actually supports multi-line messages. Currently the syslog, udp, unix-dgram drivers support multi-line messages; other drivers, for example, the tcp driver does not.

  • no-parse: By default, syslog-ng OSE parses incoming messages as syslog messages. The no-parse flag completely disables syslog message parsing and processes the complete line as the message part of a syslog message. The syslog-ng OSE application will generate a new syslog header (timestamp, host, and so on) automatically and put the entire incoming message into the MSG part of the syslog message. This flag is useful for parsing messages not complying to the syslog format.

  • store-legacy-msghdr: If the store-legacy-msghdr flag is enabled, syslog-ng stores the original incoming header of the log message. This is useful of the original format of a non-syslog-compliant message must be retained (syslog-ng automatically corrects minor header errors, for example, adds a whitespace before msg in the following message: Jan 22 10:06:11 host program:msg). Note that store-legacy-msghdr should be enabled when receiving messages from syslog-ng Agent for Windows clients that use the Snare-compatible mode.

  • syslog-protocol: The syslog-protocol flag specifies that incoming messages are expected to be formatted according to the new IETF syslog protocol standard (RFC5424), but without the frame header. Note that this flag is not needed for the syslog driver, which handles only messages that have a frame header.

  • validate-utf8: The validate-utf8 flag enables encoding-verification for messages formatted according to the new IETF syslog standard (for details, see Section 2.9.2, IETF-syslog messages). If the BOM[7] character is missing, but the message is otherwise UTF-8 compliant, syslog-ng automatically adds the BOM character to the message.

follow_freq()

Type: number
Default: 1

Description: Indicates that the source should be checked periodically. This is useful for files which always indicate readability, even though no new lines were appended. If this value is higher than zero, syslog-ng will not attempt to use poll() on the file, but checks whether the file changed every time the follow_freq() interval (in seconds) has elapsed. Floating-point numbers (for example 1.5) can be used as well.

keep_timestamp()

Type: yes or no
Default: yes

Description: Specifies whether syslog-ng should accept the timestamp received from the sending application or client. If disabled, the time of reception will be used instead. This option can be specified globally, and per-source as well. The local setting of the source overrides the global option if available.

log_fetch_limit()

Type: number
Default: The value specified by the global log_fetch_limit() option, which defaults to 10.

Description: The maximum number of messages fetched from a source during a single poll loop. The destination queues might fill up before flow-control could stop reading if log_fetch_limit() is too high.

log_iw_size()

Type: number
Default: 1000

Description: The size of the initial window, this value is used during flow control. If the max-connections() option is set, the log_iw_size() will be divided by the number of connections, otherwise log_iw_size() is divided by 10 (the default value of the max-connections() option). The resulting number is the initial window size of each connection.

[Example] Example 6.12. Initial window size of a connection

If log_iw_size(1000) and max-connections(10), then each connection will have an initial window size of 100.

log_msg_size()

Type: number
Default: Use the global log_msg_size() option, which defaults to 8192.

Description: Specifies the maximum length of incoming log messages. Uses the value of the global option if not specified.

log_prefix() (DEPRECATED)

Type: string
Default:  

Description: A string added to the beginning of every log message. It can be used to add an arbitrary string to any log source, though it is most commonly used for adding kernel: to the kernel messages on Linux. NOTE: This option is deprecated. Use program_override() instead.

optional()

Type: yes or no
Default:  

Description: Instruct syslog-ng to ignore the error if a specific source cannot be initialized. No other attempts to initialize the source will be made until the configuration is reloaded. This option currently applies to the pipe(), unix-dgram, and unix-stream drivers.

pad_size()

Type: number
Default: 0

Description: Specifies input padding. Some operating systems (such as HP-UX) pad all messages to block boundary. This option can be used to specify the block size. (HP-UX uses 2048 bytes). The syslog-ng OSE application will pad reads from the associated device to the number of bytes set in pad_size(). Mostly used on HP-UX where /dev/log is a named pipe and every write is padded to 2048 bytes. If pad_size was given and the incoming message does not fit into pad_size, syslog-ng will not read anymore from this pipe and displays the following error message:

Padding was set, and couldn't read enough bytes

program

Type: filename with path
Default:  

Description: The name of the application to start and read messages from.

program_override()

Type: string
Default:  

Description: Replaces the $PROGRAM part of the message with the parameter string. For example, to mark every message coming from the kernel, include the program_override("kernel") option in the source containing /proc/kmsg. NOTE: This option replaces the deprecated log_prefix() option.

tags()

Type: string
Default:  

Description: Label the messages received from the source with custom tags. Tags must be unique, and enclosed between double quotes. When adding multiple tags, separate them with comma, for example tags("dmz", "router"). This option is available only in syslog-ng 3.1 and later.

time_zone()

Type: timezone in +/-HH:MM format
Default:  

Description: The default timezone for messages read from the source. Applies only if no timezone is specified within the message itself.



[7] The byte order mark (BOM) is a Unicode character used to signal the byte-order of the message text.

6.7. Collecting messages on Sun Solaris

Solaris uses its STREAMS framework to send messages to the syslogd process. Solaris 2.5.1 and above uses an IPC called door in addition to STREAMS, to confirm the delivery of a message. The syslog-ng application supports the IPC mechanism via the door() option (see below).

[Note] Note

The sun-streams() driver must be enabled when the syslog-ng application is compiled (see ./configure --help).

The sun-streams() driver has a single required argument specifying the STREAMS device to open, and the door() option. For the list of available optional parameters, see Section 6.7.1, sun-streams() source options.

Declaration:

    sun-streams(name_of_the_streams_device door(filename_of_the_door));
[Example] Example 6.13. Using the sun-streams() driver
source s_stream { sun-streams("/dev/log" door("/etc/.syslog_door")); };

6.7.1. sun-streams() source options

The sun-streams() driver has the following options.

door()

Type: string
Default: none

Description: Specifies the filename of a door to open, needed on Solaris above 2.5.1.

flags()

Type: empty-lines, kernel, no-multi-line, no-parse, store-legacy-msghdr, syslog-protocol, validate-utf8
Default: empty set

Description: Specifies the log parsing options of the source.

  • empty-lines: Use the empty-lines flag to keep the empty lines of the messages. By default, syslog-ng OSE removes empty lines automatically.

  • expect-hostname: If the expect-hostname flag is enabled, syslog-ng OSE will assume that the log message contains a hostname and parse the message accordingly. This is the default behavior for TCP sources. Note that pipe sources use the no-hostname flag by default.

  • kernel: The kernel flag makes the source default to the LOG_KERN | LOG_CRIT priority if not specified otherwise.

  • no-hostname: Enable the no-hostname flag if the log message does not include the hostname of the sender host. That way syslog-ng OSE assumes that the first part of the message header is $PROGRAM instead of $HOST. For example:

    source s_dell { udp(port(2000) flags(no-hostname)); };
  • no-multi-line: The no-multi-line flag disables line-breaking in the messages; the entire message is converted to a single line. Note that this happens only if the underlying transport method actually supports multi-line messages. Currently the syslog, udp, unix-dgram drivers support multi-line messages; other drivers, for example, the tcp driver does not.

  • no-parse: By default, syslog-ng OSE parses incoming messages as syslog messages. The no-parse flag completely disables syslog message parsing and processes the complete line as the message part of a syslog message. The syslog-ng OSE application will generate a new syslog header (timestamp, host, and so on) automatically and put the entire incoming message into the MSG part of the syslog message. This flag is useful for parsing messages not complying to the syslog format.

  • store-legacy-msghdr: If the store-legacy-msghdr flag is enabled, syslog-ng stores the original incoming header of the log message. This is useful of the original format of a non-syslog-compliant message must be retained (syslog-ng automatically corrects minor header errors, for example, adds a whitespace before msg in the following message: Jan 22 10:06:11 host program:msg). Note that store-legacy-msghdr should be enabled when receiving messages from syslog-ng Agent for Windows clients that use the Snare-compatible mode.

  • syslog-protocol: The syslog-protocol flag specifies that incoming messages are expected to be formatted according to the new IETF syslog protocol standard (RFC5424), but without the frame header. Note that this flag is not needed for the syslog driver, which handles only messages that have a frame header.

  • validate-utf8: The validate-utf8 flag enables encoding-verification for messages formatted according to the new IETF syslog standard (for details, see Section 2.9.2, IETF-syslog messages). If the BOM[8] character is missing, but the message is otherwise UTF-8 compliant, syslog-ng automatically adds the BOM character to the message.

follow_freq()

Type: number
Default: 1

Description: Indicates that the source should be checked periodically. This is useful for files which always indicate readability, even though no new lines were appended. If this value is higher than zero, syslog-ng will not attempt to use poll() on the file, but checks whether the file changed every time the follow_freq() interval (in seconds) has elapsed. Floating-point numbers (for example 1.5) can be used as well.

keep_timestamp()

Type: yes or no
Default: yes

Description: Specifies whether syslog-ng should accept the timestamp received from the sending application or client. If disabled, the time of reception will be used instead. This option can be specified globally, and per-source as well. The local setting of the source overrides the global option if available.

log_fetch_limit()

Type: number
Default: The value specified by the global log_fetch_limit() option, which defaults to 10.

Description: The maximum number of messages fetched from a source during a single poll loop. The destination queues might fill up before flow-control could stop reading if log_fetch_limit() is too high.

log_iw_size()

Type: number
Default: 1000

Description: The size of the initial window, this value is used during flow control. If the max-connections() option is set, the log_iw_size() will be divided by the number of connections, otherwise log_iw_size() is divided by 10 (the default value of the max-connections() option). The resulting number is the initial window size of each connection.

[Example] Example 6.14. Initial window size of a connection

If log_iw_size(1000) and max-connections(10), then each connection will have an initial window size of 100.

log_msg_size()

Type: number
Default: Use the global log_msg_size() option, which defaults to 8192.

Description: Specifies the maximum length of incoming log messages. Uses the value of the global option if not specified.

log_prefix() (DEPRECATED)

Type: string
Default:  

Description: A string added to the beginning of every log message. It can be used to add an arbitrary string to any log source, though it is most commonly used for adding kernel: to the kernel messages on Linux. NOTE: This option is deprecated. Use program_override() instead.

optional()

Type: yes or no
Default:  

Description: Instruct syslog-ng to ignore the error if a specific source cannot be initialized. No other attempts to initialize the source will be made until the configuration is reloaded. This option currently applies to the pipe(), unix-dgram, and unix-stream drivers.

pad_size()

Type: number
Default: 0

Description: Specifies input padding. Some operating systems (such as HP-UX) pad all messages to block boundary. This option can be used to specify the block size. (HP-UX uses 2048 bytes). The syslog-ng OSE application will pad reads from the associated device to the number of bytes set in pad_size(). Mostly used on HP-UX where /dev/log is a named pipe and every write is padded to 2048 bytes. If pad_size was given and the incoming message does not fit into pad_size, syslog-ng will not read anymore from this pipe and displays the following error message:

Padding was set, and couldn't read enough bytes

program_override()

Type: string
Default:  

Description: Replaces the $PROGRAM part of the message with the parameter string. For example, to mark every message coming from the kernel, include the program_override("kernel") option in the source containing /proc/kmsg. NOTE: This option replaces the deprecated log_prefix() option.

tags()

Type: string
Default:  

Description: Label the messages received from the source with custom tags. Tags must be unique, and enclosed between double quotes. When adding multiple tags, separate them with comma, for example tags("dmz", "router"). This option is available only in syslog-ng 3.1 and later.

time_zone()

Type: timezone in +/-HH:MM format
Default:  

Description: The default timezone for messages read from the source. Applies only if no timezone is specified within the message itself.



[8] The byte order mark (BOM) is a Unicode character used to signal the byte-order of the message text.

6.8. Collecting messages using the IETF syslog protocol

The syslog() driver can receive messages from the network using the standard IETF-syslog protocol (as described in RFC5424-28). UDP, TCP, and TLS-encrypted TCP can all be used to transport the messages.

[Note] Note

The syslog() driver can also receive BSD-syslog-formatted messages (described in RFC 3164, see Section 2.9.1, BSD-syslog or legacy-syslog messages) if they are sent using the IETF-syslog protocol.

In syslog-ng OSE versions 3.1 and earlier, the syslog() driver could handle only messages in the IETF-syslog (RFC 5424-28) format.

For the list of available optional parameters, see Section 6.8.1, syslog() source options.

Declaration:

        syslog(ip() port() transport() options());
[Example] Example 6.15. Using the syslog() driver

TCP source listening on the localhost on port 1999.

source s_syslog { syslog(ip(127.0.0.1) port(1999) transport("tcp")); };

UDP source with defaults.

source s_udp { syslog( transport("udp")); };

Encrypted source where the client is also authenticated. For details on the encryption settings, see Section 10.4, TLS options.

source s_syslog_tls{ syslog(

    ip(10.100.20.40)

    transport("tls")

    tls(

    peer-verify(required-trusted)

    ca_dir('/opt/syslog-ng/etc/syslog-ng/keys/ca.d/')

    key_file('/opt/syslog-ng/etc/syslog-ng/keys/server_privatekey.pem')

    cert_file('/opt/syslog-ng/etc/syslog-ng/keys/server_certificate.pem')

    )

    );};
[Warning] Warning

When receiving messages using the UDP protocol, increase the size of the UDP receive buffer on the receiver host (that is, the syslog-ng OSE server or relay receiving the messages). Note that on certain platforms, for example, on Red Hat Enterprise Linux 5, even low message load (~200 messages per second) can result in message loss, unless the so_rcvbuf() option of the source is increased. In such cases, you will need to increase the net.core.rmem_max parameter of the host (for example, to 1024000), but do not modify net.core.rmem_default parameter.

As a general rule, increase the so_rcvbuf() so that the buffer size in kilobytes is higher than the rate of incoming messages per second. For example, to receive 2000 messages per second, set the so_rcvbuf() at least to 2 097 152 bytes.

6.8.1. syslog() source options

The syslog() driver has the following options.

flags()

Type: empty-lines, kernel, no-multi-line, no-parse, store-legacy-msghdr, syslog-protocol, validate-utf8
Default: empty set

Description: Specifies the log parsing options of the source.

  • empty-lines: Use the empty-lines flag to keep the empty lines of the messages. By default, syslog-ng OSE removes empty lines automatically.

  • expect-hostname: If the expect-hostname flag is enabled, syslog-ng OSE will assume that the log message contains a hostname and parse the message accordingly. This is the default behavior for TCP sources. Note that pipe sources use the no-hostname flag by default.

  • kernel: The kernel flag makes the source default to the LOG_KERN | LOG_CRIT priority if not specified otherwise.

  • no-hostname: Enable the no-hostname flag if the log message does not include the hostname of the sender host. That way syslog-ng OSE assumes that the first part of the message header is $PROGRAM instead of $HOST. For example:

    source s_dell { udp(port(2000) flags(no-hostname)); };
  • no-multi-line: The no-multi-line flag disables line-breaking in the messages; the entire message is converted to a single line. Note that this happens only if the underlying transport method actually supports multi-line messages. Currently the syslog, udp, unix-dgram drivers support multi-line messages; other drivers, for example, the tcp driver does not.

  • no-parse: By default, syslog-ng OSE parses incoming messages as syslog messages. The no-parse flag completely disables syslog message parsing and processes the complete line as the message part of a syslog message. The syslog-ng OSE application will generate a new syslog header (timestamp, host, and so on) automatically and put the entire incoming message into the MSG part of the syslog message. This flag is useful for parsing messages not complying to the syslog format.

  • store-legacy-msghdr: If the store-legacy-msghdr flag is enabled, syslog-ng stores the original incoming header of the log message. This is useful of the original format of a non-syslog-compliant message must be retained (syslog-ng automatically corrects minor header errors, for example, adds a whitespace before msg in the following message: Jan 22 10:06:11 host program:msg). Note that store-legacy-msghdr should be enabled when receiving messages from syslog-ng Agent for Windows clients that use the Snare-compatible mode.

  • syslog-protocol: The syslog-protocol flag specifies that incoming messages are expected to be formatted according to the new IETF syslog protocol standard (RFC5424), but without the frame header. Note that this flag is not needed for the syslog driver, which handles only messages that have a frame header.

  • validate-utf8: The validate-utf8 flag enables encoding-verification for messages formatted according to the new IETF syslog standard (for details, see Section 2.9.2, IETF-syslog messages). If the BOM[9] character is missing, but the message is otherwise UTF-8 compliant, syslog-ng automatically adds the BOM character to the message.

follow_freq()

Type: number
Default: 1

Description: Indicates that the source should be checked periodically. This is useful for files which always indicate readability, even though no new lines were appended. If this value is higher than zero, syslog-ng will not attempt to use poll() on the file, but checks whether the file changed every time the follow_freq() interval (in seconds) has elapsed. Floating-point numbers (for example 1.5) can be used as well.

host_override()

Type: string
Default:  

Description: Replaces the $HOST part of the message with the parameter string.

ip() or localip()

Type: string
Default: 0.0.0.0

Description: The IP address to bind to. Note that this is not the address where messages are accepted from.

ip_tos()

Type: number
Default: 0

Description: Specifies the Type-of-Service value of outgoing packets.

ip_ttl()

Type: number
Default: 0

Description: Specifies the Time-To-Live value of outgoing packets.

keep-alive()

Type: yes or no
Default: yes

Description: Specifies whether connections to sources should be closed when syslog-ng is forced to reload its configuration (upon the receipt of a SIGHUP signal). Note that this applies to the server (source) side of the syslog-ng connections, client-side (destination) connections are always reopened after receiving a HUP signal unless the keep-alive option is enabled for the destination.

keep_hostname()

Type: yes or no
Default: no

Description: Enable or disable hostname rewriting.

  • If enabled (keep_hostname(yes)), syslog-ng OSE assumes that the incoming log message was sent by the host specified in the HOST field of the message.

  • If disabled (keep_hostname(no)), syslog-ng OSE rewrites the HOST field of the message, either to the IP address (if the use_dns() parameter is set to no), or to the hostname (if the use_dns() parameter is set to yes and the IP address can be resolved to a hostname) of the host sending the message to syslog-ng OSE. For details on using name resolution in syslog-ng OSE, see Section 17.4, Using name resolution in syslog-ng.

[Note] Note

If the log message does not contain a hostname in its HOST field, syslog-ng OSE automatically adds a hostname to the message.

  • For messages received from the network, this hostname is the address of the host that sent the message (this means the address of the last hop if the message was transferred via a relay).

  • For messages received from the local host, syslog-ng OSE adds the name of the host.

This option can be specified globally, and per-source as well. The local setting of the source overrides the global option if available.

[Note] Note

When relaying messages, enable this option on the syslog-ng OSE server and also on every relay, otherwise syslog-ng OSE will treat incoming messages as if they were sent by the last relay.

keep_timestamp()

Type: yes or no
Default: yes

Description: Specifies whether syslog-ng should accept the timestamp received from the sending application or client. If disabled, the time of reception will be used instead. This option can be specified globally, and per-source as well. The local setting of the source overrides the global option if available.

log_fetch_limit()

Type: number
Default: The value specified by the global log_fetch_limit() option, which defaults to 10.

Description: The maximum number of messages fetched from a source during a single poll loop. The destination queues might fill up before flow-control could stop reading if log_fetch_limit() is too high.

log_iw_size()

Type: number
Default: 1000

Description: The size of the initial window, this value is used during flow control. If the max-connections() option is set, the log_iw_size() will be divided by the number of connections, otherwise log_iw_size() is divided by 10 (the default value of the max-connections() option). The resulting number is the initial window size of each connection.

[Example] Example 6.16. Initial window size of a connection

If log_iw_size(1000) and max-connections(10), then each connection will have an initial window size of 100.

log_msg_size()

Type: number
Default: Use the global log_msg_size() option, which defaults to 8192.

Description: Specifies the maximum length of incoming log messages. Uses the value of the global option if not specified.

log_prefix() (DEPRECATED)

Type: string
Default:  

Description: A string added to the beginning of every log message. It can be used to add an arbitrary string to any log source, though it is most commonly used for adding kernel: to the kernel messages on Linux. NOTE: This option is deprecated. Use program_override() instead.

max-connections()

Type: number
Default: 10

Description: Specifies the maximum number of simultaneous connections.

pad_size()

Type: number
Default: 0

Description: Specifies input padding. Some operating systems (such as HP-UX) pad all messages to block boundary. This option can be used to specify the block size. (HP-UX uses 2048 bytes). The syslog-ng OSE application will pad reads from the associated device to the number of bytes set in pad_size(). Mostly used on HP-UX where /dev/log is a named pipe and every write is padded to 2048 bytes. If pad_size was given and the incoming message does not fit into pad_size, syslog-ng will not read anymore from this pipe and displays the following error message:

Padding was set, and couldn't read enough bytes

port() or localport()

Type: number
Default: 601

Description: The port number to bind to.

program_override()

Type: string
Default:  

Description: Replaces the $PROGRAM part of the message with the parameter string. For example, to mark every message coming from the kernel, include the program_override("kernel") option in the source containing /proc/kmsg. NOTE: This option replaces the deprecated log_prefix() option.

so_broadcast()

Type: yes or no
Default: no

Description: This option controls the SO_BROADCAST socket option required to make syslog-ng send messages to a broadcast address. For details, see the socket(7) manual page.

so_keepalive()

Type: yes or no
Default: no

Description: Enables keep-alive messages, keeping the socket open. This only effects TCP and UNIX-stream sockets. For details, see the socket(7) manual page.

so_rcvbuf()

Type: number
Default: 0

Description: Specifies the size of the socket receive buffer in bytes. For details, see the socket(7) manual page.

[Warning] Warning

When receiving messages using the UDP protocol, increase the size of the UDP receive buffer on the receiver host (that is, the syslog-ng OSE server or relay receiving the messages). Note that on certain platforms, for example, on Red Hat Enterprise Linux 5, even low message load (~200 messages per second) can result in message loss, unless the so_rcvbuf() option of the source is increased. In such cases, you will need to increase the net.core.rmem_max parameter of the host (for example, to 1024000), but do not modify net.core.rmem_default parameter.

As a general rule, increase the so_rcvbuf() so that the buffer size in kilobytes is higher than the rate of incoming messages per second. For example, to receive 2000 messages per second, set the so_rcvbuf() at least to 2 097 152 bytes.

so_sndbuf()

Type: number
Default: 0

Description: Specifies the size of the socket send buffer in bytes. For details, see the socket(7) manual page.

tags()

Type: string
Default:  

Description: Label the messages received from the source with custom tags. Tags must be unique, and enclosed between double quotes. When adding multiple tags, separate them with comma, for example tags("dmz", "router"). This option is available only in syslog-ng 3.1 and later.

tcp-keep-alive()

Type: yes or no
Default: no

Description: This is an obsolete alias of the so_keepalive() option.

time_zone()

Type: timezone in +/-HH:MM format
Default:  

Description: The default timezone for messages read from the source. Applies only if no timezone is specified within the message itself.

transport()

Type: udp, tcp, or tls
Default: tcp

Description: Specifies the protocol used to receive messages from the source.

[Warning] Warning

When receiving messages using the UDP protocol, increase the size of the UDP receive buffer on the receiver host (that is, the syslog-ng OSE server or relay receiving the messages). Note that on certain platforms, for example, on Red Hat Enterprise Linux 5, even low message load (~200 messages per second) can result in message loss, unless the so_rcvbuf() option of the source is increased. In such cases, you will need to increase the net.core.rmem_max parameter of the host (for example, to 1024000), but do not modify net.core.rmem_default parameter.

As a general rule, increase the so_rcvbuf() so that the buffer size in kilobytes is higher than the rate of incoming messages per second. For example, to receive 2000 messages per second, set the so_rcvbuf() at least to 2 097 152 bytes.

tls()

Type: tls options
Default: n/a

Description: This option sets various TLS specific options like key/certificate files and trusted CA locations and can only be used with the tcp transport protocols. For details, see Section 10.4, TLS options.

use_dns()

Type: yes, no, persist_only
Default: yes

Description: Enable or disable DNS usage. The persist_only option attempts to resolve hostnames locally from file (for example from /etc/hosts). syslog-ng blocks on DNS queries, so enabling DNS may lead to a Denial of Service attack. To prevent DoS, protect your syslog-ng network endpoint with firewall rules, and make sure that all hosts which may get to syslog-ng are resolvable. This option can be specified globally, and per-source as well. The local setting of the source overrides the global option if available.

use_fqdn()

Type: yes or no
Default: no

Description: Add Fully Qualified Domain Name instead of short hostname. This option can be specified globally, and per-source as well. The local setting of the source overrides the global option if available.



[9] The byte order mark (BOM) is a Unicode character used to signal the byte-order of the message text.

6.9. Collecting the system-specific log messages of a platform

Starting with version 3.2, syslog-ng OSE can automatically collect the system-specific log messages of the host on a number of platforms using the system() driver. If the system() driver is included in the syslog-ng OSE configuration file, syslog-ng OSE executes the /opt/syslog-ng/scl/system/generate-system-source.sh script during startup, and adds the following sources to the syslog-ng OSE configuration.

The system() driver is also used in the default configuration file of syslog-ng OSE. For details on the default configuration file, see Example 4.1, The default configuration file of syslog-ng OSE.

[Warning] Warning

If syslog-ng OSE does not recognize the platform it is installed on, it does not add any sources.

Platform Message source
AIX and Tru64
unix-dgram("/dev/log");
FreeBSD
unix-dgram("/var/run/log");
unix-dgram("/var/run/logpriv" perm(0600));
file("/dev/klog" follow-freq(0) program-override("kernel") flags(no-parse));
GNU/kFreeBSD
unix-dgram("/var/run/log");
file("/dev/klog" follow-freq(0) program-override("kernel"));
HP-UX
pipe("/dev/log" pad_size(2048));
Linux
unix-dgram("/dev/log");
file("/proc/kmsg" program-override("kernel") flags(kernel));
Solaris 8
sun-streams("/dev/log");
Solaris 9
sun-streams("/dev/log" door("/etc/.syslog_door"));
Solaris 10
sun-streams("/dev/log" door("/var/run/syslog_door"));

Table 6.3. Sources automatically added by syslog-ng Open Source Edition


6.10. Collecting messages from remote hosts using the BSD syslog protocol

[Note] Note

Starting with syslog-ng OSE version 3.2, the syslog() source driver can handle both BSD-syslog (RFC 3164) and IETF-syslog (RFC 5424-28) messages. It is recommended to use the syslog() driver for both types of traffic, as the tcp(), tcp6(), udp(), udp6() source drivers will be deprecated in later versions.

The tcp(), tcp6(), udp(), udp6() drivers can receive syslog messages conforming to RFC3164 from the network using the TCP and UDP networking protocols. The tcp6() and udp6() drivers use the IPv6 network protocol, while tcp() and udp() use IPv4.

UDP is a simple datagram oriented protocol, which provides "best effort service" to transfer messages between hosts. It may lose messages, and no attempt is made at the protocol level to retransmit such lost messages. The BSD-syslog protocol traditionally uses UDP.

TCP provides connection-oriented service, which basically means that the path of the messages is flow-controlled. Along this path, each message is acknowledged, and retransmission is done for lost packets. Generally it is safer to use TCP, because lost connections can be detected, and no messages get lost, assuming that the TCP connection does not break. When a TCP connection is broken the 'in-transit' messages that were sent by syslog-ng but not yet received on the other side are lost. (Basically these messages are still sitting in the socket buffer of the sending host and syslog-ng has no information about the fate of these messages).

The tcp() and udp() drivers do not have any required parameters. By default they bind to the 0.0.0.0:514 address, which means that syslog-ng will listen on all available interfaces, port 514. To limit accepted connections to only one interface, use the localip() parameter as described below. For the list of available optional parameters, see Section 6.10.1, tcp(), tcp6(), udp() and udp6() source options.

Declaration:

            tcp([options]);

            udp([options]);
[Note] Note

The tcp port 514 is reserved for use with rshell, so select a different port if syslog-ng and rshell is used at the same time.

If you specify a multicast bind address to udp() and udp6(), syslog-ng will automatically join the necessary multicast group. TCP does not support multicasting.

The syslog-ng application supports TLS (Transport Layer Security, also known as SSL) for the tcp() and tcp6() drivers. For details, see the TLS-specific options below and Section 10.2, Encrypting log messages with TLS. For the list of available optional parameters, see Section 6.10.1, tcp(), tcp6(), udp() and udp6() source options.

[Tip] Tip

The syslog() driver also supports TLS-encrypted connections.

[Example] Example 6.17. Using the udp() and tcp() drivers

A simple udp() source with default settings.

source s_udp { udp(); };# An UDP source with default settings.

A TCP source listening on the localhost interface, with a limited number of connections allowed.

source s_tcp { tcp(ip(127.0.0.1) port(1999) max-connections(10)); };

A TCP source listening on a TLS-encrypted channel.

source s_tcp { tcp(ip(127.0.0.1) port(1999)

           tls(peer-verify('required-trusted')

               key_file('/opt/syslog-ng/etc/syslog-ng/syslog-ng.key')

           cert_file('/opt/syslog-ng/etc/syslog-ng/syslog-ng.crt')));

};

A TCP source listening for messages using the IETF-syslog message format. Note that for transferring IETF-syslog messages, generally you are recommended to use the syslog() driver on both the client and the server, as it uses both the IETF-syslog message format and the protocol. For details, see Section 6.8, Collecting messages using the IETF syslog protocol.

source s_tcp_syslog { tcp(ip(127.0.0.1) port(1999) flags(syslog-protocol) ); };

6.10.1. tcp(), tcp6(), udp() and udp6() source options

The tcp(), tcp6(), udp(), udp6() drivers can receive messages conforming to RFC3164 from the network using the TCP and UDP networking protocols.

The following options are valid for tcp(), tcp6(), udp(), and udp6() drivers:

[Warning] Warning

When receiving messages using the UDP protocol, increase the size of the UDP receive buffer on the receiver host (that is, the syslog-ng OSE server or relay receiving the messages). Note that on certain platforms, for example, on Red Hat Enterprise Linux 5, even low message load (~200 messages per second) can result in message loss, unless the so_rcvbuf() option of the source is increased. In such cases, you will need to increase the net.core.rmem_max parameter of the host (for example, to 1024000), but do not modify net.core.rmem_default parameter.

As a general rule, increase the so_rcvbuf() so that the buffer size in kilobytes is higher than the rate of incoming messages per second. For example, to receive 2000 messages per second, set the so_rcvbuf() at least to 2 097 152 bytes.

encoding()

Type: string
Default:  

Description: Specifies the characterset (encoding, for example UTF-8) of messages using the legacy BSD-syslog protocol. To list the available character sets on a host, execute the iconv -l command.

flags()

Type: empty-lines, kernel, no-multi-line, no-parse, store-legacy-msghdr, syslog-protocol, validate-utf8
Default: empty set

Description: Specifies the log parsing options of the source.

  • empty-lines: Use the empty-lines flag to keep the empty lines of the messages. By default, syslog-ng OSE removes empty lines automatically.

  • expect-hostname: If the expect-hostname flag is enabled, syslog-ng OSE will assume that the log message contains a hostname and parse the message accordingly. This is the default behavior for TCP sources. Note that pipe sources use the no-hostname flag by default.

  • kernel: The kernel flag makes the source default to the LOG_KERN | LOG_CRIT priority if not specified otherwise.

  • no-hostname: Enable the no-hostname flag if the log message does not include the hostname of the sender host. That way syslog-ng OSE assumes that the first part of the message header is $PROGRAM instead of $HOST. For example:

    source s_dell { udp(port(2000) flags(no-hostname)); };
  • no-multi-line: The no-multi-line flag disables line-breaking in the messages; the entire message is converted to a single line. Note that this happens only if the underlying transport method actually supports multi-line messages. Currently the syslog, udp, unix-dgram drivers support multi-line messages; other drivers, for example, the tcp driver does not.

  • no-parse: By default, syslog-ng OSE parses incoming messages as syslog messages. The no-parse flag completely disables syslog message parsing and processes the complete line as the message part of a syslog message. The syslog-ng OSE application will generate a new syslog header (timestamp, host, and so on) automatically and put the entire incoming message into the MSG part of the syslog message. This flag is useful for parsing messages not complying to the syslog format.

  • store-legacy-msghdr: If the store-legacy-msghdr flag is enabled, syslog-ng stores the original incoming header of the log message. This is useful of the original format of a non-syslog-compliant message must be retained (syslog-ng automatically corrects minor header errors, for example, adds a whitespace before msg in the following message: Jan 22 10:06:11 host program:msg). Note that store-legacy-msghdr should be enabled when receiving messages from syslog-ng Agent for Windows clients that use the Snare-compatible mode.

  • syslog-protocol: The syslog-protocol flag specifies that incoming messages are expected to be formatted according to the new IETF syslog protocol standard (RFC5424), but without the frame header. Note that this flag is not needed for the syslog driver, which handles only messages that have a frame header.

  • validate-utf8: The validate-utf8 flag enables encoding-verification for messages formatted according to the new IETF syslog standard (for details, see Section 2.9.2, IETF-syslog messages). If the BOM[10] character is missing, but the message is otherwise UTF-8 compliant, syslog-ng automatically adds the BOM character to the message.

host_override()

Type: string
Default:  

Description: Replaces the $HOST part of the message with the parameter string.

ip() or localip()

Type: string
Default: 0.0.0.0

Description: The IP address to bind to. Note that this is not the address where messages are accepted from.

keep-alive()

Type: yes or no
Default: yes

Description: Specifies whether connections to sources should be closed when syslog-ng is forced to reload its configuration (upon the receipt of a SIGHUP signal). Note that this applies to the server (source) side of the syslog-ng connections, client-side (destination) connections are always reopened after receiving a HUP signal unless the keep-alive option is enabled for the destination.

keep_hostname()

Type: yes or no
Default: no

Description: Enable or disable hostname rewriting.

  • If enabled (keep_hostname(yes)), syslog-ng OSE assumes that the incoming log message was sent by the host specified in the HOST field of the message.

  • If disabled (keep_hostname(no)), syslog-ng OSE rewrites the HOST field of the message, either to the IP address (if the use_dns() parameter is set to no), or to the hostname (if the use_dns() parameter is set to yes and the IP address can be resolved to a hostname) of the host sending the message to syslog-ng OSE. For details on using name resolution in syslog-ng OSE, see Section 17.4, Using name resolution in syslog-ng.

[Note] Note

If the log message does not contain a hostname in its HOST field, syslog-ng OSE automatically adds a hostname to the message.

  • For messages received from the network, this hostname is the address of the host that sent the message (this means the address of the last hop if the message was transferred via a relay).

  • For messages received from the local host, syslog-ng OSE adds the name of the host.

This option can be specified globally, and per-source as well. The local setting of the source overrides the global option if available.

[Note] Note

When relaying messages, enable this option on the syslog-ng OSE server and also on every relay, otherwise syslog-ng OSE will treat incoming messages as if they were sent by the last relay.

keep_timestamp()

Type: yes or no
Default: yes

Description: Specifies whether syslog-ng should accept the timestamp received from the sending application or client. If disabled, the time of reception will be used instead. This option can be specified globally, and per-source as well. The local setting of the source overrides the global option if available.

log_fetch_limit()

Type: number
Default: The value specified by the global log_fetch_limit() option, which defaults to 10.

Description: The maximum number of messages fetched from a source during a single poll loop. The destination queues might fill up before flow-control could stop reading if log_fetch_limit() is too high.

log_iw_size()

Type: number
Default: 1000

Description: The size of the initial window, this value is used during flow control. If the max-connections() option is set, the log_iw_size() will be divided by the number of connections, otherwise log_iw_size() is divided by 10 (the default value of the max-connections() option). The resulting number is the initial window size of each connection.

[Example] Example 6.18. Initial window size of a connection

If log_iw_size(1000) and max-connections(10), then each connection will have an initial window size of 100.

log_msg_size()

Type: number
Default: Use the global log_msg_size() option, which defaults to 8192.

Description: Specifies the maximum length of incoming log messages. Uses the value of the global option if not specified.

log_prefix() (DEPRECATED)

Type: string
Default:  

Description: A string added to the beginning of every log message. It can be used to add an arbitrary string to any log source, though it is most commonly used for adding kernel: to the kernel messages on Linux. NOTE: This option is deprecated. Use program_override() instead.

max-connections()

Type: number
Default: 10

Description: Specifies the maximum number of simultaneous connections.

Note that the udp() and udp6() drivers do not support this option.

pad_size()

Type: number
Default: 0

Description: Specifies input padding. Some operating systems (such as HP-UX) pad all messages to block boundary. This option can be used to specify the block size. (HP-UX uses 2048 bytes). The syslog-ng OSE application will pad reads from the associated device to the number of bytes set in pad_size(). Mostly used on HP-UX where /dev/log is a named pipe and every write is padded to 2048 bytes. If pad_size was given and the incoming message does not fit into pad_size, syslog-ng will not read anymore from this pipe and displays the following error message:

Padding was set, and couldn't read enough bytes

port() or localport()

Type: number
Default: 514

Description: The port number to bind to.

program_override()

Type: string
Default:  

Description: Replaces the $PROGRAM part of the message with the parameter string. For example, to mark every message coming from the kernel, include the program_override("kernel") option in the source containing /proc/kmsg. NOTE: This option replaces the deprecated log_prefix() option.

so_keepalive()

Type: yes or no
Default: no

Description: Enables keep-alive messages, keeping the socket open. This only effects TCP and UNIX-stream sockets. For details, see the socket(7) manual page.

so_rcvbuf()

Type: number
Default: 0

Description: Specifies the size of the socket receive buffer in bytes. For details, see the socket(7) manual page.

[Warning] Warning

When receiving messages using the UDP protocol, increase the size of the UDP receive buffer on the receiver host (that is, the syslog-ng OSE server or relay receiving the messages). Note that on certain platforms, for example, on Red Hat Enterprise Linux 5, even low message load (~200 messages per second) can result in message loss, unless the so_rcvbuf() option of the source is increased. In such cases, you will need to increase the net.core.rmem_max parameter of the host (for example, to 1024000), but do not modify net.core.rmem_default parameter.

As a general rule, increase the so_rcvbuf() so that the buffer size in kilobytes is higher than the rate of incoming messages per second. For example, to receive 2000 messages per second, set the so_rcvbuf() at least to 2 097 152 bytes.

tcp-keep-alive()

Type: yes or no
Default: no

Description: This is an obsolete alias of the so_keepalive() option.

tags()

Type: string
Default:  

Description: Label the messages received from the source with custom tags. Tags must be unique, and enclosed between double quotes. When adding multiple tags, separate them with comma, for example tags("dmz", "router"). This option is available only in syslog-ng 3.1 and later.

time_zone()

Type: timezone in +/-HH:MM format
Default:  

Description: The default timezone for messages read from the source. Applies only if no timezone is specified within the message itself.

tls()

Type: tls options
Default: n/a

Description: This option sets various TLS specific options like key/certificate files and trusted CA locations and can only be used with the tcp transport protocols. For details, see Section 10.4, TLS options.

use_dns()

Type: yes, no, persist_only
Default: yes

Description: Enable or disable DNS usage. The persist_only option attempts to resolve hostnames locally from file (for example from /etc/hosts). syslog-ng blocks on DNS queries, so enabling DNS may lead to a Denial of Service attack. To prevent DoS, protect your syslog-ng network endpoint with firewall rules, and make sure that all hosts which may get to syslog-ng are resolvable. This option can be specified globally, and per-source as well. The local setting of the source overrides the global option if available.

use_fqdn()

Type: yes or no
Default: no

Description: Add Fully Qualified Domain Name instead of short hostname. This option can be specified globally, and per-source as well. The local setting of the source overrides the global option if available.



[10] The byte order mark (BOM) is a Unicode character used to signal the byte-order of the message text.

6.11. Collecting messages from UNIX domain sockets

The unix-stream() and unix-dgram() drivers open an AF_UNIX socket and start listening on it for messages. The unix-stream() driver is primarily used on Linux and uses SOCK_STREAM semantics (connection oriented, no messages are lost); while unix-dgram() is used on BSDs and uses SOCK_DGRAM semantics: this may result in lost local messages if the system is overloaded.

To avoid denial of service attacks when using connection-oriented protocols, the number of simultaneously accepted connections should be limited. This can be achieved using the max-connections() parameter. The default value of this parameter is quite strict, you might have to increase it on a busy system.

Both unix-stream and unix-dgram have a single required argument that specifies the filename of the socket to create. For the list of available optional parameters, see Section 6.11.1, unix-stream() and unix-dgram() source options

Declaration:

            unix-stream(filename [options]);

            unix-dgram(filename [options]);
[Note] Note

syslogd on Linux originally used SOCK_STREAM sockets, but some distributions switched to SOCK_DGRAM around 1999 to fix a possible DoS problem. On Linux you can choose to use whichever driver you like as syslog clients automatically detect the socket type being used.

[Example] Example 6.19. Using the unix-stream() and unix-dgram() drivers
source s_stream { unix-stream("/dev/log" max-connections(10)); };
source s_dgram { unix-dgram("/var/run/log"); };

6.11.1. unix-stream() and unix-dgram() source options

These two drivers behave similarly: they open an AF_UNIX socket and start listening on it for messages. The following options can be specified for these divers:

encoding()

Type: string
Default:  

Description: Specifies the characterset (encoding, for example UTF-8) of messages using the legacy BSD-syslog protocol. To list the available character sets on a host, execute the iconv -l command.

flags()

Type: empty-lines, kernel, no-multi-line, no-parse, store-legacy-msghdr, syslog-protocol, validate-utf8
Default: empty set

Description: Specifies the log parsing options of the source.

  • empty-lines: Use the empty-lines flag to keep the empty lines of the messages. By default, syslog-ng OSE removes empty lines automatically.

  • expect-hostname: If the expect-hostname flag is enabled, syslog-ng OSE will assume that the log message contains a hostname and parse the message accordingly. This is the default behavior for TCP sources. Note that pipe sources use the no-hostname flag by default.

  • kernel: The kernel flag makes the source default to the LOG_KERN | LOG_CRIT priority if not specified otherwise.

  • no-hostname: Enable the no-hostname flag if the log message does not include the hostname of the sender host. That way syslog-ng OSE assumes that the first part of the message header is $PROGRAM instead of $HOST. For example:

    source s_dell { udp(port(2000) flags(no-hostname)); };
  • no-multi-line: The no-multi-line flag disables line-breaking in the messages; the entire message is converted to a single line. Note that this happens only if the underlying transport method actually supports multi-line messages. Currently the syslog, udp, unix-dgram drivers support multi-line messages; other drivers, for example, the tcp driver does not.

  • no-parse: By default, syslog-ng OSE parses incoming messages as syslog messages. The no-parse flag completely disables syslog message parsing and processes the complete line as the message part of a syslog message. The syslog-ng OSE application will generate a new syslog header (timestamp, host, and so on) automatically and put the entire incoming message into the MSG part of the syslog message. This flag is useful for parsing messages not complying to the syslog format.

  • store-legacy-msghdr: If the store-legacy-msghdr flag is enabled, syslog-ng stores the original incoming header of the log message. This is useful of the original format of a non-syslog-compliant message must be retained (syslog-ng automatically corrects minor header errors, for example, adds a whitespace before msg in the following message: Jan 22 10:06:11 host program:msg). Note that store-legacy-msghdr should be enabled when receiving messages from syslog-ng Agent for Windows clients that use the Snare-compatible mode.

  • syslog-protocol: The syslog-protocol flag specifies that incoming messages are expected to be formatted according to the new IETF syslog protocol standard (RFC5424), but without the frame header. Note that this flag is not needed for the syslog driver, which handles only messages that have a frame header.

  • validate-utf8: The validate-utf8 flag enables encoding-verification for messages formatted according to the new IETF syslog standard (for details, see Section 2.9.2, IETF-syslog messages). If the BOM[11] character is missing, but the message is otherwise UTF-8 compliant, syslog-ng automatically adds the BOM character to the message.

group()

Type: string
Default: root

Description: Set the gid of the socket.

host_override()

Type: string
Default:  

Description: Replaces the $HOST part of the message with the parameter string.

keep-alive()

Type: yes or no
Default: yes

Description: Selects whether to keep connections open when syslog-ng is restarted; cannot be used with unix-dgram().

keep_timestamp()

Type: yes or no
Default: yes

Description: Specifies whether syslog-ng should accept the timestamp received from the sending application or client. If disabled, the time of reception will be used instead. This option can be specified globally, and per-source as well. The local setting of the source overrides the global option if available.

log_fetch_limit()

Type: number
Default: The value specified by the global log_fetch_limit() option, which defaults to 10.

Description: The maximum number of messages fetched from a source during a single poll loop. The destination queues might fill up before flow-control could stop reading if log_fetch_limit() is too high.

log_iw_size()

Type: number
Default: 1000

Description: The size of the initial window, this value is used during flow control. If the max-connections() option is set, the log_iw_size() will be divided by the number of connections, otherwise log_iw_size() is divided by 10 (the default value of the max-connections() option). The resulting number is the initial window size of each connection.

[Example] Example 6.20. Initial window size of a connection

If log_iw_size(1000) and max-connections(10), then each connection will have an initial window size of 100.

log_msg_size()

Type: number
Default: Use the global log_msg_size() option, which defaults to 8192.

Description: Specifies the maximum length of incoming log messages. Uses the value of the global option if not specified.

log_prefix() (DEPRECATED)

Type: string
Default:  

Description: A string added to the beginning of every log message. It can be used to add an arbitrary string to any log source, though it is most commonly used for adding kernel: to the kernel messages on Linux. NOTE: This option is deprecated. Use program_override() instead.

max-connections()

Type: number
Default: 256

Description: Limits the number of simultaneously open connections. Cannot be used with unix-dgram().

optional()

Type: yes or no
Default:  

Description: Instruct syslog-ng to ignore the error if a specific source cannot be initialized. No other attempts to initialize the source will be made until the configuration is reloaded. This option currently applies to the pipe(), unix-dgram, and unix-stream drivers.

owner()

Type: string
Default: root

Description: Set the uid of the socket.

pad_size()

Type: number
Default: 0

Description: Specifies input padding. Some operating systems (such as HP-UX) pad all messages to block boundary. This option can be used to specify the block size. (HP-UX uses 2048 bytes). The syslog-ng OSE application will pad reads from the associated device to the number of bytes set in pad_size(). Mostly used on HP-UX where /dev/log is a named pipe and every write is padded to 2048 bytes. If pad_size was given and the incoming message does not fit into pad_size, syslog-ng will not read anymore from this pipe and displays the following error message:

Padding was set, and couldn't read enough bytes

perm()

Type: number
Default: 0666

Description: Set the permission mask. For octal numbers prefix the number with '0', for example: use 0755 for rwxr-xr-x.

program_override()

Type: string
Default:  

Description: Replaces the $PROGRAM part of the message with the parameter string. For example, to mark every message coming from the kernel, include the program_override("kernel") option in the source containing /proc/kmsg. NOTE: This option replaces the deprecated log_prefix() option.

so_keepalive()

Type: yes or no
Default: no

Description: Enables keep-alive messages, keeping the socket open. This only effects TCP and UNIX-stream sockets. For details, see the socket(7) manual page.

so_rcvbuf()

Type: number
Default: 0

Description: Specifies the size of the socket receive buffer in bytes. For details, see the socket(7) manual page.

[Warning] Warning

When receiving messages using the UDP protocol, increase the size of the UDP receive buffer on the receiver host (that is, the syslog-ng OSE server or relay receiving the messages). Note that on certain platforms, for example, on Red Hat Enterprise Linux 5, even low message load (~200 messages per second) can result in message loss, unless the so_rcvbuf() option of the source is increased. In such cases, you will need to increase the net.core.rmem_max parameter of the host (for example, to 1024000), but do not modify net.core.rmem_default parameter.

As a general rule, increase the so_rcvbuf() so that the buffer size in kilobytes is higher than the rate of incoming messages per second. For example, to receive 2000 messages per second, set the so_rcvbuf() at least to 2 097 152 bytes.

tags()

Type: string
Default:  

Description: Label the messages received from the source with custom tags. Tags must be unique, and enclosed between double quotes. When adding multiple tags, separate them with comma, for example tags("dmz", "router"). This option is available only in syslog-ng 3.1 and later.

time_zone()

Type: timezone in +/-HH:MM format
Default:  

Description: The default timezone for messages read from the source. Applies only if no timezone is specified within the message itself.



[11] The byte order mark (BOM) is a Unicode character used to signal the byte-order of the message text.

Chapter 7. Sending and storing log messages — destinations and destination drivers

A destination is where a log message is sent if the filtering rules match. Similarly to sources, destinations consist of one or more drivers, each defining where and how messages are sent.

[Tip] Tip

If no drivers are defined for a destination, all messages sent to the destination are discarded. This is equivalent to omitting the destination from the log statement.

To define a destination, add a destination statement to the syslog-ng configuration file using the following syntax:

destination <identifier> { 

                destination-driver(params); destination-driver(params); ... };

[Example] Example 7.1. A simple destination statement

The following destination statement sends messages to the TCP port 1999 of the 10.1.2.3 host.

destination d_demo_tcp { tcp("10.1.2.3" port(1999)); };

If name resolution is configured, the hostname of the target server can be used as well.

destination d_tcp { tcp("target_host" port(1999); localport(999)); };
[Note] Note

Sources and destinations are initialized only when they are used in a log statement. For example, syslog-ng OSE connects a remote destination only if the destination is used in a log statement. For details on creating log statements, see Chapter 8, Routing messages: log paths and filters.

The following table lists the destination drivers available in syslog-ng.

Name Description
file() Writes messages to the specified file.
pipe() Writes messages to the specified named pipe.
program() Forks and launches the specified program, and sends messages to its standard input.
sql() Sends messages into an SQL database. In addition to the standard syslog-ng packages, the sql() destination requires database-specific packages to be installed. Refer to the section appropriate for your platform in Chapter 3, Installing syslog-ng.
syslog() Sends messages to the specified remote host using the IETF-syslog protocol. The IETF standard supports message transport using the UDP, TCP, and TLS networking protocols.
tcp() and tcp6() Sends messages to the specified TCP port of a remote host using the BSD-syslog protocol over IPv4 and IPv6, respectively.
udp() and udp6() Sends messages to the specified UDP port of a remote host using the BSD-syslog protocol over IPv4 and IPv6, respectively.
unix-dgram() Sends messages to the specified unix socket in SOCK_DGRAM style (BSD).
unix-stream() Sends messages to the specified unix socket in SOCK_STREAM style (Linux).
usertty() Sends messages to the terminal of the specified user, if the user is logged in.

Table 7.1. Destination drivers available in syslog-ng


7.1. Storing messages in plain-text files

The file driver is one of the most important destination drivers in syslog-ng. It allows to output messages to the specified text file, or to a set of files.

The destination filename may include macros which get expanded when the message is written, thus a simple file() driver may create several files: for example, syslog-ng OSE can store the messages of client hosts in a separate file for each host. For more information on available macros see Section 11.1.5, Macros of syslog-ng OSE.

If the expanded filename refers to a directory which does not exist, it will be created depending on the create_dirs() setting (both global and a per destination option).

The file() has a single required parameter that specifies the filename that stores the log messages. For the list of available optional parameters, see Section 7.1.1, file() destination options.

Declaration:

                file(filename options());
[Example] Example 7.2. Using the file() driver
destination d_file { file("/var/log/messages" ); };
[Example] Example 7.3. Using the file() driver with macros in the file name and a template for the message
destination d_file {

        file("/var/log/$YEAR.$MONTH.$DAY/messages"

             template("$HOUR:$MIN:$SEC $TZ $HOST [$LEVEL] $MSG $MSG\n")

             template_escape(no));

};
[Note] Note

When using this destination, update the configuration of your log rotation program to rotate these files. Otherwise, the log files can become very large.

Also, after rotating the log files, reload syslog-ng OSE using the syslog-ng-ctl reload command, or use another method to send a SIGHUP to syslog-ng OSE.

[Warning] Warning

Since the state of each created file must be tracked by syslog-ng, it consumes some memory for each file. If no new messages are written to a file within 60 seconds (controlled by the time_reap() global option), it is closed, and its state is freed.

Exploiting this, a DoS attack can be mounted against the system. If the number of possible destination files and its needed memory is more than the amount available on the syslog-ng server.

The most suspicious macro is $PROGRAM, where the number of possible variations is rather high. Do not use the $PROGRAM macro in insecure environments.

7.1.1. file() destination options

The file() driver outputs messages to the specified text file, or to a set of files. The file() destination has the following options:

[Warning] Warning

When creating several thousands separate log files, syslog-ng might not be able to open the required number of files. This might happen for example when using the $HOST macro in the filename while receiving messages from a large number of hosts. To overcome this problem, adjust the --fd-limit comman-line parameter of syslog-ng or the global ulimit parameter of your host. For setting the --fd-limit comman-line parameter of syslog-ng see the syslog-ng(8) manual page. For setting the ulimit parameter of the host, see the documentation of your operating system.

create_dirs()

Type: yes or no
Default: no

Description: Enable creating non-existing directories.

dir_group()

Type: string
Default: root

Description: The group of directories created by syslog-ng.

dir_owner()

Type: string
Default: root

Description: The owner of directories created by syslog-ng.

dir_perm()

Type: number
Default: Use the global settings

Description: The permission mask of directories created by syslog-ng. Log directories are only created if a file after macro expansion refers to a non-existing directory, and directory creation is enabled (see also the create_dirs() option). For octal numbers prefix the number with 0, for example use 0755 for rwxr-xr-x.

To preserve the original properties of an existing directory, use the option without specifying an attribute: dir_perm(). Note that when creating a new directory without specifying attributes for dir_perm(), the default permission of the directories is masked with the umask of the parent process (typically 0022).

flags()

Type: no_multi_line, syslog-protocol
Default: empty set

Description: Flags influence the behavior of the destination driver.

  • no-multi-line: The no-multi-line flag disables line-breaking in the messages; the entire message is converted to a single line.

  • syslog-protocol: The syslog-protocol flag instructs the driver to format the messages according to the new IETF syslog protocol standard (RFC5424), but without the frame header. If this flag is enabled, macros used for the message have effect only for the text of the message, the message header is formatted to the new standard. Note that this flag is not needed for the syslog driver, and that the syslog driver automatically adds the frame header to the messages.

flush_lines()

Type: number
Default: Use global setting.

Description: Specifies how many lines are flushed to a destination at a time. Syslog-ng waits for this number of lines to accumulate and sends them off in a single batch. Setting this number high increases throughput as fully filled frames are sent to the destination, but also increases message latency. The latency can be limited by the use of the flush_timeout option.

flush_timeout()

Type: time in milliseconds
Default: Use global setting.

Description: Specifies the time syslog-ng waits for lines to accumulate in its output buffer. For details, see the flush_lines option.

frac_digits()

Type: number
Default: 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.

fsync()

Type: yes or no
Default: no

Description: Forces an fsync() call on the destination fd after each write. Note: enabling this option may seriously degrade performance.

group()

Type: string
Default: root

Description: Set the group of the created file to the one specified.

local_time_zone()

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 (for example +01:00). The valid timezone names are listed under the /usr/share/zoneinfo directory.

log_fifo_size()

Type: number
Default: Use global setting.

Description: The number of messages that the output queue can store.

overwrite_if_older()

Type: number
Default: 0

Description: If set to a value higher than 0, syslog-ng checks when the file was last modified before starting to write into the file. If the file is older than the specified amount of time (in seconds), then syslog-ng removes the existing file and opens a new file with the same name. In combination with for example the $WEEKDAY macro, this can be used for simple log rotation, in case not all history has to be kept. (Note that in this weekly log rotation example if its Monday 00:01, then the file from last Monday is not seven days old, because it was probably last modified shortly before 23:59 last Monday, so it is actually not even six days old. So in this case, set the overwrite_if_older() parameter to a-bit-less-than-six-days, for example, to 518000 seconds.

owner()

Type: string
Default: root

Description: Set the owner of the created file to the one specified.

pad_size()

Type: number
Default: 0

Description: If set, syslog-ng OSE will pad output messages to the specified size (in bytes). Some operating systems (such as HP-UX) pad all messages to block boundary. This option can be used to specify the block size. (HP-UX uses 2048 bytes).

[Warning] Warning

Hazard of data loss! If the size of the incoming message is larger than the previously set pad_size value, syslog-ng will truncate the message to the specified size. Therefore, all message content above that size will be lost.

perm()

Type: number
Default: 0600

Description: The permission mask of the file if it is created by syslog-ng. For octal numbers prefix the number with 0, for example use 0755 for rwxr-xr-x.

suppress()

Type: seconds
Default: 0 (disabled)

Description: If several identical log messages would be sent to the destination without any other messages between the identical messages (for example, an application repeated an error message ten times), syslog-ng can suppress the repeated messages and send the message only once, followed by the Last message repeated n times. message. The parameter of this option specifies the number of seconds syslog-ng waits for identical messages.

template()

Type: string
Default: A format conforming to the default logfile format.

Description: Specifies a template defining the logformat to be used in the destination. Macros are described in Section 11.1.5, Macros of syslog-ng OSE. Please note that for network destinations it might not be appropriate to change the template as it changes the on-wire format of the syslog protocol which might not be tolerated by stock syslog receivers (like syslogd or syslog-ng itself). For network destinations make sure the receiver can cope with the custom format defined.

template_escape()

Type: yes or no
Default: no

Description: Turns on escaping for the ', ", and backspace characters in templated output files. This is useful for generating SQL statements and quoting string contents so that parts of the log message are not interpreted as commands to the SQL server.

throttle()

Type: number
Default: 0

Description: Sets the maximum number of messages sent to the destination per second. Use this output-rate-limiting functionality only when using disk-buffer as well to avoid the risk of losing messages. Specifying 0 or a lower value sets the output limit to unlimited.

time_zone()

Type: timezone in +/-HH:MM format
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.

time_reap()

Accepted values: number
Default: Use global settings

Description: The time to wait in seconds before an idle destination file is closed. Note that only destination files having macros in their filenames are closed automatically.

ts_format()

Type: rfc3164, bsd, rfc3339, iso
Default: rfc3164

Description: Override the global timestamp format (set in the global ts_format() parameter) for the specific destination. For details, see Section 2.5.1, A note on timezones and timestamps.

7.2. Storing messages in a MongoDB database

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 Section 7.2.1, mongodb() destination options.

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.

[Example] Example 7.4. 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(

        host("localhost")

        port(27017)

        database("syslog")

        collection("messages")

        value-pairs(

            scope("selected-macros" "nv-pairs")

            exclude("R_*")

            exclude("S_*")

            exclude("HOST_FROM")

            exclude("LEGACY_MSGHDR")

            exclude("MSG")

            exclude("SDATA")

        )

    );

};

7.2.1. mongodb() destination options

The mongodb() driver sends messages to a MongoDB database. MongoDB is a schema-free, document-oriented database.

The mongodb() destination has the following options:

collection()

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.

[Warning] Warning

Hazard of data loss! The syslog-ng OSE 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.

database()

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.

[Warning] Warning

Hazard of data loss! The syslog-ng OSE 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.

frac_digits()

Type: number
Default: 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.

host()

Type: hostname or IP address
Default: localhost

Description: Hostname or IP address 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.

[Note] Note

If you specify host="localhost" (or use the default), syslog-ng OSE will use a socket to connect to the local database server. Use host="127.0.0.1" to force TCP communication between syslog-ng OSE and the local database server.

log_fifo_size()

Type: number
Default: Use global setting.

Description: The number of messages that the output queue can store.

port()

Type: number
Default: 27017

Description: The port number to connect to.

value-pairs()

Type: parameter list of the value-pairs() option
Default:
scope("selected-macros" "nv-pairs")

  exclude("R_*")

  exclude("S_*")

  exclude("HOST_FROM")

  exclude("LEGACY_MSGHDR")

  exclude("MSG")

  exclude("SDATA")

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 Section 2.9.4, Structuring macros, metadata, and other value-pairs.

[Note] Note

Empty keys are not logged.

7.3. Sending messages to named pipes

The pipe() driver sends messages to a named pipe like /dev/xconsole.

The pipe driver has a single required parameter, specifying the filename of the pipe to open. The filename can include macros. For the list of available optional parameters, see Section 7.3.1, pipe() destination options.

Declaration:

                pipe(filename);
[Warning] Warning

As of syslog-ng Open Source Edition 3.0.2, pipes are created automatically. In earlier versions, you had to create the pipe using the mkfifo(1) command.

[Example] Example 7.5. Using the pipe() driver
destination d_pipe { pipe("/dev/xconsole"); };

7.3.1. pipe() destination options

This driver sends messages to a named pipe like /dev/xconsole.

The pipe() destination has the following options:

flags()

Type: no_multi_line, syslog-protocol
Default: empty set

Description: Flags influence the behavior of the destination driver.

  • no-multi-line: The no-multi-line flag disables line-breaking in the messages; the entire message is converted to a single line.

  • syslog-protocol: The syslog-protocol flag instructs the driver to format the messages according to the new IETF syslog protocol standard (RFC5424), but without the frame header. If this flag is enabled, macros used for the message have effect only for the text of the message, the message header is formatted to the new standard. Note that this flag is not needed for the syslog driver, and that the syslog driver automatically adds the frame header to the messages.

flush_lines()

Type: number
Default: Use global setting.

Description: Specifies how many lines are flushed to a destination at a time. Syslog-ng waits for this number of lines to accumulate and sends them off in a single batch. Setting this number high increases throughput as fully filled frames are sent to the destination, but also increases message latency. The latency can be limited by the use of the flush_timeout option.

flush_timeout()

Type: time in milliseconds
Default: Use global setting.

Description: Specifies the time syslog-ng waits for lines to accumulate in its output buffer. For details, see the flush_lines option.

frac_digits()

Type: number
Default: 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.

group()

Type: string
Default: root

Description: Set the group of the pipe to the one specified.

log_fifo_size()

Type: number
Default: Use global setting.

Description: The number of messages that the output queue can store.

owner()

Type: string
Default: root

Description: Set the owner of the pipe to the one specified.

pad_size()

Type: number
Default: 0

Description: If set, syslog-ng OSE will pad output messages to the specified size (in bytes). Some operating systems (such as HP-UX) pad all messages to block boundary. This option can be used to specify the block size. (HP-UX uses 2048 bytes).

[Warning] Warning

Hazard of data loss! If the size of the incoming message is larger than the previously set pad_size value, syslog-ng will truncate the message to the specified size. Therefore, all message content above that size will be lost.

perm()

Type: number
Default: 0600

Description:The permission mask of the pipe. For octal numbers prefix the number with '0', for example: use 0755 for rwxr-xr-x.

suppress()

Type: seconds
Default: 0 (disabled)

Description: If several identical log messages would be sent to the destination without any other messages between the identical messages (for example, an application repeated an error message ten times), syslog-ng can suppress the repeated messages and send the message only once, followed by the Last message repeated n times. message. The parameter of this option specifies the number of seconds syslog-ng waits for identical messages.

template()

Type: string
Default: A format conforming to the default logfile format.

Description: Specifies a template defining the logformat to be used in the destination. Macros are described in Section 11.1.5, Macros of syslog-ng OSE. Please note that for network destinations it might not be appropriate to change the template as it changes the on-wire format of the syslog protocol which might not be tolerated by stock syslog receivers (like syslogd or syslog-ng itself). For network destinations make sure the receiver can cope with the custom format defined.

template_escape()

Type: yes or no
Default: no

Description: Turns on escaping for the ', ", and backspace characters in templated output files. This is useful for generating SQL statements and quoting string contents so that parts of the log message are not interpreted as commands to the SQL server.

throttle()

Type: number
Default: 0

Description: Sets the maximum number of messages sent to the destination per second. Use this output-rate-limiting functionality only when using disk-buffer as well to avoid the risk of losing messages. Specifying 0 or a lower value sets the output limit to unlimited.

time_zone()

Type: timezone in +/-HH:MM format
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.

ts_format()

Type: rfc3164, bsd, rfc3339, iso
Default: rfc3164

Description: Override the global timestamp format (set in the global ts_format() parameter) for the specific destination. For details, see Section 2.5.1, A note on timezones and timestamps.

7.4. Sending messages to external applications

The program() driver starts an external application or script and sends the log messages to its standard input (stdin).

The program() driver has a single required parameter, specifying a program name to start. The program is executed with the help of the current shell, so the command may include both file patterns and I/O redirections. For the list of available optional parameters, see Section 7.4.1, program() destination options.

Declaration: 

                program(command_to_run);
[Note] Note
  • The syslog-ng OSE application automatically restarts the external program if it exits for reliability reasons. However it is not recommended to launch programs for single messages, because if the message rate is high, launching several instances of an application might overload the system, resulting in Denial of Service.

  • Certain external applications buffer the log messages, which might cause unexpected latency and other problems. For example, if you send the log messages to an external Perl script, Perl uses a line buffer for terminal output and block buffer otherwise. You might want to disable buffering in the external application.

[Warning] Warning

The syslog-ng OSE application must be able to start and restart the external program, and have the necessary permissions to do so. For example, if your host is running AppArmor, you might have to modify your AppArmor configuration to enable syslog-ng OSE to execute external applications.

Note that the message format does not include the priority and facility values by default. To add these values, specify a template for the program destination, as shown in the following example.

[Example] Example 7.6. Using the program() destination driver
destination d_prog { program("/bin/script" template("<$PRI>$DATE $HOST $MSG\n") ); };

7.4.1. program() destination options

This driver starts an external application or script and sends the log messages to its standard input (stdin).

The program() destination has the following options:

flags()

Type: no_multi_line, syslog-protocol
Default: empty set

Description: Flags influence the behavior of the destination driver.

  • no-multi-line: The no-multi-line flag disables line-breaking in the messages; the entire message is converted to a single line.

  • syslog-protocol: The syslog-protocol flag instructs the driver to format the messages according to the new IETF syslog protocol standard (RFC5424), but without the frame header. If this flag is enabled, macros used for the message have effect only for the text of the message, the message header is formatted to the new standard. Note that this flag is not needed for the syslog driver, and that the syslog driver automatically adds the frame header to the messages.

flush_lines()

Type: number
Default: Use global setting.

Description: Specifies how many lines are flushed to a destination at a time. Syslog-ng waits for this number of lines to accumulate and sends them off in a single batch. Setting this number high increases throughput as fully filled frames are sent to the destination, but also increases message latency. The latency can be limited by the use of the flush_timeout option.

flush_timeout()

Type: time in milliseconds
Default: Use global setting.

Description: Specifies the time syslog-ng waits for lines to accumulate in its output buffer. For details, see the flush_lines option.

frac_digits()

Type: number
Default: 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.

log_fifo_size()

Type: number
Default: Use global setting.

Description: The number of messages that the output queue can store.

suppress()

Type: seconds
Default: 0 (disabled)

Description: If several identical log messages would be sent to the destination without any other messages between the identical messages (for example, an application repeated an error message ten times), syslog-ng can suppress the repeated messages and send the message only once, followed by the Last message repeated n times. message. The parameter of this option specifies the number of seconds syslog-ng waits for identical messages.

template()

Type: string
Default: A format conforming to the default logfile format.

Description: Specifies a template defining the logformat to be used in the destination. Macros are described in Section 11.1.5, Macros of syslog-ng OSE. Please note that for network destinations it might not be appropriate to change the template as it changes the on-wire format of the syslog protocol which might not be tolerated by stock syslog receivers (like syslogd or syslog-ng itself). For network destinations make sure the receiver can cope with the custom format defined.

template_escape()

Type: yes or no
Default: no

Description: Turns on escaping for the ', ", and backspace characters in templated output files. This is useful for generating SQL statements and quoting string contents so that parts of the log message are not interpreted as commands to the SQL server.

throttle()

Type: number
Default: 0

Description: Sets the maximum number of messages sent to the destination per second. Use this output-rate-limiting functionality only when using disk-buffer as well to avoid the risk of losing messages. Specifying 0 or a lower value sets the output limit to unlimited.

time_zone()

Type: timezone in +/-HH:MM format
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.

ts_format()

Type: rfc3164, bsd, rfc3339, iso
Default: rfc3164

Description: Override the global timestamp format (set in the global ts_format() parameter) for the specific destination. For details, see Section 2.5.1, A note on timezones and timestamps.

7.5. Storing messages in an SQL database

The sql() driver sends messages into an SQL database. Currently the Microsoft SQL (MSSQL), MySQL, Oracle, PostgreSQL, and SQLite databases are supported.

Declaration: 

    sql(database_type host_parameters database_parameters [options]);

The sql() driver has the following required parameters: type(), database(), table, columns(), and values.

[Warning] Warning

The syslog-ng application requires read and write access to the SQL table, otherwise it cannot verify that the destination table exists.

Currently the syslog-ng application has default schemas for the different databases and uses these defaults if the database schema (for example columns and column types) is not defined in the configuration file. However, these schemas will be deprecated and specifying the exact database schema will be required in later versions of syslog-ng.

[Note] Note

In addition to the standard syslog-ng packages, the sql() destination requires database-specific packages to be installed. These packages are automatically installed by the binary syslog-ng installer.

The sql() driver is currently not available for every platform that is supported by syslog-ng. For a list of platforms that support the sql() driver, visit this link.

The table and value parameters can include macros to create tables and columns dynamically (for details, see Section 11.1.5, Macros of syslog-ng OSE).

[Warning] Warning

When using macros in table names, note that some databases limit the maximum allowed length of table names. Consult the documentation of the database for details.

Inserting the records into the database is performed by a separate thread. The syslog-ng application automatically performs the escaping required to insert the messages into the database.

[Example] Example 7.7. Using the sql() driver

The following example sends the log messages into a PostgreSQL database running on the logserver host. The messages are inserted into the logs database, the name of the table includes the exact date and the name of the host sending the messages. The syslog-ng application automatically creates the required tables and columns, if the user account used to connect to the database has the required privileges.

destination d_sql { 

  sql(type(pgsql)

  host("logserver") username("syslog-ng") password("password")

  database("logs")

  table("messages_${HOST}_${R_YEAR}${R_MONTH}${R_DAY}")

  columns("datetime", "host", "program", "pid", "message")

  values("$R_DATE", "$HOST", "$PROGRAM", "$PID", "$MSGONLY")

  indexes("datetime", "host", "program", "pid", "message"));

  };

The following example specifies the type of the database columns as well:

destination d_sql { 

  sql(type(pgsql)

  host("logserver") username("syslog-ng") password("password")

  database("logs")

  table("messages_${HOST}_${R_YEAR}${R_MONTH}${R_DAY}")

  columns("datetime varchar(16)", "host varchar(32)", "program  varchar(20)", "pid varchar(8)", "message  varchar(200)")

  values("$R_DATE", "$HOST", "$PROGRAM", "$PID", "$MSGONLY")

  indexes("datetime", "host", "program", "pid", "message"));

};

7.5.1. Using the sql() driver with an Oracle database

The Oracle sql destination has some special aspects that are important to note.

  • The hostname of the database server is set in the tnsnames.ora file, not in the host parameter of the sql() destination.

    If the tnsnames.ora file is not located in the /etc directory (or in the /var/opt/oracle directory on Solaris), set the following Oracle-related environment variables, so syslog-ng OSE will find the file: ORACLE_BASE, ORACLE_HOME, and ORACLE_SID. For details, see the documentation of the Oracle Instant Client.

  • You cannot use the same database() settings in more than one destination, because the database() option of the SQL driver is just a reference to the connection string of the tnsnames.ora file. To overcome this problem, you can duplicate the connections in the tnsnames.ora file under a different name, and use a different table in each Oracle destination in syslog-ng OSE.

  • As certain database versions limit the maximum length of table names, macros in the table names should be used with care.

  • In the current version of syslog-ng OSE, the types of database columns must be explicitly set for the Oracle destination. The column used to store the text part of the syslog messages should be able to store messages as long as the longest message permitted by syslog-ng, therefore it is usually recommended to use the varchar2 or clob column type. (The maximum length of the messages can be set using the log_msg_size() option.) For details, see the following example.

  • The Oracle Instant Client used by syslog-ng OSE supports only the following character sets:

    • Single-byte character sets: US7ASCII, WE8DEC, WE8MSWIN1252, and WE8ISO8859P1

    • Unicode character sets: UTF8, AL16UTF16, and AL32UTF8

[Example] Example 7.8. Using the sql() driver with an Oracle database

The following example sends the log messages into an Oracle database running on the logserver host, which must be set in the /etc/tnsnames.ora file. The messages are inserted into the LOGS database, the name of the table includes the exact date when the messages were sent. The syslog-ng application automatically creates the required tables and columns, if the user account used to connect to the database has the required privileges.

destination d_sql { 

  sql(type(oracle)

  username("syslog-ng") password("password")

  database("LOGS")

  table("msgs_${R_YEAR}${R_MONTH}${R_DAY}")

  columns("datetime varchar(16)", "host varchar(32)", "program varchar(32)", "pid varchar(8)", "message varchar2")                        

  values("$R_DATE", "$HOST", "$PROGRAM", "$PID", "$MSGONLY")

  indexes("datetime", "host", "program", "pid", "message"));

  };

The Oracle Instant Client retrieves the address of the database server from the /etc/tnsnames.ora file. Edit or create this file as needed for your configuration. A sample is provided below.

LOGS =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)

(HOST = logserver)

(PORT = 1521))

)

(CONNECT_DATA =

(SERVICE_NAME = EXAMPLE.SERVICE)

)

)

7.5.2. Using the sql() driver with a Microsoft SQL database

The mssql database driver can access Microsoft SQL (MSSQL) destinations. This driver has some special aspects that are important to note.

  • The date format used by the MSSQL database must be explicitly set in the /etc/locales.conf file of the syslog-ng server. For details, see the following example.

  • As certain database versions limit the maximum length of table names, macros in the table names should be used with care.

  • In the current version of syslog-ng OSE, the types of database columns must be explicitly set for the MSSQL destination.

    [Warning] Warning

    The following column types cannot be used in MSSQL destinations: nchar, nvarchar, ntext, and xml.

  • The column used to store the text part of the syslog messages should be able to store messages as long as the longest message permitted by syslog-ng. The varchar column type can store maximum 4096 bytes-long messages. The maximum length of the messages can be set using the log_msg_size() option. For details, see the following example.

  • Remote access for SQL users must be explicitly enabled on the Microsoft Windows host running the Microsoft SQL Server. For details, see Procedure 3.3, Configuring Microsoft SQL Server to accept logs from syslog-ng.

[Example] Example 7.9. Using the sql() driver with an MSSQL database

The following example sends the log messages into an MSSQL database running on the logserver host. The messages are inserted into the syslogng database, the name of the table includes the exact date when the messages were sent. The syslog-ng application automatically creates the required tables and columns, if the user account used to connect to the database has the required privileges.

destination d_mssql { 

sql(type(mssql) host("logserver") port("1433") 

  username("syslogng") password("syslogng") database("syslogng") 

  table("msgs_${R_YEAR}${R_MONTH}${R_DAY}")columns("datetime varchar(16)", "host varchar(32)",

  "program varchar(32)", "pid varchar(8)", "message varchar(4096)")

  values("$R_DATE", "$HOST", "$PROGRAM", "$PID", "$MSGONLY")

  indexes("datetime", "host", "program", "pid"));

  };

The date format used by the MSSQL database must be explicitly set in the /etc/locales.conf file of the syslog-ng server. Edit or create this file as needed for your configuration. A sample is provided below.

[default]

date = "%Y-%m-%d %H:%M:%S"

7.5.3. The way syslog-ng interacts with the database

Used SQL operations by syslog-ng. 

Create table:

  • If the given table does not exist, syslog-ng tries to create it with the given column types.

  • The syslog-ng OSE application automatically creates the required tables and columns, if the user account used to connect to the database has the required privileges.

  • If syslog-ng cannot create or alter a table, it tries to do it again when reach the next time_reopen.

Alter table:

  • If the table structure is different from given structure in an existing table, syslog-ng tries to add columns in this table but never will delete or modify an existing column.

  • If syslog-ng OSE cannot create or alter a table, it tries to do it again when reach the next time_reopen.

  • The syslog-ng OSE application requires read and write access to the SQL table, otherwise it cannot verify that the destination table exists.

Insert table:

  • Insert new records in a table.

  • Inserting the records into the database is performed by a separate thread.

  • The syslog-ng OSE application automatically performs the escaping required to insert the messages into the database.

  • If insert returns with error, syslog-ng tries to insert the message +two times by default, then drops it. Retrying time is the value of time_reopen().

Encoding. 

The syslog-ng OSE application uses UTF-8 by default when writes logs into database.

Start/stop and reload. 

Start:

  • The syslog-ng OSE application will connect to database automatically after starting regardless existing incoming messages.

Stop:

  • The syslog-ng OSE application will close the connection to database before shutting down.

Possibility of losing logs:

  • The syslog-ng OSE application cannot lose logs during shutting down if disk buffer was given and it is not full yet.

  • The syslog-ng OSE application cannot lose logs during shutting down if disk buffer was not given.

Reload:

  • The syslog-ng OSE application will close the connection to database if it received SIGHUP signal (reload).

  • It will reconnect to the database when it tries to send a new message to this database again.

Macros: 

The value of $SEQNUM macro will be overrided by sql driver regardless of local or relayed incoming message.

It will be grown continously.

7.5.3.1. MySQL-specific interaction methods

To specify the socket to use, set and export the MYSQL_UNIX_PORT environment variable, for example MYSQL_UNIX_PORT=/var/lib/mysql/mysql.sock; export MYSQL_UNIX_PORT.

7.5.3.2. MsSQL-specific interaction methods

In SQL Server 2005 this restriction is lifted - kind of. The total length of all key columns in an index cannot exceed 900 bytes.

If you are using null() in your configuration, be sure that the columns allow NULL to insert. Give the column as the following example: "datetime varchar(16) NULL".

The date format used by the MSSQL database must be explicitly set in the /etc/locales.conf file of the syslog-ng server. [default] date = "%Y-%m-%d %H:%M:%S".

7.5.4. sql() destination options

This driver sends messages into an SQL database. The sql() destination has the following options:

columns()

Type: string list
Default: "date", "facility", "level", "host", "program", "pid", "message"

Description: Name of the columns storing the data in fieldname [dbtype] format. The [dbtype] parameter is optional, and specifies the type of the field. By default, syslog-ng creates text columns. Note that not every database engine can index text fields.

[Warning] Warning

The following column types cannot be used in MSSQL destinations: nchar, nvarchar, ntext, and xml.

database()

Type: string
Default: logs

Description: Name of the database that stores the logs. Macros cannot be used in database name. Also, when using an Oracle database, you cannot use the same database() settings in more than one destination.

flags()

Type: list of flags
Default: empty string

Description: Flags related to the sql() destination.

  • dont-create-tables: Enable this flag to prevent syslog-ng OSE from creating non-existing database tables automatically. The syslog-ng OSE application typically has to create tables if you use macros in the table names. Available in syslog-ng OSE version 3.2 and later.

  • explicit-commits: By default, syslog-ng OSE commits every log message to the target database individually. When the explicit-commits option is enabled, messages are committed in batches. This improves the performance, but results in some latency, as the messages are not immediately sent to the database. The size and frequency of batched commits can be set using the flush_lines and flush_timeout parameters. The explicit-commits option is available in syslog-ng OSE version 3.2 and later.

[Example] Example 7.10. Setting flags for SQL destinations

The following example sets the dont-create-tables and explicit-commits flags for an sql() destination.

flags(dont-create-tables,explicit-commits)

flush_lines()

Type: number
Default: Use global setting.

Description: Specifies how many lines are flushed to a destination at a time. Syslog-ng waits for this number of lines to accumulate and sends them off in a single batch. Setting this number high increases throughput as fully filled frames are sent to the destination, but also increases message latency. The latency can be limited by the use of the flush_timeout option.

flush_timeout()

Type: time in milliseconds
Default: Use global setting.

Description: Specifies the time syslog-ng waits for lines to accumulate in its output buffer. For details, see the flush_lines option.

frac_digits()

Type: number
Default: 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.

host()

Type: hostname or IP address
Default: n/a

Description: Hostname of the database server. Note that Oracle destinations do not use this parameter, but retrieve the hostname from the /etc/tnsnames.ora file.

[Note] Note

If you specify host="localhost", syslog-ng will use a socket to connect to the local database server. Use host="127.0.0.1" to force TCP communication between syslog-ng and the local database server.

To specify the socket to use, set and export the MYSQL_UNIX_PORT environment variable, for example MYSQL_UNIX_PORT=/var/lib/mysql/mysql.sock; export MYSQL_UNIX_PORT.

indexes()

Type: string list
Default: "date", "facility", "host", "program"

Description: The list of columns that are indexed by the database to speed up searching. To disable indexing for the destination, include the empty indexes() parameter in the destination, simply omitting the indexes parameter will cause syslog-ng to request indexing on the default columns.

The syslog-ng OSE application will create the name of indexes automaticaly with the following method:

  • In case of MsSQL, PostgreSQL, MySQL or SQLite or (Oracle but tablename < 30 characters): {table}_{column}_idx.

  • In case of Oracle and tablename > 30 characters: md5sum of {table}_{column}-1 and the first character will be replaced by "i" character and the md5sum will be truncated to 30 characters.

local_time_zone()

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 (for example +01:00). The valid timezone names are listed under the /usr/share/zoneinfo directory.

log_fifo_size()

Type: number
Default: Use global setting.

Description: The number of messages that the output queue can store.

null()

Type: string
Default:  

Description: If the content of a column matches the string specified in the null() parameter, the contents of the column will be replaced with an SQL NULL value. If unset (by default), the option does not match on any string. For details, see the Example 7.11, Using SQL NULL values.

[Example] Example 7.11. Using SQL NULL values

The null() parameter of the SQL driver can be used to replace the contents of a column with a special SQL NULL value. To replace every column that contains an empty string with NULL, use the null("") option, for example

destination d_sql { 

                        sql(type(pgsql)

                        host("logserver") username("syslog-ng") password("password")

                        database("logs")

                        table("messages_${HOST}_${R_YEAR}${R_MONTH}${R_DAY}")

                        columns("datetime", "host", "program", "pid", "message")

                        values("$R_DATE", "$HOST", "$PROGRAM", "$PID", "$MSGONLY")

                        indexes("datetime", "host", "program", "pid", "message")

                        null(""));                    

                        };

To replace only a specific column (for example pid) if it is empty, assign a default value to the column, and use this default value in the null() parameter:

destination d_sql { 

                        sql(type(pgsql)

                        host("logserver") username("syslog-ng") password("password")

                        database("logs")

                        table("messages_${HOST}_${R_YEAR}${R_MONTH}${R_DAY}")

                        columns("datetime", "host", "program", "pid", "message")

                        values("$R_DATE", "$HOST", "$PROGRAM", "${PID:-@@NULL@@}", "$MSGONLY")

                        indexes("datetime", "host", "program", "pid", "message")

                        null("@@NULL@@"));                    

                        };

Ensure that the default value you use does not appear in the actual log messages, because other occurrences of this string will be replaced with NULL as well.

password()

Type: string
Default: n/a

Description: Password of the database user.

port()

Type: number
Default: 1433 TCP for MSSQL, 3306 TCP for MySQL, 1521 for Oracle, and 5432 TCP for PostgreSQL

Description: The port number to connect to.

retry_sql_inserts

Type: number
Default: 3

Description: The number of insertion attempts. If syslog-ng OSE could not insert a message into the database, it will repeat the attempt until the number of attempts reaches retry_sql_inserts, then drops the line. For example, syslog-ng OSE will try to insert a message maximum three times by default (once for first insertion and twice if the first insertion was failed).

session-statements()

Type: comma-separated list of SQL statements
Default: empty string

Description: Specifies one or more SQL-like statement which is executed after syslog-ng OSE has successfully connected to the database. For example:

session-statements("SET COLLATION_CONNECTION='utf8_general_ci'")
[Warning] Warning

The syslog-ng OSE application does not validate or limit the contents of customized queries. Consequently, queries performed with a user with write-access can potentially modify or even harm the database. Use customized queries with care, and only for your own responsibility.

table()

Type: string
Default: messages

Description: Name of the database table to use (can include macros). When using macros, note that some databases limit the length of table names.

time_zone()

Type: timezone in +/-HH:MM format
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.

type()

Type: mssql, mysql, oracle, pgsql, or sqlite3
Default: mysql

Description: Specifies the type of the database, that is, the DBI database driver to use. Use the mssql option to send logs to an MSSQL database. For details, see the examples of the databases on the following sections.

username()

Type: string
Default: n/a

Description: Name of the database user.

values()

Type: string list
Default: "${R_YEAR}-${R_MONTH}-${R_DAY} ${R_HOUR}:${R_MIN}:${R_SEC}", "$FACILITY", "$LEVEL", "$HOST", "$PROGRAM", "$PID", "$MSGONLY"

Description: The parts of the message to store in the fields specified in the columns parameter.

It is possible to give a special value calling: default (without quotation marks).It means that the value will be used that is the default of the column type of this value.

[Example] Example 7.12. Value: default
columns("date datetime", "host varchar(32)", "row_id serial")

	values("$R_DATE", "$HOST", default)

7.6. Sending messages to a remote logserver using the IETF-syslog protocol

The syslog() driver sends messages to a remote host (for example a syslog-ng server or relay) on the local intranet or internet using the new standard syslog protocol developed by IETF (for details about the new protocol, see Section 2.9.2, IETF-syslog messages). The protocol supports sending messages using the UDP, TCP, or the encrypted TLS networking protocols.

The required arguments of the driver are the address of the destination host (where messages should be sent). The transport method (networking protocol) is optional, syslog-ng uses the TCP protocol by default. For the list of available optional parameters, see Section 7.6.1, syslog() destination options.

Declaration:

                syslog(host transport [options]);
[Note] Note

Note that the syslog destination driver has required parameters, while the source driver defaults to the local bind address, and every parameter is optional.

The udp transport method automatically sends multicast packets if a multicast destination address is specified. The tcp and tls methods do not support multicasting.

[Note] Note

The default ports for the different transport protocols are as follows: UDP — 514; TLS — 6514.

[Example] Example 7.13. Using the syslog() driver
destination d_tcp { syslog("10.1.2.3" transport("tcp") port(1999) localport(999)); };

If name resolution is configured, the hostname of the target server can be used as well.

destination d_tcp { syslog("target_host" transport("tcp") port(1999) localport(999)); };

Send the log messages using TLS encryption and use mutual authentication. For details on the encryption and authentication options, see Section 10.4, TLS options.

destination d_syslog_tls{ 

                syslog("10.100.20.40"

                transport("tls")

                port(6514)

                tls(peer-verify(required-trusted)

                ca_dir('/opt/syslog-ng/etc/syslog-ng/keys/ca.d/')

                key_file('/opt/syslog-ng/etc/syslog-ng/keys/client_key.pem')

                cert_file('/opt/syslog-ng/etc/syslog-ng/keys/client_certificate.pem'))

                );};

7.6.1. syslog() destination options

The syslog() driver sends messages to a remote host (for example a syslog-ng server or relay) on the local intranet or internet using the RFC5424 syslog protocol developed by IETF (for details about the protocol, see Section 2.9.2, IETF-syslog messages). The protocol supports sending messages using the UDP, TCP, or the encrypted TLS networking protocols.

These destinations have the following options:

flags()

Type: no_multi_line, syslog-protocol
Default: empty set

Description: Flags influence the behavior of the destination driver.

  • no-multi-line: The no-multi-line flag disables line-breaking in the messages; the entire message is converted to a single line.

  • syslog-protocol: The syslog-protocol flag instructs the driver to format the messages according to the new IETF syslog protocol standard (RFC5424), but without the frame header. If this flag is enabled, macros used for the message have effect only for the text of the message, the message header is formatted to the new standard. Note that this flag is not needed for the syslog driver, and that the syslog driver automatically adds the frame header to the messages.

flush_lines()

Type: number
Default: Use global setting.

Description: Specifies how many lines are flushed to a destination at a time. Syslog-ng waits for this number of lines to accumulate and sends them off in a single batch. Setting this number high increases throughput as fully filled frames are sent to the destination, but also increases message latency. The latency can be limited by the use of the flush_timeout option.

flush_timeout()

Type: time in milliseconds
Default: Use global setting.

Description: Specifies the time syslog-ng waits for lines to accumulate in its output buffer. For details, see the flush_lines option.

frac_digits()

Type: number
Default: 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.

ip_tos()

Type: number
Default: 0

Description: Specifies the Type-of-Service value of outgoing packets.

ip_ttl()

Type: number
Default: 0

Description: Specifies the Time-To-Live value of outgoing packets.

keep-alive()

Type: yes or no
Default: yes

Description: Specifies whether connections to destinations should be closed when syslog-ng is restarted (upon the receipt of a SIGHUP signal). Note that this applies to the client (destination) side of the syslog-ng connections, server-side (source) connections are always reopened after receiving a HUP signal unless the keep-alive option is enabled for the source. When the keep-alive option is enabled, syslog-ng saves the contents of the output queue of the destination when receiving a HUP signal, reducing the risk of losing messages

localip()

Type: string
Default: 0.0.0.0

Description: The IP address to bind to before connecting to target.

localport()

Type: number
Default: 0

Description: The port number to bind to. Messages are sent from this port.

log_fifo_size()

Type: number
Default: Use global setting.

Description: The number of messages that the output queue can store.

port() or destport()

Type: number
Default: 601

Description: The port number to connect to. Note that the default port numbers used by syslog-ng do not comply with the latest RFC which was published after the release of syslog-ng 3.0.2, therefore the default port numbers will change in the future releases.

so_broadcast()

Type: yes or no
Default: no

Description: This option controls the SO_BROADCAST socket option required to make syslog-ng send messages to a broadcast address. For details, see the socket(7) manual page.

so_keepalive()

Type: yes or no
Default: no

Description: Enables keep-alive messages, keeping the socket open. This only effects TCP and UNIX-stream sockets. For details, see the socket(7) manual page.

so_rcvbuf()

Type: number
Default: 0

Description: Specifies the size of the socket receive buffer in bytes. For details, see the socket(7) manual page.

so_sndbuf()

Type: number
Default: 0

Description:Specifies the size of the socket send buffer in bytes. For details, see the socket(7) manual page.

spoof_source()

Type: yes or no
Default: no

Description: Enables source address spoofing. This means that the host running syslog-ng generates UDP packets with the source IP address matching the original sender of the message. It is useful when you want to perform some kind of preprocessing via syslog-ng then forward messages to your central log management solution with the source address of the original sender. This option only works for UDP destinations though the original message can be received by TCP as well. This option is only available if syslog-ng was compiled using the --enable-spoof-source configuration option.

suppress()

Type: seconds
Default: 0 (disabled)

Description: If several identical log messages would be sent to the destination without any other messages between the identical messages (for example, an application repeated an error message ten times), syslog-ng can suppress the repeated messages and send the message only once, followed by the Last message repeated n times. message. The parameter of this option specifies the number of seconds syslog-ng waits for identical messages.

template()

Type: string
Default: A format conforming to the default logfile format.

Description: Specifies a template defining the logformat to be used in the destination. Macros are described in Section 11.1.5, Macros of syslog-ng OSE. Please note that for network destinations it might not be appropriate to change the template as it changes the on-wire format of the syslog protocol which might not be tolerated by stock syslog receivers (like syslogd or syslog-ng itself). For network destinations make sure the receiver can cope with the custom format defined.

template_escape()

Type: yes or no
Default: no

Description: Turns on escaping for the ', ", and backspace characters in templated output files. This is useful for generating SQL statements and quoting string contents so that parts of the log message are not interpreted as commands to the SQL server.

throttle()

Type: number
Default: 0

Description: Sets the maximum number of messages sent to the destination per second. Use this output-rate-limiting functionality only when using disk-buffer as well to avoid the risk of losing messages. Specifying 0 or a lower value sets the output limit to unlimited.

time_zone()

Type: timezone in +/-HH:MM format
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.

tls()

Type: tls options
Default: n/a

Description: This option sets various TLS specific options like key/certificate files and trusted CA locations. TLS can be used only with the tcp transport protocols. For details, see Section 10.4, TLS options.

transport

Type: udp, tcp, or tls
Default: tcp

Description: Specifies the protocol used to receive messages from the source.

ts_format()

Type: rfc3164, bsd, rfc3339, iso
Default: rfc3164

Description: Override the global timestamp format (set in the global ts_format() parameter) for the specific destination. For details, see Section 2.5.1, A note on timezones and timestamps.

7.7. Sending messages to a remote logserver using the legacy BSD-syslog protocol

The tcp(), tcp6(), udp(), and udp6() drivers send messages to another host (for example a syslog-ng server or relay) on the local intranet or internet using the UDP or TCP protocol. The tcp6() and udp6() drivers use the IPv6 network protocol.

All four drivers have a single required parameter specifying the destination host address, where messages should be sent. For the list of available optional parameters, see Section 7.7.1, tcp(), tcp6(), udp(), and udp6() destination options.

The udp() and udp6() drivers automatically send multicast packets if a multicast destination address is specified. The tcp() and tcp6() drivers do not support multicasting.

Declaration:

                tcp(host [options]);

                udp(host [options]);

                tcp6(host [options]);

                udp6(host [options]);
[Example] Example 7.14. Using the tcp() driver
destination d_tcp { tcp("10.1.2.3" port(1999) localport(999)); };

If name resolution is configured, the hostname of the target server can be used as well.

destination d_tcp { tcp("target_host" port(1999) localport(999)); };

To send messages using the IETF-syslog message format without using the IETF-syslog protocol, enable the syslog-protocol flag:

destination d_tcp { tcp("10.1.2.3" port(1999) flags(syslog-protocol) ); };

(For details on how to use the IETF-syslog protocol, see Section 7.6.1, syslog() destination options.)

Using an IPv6 address:

tcp6("fd00:abcd:4321:2:20c:29ff:fea8:9671" port(514));

7.7.1. tcp(), tcp6(), udp(), and udp6() destination options

This driver sends messages to another host on the local intranet or internet according to RFC3164 using the UDP or TCP protocol. The tcp6() and udp6() drivers use the IPv6 network protocol.

[Note] Note

When using IPv6 destination addresses, always enclose the address between double-quotes:

tcp6("fd00:abcd:4321:2:20c:29ff:fea8:9671" port(514));

These destinations have the following options:

flags()

Type: no_multi_line, syslog-protocol
Default: empty set

Description: Flags influence the behavior of the destination driver.

  • no-multi-line: The no-multi-line flag disables line-breaking in the messages; the entire message is converted to a single line.

  • syslog-protocol: The syslog-protocol flag instructs the driver to format the messages according to the new IETF syslog protocol standard (RFC5424), but without the frame header. If this flag is enabled, macros used for the message have effect only for the text of the message, the message header is formatted to the new standard. Note that this flag is not needed for the syslog driver, and that the syslog driver automatically adds the frame header to the messages.

flush_lines()

Type: number
Default: Use global setting.

Description: Specifies how many lines are flushed to a destination at a time. Syslog-ng waits for this number of lines to accumulate and sends them off in a single batch. Setting this number high increases throughput as fully filled frames are sent to the destination, but also increases message latency. The latency can be limited by the use of the flush_timeout option.

flush_timeout()

Type: time in milliseconds
Default: Use global setting.

Description: Specifies the time syslog-ng waits for lines to accumulate in its output buffer. For details, see the flush_lines option.

frac_digits()

Type: number
Default: 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.

ip_tos()

Type: number
Default: 0

Description: Specifies the Type-of-Service value of outgoing packets.

ip_ttl()

Type: number
Default: 0

Description: Specifies the Time-To-Live value of outgoing packets.

keep-alive()

Type: yes or no
Default: yes

Description: Specifies whether connections to destinations should be closed when syslog-ng is restarted (upon the receipt of a SIGHUP signal). Note that this applies to the client (destination) side of the syslog-ng connections, server-side (source) connections are always reopened after receiving a HUP signal unless the keep-alive option is enabled for the source. When the keep-alive option is enabled, syslog-ng saves the contents of the output queue of the destination when receiving a HUP signal, reducing the risk of losing messages

localip()

Type: string
Default: 0.0.0.0

Description: The IP address to bind to before connecting to target.

localport()

Type: number
Default: 0

Description: The port number to bind to. Messages are sent from this port.

port() or destport()

Type: number
Default: 514

Description: The port number to connect to. Note that the default port numbers used by syslog-ng do not comply with the latest RFC which was published after the release of syslog-ng 3.0.2, therefore the default port numbers will change in the future releases.

[Note] Note

The TCP port 514 is reserved for use with rshell, so select a different port if syslog-ng and rshell is used at the same time.

so_broadcast()

Type: yes or no
Default: no

Description: This option controls the SO_BROADCAST socket option required to make syslog-ng send messages to a broadcast address. For details, see the socket(7) manual page.

so_keepalive()

Type: yes or no
Default: no

Description: Enables keep-alive messages, keeping the socket open. This only effects TCP and UNIX-stream sockets. For details, see the socket(7) manual page.

so_rcvbuf()

Type: number
Default: 0

Description: Specifies the size of the socket receive buffer in bytes. For details, see the socket(7) manual page.

so_sndbuf()

Type: number
Default: 0

Description:Specifies the size of the socket send buffer in bytes. For details, see the socket(7) manual page.

spoof_source()

Type: yes or no
Default: no

Description: Enables source address spoofing. This means that the host running syslog-ng generates UDP packets with the source IP address matching the original sender of the message. It is useful when you want to perform some kind of preprocessing via syslog-ng then forward messages to your central log management solution with the source address of the original sender. This option only works for UDP destinations though the original message can be received by TCP as well. This option is only available if syslog-ng was compiled using the --enable-spoof-source configuration option.

suppress()

Type: seconds
Default: 0 (disabled)

Description: If several identical log messages would be sent to the destination without any other messages between the identical messages (for example, an application repeated an error message ten times), syslog-ng can suppress the repeated messages and send the message only once, followed by the Last message repeated n times. message. The parameter of this option specifies the number of seconds syslog-ng waits for identical messages.

template()

Type: string
Default: A format conforming to the default logfile format.

Description: Specifies a template defining the logformat to be used in the destination. Macros are described in Section 11.1.5, Macros of syslog-ng OSE. Please note that for network destinations it might not be appropriate to change the template as it changes the on-wire format of the syslog protocol which might not be tolerated by stock syslog receivers (like syslogd or syslog-ng itself). For network destinations make sure the receiver can cope with the custom format defined.

template_escape()

Type: yes or no
Default: no

Description: Turns on escaping for the ', ", and backspace characters in templated output files. This is useful for generating SQL statements and quoting string contents so that parts of the log message are not interpreted as commands to the SQL server.

throttle()

Type: number
Default: 0

Description: Sets the maximum number of messages sent to the destination per second. Use this output-rate-limiting functionality only when using disk-buffer as well to avoid the risk of losing messages. Specifying 0 or a lower value sets the output limit to unlimited.

time_zone()

Type: timezone in +/-HH:MM format
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.

tls()

Type: tls options
Default: n/a

Description: This option sets various TLS specific options like key/certificate files and trusted CA locations. TLS can be used only with the tcp transport protocols. For details, see Section 10.4, TLS options.

ts_format()

Type: rfc3164, bsd, rfc3339, iso
Default: rfc3164

Description: Override the global timestamp format (set in the global ts_format() parameter) for the specific destination. For details, see Section 2.5.1, A note on timezones and timestamps.

7.8. Sending messages to UNIX domain sockets

The unix-stream() and unix-dgram() drivers send messages to a UNIX domain socket in either SOCK_STREAM or SOCK_DGRAM mode.

Both drivers have a single required argument specifying the name of the socket to connect to. For the list of available optional parameters, see Section 7.8.1, unix-stream() and unix-dgram() destination options.

Declaration: 

                unix-stream(filename [options]);

                unix-dgram(filename [options]);
[Example] Example 7.15. Using the unix-stream() driver
destination d_unix_stream { unix-stream("/var/run/logs"); };

7.8.1. unix-stream() and unix-dgram() destination options

These drivers send messages to a unix socket in either SOCK_STREAM or SOCK_DGRAM mode. The unix-stream() and unix-dgram() destinations have the following options:

flags()

Type: no_multi_line, syslog-protocol
Default: empty set

Description: Flags influence the behavior of the destination driver.

  • no-multi-line: The no-multi-line flag disables line-breaking in the messages; the entire message is converted to a single line.

  • syslog-protocol: The syslog-protocol flag instructs the driver to format the messages according to the new IETF syslog protocol standard (RFC5424), but without the frame header. If this flag is enabled, macros used for the message have effect only for the text of the message, the message header is formatted to the new standard. Note that this flag is not needed for the syslog driver, and that the syslog driver automatically adds the frame header to the messages.

flush_lines()

Type: number
Default: Use global setting.

Description: Specifies how many lines are flushed to a destination at a time. Syslog-ng waits for this number of lines to accumulate and sends them off in a single batch. Setting this number high increases throughput as fully filled frames are sent to the destination, but also increases message latency. The latency can be limited by the use of the flush_timeout option.

flush_timeout()

Type: time in milliseconds
Default: Use global setting.

Description: Specifies the time syslog-ng waits for lines to accumulate in its output buffer. For details, see the flush_lines option.

frac_digits()

Type: number
Default: 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.

log_fifo_size()

Type: number
Default: Use global setting.

Description: The number of messages that the output queue can store.

keep-alive()

Type: yes or no
Default: yes

Description: Specifies whether connections to destinations should be closed when syslog-ng is restarted (upon the receipt of a SIGHUP signal). Note that this applies to the client (destination) side of the syslog-ng connections, server-side (source) connections are always reopened after receiving a HUP signal unless the keep-alive option is enabled for the source. When the keep-alive option is enabled, syslog-ng saves the contents of the output queue of the destination when receiving a HUP signal, reducing the risk of losing messages

so_broadcast()

Type: yes or no
Default: no

Description: This option controls the SO_BROADCAST socket option required to make syslog-ng send messages to a broadcast address. For details, see the socket(7) manual page.

so_keepalive()

Type: yes or no
Default: no

Description: Enables keep-alive messages, keeping the socket open. This only effects TCP and UNIX-stream sockets. For details, see the socket(7) manual page.

so_rcvbuf()

Type: number
Default: 0

Description: Specifies the size of the socket receive buffer in bytes. For details, see the socket(7) manual page.

so_sndbuf()

Type: number
Default: 0

Description:Specifies the size of the socket send buffer in bytes. For details, see the socket(7) manual page.

suppress()

Type: seconds
Default: 0 (disabled)

Description: If several identical log messages would be sent to the destination without any other messages between the identical messages (for example, an application repeated an error message ten times), syslog-ng can suppress the repeated messages and send the message only once, followed by the Last message repeated n times. message. The parameter of this option specifies the number of seconds syslog-ng waits for identical messages.

template()

Type: string
Default: A format conforming to the default logfile format.

Description: Specifies a template defining the logformat to be used in the destination. Macros are described in Section 11.1.5, Macros of syslog-ng OSE. Please note that for network destinations it might not be appropriate to change the template as it changes the on-wire format of the syslog protocol which might not be tolerated by stock syslog receivers (like syslogd or syslog-ng itself). For network destinations make sure the receiver can cope with the custom format defined.

template_escape()

Type: yes or no
Default: no

Description: Turns on escaping for the ', ", and backspace characters in templated output files. This is useful for generating SQL statements and quoting string contents so that parts of the log message are not interpreted as commands to the SQL server.

throttle()

Type: number
Default: 0

Description: Sets the maximum number of messages sent to the destination per second. Use this output-rate-limiting functionality only when using disk-buffer as well to avoid the risk of losing messages. Specifying 0 or a lower value sets the output limit to unlimited.

time_zone()

Type: timezone in +/-HH:MM format
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.

ts_format()

Type: rfc3164, bsd, rfc3339, iso
Default: rfc3164

Description: Override the global timestamp format (set in the global ts_format() parameter) for the specific destination. For details, see Section 2.5.1, A note on timezones and timestamps.

7.9. Sending messages to a user terminal — usertty() destination

This driver writes messages to the terminal of a logged-in user.

The usertty() driver has a single required argument, specifying a username who should receive a copy of matching messages. Use the asterisk * to specify every user currently logged in to the system.

Declaration: 

usertty(username);

The usertty() does not have any further options nor does it support templates.

[Example] Example 7.16. Using the usertty() driver
destination d_usertty { usertty("root"); };

Chapter 8. Routing messages: log paths and filters

8.1. Log paths

Log paths determine what happens with the incoming log messages. Messages coming from the sources listed in the log statement and matching all the filters are sent to the listed destinations.

To define a log path, add a log statement to the syslog-ng configuration file using the following syntax:

log {

    source(s1); source(s2); ...

    optional_element(filter1|parser1|rewrite1);...

    optional_element(filter2|parser2|rewrite2);...

    destination(d1); destination(d2); ...

    flags(flag1[, flag2...]);

    };
[Warning] Warning

Log statements are processed in the order they appear in the configuration file, thus the order of log paths may influence what happens to a message, especially when using filters and log flags.

[Example] Example 8.1. A simple log statement

The following log statement sends all messages arriving to the localhost to a remote server.

source s_localhost { tcp(ip(127.0.0.1) port(1999) ); };

destination d_tcp { tcp("10.1.2.3" port(1999); localport(999)); };

log { source(s_localhost); destination(d_tcp); };

All matching log statements are processed by default, and the messages are sent to every matching destination by default. So a single log message might be sent to the same destination several times, provided the destination is listed in several log statements, and it can be also sent to several different destinations.

This default behavior can be changed using the flags() parameter. Flags apply to individual log paths; they are not global options. The following flags available in syslog-ng:

  • final: Do not send the messages processed by this log path to any further destination.

  • fallback: Process messages that were not processed by other log paths.

  • catchall: Process every message, regardless of its source or if it was already processed by other log paths.

  • flow-control: Stop reading messages from the source if the destination cannot accept them. For details, see Section 8.2, Managing incoming and outgoing messages with flow-control.

For details on the individual flags, see Section 8.1.2, Log path flags. The effect and use of the flow-control flag is detailed in Section 8.2, Managing incoming and outgoing messages with flow-control.

8.1.1. Embedded log statements

Starting from version 3.0, syslog-ng can handle embedded log statements (also called log pipes). Embedded log statements are useful for creating complex, multi-level log paths with several destinations and use filters, parsers, and rewrite rules.

For example, if you want to filter your incoming messages based on the facility parameter, and then use further filters to send messages arriving from different hosts to different destinations, you would use embedded log statements.

Embedded log statement

Figure 8.1. Embedded log statement


Embedded log statements include sources — and usually filters, parsers, rewrite rules, or destinations — and other log statements that can include filters, parsers, rewrite rules, and destinations. The following rules apply to embedded log statements:

  • Only the beginning (also called top-level) log statement can include sources.

  • Embedded log statements can include multiple log statements on the same level (that is, a top-level log statement can include two or more log statements).

  • Embedded log statements can include several levels of log statements (that is, a top-level log statement can include a log statement that includes another log statement, and so on).

  • After an embedded log statement, you can write either another log statement, or the flags() option of the original log statement. You cannot use filters or other configuration objects.

  • Embedded log statements that are on the same level receive the same messages from the higher-level log statement. For example, if the top-level log statement includes a filter, the lower-level log statements receive only the messages that pass the filter.

Embedded log statements

Figure 8.2. Embedded log statements


Embedded log filters can be used to optimize the processing of log messages, for example, to re-use the results of filtering and rewriting operations.

8.1.1.1. Using embedded log statements

Embedded log statements (for details, see Section 8.1.1, Embedded log statements) re-use the results of processing messages (for example the results of filtering or rewriting) to create complex log paths. Embedded log statements use the same syntax as regular log statements, but they cannot contain additional sources. To define embedded log statements, use the following syntax:

log {

    source(s1); source(s2); ...



    optional_element(filter1|parser1|rewrite1);

    optional_element(filter2|parser2|rewrite2);...



    destination(d1); destination(d2); ...



    #embedded log statement

    log

        {

        optional_element(filter1|parser1|rewrite1);

        optional_element(filter2|parser2|rewrite2);

        ...

        destination(d1); destination(d2); ...

        #another embedded log statement

        log

        {

            optional_element(filter1|parser1|rewrite1);

            optional_element(filter2|parser2|rewrite2);

            ...

            destination(d1); destination(d2); ...};

        };

    #set flags after the embedded log statements

    flags(flag1[, flag2...]);

        };
[Example] Example 8.2. Using embedded log paths

The following log path sends every message to the configured destinations: both the d_file1 and the d_file2 destinations receive every message of the source.

log { source(s_localhost); destination(d_file1); destination(d_file2); };

The next example is equivalent with the one above, but uses an embedded log statement.

log { source(s_localhost); destination(d_file1);

                    log {destination(d_file2); };

};

The following example uses two filters:

  • messages coming from the host 192.168.1.1 are sent to the d_file1 destination; and

  • messages coming from the host 192.168.1.1 and containing the string example are sent to the d_file2 destination.

log { source(s_localhost); host(192.168.1.); destination(d_file1);

                    log {message("example"); destination(d_file2); };

};

The following example collects logs from multiple source groups and uses the source() filter in the embedded log statement to select messages of the s_network source group.

log { source(s_localhost); source(s_network); destination(d_file1);

                    log {source(s_network); destination(d_file2); };

                    };

8.1.2. Log path flags

Flags influence the behavior of syslog-ng, and the way it processes messages. The following flags may be used in the log paths, as described in Section 8.1, Log paths.

Flag Description
catchall This flag means that the source of the message is ignored, only the filters are taken into account when matching messages. A log statement using the catchall flag processes every message that arrives to any of the defined sources.
fallback This flag makes a log statement 'fallback'. Fallback log statements process messages that were not processed by other, 'non-fallback' log statements.
final This flag means that the processing of log messages processed by the log statement ends here, other log statements appearing later in the configuration file will not process the messages processed by the log statement labeled as 'final'. Note that this does not necessarily mean that matching messages will be stored only once, as there can be matching log statements processed prior the current one.
flow-control Enables flow-control to the log path, meaning that syslog-ng will stop reading messages from the sources of this log statement if the destinations are not able to process the messages at the required speed. If disabled, syslog-ng will drop messages if the destination queues are full. If enabled, syslog-ng will only drop messages if the destination queues/window sizes are improperly sized. For details, see Section 8.2, Managing incoming and outgoing messages with flow-control.

Table 8.1. Log statement flags


[Warning] Warning

The final, fallback, and catchall flags apply only for the top-level log paths, they have no effect on embedded log paths.

[Example] Example 8.3. Using log path flags

Let's suppose that you have two hosts (myhost_A and myhost_B) that run two applications each (application_A and application_B), and you collect the log messages to a central syslog-ng server. On the server, you create two log paths:

  • one that processes only the messages sent by myhost_A; and

  • one that processes only the messages sent by application_A.

This means that messages sent by application_A running on myhost_A will be processed by both log paths, and the messages of application_B running on myhost_B will not be processed at all.

  • If you add the final flag to the first log path, then only this log path will process the messages of myhost_A, so the second log path will receive only the messages of application_A running on myhost_B.

  • If you create a third log path that includes the fallback flag, it will process the messages not processed by the first two log paths, in this case, the messages of application_B running on myhost_B.

  • Adding a fourth log path with the catchall flag would process every message received by the syslog-ng server.

    log { source(s_localhost); destination(d_file); flags(catchall); };

8.2. Managing incoming and outgoing messages with flow-control

This section describes the internal message-processing model of syslog-ng, as well as the flow-control feature that can prevent message losses. To use flow-control, the flow-control flag must be enabled for the particular log path.

The syslog-ng application monitors (polls) the sources defined in its configuration file, periodically checking each source for messages. When a log message is found in one of the sources, syslog-ng polls every source and reads the available messages. These messages are processed and put into the output buffer of syslog-ng (also called fifo). From the output buffer, the operating system sends the messages to the appropriate destinations.

In large-traffic environments many messages can arrive during a single poll loop, therefore syslog-ng reads only a fixed number of messages from each source. The log_fetch_limit() option specifies the number of messages read during a poll loop from a single source.

Managing log messages in syslog-ng

Figure 8.3. Managing log messages in syslog-ng


[Note] Note

The log_fetch_limit() parameter can be set as a global option, or for every source individually.

Every destination has its own output buffer. The output buffer is needed because the destination might not be able to accept all messages immediately. The log_fifo_size() parameter sets the size of the output buffer. The output buffer must be larger than the log_fetch_limit() of the sources, to ensure that every message read during the poll loop fits into the output buffer. If the log path sends messages to a destination from multiple sources, the output buffer must be large enough to store the incoming messages of every source.

TCP and unix-stream sources can receive the logs from several incoming connections (for example many different clients or applications). For such sources, syslog-ng reads messages from every connection, thus the log_fetch_limit() parameter applies individually to every connection of the source.

Managing log messages of TCP sources in syslog-ng

Figure 8.4. Managing log messages of TCP sources in syslog-ng


The flow-control of syslog-ng introduces a control window to the source that tracks how many messages can syslog-ng accept from the source. Every message that syslog-ng reads from the source lowers the window size by one; every message that syslog-ng successfully sends from the output buffer increases the window size by one. If the window is full (that is, its size decreases to zero), syslog-ng stops reading messages from the source. The initial size of the control window is by default 1000: the log_fifo_size() must be larger than this value in order for flow-control to have any effect. If a source accepts messages from multiple connections, all messages use the same control window.

[Note] Note

Starting with syslog-ng OSE version 3.3, if the source can handle multiple connections (for example, tcp()), the size of the control window is divided by the value of the max_connections() parameter and this smaller control window is applied to each connection of the source.

When flow-control is used, every source has its own control window. As a worst-case situation, the output buffer of the destination must be set to accommodate all messages of every control window, that is, the log_fifo_size() of the destination must be greater than number_of_sources*log_iw_size(). This applies to every source that sends logs to the particular destination. Thus if two sources having several connections and heavy traffic send logs to the same destination, the control window of both sources must fit into the output buffer of the destination. Otherwise, syslog-ng does not activate the flow-control, and messages may be lost.

The syslog-ng application handles outgoing messages the following way:

Handling outgoing messages in syslog-ng OSE

Figure 8.5. Handling outgoing messages in syslog-ng OSE


  • Output queue: Messages from the output queue are sent to the target syslog-ng server. The syslog-ng application puts the outgoing messages directly into the output queue, unless the output queue is full. The output queue can hold 64 messages, this is a fixed value and cannot be modified.

  • Overflow queue: If the output queue is full, syslog-ng puts the outgoing messages into the overflow queue of the destination. (The overflow queue is identical to the output buffer used by other destinations.) The log_fifo_size() parameter specifies the number of messages stored in the overflow queue. For details on sizing the log_fifo_size() parameter, see Section 8.2, Managing incoming and outgoing messages with flow-control.

8.2.1. Flow-control and multiple destinations

Using flow-control on a source has an important side-effect if the messages of the source are sent to multiple destinations. If flow-control is in use and one of the destinations cannot accept the messages, the other destinations do not receive any messages either, because syslog-ng stops reading the source. For example, if messages from a source are sent to a remote server and also stored locally in a file, and the network connection to the server becomes unavailable, neither the remote server nor the local file will receive any messages.

[Note] Note

Creating separate log paths for the destinations that use the same flow-controlled source does not avoid the problem.

8.2.2. Configuring flow-control

For details on how flow-control works, see Section 8.2, Managing incoming and outgoing messages with flow-control. The summary of the main points is as follows:

  • The syslog-ng application normally reads a maximum of log_fetch_limit() number of messages from a source.

  • From TCP and unix-stream sources, syslog-ng reads a maximum of log_fetch_limit() from every connection of the source. The number of connections to the source is set using the max_connections() parameter.

  • Every destination has an output buffer (log_fifo_size()).

  • Flow-control uses a control window to determine if there is free space in the output buffer for new messages. Every source has its own control window; log_iw_size() parameter sets the size of the control window.

  • When a source accepts multiple connections, the size of the control window is divided by the value of the max_connections() parameter and this smaller control window is applied to each connection of the source.

  • The output buffer must be larger than the control window of every source that logs to the destination.

  • If the control window is full, syslog-ng stops reading messages from the source until some messages are successfully sent to the destination.

  • If the output buffer becomes full, and flow-control is not used, messages may be lost.

[Note] Note

If you modify the max_connections() or the log_fetch_limit() parameter, do not forget to adjust the log_iw_size() and log_fifo_size() parameters accordingly.

[Example] Example 8.4. Sizing parameters for flow-control

Suppose that syslog-ng has a source that must accept up to 300 parallel connections. Such situation can arise when a network source receives connections from many clients, or if many applications log to the same socket. Therefore, set the max_connections() parameter of the source to 300. However, the log_fetch_limit() (default value: 10) parameter applies to every connection of the source individually, while the log_iw_size() (default value: 1000) parameter applies to the source. In a worst-case scenario, the destination does not accept any messages, while all 300 connections send at least log_fetch_limit() number of messages to the source during every poll loop. Therefore, the control window must accommodate at least max_connections()*log_fetch_limit() messages to be able to read every incoming message of a poll loop. In the current example this means that (log_iw_size() should be greater than 300*10=3000. If the control window is smaller than this value, the control window might fill up with messages from the first connections — causing syslog-ng to read only one message of the last connections in every poll loop.

The output buffer of the destination must accommodate at least log_iw_size() messages, but use a greater value: in the current example 3000*10=30000 messages. That way all incoming messages of ten poll loops fit in the output buffer. If the output buffer is full, syslog-ng does not read any messages from the source until some messages are successfully sent to the destination.

source s_localhost {

            tcp(ip(127.0.0.1) port(1999) max-connections(300)); };

destination d_tcp {

            tcp("10.1.2.3" port(1999); localport(999)); log_fifo_size(30000); };

log { source(s_localhost); destination(d_tcp); flags(flow-control); };

If other sources send messages to this destination, than the output buffer must be further increased. For example, if a network host with maximum 100 connections also logs into the destination, than increase the log_fifo_size() by 10000.

source s_localhost {

            tcp(ip(127.0.0.1) port(1999) max-connections(300)); };

source s_tcp {

            tcp(ip(192.168.1.5) port(1999) max-connections(100)); };

destination d_tcp {

            tcp("10.1.2.3" port(1999); localport(999)); log_fifo_size(40000); };

log { source(s_localhost); destination(d_tcp); flags(flow-control); };

For details, see also Section 17.2, Handling lots of parallel connections.

8.3. Filters

The following sections describe how to select and filter log messages.

8.3.1. Using filters

Filters perform log routing within syslog-ng: a message passes the filter if the filter expression is true for the particular message. If a log statement includes filters, the messages are sent to the destinations only if they pass all filters of the log path. For example, a filter can select only the messages originating from a particular host. Complex filters can be created using filter functions and logical boolean expressions.

To define a filter, add a filter statement to the syslog-ng configuration file using the following syntax:

filter <identifier> { <filter_type>("<filter_expression>"); };
[Example] Example 8.5. A simple filter statement

The following filter statement selects the messages that contain the word deny and come from the host example.

filter demo_filter { host("example") and match("deny" value("MESSAGE")) };

For the filter to have effect, include it in a log statement:

log demo_filteredlog {

        source(s1);

        filter(demo_filter);

        destination(d1);};

8.3.2. Combining filters with boolean operators

When a log statement includes multiple filter statements, syslog-ng sends a message to the destination only if all filters are true for the message. In other words, the filters are connected with the logical AND operator. In the following example, no message arrives to the destination, because the filters are exclusive (the hostname of a client cannot be example1 and example2 at the same time):

filter demo_filter1 { host("example1"); };

filter demo_filter2 { host("example2"); };

log demo_filteredlog {

    source(s1); source(s2);

    filter(demo_filter1); filter(demo_filter2);

    destination(d1); destination(d2); };

To select the messages that come from either host example1 or example2, use a single filter expression:

filter demo_filter { host("example1") or host("example2"); };

log demo_filteredlog {

    source(s1); source(s2);

    filter(demo_filter);

    destination(d1); destination(d2); };

Use the not operator to invert filters, for example, to select the messages that were not sent by host example1:

filter demo_filter { not host("example1"); };

However, to select the messages that were not sent by host example1 or example2, you have to use the and operator (that's how boolean logic works):

filter demo_filter { not host("example1") and not host("example2"); };

Alternatively, you can use parentheses to avoid this confusion:

filter demo_filter { not (host("example1") or host("example2")); };

For a complete description on filter functions, see Section 8.3.6, Filter functions.

The following filter statement selects the messages that contain the word deny and come from the host example.

filter demo_filter { host("example") and match("deny" value("MESSAGE")); };

The value() parameter of the match function limits the scope of the function to the text part of the message (that is, the part returned by the $MESSAGE macro). For details on using the match() filter function, see Section match().

[Tip] Tip

Filters are often used together with log path flags. For details, see Section 8.1.2, Log path flags.

8.3.3. Comparing macro values in filters

Starting with syslog-ng OSE version 3.2, it is also possible to compare macro values and templates as numerical and string values. String comparison is alphabetical: it determines if a string is alphabetically greater or equal to another string. Use the following syntax to compare macro values or templates. For details on macros and templates, see Section 11.1, Customizing message format.

filter <filter-id>

        {"<macro-or-template>" operator "<value-or-macro-or-template>"};
[Example] Example 8.6. Comparing macro values in filters

The following expression selects log messages containing a PID (that is, $PID macro is not empty):

filter f_pid {"$PID" !=""};

The following expression accomplishes the same, but uses a template as the left argument of the operator and compares the values as strings:

filter f_pid {"$HOST$PID" eq "$HOST"};

The following example selects messages with priority level 4 or higher.

filter f_level {"$LEVEL_NUM" > "5"};

Note that:

  • The macro or template must be enclosed in double-quotes.

  • The $ character must be used before macros.

  • Using comparator operators can be equivalent to using filter functions, but is somewhat slower. For example, using "$HOST" eq "myhost" is equivalent to using host("myhost" type(string)).

  • You can use any macro in the expression, including user-defined macros from parsers and results of pattern database classifications.

  • The results of filter functions are boolean values, so they cannot be compared to other values.

  • You can use boolean operators to combine comparison expressions.

The following operators are available:

Numerical operator String operator Meaning
== eq Equals
!= ne Not equal to
> gt Greater than
< lt Less than
>= ge Greater than or equal
=< le Less than or equal

Table 8.2. Numerical and string comparison operators


8.3.4. Using wildcards, special characters, and regular expressions in filters

The host(), match(), and program() filter functions accept regular expressions as parameters. The exact type of the regular expression to use can be specified with the type() option. By default, syslog-ng OSE uses POSIX regular expressions.

In regular expressions, the asterisk (*) character means 0, 1 or any number of the previous expression. For example, in the f*ilter expression the asterisk means 0 or more f letters. This expression matches for the following strings: ilter, filter, ffilter, and so on. To achieve the wildcard functionality commonly represented by the asterisk character in other applications, use .* in your expressions, for example f.*ilter.

Alternatively, if you do not need regular expressions, only wildcards, use type(glob) in your filter:

[Example] Example 8.7. Filtering with widcards

The following filter matches on hostnames starting with the myhost string, for example, on myhost-1, myhost-2, and so on.

filter f_wildcard {host("myhost*" type(glob));};

For details on using regular expressions in syslog-ng OSE, see Section 11.3, Regular expressions.

To filter for special control characters like the carriage return (CR), use the \r escape prefix in syslog-ng OSE version 3.0 and 3.1. In syslog-ng OSE 3.2 and later, you can also use the \x escape prefix and the ASCII code of the character. For example, to filter on carriage returns, use the following filter:

filter f_carriage_return {match("\x0d" value ("MESSAGE"));};

8.3.5. Tagging messages

Starting with syslog-ng 3.1, it is also possible to label the messages with custom tags. Tags are simple labels, identified by their names, which must be unique. Currently syslog-ng can tag a message at two different places:

When syslog-ng receives a message, it automatically adds the .source.<id_of_the_source_statement> tag to the message. Use the tags() option of the source to add custom tags, and the tags() option of the filters to select only specific messages.

[Note] Note
  • Tagging messages and also filtering on the tags is very fast, much faster then other types of filters.

  • Tags are available locally, that is, if you add tags to a message on the client, these tags will not be available on the server.

  • To include the tags in the message, use the $TAGS macro in a template. Alternatively, if you are using the IETF-syslog message format, you can include the $TAGS macro in the .SDATA.meta part of the message. Note that the $TAGS macro is available only in syslog-ng OSE 3.1.1 and later.

For an example on tagging, see Example 8.8, Adding tags and filtering messages with tags.

8.3.6. Filter functions

The following functions may be used in the filter statement, as described in Section 8.3, Filters.

Name Description
facility() Filter messages based on the sending facility.
filter() Call another filter function.
host() Filter messages based on the sending host.
level() or priority() Filter messages based on their priority.
match() Use a regular expression to filter messages based on a specified header or content field.
message() Use a regular expression to filter messages based their content.
netmask() Filter messages based on the IP address of the sending host.
program() Filter messages based on the sending application.
source() Select messages of the specified syslog-ng OSE source statement.
tags() Select messages having the specified tag.

Table 8.3. Filter functions available in syslog-ng OSE


facility()

Synopsis: facility(facility[,facility])

Description: Match messages having one of the listed facility code. An alternate syntax permits the use an arbitrary facility codes.

The facility() filter accepts both the name and the numerical code of the facility or the importance level.

Messages sent by a range of facilities can also be selected. Note that this is only possible when using the name of the facilities. It is not possible to select ranges the numerical codes of the facilities.

facility(local0..local5)

The syslog-ng application recognizes the following facilities: (Note that some of these facilities are available only on specific platforms.)

Numerical Code Facility name Facility
0 kern kernel messages
1 user user-level messages
2 mail mail system
3 daemon system daemons
4 auth security/authorization messages
5 syslog messages generated internally by syslogd
6 lpr line printer subsystem
7 news network news subsystem
8 uucp UUCP subsystem
9 cron clock daemon
10 authpriv security/authorization messages
11 ftp FTP daemon
12 ntp NTP subsystem
13 security log audit
14 console log alert
15 solaris-cron clock daemon
16-23 local0..local7 locally used facilities (local0-local7)

Table 8.4. syslog Message Facilities recognized by the facility() filter


facility()

Synopsis: facility(<numeric facility code>)

Description: An alternate syntax for facility permitting the use of an arbitrary facility code. Facility codes 0-23 are predefined and can be referenced by their usual name. Facility codes above 24 are not defined but can be used by this alternate syntax.

filter()

Synopsis: filter(filtername)

Description: Call another filter rule and evaluate its value.

host()

Synopsis: host(regexp)

Description: Match messages by using a regular expression against the hostname field of log messages.

level() or priority()

Synopsis: level(pri[,pri1..pri2[,pri3]])

Description: Match messages based on priority.

The level() filter accepts the following levels: emerg, alert, crit, err, warning, notice, info, debug.

The level() filter can select messages corresponding to a single importance level, or a level-range. To select messages of a specific level, use the name of the level as a filter parameter, for example use the following to select warning messages:

level(warning)

To select a range of levels, include the beginning and the ending level in the filter, separated with two dots (..). For example, to select every message of error or higher level, use the following filter:

level(err..emerg)

match()

Synopsis: match(regexp)

Description: Match a regular expression to the headers and the message itself (that is, the values returned by the MSGHDR and MSG macros). Note that in syslog-ng version 2.1 and earlier, the match() filter was applied only to the text of the message, excluding the headers. This functionality has been moved to the message() filter.

To limit the scope of the match to a specific part of the message (identified with a macro), use the match(regexp value("MACRO")) syntax. Do not include the $ sign in the parameter of the value() option.

The value() parameter accepts both built-in macros and user-defined ones created with a parser or using a pattern database. For details on macros and parsers, see Section 11.1.2, Templates and macros, Section 12.1, Parsing messages, and Section 13.2.1, Using parser results in filters and templates.

message()

Synopsis: message(regexp)

Description: Match a regular expression to the text of the log message, excluding the headers (that is, the value returned by the MSG macros). Note that in syslog-ng version 2.1 and earlier, this functionality was performed by the match() filter.

netmask()

Synopsis: netmask(ip/mask)

Description: Select only messages sent by a host whose IP address belongs to the specified IP subnet. Note that this filter checks the IP address of the last-hop relay (the host that actually sent the message to syslog-ng), not the contents of the HOST field of the message.

program()

Synopsis: program(regexp)

Description: Match messages by using a regular expression against the program name field of log messages.

source()

Synopsis: source id

Description: Select messages of a source statement. This filter can be used in embedded log statements if the parent statement contains multiple source groups — only messages originating from the selected source group are sent to the destination of the embedded log statement.

tags()

Synopsis: tag

Description: Select messages labeled with the specified tag. Every message automatically has the tag of its source in .source.<id_of_the_source_statement> format. This option is available only in syslog-ng 3.1 and later.

[Example] Example 8.8. Adding tags and filtering messages with tags
source s_tcp {

    tcp(ip(192.168.1.1) port(1514) tags("tcp", "router"));

    };

Use the tags() option of the filters to select only specific messages:

filter f_tcp {

       tags(".source.s_tcp");

    };



    filter f_router {

       tags("router");

    };

Starting with version 3.2, syslog-ng OSE automatically adds the class of the message as a tag using the .classifier.<message-class> format. For example, messages classified as "system" receive the .classifier.system tag. Use the tags() filter function to select messages of a specific class.

filter f_tag_filter {tags(".classifier.system");};

8.4. Dropping messages

To skip the processing of a message without sending it to a destination, create a log statement with the appropriate filters, but do not include any destination in the statement, and use the final flag.

[Example] Example 8.9. Skipping messages

The following log statement drops all debug level messages without any further processing.

filter demo_debugfilter { level(debug); };

log { source(s_all); filter(demo_debugfilter); flags(final); };

Chapter 9. Global options of syslog-ng OSE

9.1. Configuring global syslog-ng options

The syslog-ng application has a number of global options governing DNS usage, the timestamp format used, and other general points. Each option may have parameters, similarly to driver specifications. To set global options, add an option statement to the syslog-ng configuration file using the following syntax:

options { option1(params); option2(params); ... };
[Example] Example 9.1. Using global options

To disable domain name resolving, add the following line to the syslog-ng configuration file:

options { use_dns(no); };

For a detailed list of the available options, see Section 9.2, Global options. For important global options and recommendations on their use, see Chapter 17, Best practices and examples.

9.2. Global options

The following options can be specified in the options statement, as described in Section 9.1, Configuring global syslog-ng options.

bad_hostname()

Accepted values: regular expression
Default: no

Description: A regexp containing hostnames which should not be handled as hostnames.

chain_hostnames()

Accepted values: yes | no
Default: no

Description: Enable or disable the chained hostname format. If the log message is forwarded to the logserver via a relay, and the chain_hostnames() option is enabled, the relay adds its own hostname to the hostname of the client, separated with a / character. For example, consider a client-relay-server scenario with the following hostnames: client-hostname, relay-hostname, server-hostname. The hostname of the log message received by the server will look like: client-hostname/relay-hostname. If the client sends a hostname in the message that is different from its real hostname (as resolved from DNS), the relay can add the resolved hostname to the message, resulting in two different client hostnames in the message, for examle, client-hostname-from-the-message/client-hostname-resolved-on-the-relay/relay-hostname.

check_hostname()

Accepted values: yes | no
Default: no

Description: Enable or disable checking whether the hostname contains valid characters.

create_dirs()

Accepted values: yes | no
Default: no

Description: Enable or disable directory creation for destination files.

dir_group()

Accepted values: groupid
Default: root

Description: The default group for newly created directories.

dir_owner()

Accepted values: userid
Default: root

Description: The default owner of newly created directories.

dir_perm()

Accepted values: permission value
Default: 0700

Description: The permission mask of directories created by syslog-ng. Log directories are only created if a file after macro expansion refers to a non-existing directory, and directory creation is enabled (see also the create_dirs() option). For octal numbers prefix the number with 0, for example use 0755 for rwxr-xr-x.

To preserve the original properties of an existing directory, use the option without specifying an attribute: dir_perm(). Note that when creating a new directory without specifying attributes for dir_perm(), the default permission of the directories is masked with the umask of the parent process (typically 0022).

dns_cache()

Accepted values: yes | no
Default: yes

Description: Enable or disable DNS cache usage.

dns_cache_expire()

Accepted values: number
Default: 3600

Description: Number of seconds while a successful lookup is cached.

dns_cache_expire_failed()

Accepted values: number
Default: 60

Description: Number of seconds while a failed lookup is cached.

dns_cache_hosts()

Accepted values: filename
Default: unset

Description: Name of a file in /etc/hosts format that contains static IP->hostname mappings. Use this option to resolve hostnames locally without using a DNS. Note that any change to this file triggers a reload in syslog-ng and is instantaneous.

dns_cache_size()

Accepted values: number
Default: 1007

Description: Number of hostnames in the DNS cache.

file-template()

Accepted values: time offset (for example: +03:00)
Default: local timezone

Description: Specifies a template that file-like destinations use by default. For example:

template t_isostamp { template("$ISODATE $HOST $MSGHDR$MSG\n"); };



options { file-template(t_isostamp); };

flush_lines()

Accepted values: number
Default: 0

Description: Specifies how many lines are flushed to a destination at a time. Syslog-ng waits for this number of lines to accumulate and sends them off in a single batch. Setting this number high increases throughput as fully filled frames are sent to the network, but also increases message latency. The latency can be limited by the use of the flush_timeout option.

flush_timeout()

Accepted values: time in milliseconds
Default: 10000

Description: Specifies the time syslog-ng waits for lines to accumulate in its output buffer. For more information, see the flush_lines() option.

group()

Accepted values: groupid
Default: root

Description: The default group of output files. By default, syslog-ng changes the privileges of accessed files (for example /dev/null) to root.root 0600. To disable modifying privileges, use this option with the -1 value.

keep_hostname()

Type: yes or no
Default: no

Description: Enable or disable hostname rewriting.

  • If enabled (keep_hostname(yes)), syslog-ng OSE assumes that the incoming log message was sent by the host specified in the HOST field of the message.

  • If disabled (keep_hostname(no)), syslog-ng OSE rewrites the HOST field of the message, either to the IP address (if the use_dns() parameter is set to no), or to the hostname (if the use_dns() parameter is set to yes and the IP address can be resolved to a hostname) of the host sending the message to syslog-ng OSE. For details on using name resolution in syslog-ng OSE, see Section 17.4, Using name resolution in syslog-ng.

[Note] Note

If the log message does not contain a hostname in its HOST field, syslog-ng OSE automatically adds a hostname to the message.

  • For messages received from the network, this hostname is the address of the host that sent the message (this means the address of the last hop if the message was transferred via a relay).

  • For messages received from the local host, syslog-ng OSE adds the name of the host.

This option can be specified globally, and per-source as well. The local setting of the source overrides the global option if available.

[Note] Note

When relaying messages, enable this option on the syslog-ng OSE server and also on every relay, otherwise syslog-ng OSE will treat incoming messages as if they were sent by the last relay.

keep_timestamp()

Type: yes or no
Default: yes

Description: Specifies whether syslog-ng should accept the timestamp received from the sending application or client. If disabled, the time of reception will be used instead. This option can be specified globally, and per-source as well. The local setting of the source overrides the global option if available.

log_fifo_size()

Accepted values: number
Default: 10000

Description: The number of messages that the output queue can store.

log_msg_size()

Accepted values: number
Default: 8192

Description: Maximum length of a message in bytes.

normalize_hostnames()

Accepted values: yes | no
Default: no

Description: If enabled (normalize_hostnames(yes)), syslog-ng OSE converts the hostnames to lowercase.

[Note] Note

This setting applies only to hostnames resolved from DNS. It has no effect if the keep_hostname() option is enabled, and the message contains a hostname.

owner()

Accepted values: userid
Default: root

Description: The default owner of output files. By default, syslog-ng changes the privileges of accessed files (for example /dev/null) to root.root 0600. To disable modifying privileges, use this option with the -1 value.

mark()

Accepted values: number
Default: 1200

Description: An alias for the obsolete mark_freq() option, retained for compatibility with syslog-ng version 1.6.x.

mark_freq()

Accepted values: number
Default: 1200

Description: The number of seconds between two MARK messages. MARK messages are generated when there was no message traffic to inform the receiver that the connection is still alive. Note that only local messages postpone the sending of the MARK message, relayed messages do not. If set to zero (0), no MARK messages are sent.

perm()

Accepted values: permission value
Default: 0600

Description: The default permission for output files. By default, syslog-ng changes the privileges of accessed files (for example /dev/null) to root.root 0600. To disable modifying privileges, use this option with the -1 value.

proto-template()

Accepted values: time offset (for example: +03:00)
Default: local timezone

Description: Specifies a template that protocol-like destinations (for example, tcp() and syslog()) use by default. For example:

template t_isostamp { template("$ISODATE $HOST $MSGHDR$MSG\n"); };



options { proto-template(t_isostamp); };

recv_time_zone()

Accepted values: time offset (for example: +03:00)
Default: local timezone

Description: Specifies the time zone associated with the incoming messages, if not specified otherwise in the message or in the source driver. For details, see also Section 2.5, Timezones and daylight saving and Section 2.5.1, A note on timezones and timestamps.

send_time_zone()

Accepted values: time offset (for example: +03:00)
Default: local timezone

Description: Specifies the time zone associated with the messages sent by syslog-ng, if not specified otherwise in the message or in the destination driver. For details, see Section 2.5, Timezones and daylight saving.

stats_freq()

Accepted values: number
Default: 600

Description: The period between two STATS messages in seconds. STATS are log messages sent by syslog-ng, containing statistics about dropped log messages. Set to 0 to disable the STATS messages.

stats_level()

Accepted values: 0 | 1 | 2 | 3
Default: 0

Description: Specifies the detail of statistics syslog-ng collects about the processed messages.

  • Level 0 collects only statistics about the sources and destinations

  • Level 1 contains details about the different connections and log files, but has a slight memory overhead

  • Level 2 contains detailed statistics based on the hostname.

  • Level 3 contains detailed statistics based on various message parameters like facility, severity, or tags.

Note that level 2 and 3 increase the memory requirements and CPU load. For details on message statistics, see Chapter 14, Statistics of syslog-ng.

sync() or sync_freq() (DEPRECATED)

Accepted values: number
Default: 0

Description: Obsolete aliases for flush_lines()

threaded()

Accepted values: yes|no
Default: no

Description: Enable syslog-ng OSE to run in multithreaded mode and use multiple CPUs. Available only in syslog-ng Open Source Edition 3.3 and later. See Chapter 15, Multithreading and scaling in syslog-ng OSE for details.

time_reap()

Accepted values: number
Default: 60

Description: The time to wait in seconds before an idle destination file is closed. Note that only destination files having macros in their filenames are closed automatically.

time_reopen()

Accepted values: number
Default: 60

Description: The time to wait in seconds before a dead connection is reestablished.

time_sleep()

Accepted values: number
Default: 0

Description: The time to wait in milliseconds between each invocation of the poll() iteration.

time_zone()

Type: timezone in +/-HH:MM format
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.

ts_format()

Accepted values: rfc3164 | bsd | rfc3339 | iso
Default: rfc3164

Description: Specifies the timestamp format used when syslog-ng itself formats a timestamp and nothing else specifies a format (for example: STAMP macros, internal messages, messages without original timestamps). For details, see also Section 2.5.1, A note on timezones and timestamps.

[Note] Note

This option applies only to file and file-like destinations. Destinations that use specific protocols (for example, tcp(), or syslog()) ignore this option. For protocol-like destinations, use a template locally in the destination, or use the proto-template option.

use_dns()

Type: yes, no, persist_only
Default: yes

Description: Enable or disable DNS usage. The persist_only option attempts to resolve hostnames locally from file (for example from /etc/hosts). syslog-ng blocks on DNS queries, so enabling DNS may lead to a Denial of Service attack. To prevent DoS, protect your syslog-ng network endpoint with firewall rules, and make sure that all hosts which may get to syslog-ng are resolvable. This option can be specified globally, and per-source as well. The local setting of the source overrides the global option if available.

use_fqdn()

Type: yes or no
Default: no

Description: Add Fully Qualified Domain Name instead of short hostname. This option can be specified globally, and per-source as well. The local setting of the source overrides the global option if available.

use_time_recvd() (DEPRECATED)

Accepted values: yes | no
Default: no
[Warning] Warning

This option is not available in syslog-ng OSE version 3.2 and later. Use the R_ prefixed version of the respective macro instead. Starting with syslog-ng OSE version 3.2, the DATE macro equals the S_DATE macro.

Description: This option controls how the time related macros are expanded in filename and content templates. If set to yes, then the non-prefixed versions of the time related macros (for example: HOUR instead of R_HOUR and S_HOUR) refer to the time when the message was received, otherwise it refers to the timestamp which is in the message.

[Note] Note

The timestamps in the messages are generated by the originating host and might not be accurate.

This option is deprecated as many users assumed that it controls the timestamp as it is written to logfiles/destinations, which is not the case. To change how messages are formatted, specify a content-template referring to the appropriate prefixed (S_ or R_) time macro.

Chapter 10. TLS-encrypted message tranfer

10.1. Secure logging using TLS

The syslog-ng application can send and receive log messages securely over the network using the Transport Layer Security (TLS) protocol. TLS is an encryption protocol over the TCP/IP network protocol, so it can be used only with TCP-based sources and destinations ( tcp() and tcp6()).

TLS uses certificates to authenticate and encrypt the communication, as illustrated on the following figure:

Certificate-based authentication

Figure 10.1. Certificate-based authentication


The client authenticates the server by requesting its certificate and public key. Optionally, the server can also request a certificate from the client, thus mutual authentication is also possible.

In order to use TLS encryption in syslog-ng, the following elements are required:

  • A certificate on the syslog-ng server that identifies the syslog-ng server.

  • The certificate of the Certificate Authority that issued the certificate of the syslog-ng server must be available on the syslog-ng client.

When using mutual authentication to verify the identity of the clients, the following elements are required:

  • A certificate must be available on the syslog-ng client. This certificate identifies the syslog-ng client.

  • The certificate of the Certificate Authority that issued the certificate of the syslog-ng client must be available on the syslog-ng server.

Mutual authentication ensures that the syslog-ng server accepts log messages only from authorized clients.

For details on configuring TLS communication in syslog-ng, see Section 10.2, Encrypting log messages with TLS.

10.2. Encrypting log messages with TLS

This section describes how to configure TLS encryption in syslog-ng. For the concepts of using TLS in syslog-ng, see Section 10.1, Secure logging using TLS.

Create an X.509 certificate for the syslog-ng server.

[Note] Note

The subject_alt_name parameter (or the Common Name parameter if the subject_alt_name parameter is empty) of the server's certificate must contain the hostname or the IP address (as resolved from the syslog-ng clients and relays) of the server (for example syslog-ng.example.com).

Alternatively, the Common Name or the subject_alt_name parameter can contain a generic hostname, for example *.example.com.

Note that if the Common Name of the certificate contains a generic hostname, do not specify a specific hostname or an IP address in the subject_alt_name parameter.

10.2.1. Procedure – Configuring TLS on the syslog-ng clients

Purpose: 

Complete the following steps on every syslog-ng client host. Examples are provided using both the legacy BSD-syslog protocol (using the tcp() driver) and the new IETF-syslog protocol standard (using the syslog() driver):

Steps: 

  1. Copy the CA certificate (for example cacert.pem) of the Certificate Authority that issued the certificate of the syslog-ng server to the syslog-ng client hosts, for example into the /opt/syslog-ng/etc/syslog-ng/ca.d directory.

    Issue the following command on the certificate: openssl x509 -noout -hash -in cacert.pem The result is a hash (for example 6d2962a8), a series of alphanumeric characters based on the Distinguished Name of the certificate.

    Issue the following command to create a symbolic link to the certificate that uses the hash returned by the previous command and the .0 suffix.

    ln -s cacert.pem 6d2962a8.0

  2. Add a destination statement to the syslog-ng configuration file that uses the tls( ca_dir(path_to_ca_directory) ) option and specify the directory using the CA certificate. The destination must use the tcp() or tcpv6() destination driver, and the IP address and port parameters of the driver must point to the syslog-ng server.

    [Example] Example 10.1. A destination statement using TLS

    The following destination encrypts the log messages using TLS and sends them to the 6514/TCP port of the syslog-ng server having the 10.1.2.3 IP address.

    destination demo_tls_destination {
    
                    tcp("10.1.2.3" port(6514) 
    
                        tls( ca_dir("/opt/syslog-ng/etc/syslog-ng/ca.d")) ); };

    A similar statement using the IETF-syslog protocol and thus the syslog() driver:

    destination demo_tls_syslog_destination { syslog("10.1.2.3" port(6514)
    
                            transport("tls")
    
                            port(3214)
    
                            tls(ca_dir("/opt/syslog-ng/etc/syslog-ng/ca.d")) ); 
    
    };
  3. Include the destination created in Step 2 in a log statement.

    [Warning] Warning

    The encrypted connection between the server and the client fails if the Common Name or the subject_alt_name parameter of the server certificate does not contain the hostname or the IP address (as resolved from the syslog-ng clients and relays) of the server.

    Do not forget to update the certificate files when they expire.

10.2.2. Procedure – Configuring TLS on the syslog-ng server

Purpose: 

Complete the following steps on the syslog-ng server:

Steps: 

  1. Copy the certificate (for example syslog-ng.cert) of the syslog-ng server to the syslog-ng server host, for example into the /opt/syslog-ng/etc/syslog-ng/cert.d directory. The certificate must be a valid X.509 certificate in PEM format.

  2. Copy the private key (for example syslog-ng.key) matching the certificate of the syslog-ng server to the syslog-ng server host, for example into the /opt/syslog-ng/etc/syslog-ng/key.d directory. The key must be in PEM format, and must not be password-protected.

  3. Add a source statement to the syslog-ng configuration file that uses the tls( key_file(key_file_fullpathname) cert_file(cert_file_fullpathname) ) option and specify the key and certificate files. The source must use the source driver (tcp() or tcpv6()) matching the destination driver used by the syslog-ng client.

    [Example] Example 10.2. A source statement using TLS

    The following source receives log messages encrypted using TLS, arriving to the 1999/TCP port of any interface of the syslog-ng server.

    source demo_tls_source {
    
               tcp(ip(0.0.0.0) port(1999) 
    
                   tls( key_file("/opt/syslog-ng/etc/syslog-ng/key.d/syslog-ng.key") 
    
                        cert_file("/opt/syslog-ng/etc/syslog-ng/cert.d/syslog-ng.cert")) ); };

    A similar source for receiving messages using the IETF-syslog protocol:

    source demo_tls_syslog_source {                    
    
                        syslog(ip(0.0.0.0) port(1999)
    
                        transport("tls")
    
                        tls( key_file("/opt/syslog-ng/etc/syslog-ng/key.d/syslog-ng.key") 
    
                        cert_file("/opt/syslog-ng/etc/syslog-ng/cert.d/syslog-ng.cert")) ); };
  4. Disable mutual authentication for the source by setting the following TLS option in the source statement: tls( peer_verify(optional-untrusted);

    For details on how to configure mutual authentication, see Section 10.3, Mutual authentication using TLS.

    [Example] Example 10.3. Disabling mutual authentication

    The following source receives log messages encrypted using TLS, arriving to the 1999/TCP port of any interface of the syslog-ng server. The identity of the syslog-ng client is not verified.

    source demo_tls_source {
    
               tcp(ip(0.0.0.0) port(1999) 
    
                   tls( key_file("/opt/syslog-ng/etc/syslog-ng/key.d/syslog-ng.key") 
    
                        cert_file("/opt/syslog-ng/etc/syslog-ng/cert.d/syslog-ng.cert") 
    
                        peer_verify(optional-untrusted))  ); };

    A similar source for receiving messages using the IETF-syslog protocol:

    source demo_tls_syslog_source {                    
    
                            syslog(ip(0.0.0.0) port(1999)
    
                            transport("tls")
    
                            tls( key_file("/opt/syslog-ng/etc/syslog-ng/key.d/syslog-ng.key") 
    
                            cert_file("/opt/syslog-ng/etc/syslog-ng/cert.d/syslog-ng.cert") 
    
                            peer_verify(optional-untrusted))  ); };
    [Warning] Warning

    Do not forget to update the certificate and key files when they expire.

For the details of the available tls() options, see Section 10.4, TLS options.

10.3. Mutual authentication using TLS

This section describes how to configure mutual authentication between the syslog-ng server and the client. Configuring mutual authentication is similar to configuring TLS (for details, see Section 10.2, Encrypting log messages with TLS), but the server verifies the identity of the client as well. Therefore, each client must have a certificate, and the server must have the certificate of the CA that issued the certificate of the clients. For the concepts of using TLS in syslog-ng, see Section 10.1, Secure logging using TLS.

10.3.1. Procedure – Configuring TLS on the syslog-ng clients

Purpose: 

Complete the following steps on every syslog-ng client host. Examples are provided using both the legacy BSD-syslog protocol (using the tcp() driver) and the new IETF-syslog protocol standard (using the syslog() driver):

Steps: 

  1. Create an X.509 certificate for the syslog-ng client.

  2. Copy the certificate (for example client_cert.pem) and the matching private key (for example client.key) to the syslog-ng client host, for example into the /opt/syslog-ng/etc/syslog-ng/cert.d directory. The certificate must be a valid X.509 certificate in PEM format and must not be password-protected.

  3. Copy the CA certificate of the Certificate Authority (for example cacert.pem) that issued the certificate of the syslog-ng server to the syslog-ng client hosts, for example into the /opt/syslog-ng/etc/syslog-ng/ca.d directory.

    Issue the following command on the certificate: openssl x509 -noout -hash -in cacert.pem The result is a hash (for example 6d2962a8), a series of alphanumeric characters based on the Distinguished Name of the certificate.

    Issue the following command to create a symbolic link to the certificate that uses the hash returned by the previous command and the .0 suffix.

    ln -s cacert.pem 6d2962a8.0

  4. Add a destination statement to the syslog-ng configuration file that uses the tls( ca_dir(path_to_ca_directory) ) option and specify the directory using the CA certificate. The destination must use the tcp() or tcpv6() destination driver, and the IP address and port parameters of the driver must point to the syslog-ng server. Include the client's certificate and private key in the tls() options.

    [Example] Example 10.4. A destination statement using mutual authentication

    The following destination encrypts the log messages using TLS and sends them to the 1999/TCP port of the syslog-ng server having the 10.1.2.3 IP address. The private key and the certificate file authenticating the client is also specified.

    destination demo_tls_destination {
    
        tcp("10.1.2.3" port(1999) 
    
            tls( ca_dir("/opt/syslog-ng/etc/syslog-ng/ca.d") 
    
                 key_file("/opt/syslog-ng/etc/syslog-ng/key.d/client.key")
    
                 cert_file("/opt/syslog-ng/etc/syslog-ng/cert.d/client_cert.pem")) ); };
    destination demo_tls_syslog_destination {
    
        syslog("10.1.2.3" port(1999) 
    
            transport("tls")
    
                tls( ca_dir("/opt/syslog-ng/etc/syslog-ng/ca.d")
    
                     key_file("/opt/syslog-ng/etc/syslog-ng/key.d/client.key")
    
                     cert_file("/opt/syslog-ng/etc/syslog-ng/cert.d/client_cert.pem")) ); };
  5. Include the destination created in Step 2 in a log statement.

    [Warning] Warning

    The encrypted connection between the server and the client fails if the Common Name or the subject_alt_name parameter of the server certificate does not the hostname or the IP address (as resolved from the syslog-ng clients and relays) of the server.

    Do not forget to update the certificate files when they expire.

10.3.2. Procedure – Configuring TLS on the syslog-ng server

Purpose: 

Complete the following steps on the syslog-ng server:

Steps: 

  1. Copy the certificate (for example syslog-ng.cert) of the syslog-ng server to the syslog-ng server host, for example into the /opt/syslog-ng/etc/syslog-ng/cert.d directory. The certificate must be a valid X.509 certificate in PEM format.

  2. Copy the CA certificate (for example cacert.pem) of the Certificate Authority that issued the certificate of the syslog-ng clients to the syslog-ng server, for example into the /opt/syslog-ng/etc/syslog-ng/ca.d directory.

    Issue the following command on the certificate: openssl x509 -noout -hash -in cacert.pem The result is a hash (for example 6d2962a8), a series of alphanumeric characters based on the Distinguished Name of the certificate.

    Issue the following command to create a symbolic link to the certificate that uses the hash returned by the previous command and the .0 suffix.

    ln -s cacert.pem 6d2962a8.0

  3. Copy the private key (for example syslog-ng.key) matching the certificate of the syslog-ng server to the syslog-ng server host, for example into the /opt/syslog-ng/etc/syslog-ng/key.d directory. The key must be in PEM format, and must not be password-protected.

  4. Add a source statement to the syslog-ng configuration file that uses the tls( key_file(key_file_fullpathname) cert_file(cert_file_fullpathname) ) option and specify the key and certificate files. The source must use the source driver (tcp() or tcpv6()) matching the destination driver used by the syslog-ng client. Also specify the directory storing the certificate of the CA that issued the client's certificate.

    [Example] Example 10.5. A source statement using TLS

    The following source receives log messages encrypted using TLS, arriving to the 1999/TCP port of any interface of the syslog-ng server.

    source demo_tls_source {
    
               tcp(ip(0.0.0.0) port(1999) 
    
                   tls( key_file("/opt/syslog-ng/etc/syslog-ng/key.d/syslog-ng.key") 
    
                        cert_file("/opt/syslog-ng/etc/syslog-ng/cert.d/syslog-ng.cert") 
    
                        ca_dir("/opt/syslog-ng/etc/syslog-ng/ca.d")) ); };

    A similar source for receiving messages using the IETF-syslog protocol:

    source demo_tls_syslog_source {                    
    
                            syslog(ip(0.0.0.0) port(1999)
    
                            transport("tls")
    
                            tls( key_file("/opt/syslog-ng/etc/syslog-ng/key.d/syslog-ng.key")
    
                            cert_file("/opt/syslog-ng/etc/syslog-ng/cert.d/syslog-ng.cert") 
    
                            ca_dir("/opt/syslog-ng/etc/syslog-ng/ca.d")) ); };
    [Warning] Warning

    Do not forget to update the certificate and key files when they expire.

For the details of the available tls() options, see Section 10.4, TLS options.

10.4. TLS options

The syslog-ng application is able to encrypt incoming and outgoing syslog message flows using SSL/TLS, if the TCP transport protocol (the tcp() or tcp6() sources or destination) is used.

[Note] Note

The format of the TLS connections used by syslog-ng is similar to using syslog-ng and stunnel, but the source IP information is not lost.

To encrypt connections, use the tls() option in the source and destination statements.

The tls() option can include the following settings:

ca_dir()

Accepted values: Directory name
Default: none

Description: Name of a directory, that contains a set of trusted CA certificates in PEM format. The CA certificate files has to be named after the 32-bit hash of the subject's name. This naming can be created using the c_rehash utility in openssl.

cert_file()

Accepted values: Filename
Default: none

Description: Name of a file, that contains an X.509 certificate in PEM format, suitable as a TLS certificate, matching the private key.

cipher_suite()

Accepted values: Cipher name
Default: aes-128-cbc

Description: Specifies the cipher, hash, and key-exchange algorithms used for the encryption. The following values are accepted: aes-128-cbc, aes-128-ecb, aes-192-cbc, aes-192-ecb, aes-256-cbc, aes-256-ecb, base64, bf, bf-cbc, bf-cfb, bf-ecb, bf-ofb, cast, cast-cbc, cast5-cbc, cast5-cfb, cast5-ecb, cast5-ofb, des, des-cbc, des-cfb, des-ecb, des-ede, des-ede-cbc, des-ede-cfb, des-ede-ofb, des-ede3, des-ede3-cbc des-ede3-cfb des-ede3-ofbdes-ofb, , des3, , desx, rc2, rc2-40-cbc, rc2-64-cbc, rc2-cbc, rc2-cfb, rc2-ecb, rc2-ofb, rc4, rc4-40, md2, md4, md5, rmd160, sha, sha1.

crl_dir()

Accepted values: Directory name
Default: none

Description: Name of a directory that contains the Certificate Revocation Lists for trusted CAs. Similarly to ca_dir() files, use the 32-bit hash of the name of the issuing CAs as filenames. The extension of the files must be .r0.

key_file()

Accepted values: Filename
Default: none

Description: Name of a file, that contains an unencrypted private key in PEM format, suitable as a TLS key.

peer_verify()

Accepted values: optional-trusted | optional-untrusted | required-trusted | required-untrusted
Default: required-trusted

Description: Verification method of the peer, the four possible values is a combination of two properties of validation:

  • whether the peer is required to provide a certificate (required or optional prefix), and

  • whether the certificate provided needs to be trusted or not.

For untrusted certificates only the existence of the certificate is checked, but it does not have to be valid — syslog-ng accepts the certificate even if it is expired, signed by an unknown CA, or its CN and the name of the machine mismatch.

[Warning] Warning

When validating a certificate, the entire certificate chain must be valid, including the CA certificate. If any certificate of the chain is invalid, syslog-ng OSE will reject the connection.

trusted_dn()

Accepted values: list of accepted distinguished names
Default: none

Description: To accept connections only from hosts using certain certificates signed by the trusted CAs, list the distinguished names of the accepted certificates in this parameter. For example using trusted_dn("*, O=Example Inc, ST=Some-State, C=*") will accept only certificates issued for the Example Inc organization in Some-State state.

trusted_keys()

Accepted values: list of accepted SHA-1 fingerprints
Default: none

Description: To accept connections only from hosts using certain certificates having specific SHA-1 fingerprints, list the fingerprints of the accepted certificates in this parameter. For example trusted_keys("SHA1:00:EF:ED:A4:CE:00:D1:14:A4:AB:43:00:EF:00:91:85:FF:89:28:8F", "SHA1:0C:42:00:3E:B2:60:36:64:00:E2:83:F0:80:46:AD:00:A8:9D:00:15").

To find the fingerprint of a certificate, you can use the following command: openssl x509 -in <certificate-filename> -sha1 -noout -fingerprint

[Note] Note

When using the trusted_keys() and trusted_dn() parameters, note the following:

  • First, the trusted_keys() parameter is checked. If the fingerprint of the peer is listed, the certificate validation is performed.

  • If the fingerprint of the peer is not listed in the trusted_keys() parameter, the trusted_dn() parameter is checked. If the DN of the peer is not listed in the trusted_dn() parameter, the authentication of the peer fails and the connection is closed.

Chapter 11. Manipulating messages

This chapter explains the methods that you can use to customize, reformat, and modify log messages using syslog-ng Open Source Edition.

11.1. Customizing message format

The following sections describe how to customize the names of logfiles, and also how to use templates, macros, and template functions.

11.1.1. Formatting messages, filenames, directories, and tablenames

The syslog-ng OSE application can dynamically create filenames, directories, or names of database tables using macros that help you organize your log messages. Macros refer to a property or a part of the log message, for example, the $HOST macro refers to the name or IP address of the client that sent the log message, while $DAY is the day of the month when syslog-ng has received the message. Using these macros in the path of the destination log files allows you for example to collect the logs of every host into separate files for every day.

A set of macros can be defined as a template object and used in multiple destinations.

Another use of macros and templates is to customize the format of the syslog message, for example to add elements of the message header to the message text. Note that if a message uses the IETF-syslog format, only the text of the message can be customized, the structure of the header is fixed.

11.1.2. Templates and macros

The syslog-ng OSE application allows you to define message templates, and reference them from every object that can use a template. Templates can be used for example to create standard message formats or filenames. Templates can reference one or more macros (for example date, the hostname, and so on). For a list of macros available in syslog-ng Open Source Edition, see Section 11.1.5, Macros of syslog-ng OSE. Fields from the structured data (SD) part of messages using the new IETF-syslog standard can also be used as macros.

Template objects have a single option called template_escape, which is disabled by default (template_escape(no)). This behavior is useful when the messages are passed to an application that cannot handle escaped characters properly. Enabling template escaping (template_escape(yes)) causes syslog-ng to escape the ', ", and backspace characters from the messages.

[Note] Note

In versions 2.1 and earlier, the template_escape() option was enabled by default.

Macros can be included by prefixing the macro name with a $ sign, just like in Bourne compatible shells. Although using braces around macro names is not mandatory, and the "$MSG" and "${MSG}" formats are equivalent, using the "${MSG}" format is recommended for clarity.

Default values for macros can also be specified by appending the :- characters and the default value of the macro. If a message does not contain the field referred to by the macro, or it is empty, the default value will be used when expanding the macro. For example, if a message does not contain a hostname, the following macro can specify a default hostname.

${HOST:-default_hostname}
[Warning] Warning

The hostname-related macros (FULLHOST, FULLHOST_FROM, HOST, and HOST_FROM) do not have any effect if the keep_hostname() option is disabled.

By default, syslog-ng sends messages using the following template: $ISODATE $HOST $MSGHDR$MSG\n. (The $MSGHDR$MSG part is written together because the $MSGHDR macro includes a trailing whitespace.)

[Note] Note

Earlier versions of syslog-ng used templates and scripts to send log messages into SQL databases. Starting from version 2.1, syslog-ng natively supports direct database access using the sql() destination. For details, see Section 7.5.4, sql() destination options.

[Example] Example 11.1. Using templates and macros

The following template (t_demo_filetemplate) adds the date of the message and the name of the host sending the message to the beginning of the message text. The template is then used in a file destination: messages sent to this destination (d_file) will use the message format defined in the template.

template t_demo_filetemplate {

             template("$ISODATE $HOST $MSG\n"); template_escape(no); };

destination d_file {

             file("/var/log/messages" template(t_demo_filetemplate)); };

Templates can also be used inline, if they are used only at a single location. The following destination is equivalent with the previous example:

destination d_file {

                file ("/var/log/messages"

                        template("$ISODATE $HOST $MSG\n") template_escape(no) );

                };

            

The following file destination uses macros to daily create separate logfiles for every client host.

destination d_file {

        file("/var/log/$YEAR.$MONTH.$DAY/$HOST.log");

};
[Note] Note

Macros can be used to format messages, and also in the name of destination files or database tables. However, they cannot be used in sources as wildcards, for example, to read messages from files or directories that include a date in their name.

11.1.3. Date-related macros

The macros related to the date of the message (for example: ISODATE, HOUR, and so on) have two variants each:

  • S_ prefix, for example, S_DATE: The S_DATE macro represents the date found in the log message, that is, when the message was sent by the original application.

  • R_ prefix, for example, R_DATE: R_DATE is the date when syslog-ng OSE has received the message.

Starting with syslog-ng OSE version 3.2, the DATE macro equals the S_DATE macro. In earlier versions the value of DATE depended on the use_time_recvd() global option, which was removed from syslog-ng OSE.

11.1.4. Hard vs. soft macros

Hard macros contain data that is directly derived from the log message, for example, the $MONTH macro derives its value from the timestamp. Hard macros are read-only. Soft macros (sometimes also called name-value pairs) are either built-in macros automatically generated from the log message (for example, $HOST), or custom user-created macros generated by using the syslog-ng pattern database or a CSV-parser. In contrast to hard macros, soft macros are writable and can be modified within syslog-ng OSE, for example, using rewrite rules.

Hard and soft macros are rather similar and often treated as equivalent. Macros are most commonly used in filters and templates, which does not modify the value of the macro, so both soft and hard macros can be used. However, it is not possible to change the values of hard macros in rewrite rules or via any other means.

The following macros in syslog-ng OSE are hard macros and cannot be modified: BSDTAG, CONTEXT_ID, DATE, DAY, FACILITY_NUM, FACILITY, FULLDATE, HOUR, ISODATE, LEVEL_NUM, LEVEL, MIN, MONTH_ABBREV, MONTH_NAME, MONTH, MONTH_WEEK, , PRIORITY, PRI, SDATA, SEC, SEQNUM, SOURCEIP, STAMP, TAG, TAGS, TZOFFSET, TZ, UNIXTIME, WEEK_DAY_ABBREV, WEEK_DAY_NAME, WEEK_DAY, WEEK, YEAR_DAY, YEAR.

The following macros can be modified:FULLHOST_FROM, FULLHOST, HOST_FROM, HOST, LEGACY_MSGHDR, MESSAGE, MSG,MSGID, MSGONLY, PID, PROGRAM, SOURCE. Custom values created using rewrite rules or parsers can be modified as well, just like stored matches of regular expressions ($0 ... $255).

11.1.5. Macros of syslog-ng OSE

The following macros are available in syslog-ng OSE.

BSDTAG

Description: Facility/priority information in the format used by the FreeBSD syslogd: a priority number followed by a letter that indicates the facility. The priority number can range from 0 to 7. The facility letter can range from A to Y, where A corresponds to facility number zero (LOG_KERN), B corresponds to facility 1 (LOG_USER), and so on.

Custom macros

Description: CSV parsers and pattern databases can also define macros from the content of the messages, for example, a pattern database rule can extract the username from a login message and create a macro that references the username. For details on using custom macros created with CSV parsers and pattern databases, see Chapter 12, Parsing and segmenting structured messages and Section 13.2.1, Using parser results in filters and templates, respectively.

DATE, R_DATE, S_DATE

Description: Date of the message using the BSD-syslog style timestamp format (month/day/hour/minute/second, each expressed in two digits). This is the original syslog time stamp without year information, for example: Jun 13 15:58:00.

DAY, R_DAY, S_DAY

Description: The day the message was sent.

FACILITY

Description: The name of the facility (for example, kern) that sent the message.

FACILITY_NUM

Description: The numerical code of the facility (for example, 0) that sent the message.

FULLDATE, R_FULLDATE, S_FULLDATE

Description: A nonstandard format for the date of the message using the same format as DATE, but including the year as well, for example: 2006 Jun 13 15:58:00.

FULLHOST

Description: The full FQDN of the host name chain (without trimming chained hosts), including the domain name.

FULLHOST_FROM

Description: FQDN of the host that sent the message to syslog-ng as resolved by syslog-ng using DNS. If the message traverses several hosts, this is the last host in the chain.

The syslog-ng OSE application uses the following procedure to determine the value of the $FULLHOST_FROM macro:

  1. The syslog-ng OSE application takes the IP address of the host sending the message.

  2. If the use_dns() option is enabled, syslog-ng OSE attempts to resolve the IP address to a hostname. If it succeeds, the returned hostname will be the value of the $FULLHOST_FROM macro. This value will be the FQDN of the host if the use_fqdn() option is enabled, but only the hostname if use_fqdn() is disabled.

  3. If the use_dns() option is disabled, or the address resolution fails, the $FULLHOST_FROM macro will return the IP address of the sender host.

HOUR, R_HOUR, S_HOUR

Description: The hour of day the message was sent.

HOST

Description: The name of the source host where the message originates from.

  • If the message traverses several hosts and the chain_hostnames() option is on, the first host in the chain is used.

  • If the keep_hostname() option is disabled (keep_hostname(no)), the value of the $HOST macro will be the DNS hostname of the host that sent the message to syslog-ng OSE (that is, the DNS hostname of the last hop). In this case the $HOST and $HOST_FROM macros will have the same value.

  • If the keep_hostname() option is enabled (keep_hostname(yes)), the value of the $HOST macro will be the hostname retrieved from the log message. That way the name of the original sender host can be used, even if there are log relays between the sender and the server.

HOST_FROM

Description: Name of the host that sent the message to syslog-ng, as resolved by syslog-ng using DNS. If the message traverses several hosts, this is the last host in the chain.

ISODATE, R_ISODATE, S_ISODATE

Description: Date of the message in the ISO 8601 compatible standard timestamp format (yyyy-mm-ddThh:mm:ss+-ZONE), for example: 2006-06-13T15:58:00.123+01:00. If possible, it is recommended to use ISODATE for timestamping. Note that syslog-ng can produce fractions of a second (for example milliseconds) in the timestamp by using the frac_digits() global or per-destination option.

LEVEL_NUM

Description: The priority (also called severity) of the message, represented as a numeric value, for example, 3. For the textual representation of this value, use the $LEVEL macro. See Section PRIORITY or LEVEL for details.

MIN, R_MIN, S_MIN

Description: The minute the message was sent.

MONTH, R_MONTH, S_MONTH

Description: The month the message was sent as a decimal value, prefixed with a zero if smaller than 10.

MONTH_ABBREV, R_MONTH_ABBREV, S_MONTH_ABBREV

Description: The English abbreviation of the month name (3 letters).

MONTH_NAME, R_MONTH_NAME, S_MONTH_NAME

Description: The English name of the month name.

MONTH_WEEK, R_MONTH_WEEK, S_MONTH_WEEK

Description: The number of the week in the given month (0-5). The week with numerical value 1 is the first week containing a Monday. The days of month before the first Monday are considered week 0. For example, if a 31-day month begins on a Sunday, then the 1st of the month is week 0, and the end of the month (the 30th and 31st) is week 5.

MSG or MESSAGE

Description: Text contents of the log message without the program name and pid. Note that this has changed in syslog-ng version 3.0; in earlier versions this macro included the program name and the pid. In syslog-ng 3.0, the MSG macro became equivalent with the MSGONLY macro. The program name and the pid together are available in the MSGHDR macro.

MSGHDR

Description: The name and the pid of the program that sent the log message in PROGRAM[PID]: format. Includes a trailing whitespace. Note that the macro returns an empty value if both the program and pid fields of the message are empty.

MSGID

Description: A string specifying the type of the message in IETF-syslog (RFC5424-formatted) messages. For example, a firewall might use the MSGID "TCPIN" for incoming TCP traffic and the MSGID "TCPOUT" for outgoing TCP traffic. By default, syslog-ng OSE does not specify this value, but uses a dash (-) character instead. If an incoming message includes the MSGID value, it is retained and relayed without modification.

MSGONLY

Description: Message contents without the program name or pid.

PID

Description: The PID of the program sending the message.

PRI

Description: The priority and facility encoded as a 2 or 3 digit decimal number as it is present in syslog messages.

PRIORITY or LEVEL

Description: The priority (also called severity) of the message, for example, error. For the textual representation of this value, use the $LEVEL macro. See Section PRIORITY or LEVEL for details.

PROGRAM

Description: The name of the program sending the message. Note that the content of the $PROGRAM variable may not be completely trusted as it is provided by the client program that constructed the message.

SDATA, .SDATA.SDID.SDNAME

Description: The syslog-ng application automatically parses the STRUCTURED-DATA part of IETF-syslog messages, which can be referenced in macros. The $SDATA macro references the entire STRUCTURED-DATA part of the message, while structured data elements can be referenced using the $.SDATA.SDID.SDNAME macro.

[Note] Note

When using STRUCTURED-DATA macros, consider the following:

  • When referencing an element of the structured data, the macro must begin with the dot (.) character. For example, $.SDATA.timeQuality.isSynced.

  • The SDID and SDNAME parts of the macro names are case sensitive: $.SDATA.timeQuality.isSynced is not the same as $.SDATA.TIMEQUALITY.ISSYNCED.

[Example] Example 11.2. Using SDATA macros

For example, if a log message contains the following structured data: [exampleSDID@0 iut="3" eventSource="Application" eventID="1011"][examplePriority@0 class="high"] you can use macros like: ${.SDATA.exampleSDID@0.eventSource} — this would return the Application string in this case.

SEC, R_SEC, S_SEC

Description: The second the message was sent.

SEQNUM

Description: The sequence number of the message is a unique identifier of the message between the end-points. The syslog-ng client calculates this number when processing a new message from a local source; it is not calculated for relayed messages. The sequence number increases for every message, and is not lost even if syslog-ng is reloaded. The sequence number starts again from 0 when syslog-ng OSE is restarted. The sequence number is a part of every message that uses the new IETF-syslog protocol (.SDATA.meta.sequenceId), and can be added to BSD-syslog messages using this macro.

SOURCEIP

Description: IP address of the host that sent the message to syslog-ng. (That is, the IP address of the host in the FULLHOST_FROM macro.) Please note that when a message traverses several relays, this macro contains the IP of the last relay.

STAMP, R_STAMP, S_STAMP

Description: A timestamp formatted according to the ts_format() global or per-destination option.

TAG

Description: The priority and facility encoded as a 2 digit hexadecimal number.

TAGS

Description: A comma-separated list of the tags assigned to the message.

[Note] Note

Note that the tags are not part of the log message and are not automatically transferred from a client to the server. For example, if a client uses a pattern database to tag the messages, the tags are not transferred to the server. A way of transferring the tags is to explicitly add them to the log messages using a template and the $TAGS macro, or to add them to the structured metadata part of messages when using the IETF-syslog message format.

When sent as structured metadata, it is possible to reference to the list of tags on the central server, and for example, to add them to a database column.

TZ, R_TZ, S_TZ

Description: Equivalent to TZOFFSET, used to mean the time zone name abbreviation in syslog-ng 1.6.x.

TZOFFSET, R_TZOFFSET, S_TZOFFSET

Description: The time-zone as hour offset from GMT; for example: -07:00. In syslog-ng 1.6.x this used to be -0700 but as ISODATE requires the colon it was added to TZOFFSET as well.

UNIXTIME, R_UNIXTIME, S_UNIXTIME

Description: Standard unix timestamp, represented as the number of seconds since 1970-01-01T00:00:00.

YEAR, R_YEAR, S_YEAR

Description: The year the message was sent.

WEEK, R_WEEK, S_WEEK

Description: The week number of the year, prefixed with a zero for the first nine week of the year. (The first Monday in the year marks the first week.)

WEEK_ABBREV, R_WEEK_ABBREV, S_WEEK_ABBREV

Description: The 3-letter English abbreviation of the name of the day the message was sent, for example Thu.

WEEK_DAY, R_WEEK_DAY, S_WEEK_DAY

Description: The day of the week as a numerical value (1-7).

WEEKDAY, R_WEEKDAY, S_WEEKDAY

Description: These macros are deprecated, use WEEK_ABBREV, R_WEEK_ABBREV, S_WEEK_ABBREV instead. The 3-letter name of the day of week the message was sent, for example Thu.

WEEK_DAY_NAME, R_WEEK_DAY_NAME, S_WEEK_DAY_NAME

Description: The English name of the day.

11.1.6. Using template functions

A template function is a transformation: it modifies the way macros or name-value pairs are expanded. Template functions can be used in template definitions, or when macros are used in the configuration of syslog-ng OSE. Template functions use the following syntax:

$(function-name parameter1 parameter2 parameter3 ...)

For example, the $(echo) template function simply returns the value of the macro it receives as a parameter, thus $(echo $HOST) is equivalent to $HOST.

The parameters of template functions are separated by a whitespace character. If you want to use a longer string or multiple macros as a single parameter, enclose the parameter in double-quotes or apostrophes. For example:

$(echo "$HOST $PROGRAM $PID")

Template functions can be nested into each other, so the parameter of a template function can be another template function, like:

$(echo $(echo $HOST))

For details on using template functions, see the descriptions of the individual template functions in Section 11.1.7, Template functions of syslog-ng OSE.

11.1.7. Template functions of syslog-ng OSE

The following template functions are available in syslog-ng OSE.

echo

Syntax:

$(echo argument)

Description: Returns the value of its argument. using $(echo $HOST) is equivalent to $HOST.

format-json

Syntax:

$(format-json parameters)

Description: The format-json template function receives value-pairs as parameters and converts them into JavaScript Object Notation (JSON) format. Including the template function in a message template allows you to store selected information about a log message (that is, its content, macros, or other metadata) in JSON format.

For details on selecting value-pairs in syslog-ng OSE and for possibilities to specify which information to convert to JSON format, see Section 2.9.4, Structuring macros, metadata, and other value-pairs. Note that the syntax of format-json is different from the syntax of value-pairs(): format-json uses a syntax similar to command lines.

[Example] Example 11.3. Using the format-json template function

The following example selects every available information about the log message, except for the date-related macros (R_* and S_*), selects the .SDATA.meta.sequenceId macro, and defines a new value-pair called MSGHDR that contains the program name and PID of the application that sent the log message.

$(format-json --scope syslog,all_macros,selected_macros \

  --exclude R_* --exclude S_* --key .SDATA.meta.sequenceId \

  --pair MSGHDR="$PROGRAM[$PID]: ")

The following example shows how to use this template function to store log messages in JSON format:

destination d_json {

  file("/var/log/messages.json" template("$(format_json --scope selected_macros --scope nv_pairs)"));

};

grep

Syntax:

$(grep condition value-to-select)

Description: The grep template function is useful when using a pattern database to correlate related log messages. The grep template function can be used to filter the messages of the same context when the index of the particular message is not known.

[Example] Example 11.4. Using the grep template function

The following example selects the message of the context that has a username name-value pair with the root value, and returns the value of the auth_method name-value pair.

$(grep ("${username}" == "root") ${auth_method})

It is possible to specify multiple name-value pairs as parameters, separated with commas. If multiple messages match the condition of grep, these will be returned also separated by commas. This can be used for example to collect the e-mail recipients from postfix messages.

if

Syntax:

$(if (<condition>) <true template> <false template>)

Description: Returns the value of the <true template> parameter if the <condition> is true. If the <condition> is false, the value of <false template> is returned.

[Example] Example 11.5. Using pattern databases and the if template function

The following example returns violation if the username name-value pair of a message processed with pattern database is root, and system otherwise.

$(if ("${username}" == "root") "violation" "system")

This can be used to set the class of a message in pattern database rules based on the condition.

<value name="username">$(if ("${username}" == "root") "violation" "system")</value>

Since template functions can be embedded into each other, it is possible to use another template function as the template of the first one. For example, the following expression returns root if the username is root, admin if the username is joe, and normal user otherwise.

<value name="username">

        $(if ("${username}" == "root")

            "root"

            $(if ("${username}" == "joe") "admin" "normal user")

            "normal user")</value>

indent-multi-line

Syntax:

$(indent-multi-line parameter)

Description: This template function makes it possible to write multi-line log messages into a file. The first line is written like a regular message, subsequent lines are indented with a tab, in compliance with RFC822.

[Example] Example 11.6. Using the indent-multi-line template function

The following example writes multi-line messages into a text file.

destination d_file {

                file ("/var/log/messages"

                        template("${ISODATE} ${HOST} $(indent-multi-line ${MESSAGE})\n") );

};

ipv4-to-int

Syntax:

$(ipv4-to-int parameter)

Description: Converts the specified IPv4 address to its numeric representation. The numerical value of an IPv4 address is calculated by treating the IP address as a 4-byte hexadecimal value. For example, the 192.168.1.1 address equals to: 192=C0, 168=A8, 1=01, 1=01, or C0A80101, which is 3232235777 in decimal representation.

[Note] Note

This template function is available only if the convertfuncs module has been loaded. By default, syslog-ng OSE loads every available module.

11.2. Modifying messages

The syslog-ng application can rewrite parts of the messages using rewrite rules. Rewrite rules are global objects similar to parsers and filters and can be used in log paths. The syslog-ng application has two methods to rewrite parts of the log messages: substituting (setting) a part of the message to a fix value, and a general search-and-replace mode.

Substitution completely replaces a specific part of the message that is referenced using a built-in or user-defined macro.

General rewriting searches for a string in the entire message (or only a part of the message specified by a macro) and replaces it with another string. Optionally, this replacement string can be a template that contains macros.

Rewriting messages is often used in conjunction with message parsing Section 12.1, Parsing messages.

Rewrite rules are similar to filters: they must be defined in the syslog-ng configuration file and used in the log statement.

[Note] Note

The order of filters, rewriting rules, and parsers in the log statement is important, as they are processed sequentially.

11.2.1. Replacing message parts

To replace a part of the log message, you have to:

  • define a string or regular expression to find the text to replace

  • define a string to replace the original text (macros can be used as well)

  • select the field of the message that the rewrite rule should process

Substitution rules can operate on any value available via macros, for example HOST, MESSAGE, PROGRAM, or any user-defined macros created using parsers (for details, see Chapter 12, Parsing and segmenting structured messages and Chapter 13, Processing message content with a pattern database). The only exceptions are the FACILITY, SEVERITY, TAGS, and the date-related fields, which cannot be rewritten. You can also rewrite the structured-data fields of messages complying to the RFC5424 (IETF-syslog) message format. Substitution rules use the following syntax:

Declaration:

rewrite <name_of_the_rule> {

    subst("<string or regular expression to find>",

        "<replacement string>", value(<field name>), flags() );

};

The type() and flags() options are optional. The type() specifies the type of regular expression to use; while the flags() are the flags of the regular expressions. For details on regular expressions, see Section 11.3, Regular expressions.

A single substitution rule can include multiple substitutions that are applied sequentially to the message. Note that rewriting rules must be included in the log statement to have any effect.

[Tip] Tip

For case-insensitive searches, add the flags(ignore-case) option; to replace every occurrence of the string, add flags(global) option.

[Example] Example 11.7. Using substitution rules

The following example replaces th IP in the text of the message with the string IP-Address.

rewrite r_rewrite_subst{subst("IP", "IP-Address", value("MESSAGE"));};

To replace every occurrence, use:

rewrite r_rewrite_subst{

    subst("IP", "IP-Address", value("MESSAGE"), flags("global"));

};

Multiple substitution rules are applied sequentially; the following rules replace the first occurrence of the string IP with the string IP-Addresses.

rewrite r_rewrite_subst{

    subst("IP", "IP-Address", value("MESSAGE"));

    subst("Address", "Addresses", value("MESSAGE"));

};

11.2.2. Setting message fields to specific values

To set a field of the message to a specific value, you have to:

  • define the string to include in the message, and

  • select the field where it should be included.

You can set the any value available via macros, for example HOST, MESSAGE, PROGRAM, or any user-defined macros created using parsers (for details, see Chapter 12, Parsing and segmenting structured messages and Chapter 13, Processing message content with a pattern database). The only exceptions are the FACILITY, SEVERITY, TAGS, and the date-related fields, which cannot be rewritten. Note that the rewrite operation completely replaces any previous value of that field. Use the following syntax:

Declaration:

rewrite <name_of_the_rule> {

    set("<string to include>", value(<field name>));

};
[Example] Example 11.8. Setting message fields to a particular value

The following example sets the HOST field of the message to myhost.

rewrite r_rewrite_set{set("myhost", value("HOST"));};

For details on rewriting SDATA fields, see Section 11.2.3, Creating custom SDATA fields.

11.2.3. Creating custom SDATA fields

If you use RFC5424-formatted (IETF-syslog) messages, you can also create custom fields in the SDATA part of the message (For details on the SDATA message part, see Section 2.9.2.3, The STRUCTURED-DATA message part). According to RFC5424, the name of the field (its SD-ID) must not contain the @ character for reserved SD-IDs. Custom SDATA fields must be in the following format: name@<private enterprise number>, for example, mySDATA-field@18372.4. (18372.4 is the private enterprise number of BalaBit IT Security, the developer of syslog-ng OSE.)

[Example] Example 11.9. Rewriting custom SDATA fields

The following example sets the sequence ID field of the RFC5424-formatted (IETF-syslog) messages to a fixed value. This field is a predefined SDATA field with a reserved SD-ID, therefore its name does not contain the @ character.

rewrite r_sd {

    set("55555" value(".SDATA.meta.sequenceId"));

};

It is also possible to set the value of a field that does not exist yet, and create a new, custom name-value pair that is associated with the message. The following example creates the MODIFIED@18372.4 field and sets its value to yes. If you use the ${MODIFIED@18372.4} macro in a template or SQL table, its value will be yes for every message that was processed with this rewrite rule, and empty for every other message.

rewrite r_rewrite_set {

    set("yes", value("MODIFIED@18372.4"));

};

11.2.4. Conditional rewrites

Starting with 3.2, it is possible to apply a rewrite rule to a message only if certain conditions are met. The condition() option effectively embeds a filter expression into the rewrite rule: the message is modified only if the message passes the filter. If the condition is not met, the message is passed to the next element of the log path (that is, the element following the rewrite rule in the log statement, for example, the destination). Any filter expression normally used in filters can be used as a rewrite condition. Existing filter statements can be referenced using the filter() function within the condition.

[Tip] Tip

Using conditions in rewrite rules can simplify your syslog-ng OSE configuration file, as you do not need to create separate log paths to modify certain messages.

[Example] Example 11.10. Using conditional rewriting

The following example sets the HOST field of the message to myhost only if the message was sent by the myapplication program.

rewrite r_rewrite_set{set("myhost", value("HOST") condition(program("myapplication")));};

The following example is identical to the previous one, except that the condition references an existing filter template.

filter f_rewritefilter {program("myapplication");};

rewrite r_rewrite_set{set("myhost", value("HOST") condition(filter(f_rewritefilter)));};

11.3. Regular expressions

Filters and substitution rewrite rules can use regular expressions. In regular expressions, the characters ()[].*?+^$|\ are used as special symbols. Depending on how you want to use these characters and which quotation mark you use, these characters must be used differently, as summarized below.

  • Strings between single quotes ('string') are treated literally and are not interpreted at all, you do not have to escape special characters. For example the output of '\x41' is \x41 (characters as follows: backslash, x(letter), 4(number), 1(number)). This makes writing and reading regular expressions much more simple: it is recommended to use single quotes when writing regular expressions.

  • When enclosing strings between double-quotes ("string"), the string is interpreted and you have to escape special characters, that is, to precede them with a backslash (\) character if they are meant literally. For example the output of the "\x41" is simply the letter a. Therefore special characters like \(backslash) "(quotation mark) must be escaped (\\ and \"). The following expressions are interpreted: \a; \n; \r; \t; \v. For example, the \$40 expression matches the $40 string. Backslashes have to be escaped as well if they are meant literally, for example, the \\d expression matches the \d string.

    [Tip] Tip

    If you use single quotes in, you do not need to escape the backslash, for example match("\\.") is equivalent to match('\.').

  • Enclosing alphanumeric strings between double-quotes ("string") is not necessary, you can just omit the double-quotes. For example when writing filters, match("sometext") and match(sometext) will both match for the sometext string.

    [Note] Note

    Only strings containing alphanumerical characters can be used without quotes or double quotes. If the string contains whitespace or any special characters (()[].*?+^$|\ or ;:#), you must use quotes or double quotes.

    When using the ;:# characters, you must use quotes or double quotes, but escaping them is not required.

By default, all regular expressions are case sensitive. To disable the case sensitivity of the expression, add the flags(ignore-case) option to the regular expression.

filter demo_regexp_insensitive { host("system" flags(ignore-case)); };

The regular expressions can use up to 255 regexp matches (${1} ... ${255}), but only from the last filter and only if the flags("store-matches") flag was set for the filter. For case-insensitive searches, use the flags("ignore-case") option.

11.3.1. Types and options of regular expressions

By default, syslog-ng uses POSIX-style regular expressions. To use other expression types, add the type() option after the regular expression.

The syslog-ng OSE application supports the following expression types:

posix

Description: Use POSIX regular expressions. If the type() parameter is not specified, syslog-ng uses POSIX regular expressions by default.

Posix regular expressions have the following flag options:

global: Usable only in rewrite rules; match for every occurrence of the expression, not only the first one.

ignore-case: Disable case-sensitivity.

store-matches: Store the matches of the regular expression into the $1, ... $255 variables. Matches from the last filter expression can be referenced in regular expressions.

utf8: Use UTF-8 matching.

[Example] Example 11.11. Using Posix regular expressions
filter f_message { message("keyword" flags("utf8" "ignore-case") );

pcre

Description: Use Perl Compatible Regular Expressions (PCRE). PCRE expressions can be used if syslog-ng OSE was compiled with the --enable-pcre option enabled. Execute the syslog-ng -V command to check if your binary supports PCRE regular expressions. Starting with syslog-ng OSE version 3.1, PCRE expressions are supported on every platform.

PCRE regular expressions have the following flag options:

global: Usable only in rewrite rules; match for every occurrence of the expression, not only the first one.

ignore-case: Disable case-sensitivity.

nobackref: Do not store back references for the matches — improves performance.

store-matches: Store the matches of the regular expression into the $1, ... $255 variables. Named matches (also called named subpatterns), for example (?<name>...), are stored as well. Matches from the last filter expression can be referenced in regular expressions.

unicode: Use Unicode support for UTF-8 matches: UTF-8 character sequences are handled as single characters.

utf8: An alias for the unicode flag.

[Example] Example 11.12. Using PCRE regular expressions
rewrite r_rewrite_subst

        {subst("a*", "?", value("MESSAGE") type("pcre") flags("utf8" "global"));  };

string

Description: Match the strings literally, without regular expression support. By default, only identical strings are matched. For partial matches, use the flags("prefix") or the flags("substring") flags.

glob

Description: Match the strings against a pattern containing '*' and '?' wildcards, without regular expression and character range support. The advantage of glob patterns to regular expressions is that globs can be processed much faster.

*

matches an arbitrary string, including an empty string

?

matches an arbitrary character

[Note] Note
  • The wildcards can match the / character.

  • You cannot use the * and ? literally in the pattern.

11.3.2. Optimizing regular expressions

The host(), match(), and program() filter functions and some other syslog-ng objects accept regular expressions as parameters. But evaluating general regular expressions puts a high load on the CPU, which can cause problems when the message traffic is very high. Often the regular expression can be replaced with simple filter functions and logical operators. Using simple filters and logical operators, the same effect can be achieved at a much lower CPU load.

[Example] Example 11.13. Optimizing regular expressions in filters

Suppose you need a filter that matches the following error message logged by the xntpd NTP daemon:

xntpd[1567]: time error -1159.777379 is too large (set clock manually);

The following filter uses regular expressions and matches every instance and variant of this message.

filter f_demo_regexp {

    program("demo_program") and

    match("time error .* is too large .* set clock manually"); };

Segmenting the match() part of this filter into separate match() functions greatly improves the performance of the filter.

filter f_demo_optimized_regexp {

    program("demo_program") and

    match("time error") and

    match("is too large") and

    match("set clock manually"); };

Chapter 12. Parsing and segmenting structured messages

The filters and default macros of syslog-ng work well on the headers and metainformation of the log messages, but are rather limited when processing the content of the messages. Parsers can segment the content of the messages into name-value pairs, and these names can be used as user-defined macros. Subsequent filtering or other type of processing of the message can use these custom macros to refer to parts of the message. Parsers are global objects most often used together with filters and rewrite rules.

syslog-ng OSE provides the following possibilities to parse the messages, or parts of the messages:

12.1. Parsing messages

The syslog-ng application can separate parts of log messages (that is, the contents of the $MSG macro) to named fields (columns). These fields act as user-defined macros that can be referenced in message templates, file- and tablenames, and so on.

Parsers are similar to filters: they must be defined in the syslog-ng configuration file and used in the log statement.

[Note] Note

The order of filters, rewriting rules, and parsers in the log statement is important, as they are processed sequentially.

To create a parser, define the columns of the message, the delimiter or separator characters (for example, semicolon or tabulator), and optionally the characters that are used to escape the delimiter characters (quote-pairs). For the list of parser parameters, see Section 12.1.1, Options of CSV parsers.

Declaration:

            parser parser_name {

            csv-parser(column1, column2, ...)

            delimiters()

            quote-pairs()

            };

Column names work like macros. Always use a prefix to identify the columns of the parsers, for example MYPARSER1.COLUMN1, MYPARSER2.COLUMN2, and so on. Column names starting with a dot (for example .HOST) are reserved for use by syslog-ng.

[Example] Example 12.1. Segmenting hostnames separated with a dash

The following example separates hostnames like example-1 and example-2 into two parts.

parser p_hostname_segmentation {

    csv-parser(columns("HOSTNAME.NAME", "HOSTNAME.ID")

    delimiters("-")

    flags(escape-none)

    template("${HOST}"));

};

destination d_file { file("/var/log/messages-${HOSTNAME.NAME:-examplehost}"); };

log { source(s_local); parser(p_hostname_segmentation); destination(d_file);};
[Example] Example 12.2. Parsing Apache log files

The following parser processes the log of Apache web servers and separates them into different fields. Apache log messages can be formatted like:

"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %T %v"

Here is a sample message:

192.168.1.1 - - [31/Dec/2007:00:17:10 +0100] "GET /cgi-bin/example.cgi HTTP/1.1" 200 2708 "-" "curl/7.15.5 (i4 86-pc-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8c zlib/1.2.3 libidn/0.6.5" 2 example.balabit

To parse such logs, the delimiter character is set to a single whitespace (delimiters(" ")). Whitespaces between quotes and brackets are ignored (quote-pairs('""[]')).

parser p_apache {

    csv-parser(columns("APACHE.CLIENT_IP", "APACHE.IDENT_NAME", "APACHE.USER_NAME",

        "APACHE.TIMESTAMP", "APACHE.REQUEST_URL", "APACHE.REQUEST_STATUS",

        "APACHE.CONTENT_LENGTH", "APACHE.REFERER", "APACHE.USER_AGENT",

        "APACHE.PROCESS_TIME", "APACHE.SERVER_NAME")

         flags(escape-double-char,strip-whitespace)

         delimiters(" ")

         quote-pairs('""[]')

         );

};

The results can be used for example to separate log messages into different files based on the APACHE.USER_NAME field. If the field is empty, the nouser name is assigned.

log { source(s_local);

    parser(p_apache); destination(d_file);};

};

destination d_file { file("/var/log/messages-${APACHE.USER_NAME:-nouser}"); };

Multiple parsers can be used to split a part of an already parsed message into further segments.

[Example] Example 12.3. Segmenting a part of a message

The following example splits the timestamp of a parsed Apache log message into separate fields.

parser p_apache_timestamp {

    csv-parser(columns("APACHE.TIMESTAMP.DAY", "APACHE.TIMESTAMP.MONTH", "APACHE.TIMESTAMP.YEAR", "APACHE.TIMESTAMP.HOUR", "APACHE.TIMESTAMP.MIN", "APACHE.TIMESTAMP.MIN", "APACHE.TIMESTAMP.ZONE")

    delimiters("/: ")

    flags(escape-none)

    template("${APACHE.TIMESTAMP}"));

    };

log { source(s_local);

    log { parser(p_apache); parser(p_apache_timestamp); destination(d_file);};

};

Further examples: 

12.1.1. Options of CSV parsers

The syslog-ng application can separate parts of log messages (that is, the contents of the $MSG macro) to named fields (columns). These fields act as user-defined macros that can be referenced in message templates, file- and tablenames, and so on.

To create a parser, define the columns of the message, the delimiter or separator characters, and optionally the characters that are used to escape the delimiter characters (quote-pairs).

Declaration:

    parser parser_name {

        csv-parser(column1, column2, ...)

        delimiters()

        quote-pairs()

    };

Column names work like macros. Always use a prefix to identify the columns of the parsers, for example MYPARSER1.COLUMN1, MYPARSER2.COLUMN2, and so on. Column names starting with a dot (for example .HOST) are reserved for use by syslog-ng.

csv-parser

Synopsis: csv-parser(columns("PARSER.COLUMN1", "PARSER.COLUMN2", ...))

Description: Specifies the type of parser to use, and the name of the columns to separate messages to. Currently only the csv-parser is implemented, which can separate columns based on delimiter characters and strings.

delimiters

Synopsis: delimiters("<delimiter_characters>")

Description: The character that separates the columns in the message. If you specify multiple characters, every character will be treated as a delimiter. To separate the columns at the tabulator (tab character), specify \t. For example, to separate the text at evert hyphen (-) and colon (:) character, use delimiters("-:")

flags()

Synopsis: drop-invalid, escape-none, escape-backslash, escape-double-char, greedy, strip-whitespace

Description: Specifies various options for parsing the message. The following flags are available:

  • drop-invalid: When the drop-invalid option is set, the parser does not process messages that do not match the parser. For example, a message does not match the parser if it has less columns than specified in the parser, or it has more columns but the greedy flag is not enabled. Using the drop-invalid option practically turns the parser into a special filter, that matches messages that have the predefined number of columns (using the specified delimiters).

    [Tip] Tip

    Messages dropped as invalid can be processed by a fallback log path. For details on the fallback option, see Section 8.1.2, Log path flags.

  • escape-backslash: The parsed message uses the backslash (\) character to escape quote characters.

  • escape-double-char: The parsed message repeats the quote character when the quote character is used literally. For example, to escape a comma (,), the message contains two commas (,,).

  • escape-none: The parsed message does not use any escaping for using the quote character literally.

  • greedy: The greedy option assigns the remainder of the message to the last column, regardless of the delimiter characters set. You can use this option to process messages where the number of columns varies.

    [Example] Example 12.4. Adding the end of the message to the last column

    If the greedy option is enabled, the syslog-ng application adds the not-yet-parsed part of the message to the last column, ignoring any delimiter characters that may appear in this part of the message.

    For example, you receive the following comma-separated message: example 1, example2, example3, and you segment it with the following parser:

    csv_parser(columns("COLUMN1", "COLUMN2", "COLUMN3") delimiters(","));

    The COLUMN1, COLUMN2, and COLUMN3 variables will contain the strings example1, example2, and example3, respectively. If the message looks like example 1, example2, example3, some more information, then any text appearing after the third comma (that is, some more information) is not parsed, and possibly lost if you use only the variables to reconstruct the message (for example, to send it to different columns of an SQL table).

    Using the greedy flag will assign the remainder of the message to the last column, so that the COLUMN1, COLUMN2, and COLUMN3 variables will contain the strings example1, example2, and example3, some more information.

    csv_parser(columns("COLUMN1", "COLUMN2", "COLUMN3") delimiters(",") flags(greedy));
  • strip-whitespace: The strip-whitespace flag removes trailing whitespaces from the beginning and the end of the columns.

quote-pairs()

Synopsis: quote-pairs('<quote_pairs>')

Description: List quote-pairs between single quotes. Delimiter characters enclosed between quote characters are ignored. Note that the beginning and ending quote character does not have to be identical, for example [} can also be a quote-pair. For an example of using quote-pairs() to parse Apache log files, see Example 12.2, Parsing Apache log files.

template()

Synopsis: template("${<macroname>}")

Description: The macro that contains the part of the message that the parser will process. It can also be a macro created by a previous parser of the log path. By default, this is empty and the parser processes the entire message. For examples, see Example 12.1, Segmenting hostnames separated with a dash and Example 12.3, Segmenting a part of a message.

Chapter 13. Processing message content with a pattern database

13.1. Classifying log messages

The syslog-ng application can compare the contents of the received log messages to predefined message patterns. By comparing the messages to the known patterns, syslog-ng is able to identify the exact type of the messages, and sort them into message classes. The message classes can be used to classify the type of the event described in the log message. The message classes can be customized, and for example can label the messages as user login, application crash, file transfer, and so on events.

To find the pattern that matches a particular message, syslog-ng uses a method called longest prefix match radix tree. This means that syslog-ng creates a tree structure of the available patterns, where the different characters available in the patterns for a given position are the branches of the tree.

To classify a message, syslog-ng selects the first character of the message (the text of message, not the header), and selects the patterns starting with this character, other patterns are ignored for the rest of the process. After that, the second character of the message is compared to the second character of the selected patterns. Again, matching patterns are selected, and the others discarded. This process is repeated until a single pattern completely matches the message, or no match is found. In the latter case, the message is classified as unknown, otherwise the class of the matching pattern is assigned to the message.

To make the message classification more flexible and robust, the patterns can contain pattern parsers: elements that match on a set of characters. For example, the NUMBER parser matches on any integer or hexadecimal number (for example 1, 123, 894