pax_global_header00006660000000000000000000000064122575751140014523gustar00rootroot0000000000000052 comment=b5278134eece6c6ceba7524335ce2cf75d482244 syslog-ng-incubator-0.1.0/000077500000000000000000000000001225757511400154275ustar00rootroot00000000000000syslog-ng-incubator-0.1.0/.gitignore000066400000000000000000000004771225757511400174270ustar00rootroot00000000000000*~ ._* .*.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/ syslog-ng-incubator-0.1.0/COPYING000066400000000000000000000016221225757511400164630ustar00rootroot00000000000000Copyright (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.1.0/GPL.txt000066400000000000000000000354311225757511400166200ustar00rootroot00000000000000 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.1.0/Makefile.am000066400000000000000000000005011225757511400174570ustar00rootroot00000000000000ACLOCAL_AMFLAGS = -I m4 AM_YFLAGS = -Wno-other -d check_PROGRAMS = TESTS = ${check_PROGRAMS} bin_PROGRAMS = module_LTLIBRARIES = BUILT_SOURCES = EXTRA_DIST = \ COPYING GPL.txt README.md NEWS ${BUILT_SOURCES} .y.c: include modules/Makefile.am include tools/Makefile.am include $(syslog_ng_tools)/lex-rules.am syslog-ng-incubator-0.1.0/NEWS000066400000000000000000000001611225757511400161240ustar00rootroot00000000000000#+STARTUP: indent showall -*- org -*- * 0.1.0 - <2013-12-28 Sat> Initial public release. syslog-ng-incubator-0.1.0/README.md000066400000000000000000000051511225757511400167100ustar00rootroot00000000000000syslog-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-3.5 **NOTE**: The Incubator requires syslog-ng 3.5.0rc1 or newer! Contents -------- * [Riemann destination][sng:riemann]: A simple, work in progress destination that allows syslog-ng to send events to the [Riemann](http://riemann.io/) network monitoring system. [sng:riemann]: https://github.com/balabit/syslog-ng-incubator/tree/master/modules/riemann/ * [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/ * [Extra template functions][sng:bf+]: Extra template functions, such as `$(//)` which is floating-point division, as opposed to the built-in `$(/)` (integer division). [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/ 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], [riemann-c-client][lrc], and [libmongo-client][lmc]; of which the latter two are optional) installed too. [lrc]: https://github.com/algernon/riemann-c-client [lmc]: https://github.com/algernon/libmongo-client License ------- Copyright (C) 2011-2013 BalaBit IT Security Ltd., Gergely Nagy 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.1.0/configure.ac000066400000000000000000000072621225757511400177240ustar00rootroot00000000000000dnl Process this file with autoconf to produce a configure script. dnl AC_PREREQ([2.68]) AC_INIT([syslog-ng-incubator], [0.1.0], [algernon@madhouse-project.org]) AM_INIT_AUTOMAKE([foreign subdir-objects dist-xz no-dist-gzip]) m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([no])]) AC_CONFIG_MACRO_DIR([m4]) 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.5" EVENTLOG_MIN_VERSION="0.2.10" IVYKIS_MIN_VERSION="0.30.0" LMC_MIN_VERSION="0.1.2" LRC_MIN_VERSION="1.0.0" dnl *************************************************************************** dnl Initial setup 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]) dnl *************************************************************************** dnl Checks for programs. AC_PROG_YACC AC_PROG_CC AC_PROG_CC_C_O AC_PROG_CXX 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 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) PKG_CHECK_MODULES(EVENTLOG, eventlog >= $EVENTLOG_MIN_VERSION) if test "x$with_ivykis" != "xno"; 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 *************************************************************************** PKG_CHECK_MODULES(LIBMONGO, libmongo-client >= $LMC_MIN_VERSION,,enable_logmongource="no") dnl *************************************************************************** dnl riemann-client headers/libraries dnl *************************************************************************** PKG_CHECK_MODULES(RIEMANN_CLIENT, riemann-client >= $LRC_MIN_VERSION,,enable_riemann="no") dnl *************************************************************************** dnl misc features to be enabled dnl *************************************************************************** AC_SUBST(syslog_ng_tools) AC_SUBST(moduledir) AM_CONDITIONAL(ENABLE_LOGMONGOURCE, [test "$enable_logmongource" != "no"]) AM_CONDITIONAL(ENABLE_RIEMANN, [test "$enable_riemann" != "no"]) AC_CONFIG_FILES([Makefile]) AC_OUTPUT syslog-ng-incubator-0.1.0/m4/000077500000000000000000000000001225757511400157475ustar00rootroot00000000000000syslog-ng-incubator-0.1.0/m4/.placeholder000066400000000000000000000000001225757511400202200ustar00rootroot00000000000000syslog-ng-incubator-0.1.0/modules/000077500000000000000000000000001225757511400170775ustar00rootroot00000000000000syslog-ng-incubator-0.1.0/modules/Makefile.am000066400000000000000000000002331225757511400211310ustar00rootroot00000000000000include modules/riemann/Makefile.am include modules/trigger-source/Makefile.am include modules/basicfuncs-plus/Makefile.am include modules/rss/Makefile.am syslog-ng-incubator-0.1.0/modules/basicfuncs-plus/000077500000000000000000000000001225757511400222005ustar00rootroot00000000000000syslog-ng-incubator-0.1.0/modules/basicfuncs-plus/Makefile.am000066400000000000000000000015001225757511400242300ustar00rootroot00000000000000module_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) \ $(SYSLOG_NG_CFLAGS) \ $(EVENTLOG_CFLAGS) \ -I$(top_srcdir)/modules/basicfuncs-plus modules_basicfuncs_plus_libbasicfuncs_plus_la_LIBADD = \ $(SYSLOG_NG_LIBS) modules_basicfuncs_plus_libbasicfuncs_plus_la_LDFLAGS = \ -avoid-version -module -no-undefined EXTRA_DIST += \ modules/basicfuncs-plus/cond-funcs.c \ 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.1.0/modules/basicfuncs-plus/basic-funcs-plus.c000066400000000000000000000035221225757511400255240ustar00rootroot00000000000000/* * 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 "plugin.h" #include "cfg.h" #include "plugin-types.h" #include "number-funcs.c" #include "state-funcs.c" #include "cond-funcs.c" /* * Plugin glue */ static Plugin basicfuncs_plus_plugins[] = { TEMPLATE_FUNCTION_PLUGIN(tf_num_divx, "//"), TEMPLATE_FUNCTION_PLUGIN(tf_state, "state"), TEMPLATE_FUNCTION_PLUGIN(tf_or, "or"), }; gboolean basicfuncs_plus_module_init(GlobalConfig *cfg, CfgArgs *args) { plugin_register(cfg, basicfuncs_plus_plugins, G_N_ELEMENTS(basicfuncs_plus_plugins)); return TRUE; } const ModuleInfo module_info = { .canonical_name = "basicfuncs-plus", .version = 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.1.0/modules/basicfuncs-plus/cond-funcs.c000066400000000000000000000025051225757511400244050ustar00rootroot00000000000000/* * 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 "plugin.h" #include "cfg.h" #include "plugin-types.h" static void tf_or (LogMessage *msg, gint argc, GString *argv[], GString *result) { gint i; for (i = 0; i < argc; i++) { if (argv[i]->len == 0) continue; g_string_append_len (result, argv[i]->str, argv[i]->len); break; } } TEMPLATE_FUNCTION_SIMPLE(tf_or); syslog-ng-incubator-0.1.0/modules/basicfuncs-plus/number-funcs.c000066400000000000000000000044501225757511400247530ustar00rootroot00000000000000/* * 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 #include #include #include "plugin.h" #include "cfg.h" #include "parse-number.h" #include "plugin-types.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 first argument is not a number", evt_tag_str("function", func_name), evt_tag_str("arg1", 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.1.0/modules/basicfuncs-plus/state-funcs.c000066400000000000000000000050621225757511400246030ustar00rootroot00000000000000/* * 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.1.0/modules/riemann/000077500000000000000000000000001225757511400205305ustar00rootroot00000000000000syslog-ng-incubator-0.1.0/modules/riemann/Makefile.am000066400000000000000000000021761225757511400225720ustar00rootroot00000000000000if ENABLE_RIEMANN module_LTLIBRARIES += modules/riemann/libriemann.la modules_riemann_libriemann_la_CFLAGS = \ $(RIEMANN_CLIENT_CFLAGS) \ $(SYSLOG_NG_CFLAGS) \ $(EVENTLOG_CFLAGS) \ $(IVYKIS_CFLAGS) \ -I$(top_srcdir)/modules/riemann \ -I$(top_builddir)/modules/riemann modules_riemann_libriemann_la_SOURCES = \ modules/riemann/riemann-grammar.y \ modules/riemann/riemann.c \ modules/riemann/riemann.h \ modules/riemann/riemann-parser.c \ modules/riemann/riemann-parser.h \ modules/riemann/riemann-plugin.c modules_riemann_libriemann_la_LIBADD = \ $(RIEMANN_CLIENT_LIBS) $(EVENTLOG_LIBS) \ $(SYSLOG_NG_LIBS) $(IVYKIS_LIBS) modules_riemann_libriemann_la_LDFLAGS = \ -avoid-version -module -no-undefined BUILT_SOURCES += \ modules/riemann/riemann-grammar.y \ modules/riemann/riemann-grammar.c \ modules/riemann/riemann-grammar.h modules/riemann mod-riemann: modules/riemann/libriemann.la else modules/riemann mod-riemann: endif EXTRA_DIST += \ modules/riemann/riemann-grammar.ym \ modules/riemann/riemann-example.conf .PHONY: modules/riemann mod-riemann syslog-ng-incubator-0.1.0/modules/riemann/riemann-example.conf000066400000000000000000000010051225757511400244550ustar00rootroot00000000000000@version: 3.5 source s_network { tcp(port(12345)); }; destination d_riemann { riemann( server("localhost") port(5555) ttl("300.5") metric(int("$SEQNUM")) description("syslog-ng-incubator riemann test") state("ok") #tags("foo", "bar", "baz") attributes(x-ultimate-answer("$(+ $PID 42)") key("MESSAGE", rekey(add-prefix("x-")))) ); }; log { source(s_network); destination(d_riemann); flags(flow-control); }; syslog-ng-incubator-0.1.0/modules/riemann/riemann-grammar.ym000066400000000000000000000077141225757511400241650ustar00rootroot00000000000000/* * 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 "riemann-parser.h" #include "value-pairs.h" #include "vptransform.h" } %code { #include "cfg-grammar.h" #include "cfg-parser.h" #include "plugin.h" } %name-prefix "riemann_" %lex-param {CfgLexer *lexer} %parse-param {CfgLexer *lexer} %parse-param {LogDriver **instance} %parse-param {gpointer arg} /* INCLUDE_DECLS */ %token KW_RIEMANN %token KW_SERVER %token KW_STATE %token KW_SERVICE %token KW_DESCRIPTION %token KW_METRIC %token KW_TTL %token KW_ATTRIBUTES %% start : LL_CONTEXT_DESTINATION KW_RIEMANN { last_driver = *instance = riemann_dd_new(); } '(' riemann_options ')' { YYACCEPT; } ; riemann_options : riemann_option riemann_options | ; riemann_option : KW_SERVER '(' string ')' { riemann_dd_set_server(last_driver, $3); free($3); } | KW_PORT '(' LL_NUMBER ')' { riemann_dd_set_port(last_driver, $3); } | KW_HOST '(' template_content ')' { riemann_dd_set_field_host(last_driver, $3); } | KW_SERVICE '(' template_content ')' { riemann_dd_set_field_service(last_driver, $3); } | KW_STATE '(' template_content ')' { riemann_dd_set_field_state(last_driver, $3); } | KW_DESCRIPTION '(' template_content ')' { riemann_dd_set_field_description(last_driver, $3); } | KW_TTL '(' template_content ')' { riemann_dd_set_field_ttl(last_driver, $3); } | KW_METRIC '(' template_content ')' { riemann_dd_set_field_metric(last_driver, $3); } | KW_TAGS '(' string_list ')' { riemann_dd_set_field_tags(last_driver, $3); } | KW_TYPE '(' LL_IDENTIFIER ')' { CHECK_ERROR(riemann_dd_set_connection_type(last_driver, $3), @3, "Unknown Riemann connection type: %s", $3); free($3); } | KW_TYPE '(' LL_STRING ')' { CHECK_ERROR(riemann_dd_set_connection_type(last_driver, $3), @3, "Unknown Riemann connection type: %s", $3); free($3); } | KW_ATTRIBUTES { last_value_pairs = value_pairs_new(); } '(' attribute_options ')' { riemann_dd_set_field_attributes(last_driver, last_value_pairs); } | dest_driver_option | { last_template_options = riemann_dd_get_template_options(last_driver); } template_option ; attribute_options : attribute_option attribute_options | ; attribute_option : LL_IDENTIFIER '(' template_content ')' { value_pairs_add_pair(last_value_pairs, $1, $3); free($1); } | vp_option ; /* INCLUDE_RULES */ %% syslog-ng-incubator-0.1.0/modules/riemann/riemann-parser.c000066400000000000000000000037351225757511400236270ustar00rootroot00000000000000/* * 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 "riemann.h" #include "cfg-parser.h" #include "riemann-grammar.h" extern int riemann_debug; int riemann_parse(CfgLexer *lexer, LogDriver **instance, gpointer arg); static CfgLexerKeyword riemann_keywords[] = { { "riemann", KW_RIEMANN }, { "server", KW_SERVER }, { "port", KW_PORT }, { "host", KW_HOST }, { "service", KW_SERVICE }, { "state", KW_STATE }, { "description", KW_DESCRIPTION }, { "metric", KW_METRIC }, { "ttl", KW_TTL }, { "attributes", KW_ATTRIBUTES }, { NULL } }; CfgParser riemann_parser = { #if ENABLE_DEBUG .debug_flag = &riemann_debug, #endif .name = "riemann", .keywords = riemann_keywords, .parse = (int (*)(CfgLexer *lexer, gpointer *instance, gpointer)) riemann_parse, .cleanup = (void (*)(gpointer)) log_pipe_unref, }; CFG_PARSER_IMPLEMENT_LEXER_BINDING(riemann_, LogDriver **) syslog-ng-incubator-0.1.0/modules/riemann/riemann-parser.h000066400000000000000000000023221225757511400236230ustar00rootroot00000000000000/* * 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_RIEMANN_PARSER_H_INCLUDED #define SNG_RIEMANN_PARSER_H_INCLUDED #include "cfg-parser.h" #include "cfg-lexer.h" #include "riemann.h" extern CfgParser riemann_parser; CFG_PARSER_DECLARE_LEXER_BINDING(riemann_, LogDriver **) #endif syslog-ng-incubator-0.1.0/modules/riemann/riemann-plugin.c000066400000000000000000000031711225757511400236230ustar00rootroot00000000000000/* * 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 "riemann.h" #include "riemann-parser.h" #include "plugin.h" #include "plugin-types.h" extern CfgParser riemann_parser; static Plugin riemann_plugin = { .type = LL_CONTEXT_DESTINATION, .name = "riemann", .parser = &riemann_parser, }; gboolean riemann_module_init(GlobalConfig *cfg, CfgArgs *args G_GNUC_UNUSED) { plugin_register(cfg, &riemann_plugin, 1); return TRUE; } const ModuleInfo module_info = { .canonical_name = "riemann", .version = VERSION, .description = "The riemann module provides Riemann destination support for syslog-ng.", .core_revision = VERSION_CURRENT_VER_ONLY, .plugins = &riemann_plugin, .plugins_len = 1, }; syslog-ng-incubator-0.1.0/modules/riemann/riemann.c000066400000000000000000000337661225757511400223440ustar00rootroot00000000000000/* * 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 #include #include #include #include "logthrdestdrv.h" #include "misc.h" #include "stats.h" #include "scratch-buffers.h" #include "riemann.h" #ifndef SCS_RIEMANN #define SCS_RIEMANN 0 #endif typedef struct { LogThrDestDriver super; gchar *server; gint port; riemann_client_type_t type; struct { LogTemplate *host; LogTemplate *service; LogTemplate *state; LogTemplate *description; LogTemplate *metric; LogTemplate *ttl; GList *tags; ValuePairs *attributes; } fields; LogTemplateOptions template_options; riemann_client_t *client; gint32 seq_num; } RiemannDestDriver; /* * Configuration */ void riemann_dd_set_server(LogDriver *d, const gchar *host) { RiemannDestDriver *self = (RiemannDestDriver *)d; g_free(self->server); self->server = g_strdup(host); } void riemann_dd_set_port(LogDriver *d, gint port) { RiemannDestDriver *self = (RiemannDestDriver *)d; self->port = port; } void riemann_dd_set_field_host(LogDriver *d, LogTemplate *value) { RiemannDestDriver *self = (RiemannDestDriver *)d; self->fields.host = log_template_ref(value); } void riemann_dd_set_field_service(LogDriver *d, LogTemplate *value) { RiemannDestDriver *self = (RiemannDestDriver *)d; self->fields.service = log_template_ref(value); } void riemann_dd_set_field_state(LogDriver *d, LogTemplate *value) { RiemannDestDriver *self = (RiemannDestDriver *)d; self->fields.state = log_template_ref(value); } void riemann_dd_set_field_description(LogDriver *d, LogTemplate *value) { RiemannDestDriver *self = (RiemannDestDriver *)d; self->fields.description = log_template_ref(value); } void riemann_dd_set_field_metric(LogDriver *d, LogTemplate *value) { RiemannDestDriver *self = (RiemannDestDriver *)d; self->fields.metric = log_template_ref(value); } void riemann_dd_set_field_ttl(LogDriver *d, LogTemplate *value) { RiemannDestDriver *self = (RiemannDestDriver *)d; self->fields.ttl = log_template_ref(value); } void riemann_dd_set_field_tags(LogDriver *d, GList *taglist) { RiemannDestDriver *self = (RiemannDestDriver *)d; string_list_free(self->fields.tags); self->fields.tags = taglist; } void riemann_dd_set_field_attributes(LogDriver *d, ValuePairs *vp) { RiemannDestDriver *self = (RiemannDestDriver *)d; if (self->fields.attributes) value_pairs_free(self->fields.attributes); self->fields.attributes = vp; } gboolean riemann_dd_set_connection_type(LogDriver *d, const gchar *type) { RiemannDestDriver *self = (RiemannDestDriver *)d; if (strcmp(type, "tcp") == 0) self->type = RIEMANN_CLIENT_TCP; else if (strcmp(type, "udp") == 0) self->type = RIEMANN_CLIENT_UDP; else return FALSE; return TRUE; } LogTemplateOptions * riemann_dd_get_template_options(LogDriver *d) { RiemannDestDriver *self = (RiemannDestDriver *)d; return &self->template_options; } /* * Utilities */ static gchar * riemann_dd_format_stats_instance(LogThrDestDriver *s) { RiemannDestDriver *self = (RiemannDestDriver *)s; static gchar persist_name[1024]; g_snprintf(persist_name, sizeof(persist_name), "riemann,%s,%u", self->server, self->port); return persist_name; } static gchar * riemann_dd_format_persist_name(LogThrDestDriver *s) { RiemannDestDriver *self = (RiemannDestDriver *)s; static gchar persist_name[1024]; g_snprintf(persist_name, sizeof(persist_name), "riemann(%s,%u)", self->server, self->port); return persist_name; } static void riemann_dd_disconnect(LogThrDestDriver *s) { RiemannDestDriver *self = (RiemannDestDriver *)s; riemann_client_disconnect(self->client); self->client = NULL; } static gboolean riemann_dd_connect(RiemannDestDriver *self, gboolean reconnect) { if (reconnect && self->client) return TRUE; self->client = riemann_client_create(self->type, self->server, self->port); if (!self->client) { msg_error("Error connecting to Riemann", evt_tag_errno("errno", errno), NULL); return FALSE; } return TRUE; } /* * Main thread */ static gboolean riemann_worker_init(LogPipe *s) { RiemannDestDriver *self = (RiemannDestDriver *)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); if (!self->server) self->server = g_strdup("127.0.0.1"); if (self->port == -1) self->port = 5555; if (!self->fields.host) { self->fields.host = log_template_new(cfg, NULL); log_template_compile(self->fields.host, "${HOST}", NULL); } if (!self->fields.service) { self->fields.service = log_template_new(cfg, NULL); log_template_compile(self->fields.service, "${PROGRAM}", NULL); } msg_verbose("Initializing Riemann destination", evt_tag_str("driver", self->super.super.super.id), evt_tag_str("server", self->server), evt_tag_int("port", self->port), NULL); return log_threaded_dest_driver_start(s); } static void riemann_dd_field_maybe_add(riemann_event_t *event, LogMessage *msg, LogTemplate *template, const LogTemplateOptions *template_options, riemann_event_field_t ftype, gint32 seq_num, GString *target) { if (!template) return; log_template_format(template, msg, template_options, LTZ_SEND, seq_num, NULL, target); riemann_event_set(event, ftype, target->str, RIEMANN_EVENT_FIELD_NONE); } static void riemann_dd_field_add_tag(gpointer data, gpointer user_data) { gchar *tag = (gchar *)data; riemann_event_t *event = (riemann_event_t *)user_data; riemann_event_tag_add(event, tag); } static gboolean riemann_dd_field_add_msg_tag(LogMessage *msg, LogTagId tag_id, const gchar *tag_name, gpointer user_data) { riemann_event_t *event = (riemann_event_t *)user_data; riemann_event_tag_add(event, tag_name); return TRUE; } static gboolean riemann_dd_field_add_attribute_vp(const gchar *name, TypeHint type, const gchar *value, gpointer user_data) { riemann_event_t *event = (riemann_event_t *)user_data; riemann_attribute_t *attrib = riemann_attribute_new(); riemann_attribute_set(attrib, name, value); riemann_event_attribute_add(event, attrib); return FALSE; } static gboolean riemann_worker_insert(LogThrDestDriver *s) { RiemannDestDriver *self = (RiemannDestDriver *)s; riemann_event_t *event; gboolean success, need_drop = FALSE; LogMessage *msg; LogPathOptions path_options = LOG_PATH_OPTIONS_INIT; SBGString *str; riemann_dd_connect(self, TRUE); success = log_queue_pop_head(self->super.queue, &msg, &path_options, FALSE, FALSE); if (!success) return TRUE; msg_set_context(msg); event = riemann_event_new(); str = sb_gstring_acquire(); if (self->fields.metric) { log_template_format(self->fields.metric, msg, &self->template_options, LTZ_SEND, self->seq_num, NULL, sb_gstring_string(str)); switch (self->fields.metric->type_hint) { case TYPE_HINT_INT32: case TYPE_HINT_INT64: { glong i; if (type_cast_to_int64(sb_gstring_string(str)->str, &i, NULL)) riemann_event_set(event, RIEMANN_EVENT_FIELD_METRIC_S64, i, RIEMANN_EVENT_FIELD_NONE); else need_drop = type_cast_drop_helper(self->template_options.on_error, sb_gstring_string(str)->str, "int"); break; } case TYPE_HINT_STRING: { gfloat f; gchar *endptr; gboolean r; errno = 0; f = strtof(sb_gstring_string(str)->str, &endptr); if (errno == ERANGE && (f == HUGE_VAL || f == -HUGE_VAL)) r = FALSE; if (endptr == sb_gstring_string(str)->str) r = FALSE; if (r) riemann_event_set(event, RIEMANN_EVENT_FIELD_METRIC_D, (double) f, RIEMANN_EVENT_FIELD_NONE); else need_drop = type_cast_drop_helper(self->template_options.on_error, sb_gstring_string(str)->str, "float"); break; } default: need_drop = type_cast_drop_helper(self->template_options.on_error, sb_gstring_string(str)->str, ""); break; } } if (!need_drop && self->fields.ttl) { float f; gchar *endptr; gboolean r = TRUE; log_template_format(self->fields.ttl, msg, &self->template_options, LTZ_SEND, self->seq_num, NULL, sb_gstring_string(str)); errno = 0; f = strtof(sb_gstring_string(str)->str, &endptr); if ((errno == ERANGE && (f == HUGE_VAL || f == -HUGE_VAL)) || (errno == 0 && f == 0)) r = FALSE; if (endptr == sb_gstring_string(str)->str) r = FALSE; if (r) riemann_event_set(event, RIEMANN_EVENT_FIELD_TTL, f, RIEMANN_EVENT_FIELD_NONE); else need_drop = type_cast_drop_helper(self->template_options.on_error, sb_gstring_string(str)->str, "float"); } if (!need_drop) { riemann_dd_field_maybe_add(event, msg, self->fields.host, &self->template_options, RIEMANN_EVENT_FIELD_HOST, self->seq_num, sb_gstring_string(str)); riemann_dd_field_maybe_add(event, msg, self->fields.service, &self->template_options, RIEMANN_EVENT_FIELD_SERVICE, self->seq_num, sb_gstring_string(str)); riemann_dd_field_maybe_add(event, msg, self->fields.description, &self->template_options, RIEMANN_EVENT_FIELD_DESCRIPTION, self->seq_num, sb_gstring_string(str)); riemann_dd_field_maybe_add(event, msg, self->fields.state, &self->template_options, RIEMANN_EVENT_FIELD_STATE, self->seq_num, sb_gstring_string(str)); if (self->fields.tags) g_list_foreach(self->fields.tags, riemann_dd_field_add_tag, (gpointer)event); else log_msg_tags_foreach(msg, riemann_dd_field_add_msg_tag, (gpointer)event); if (self->fields.attributes) value_pairs_foreach(self->fields.attributes, riemann_dd_field_add_attribute_vp, msg, self->seq_num, &self->template_options, event); riemann_client_send_message_oneshot (self->client, riemann_message_create_with_events(event, NULL)); } sb_gstring_release(str); msg_set_context(NULL); if (success) { stats_counter_inc(self->super.stored_messages); step_sequence_number(&self->seq_num); log_msg_ack(msg, &path_options); log_msg_unref(msg); } else { if (need_drop) { stats_counter_inc(self->super.dropped_messages); step_sequence_number(&self->seq_num); log_msg_ack(msg, &path_options); log_msg_unref(msg); } else log_queue_push_head(self->super.queue, msg, &path_options); } return success; } /* * Plugin glue. */ static void riemann_dd_free(LogPipe *d) { RiemannDestDriver *self = (RiemannDestDriver *)d; g_free(self->server); log_template_options_destroy(&self->template_options); riemann_client_free(self->client); log_template_unref(self->fields.host); log_template_unref(self->fields.service); log_template_unref(self->fields.state); log_template_unref(self->fields.description); log_template_unref(self->fields.metric); log_template_unref(self->fields.ttl); string_list_free(self->fields.tags); if (self->fields.attributes) value_pairs_free(self->fields.attributes); log_threaded_dest_driver_free(d); } LogDriver * riemann_dd_new(void) { RiemannDestDriver *self = g_new0(RiemannDestDriver, 1); log_threaded_dest_driver_init_instance(&self->super); self->super.super.super.super.init = riemann_worker_init; self->super.super.super.super.free_fn = riemann_dd_free; self->super.worker.disconnect = riemann_dd_disconnect; self->super.worker.insert = riemann_worker_insert; self->super.format.stats_instance = riemann_dd_format_stats_instance; self->super.format.persist_name = riemann_dd_format_persist_name; self->super.stats_source = SCS_RIEMANN; self->port = -1; self->type = RIEMANN_CLIENT_TCP; init_sequence_number(&self->seq_num); log_template_options_defaults(&self->template_options); return (LogDriver *)self; } syslog-ng-incubator-0.1.0/modules/riemann/riemann.h000066400000000000000000000036141225757511400223360ustar00rootroot00000000000000/* * 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_RIEMANN_H_INCLUDED #define SNG_RIEMANN_H_INCLUDED #include "driver.h" #include "value-pairs.h" LogDriver *riemann_dd_new(void); void riemann_dd_set_server(LogDriver *d, const gchar *host); void riemann_dd_set_port(LogDriver *d, gint port); LogTemplateOptions *riemann_dd_get_template_options(LogDriver *d); void riemann_dd_set_field_host(LogDriver *d, LogTemplate *value); void riemann_dd_set_field_service(LogDriver *d, LogTemplate *value); void riemann_dd_set_field_state(LogDriver *d, LogTemplate *value); void riemann_dd_set_field_description(LogDriver *d, LogTemplate *value); void riemann_dd_set_field_metric(LogDriver *d, LogTemplate *value); void riemann_dd_set_field_ttl(LogDriver *d, LogTemplate *value); void riemann_dd_set_field_tags(LogDriver *d, GList *taglist); void riemann_dd_set_field_attributes(LogDriver *d, ValuePairs *vp); gboolean riemann_dd_set_connection_type(LogDriver *d, const gchar *type); #endif syslog-ng-incubator-0.1.0/modules/rss/000077500000000000000000000000001225757511400177065ustar00rootroot00000000000000syslog-ng-incubator-0.1.0/modules/rss/Makefile.am000066400000000000000000000013621225757511400217440ustar00rootroot00000000000000module_LTLIBRARIES += modules/rss/librss.la modules_rss_librss_la_CFLAGS = \ $(SYSLOG_NG_CFLAGS) \ $(EVENTLOG_CFLAGS) \ $(IVYKIS_CFLAGS) \ -I$(top_srcdir)/modules/rss \ -I$(top_builddir)/modules/rss modules_rss_librss_la_SOURCES = \ modules/rss/rss-grammar.y \ modules/rss/rss.c \ modules/rss/rss.h \ modules/rss/rss-parser.c \ modules/rss/rss-parser.h modules_rss_librss_la_LDFLAGS = \ -avoid-version -module -no-undefined BUILT_SOURCES += \ modules/rss/rss-grammar.y \ modules/rss/rss-grammar.c \ modules/rss/rss-grammar.h modules/rss mod-rss: modules/rss/librss.la EXTRA_DIST += \ modules/rss/rss-grammar.ym \ modules/rss/rss-example.conf .PHONY: modules/rss mod-rss syslog-ng-incubator-0.1.0/modules/rss/rss-example.conf000066400000000000000000000005331225757511400230160ustar00rootroot00000000000000@version: 3.5 source s_network { tcp(port(12345)); }; destination d_rss { rss( port(8192) feed-title("A sample RSS feed") entry-title("${HOST} has a new message for you [${DATE}]") entry-description("${MESSAGE}") ); }; log { source(s_network); destination(d_rss); flags(flow-control); }; syslog-ng-incubator-0.1.0/modules/rss/rss-grammar.ym000066400000000000000000000041261225757511400225130ustar00rootroot00000000000000/* * Copyright (c) 2013 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2013 Tusa Viktor * * 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 library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; 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 "rss-parser.h" } %code { #include "cfg-parser.h" #include "rss-grammar.h" #include "plugin.h" extern LogDriver *last_driver; } %name-prefix "rss_" %lex-param {CfgLexer *lexer} %parse-param {CfgLexer *lexer} %parse-param {LogDriver **instance} %parse-param {gpointer arg} /* INCLUDE_DECLS */ %token KW_RSS %token KW_RSS_PORT %token KW_RSS_TITLE %token KW_RSS_ENTRY_TITLE %token KW_RSS_ENTRY_DESCRIPTION %% start : LL_CONTEXT_DESTINATION KW_RSS { last_driver = *instance = rss_dd_new(); } '(' rss_options ')' { YYACCEPT; } ; rss_options : rss_option rss_options | ; rss_option : KW_RSS_PORT '(' LL_NUMBER ')' { rss_dd_set_port(last_driver,$3); }; | KW_RSS_TITLE '(' string ')' { rss_dd_set_title(last_driver, $3); free($3); }; | KW_RSS_ENTRY_TITLE '(' string ')' { rss_dd_set_entry_title(last_driver, $3); free($3); }; | KW_RSS_ENTRY_DESCRIPTION '(' string ')' { rss_dd_set_entry_description(last_driver, $3); free($3); }; | dest_driver_option ; /* INCLUDE_RULES */ %% syslog-ng-incubator-0.1.0/modules/rss/rss-parser.c000066400000000000000000000033261225757511400221570ustar00rootroot00000000000000/* * Copyright (c) 2013 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2013 Tusa Viktor * * 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 library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; 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 "rss.h" #include "cfg-parser.h" #include "rss-grammar.h" extern int rss_debug; int rss_parse(CfgLexer *lexer, LogDriver **instance, gpointer arg); static CfgLexerKeyword rss_keywords[] = { { "rss", KW_RSS }, { "port", KW_RSS_PORT }, { "feed_title", KW_RSS_TITLE }, { "entry_title", KW_RSS_ENTRY_TITLE }, { "entry_description", KW_RSS_ENTRY_DESCRIPTION }, { NULL } }; CfgParser rss_parser = { #if ENABLE_DEBUG .debug_flag = &rss_debug, #endif .name = "rss", .keywords = rss_keywords, .parse = (int (*)(CfgLexer *lexer, gpointer *instance, gpointer arg)) rss_parse, .cleanup = (void (*)(gpointer)) log_pipe_unref, }; CFG_PARSER_IMPLEMENT_LEXER_BINDING(rss_, LogDriver **) syslog-ng-incubator-0.1.0/modules/rss/rss-parser.h000066400000000000000000000022551225757511400221640ustar00rootroot00000000000000/* * Copyright (c) 2013 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2013 Tusa Viktor * * 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 library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; 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 RSS_PARSER_H_INCLUDED #define RSS_PARSER_H_INCLUDED #include "cfg-parser.h" #include "cfg-lexer.h" #include "rss.h" extern CfgParser rss_parser; CFG_PARSER_DECLARE_LEXER_BINDING(rss_, LogDriver **) #endif syslog-ng-incubator-0.1.0/modules/rss/rss.c000066400000000000000000000207401225757511400206640ustar00rootroot00000000000000/* * Copyright (c) 2013 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2013 Tusa Viktor * * 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 library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; 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 "rss.h" #include "rss-parser.h" #include "plugin.h" #include "plugin-types.h" #include "messages.h" #include static GString * _format_feed_header (RssDestDriver *self, GString *result) { result = g_string_append (result, "\n\n"); result = g_string_append (result, self->feed_title->str); result = g_string_append (result, ""); result = g_string_append (result, self->address->str); result = g_string_append (result, ""); return result; } static GString * _format_feed_footer (RssDestDriver *self, GString *result) { return g_string_append (result, "\n"); }; static GString * _append_text_escaped (GString*result, GString *message) { gchar* escaped_text = g_markup_escape_text (message->str, message->len); result = g_string_append (result, escaped_text); g_free (escaped_text); return result; } static GString * _format_backlog (RssDestDriver *self, GString *result) { GList *feed_item = self->backlog; GString *message; char id_str[10]; int offset = self->id; result = _format_feed_header (self, result); while (feed_item) { message = g_string_new (""); log_template_format (self->entry_title, feed_item->data, NULL, LTZ_LOCAL, 0, NULL, message); result = g_string_append (result, "\n "); result = _append_text_escaped (result, message); result = g_string_append (result, "\n "); log_template_format (self->entry_description, feed_item->data, NULL, LTZ_LOCAL, 0, NULL, message); result = _append_text_escaped (result, message); result = g_string_append (result, "\n "); snprintf (id_str, 10, "%d", offset); result = g_string_append (result, id_str); result = g_string_append (result, "\n\n"); g_string_free (message, TRUE); feed_item = g_list_next (feed_item); offset++; } result = _format_feed_footer (self, result); return result; } static void _generate_address_string (RssDestDriver *self) { self->address = g_string_new (""); g_string_printf (self->address, "localhost:%d", self->port); } static int _init_rss_listen_socket (RssDestDriver * self) { int sock, optval; struct sockaddr_in lsockaddr; sock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); optval = 1; if (setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval) == -1) msg_error ("RSS setsockopt failed!", NULL); lsockaddr.sin_family = AF_INET; lsockaddr.sin_port = htons (self->port); lsockaddr.sin_addr.s_addr = INADDR_ANY; memset (lsockaddr.sin_zero, '\0', sizeof (lsockaddr.sin_zero)); if (bind (sock, (struct sockaddr *) &lsockaddr, sizeof (lsockaddr)) < 0) { msg_error ("RSS Bind failed!", NULL); return -1; } if (listen (sock, 10) < 0) { msg_error ("RSS Listen failed!", NULL); return -1; } return sock; } static int _accept_rss_connection (int sock) { struct sockaddr_in rsockaddr; socklen_t addrlen; return accept (sock, (struct sockaddr *)&rsockaddr, &addrlen); } static GString * _create_http_header () { return g_string_new ("HTTP/1.1 200 OK\nContent-Type:application/atom+xml\n\n"); } static void _respond_with_feed (int sock, GString *feed) { gchar buffer[4096]; read (sock, buffer, sizeof (buffer)); write (sock, feed->str, feed->len); } static void _accept_and_serve_rss_connection (void *userdata) { GString *feed; int newsock, sock; RssDestDriver *self = (RssDestDriver*) userdata; sock = self->listen_fd.fd; newsock = _accept_rss_connection (sock); feed = _create_http_header (); feed = _format_backlog (self, feed); _respond_with_feed (newsock, feed); shutdown (newsock, 2); close (newsock); g_string_free (feed, TRUE); } static void _remove_msg_from_backlog_unlocked (RssDestDriver *self) { LogMessage *msg; msg = g_list_nth_data (self->backlog, 0); self->backlog = g_list_remove (self->backlog, msg); log_msg_unref (msg); self->id++; } static void _append_msg_to_backlog (RssDestDriver *self, LogMessage *msg) { g_mutex_lock (self->lock); log_msg_ref (msg); self->backlog = g_list_append (self->backlog, msg); if (g_list_length (self->backlog) > 100) { _remove_msg_from_backlog_unlocked (self); } g_mutex_unlock (self->lock); } static void rss_dd_queue (LogPipe *s, LogMessage *msg, const LogPathOptions *path_options, gpointer user_data) { RssDestDriver *self = (RssDestDriver *)s; _append_msg_to_backlog (self, msg); log_dest_driver_queue_method (s, msg, path_options, user_data); } void rss_dd_set_port (LogDriver *s, int port) { RssDestDriver *self = (RssDestDriver *)s; self->port = port; } void rss_dd_set_title(LogDriver *s, const char *title) { RssDestDriver *self = (RssDestDriver *)s; self->feed_title = g_string_new (g_strdup (title)); } void rss_dd_set_entry_title(LogDriver *s, const char *title) { GError *error = NULL; RssDestDriver *self = (RssDestDriver *)s; self->entry_title = log_template_new (configuration, NULL); log_template_compile (self->entry_title, title, &error); } void rss_dd_set_entry_description(LogDriver *s, const char *description) { GError *error = NULL; RssDestDriver *self = (RssDestDriver *)s; self->entry_description = log_template_new (configuration, NULL); log_template_compile (self->entry_description, description, &error); } static gboolean _register_listen_fd (RssDestDriver *self) { int listen_socket; IV_FD_INIT (&self->listen_fd); listen_socket = _init_rss_listen_socket (self); if (listen_socket == -1) return FALSE; self->listen_fd.fd = listen_socket; self->listen_fd.cookie = self; self->listen_fd.handler_in = _accept_and_serve_rss_connection; iv_fd_register (&self->listen_fd); _generate_address_string(self); return TRUE; } gboolean rss_dd_init (LogPipe * s) { RssDestDriver *self = (RssDestDriver *) s; if (!self->feed_title || !self->entry_title || !self->entry_description) { msg_error("title, entry_title, entry_description options are mandatory for RSS destination", NULL); return FALSE; } self->lock = g_mutex_new (); return _register_listen_fd (self); } gboolean rss_dd_deinit (LogPipe *s) { return TRUE; } void rss_dd_free (LogPipe *s) { RssDestDriver *self = (RssDestDriver *)s; g_list_free_full (self->backlog, (GDestroyNotify)log_msg_unref); g_string_free (self->address, TRUE); g_string_free (self->feed_title, TRUE); log_template_unref (self->entry_title); log_template_unref (self->entry_description); } LogDriver * rss_dd_new (void) { RssDestDriver *self = g_new0 (RssDestDriver, 1); log_dest_driver_init_instance (&self->super); self->super.super.super.queue = rss_dd_queue; self->super.super.super.init = rss_dd_init; self->super.super.super.deinit = rss_dd_deinit; self->super.super.super.free_fn = rss_dd_free; self->backlog = NULL; return &self->super.super; } extern CfgParser rss_dd_parser; static Plugin rss_plugin = { .type = LL_CONTEXT_DESTINATION, .name = "rss", .parser = &rss_parser, }; gboolean rss_module_init (GlobalConfig * cfg, CfgArgs * args) { plugin_register (cfg, &rss_plugin, 1); return TRUE; } const ModuleInfo module_info = { .canonical_name = "rss", .version = VERSION, .description = "The rss module is a destination driver to offer logs in RSS feed.", .core_revision = VERSION_CURRENT_VER_ONLY, .plugins = &rss_plugin, .plugins_len = 1, }; syslog-ng-incubator-0.1.0/modules/rss/rss.h000066400000000000000000000031441225757511400206700ustar00rootroot00000000000000/* * Copyright (c) 2013 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2013 Tusa Viktor * * 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 library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; 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 RSS_H_INCLUDED #define RSS_H_INCLUDED #include "driver.h" #include typedef struct { LogDestDriver super; GList* backlog; int port; int id; GMutex* lock; LogTemplate* entry_title; LogTemplate* entry_description; struct iv_fd listen_fd; GString *address; GString* feed_title; } RssDestDriver; LogDriver *rss_dd_new(void); void rss_dd_set_port(LogDriver *self, int port); void rss_dd_set_localip(LogDriver *s, gchar *localip); void rss_dd_set_title(LogDriver *s, const char *title); void rss_dd_set_entry_title(LogDriver *s, const char *title); void rss_dd_set_entry_description(LogDriver *s, const char *title); #endif syslog-ng-incubator-0.1.0/modules/trigger-source/000077500000000000000000000000001225757511400220405ustar00rootroot00000000000000syslog-ng-incubator-0.1.0/modules/trigger-source/Makefile.am000066400000000000000000000024441225757511400241000ustar00rootroot00000000000000module_LTLIBRARIES += modules/trigger-source/libtrigger-source.la modules_trigger_source_libtrigger_source_la_CFLAGS = \ $(SYSLOG_NG_CFLAGS) \ $(EVENTLOG_CFLAGS) \ $(IVYKIS_CFLAGS) \ -I$(top_srcdir)/modules/trigger-source \ -I$(top_builddir)/modules/trigger-source modules_trigger_source_libtrigger_source_la_SOURCES = \ modules/trigger-source/trigger-source-grammar.y \ modules/trigger-source/trigger-source.c \ modules/trigger-source/trigger-source.h \ modules/trigger-source/trigger-source-parser.c \ modules/trigger-source/trigger-source-parser.h \ modules/trigger-source/trigger-source-plugin.c modules_trigger_source_libtrigger_source_la_LIBADD = \ $(EVENTLOG_LIBS) \ $(SYSLOG_NG_LIBS) \ $(IVYKIS_LIBS) modules_trigger_source_libtrigger_source_la_LDFLAGS = \ -avoid-version -module -no-undefined modules/trigger-source mod-trigger: modules/trigger-source/libtrigger-source.la BUILT_SOURCES += \ modules/trigger-source/trigger-source-grammar.y \ modules/trigger-source/trigger-source-grammar.c \ modules/trigger-source/trigger-source-grammar.h EXTRA_DIST += \ modules/trigger-source/trigger-source-grammar.ym \ modules/trigger-source/trigger-source-example.conf .PHONY: modules/trigger-source mod-trigger syslog-ng-incubator-0.1.0/modules/trigger-source/trigger-source-example.conf000066400000000000000000000006511225757511400273030ustar00rootroot00000000000000@version: 3.5 source s_trigger { trigger( program-override("trigger") host-override("trigger-host") tags("trigger-happy") trigger-freq(5) trigger-message("Trigger source is trigger happy!") ); }; destination d_triggered { file("/tmp/triggers.log" template("$(format-json --scope syslog-proto --scope sdata --scope selected-macros)\n") ); }; log { source(s_trigger); destination(d_triggered); }; syslog-ng-incubator-0.1.0/modules/trigger-source/trigger-source-grammar.ym000066400000000000000000000042251225757511400267770ustar00rootroot00000000000000/* * 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 "trigger-source-parser.h" } %code { #include "cfg-grammar.h" #include "cfg-parser.h" #include "plugin.h" } %name-prefix "trigger_" %lex-param {CfgLexer *lexer} %parse-param {CfgLexer *lexer} %parse-param {LogDriver **instance} %parse-param {gpointer arg} /* INCLUDE_DECLS */ %token KW_TRIGGER %token KW_TRIGGER_FREQ %token KW_TRIGGER_MESSAGE %% start : LL_CONTEXT_SOURCE KW_TRIGGER { last_driver = *instance = trigger_sd_new (); } '(' trigger_source_params ')' { YYACCEPT; } ; trigger_source_params : { last_source_options = trigger_sd_get_source_options (last_driver); } trigger_source_options ; trigger_source_options : trigger_source_option trigger_source_options | ; trigger_source_option : source_option | KW_TRIGGER_FREQ '(' LL_NUMBER ')' { trigger_sd_set_trigger_freq (last_driver, $3); } | KW_TRIGGER_MESSAGE '(' string ')' { trigger_sd_set_trigger_message (last_driver, $3); free ($3); } ; /* INCLUDE_RULES */ %% syslog-ng-incubator-0.1.0/modules/trigger-source/trigger-source-parser.c000066400000000000000000000033151225757511400264410ustar00rootroot00000000000000/* * 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 "trigger-source.h" #include "cfg-parser.h" #include "trigger-source-grammar.h" extern int trigger_source_debug; int trigger_parse(CfgLexer *lexer, LogDriver **instance, gpointer arg); static CfgLexerKeyword trigger_keywords[] = { { "trigger", KW_TRIGGER }, { "trigger_freq", KW_TRIGGER_FREQ }, { "trigger_message", KW_TRIGGER_MESSAGE }, { NULL } }; CfgParser trigger_parser = { #if ENABLE_DEBUG .debug_flag = &trigger_source_debug, #endif .name = "trigger-source", .keywords = trigger_keywords, .parse = (int (*)(CfgLexer *lexer, gpointer *instance, gpointer)) trigger_parse, .cleanup = (void (*)(gpointer)) log_pipe_unref, }; CFG_PARSER_IMPLEMENT_LEXER_BINDING(trigger_, LogDriver **) syslog-ng-incubator-0.1.0/modules/trigger-source/trigger-source-parser.h000066400000000000000000000023561225757511400264520ustar00rootroot00000000000000/* * 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 "cfg-parser.h" #include "cfg-lexer.h" #include "trigger-source.h" extern CfgParser trigger_source_parser; CFG_PARSER_DECLARE_LEXER_BINDING(trigger_, LogDriver **) #endif syslog-ng-incubator-0.1.0/modules/trigger-source/trigger-source-plugin.c000066400000000000000000000031361225757511400264440ustar00rootroot00000000000000/* * 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 "trigger-source.h" #include "trigger-source-parser.h" #include "plugin.h" #include "plugin-types.h" extern CfgParser trigger_parser; static Plugin trigger_plugin = { .type = LL_CONTEXT_SOURCE, .name = "trigger", .parser = &trigger_parser, }; gboolean trigger_module_init(GlobalConfig *cfg, CfgArgs *args G_GNUC_UNUSED) { plugin_register(cfg, &trigger_plugin, 1); return TRUE; } const ModuleInfo module_info = { .canonical_name = "trigger", .version = VERSION, .description = "The trigger module provides stuff.", .core_revision = VERSION_CURRENT_VER_ONLY, .plugins = &trigger_plugin, .plugins_len = 1, }; syslog-ng-incubator-0.1.0/modules/trigger-source/trigger-source.c000066400000000000000000000137171225757511400251560ustar00rootroot00000000000000/* * 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 "trigger-source.h" #include "driver.h" #include "logsource.h" #include "mainloop.h" typedef struct { gint trigger_freq; gchar *message; } TriggerOptions; typedef struct _TriggerSourceDriver { LogSrcDriver super; LogSource *source; LogSourceOptions source_options; TriggerOptions options; } TriggerSourceDriver; typedef struct { LogSource super; struct iv_timer trigger_timer; gboolean watches_running; TriggerOptions *options; } TriggerSource; #ifndef SCS_TRIGGER #define SCS_TRIGGER 0 #endif /* * TriggerSource */ static void trigger_source_update_watches (TriggerSource *self); static void trigger_source_triggered (gpointer s) { TriggerSource *self = (TriggerSource *) s; LogMessage *msg; LogPathOptions path_options = LOG_PATH_OPTIONS_INIT; main_loop_assert_main_thread (); if (!log_source_free_to_send (&self->super)) goto end; msg = log_msg_new_internal (LOG_INFO, self->options->message); path_options.ack_needed = FALSE; log_pipe_queue (&self->super.super, msg, &path_options); end: trigger_source_update_watches (self); } static void trigger_source_init_watches (TriggerSource *self) { IV_TIMER_INIT (&self->trigger_timer); self->trigger_timer.cookie = self; self->trigger_timer.handler = trigger_source_triggered; } static void trigger_source_start_watches (TriggerSource *self) { if (self->watches_running) return; if (self->trigger_timer.expires.tv_sec >= 0) iv_timer_register (&self->trigger_timer); self->watches_running = TRUE; } static void trigger_source_stop_watches (TriggerSource *self) { if (!self->watches_running) return; if (iv_timer_registered (&self->trigger_timer)) iv_timer_unregister (&self->trigger_timer); self->watches_running = FALSE; } static void trigger_source_update_watches (TriggerSource *self) { if (!log_source_free_to_send (&self->super)) { trigger_source_stop_watches (self); return; } iv_validate_now (); trigger_source_stop_watches (self); self->trigger_timer.expires = iv_now; self->trigger_timer.expires.tv_sec += self->options->trigger_freq; trigger_source_start_watches (self); } static gboolean trigger_source_init (LogPipe *s) { TriggerSource *self = (TriggerSource *)s; if (!log_source_init (s)) return FALSE; iv_validate_now (); self->trigger_timer.expires = iv_now; self->trigger_timer.expires.tv_sec += self->options->trigger_freq; trigger_source_start_watches (self); return TRUE; } static gboolean trigger_source_deinit (LogPipe *s) { TriggerSource *self = (TriggerSource *)s; trigger_source_stop_watches (self); return log_source_deinit (s); } static LogSource * trigger_source_new (TriggerSourceDriver *owner, LogSourceOptions *options) { TriggerSource *self = g_new0 (TriggerSource, 1); log_source_init_instance (&self->super); log_source_set_options (&self->super, options, 0, SCS_TRIGGER, owner->super.super.id, NULL, FALSE); self->options = &owner->options; trigger_source_init_watches (self); self->super.super.init = trigger_source_init; self->super.super.deinit = trigger_source_deinit; return &self->super; } /* * TriggerSourceDriver */ static gboolean trigger_sd_init (LogPipe *s) { TriggerSourceDriver *self = (TriggerSourceDriver *)s; GlobalConfig *cfg = log_pipe_get_config (s); if (!log_src_driver_init_method (s)) return FALSE; if (self->options.trigger_freq <= 0) self->options.trigger_freq = 10; if (!self->options.message) self->options.message = g_strdup ("Trigger source is trigger happy."); log_source_options_init (&self->source_options, cfg, self->super.super.group); self->source = trigger_source_new (self, &self->source_options); log_pipe_append (&self->source->super, s); log_pipe_init (&self->source->super, cfg); return TRUE; } static gboolean trigger_sd_deinit (LogPipe *s) { TriggerSourceDriver *self = (TriggerSourceDriver *)s; if (self->source) { log_pipe_deinit (&self->source->super); log_pipe_unref (&self->source->super); self->source = NULL; } g_free (self->options.message); return log_src_driver_deinit_method (s); } LogSourceOptions * trigger_sd_get_source_options (LogDriver *s) { TriggerSourceDriver *self = (TriggerSourceDriver *)s; return &self->source_options; } void trigger_sd_set_trigger_freq (LogDriver *s, gint freq) { TriggerSourceDriver *self = (TriggerSourceDriver *)s; self->options.trigger_freq = freq; } void trigger_sd_set_trigger_message (LogDriver *s, const gchar *message) { TriggerSourceDriver *self = (TriggerSourceDriver *)s; g_free (self->options.message); self->options.message = g_strdup (message); } LogDriver * trigger_sd_new (void) { TriggerSourceDriver *self = g_new0 (TriggerSourceDriver, 1); log_src_driver_init_instance ((LogSrcDriver *)&self->super); self->super.super.super.init = trigger_sd_init; self->super.super.super.deinit = trigger_sd_deinit; log_source_options_defaults (&self->source_options); return (LogDriver *)self; } syslog-ng-incubator-0.1.0/modules/trigger-source/trigger-source.h000066400000000000000000000025071225757511400251560ustar00rootroot00000000000000/* * 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 "driver.h" #include "logsource.h" LogDriver *trigger_sd_new (void); void trigger_sd_set_trigger_freq (LogDriver *s, gint freq); LogSourceOptions *trigger_sd_get_source_options (LogDriver *s); void trigger_sd_set_trigger_message (LogDriver *s, const gchar *message); #endif syslog-ng-incubator-0.1.0/tools/000077500000000000000000000000001225757511400165675ustar00rootroot00000000000000syslog-ng-incubator-0.1.0/tools/Makefile.am000066400000000000000000000000441225757511400206210ustar00rootroot00000000000000include tools/visualize/Makefile.am syslog-ng-incubator-0.1.0/tools/visualize/000077500000000000000000000000001225757511400206025ustar00rootroot00000000000000syslog-ng-incubator-0.1.0/tools/visualize/Makefile.am000066400000000000000000000004141225757511400226350ustar00rootroot00000000000000if ENABLE_LOGMONGOURCE bin_PROGRAMS += tools/visualize/logmongource tools_visualize_logmongource_CFLAGS = ${LIBMONGO_CFLAGS} ${GLIB_CFLAGS} tools_visualize_logmongource_LDFLAGS = ${LIBMONGO_LIBS} ${GLIB_LIBS} -lm endif EXTRA_DIST += tools/visualize/README.md syslog-ng-incubator-0.1.0/tools/visualize/README.md000066400000000000000000000024561225757511400220700ustar00rootroot00000000000000Visualisation tools for syslog-ng ================================= One way to visualize the history of log messages that pass through syslog-ng is to wrap them into a format that gource[0] understands: destination d_gource { file("/var/log/gource/logs.src" template("$UNIXTIME|$HOST@$SOURCE|M|$HOST/$PROGRAM/messages")); }; Once this is done, we only need to call gource appropriately, to produce spectacular results: $ gource --log-format custom --auto-skip-seconds 3 \ --seconds-per-day 1 --file-idle-time 1 \ --hide files \ --bloom-intensity 0.25 --bloom-multiplier 0.25 \ --user-friction 0.25 --highlight-all-users \ /var/log/gource/logs.src Of course, one can tweak the options, or even use completely different ones - the possibilities are endless! And if one just so happens to have their logs stored in MongoDB, the logmongource tool in this directory can be used to export the data into a format suitable for gource. For added amusement, it also colors each host differently - something which the destination above cannot do (yet). The tool assumes that the DATE key in the database is a UNIXTIME, but other than that, it uses the standard mongodb() destination defaults. [0]: https://code.google.com/p/gource/ syslog-ng-incubator-0.1.0/tools/visualize/logmongource.c000066400000000000000000000233141225757511400234510ustar00rootroot00000000000000/* * Copyright (c) 2011 BalaBit IT Ltd, Budapest, Hungary * Copyright (c) 2011 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 #include static const gdouble golden_ratio = 0.618033988749895; typedef struct { gchar *host; gint port; gchar *db; gchar *coll; gchar *output; gchar *sort_by; struct { gchar *timestamp; gchar *username; gchar *filename; gchar *color_by; } template; gboolean verbose; /* Computed settings */ gchar *ns; } config_t; static void hsv_to_rgb (gdouble *r, gdouble *g, gdouble *b, gdouble h, gdouble s, gdouble v) { gint i; gdouble f, p, q, t; if (s == 0) { *r = *g = *b = v; return; } h /= 60; i = floor (h); f = h - i; p = v * (1 - s); q = v * (1 - s * f); t = v * (1 - s * (1 - f)); switch (i) { case 0: *r = v; *g = t; *b = p; break; case 1: *r = q; *g = v; *b = p; break; case 2: *r = p; *g = v; *b = t; break; case 3: *r = p; *g = q; *b = v; break; case 4: *r = t; *g = p; *b = v; break; default: *r = v; *g = p; *b = q; break; } } static gchar * lmg_color_next (gdouble *h) { gdouble r, g, b; *h += golden_ratio; *h = fmod (*h, 1.0); hsv_to_rgb (&r, &g, &b, (*h) * 360, 0.95, 0.95); return g_strdup_printf ("%02X%02X%02X", (gint)(r * 255), (gint)(g * 255), (gint)(b * 255)); } static gboolean lmg_regex_eval_cb (const GMatchInfo *info, GString *res, gpointer data) { bson *msg = (bson *)data; bson_cursor *c; gchar *match; const gchar *r; match = g_match_info_fetch (info, 1); c = bson_find (msg, match); if (!c) { g_free (match); return FALSE; } if (!bson_cursor_get_string (c, &r)) { g_free (match); bson_cursor_free (c); return FALSE; } g_string_append (res, r); g_free (match); bson_cursor_free (c); return FALSE; } int main (int argc, char *argv[]) { mongo_sync_connection *conn; mongo_sync_cursor *cursor; mongo_packet *p; bson *query, *empty; GHashTable *host_colors; gdouble h; gint64 cnt, pos = 0; GRand *rnd; GError *error = NULL; GOptionContext *context; config_t config; GOptionEntry entries[] = { { "host", 'h', 0, G_OPTION_ARG_STRING, &config.host, "Host to connect to", "HOST" }, { "port", 'p', 0, G_OPTION_ARG_INT, &config.port, "Port to connect to", "PORT" }, { "db", 'd', 0, G_OPTION_ARG_STRING, &config.db, "Database to use", "DB" }, { "collection", 'c', 0, G_OPTION_ARG_STRING, &config.coll, "Collection tthat stores the log messages", "COLL" }, { "sort-by", 's', 0, G_OPTION_ARG_STRING, &config.sort_by, "Field to sort on", "FIELD" }, { "template-timestamp", 'T', 0, G_OPTION_ARG_STRING, &config.template.timestamp, "Timestamp template", "TEMPLATE" }, { "template-username", 'U', 0, G_OPTION_ARG_STRING, &config.template.username, "Username template", "TEMPLATE" }, { "template-filename", 'F', 0, G_OPTION_ARG_STRING, &config.template.filename, "Filename template", "TEMPLATE" }, { "template-color-by", 'C', 0, G_OPTION_ARG_STRING, &config.template.color_by, "Color key template", "TEMPLATE" }, { "output", 'o', 0, G_OPTION_ARG_STRING, &config.output, "Output file", "FILENAME" }, { "verbose", 'v', 0, G_OPTION_ARG_NONE, &config.verbose, "Be verbose", NULL }, { NULL, 0, 0, 0, NULL, NULL, NULL } }; GRegex *reg; FILE *out; memset (&config, 0, sizeof (config)); context = g_option_context_new ("- MongoDB log to Gource custom format exporter"); g_option_context_add_main_entries (context, entries, "logmongource"); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_print ("option parsing failed: %s\n", error->message); exit (1); } if (!config.host) config.host = g_strdup ("localhost"); if (!config.port) config.port = 27017; if (!config.db) config.db = g_strdup ("syslog"); if (!config.coll) config.coll = g_strdup ("messages"); if (!config.sort_by) config.sort_by = g_strdup ("DATE"); if (!config.template.timestamp) config.template.timestamp = g_strdup ("${DATE}"); if (!config.template.username) config.template.username = g_strdup ("${HOST}@${SOURCE}"); if (!config.template.filename) config.template.filename = g_strdup ("${HOST}/${PROGRAM}/msgs"); if (!config.output) { gchar *help = g_option_context_get_help (context, TRUE, NULL); printf ("%s", help); exit (1); } config.ns = g_strdup_printf ("%s.%s", config.db, config.coll); rnd = g_rand_new (); h = g_rand_double (rnd); g_rand_free (rnd); conn = mongo_sync_connect (config.host, config.port, TRUE); if (!conn) { perror ("logmongource/mongo_sync_connect()"); exit (1); } empty = bson_new (); bson_finish (empty); query = bson_build_full (BSON_TYPE_DOCUMENT, "$query", FALSE, empty, BSON_TYPE_DOCUMENT, "$orderby", TRUE, bson_build (BSON_TYPE_INT32, config.sort_by, 1, BSON_TYPE_NONE), BSON_TYPE_NONE); bson_finish (query); cnt = (gint64)mongo_sync_cmd_count (conn, config.db, config.coll, empty); bson_free (empty); if (cnt < 0) { perror ("logmongource/mongo_sync_cmd_count()"); exit (1); } p = mongo_sync_cmd_query (conn, config.ns, 0, 0, 0, query, NULL); bson_free (query); if (!p) { perror ("logmongource/mongo_sync_cmd_query()"); exit (1); } cursor = mongo_sync_cursor_new (conn, config.ns, p); if (!cursor) { perror ("logmongource/mongo_sync_cursor_new()"); exit (1); } host_colors = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); reg = g_regex_new ("\\$\\{([^\\}]+)\\}", G_REGEX_OPTIMIZE, 0, &error); if (!reg) { g_print ("logmongource/g_regex_new(): %s\n", error->message); exit (1); } if (strcmp (config.output, "-") == 0) out = stdout; else { out = fopen (config.output, "w"); if (!out) { perror ("logmongource/fopen()"); exit (1); } } while (mongo_sync_cursor_next (cursor) && pos < cnt) { bson *data; gchar *ts, *user, *file, *color_by, *hc; data = mongo_sync_cursor_get_data (cursor); ts = g_regex_replace_eval (reg, config.template.timestamp, strlen (config.template.timestamp), 0, 0, lmg_regex_eval_cb, data, &error); user = g_regex_replace_eval (reg, config.template.username, strlen (config.template.username), 0, 0, lmg_regex_eval_cb, data, &error); file = g_regex_replace_eval (reg, config.template.filename, strlen (config.template.filename), 0, 0, lmg_regex_eval_cb, data, &error); if (config.template.color_by) { color_by = g_regex_replace_eval (reg, config.template.color_by, strlen (config.template.color_by), 0, 0, lmg_regex_eval_cb, data, &error); if (!color_by) { fprintf (out, "%s|%s|M|%s\n", ts, user, file); break; } hc = g_hash_table_lookup (host_colors, color_by); if (!hc) { hc = lmg_color_next (&h); g_hash_table_insert (host_colors, g_strdup (color_by), hc); } fprintf (out, "%s|%s|M|%s|%s\n", ts, user, file, hc); g_free (color_by); } else fprintf (out, "%s|%s|M|%s\n", ts, user, file); bson_free (data); g_free (ts); g_free (user); g_free (file); if (pos % 10 == 0 && config.verbose) { fprintf (stderr, "\r%03.02f%%", ((pos * 1.0 / cnt) * 100)); fflush (stderr); } pos++; } if (config.verbose) fprintf (stderr, "\r%02.02f%%\n", ((pos * 1.0 / cnt) * 100)); if (out != stdout) fclose (out); mongo_sync_cursor_free (cursor); mongo_sync_disconnect (conn); g_hash_table_destroy (host_colors); g_regex_unref (reg); g_free (config.host); g_free (config.db); g_free (config.coll); g_free (config.output); g_free (config.sort_by); g_free (config.template.timestamp); g_free (config.template.username); g_free (config.template.filename); g_free (config.ns); g_option_context_free (context); return 0; }