pax_global_header00006660000000000000000000000064132622243070014513gustar00rootroot0000000000000052 comment=a9571072beb623f2e13241624a07d3bdb258c813 syslog-ng-incubator-0.6.2/000077500000000000000000000000001326222430700154265ustar00rootroot00000000000000syslog-ng-incubator-0.6.2/.gitignore000066400000000000000000000005071326222430700174200ustar00rootroot00000000000000*~ ._* .*.swp /.pc/ /autom4te.cache /autoscan.log /Makefile.in /aclocal.m4 /compile /config.* /configure /configure.scan /depcomp /install-sh /ltmain.sh /m4/libtool.m4 /m4/lt~obsolete.m4 /m4/ltoptions.m4 /m4/ltsugar.m4 /m4/ltversion.m4 /m4/pkg.m4 /missing /mkinstalldirs /stamp-h.in /stamp-h /test-driver /ylwrap /b/ /build/ syslog-ng-incubator-0.6.2/.travis.yml000066400000000000000000000020541326222430700175400ustar00rootroot00000000000000language: c install: - sudo apt-get update -qq - sudo apt-get install -qq curl - wget http://download.opensuse.org/repositories/home:/laszlo_budai:/syslog-ng/xUbuntu_12.04/Release.key - sudo apt-key add Release.key - rm -rf Release.key - wget http://download.opensuse.org/repositories/home:/viktorjuhasz/xUbuntu_12.04/Release.key - sudo apt-key add Release.key - sudo sh -c 'echo "deb http://download.opensuse.org/repositories/home:/laszlo_budai:/syslog-ng/xUbuntu_12.04 ./" >> /etc/apt/sources.list' - sudo sh -c 'echo "deb http://download.opensuse.org/repositories/home:/viktorjuhasz/xUbuntu_12.04/ ./" >> /etc/apt/sources.list' - sudo apt-get update -qq - sudo apt-get install -qq aptitude - sudo aptitude install -q -y pkg-config flex bison liblua5.2-dev libmongo-client-dev syslog-ng-dev libperl-dev python-dev python3-dev libgrok-dev libtokyocabinet-dev libzmq3-dev librdkafka-dev before_script: - autoreconf -i script: - travis/build compiler: - gcc - clang notifications: irc: channels: - "irc.freenode.org#balabit" syslog-ng-incubator-0.6.2/COPYING000066400000000000000000000016221326222430700164620ustar00rootroot00000000000000Copyright (C) 2011-2013 BalaBit IT Security Ltd. Copyright (C) 2011-2013 Gergely Nagy The syslog-ng incubator modules are released under the terms of the GNU General Public License version 2 as published by the Free Software Foundation, or (at your opinion) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA As an additional exemption you are allowed to compile & link against the OpenSSL libraries as published by the OpenSSL project. See the GPL.txt for the full text of the GNU GPL. syslog-ng-incubator-0.6.2/GPL.txt000066400000000000000000000354311326222430700166170ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS syslog-ng-incubator-0.6.2/Makefile.am000066400000000000000000000011561326222430700174650ustar00rootroot00000000000000ACLOCAL_AMFLAGS = -I m4 AM_YFLAGS = -Wno-other -d scldir = ${datadir}/include/scl check_PROGRAMS = TESTS = ${check_PROGRAMS} bin_PROGRAMS = module_LTLIBRARIES = BUILT_SOURCES = EXTRA_DIST = \ COPYING GPL.txt README.md NEWS DISTFILES = \ $(filter-out %-grammar.y %-grammar.c %-grammar.h,$(DIST_COMMON)) \ $(filter-out %-grammar.y,$(DIST_SOURCES)) \ $(TEXINFOS) $(EXTRA_DIST) DISTCLEANFILES = \ $(filter %-grammar.y %-grammar.c %-grammar.h,$(DIST_COMMON)) \ $(filter %-grammar.y,$(DIST_SOURCES)) .y.c: include modules/Makefile.am include tools/Makefile.am include $(syslog_ng_tools)/lex-rules.am syslog-ng-incubator-0.6.2/NEWS000066400000000000000000000237031326222430700161320ustar00rootroot00000000000000# 0.6.0 - <2017-07-28 Fri> ## Remove: date parser Date parser was removed as it was incorporated into syslog-ng master ## Remove: getent template function Getent module was merged into syslog-ng, so it was removed from here ## Feature: syslog-ng 3.8 support This release adds support for syslog-ng 3.8 and also incorporated a lot of bugfixes needed to compile the code. ## Bugfix: Renamed kafka destination to kafka_c To fix conflict with syslog-ng ## Bugfix: Fix queue.buffering.max.ms value in example Setting a too low value incurs a moderate CPU usage even when no logs need to be forwarded. Increase the value to 1s instead. We would like to thank the following people for their contribution: Vincent Bernat, Balazs Scheidler, Yilin Li, Laszlo Varady # 0.5.0 - <2015-08-18 Tue> ## Feature: syslog-ng 3.7 support This release adds support for syslog-ng 3.7, but older versions are not supported anymore. ## Feature: date parser A parser for arbitrary date formats which may be contained in non-syslog messages ## Feature: Kafka improvements * check for partition availability before selecting one * synchronously insert events into kafka (configurable) ## Bugfix: Various kafka/grok configure fixes In some cases enable/disable kafka and grok support were confused ## Bugfix: getent group size Fixes extraction on large groups We would like to thank the following people for their contribution: Andras Mitzki, Fabien Wernli, Gergely Nagy, Laszlo Meszaros, Levente Kurusa, Peter Czanik, Viktor Juhasz, Vincent Bernat # 0.4.1 - <2014-12-16 Tue> ## Bugfix: Make it possible to disable java destination And the detection of java environment is refined ## Bugfix: Purge the last traces of graphite Because graphite was feature merged into syslog-ng 3.6 We would like to thank the following people for their contribution: Peter Czanik, Gergely Nagy, Viktor Juhasz, Laszlo Budai # 0.4.0 - <2014-12-10 Wed> This release contains a wide variety of new features as well as several bugfixes, too. This is the first version with support for syslog-ng 3.6. Support for older versions of syslog-ng is dropped. ## Feature: syslog-ng 3.6 support. This release adds support for syslog-ng 3.6, but older versions are not supported anymore. ## Feature: Kafka destination. This destination enables sending logs to Apache Kafka messaging system. ## Feature: grok parser. Grok is an advanced pattern format (like PatternDB) used primarily by LogStash, which allows users to parse unstructured data into a structured format. This module allows syslog-ng users to use Grok patterns, too. ## Feature: ZMQ source/destination. ZeroMQ is a simple, high-speed messaging protocol. These drivers allows syslog-ng to send/receive logs from ZeroMQ message brokers. ## Feature: Java destination. Java destination drivers enables the users to write destinations in Java or in any JVM compatible language. ## Bugfix: Fixed counting inserted/sent messages as stored ones. ## Bugfix: Fixed two python destination segfaults. Python exceptions and messages not conforming to UTF-8 do not crash the destination anymore. We would like to thank the following people for their contribution: Balazs Scheidler, Brandon Smith, Fabian Wernli, Gergely Nagy, Laszlo Meszaros, Pierre-Yves Ritschard, Robert Fekete, Sandor Irhazi, Viktor Juhasz, Viktor Tusa # 0.3.3 - <2014-07-25 Fri> ## Bugfix: Compatibility with syslog-ng 3.5.5 The newest syslog-ng release, syslog-ng 3.5.5 introduced a breaking API change. The Incubator has been updated, and now works with - and requires - at least syslog-ng 3.5.5. ## Bugfix: Fix for the ElasticSearch SCL plugin The ElasticSearch SCL plugin has been fixed, and will now work out of the box. # 0.3.2 - <2014-07-15 Tue> Larger bugfix release with several small features. ## Bugfix: Fixed getent template function compilation on FreeBSD. There was an unnecessary header file, which isn't present on FreeBSD. ## Feature: Added support for protocols in getent template function. Getent template function can now resolve protocol names. ## Bugfix: Lua destination became a so-called threaded destination. It has now a separate thread, and it prevents race conditions in multi-threaded mode. ## Feature: Lua destination init parameters and queue parameters are reworked. Globals are now constants as they should ever be. There is a new feature with the params() option, which works exactly as the old globals(), eg. uses value pairs, and templates can be used. The result is manifested as a lua table as the second parameter of the queue func. Although the same result can be achieved by using raw mode and Template class in Lua, using params is more comfortable in some cases (eg: SCL). ## Bugfix: Perl destination driver has a separate thread. This prevents reace conditions like in Lua. ## Feature: Graphite SCL is added. This allows a brand new graphite destination on top of tcp() driver and graphite-output template function. ## Bugfix: Consolidated --enable-# configure parameters. They are now working similarly, yes means that if configure doesn't find the depending lib, it fails, auto means, that if configure doesn't find the depending lib, it disables the feature, and no means configure simply disables the feature. The only exception is python. ## Feature: Python version autodetection. --with-python switch has now the following options: no: disables python related modules; auto: autodetects python version, disables python modules if not found; force: autodetects python version, fails if not found; python-: forces specified version, fails if not found. # 0.3.1 - <2014-06-02 Mon> ## Bugfix: Fixed linkage of modules All modules were accidentally linked to libperl, now only perl destination module is linked to libperl. ## Bugfix: Fixed rss module linkage. It wasn't linked to libsyslog-ng.so. # 0.3.0 - <2014-05-28 Wed> New scripted destinations are introduced by algernon : Python and Perl. Additionally several bugfixes, small features and the getent template function are introduced. ## Feature: Python and Perl destination These destinations are very similar to the current Lua destination, except that their queue method get a dict (or hash in Perl) as a parameter. ## Feature: getent template function. Getent template function can query information from the system user databases. For example it can convert uid to username and can get other fields from user databases. ## Feature: Graphite output timestamp now configurable as a template. ## Feature: Padding template function allows user to pad a string to a specified width. ## Bugfix: Fixed float casting in Riemann destination ## Bugfix: Fixed an error messsage in + template function. # 0.2.1 - <2014-03-12 Wed> This is a bug fix only release over the previous 0.2.0 version, with the following changes: ## Bugfix: FreeBSD portability The Incubator can now be compiled on FreeBSD! ## Bugfix: Improved Lua detection On some systems, the Lua pkg-config file is called lua-5.1, or lua-5.2, not lua5.1/lua5.2. The configure script was taught to recognise all of these. ## Bugfix: Fixed a crash in the Lua destination When using the Lua destination without globals() being present does not crash the module anymore. # 0.2.0 - <2014-02-26 Wed> Most of the features of this release are contributed by Viktor Tusa , many thanks for them! ## Feature: LuaJIT support When configured with --enable-luajit, and LuaJIT is available, it is now possible to build the Lua destination against that version of Lua. ## Feature: monitor source This new source is somewhere between the trigger() source and the lua() destination, in that it allows one to write a Lua function that gets periodically executed, and can produce a log message. ## Feature: Templating support for the Lua destination Destinations written in Lua can now use Templates, from within the Lua code itself. Most useful for raw mode. ## Feature: Lua destinations have easy access to the timestamps The Lua destination now makes another function available: Message.get_timestamp(), that gets one the UNIX timestamp in integer format, without having to format it first with a template, and then converting it back. ## Feature: The Lua modules now have a deinit hook In case the destination needs to do something at deinit time, there is now a deinit hook. ## Feature: The Lua modules has access to logging functions It is now possible to use syslogng.debug, syslogng.error, syslogng.info and syslogng.verbose functions from within Lua, to construct internal log messages. ## Feature: The Lua destination can have global variables set It is now possible to set global variables (strings and ints) from within the syslog-ng configuration file, that get passed down to the Lua destination. ## Feature: graphite output template function This template function, with syntax much like that of $(format-json) allows one to easily forward data to a Graphite server, when combined with the tcp() destination. ## Feature: An ElasticSearch SCL The Incubator now ships with an SCL file, and a helper program that makes it possible to easily send events to ElasticSearch, in a Kibana-compatible format. ## Bugfix: RSS destination does not require newer glib The RSS destination used features not available in the glib version targeted by the Incubator. It was fixed to work with the older version we target. # 0.1.1 - <2014-01-24 Fri> ## Bugfix: Grammar files are not shipped in the tarball anymore When generating a tarball with "make dist", the built grammar files are not shipped anymore. They're built against a specific syslog-ng version, and as such, are not portable to another version of it. The grammars need to be rebuilt, and shipping them prevents that. ## Bugfix: Don't depend on recent glib When glib is too old, the $(state) template function gets disabled now, instead of the build failing. ## Feature: Lua destination This new feature allows one to write destination driver scripts in Lua. Example scripts are provided in modules/lua/. # 0.1.0 - <2013-12-28 Sat> Initial public release. syslog-ng-incubator-0.6.2/README.md000066400000000000000000000104131326222430700167040ustar00rootroot00000000000000syslog-ng module incubator ========================== The [syslog-ng][sng] module incubator (Incubator henceforth) is a collection of tools and modules for [syslog-ng][sng] that for one reason or the other, are not part of the official repository. This serves both as a staging ground for experimental modules, and as a repository of plugins that are not aimed at upstream inclusion. It's also an example of a third party syslog-ng module. [sng]: https://github.com/balabit/syslog-ng **NOTE**: The Incubator requires syslog-ng 3.12.1 or newer. Contents -------- * [Lua destination][sng:lua]: This destination is really just a wrapper, that allows one to write destination drivers in Lua, with some limitations. [sng:lua]: https://github.com/balabit/syslog-ng-incubator/tree/master/modules/lua/ * [Perl destination][sng:perl]: This destination allows one to write destination plugins in Perl. [sng:perl]: https://github.com/balabit/syslog-ng-incubator/tree/master/modules/perl/ * [Trigger source][sng:trigger]: A very simple example source that periodically generates a message. Useful mostly for debugging purposes. [sng:trigger]: https://github.com/balabit/syslog-ng-incubator/tree/master/modules/trigger-source/ * [Monitor source][sng:monitor]: A module similar to the trigger source, except it dispatches to a Lua function to generate the message. [sng:monitor]: https://github.com/balabit/syslog-ng-incubator/tree/master/modules/monitor-source/ * [Extra template functions][sng:bf+]: Extra template functions, such as `$(//)` which is floating-point division, as opposed to the built-in `$(/)` (integer division). Functions: * // : floating point division * state : gets or sets global state from template function. [sng:bf+]: https://github.com/balabit/syslog-ng-incubator/tree/master/modules/basicfuncs-plus/ * [RSS destination][sng:rss]: A very simple destination module that allows one to offer log messages as an RSS feed. [sng:rss]: https://github.com/balabit/syslog-ng-incubator/tree/master/modules/rss/ * [logmongource][sng:mongource]: A log visualisation tool that extracts messages from a MongoDB collection, and visualises them with [Gource](https://code.google.com/p/gource/). [sng:mongource]: https://github.com/balabit/syslog-ng-incubator/tree/master/tools/visualize/ * [Kafka destination][sng:kafka]: A simple, work in progress destination that allows syslog-ng to send events to the [Apache Kafka](http://kafka.apache.org/) distributed queue. [sng:kafka]: https://github.com/balabit/syslog-ng-incubator/tree/master/modules/kafka/ * [Grok parser][sng:grok]: Grok is an advanced pattern format (like PatternDB) used primarily by LogStash, which allows users to parse unstructured data into a structured format. This module allows syslog-ng users to use Grok patterns, too. [Grok](https://github.com/jordansissel/grok/) C parser for grok. [sng:grok]: https://github.com/balabit/syslog-ng-incubator/tree/master/modules/grok/ * [0MQ source/destination][sng:zmq]: ZeroMQ is a simple, high-speed messaging protocol. These drivers allows syslog-ng to send/receive logs from ZeroMQ message brokers. [0MQ](http://zeromq.org/) message protocol. [sng:zmq]: https://github.com/balabit/syslog-ng-incubator/tree/master/modules/zmq/ Installation ------------ Installing the modules and tools follows the usual autotools way: $ git clone git://github.com/balabit/syslog-ng-incubator.git $ cd syslog-ng-incubator $ autoreconf -i $ ./configure && make && make install Of course, one will need all the dependencies ([syslog-ng][sng], bison, flex, [libmongo-client][lmc], [lua][lua], [perl][perl], [rdkafka][kafka]; of which the latter six are optional) installed too. [lmc]: https://github.com/algernon/libmongo-client [lua]: http://www.lua.org/ [perl]: http://www.perl.org/ [kafka]: https://github.com/edenhill/librdkafka License ------- Copyright (C) 2011-2017 BalaBit IT Security Ltd., Gergely Nagy , Viktor Tusa , Viktor Juhasz , Attila Szalay and other contributors; released under the terms of the [GNU General Public License][gpl], version 2 (or later). [gpl]: http://www.gnu.org/licenses/gpl-2.0.html syslog-ng-incubator-0.6.2/configure.ac000066400000000000000000000247651326222430700177320ustar00rootroot00000000000000dnl Process this file with autoconf to produce a configure script. dnl AC_PREREQ([2.68]) AC_INIT([syslog-ng-incubator], [0.6.2], [sasa@ubainba.hu]) AM_INIT_AUTOMAKE([foreign subdir-objects dist-xz no-dist-gzip]) AC_CONFIG_MACRO_DIR([m4]) m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) AC_CONFIG_HEADERS([config.h]) dnl *************************************************************************** dnl definitions moduledir='${exec_prefix}/lib/syslog-ng' enable_value() { if test "x$1" = "xyes" ; then echo 1 else echo 0 fi } dnl *************************************************************************** dnl dependencies GLIB_MIN_VERSION="2.14" SYSLOG_NG_MIN_VERSION="3.12.0" IVYKIS_MIN_VERSION="0.30.0" LMC_MIN_VERSION="0.1.2" LRC_MIN_VERSION="1.0.0" LUA_MIN_VERSION="5.1.4" ZMQ_MIN_VERSION="3.1.1" dnl *************************************************************************** dnl Initial setup AC_ARG_ENABLE(debug, [ --enable-debug Enable debugging code.],, enable_debug="no") AC_ARG_WITH(module-dir, [ --with-module-dir=path Use path as the list of directories looked up when searching for modules], moduledir=$with_module_dir,moduledir="auto") AC_ARG_WITH(ivykis, [ --without-ivykis Build without explicitly linking to ivykis]) AC_ARG_ENABLE(luajit, [ --enable-luajit Use luajit instead of standard liblua for Lua support], enable_luajit="yes",) AC_ARG_ENABLE(lua, [ --disable-lua Disable lua based modules (lua-dest, monitoring source)], ,enable_lua="auto") AC_ARG_ENABLE(perl, [ --disable-perl Disable perl based modules (perl-dest)], ,enable_perl="auto") AC_ARG_ENABLE(logmongource, [ --disable-logmongource Disable logmongource tool], ,enable_logmongource="auto") AC_ARG_ENABLE(kafka, [ --disable-kafka Disable Kafka support (default: auto)] ,,enable_kafka="auto") AC_ARG_WITH(librdkafka, AC_HELP_STRING([--with-librdkafka=DIR], [use librdkafka library from (prefix) directory DIR]) ,,with_librdkafka="no") AC_ARG_ENABLE(grok, [ --disable-grok Disable Grok Parser support (default: auto)] ,,enable_grok="auto") AC_ARG_WITH(libgrok, AC_HELP_STRING([--with-libgrok=DIR], [use libgrok library from (prefix) directory DIR]) ,,with_libgrok="no") AC_ARG_ENABLE(zmq, [ --enable-zmq Enable zmq destination ], ,enable_zmq="auto") dnl *************************************************************************** dnl Checks for programs. AC_PROG_YACC AC_PROG_CC AC_PROG_CC_C_O AC_PROG_CC_C99 AC_C_INLINE LT_INIT([shared dlopen]) AC_PROG_MAKE_SET PKG_PROG_PKG_CONFIG dnl *************************************************************************** dnl Miscellanneous headers dnl *************************************************************************** AC_HEADER_STDC AC_CHECK_HEADERS([stdlib.h]) AC_CHECK_FUNCS([floor memrchr memset strdup strtoll]) dnl *************************************************************************** dnl Header checks dnl *************************************************************************** dnl *************************************************************************** dnl Checks for libraries dnl *************************************************************************** PKG_CHECK_MODULES(GLIB, glib-2.0 >= $GLIB_MIN_VERSION) dnl *************************************************************************** dnl syslog-ng headers/libraries dnl *************************************************************************** PKG_CHECK_MODULES(SYSLOG_NG, syslog-ng >= $SYSLOG_NG_MIN_VERSION) syslog_ng_ivykis=[`pkg-config syslog-ng --variable ivykis`] if test "x$with_ivykis" != "xno" && test "x$syslog_ng_ivykis" != "xinternal"; then PKG_CHECK_MODULES(IVYKIS, ivykis >= $IVYKIS_MIN_VERSION,,true) fi syslog_ng_tools=[`pkg-config syslog-ng --variable toolsdir`] if test "x$moduledir" = "xauto"; then moduledir=[`pkg-config syslog-ng --variable moduledir`] fi dnl *************************************************************************** dnl libmongo-client headers/libraries dnl *************************************************************************** INCUBATOR_CHECK_DEP(logmongource,[PKG_CHECK_MODULES(LIBMONGO, libmongo-client >= $LMC_MIN_VERSION,,logmongource_found="no")]) dnl *************************************************************************** dnl lua headers/libraries dnl *************************************************************************** dnl if test "x$enable_lua" != "xno"; then INCUBATOR_CHECK_DEP(lua,[ if test "x$enable_luajit" == "xyes"; then PKG_CHECK_EXISTS(luajit, [lua_mod="luajit"; LUA_MIN_VERSION="2.0"]) fi if test "x$lua_mod" != "xluajit"; then PKG_CHECK_EXISTS(lua, lua_mod="lua", PKG_CHECK_EXISTS(lua5.2, lua_mod="lua5.2", PKG_CHECK_EXISTS(lua-5.2, lua_mod="lua-5.2", PKG_CHECK_EXISTS(lua5.1, lua_mod="lua5.1", PKG_CHECK_EXISTS(lua-5.1, lua_mod="lua-5.1"))))) fi PKG_CHECK_MODULES(LUA, $lua_mod >= $LUA_MIN_VERSION,,lua_found="no")]) dnl *************************************************************************** dnl Perl checks dnl *************************************************************************** INCUBATOR_CHECK_DEP(perl,[ AC_CHECK_PROG(PERL, perl, perl) if test "x$PERL" != "x"; then AC_MSG_CHECKING(for perl module ExtUtils::Embed) $PERL -e "use ExtUtils::Embed; exit" >/dev/null 2>&1 if test $? -ne 0; then AC_MSG_RESULT(no) perl_found="no" else AC_MSG_RESULT(ok) fi else perl_found="no" fi if test "x$perl_found" != "xno"; then LDFLAGS_SAVE="$LDFLAGS" LDFLAGS="$LDFLAGS `$PERL -MExtUtils::Embed -e ldopts`" AC_CHECK_LIB(perl, perl_construct, [true], perl_found="no") LDFLAGS="$LDFLAGS_SAVE" fi]) dnl *************************************************************************** dnl grok headers/libraries dnl *************************************************************************** if test "x$enable_grok" != "xno"; then grok="no" if test "x$with_libgrok" != "xno"; then GROK_LIBS="-L$with_libgrok" GROK_CFLAGS="-I$with_libgrok" grok="yes" else PKG_CHECK_MODULES(GROK, libgrok libtokyocabinet, grok="yes", AC_CHECK_LIB(grok, grok_new, [grok="yes"; GROK_LIBS="-lgrok"], [grok="no"])) fi if test "x$enable_grok" = "xyes" && test "x$grok" = "xno"; then AC_MSG_ERROR(libgrok not found) fi enable_grok=$grok fi dnl *************************************************************************** dnl librdkafka headers/libraries dnl *************************************************************************** if test "x$enable_kafka" != "xno"; then rdkafka="yes" if test "x$with_librdkafka" != "xno"; then CFLAGS_SAVE="$CFLAGS" LDFLAGS_SAVE="$LDFLAGS" CFLAGS="$CFLAGS -I$with_librdkafka/include" LDFLAGS="$LDFLAGS -L$with_librdkafka/lib" AC_CHECK_HEADER(librdkafka/rdkafka.h, [RDKAFKA_CFLAGS="-I$with_librdkafka/include" RDKAFKA_LIBS="-L$with_librdkafka/lib -lrdkafka"], [rdkafka=no]) CFLAGS="$CFLAGS_SAVE" LDFLAGS="$LDFLAGS_SAVE" else AC_CHECK_HEADER(librdkafka/rdkafka.h, [RDKAFKA_LIBS="-lrdkafka"], [rdkafka=no]) fi if test "x$enable_kafka" = "xyes" && test "x$rdkafka" = "xno"; then AC_MSG_ERROR(librdkafka not found) fi AC_CHECK_LIB(rdkafka, rd_kafka_conf_set_log_cb, [with_librdkafka_log_cb="yes"], [with_librdkafka_log_cb="no"]) AC_CHECK_LIB(rdkafka, rd_kafka_set_logger, [with_librdkafka_logger="yes"], [with_librdkafka_logger="no"]) if test "x$with_librdkafka_log_cb" = "xyes"; then AC_DEFINE(HAVE_LIBRDKAFKA_LOG_CB, 1, [Define if librdkafka log_cb facility is present and usable.]) fi if test "x$with_librdkafka_logger" = "xyes"; then AC_DEFINE(HAVE_LIBRDKAFKA_LOGGER, 1, [Define if librdkafka logger facility is present and usable.]) fi enable_kafka=$rdkafka fi dnl *************************************************************************** dnl zmq headers/libraries dnl *************************************************************************** INCUBATOR_CHECK_DEP(zmq,[PKG_CHECK_MODULES(ZMQ_CLIENT, libzmq >= $ZMQ_MIN_VERSION, zmq_found="yes", zmq_found="no")]) dnl *************************************************************************** dnl create common cflags/libs for incubator modules. dnl *************************************************************************** SYSLOG_NG_LIBDIR="`$PKG_CONFIG --variable=libdir syslog-ng`" INCUBATOR_CFLAGS="$SYSLOG_NG_CFLAGS $IVYKIS_CFLAGS $GLIB_CFLAGS" INCUBATOR_LIBS="$SYSLOG_NG_LIBS $IVYKIS_LIBS $GLIB_LIBS" INCUBATOR_TEST_LDADD="$SYSLOG_NG_LIBDIR/syslog-ng/libtest/libsyslog-ng-test.a -rpath $SYSLOG_NG_LIBDIR" dnl *************************************************************************** dnl misc features to be enabled dnl *************************************************************************** AC_SUBST(syslog_ng_tools) AC_SUBST(moduledir) AC_SUBST(GROK_LIBS) AC_SUBST(INCUBATOR_CFLAGS) AC_SUBST(INCUBATOR_LIBS) AC_SUBST(RDKAFKA_CFLAGS) AC_SUBST(RDKAFKA_LIBS) AC_SUBST(INCUBATOR_TEST_LDADD) AC_SUBST(SYSLOG_NG_LIBDIR) AC_DEFINE_UNQUOTED(ENABLE_DEBUG, `enable_value $enable_debug`, [Enable debugging]) AM_CONDITIONAL(ENABLE_LOGMONGOURCE, [test "$enable_logmongource" != "no"]) AM_CONDITIONAL(ENABLE_LUA, [test "$enable_lua" != "no"]) AM_CONDITIONAL(ENABLE_PERL, [test "$enable_perl" != "no"]) AM_CONDITIONAL(ENABLE_KAFKA, [test "x$enable_kafka" = "xyes"]) AM_CONDITIONAL(ENABLE_ZMQ, [test "$enable_zmq" != "no"]) AM_CONDITIONAL(ENABLE_GROK, [test "$enable_grok" != "no"]) AC_CONFIG_FILES([Makefile]) AC_OUTPUT echo echo "syslog-ng Incubator $VERSION configured" echo "syslog-ng Incubator $VERSION configured" | sed -e "s/./-/g" echo " Debugging: ${enable_debug:=no}" echo " Modules:" echo " basicfuncs-plus yes" echo " kafka ${enable_kafka:=no}" echo " logmongource: ${enable_logmongource:-yes}" echo " lua: ${enable_lua:-yes} ${lua_mod:+($lua_mod)}" echo " monitor-source: ${enable_lua:-yes} ${lua_mod:+($lua_mod)}" echo " perl: ${enable_perl:-yes}" echo " rss yes" echo " trigger-source yes" echo " zmq ${enable_zmq:=no}" echo " grok-parser ${enable_grok}" echo syslog-ng-incubator-0.6.2/m4/000077500000000000000000000000001326222430700157465ustar00rootroot00000000000000syslog-ng-incubator-0.6.2/m4/.placeholder000066400000000000000000000000001326222430700202170ustar00rootroot00000000000000syslog-ng-incubator-0.6.2/m4/check_java_version.m4000066400000000000000000000034171326222430700220400ustar00rootroot00000000000000AU_ALIAS([AC_CHECK_JAVA_VERSION], [AX_CHECK_JAVA_VERSION]) AC_DEFUN([AX_CHECK_JAVA_VERSION], [AC_MSG_CHECKING([for JAVA_VERSION]) JAVA_VERSION=[$1] JAVAC_BIN=`which javac` JAVAH_BIN=`which javah` JAR_BIN=`which jar` if test "x$JAVAC_BIN" != "x"; then JAVAC_BIN=`readlink -f $JAVAC_BIN` JAVAH_BIN=`readlink -f $JAVAH_BIN` JAR_BIN=`readlink -f $JAR_BIN` JAVAC_VERSION=`$JAVAC_BIN -version 2>&1 | sed "s/.*\ \(.*\)/\1/"` SHORT_VERSION=${JAVAC_VERSION%.*} MAJOR_VERSION=${SHORT_VERSION%.*} MINOR_VERSION=${SHORT_VERSION##*.} EXPECTED_MAJOR_VERSION=${JAVA_VERSION%.*} EXPECTED_MINOR_VERSION=${JAVA_VERSION##*.} if test "$MAJOR_VERSION" -lt "$EXPECTED_MAJOR_VERSION"; then AC_MSG_ERROR([Too old java version required: $JAVA_VERSION found: $SHORT_VERSION]) elif test "$MAJOR_VERSION" -eq "$EXPECTED_MAJOR_VERSION"; then if test "$MINOR_VERSION" -lt "$EXPECTED_MINOR_VERSION"; then AC_MSG_ERROR([Too old java version required: $JAVA_VERSION found: $SHORT_VERSION]) fi fi JNI_HOME=`echo $JAVAC_BIN | sed "s/\(.*\)[[/]]bin[[/]]java.*/\1/"` JNI_LIBDIR=`find $JNI_HOME -name "libjvm.so" | sed "s/\(.*\)libjvm.so/\1/" | head -n 1` JNI_LIBS="-L$JNI_LIBDIR -ljvm" JNI_INCLUDE_DIR=`find $JNI_HOME -name "jni.h" | sed "s/\(.*\)jni.h/\1/" | head -n 1` JNI_CFLAGS="-I$JNI_INCLUDE_DIR" JNI_MD_INCLUDE_DIR=`find $JNI_HOME -name "jni_md.h" | sed "s/\(.*\)jni_md.h/\1/" | head -n 1` JNI_CFLAGS="$JNI_CFLAGS -I$JNI_MD_INCLUDE_DIR" AC_SUBST(JNI_CFLAGS, "$JNI_CFLAGS") AC_SUBST(JNI_LIBS, "$JNI_LIBS") AC_SUBST(JAVAC, "$JAVAC_BIN") AC_SUBST(JAVAH, "$JAVAH_BIN") AC_SUBST(JAR, "$JAR_BIN") $2 AC_MSG_RESULT([$SHORT_VERSION]) else $3 AC_MSG_RESULT([no]) fi ]) syslog-ng-incubator-0.6.2/m4/incubator.m4000066400000000000000000000004611326222430700201770ustar00rootroot00000000000000AC_DEFUN([INCUBATOR_CHECK_DEP], [if test "$enable_]$1[" != "no"; then $2; if test "$]$1[_found" == "no" -a "$enable_]$1[" == "yes"; then AC_MSG_ERROR(Dependency for ]$1[ not found!); fi; if test "$]$1[_found" == "no"; then enable_]$1[="no" else enable_]$1[="yes" fi fi])dnl syslog-ng-incubator-0.6.2/modules/000077500000000000000000000000001326222430700170765ustar00rootroot00000000000000syslog-ng-incubator-0.6.2/modules/Makefile.am000066400000000000000000000005101326222430700211260ustar00rootroot00000000000000include modules/trigger-source/Makefile.am include modules/monitor-source/Makefile.am include modules/basicfuncs-plus/Makefile.am include modules/rss/Makefile.am include modules/lua/Makefile.am include modules/perl/Makefile.am include modules/kafka-c/Makefile.am include modules/zmq/Makefile.am include modules/grok/Makefile.am syslog-ng-incubator-0.6.2/modules/basicfuncs-plus/000077500000000000000000000000001326222430700221775ustar00rootroot00000000000000syslog-ng-incubator-0.6.2/modules/basicfuncs-plus/Makefile.am000066400000000000000000000013701326222430700242340ustar00rootroot00000000000000module_LTLIBRARIES += \ modules/basicfuncs-plus/libbasicfuncs-plus.la modules_basicfuncs_plus_libbasicfuncs_plus_la_SOURCES = \ modules/basicfuncs-plus/basic-funcs-plus.c modules_basicfuncs_plus_libbasicfuncs_plus_la_CPPFLAGS = \ $(AM_CPPFLAGS) \ $(INCUBATOR_CFLAGS) \ -I$(top_srcdir)/modules/basicfuncs-plus modules_basicfuncs_plus_libbasicfuncs_plus_la_LIBADD = \ $(INCUBATOR_LIBS) modules_basicfuncs_plus_libbasicfuncs_plus_la_LDFLAGS = \ -avoid-version -module -no-undefined EXTRA_DIST += \ modules/basicfuncs-plus/number-funcs.c \ modules/basicfuncs-plus/state-funcs.c modules/basicfuncs-plus mod-basicfuncs-plus: modules/basicfuncs-plus/libbasicfuncs-plus.la .PHONY: modules/basicfuncs-plus mod-basicfuncs-plus syslog-ng-incubator-0.6.2/modules/basicfuncs-plus/basic-funcs-plus.c000066400000000000000000000036341326222430700255270ustar00rootroot00000000000000/* * Copyright (c) 2013, 2014 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2013, 2014 Gergely Nagy * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * As an additional exemption you are allowed to compile & link against the * OpenSSL libraries as published by the OpenSSL project. See the file * COPYING for details. * */ #include "plugin.h" #include "cfg.h" #include "template/function.h" #include "plugin-types.h" #include "number-funcs.c" #if GLIB_CHECK_VERSION(2,32,0) #include "state-funcs.c" #endif /* * Plugin glue */ static Plugin basicfuncs_plus_plugins[] = { TEMPLATE_FUNCTION_PLUGIN(tf_num_divx, "//"), #if GLIB_CHECK_VERSION(2,32,0) TEMPLATE_FUNCTION_PLUGIN(tf_state, "state"), #endif }; gboolean basicfuncs_plus_module_init(PluginContext *context, CfgArgs *args) { plugin_register(context, basicfuncs_plus_plugins, G_N_ELEMENTS(basicfuncs_plus_plugins)); return TRUE; } const ModuleInfo module_info = { .canonical_name = "basicfuncs-plus", .version = SYSLOG_NG_VERSION, .description = "The basicfuncs-plus module provides some additional template functions for syslog-ng.", .core_revision = VERSION_CURRENT_VER_ONLY, .plugins = basicfuncs_plus_plugins, .plugins_len = G_N_ELEMENTS(basicfuncs_plus_plugins), }; syslog-ng-incubator-0.6.2/modules/basicfuncs-plus/number-funcs.c000066400000000000000000000045331326222430700247540ustar00rootroot00000000000000/* * Copyright (c) 2013, 2014 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2013, 2014 Gergely Nagy * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * As an additional exemption you are allowed to compile & link against the * OpenSSL libraries as published by the OpenSSL project. See the file * COPYING for details. * */ #include #include #include #include "plugin.h" #include "cfg.h" #include "parse-number.h" #include "plugin-types.h" #include "template/simple-function.h" static gboolean tf_num_parse(gint argc, GString *argv[], const gchar *func_name, glong *n, glong *m) { if (argc != 2) { msg_debug("Template function requires two arguments.", evt_tag_str("function", func_name), NULL); return FALSE; } if (!parse_number_with_suffix(argv[0]->str, n)) { msg_debug("Parsing failed, template function's first argument is not a number", evt_tag_str("function", func_name), evt_tag_str("arg1", argv[0]->str), NULL); return FALSE; } if (!parse_number_with_suffix(argv[1]->str, m)) { msg_debug("Parsing failed, template function's second argument is not a number", evt_tag_str("function", func_name), evt_tag_str("arg2", argv[1]->str), NULL); return FALSE; } return TRUE; } static void tf_num_divx(LogMessage *msg, gint argc, GString *argv[], GString *result) { glong n, m; if (!tf_num_parse(argc, argv, "//", &n, &m) || !m) { g_string_append_len(result, "NaN", 3); return; } g_string_append_printf (result, "%f", (double) ((double)n / (double)m)); } TEMPLATE_FUNCTION_SIMPLE(tf_num_divx); syslog-ng-incubator-0.6.2/modules/basicfuncs-plus/state-funcs.c000066400000000000000000000050621326222430700246020ustar00rootroot00000000000000/* * Copyright (c) 2013 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2013 Gergely Nagy * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * As an additional exemption you are allowed to compile & link against the * OpenSSL libraries as published by the OpenSSL project. See the file * COPYING for details. * */ #include "syslog-ng.h" #include "plugin.h" #include "cfg.h" #include "plugin-types.h" static struct { GRWLock lock; GHashTable *hashtable; } tf_state_global_state; static void tf_state_get (LogMessage *msg, GString *result, GString *var) { gchar *val; g_rw_lock_reader_lock (&tf_state_global_state.lock); if (!tf_state_global_state.hashtable) { g_rw_lock_reader_unlock (&tf_state_global_state.lock); return; } val = g_hash_table_lookup (tf_state_global_state.hashtable, (gpointer)var->str); if (val) g_string_append_printf (result, "%s", val); g_rw_lock_reader_unlock (&tf_state_global_state.lock); } static void tf_state_set (LogMessage *msg, GString *result, GString *var, GString *val) { g_rw_lock_writer_lock (&tf_state_global_state.lock); if (!tf_state_global_state.hashtable) tf_state_global_state.hashtable = g_hash_table_new (g_str_hash, g_str_equal); g_hash_table_insert (tf_state_global_state.hashtable, (gpointer)g_strdup (var->str), (gpointer)g_strdup (val->str)); g_rw_lock_writer_unlock (&tf_state_global_state.lock); tf_state_get (msg, result, var); } static void tf_state (LogMessage *msg, gint argc, GString *argv[], GString *result) { if (argc == 1) tf_state_get (msg, result, argv[0]); else if (argc == 2) tf_state_set (msg, result, argv[0], argv[1]); else msg_debug ("The $(state) template function requires either one or two arguments.", evt_tag_int("argc", argc), NULL); } TEMPLATE_FUNCTION_SIMPLE(tf_state); syslog-ng-incubator-0.6.2/modules/grok/000077500000000000000000000000001326222430700200405ustar00rootroot00000000000000syslog-ng-incubator-0.6.2/modules/grok/Makefile.am000066400000000000000000000021221326222430700220710ustar00rootroot00000000000000if ENABLE_GROK module_LTLIBRARIES += modules/grok/libgrok-parser.la modules_grok_libgrok_parser_la_CFLAGS = \ $(INCUBATOR_CFLAGS) \ $(GROK_CFLAGS) \ -I$(top_srcdir)/modules/grok \ -I$(top_builddir)/modules/grok modules_grok_libgrok_parser_la_SOURCES = \ modules/grok/grok-parser-grammar.y \ modules/grok/grok-parser.c \ modules/grok/grok-parser.h \ modules/grok/grok-parser-parser.c \ modules/grok/grok-parser-parser.h \ modules/grok/grok-parser-plugin.c modules_grok_libgrok_parser_la_LIBADD = \ $(INCUBATOR_LIBS) modules_grok_libgrok_parser_la_LDFLAGS = \ -avoid-version -module -no-undefined $(GROK_LIBS) BUILT_SOURCES += \ modules/grok/grok-parser-grammar.y \ modules/grok/grok-parser-grammar.c \ modules/grok/grok-parser-grammar.h include modules/grok/tests/Makefile.am modules/grok-parser mod-grok: modules/grok/libgrok-parser.la else modules/grok-parser mod-grok: endif EXTRA_DIST += \ modules/grok/grok-parser-grammar.ym \ modules/grok/grok-parser-example.conf .PHONY: modules/grok mod-grok syslog-ng-incubator-0.6.2/modules/grok/README.md000066400000000000000000000016671326222430700213310ustar00rootroot00000000000000grok parser =========== grok parser can parse log messages using grok patterns. Example config: ``` parser p_grok { grok( pattern_directory("/etc/syslog-ng/grok.d") match("%{STRING:field}" tags("matched" "string") ) match("%{NUMBER:field}" tags("matched" "number") ) ); }; ``` How to compile: you should have libgrok (https://github.com/jordansissel/grok) installed on your system. --with-libgrok in not implemented yet, but I should implement it or include libgrok as a git submodule. You can alternatively compile libgrok from my repository: https://github.com/talien/grok. It has an autotools based Makefile, so can configure it like this: autoreconf -i && ./configure && make && make install. It also installs a .pc file for pkg-config. It's not a filter like in logstash, instead a syslog-ng parser (eg. it does not drop the message if it does not match) The parsed subpatterns are available as message fields. syslog-ng-incubator-0.6.2/modules/grok/grok-parser-example.conf000066400000000000000000000005331326222430700245750ustar00rootroot00000000000000source s_tcp { tcp(); }; parser p_grok { grok ( pattern_directory("/etc/syslog-ng/grok.d") match("%{STRING:field}" tags("string") ) match("%{NUMBER:field}" tags("number") ) ); }; destination d_file { file("/var/log/messages"); }; log { source (s_tcp); parser (p_grok); destination (d_file); }; syslog-ng-incubator-0.6.2/modules/grok/grok-parser-grammar.ym000066400000000000000000000051261326222430700242730ustar00rootroot00000000000000/* * Copyright (c) 2013 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2013 Gergely Nagy * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * As an additional exemption you are allowed to compile & link against the * OpenSSL libraries as published by the OpenSSL project. See the file * COPYING for details. * */ %code requires { #include "grok-parser-parser.h" } %code { #include "cfg-grammar.h" #include "cfg-parser.h" #include "plugin.h" #include "parser/parser-expr.h" #include "grok-parser.h" LogParser *last_parser; GrokInstance *last_grok_instance; } %name-prefix "grok_" %lex-param {CfgLexer *lexer} %parse-param {CfgLexer *lexer} %parse-param {LogParser **instance} %parse-param {gpointer arg} /* INCLUDE_DECLS */ %token KW_GROK %token KW_GROK_MATCH %token KW_GROK_CUSTOM_PATTERN %token KW_GROK_PATTERN_DIRECTORY %type grok_pattern %% start : LL_CONTEXT_PARSER grok_parser { YYACCEPT; } ; grok_parser : KW_GROK '(' { last_parser = *instance = grok_parser_new (configuration); } grok_parser_options ')' ; grok_parser_options : grok_parser_option grok_parser_options | ; grok_parser_option : grok_pattern { grok_parser_add_pattern_instance(last_parser, last_grok_instance); } | KW_GROK_CUSTOM_PATTERN '(' string string ')' { grok_parser_add_named_subpattern(last_parser, $3, $4); free($3); free($4); } | KW_GROK_PATTERN_DIRECTORY '(' string ')' { grok_parser_set_pattern_directory(last_parser, $3); free($3); } ; grok_pattern : KW_GROK_MATCH { last_grok_instance = grok_instance_new(); } '(' string grok_instance_options ')' { grok_instance_set_pattern(last_grok_instance, $4); free($4); } ; grok_instance_options : grok_instance_option grok_instance_options | ; grok_instance_option : KW_TAGS '(' string_list ')' { grok_instance_add_tags(last_grok_instance, $3); } ; /* INCLUDE_RULES */ %% syslog-ng-incubator-0.6.2/modules/grok/grok-parser-parser.c000066400000000000000000000033721326222430700237370ustar00rootroot00000000000000/* * Copyright (c) 2013 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2013 Gergely Nagy * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * As an additional exemption you are allowed to compile & link against the * OpenSSL libraries as published by the OpenSSL project. See the file * COPYING for details. * */ #include "grok-parser.h" #include "cfg-parser.h" #include "grok-parser-grammar.h" #include "grok-parser-parser.h" extern int grok_parser_debug; int grok_parse(CfgLexer *lexer, LogParser **instance, gpointer arg); static CfgLexerKeyword grok_keywords[] = { { "grok", KW_GROK }, { "match", KW_GROK_MATCH }, { "pattern_directory", KW_GROK_PATTERN_DIRECTORY }, { "custom_pattern", KW_GROK_CUSTOM_PATTERN }, { NULL } }; CfgParser grok_parser = { #if ENABLE_DEBUG .debug_flag = &grok_parser_debug, #endif .name = "grok-parser", .keywords = grok_keywords, .parse = (int (*)(CfgLexer *, gpointer *, gpointer)) grok_parse, .cleanup = (void (*)(gpointer)) log_pipe_unref, }; CFG_PARSER_IMPLEMENT_LEXER_BINDING(grok_, LogParser **); syslog-ng-incubator-0.6.2/modules/grok/grok-parser-parser.h000066400000000000000000000023361326222430700237430ustar00rootroot00000000000000/* * Copyright (c) 2013 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2013 Gergely Nagy * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * As an additional exemption you are allowed to compile & link against the * OpenSSL libraries as published by the OpenSSL project. See the file * COPYING for details. * */ #ifndef SNG_TRIGGER_SOURCE_PARSER_H_INCLUDED #define SNG_TRIGGER_SOURCE_PARSER_H_INCLUDED #include "grok-parser.h" #include "cfg-parser.h" #include "cfg-lexer.h" extern CfgParser grok_parser; CFG_PARSER_DECLARE_LEXER_BINDING(grok_, LogParser **) #endif syslog-ng-incubator-0.6.2/modules/grok/grok-parser-plugin.c000066400000000000000000000031121326222430700237310ustar00rootroot00000000000000/* * Copyright (c) 2013 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2013 Gergely Nagy * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * As an additional exemption you are allowed to compile & link against the * OpenSSL libraries as published by the OpenSSL project. See the file * COPYING for details. * */ #include "grok-parser.h" #include "grok-parser-parser.h" #include "plugin.h" #include "plugin-types.h" extern CfgParser grok_parser; static Plugin grok_plugin = { .type = LL_CONTEXT_PARSER, .name = "grok", .parser = &grok_parser, }; gboolean grok_module_init(PluginContext *context, CfgArgs *args G_GNUC_UNUSED) { plugin_register(context, &grok_plugin, 1); return TRUE; } const ModuleInfo module_info = { .canonical_name = "grok", .version = SYSLOG_NG_VERSION, .description = "Experimental grok parser.", .core_revision = VERSION_CURRENT_VER_ONLY, .plugins = &grok_plugin, .plugins_len = 1, }; syslog-ng-incubator-0.6.2/modules/grok/grok-parser.c000066400000000000000000000250041326222430700224410ustar00rootroot00000000000000/* * Copyright (c) 2013 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2013 Gergely Nagy * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * As an additional exemption you are allowed to compile & link against the * OpenSSL libraries as published by the OpenSSL project. See the file * COPYING for details. * */ #include "grok-parser.h" #include #include #include "scratch-buffers.h" #include "string-list.h" #define KEY_BUFFER_LENGTH 1024 struct _GrokInstance { grok_t *grok; char *grok_pattern; char *key_prefix; int key_prefix_len; GList *tags; }; typedef struct _GrokPattern { char *name; char *pattern; } GrokPattern; typedef struct _GrokParser { LogParser super; GList *instances; GList *custom_patterns; char *grok_pattern_dir; char *key_prefix; int key_prefix_len; LogTemplate *template; gboolean debug; } GrokParser; GrokInstance * grok_instance_new(void) { return g_new0(GrokInstance, 1); } void grok_parser_add_named_subpattern(LogParser *parser, const char *name, const char *pattern) { GrokParser *self = (GrokParser *)parser; GrokPattern *grok_pattern = g_new0(GrokPattern, 1); grok_pattern->name = g_strdup(name); grok_pattern->pattern = g_strdup(pattern); self->custom_patterns = g_list_append(self->custom_patterns, grok_pattern); }; void grok_instance_add_tags(GrokInstance *instance, GList *tags) { string_list_free(instance->tags); instance->tags = tags; }; void grok_parser_turn_on_debug(LogParser *parser) { GrokParser *self = (GrokParser *)parser; self->debug = TRUE; } static void grok_instance_pattern_list_foreach(gpointer pattern, gpointer user_data) { GrokPattern *grok_pattern = (GrokPattern *)pattern; GrokInstance *self = (GrokInstance *)user_data; grok_pattern_add(self->grok, grok_pattern->name, strlen(grok_pattern->name), grok_pattern->pattern, strlen(grok_pattern->pattern)); }; static void grok_instance_load_named_subpatterns(GrokInstance *self, GrokParser *parser) { g_list_foreach(parser->custom_patterns, grok_instance_pattern_list_foreach, self); }; void grok_instance_set_pattern(GrokInstance *self, char *pattern) { self->grok_pattern = g_strdup(pattern); }; static void grok_instance_free(gpointer obj) { GrokInstance *self = (GrokInstance *) obj; string_list_free(self->tags); g_free(self->grok_pattern); if (self->grok) { grok_free(self->grok); g_free(self->grok); } }; static void grok_patterns_import_from_directory(GrokInstance *self, GrokParser *parser) { const gchar *fname; if (parser->grok_pattern_dir == NULL) return; GDir *dir = g_dir_open(parser->grok_pattern_dir, 0, NULL); if (!dir) { msg_error("Could not open pattern directory", evt_tag_str("pattern_dir", parser->grok_pattern_dir), NULL); return; } while ((fname = g_dir_read_name(dir))) { gchar *full_name = g_build_filename(parser->grok_pattern_dir, fname, NULL); grok_patterns_import_from_file(self->grok, full_name); g_free(full_name); } g_dir_close(dir); } static gboolean grok_instance_init(GrokInstance *self, GrokParser *parser) { self->grok = g_new0(grok_t, 1); grok_init(self->grok); if (parser->debug) self->grok->logmask = (~0); grok_patterns_import_from_directory(self, parser); grok_instance_load_named_subpatterns(self, parser); if (grok_compile(self->grok, self->grok_pattern) != GROK_OK) { msg_error("Grok pattern compilation failed", evt_tag_str("error", self->grok->errstr), evt_tag_str("pattern", self->grok_pattern),NULL); return FALSE; } self->key_prefix = parser->key_prefix; self->key_prefix_len = parser->key_prefix_len; return TRUE; }; static void _split_and_add_key_prefix(GrokInstance *self, char *key_buffer, char *key, int key_len) { char *key_start = strchr(key, ':'); if (key_start == NULL) key_start = key; else { key_start = key_start + 1; key_len = key_len - (key_start - key); } if (key_len > (KEY_BUFFER_LENGTH - 1) - self->key_prefix_len) key_len = (KEY_BUFFER_LENGTH - 1) - self->key_prefix_len; if (self->key_prefix_len > 0) strncpy(key_buffer, self->key_prefix, self->key_prefix_len); strncpy(key_buffer + self->key_prefix_len, key_start, key_len); key_buffer[key_len + self->key_prefix_len] = '\0'; } static void grok_instance_add_matched_values_to_msg(GrokInstance *self, grok_match_t *match, LogMessage *msg) { char *key, *value; int key_len, value_len; char key_buffer[KEY_BUFFER_LENGTH]; grok_match_walk_init(match); while (grok_match_walk_next(match, &key, &key_len, (const char**) &value, &value_len) == 0) { _split_and_add_key_prefix(self, key_buffer, key, key_len); NVHandle handle = log_msg_get_value_handle(key_buffer); log_msg_set_value(msg, handle, value, value_len); } grok_match_walk_end(match); } static void _add_tag_to_msg(gpointer data, gpointer userdata) { char *tag = (char *) data; LogMessage *msg = (LogMessage *) userdata; log_msg_set_tag_by_name(msg, tag); }; static void grok_instance_add_tags_to_msg(GrokInstance *self, LogMessage *msg) { g_list_foreach(self->tags, _add_tag_to_msg, msg); }; static gboolean grok_instance_match(GrokInstance *self, char* text, LogMessage *msg) { grok_match_t match; int grok_res = grok_exec(self->grok, text, &match); if (grok_res == GROK_OK) { msg_debug("Grok pattern matched!", NULL); grok_instance_add_matched_values_to_msg(self, &match, msg); grok_instance_add_tags_to_msg(self, msg); return TRUE; } else if (grok_res == GROK_ERROR_NOMATCH) { msg_debug("Grok pattern not matched!", NULL); } else if (grok_res == GROK_ERROR_PCRE_ERROR) { msg_debug("Pcre error happened during grok matching!", NULL); } return FALSE; }; static gboolean grok_parser_init(LogPipe *parser) { GrokParser *self = (GrokParser *)parser; GlobalConfig *cfg = log_pipe_get_config(&self->super.super); if (self->key_prefix != NULL) self->key_prefix_len = strlen(self->key_prefix); if (!self->template) { self->template = log_template_new(cfg, "default_grok_template"); log_template_compile(self->template, "$MESSAGE", NULL); } g_list_foreach(self->instances, (GFunc) grok_instance_init, self); return TRUE; }; void grok_parser_set_pattern_directory(LogParser *s, gchar *pattern_directory) { GrokParser *self = (GrokParser *)s; if (self->grok_pattern_dir) g_free(self->grok_pattern_dir); self->grok_pattern_dir = g_strdup(pattern_directory); } void grok_parser_add_pattern_instance(LogParser *s, GrokInstance *instance) { GrokParser *self = (GrokParser *)s; self->instances = g_list_append(self->instances, instance); }; static gboolean grok_parser_process(LogParser *s, LogMessage **pmsg, const LogPathOptions *path_options, const char *input, gsize input_len) { LogMessage *msg = *pmsg; GString *str; GList *instance; LogTemplateOptions template_options; GrokParser *self = (GrokParser *)s; str = g_string_new(""); log_template_options_defaults(&template_options); log_template_format(self->template, msg, &template_options, 0, 0, NULL, str); instance = self->instances; while (instance && !(grok_instance_match(instance->data, str->str, msg))) { instance = instance->next; } g_string_free(str, TRUE); return TRUE; }; static GList* _clone_list(GList* list, gpointer(*item_cloner)(gpointer)); static gpointer grok_custom_pattern_clone(gpointer obj) { GrokPattern *pattern = (GrokPattern *) obj; GrokPattern *cloned_pattern = g_new0(GrokPattern, 1); cloned_pattern->name = g_strdup(pattern->name); cloned_pattern->pattern = g_strdup(pattern->pattern); return (gpointer) cloned_pattern; }; static gpointer grok_instance_clone(gpointer obj) { GrokInstance *instance = (GrokInstance *) obj; GrokInstance *cloned = g_new0(GrokInstance, 1); cloned->grok_pattern = g_strdup(instance->grok_pattern); cloned->tags = _clone_list(instance->tags, g_strdup); return (gpointer) cloned; }; static GList* _clone_list(GList* list, gpointer(*item_cloner)(gpointer)) { GList *result = NULL; GList *p; for (p = list; p; p = p->next) { result = g_list_append(result, item_cloner(p->data)); } return result; } static GList * grok_parser_clone_instances(GrokParser *self) { return _clone_list(self->instances, grok_instance_clone); }; static GList * grok_parser_clone_custom_patterns(GrokParser *self) { return _clone_list(self->custom_patterns, grok_custom_pattern_clone); }; static LogPipe * grok_parser_clone(LogPipe *s) { GrokParser *self = (GrokParser *)s; GrokParser *cloned = (GrokParser *) grok_parser_new(log_pipe_get_config(&self->super.super)); cloned->instances = grok_parser_clone_instances(self); cloned->custom_patterns = grok_parser_clone_custom_patterns(self); cloned->template = log_template_ref(self->template); cloned->key_prefix = g_strndup(self->key_prefix, self->key_prefix_len); cloned->key_prefix_len = self->key_prefix_len; cloned->grok_pattern_dir = g_strdup(self->grok_pattern_dir); return &cloned->super.super; }; static void grok_pattern_free(gpointer obj) { GrokPattern *self = (GrokPattern *) obj; g_free(self->name); g_free(self->pattern); g_free(self); }; static void grok_parser_free(LogPipe *s) { GrokParser *self = (GrokParser *)s; g_list_free_full(self->instances, grok_instance_free); g_list_free_full(self->custom_patterns, grok_pattern_free); g_free(self->key_prefix); log_template_unref(self->template); g_free(self->grok_pattern_dir); log_parser_free_method(s); }; LogParser *grok_parser_new(GlobalConfig *cfg) { GrokParser *self = g_new0(GrokParser, 1); log_parser_init_instance(&self->super, cfg); self->super.super.init = grok_parser_init; self->super.process = grok_parser_process; self->super.super.clone = grok_parser_clone; self->super.super.free_fn = grok_parser_free; return &self->super; }; syslog-ng-incubator-0.6.2/modules/grok/grok-parser.h000066400000000000000000000032771326222430700224560ustar00rootroot00000000000000/* * Copyright (c) 2013 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2013 Gergely Nagy * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * As an additional exemption you are allowed to compile & link against the * OpenSSL libraries as published by the OpenSSL project. See the file * COPYING for details. * */ #ifndef SNG_TRIGGER_SOURCE_H_INCLUDED #define SNG_TRIGGER_SOURCE_H_INCLUDED #include "parser/parser-expr.h" typedef struct _GrokInstance GrokInstance; GrokInstance *grok_instance_new(void); LogParser *grok_parser_new(GlobalConfig *cfg); void grok_instance_set_pattern (GrokInstance *s, gchar *pattern); void grok_instance_add_tags (GrokInstance *s, GList *tags); void grok_parser_add_named_subpattern(LogParser *self, const char *name, const char *pattern); void grok_parser_set_pattern_directory(LogParser *s, gchar *pattern_directory); void grok_parser_set_key_prefix(LogParser *s, gchar *key_prefix); void grok_parser_add_pattern_instance(LogParser *s, GrokInstance *instance); void grok_parser_turn_on_debug(LogParser *s); #endif syslog-ng-incubator-0.6.2/modules/grok/tests/000077500000000000000000000000001326222430700212025ustar00rootroot00000000000000syslog-ng-incubator-0.6.2/modules/grok/tests/Makefile.am000066400000000000000000000004611326222430700232370ustar00rootroot00000000000000modules_grok_tests_TESTS = \ modules/grok/tests/test_grok check_PROGRAMS += \ ${modules_grok_tests_TESTS} modules_grok_tests_test_grok_CFLAGS = \ $(INCUBATOR_CFLAGS) modules_grok_tests_test_grok_LDADD = \ $(INCUBATOR_TEST_LDADD) $(INCUBATOR_LIBS) \ $(top_builddir)/modules/grok/libgrok-parser.la syslog-ng-incubator-0.6.2/modules/grok/tests/test_grok.c000066400000000000000000000064041326222430700233530ustar00rootroot00000000000000#include "modules/grok/grok-parser.h" #include #include GrokInstance *grok_instance_new(); LogParser* create_simple_parser() { GlobalConfig *cfg = cfg_new(0x0); LogParser *parser = grok_parser_new(cfg); grok_parser_turn_on_debug(parser); grok_parser_add_named_subpattern(parser, "STRING", "[a-zA-Z]+"); grok_parser_add_named_subpattern(parser, "NUMBER", "[0-9]+"); return parser; }; LogMessage * create_message_with_fields(const char *field_name, ...) { va_list args; const char* arg; LogMessage *msg = log_msg_new_empty(); arg = field_name; va_start(args, field_name); while (arg != NULL) { NVHandle handle = log_msg_get_value_handle(arg); arg = va_arg(args, char*); log_msg_set_value(msg, handle, arg, -1); arg = va_arg(args, char*); } va_end(args); return msg; } void parse_msg_with_defaults(LogParser *parser, LogMessage *msg) { LogPathOptions options; log_pipe_init(&parser->super); log_parser_process(parser, &msg, &options, NULL, 0); log_pipe_deinit(&parser->super); } void create_and_add_grok_instance_with_pattern(LogParser *parser, char* pattern) { GrokInstance *instance = (GrokInstance*) grok_instance_new(); grok_instance_set_pattern(instance, pattern); grok_parser_add_pattern_instance(parser, instance); }; void test_grok_pattern_single() { LogParser *parser = create_simple_parser(); create_and_add_grok_instance_with_pattern(parser, "%{STRING:field}"); LogMessage *msg = create_message_with_fields("MESSAGE", "value", NULL); parse_msg_with_defaults(parser, msg); NVHandle field = log_msg_get_value_handle("field"); gssize value_len; const gchar *value = log_msg_get_value(msg, field, &value_len); assert_nstring(value, value_len, "value", 5, "Named capture didn't stored"); log_pipe_unref(&parser->super); } void test_grok_pattern_multiple() { LogParser *parser = create_simple_parser(); create_and_add_grok_instance_with_pattern(parser, "%{STRING:field}"); create_and_add_grok_instance_with_pattern(parser, "%{NUMBER:field2}"); LogMessage *msg = create_message_with_fields("MESSAGE", "123", NULL); parse_msg_with_defaults(parser, msg); NVHandle field = log_msg_get_value_handle("field2"); gssize value_len; const gchar *value = log_msg_get_value(msg, field, &value_len); assert_nstring(value, value_len, "123", 3, "Named capture didn't stored"); log_pipe_unref(&parser->super); } void test_grok_parser_clone() { LogParser *old_parser = create_simple_parser(); create_and_add_grok_instance_with_pattern(old_parser, "%{STRING:field}"); LogParser *parser = (LogParser*) log_pipe_clone(&old_parser->super); LogMessage *msg = create_message_with_fields("MESSAGE", "value", NULL); parse_msg_with_defaults(parser, msg); NVHandle field = log_msg_get_value_handle("field"); gssize value_len; const gchar *value = log_msg_get_value(msg, field, &value_len); assert_nstring(value, value_len, "value", 5, "Named capture didn't stored"); log_pipe_unref(&old_parser->super); log_pipe_unref(&parser->super); }; int main() { app_startup(); test_grok_pattern_single(); test_grok_pattern_multiple(); test_grok_parser_clone(); app_shutdown(); return 0; }; syslog-ng-incubator-0.6.2/modules/kafka-c/000077500000000000000000000000001326222430700203735ustar00rootroot00000000000000syslog-ng-incubator-0.6.2/modules/kafka-c/Makefile.am000066400000000000000000000017111326222430700224270ustar00rootroot00000000000000if ENABLE_KAFKA module_LTLIBRARIES += \ modules/kafka-c/libkafka-c.la modules_kafka_c_libkafka_c_la_CFLAGS = \ $(RDKAFKA_CFLAGS) \ $(INCUBATOR_CFLAGS) \ -I$(top_srcdir)/modules/kafka-c \ -I$(top_builddir)/modules/kafka-c modules_kafka_c_libkafka_c_la_SOURCES = \ modules/kafka-c/kafka-grammar.y \ modules/kafka-c/kafka.c \ modules/kafka-c/kafka.h \ modules/kafka-c/kafka-parser.h \ modules/kafka-c/kafka-parser.c modules_kafka_c_libkafka_c_la_LIBADD = \ $(RDKAFKA_LIBS) $(INCUBATOR_LIBS) modules_kafka_c_libkafka_c_la_LDFLAGS = \ -avoid-version -module -no-undefined modules/kafka-c modules/kafka-c/ mod-kafka-c: \ modules/kafka-c/libkafka-c.la else modules/kafka-c modules/kafka-c/ mod-kafka-c: endif BUILT_SOURCES += \ modules/kafka-c/kafka-grammar.y \ modules/kafka-c/kafka-grammar.c \ modules/kafka-c/kafka-grammar.h EXTRA_DIST += \ modules/kafka-c/kafka-grammar.ym .PHONY: modules/kafka-c/ mod-kafka-c syslog-ng-incubator-0.6.2/modules/kafka-c/README.md000066400000000000000000000032651326222430700216600ustar00rootroot00000000000000Kafka destination ================= Here is a simple configuration sending the messages on a dedicated Kafka queue (`syslog-ng`) using Logstash's JSON event layout: ``` source s_system { system(); }; destination d_kafka { channel { rewrite { set("${HOST}" value(".eventv1.host")); set("1" value(".eventv1.@version")); set("${ISODATE}" value(".eventv1.@timestamp") condition("${.eventv1.@timestamp}" eq "")); set("${MESSAGE}" value(".eventv1.message") condition("${.eventv1.message}" eq "")); set("${MSG}" value(".eventv1.message") condition("${.eventv1.message}" eq "")); set("generic" value(".eventv1.type") condition("${.eventv1.type}" eq "")); }; destination { kafka-c(properties(metadata.broker.list("localhost:9092") queue.buffering.max.ms("1000")) topic("syslog-ng") payload("$(format-json --key .eventv1.* --rekey .eventv1.* --shift 9)")); }; }; }; log { source(s_system); destination(d_kafka); }; ``` Compilation ----------- You need [librdkafka](https://github.com/edenhill/librdkafka/). Once installed, compile with `--with-librdkafka`. Running Kafka ------------- If you are not too familiar with Kafka, a simple recipe using [Docker](http://docker.io) can get you started in a minute: ``` git clone https://github.com/spotify/docker-kafka docker build -t spotify/kafka docker-kafka/kafka docker run -e HELIOS_PORT_kafka=vcap.me:9092 -p 2181:2181 -p 9092:9092 spotify/kafka ``` Another useful tool is [kafkacat](https://github.com/edenhill/kafkacat). For example, to look at logs sent to Kafka, use: ``` kafkacat -C -u -b localhost -t syslog-ng ``` syslog-ng-incubator-0.6.2/modules/kafka-c/kafka-grammar.ym000066400000000000000000000064051326222430700234500ustar00rootroot00000000000000/* * Copyright (c) 2013 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2013 Tihamer Petrovics * Copyright (c) 2014 Pierre-Yves Ritschard * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * As an additional exemption you are allowed to compile & link against the * OpenSSL libraries as published by the OpenSSL project. See the file * COPYING for details. * */ %code requires { #include "kafka-parser.h" } %code { #include "cfg-grammar.h" #include "plugin.h" extern GList *last_property; } %name-prefix "kafka_c_" %lex-param {CfgLexer *lexer} %parse-param {CfgLexer *lexer} %parse-param {LogDriver **instance} %parse-param {gpointer arg} /* INCLUDE_DECLS */ %token KW_KAFKA_C %token KW_TOPIC %token KW_PROP %token KW_PAYLOAD %token KW_PARTITION %token KW_RANDOM %token KW_FIELD %token KW_FLAGS %token KW_SYNC %% start : LL_CONTEXT_DESTINATION KW_KAFKA_C { last_driver = *instance = kafka_dd_new(configuration); last_property = NULL; } '(' kafka_options ')' { YYACCEPT; } ; kafka_options : kafka_option kafka_options | ; kafka_option : KW_TOPIC '(' string kafka_properties ')' { kafka_dd_set_topic(last_driver, $3, last_property); free($3); last_property = NULL; } | KW_PARTITION '(' KW_RANDOM ')' { kafka_dd_set_partition_random(last_driver); } | KW_PARTITION '(' template_content ')' { kafka_dd_set_partition_field(last_driver, $3); } | KW_PROP '(' kafka_properties ')' { kafka_dd_set_props(last_driver, last_property); last_property = NULL; } | KW_FLAGS '(' kafka_flags ')' | KW_PAYLOAD '(' template_content ')' { kafka_dd_set_payload(last_driver, $3); } | dest_driver_option | { last_template_options = kafka_dd_get_template_options(last_driver); } template_option ; kafka_properties : kafka_property kafka_properties | ; kafka_property : string '(' string ')' { struct kafka_property *prop = g_new0(struct kafka_property, 1); prop->key = g_strdup($1); prop->val = g_strdup($3); last_property = g_list_append(last_property, prop); free($1); free($3); } ; kafka_flags : kafka_flag kafka_flags | ; kafka_flag : KW_SYNC { kafka_dd_set_flag_sync(last_driver); } ; /* INCLUDE_RULES */ %% syslog-ng-incubator-0.6.2/modules/kafka-c/kafka-parser.c000066400000000000000000000034041326222430700231070ustar00rootroot00000000000000/* * Copyright (c) 2014 Pierre-Yves Ritschard * * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * As an additional exemption you are allowed to compile & link against the * OpenSSL libraries as published by the OpenSSL project. See the file * COPYING for details. * */ #include "kafka.h" #include "cfg-parser.h" #include "kafka-grammar.h" extern int kafka_debug; int kafka_c_parse(CfgLexer *lexer, LogDriver **instance, gpointer arg); static CfgLexerKeyword kafka_keywords[] = { { "field", KW_FIELD }, { "kafka_c", KW_KAFKA_C }, { "partition", KW_PARTITION }, { "payload", KW_PAYLOAD }, { "properties", KW_PROP }, { "random", KW_RANDOM }, { "topic", KW_TOPIC }, { "sync", KW_SYNC }, { NULL } }; CfgParser kafka_c_parser = { #if ENABLE_DEBUG .debug_flag = &kafka_debug, #endif .name = "kafka-c", .keywords = kafka_keywords, .parse = (int (*)(CfgLexer *lexer, gpointer *instance, gpointer)) kafka_c_parse, .cleanup = (void (*)(gpointer)) log_pipe_unref, }; CFG_PARSER_IMPLEMENT_LEXER_BINDING(kafka_c_, LogDriver **) syslog-ng-incubator-0.6.2/modules/kafka-c/kafka-parser.h000066400000000000000000000023611326222430700231150ustar00rootroot00000000000000/* * Copyright (c) 2014 Pierre-Yves Ritschard * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * As an additional exemption you are allowed to compile & link against the * OpenSSL libraries as published by the OpenSSL project. See the file * COPYING for details. * */ #ifndef KAFKA_PARSER_H_INCLUDED #define KAFKA_PARSER_H_INCLUDED #include "cfg-parser.h" #include "cfg-lexer.h" #include "kafka.h" extern CfgParser kafka_c_parser; struct kafka_property { gchar *key; gchar *val; }; void kafka_property_free(void *); CFG_PARSER_DECLARE_LEXER_BINDING(kafka_c_, LogDriver **) #endif syslog-ng-incubator-0.6.2/modules/kafka-c/kafka.c000066400000000000000000000351021326222430700216150ustar00rootroot00000000000000/* * Copyright (c) 2013 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2013 Tihamer Petrovics * Copyright (c) 2014 Pierre-Yves Ritschard * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * As an additional exemption you are allowed to compile & link against the * OpenSSL libraries as published by the OpenSSL project. See the file * COPYING for details. * */ #include #include #include #include "kafka.h" #include "kafka-parser.h" #include "plugin.h" #include "messages.h" #include "stats/stats.h" #include "logqueue.h" #include "driver.h" #include "plugin-types.h" #include "logthrdestdrv.h" #include "seqnum.h" /* * This module draws from the redis module and provides an Apache Kafka * output. Please refer to http://kafka.apache.org for details on the * kafka distributed queue. * * This module accepts the following options: * - _properties_, mandatory. Sets global properties, you will need at least * "metadata.broker.list" set * - _topic_, mandatory. Expects a named topic and optional associated * metadata such as the number of partitions * - _payload_, mandatory. A template to describe payload content * - _partition_, optional. Describes the partitioning method for the topic. * a random partition is assigned by default. Accepts the following arguments: * "random" for random partitions any other string to use the checksum of a * message template. */ #ifndef SCS_KAFKA #define SCS_KAFKA 0 #endif GList *last_property = NULL; #define KAFKA_FLAG_NONE 0 #define KAFKA_FLAG_SYNC 0x0001 typedef struct { LogThrDestDriver super; gchar *topic_name; gchar *key_str; LogTemplate *field; LogTemplateOptions template_options; LogTemplateOptions field_template_options; GString *payload_str; LogTemplate *payload; gint32 flags; gint32 seq_num; rd_kafka_topic_t *topic; rd_kafka_t *kafka; enum { PARTITION_RANDOM = 0, PARTITION_FIELD = 1 } partition_type; } KafkaDriver; void kafka_log(const rd_kafka_t *rkt, int level, const char *fac, const char *msg) { msg_event_suppress_recursions_and_send( msg_event_create(level, "Kafka internal message", evt_tag_str("msg", msg), NULL )); } void kafka_property_free(void *p) { struct kafka_property *kp = p; g_free(kp->key); g_free(kp->val); g_free(kp); } int32_t kafka_partition(const rd_kafka_topic_t *rkt, const void *keydata, size_t keylen, int32_t partition_cnt, void *rktp, void *msgp) { u_int32_t key = *((u_int32_t *)keydata); u_int32_t target = key % partition_cnt; int32_t i = partition_cnt; while (--i > 0 && !rd_kafka_topic_partition_available(rkt, target)) { target = (target + 1) % partition_cnt; } return target; } static void kafka_worker_sync_produce_dr_cb(rd_kafka_t *rk, void *payload, size_t len, rd_kafka_resp_err_t err, void *opaque, void *msg_opaque) { /* When done, just copy error code */ rd_kafka_resp_err_t *errp = (rd_kafka_resp_err_t *)msg_opaque; *errp = err; } /* * Configuration */ void kafka_dd_set_props(LogDriver *d, GList *props) { KafkaDriver *self = (KafkaDriver *)d; GList *list; struct kafka_property *kp; rd_kafka_conf_t *conf; char errbuf[1024]; bzero(errbuf, sizeof(errbuf)); conf = rd_kafka_conf_new(); for (list = g_list_first(props); list != NULL; list = g_list_next(list)) { kp = list->data; msg_debug("setting kafka property", evt_tag_str("key", kp->key), evt_tag_str("val", kp->val), NULL); rd_kafka_conf_set(conf, kp->key, kp->val, errbuf, sizeof(errbuf)); } #ifdef HAVE_LIBRDKAFKA_LOG_CB rd_kafka_conf_set_log_cb(conf, kafka_log); #endif if (self->flags & KAFKA_FLAG_SYNC) { msg_info("synchronous insertion into kafka, " "lower the value of queue.buffering.max.ms to increase performance", evt_tag_str("driver", self->super.super.super.id), NULL); rd_kafka_conf_set_dr_cb(conf, kafka_worker_sync_produce_dr_cb); } self->kafka = rd_kafka_new(RD_KAFKA_PRODUCER, conf, errbuf, sizeof(errbuf)); #ifdef HAVE_LIBRDKAFKA_LOGGER if (self->kafka != NULL) { rd_kafka_set_logger(self->kafka, kafka_log); } #endif } void kafka_dd_set_partition_random(LogDriver *d) { KafkaDriver *self = (KafkaDriver *)d; self->partition_type = PARTITION_RANDOM; } void kafka_dd_set_partition_field(LogDriver *d, LogTemplate *field) { KafkaDriver *self = (KafkaDriver *)d; self->partition_type = PARTITION_FIELD; log_template_unref(self->field); self->field = log_template_ref(field); } void kafka_dd_set_flag_sync(LogDriver *d) { KafkaDriver *self = (KafkaDriver *)d; if (self->kafka != NULL) { msg_error("kafka flags must be set before kafka properties", NULL); return; } self->flags |= KAFKA_FLAG_SYNC; } void kafka_dd_set_topic(LogDriver *d, const gchar *topic, GList *props) { KafkaDriver *self = (KafkaDriver *)d; GList *list; struct kafka_property *kp; rd_kafka_topic_conf_t *topic_conf; char errbuf[1024]; if (self->kafka == NULL) { msg_error("kafka topic must be set after kafka properties", NULL); return; } topic_conf = rd_kafka_topic_conf_new(); for (list = g_list_first(props); list != NULL; list = g_list_next(list)) { kp = list->data; msg_debug("setting kafka topic property", evt_tag_str("key", kp->key), evt_tag_str("val", kp->val), NULL); rd_kafka_topic_conf_set(topic_conf, kp->key, kp->val, errbuf, sizeof(errbuf)); } rd_kafka_topic_conf_set_partitioner_cb(topic_conf, kafka_partition); rd_kafka_topic_conf_set_opaque(topic_conf, self); self->topic_name = g_strdup(topic); self->topic = rd_kafka_topic_new(self->kafka, topic, topic_conf); } void kafka_dd_set_payload(LogDriver *d, LogTemplate *payload) { KafkaDriver *self = (KafkaDriver *)d; log_template_unref(self->payload); self->payload = log_template_ref(payload); } /* * Utilities */ LogTemplateOptions * kafka_dd_get_template_options(LogDriver *d) { KafkaDriver *self = (KafkaDriver *)d; return &self->template_options; } static gchar * kafka_dd_format_stats_instance(LogThrDestDriver *d) { KafkaDriver *self = (KafkaDriver *)d; static gchar persist_name[1024]; if (d->super.super.super.persist_name) g_snprintf(persist_name, sizeof(persist_name), "kafka,%s", d->super.super.super.persist_name); else g_snprintf(persist_name, sizeof(persist_name), "kafka,%s", self->topic_name); return persist_name; } static const gchar * kafka_dd_format_persist_name(const LogPipe *d) { const KafkaDriver *self = (const KafkaDriver *)d; static gchar persist_name[1024]; if (d->persist_name) g_snprintf(persist_name, sizeof(persist_name), "kafka.%s", d->persist_name); else g_snprintf(persist_name, sizeof(persist_name), "kafka(%s)", self->topic_name); return persist_name; } static u_int32_t kafka_calculate_partition_key(KafkaDriver *self, LogMessage *msg) { u_int32_t key; GString *field = g_string_sized_new(1024); log_template_format(self->field, msg, &self->field_template_options, LTZ_SEND, self->seq_num, NULL, field); msg_debug("Kafka dynamic key", evt_tag_str("key", field->str), evt_tag_str("driver", self->super.super.super.id), NULL); key = crc32(0L, Z_NULL, 0); key = crc32(key, (const u_char *)field->str, field->len); msg_debug("Kafka field crc32", evt_tag_str("payload", field->str), evt_tag_int("length", field->len), evt_tag_int("crc32", key), evt_tag_str("driver", self->super.super.super.id), NULL); g_string_free(field, TRUE); return key; } /* * Worker thread */ static worker_insert_result_t kafka_worker_insert(LogThrDestDriver *s, LogMessage *msg) { KafkaDriver *self = (KafkaDriver *)s; gboolean success; LogPathOptions path_options = LOG_PATH_OPTIONS_INIT; GString *field; u_int32_t key; log_template_format(self->payload, msg, &self->template_options, LTZ_SEND, self->seq_num, NULL, self->payload_str); switch (self->partition_type) { case PARTITION_RANDOM: key = rand(); break; case PARTITION_FIELD: key = kafka_calculate_partition_key(self, msg); break; default: key = 0; } #define KAFKA_INITIAL_ERROR_CODE -12345 rd_kafka_resp_err_t err = KAFKA_INITIAL_ERROR_CODE; if (rd_kafka_produce(self->topic, RD_KAFKA_PARTITION_UA, RD_KAFKA_MSG_F_COPY, self->payload_str->str, self->payload_str->len, &key, sizeof(key), &err) == -1) { msg_error("Failed to add message to Kafka topic!", evt_tag_str("driver", self->super.super.super.id), evt_tag_str("topic", self->topic_name), evt_tag_str("error", rd_kafka_err2str(rd_kafka_errno2err(errno))), NULL); return WORKER_INSERT_RESULT_ERROR; } msg_debug("Kafka produce done", evt_tag_str("driver", self->super.super.super.id), NULL); /* Wait for completion. */ if (self->flags & KAFKA_FLAG_SYNC) { while (err == KAFKA_INITIAL_ERROR_CODE) { rd_kafka_poll(self->kafka, 5000); if (err == KAFKA_INITIAL_ERROR_CODE) { msg_debug("Kafka producer is freezed", evt_tag_str("driver", self->super.super.super.id), evt_tag_str("topic", self->topic_name), NULL); } } if (err != RD_KAFKA_RESP_ERR_NO_ERROR) { msg_error("Failed to add message to Kafka topic!", evt_tag_str("driver", self->super.super.super.id), evt_tag_str("topic", self->topic_name), evt_tag_str("error", rd_kafka_err2str(err)), NULL); return WORKER_INSERT_RESULT_ERROR; } } msg_debug("Kafka event sent", evt_tag_str("driver", self->super.super.super.id), evt_tag_str("topic", self->topic_name), evt_tag_str("payload", self->payload_str->str), NULL); return WORKER_INSERT_RESULT_SUCCESS; } static void kafka_worker_thread_init(LogThrDestDriver *d) { KafkaDriver *self = (KafkaDriver *)d; msg_debug("Worker thread started", evt_tag_str("driver", self->super.super.super.id), NULL); self->payload_str = g_string_sized_new(1024); } static void kafka_worker_thread_deinit(LogThrDestDriver *d) { KafkaDriver *self = (KafkaDriver *)d; g_string_free(self->payload_str, TRUE); } /* * Main thread */ static gboolean kafka_dd_init(LogPipe *s) { KafkaDriver *self = (KafkaDriver *)s; GlobalConfig *cfg = log_pipe_get_config(s); if (!log_dest_driver_init_method(s)) return FALSE; log_template_options_init(&self->template_options, cfg); log_template_options_init(&self->field_template_options, cfg); msg_verbose("Initializing Kafka destination", evt_tag_str("driver", self->super.super.super.id), NULL); if (self->topic == NULL) { msg_error("Kafka producer is not set up properly, topic name is missing", evt_tag_str("driver", self->super.super.super.id), NULL); return FALSE; } if (self->payload == NULL) { self->payload = log_template_new(cfg, "default_kafka_template"); log_template_compile(self->payload, "$MESSAGE", NULL); } if (self->kafka == NULL) { msg_error("Kafka producer is not set up properly, perhaps metadata.broker.list property is missing?", evt_tag_str("driver", self->super.super.super.id), NULL); return FALSE; } return log_threaded_dest_driver_start(s); } static void kafka_dd_free(LogPipe *d) { KafkaDriver *self = (KafkaDriver *)d; log_template_options_destroy(&self->template_options); log_template_options_destroy(&self->field_template_options); log_template_unref(self->payload); if (self->topic) rd_kafka_topic_destroy(self->topic); if (self->kafka) rd_kafka_destroy(self->kafka); if (self->topic_name) g_free(self->topic_name); log_threaded_dest_driver_free(d); } /* * Plugin glue. */ LogDriver * kafka_dd_new(GlobalConfig *cfg) { KafkaDriver *self = g_new0(KafkaDriver, 1); log_threaded_dest_driver_init_instance(&self->super, cfg); self->super.super.super.super.init = kafka_dd_init; self->super.super.super.super.free_fn = kafka_dd_free; self->super.super.super.super.generate_persist_name = kafka_dd_format_persist_name; self->super.worker.thread_init = kafka_worker_thread_init; self->super.worker.thread_deinit = kafka_worker_thread_deinit; self->super.worker.insert = kafka_worker_insert; self->super.format.stats_instance = kafka_dd_format_stats_instance; self->super.stats_source = SCS_KAFKA; self->flags = KAFKA_FLAG_NONE; init_sequence_number(&self->seq_num); log_template_options_defaults(&self->template_options); log_template_options_defaults(&self->field_template_options); return (LogDriver *)self; } extern CfgParser kafka_c_parser; static Plugin kafka_plugin = { .type = LL_CONTEXT_DESTINATION, .name = "kafka-c", .parser = &kafka_c_parser, }; gboolean kafka_c_module_init(PluginContext *context, CfgArgs *args) { plugin_register(context, &kafka_plugin, 1); return TRUE; } const ModuleInfo module_info = { .canonical_name = "kafka-c", .version = SYSLOG_NG_VERSION, .description = "The kafka-c module provides Kafka destination support for syslog-ng.", .core_revision = VERSION_CURRENT_VER_ONLY, .plugins = &kafka_plugin, .plugins_len = 1, }; syslog-ng-incubator-0.6.2/modules/kafka-c/kafka.h000066400000000000000000000027571326222430700216340ustar00rootroot00000000000000/* * Copyright (c) 2014 Pierre-Yves Ritschard * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * As an additional exemption you are allowed to compile & link against the * OpenSSL libraries as published by the OpenSSL project. See the file * COPYING for details. * */ #ifndef KAFKA_H_INCLUDED #define KAFKA_H_INCLUDED #include "driver.h" LogDriver *kafka_dd_new(GlobalConfig *cfg); void kafka_dd_set_partition_field(LogDriver *d, LogTemplate *key_field); void kafka_dd_set_partition_random(LogDriver *d); void kafka_dd_set_props(LogDriver *d, GList *props); void kafka_dd_set_topic(LogDriver *d, const gchar *topic, GList *props); void kafka_dd_set_payload(LogDriver *d, LogTemplate *payload); void kafka_dd_set_flag_sync(LogDriver *d); LogTemplateOptions *kafka_dd_get_template_options(LogDriver *d); void kafka_property_free(void *p); #endif syslog-ng-incubator-0.6.2/modules/lua/000077500000000000000000000000001326222430700176575ustar00rootroot00000000000000syslog-ng-incubator-0.6.2/modules/lua/Makefile.am000066400000000000000000000027641326222430700217240ustar00rootroot00000000000000if ENABLE_LUA module_LTLIBRARIES += modules/lua/liblua.la noinst_LTLIBRARIES = modules/lua/libluautil.la modules_lua_liblua_la_CFLAGS = \ $(LUA_CFLAGS) \ $(INCUBATOR_CFLAGS) \ -I$(top_srcdir)/modules/lua \ -I$(top_builddir)/modules/lua modules_lua_libluautil_la_CFLAGS = \ $(LUA_CFLAGS) \ $(INCUBATOR_CFLAGS) \ -I$(top_srcdir)/modules/lua \ -I$(top_builddir)/modules/lua modules_lua_libluautil_la_SOURCES = \ modules/lua/lua-msg.h \ modules/lua/lua-msg.c \ modules/lua/lua-utils.h \ modules/lua/lua-utils.c \ modules/lua/lua-template.h \ modules/lua/lua-template.c modules_lua_libluautil_la_LIBADD = \ $(LUA_LIBS) \ $(INCUBATOR_LIBS) modules_lua_liblua_la_SOURCES = \ modules/lua/lua-grammar.y \ modules/lua/lua-dest.c \ modules/lua/lua-dest.h \ modules/lua/lua-parser.c \ modules/lua/lua-parser.h \ modules/lua/lua-plugin.c modules_lua_liblua_la_LIBADD = \ $(LUA_LIBS) \ $(INCUBATOR_LIBS) modules/lua/libluautil.la modules_lua_liblua_la_LDFLAGS = \ -avoid-version -module -no-undefined BUILT_SOURCES += \ modules/lua/lua-grammar.y \ modules/lua/lua-grammar.c \ modules/lua/lua-grammar.h modules/lua mod-lua: modules/lua/liblua.la else modules/lua mod-lua: endif EXTRA_DIST += \ modules/lua/lua-grammar.ym \ modules/lua/lua-example.conf \ modules/lua/lua-example.lua \ modules/lua/elasticsearch.conf \ modules/lua/elasticsearch.lua .PHONY: modules/lua mod-lua syslog-ng-incubator-0.6.2/modules/lua/elasticsearch.conf000066400000000000000000000007751326222430700233510ustar00rootroot00000000000000@version:3.6 source s_test { tcp(port(12345)); }; destination d_lua { lua( script("elasticsearch.lua") template("$(format_json --scope nv_pairs --key PROGRAM --pair @timestamp=\"${R_ISODATE}\" --pair @message=\"${MSG}\")") init-func("elastic_init") queue-func("elastic_queue") globals( es_batch_size(int(100)) es_host("localhost") es_port("9200") es_index("syslog-ng") es_type("message") ) ); }; log { source(s_test); destination(d_lua); }; syslog-ng-incubator-0.6.2/modules/lua/elasticsearch.lua000066400000000000000000000043601326222430700231770ustar00rootroot00000000000000--[[ elasticsearch.lua -- A simple ElasticSearch destination for syslog-ng Copyright (c) 2014 BalaBit IT Ltd, Budapest, Hungary Copyright (c) 2014 Viktor Tusa Copyright (c) 2014 Gergely Nagy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA As an additional exemption you are allowed to compile & link against the OpenSSL libraries as published by the OpenSSL project. See the file COPYING for details. --]] -- -- Use this table to configure the destination -- es_batch_size = 100 es_host = "localhost" es_port = "9200" es_index = "syslog-ng" es_type = "message" function elastic_request(config, ep, req) req = req .. "\n" local request_len = tostring(#req) local result, respcode, respheaders, respstatus = http.request { url = "http://" .. es_host .. ":" .. es_port .. ep .. "/_bulk", source = ltn12.source.string(req), headers = { ["Content-Type"] = "application/json", ["Content-Length"] = request_len, ["Connection"] = "close" }, method = "POST", sink = ltn12.sink.table(respbody) } end function elastic_queue(msg) request = request .. '\n{"create":null}\n' .. msg msgcount = msgcount + 1 if (msgcount % es_batch_size) == 0 then request_len = tostring(#request) -- print ("Sending msgs, bytes=" .. request_len .. "; count="..tostring(msgcount)) elastic_request(config, "/" .. es_index .. "/" .. es_type, request) request = "" end end function elastic_init() http = require 'socket.http' msgcount = 1 request = "" http.TIMEOUT = 0 end syslog-ng-incubator-0.6.2/modules/lua/lua-dest.c000066400000000000000000000352371326222430700215530ustar00rootroot00000000000000/* * Copyright (c) 2013, 2014 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2013, 2014 Viktor Tusa * Copyright (c) 2014 Gergely Nagy * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * As an additional exemption you are allowed to compile & link against the * OpenSSL libraries as published by the OpenSSL project. See the file * COPYING for details. * */ #include "lua-dest.h" #include "lua-msg.h" #include "lua-template.h" #include "lua-utils.h" #include "messages.h" #include #include #include "scratch-buffers.h" #define LUA_DEST_MODE_RAW 1 #define LUA_DEST_MODE_FORMATTED 2 #ifndef SCS_LUA #define SCS_LUA 0 #endif typedef struct _LuaGlobalConstant { char *name; char *value; TypeHint type; } LuaGlobalConstant; static void lua_global_constant_free(LuaGlobalConstant *self) { g_free(self->name); g_free(self->value); g_free(self); }; static gboolean lua_dd_load_file(LuaDestDriver *self) { if (luaL_loadfile(self->state, self->filename) || lua_pcall(self->state, 0,0,0) ) { msg_error("Error parsing lua script file for lua destination", evt_tag_str("error", lua_tostring(self->state, -1)), evt_tag_str("filename", self->filename), evt_tag_str("driver_id", self->super.super.super.id), NULL); return FALSE; } return TRUE; }; static void lua_dd_accept_message(LogMessage *msg, LogPathOptions *path_options) { log_msg_ack(msg, path_options, AT_PROCESSED); log_msg_unref(msg); }; static void lua_dd_ack_message(LuaDestDriver *self, LogMessage *msg, LogPathOptions *path_options) { lua_dd_accept_message(msg, path_options); }; static void lua_dd_drop_message(LuaDestDriver *self, LogMessage *msg, LogPathOptions *path_options) { stats_counter_inc(self->super.dropped_messages); lua_dd_accept_message(msg, path_options); }; static void lua_cast_and_push_value_to_stack(lua_State *state, const gchar *name, TypeHint type, const gchar *value) { switch (type) { case TYPE_HINT_INT32: { gint32 i; if (type_cast_to_int32(value, &i, NULL)) lua_pushinteger(state, i); else msg_error("Cannot cast value to integer", evt_tag_str("name", name), evt_tag_str("value", value), NULL); break; } case TYPE_HINT_STRING: lua_pushstring(state, value); break; default: msg_error("Unsupported type hint (strings or integers only!)", evt_tag_str("name", name), evt_tag_str("value", value), NULL); break; } }; static gboolean lua_dd_add_parameter_to_table(const gchar *name, TypeHint type, const gchar *value, gsize value_len, gpointer user_data) { lua_State *state = (lua_State *) user_data; lua_pushstring(state, name); lua_cast_and_push_value_to_stack(state, name, type, value); lua_settable(state, -3); return FALSE; }; static void lua_dd_create_parameter_table_for_queue_func(lua_State *state, ValuePairs *params, LogMessage *msg) { lua_newtable(state); value_pairs_foreach(params, lua_dd_add_parameter_to_table, msg, 0, LTZ_SEND, NULL, state); } static worker_insert_result_t lua_dd_queue(LogThrDestDriver *d, LogMessage *msg) { LuaDestDriver *self = (LuaDestDriver *) d; LogPathOptions path_options = LOG_PATH_OPTIONS_INIT; GString *str = scratch_buffers_alloc(); gboolean success; int number_of_parameters = 1; lua_getglobal(self->state, self->queue_func_name); if (self->mode == LUA_DEST_MODE_FORMATTED) { log_template_format(self->template, msg, NULL, 0, 0, NULL, str); lua_pushlstring(self->state, str->str, str->len); } if (self->mode == LUA_DEST_MODE_RAW) { lua_message_create_from_logmsg(self->state, msg); } if (self->params) { lua_dd_create_parameter_table_for_queue_func(self->state, self->params, msg); number_of_parameters = 2; } success = !lua_pcall(self->state, number_of_parameters, 0, 0); if (success) { return WORKER_INSERT_RESULT_SUCCESS; } else { msg_error("Error happened during calling Lua destination function!", evt_tag_str("error", lua_tostring(self->state, -1)), evt_tag_str("queue_func", self->queue_func_name), evt_tag_str("filename", self->filename), evt_tag_str("driver_id", self->super.super.super.id), NULL); lua_dd_drop_message(self, msg, &path_options); return WORKER_INSERT_RESULT_DROP; } }; static gboolean lua_dd_check_and_call_function(LuaDestDriver *self, const char *function_name, const char *function_type) { msg_debug("Calling lua destination function", evt_tag_str("function_type", function_type), NULL); lua_getglobal(self->state, function_name); if (lua_isnil(self->state, -1)) { msg_warning("Lua destination function cannot be found, continueing anyway!", evt_tag_str("function_type", function_type), evt_tag_str("function_name", function_name), evt_tag_str("filename", self->filename), evt_tag_str("driver_id", self->super.super.super.id), NULL); return TRUE; } if (lua_pcall(self->state, 0, 0, 0)) { msg_error("Error happened during calling Lua destination initializing function!", evt_tag_str("error", lua_tostring(self->state, -1)), evt_tag_str("function_type", function_type), evt_tag_str("function_name", function_name), evt_tag_str("filename", self->filename), evt_tag_str("driver_id", self->super.super.super.id), NULL); return FALSE; } return TRUE; }; static gboolean lua_dd_call_init_func(LuaDestDriver *self) { return lua_dd_check_and_call_function(self, self->init_func_name, "initialization"); } static gboolean lua_dd_call_deinit_func(LuaDestDriver *self) { return lua_dd_check_and_call_function(self, self->deinit_func_name, "deinitialization"); } static gboolean lua_dd_check_existence_of_queue_func(LuaDestDriver *self) { if (!lua_check_existence_of_global_variable(self->state, self->queue_func_name)) { msg_error("Lua destination queue function cannot be found!", evt_tag_str("queue_func", self->queue_func_name), evt_tag_str("filename", self->filename), evt_tag_str("driver_id", self->super.super.super.id), NULL); return FALSE; } return TRUE; } static void lua_dd_set_config_variable(lua_State *state, GlobalConfig *conf) { lua_pushlightuserdata(state, conf); lua_setglobal(state, "__conf"); }; static void lua_dd_inject_global_variable(gpointer data, gpointer user_data) { LuaGlobalConstant *constant = (LuaGlobalConstant *) data; lua_State *state = (lua_State *)user_data; lua_cast_and_push_value_to_stack(state, constant->name, constant->type, constant->value); lua_setglobal(state, constant->name); } static void lua_dd_inject_all_global_variables(lua_State *state, GList *globals) { g_list_foreach(globals, lua_dd_inject_global_variable, state); }; static gboolean lua_dd_init(LogPipe *s) { LuaDestDriver *self = (LuaDestDriver *) s; GlobalConfig *cfg; if (!lua_dd_load_file(self)) { lua_close(self->state); return FALSE; } lua_register_message(self->state); lua_register_template_class(self->state); lua_register_utility_functions(self->state); cfg = log_pipe_get_config(s); lua_dd_set_config_variable(self->state, cfg); if (self->globals) { lua_dd_inject_all_global_variables(self->state, self->globals); g_list_free_full(self->globals, lua_global_constant_free); self->globals = NULL; } if (!self->template) { msg_info("No template set in lua destination, falling back to template \"$MESSAGE\"", evt_tag_str("driver_id", self->super.super.super.id), NULL); self->template = log_template_new(cfg, "default_lua_template"); log_template_compile(self->template, "$MESSAGE", NULL); } if (!self->init_func_name) { msg_info("No init function name set, defaulting to \"lua_init_func\"", evt_tag_str("driver_id", self->super.super.super.id), NULL); self->init_func_name = g_strdup("lua_init_func"); } if (!self->queue_func_name) { msg_info("No queue function name set, defaulting to \"lua_queue_func\"", evt_tag_str("driver_id", self->super.super.super.id), NULL); self->queue_func_name = g_strdup("lua_queue_func"); } if (!self->deinit_func_name) { msg_info("No deinit function name set, defaulting to \"lua_deinit_func\"", evt_tag_str("driver_id", self->super.super.super.id), NULL); self->deinit_func_name = g_strdup("lua_deinit_func"); } if (!self->mode) self->mode = LUA_DEST_MODE_FORMATTED; if (!lua_dd_call_init_func(self)) { return FALSE; } if (!lua_dd_check_existence_of_queue_func(self)) { return FALSE; } return log_threaded_dest_driver_start(s); } static gboolean lua_dd_deinit(LogPipe *s) { LuaDestDriver *self = (LuaDestDriver *) s; lua_dd_call_deinit_func(self); if (!log_dest_driver_deinit_method(s)) return FALSE; lua_close(self->state); return TRUE; } static void lua_dd_free(LogPipe *s) { LuaDestDriver *self = (LuaDestDriver *) s; log_dest_driver_free(s); log_template_unref(self->template); g_free(self->filename); g_free(self->init_func_name); g_free(self->queue_func_name); } void lua_dd_set_template(LogDriver *d, LogTemplate *template) { LuaDestDriver *self = (LuaDestDriver *) d; self->template = log_template_ref(template); } void lua_dd_set_filename(LogDriver *d, gchar *filename) { LuaDestDriver *self = (LuaDestDriver *) d; self->filename = g_strdup(filename); } LogTemplateOptions * lua_dd_get_template_options(LogDriver *d) { LuaDestDriver *self = (LuaDestDriver *)d; return &self->template_options; } void lua_dd_set_init_func(LogDriver *d, gchar *init_func_name) { LuaDestDriver *self = (LuaDestDriver *) d; g_free(self->init_func_name); self->init_func_name = g_strdup(init_func_name); } void lua_dd_set_queue_func(LogDriver *d, gchar *queue_func_name) { LuaDestDriver *self = (LuaDestDriver *) d; g_free(self->queue_func_name); self->queue_func_name = g_strdup(queue_func_name); } void lua_dd_set_deinit_func(LogDriver *d, gchar *deinit_func_name) { LuaDestDriver *self = (LuaDestDriver *) d; g_free(self->deinit_func_name); self->deinit_func_name = g_strdup(deinit_func_name); } void lua_dd_set_mode(LogDriver *d, gchar *mode) { LuaDestDriver *self = (LuaDestDriver *) d; if (!strcmp("raw", mode)) self->mode = LUA_DEST_MODE_RAW; if (!strcmp("formatted", mode)) self->mode = LUA_DEST_MODE_FORMATTED; }; void lua_dd_init_global_contants(LogDriver *d) { LuaDestDriver *self = (LuaDestDriver *)d; if (self->globals) g_list_free_full(self->globals, lua_global_constant_free); self->globals = NULL; }; static void lua_dd_create_global_constant_from_params(LuaDestDriver *self, const char *name, const char *value, TypeHint type) { LuaGlobalConstant *constant = g_new0(LuaGlobalConstant, 1); constant->name = g_strdup(name); constant->value = g_strdup(value); constant->type = type; self->globals = g_list_append(self->globals, constant); }; void lua_dd_add_global_constant(LogDriver *d, const char *name, const char *value) { LuaDestDriver *self = (LuaDestDriver *)d; lua_dd_create_global_constant_from_params(self, name, value, TYPE_HINT_STRING); }; void lua_dd_add_global_constant_with_type_hint(LogDriver *d, const char *name, const char *value, const char *type) { TypeHint type_hint; LuaDestDriver *self = (LuaDestDriver *)d; if (!type_hint_parse(type, &type_hint, NULL)) { msg_error("Type hint parsing failed for lua constant, adding with default type hint", evt_tag_str("name", name), evt_tag_str("value", value), evt_tag_str("type", type), NULL); lua_dd_create_global_constant_from_params(self, name, value, TYPE_HINT_STRING); } else { lua_dd_create_global_constant_from_params(self, name, value, type_hint); } }; static gchar * lua_dd_format_string_instance(const LogPipe *d, char* persist_name, size_t persist_name_len) { LuaDestDriver *self = (LuaDestDriver *)d; if (d->persist_name) g_snprintf(persist_name, persist_name_len, "lua.%s", d->persist_name); else g_snprintf(persist_name, persist_name_len, "lua(%s,%s,%s,%s)", self->filename, self->init_func_name, self->queue_func_name, self->deinit_func_name); return persist_name; }; static gchar * lua_dd_format_stats_instance(LogThrDestDriver *d) { static gchar stats_name[1024]; return lua_dd_format_string_instance((LogPipe *) d, stats_name, sizeof(stats_name)); } static const gchar * lua_dd_format_persist_name(const LogPipe *d) { static gchar persist_name[1024]; return lua_dd_format_string_instance(d, persist_name, sizeof(persist_name)); } void lua_dd_set_params(LogDriver *d, ValuePairs *vp) { LuaDestDriver *self = (LuaDestDriver *) d; if (self->params) value_pairs_unref(self->params); self->params = vp; } LogDriver * lua_dd_new(GlobalConfig *cfg) { LuaDestDriver *self = g_new0(LuaDestDriver, 1); self->state = luaL_newstate(); luaL_openlibs(self->state); log_threaded_dest_driver_init_instance(&self->super, cfg); self->super.super.super.super.init = lua_dd_init; self->super.super.super.super.deinit = lua_dd_deinit; self->super.super.super.super.free_fn = lua_dd_free; self->super.super.super.super.generate_persist_name = lua_dd_format_persist_name; self->super.worker.insert = lua_dd_queue; self->super.worker.disconnect = NULL; self->super.format.stats_instance = lua_dd_format_stats_instance; self->super.stats_source = SCS_LUA; return &self->super.super.super; } syslog-ng-incubator-0.6.2/modules/lua/lua-dest.h000066400000000000000000000044541326222430700215550ustar00rootroot00000000000000/* * Copyright (c) 2013, 2014 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2013, 2014 Viktor Tusa * Copyright (c) 2014 Gergely Nagy * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * As an additional exemption you are allowed to compile & link against the * OpenSSL libraries as published by the OpenSSL project. See the file * COPYING for details. * */ #ifndef _AFLUA_DEST_H #define _AFLUA_DEST_H #include "driver.h" #include "logwriter.h" #include "value-pairs/value-pairs.h" #include "logthrdestdrv.h" #include typedef struct _LuaDestDriver { LogThrDestDriver super; lua_State *state; gchar *template_string; gchar *filename; gchar *init_func_name; gchar *queue_func_name; gchar *deinit_func_name; LogTemplate *template; LogTemplateOptions template_options; gint mode; ValuePairs *params; GList *globals; } LuaDestDriver; LogDriver *lua_dd_new(GlobalConfig *cfg); void lua_dd_set_init_func(LogDriver *d, gchar *init_func_name); void lua_dd_set_queue_func(LogDriver *d, gchar *queue_func_name); void lua_dd_set_deinit_func(LogDriver *d, gchar *deinit_func_name); void lua_dd_set_filename(LogDriver *d, gchar *filename); void lua_dd_set_template(LogDriver *d, LogTemplate *template); void lua_dd_set_mode(LogDriver *d, gchar *mode); void lua_dd_set_params(LogDriver *d, ValuePairs *vp); void lua_dd_add_global_constant(LogDriver *d, const char *name, const char *value); void lua_dd_add_global_constant_with_type_hint(LogDriver *d, const char *name, const char *value, const char *type_hint); void lua_dd_init_global_contants(LogDriver *d); LogTemplateOptions *lua_dd_get_template_options(LogDriver *d); #endif syslog-ng-incubator-0.6.2/modules/lua/lua-example.conf000066400000000000000000000007201326222430700227370ustar00rootroot00000000000000@version:3.5 source s_tcp { tcp(port(12345)); }; destination d_lua_formatted { lua( script("lua-example.lua") init-func("test_init") queue-func("test_queue") template("$MESSAGE") mode("formatted") ); }; destination d_lua_raw { lua( script("lua-example.lua") init-func("test_init") queue-func("test_queue_raw") mode("raw") ); }; log { source(s_tcp); destination(d_lua_formatted); destination(d_lua_raw); }; syslog-ng-incubator-0.6.2/modules/lua/lua-example.lua000066400000000000000000000004061326222430700225740ustar00rootroot00000000000000function test_init() print "Init called!" counter = 0 end function test_queue(msg) counter = counter + 1 print(msg .. " " .. tostring(counter)) end function test_queue_raw(msg) counter = counter + 1 print(msg['MESSAGE'] .. " " .. tostring(counter)) end syslog-ng-incubator-0.6.2/modules/lua/lua-grammar.ym000066400000000000000000000074121326222430700224370ustar00rootroot00000000000000/* * Copyright (c) 2013, 2014 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2013, 2014 Viktor Tusa * Copyright (c) 2014 Gergely Nagy * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * As an additional exemption you are allowed to compile & link against the * OpenSSL libraries as published by the OpenSSL project. See the file * COPYING for details. * */ %code requires { #include "lua-parser.h" #include "lua-dest.h" #include "value-pairs/value-pairs.h" #include "value-pairs/transforms.h" } %code { #include "cfg-grammar.h" #include "cfg-parser.h" #include "plugin.h" } %name-prefix "lua_driver_" %lex-param {CfgLexer *lexer} %parse-param {CfgLexer *lexer} %parse-param {LogDriver **instance} %parse-param {gpointer arg} /* INCLUDE_DECLS */ %token KW_LUA %token KW_SCRIPT %token KW_INIT_FUNC %token KW_QUEUE_FUNC %token KW_DEINIT_FUNC %token KW_LUA_DEST_MODE %token KW_GLOBALS %token KW_PARAMS %% start : LL_CONTEXT_DESTINATION KW_LUA { last_driver = *instance = lua_dd_new(configuration); } '(' lua_options ')' { YYACCEPT; } ; lua_options : lua_option lua_options | ; lua_option : KW_SCRIPT '(' string ')' { lua_dd_set_filename(last_driver, $3); free($3); } | KW_TEMPLATE '(' template_content ')' { lua_dd_set_template(last_driver, $3); } | KW_INIT_FUNC '(' string ')' { lua_dd_set_init_func(last_driver, $3); free($3); } | KW_QUEUE_FUNC '(' string ')' { lua_dd_set_queue_func(last_driver, $3); free($3); } | KW_DEINIT_FUNC '(' string ')' { lua_dd_set_deinit_func(last_driver, $3); free($3); } | KW_LUA_DEST_MODE '(' string ')' { lua_dd_set_mode(last_driver, $3); free($3); } | KW_PARAMS { last_value_pairs = value_pairs_new(); } '(' lua_params ')' { lua_dd_set_params(last_driver, last_value_pairs); } | KW_GLOBALS { lua_dd_init_global_contants(last_driver); } '(' lua_globals ')' | dest_driver_option | { last_template_options = lua_dd_get_template_options(last_driver); } template_option ; lua_globals : lua_global lua_globals | ; lua_global : LL_IDENTIFIER '(' string_or_number ')' { lua_dd_add_global_constant(last_driver, $1, $3); free($1); free($3); } | LL_IDENTIFIER '(' LL_IDENTIFIER '(' string_or_number ')' ')' { lua_dd_add_global_constant_with_type_hint(last_driver, $1, $5, $3); free($1); free($3); free($5); } ; lua_params : lua_param lua_params | ; lua_param : LL_IDENTIFIER '(' template_content ')' { value_pairs_add_pair(last_value_pairs, $1, $3); free($1); } | vp_option ; /* INCLUDE_RULES */ %% syslog-ng-incubator-0.6.2/modules/lua/lua-msg.c000066400000000000000000000073621326222430700214000ustar00rootroot00000000000000/* * Copyright (c) 2013, 2014 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2013, 2014 Viktor Tusa * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * As an additional exemption you are allowed to compile & link against the * OpenSSL libraries as published by the OpenSSL project. See the file * COPYING for details. * */ #define LUA_COMPAT_MODULE #include "lua-msg.h" #include "lua-utils.h" #include "logmsg/logmsg.h" #include "messages.h" #include #include int lua_message_create_from_logmsg(lua_State *state, LogMessage *self) { log_msg_ref(self); return lua_create_userdata_from_pointer(state, self, LUA_MESSAGE_TYPE); }; static int lua_message_new(lua_State *state) { LogMessage *self = log_msg_new_empty(); self->pri = 0; self->flags |= LF_LOCAL; return lua_message_create_from_logmsg(state, self); } static int lua_message_get_timestamp(lua_State *state) { LogMessage *m = lua_check_and_convert_userdata(state, 1, LUA_MESSAGE_TYPE); lua_Number timestamp = m->timestamps[LM_TS_RECVD].tv_sec; lua_pushinteger(state, timestamp); return 1; } static int lua_message_metatable__new_index(lua_State *state) { gsize value_len = 0; LogMessage *m = lua_check_and_convert_userdata(state, 1, LUA_MESSAGE_TYPE); const char *key = lua_tostring(state, 2); const char *value = lua_tolstring(state, 3, &value_len); NVHandle nv_handle = log_msg_get_value_handle(key); msg_trace("Setting value to lua message", evt_tag_str("key",key), evt_tag_str("value",value), NULL); log_msg_set_value(m, nv_handle, value, value_len); return 0; } static int lua_message_metatable__index(lua_State *state) { gssize value_len; LogMessage *m = lua_check_and_convert_userdata(state, 1, LUA_MESSAGE_TYPE); const char *key = lua_tostring(state, 2); NVHandle handle = log_msg_get_value_handle(key); const char *value = log_msg_get_value(m, handle, &value_len); msg_trace("Getting value from lua message", evt_tag_str("key",key), evt_tag_str("value",value), NULL); lua_pushlstring(state, value, value_len); return 1; } static int lua_message_metatable__gc(lua_State *state) { LogMessage *m = lua_check_and_convert_userdata(state, 1, LUA_MESSAGE_TYPE); log_msg_unref(m); return 0; }; LogMessage * lua_message_to_logmsg(lua_State *state, int index) { return lua_check_and_convert_userdata(state, index, LUA_MESSAGE_TYPE); } static const struct luaL_Reg msg_function [] = { {"new", lua_message_new}, {"get_timestamp", lua_message_get_timestamp}, {NULL, NULL} }; int lua_register_message(lua_State *state) { luaL_newmetatable(state, LUA_MESSAGE_TYPE); lua_pushstring(state, "__newindex"); lua_pushcfunction(state, lua_message_metatable__new_index); lua_settable(state, -3); lua_pushstring(state, "__index"); lua_pushcfunction(state, lua_message_metatable__index); lua_settable(state, -3); lua_pushstring(state, "__gc"); lua_pushcfunction(state, lua_message_metatable__gc); lua_settable(state, -3); lua_pop(state, 1); luaL_openlib(state, "Message", msg_function, 0); return 0; } syslog-ng-incubator-0.6.2/modules/lua/lua-msg.h000066400000000000000000000024411326222430700213760ustar00rootroot00000000000000/* * Copyright (c) 2013, 2014 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2013, 2014 Viktor Tusa * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * As an additional exemption you are allowed to compile & link against the * OpenSSL libraries as published by the OpenSSL project. See the file * COPYING for details. * */ #include "logmsg/logmsg.h" #include #ifndef _LUA_MSG_H #define _LUA_MSG_H int lua_register_message(lua_State *state); LogMessage *lua_message_to_logmsg(lua_State *state, int index); int lua_message_create_from_logmsg(lua_State *state, LogMessage *self); #define LUA_MESSAGE_TYPE "SyslogNG.Message" #endif syslog-ng-incubator-0.6.2/modules/lua/lua-parser.c000066400000000000000000000036771326222430700221130ustar00rootroot00000000000000/* * Copyright (c) 2013, 2014 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2013, 2014 Viktor Tusa * Copyright (c) 2014 Gergely Nagy * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * As an additional exemption you are allowed to compile & link against the * OpenSSL libraries as published by the OpenSSL project. See the file * COPYING for details. * */ #include "lua-parser.h" #include "cfg-parser.h" #include "lua-grammar.h" extern int lua_debug; int lua_driver_parse(CfgLexer *lexer, LogDriver **instance, gpointer arg); static CfgLexerKeyword lua_keywords[] = { { "lua", KW_LUA }, { "script", KW_SCRIPT }, { "init_func", KW_INIT_FUNC }, { "queue_func", KW_QUEUE_FUNC }, { "deinit_func", KW_DEINIT_FUNC }, { "mode", KW_LUA_DEST_MODE }, { "globals", KW_GLOBALS }, { "params", KW_PARAMS }, { NULL } }; CfgParser lua_parser = { #if ENABLE_DEBUG .debug_flag = &lua_debug, #endif .name = "lua", .keywords = lua_keywords, .parse = (int (*)(CfgLexer *lexer, gpointer *instance, gpointer)) lua_driver_parse, .cleanup = (void (*)(gpointer)) log_pipe_unref, }; CFG_PARSER_IMPLEMENT_LEXER_BINDING(lua_driver_, LogDriver **) syslog-ng-incubator-0.6.2/modules/lua/lua-parser.h000066400000000000000000000023211326222430700221010ustar00rootroot00000000000000/* * Copyright (c) 2013, 2014 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2013, 2014 Viktor Tusa * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * As an additional exemption you are allowed to compile & link against the * OpenSSL libraries as published by the OpenSSL project. See the file * COPYING for details. * */ #ifndef SNG_LUA_PARSER_H_INCLUDED #define SNG_LUA_PARSER_H_INCLUDED #include "cfg-parser.h" #include "cfg-lexer.h" #include "lua-dest.h" extern CfgParser lua_parser; CFG_PARSER_DECLARE_LEXER_BINDING(lua_driver_, LogDriver **) #endif syslog-ng-incubator-0.6.2/modules/lua/lua-plugin.c000066400000000000000000000031611326222430700221010ustar00rootroot00000000000000/* * Copyright (c) 2013, 2014 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2013, 2014 Viktor Tusa * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * As an additional exemption you are allowed to compile & link against the * OpenSSL libraries as published by the OpenSSL project. See the file * COPYING for details. * */ #include "lua-dest.h" #include "lua-parser.h" #include "plugin.h" #include "plugin-types.h" extern CfgParser lua_parser; static Plugin lua_plugin = { .type = LL_CONTEXT_DESTINATION, .name = "lua", .parser = &lua_parser, }; gboolean lua_module_init(PluginContext *context, CfgArgs *args G_GNUC_UNUSED) { plugin_register(context, &lua_plugin, 1); return TRUE; } const ModuleInfo module_info = { .canonical_name = "lua", .version = SYSLOG_NG_VERSION, .description = "The lua module provides lua scripted destination support for syslog-ng.", .core_revision = VERSION_CURRENT_VER_ONLY, .plugins = &lua_plugin, .plugins_len = 1, }; syslog-ng-incubator-0.6.2/modules/lua/lua-template.c000066400000000000000000000057061326222430700224250ustar00rootroot00000000000000/* * Copyright (c) 2013, 2014 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2013, 2014 Viktor Tusa * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * As an additional exemption you are allowed to compile & link against the * OpenSSL libraries as published by the OpenSSL project. See the file * COPYING for details. * */ #define LUA_COMPAT_MODULE #include "lua-template.h" #include "lua-utils.h" #include #include "scratch-buffers.h" #include "lua-msg.h" #include #include #define LUA_TEMPLATE_TYPE "SyslogNG.Template" #define LUA_COMPAT_MODULE int lua_template_new(lua_State *state) { GlobalConfig *cfg; LogTemplate *template; const char *template_string; GError *error = NULL; cfg = lua_get_config_from_current_state(state); template_string = lua_tostring(state, -1); template = log_template_new(cfg, NULL); log_template_compile(template, template_string, &error); if (error != NULL) { return luaL_error(state, "%s", error->message); } return lua_create_userdata_from_pointer(state, template, LUA_TEMPLATE_TYPE); }; static int lua_template_metatable__gc(lua_State *state) { LogTemplate *template; template = (LogTemplate *) lua_check_and_convert_userdata(state, -1, LUA_TEMPLATE_TYPE); log_template_unref(template); return 0; } static int lua_template_format(lua_State *state) { LogTemplate *template; LogMessage *msg; GString *str = scratch_buffers_alloc(); template = (LogTemplate *) lua_check_and_convert_userdata(state, -2, LUA_TEMPLATE_TYPE); msg = (LogMessage *) lua_check_and_convert_userdata(state, -1, LUA_MESSAGE_TYPE); log_template_format(template, msg, NULL, 0, 0, NULL, str); lua_pushlstring(state, str->str, str->len); return 1; } static const struct luaL_Reg template_namespace [] = { {"new", lua_template_new}, {NULL, NULL} }; static const struct luaL_Reg template_methods [] = { {"format", lua_template_format}, {"__gc", lua_template_metatable__gc}, {NULL, NULL} }; int lua_register_template_class(lua_State *state) { luaL_newmetatable(state, LUA_TEMPLATE_TYPE); lua_pushstring(state, "__index"); lua_pushvalue(state, -2); lua_settable(state, -3); luaL_openlib(state, NULL, template_methods, 0); lua_pop(state, 1); luaL_openlib(state, "Template", template_namespace, 0); return 0; } syslog-ng-incubator-0.6.2/modules/lua/lua-template.h000066400000000000000000000022221326222430700224200ustar00rootroot00000000000000/* * Copyright (c) 2013, 2014 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2013, 2014 Viktor Tusa * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * As an additional exemption you are allowed to compile & link against the * OpenSSL libraries as published by the OpenSSL project. See the file * COPYING for details. * */ #include #include