├── .github ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTORS ├── Gemfile ├── LICENSE ├── NOTICE.TXT ├── README.md ├── Rakefile ├── docs └── index.asciidoc ├── lib └── logstash │ └── filters │ └── multiline.rb ├── logstash-filter-multiline.gemspec └── spec └── filters └── multiline_spec.rb /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Logstash 2 | 3 | All contributions are welcome: ideas, patches, documentation, bug reports, 4 | complaints, etc! 5 | 6 | Programming is not a required skill, and there are many ways to help out! 7 | It is more important to us that you are able to contribute. 8 | 9 | That said, some basic guidelines, which you are free to ignore :) 10 | 11 | ## Want to learn? 12 | 13 | Want to lurk about and see what others are doing with Logstash? 14 | 15 | * The irc channel (#logstash on irc.freenode.org) is a good place for this 16 | * The [forum](https://discuss.elastic.co/c/logstash) is also 17 | great for learning from others. 18 | 19 | ## Got Questions? 20 | 21 | Have a problem you want Logstash to solve for you? 22 | 23 | * You can ask a question in the [forum](https://discuss.elastic.co/c/logstash) 24 | * Alternately, you are welcome to join the IRC channel #logstash on 25 | irc.freenode.org and ask for help there! 26 | 27 | ## Have an Idea or Feature Request? 28 | 29 | * File a ticket on [GitHub](https://github.com/elastic/logstash/issues). Please remember that GitHub is used only for issues and feature requests. If you have a general question, the [forum](https://discuss.elastic.co/c/logstash) or IRC would be the best place to ask. 30 | 31 | ## Something Not Working? Found a Bug? 32 | 33 | If you think you found a bug, it probably is a bug. 34 | 35 | * If it is a general Logstash or a pipeline issue, file it in [Logstash GitHub](https://github.com/elasticsearch/logstash/issues) 36 | * If it is specific to a plugin, please file it in the respective repository under [logstash-plugins](https://github.com/logstash-plugins) 37 | * or ask the [forum](https://discuss.elastic.co/c/logstash). 38 | 39 | # Contributing Documentation and Code Changes 40 | 41 | If you have a bugfix or new feature that you would like to contribute to 42 | logstash, and you think it will take more than a few minutes to produce the fix 43 | (ie; write code), it is worth discussing the change with the Logstash users and developers first! You can reach us via [GitHub](https://github.com/elastic/logstash/issues), the [forum](https://discuss.elastic.co/c/logstash), or via IRC (#logstash on freenode irc) 44 | Please note that Pull Requests without tests will not be merged. If you would like to contribute but do not have experience with writing tests, please ping us on IRC/forum or create a PR and ask our help. 45 | 46 | ## Contributing to plugins 47 | 48 | Check our [documentation](https://www.elastic.co/guide/en/logstash/current/contributing-to-logstash.html) on how to contribute to plugins or write your own! It is super easy! 49 | 50 | ## Contribution Steps 51 | 52 | 1. Test your changes! [Run](https://github.com/elastic/logstash#testing) the test suite 53 | 2. Please make sure you have signed our [Contributor License 54 | Agreement](https://www.elastic.co/contributor-agreement/). We are not 55 | asking you to assign copyright to us, but to give us the right to distribute 56 | your code without restriction. We ask this of all contributors in order to 57 | assure our users of the origin and continuing existence of the code. You 58 | only need to sign the CLA once. 59 | 3. Send a pull request! Push your changes to your fork of the repository and 60 | [submit a pull 61 | request](https://help.github.com/articles/using-pull-requests). In the pull 62 | request, describe what your changes do and mention any bugs/issues related 63 | to the pull request. 64 | 65 | 66 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Please post all product and debugging questions on our [forum](https://discuss.elastic.co/c/logstash). Your questions will reach our wider community members there, and if we confirm that there is a bug, then we can open a new issue here. 2 | 3 | For all general issues, please provide the following details for fast resolution: 4 | 5 | - Version: 6 | - Operating System: 7 | - Config File (if you have sensitive info, please remove it): 8 | - Sample Data: 9 | - Steps to Reproduce: 10 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thanks for contributing to Logstash! If you haven't already signed our CLA, here's a handy link: https://www.elastic.co/contributor-agreement/ 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | Gemfile.lock 3 | .bundle 4 | vendor 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | import: 2 | - logstash-plugins/.ci:travis/travis.yml@1.x -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 3.0.4 2 | - Fix some documentation issues 3 | 4 | ## 3.0.2 5 | - Relax constraint on logstash-core-plugin-api to >= 1.60 <= 2.99 6 | 7 | ## 3.0.1 8 | - Republish all the gems under jruby. 9 | ## 3.0.0 10 | - Update the plugin to the version 2.0 of the plugin api, this change is required for Logstash 5.0 compatibility. See https://github.com/elastic/logstash/issues/5141 11 | # 2.0.5 12 | - Depend on logstash-core-plugin-api instead of logstash-core, removing the need to mass update plugins on major releases of logstash 13 | # 2.0.4 14 | - New dependency requirements for logstash-core for the 5.0 release 15 | ## 2.0.3 16 | - Fix metadata handling, fixes #19 and #22 17 | ## 2.0.0 18 | - Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully, 19 | instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895 20 | - Dependency on logstash-core update to 2.0 21 | 22 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | The following is a list of people who have contributed ideas, code, bug 2 | reports, or in general have helped logstash along its way. 3 | 4 | Contributors: 5 | * Aaron Mildenstein (untergeek) 6 | * Colin Surprenant (colinsurprenant) 7 | * John E. Vincent (lusis) 8 | * Jordan Sissel (jordansissel) 9 | * Kurt Hurtado (kurtado) 10 | * Laust Rud Jacobsen (rud) 11 | * Nick Ethier (nickethier) 12 | * Pete Fritchman (fetep) 13 | * Philippe Weber (wiibaa) 14 | * Pier-Hugues Pellerin (ph) 15 | * R. Toma (rtoma) 16 | * Richard Pijnenburg (electrical) 17 | * Suyog Rao (suyograo) 18 | * yummylogs 19 | 20 | Note: If you've sent us patches, bug reports, or otherwise contributed to 21 | Logstash, and you aren't on the list above and want to be, please let us know 22 | and we'll make sure you're here. Contributions from folks like you are what make 23 | open source awesome. 24 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | 5 | logstash_path = ENV["LOGSTASH_PATH"] || "../../logstash" 6 | use_logstash_source = ENV["LOGSTASH_SOURCE"] && ENV["LOGSTASH_SOURCE"].to_s == "1" 7 | 8 | if Dir.exist?(logstash_path) && use_logstash_source 9 | gem 'logstash-core', :path => "#{logstash_path}/logstash-core" 10 | gem 'logstash-core-plugin-api', :path => "#{logstash_path}/logstash-core-plugin-api" 11 | end 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2020 Elastic and contributors 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /NOTICE.TXT: -------------------------------------------------------------------------------- 1 | Elasticsearch 2 | Copyright 2012-2015 Elasticsearch 3 | 4 | This product includes software developed by The Apache Software 5 | Foundation (http://www.apache.org/). -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Logstash Plugin 2 | 3 | [![Travis Build Status](https://travis-ci.com/logstash-plugins/logstash-filter-multiline.svg)](https://travis-ci.com/logstash-plugins/logstash-filter-multiline) 4 | 5 | This is a plugin for [Logstash](https://github.com/elastic/logstash). 6 | 7 | It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way. 8 | 9 | ## Documentation 10 | 11 | Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/). 12 | 13 | - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive 14 | - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide 15 | 16 | ## Need Help? 17 | 18 | Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum. 19 | 20 | ## Developing 21 | 22 | ### 1. Plugin Developement and Testing 23 | 24 | #### Code 25 | - To get started, you'll need JRuby with the Bundler gem installed. 26 | 27 | - Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example). 28 | 29 | - Install dependencies 30 | ```sh 31 | bundle install 32 | ``` 33 | 34 | #### Test 35 | 36 | - Update your dependencies 37 | 38 | ```sh 39 | bundle install 40 | ``` 41 | 42 | - Run tests 43 | 44 | ```sh 45 | bundle exec rspec 46 | ``` 47 | 48 | ### 2. Running your unpublished Plugin in Logstash 49 | 50 | #### 2.1 Run in a local Logstash clone 51 | 52 | - Edit Logstash `Gemfile` and add the local plugin path, for example: 53 | ```ruby 54 | gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome" 55 | ``` 56 | - Install plugin 57 | ```sh 58 | # Logstash 2.3 and higher 59 | bin/logstash-plugin install --no-verify 60 | 61 | # Prior to Logstash 2.3 62 | bin/plugin install --no-verify 63 | 64 | ``` 65 | - Run Logstash with your plugin 66 | ```sh 67 | bin/logstash -e 'filter {awesome {}}' 68 | ``` 69 | At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash. 70 | 71 | #### 2.2 Run in an installed Logstash 72 | 73 | You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using: 74 | 75 | - Build your plugin gem 76 | ```sh 77 | gem build logstash-filter-awesome.gemspec 78 | ``` 79 | - Install the plugin from the Logstash home 80 | ```sh 81 | # Logstash 2.3 and higher 82 | bin/logstash-plugin install --no-verify 83 | 84 | # Prior to Logstash 2.3 85 | bin/plugin install --no-verify 86 | 87 | ``` 88 | - Start Logstash and proceed to test the plugin 89 | 90 | ## Contributing 91 | 92 | All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin. 93 | 94 | Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here. 95 | 96 | It is more important to the community that you are able to contribute. 97 | 98 | For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file. -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | @files=[] 2 | 3 | task :default do 4 | system("rake -T") 5 | end 6 | 7 | require "logstash/devutils/rake" 8 | -------------------------------------------------------------------------------- /docs/index.asciidoc: -------------------------------------------------------------------------------- 1 | :plugin: multiline 2 | :type: filter 3 | 4 | /////////////////////////////////////////// 5 | START - GENERATED VARIABLES, DO NOT EDIT! 6 | /////////////////////////////////////////// 7 | :version: %VERSION% 8 | :release_date: %RELEASE_DATE% 9 | :changelog_url: %CHANGELOG_URL% 10 | :include_path: ../../../../logstash/docs/include 11 | /////////////////////////////////////////// 12 | END - GENERATED VARIABLES, DO NOT EDIT! 13 | /////////////////////////////////////////// 14 | 15 | [id="plugins-{type}s-{plugin}"] 16 | 17 | === Multiline filter plugin 18 | 19 | include::{include_path}/plugin_header.asciidoc[] 20 | 21 | ==== Description 22 | 23 | 24 | This filter will collapse multiline messages from a single source into one Logstash event. 25 | 26 | The original goal of this filter was to allow joining of multi-line messages 27 | from files into a single event. For example - joining java exception and 28 | stacktrace messages into a single event. 29 | 30 | NOTE: This filter will not work with multiple worker threads `-w 2` on the logstash command line. 31 | 32 | The config looks like this: 33 | [source,ruby] 34 | filter { 35 | multiline { 36 | pattern => "pattern, a regexp" 37 | negate => boolean 38 | what => "previous" or "next" 39 | } 40 | } 41 | 42 | The `pattern` should be a regexp ({logstash-ref}/plugins-filters-grok.html[grok] patterns are 43 | supported) which matches what you believe to be an indicator that the field 44 | is part of an event consisting of multiple lines of log data. 45 | 46 | The `what` must be `previous` or `next` and indicates the relation 47 | to the multi-line event. 48 | 49 | The `negate` can be `true` or `false` (defaults to `false`). If `true`, a 50 | message not matching the pattern will constitute a match of the multiline 51 | filter and the `what` will be applied. (vice-versa is also true) 52 | 53 | For example, Java stack traces are multiline and usually have the message 54 | starting at the far-left, with each subsequent line indented. Do this: 55 | [source,ruby] 56 | filter { 57 | multiline { 58 | pattern => "^\s" 59 | what => "previous" 60 | } 61 | } 62 | 63 | This says that any line starting with whitespace belongs to the previous line. 64 | 65 | Another example is C line continuations (backslash). Here's how to do that: 66 | [source,ruby] 67 | filter { 68 | multiline { 69 | pattern => "\\$" 70 | what => "next" 71 | } 72 | } 73 | 74 | This says that any line ending with a backslash should be combined with the 75 | following line. 76 | 77 | 78 | [id="plugins-{type}s-{plugin}-options"] 79 | ==== Multiline Filter Configuration Options 80 | 81 | This plugin supports the following configuration options plus the <> described later. 82 | 83 | [cols="<,<,<",options="header",] 84 | |======================================================================= 85 | |Setting |Input type|Required 86 | | <> |<>|No 87 | | <> |<>|No 88 | | <> |<>|No 89 | | <> |<>|Yes 90 | | <> |<>|No 91 | | <> |<>|No 92 | | <> |<>|No 93 | | <> |<>, one of `["previous", "next"]`|Yes 94 | |======================================================================= 95 | 96 | Also see <> for a list of options supported by all 97 | filter plugins. 98 | 99 |   100 | 101 | [id="plugins-{type}s-{plugin}-allow_duplicates"] 102 | ===== `allow_duplicates` 103 | 104 | * Value type is <> 105 | * Default value is `true` 106 | 107 | Allow duplcate values on the source field. 108 | 109 | [id="plugins-{type}s-{plugin}-max_age"] 110 | ===== `max_age` 111 | 112 | * Value type is <> 113 | * Default value is `5` 114 | 115 | The maximum age an event can be (in seconds) before it is automatically 116 | flushed. 117 | 118 | [id="plugins-{type}s-{plugin}-negate"] 119 | ===== `negate` 120 | 121 | * Value type is <> 122 | * Default value is `false` 123 | 124 | Negate the regexp pattern ('if not matched') 125 | 126 | [id="plugins-{type}s-{plugin}-pattern"] 127 | ===== `pattern` 128 | 129 | * This is a required setting. 130 | * Value type is <> 131 | * There is no default value for this setting. 132 | 133 | The expression to match. The same matching engine as the 134 | {logstash-ref}/plugins-filters-grok.html[grok filter] is used, so the expression can contain 135 | a plain regular expression or one that also contains grok patterns. 136 | 137 | [id="plugins-{type}s-{plugin}-patterns_dir"] 138 | ===== `patterns_dir` 139 | 140 | * Value type is <> 141 | * Default value is `[]` 142 | 143 | Logstash ships by default with a bunch of patterns, so you don't 144 | necessarily need to define this yourself unless you are adding additional 145 | patterns. 146 | 147 | Pattern files are plain text with format: 148 | [source,ruby] 149 | NAME PATTERN 150 | 151 | For example: 152 | [source,ruby] 153 | NUMBER \d+ 154 | 155 | [id="plugins-{type}s-{plugin}-source"] 156 | ===== `source` 157 | 158 | * Value type is <> 159 | * Default value is `"message"` 160 | 161 | The field name to execute the pattern match on. 162 | 163 | [id="plugins-{type}s-{plugin}-stream_identity"] 164 | ===== `stream_identity` 165 | 166 | * Value type is <> 167 | * Default value is `"%{host}.%{path}.%{type}"` 168 | 169 | The stream identity is how the multiline filter determines which stream an 170 | event belongs to. This is generally used for differentiating, say, events 171 | coming from multiple files in the same file input, or multiple connections 172 | coming from a tcp input. 173 | 174 | The default value here is usually what you want, but there are some cases 175 | where you want to change it. One such example is if you are using a tcp 176 | input with only one client connecting at any time. If that client 177 | reconnects (due to error or client restart), then logstash will identify 178 | the new connection as a new stream and break any multiline goodness that 179 | may have occurred between the old and new connection. To solve this use 180 | case, you can use `%{@source_host}.%{@type}` instead. 181 | 182 | [id="plugins-{type}s-{plugin}-what"] 183 | ===== `what` 184 | 185 | * This is a required setting. 186 | * Value can be any of: `previous`, `next` 187 | * There is no default value for this setting. 188 | 189 | If the pattern matched, does event belong to the next or previous event? 190 | 191 | 192 | 193 | [id="plugins-{type}s-{plugin}-common-options"] 194 | include::{include_path}/{type}.asciidoc[] 195 | -------------------------------------------------------------------------------- /lib/logstash/filters/multiline.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require "logstash/filters/base" 3 | require "logstash/namespace" 4 | require "logstash/environment" 5 | require "logstash/patterns/core" 6 | require "set" 7 | # 8 | # This filter will collapse multiline messages from a single source into one Logstash event. 9 | # 10 | # The original goal of this filter was to allow joining of multi-line messages 11 | # from files into a single event. For example - joining java exception and 12 | # stacktrace messages into a single event. 13 | # 14 | # NOTE: This filter will not work with multiple worker threads `-w 2` on the logstash command line. 15 | # 16 | # The config looks like this: 17 | # [source,ruby] 18 | # filter { 19 | # multiline { 20 | # pattern => "pattern, a regexp" 21 | # negate => boolean 22 | # what => "previous" or "next" 23 | # } 24 | # } 25 | # 26 | # The `pattern` should be a regexp (<> patterns are 27 | # supported) which matches what you believe to be an indicator that the field 28 | # is part of an event consisting of multiple lines of log data. 29 | # 30 | # The `what` must be `previous` or `next` and indicates the relation 31 | # to the multi-line event. 32 | # 33 | # The `negate` can be `true` or `false` (defaults to `false`). If `true`, a 34 | # message not matching the pattern will constitute a match of the multiline 35 | # filter and the `what` will be applied. (vice-versa is also true) 36 | # 37 | # For example, Java stack traces are multiline and usually have the message 38 | # starting at the far-left, with each subsequent line indented. Do this: 39 | # [source,ruby] 40 | # filter { 41 | # multiline { 42 | # pattern => "^\s" 43 | # what => "previous" 44 | # } 45 | # } 46 | # 47 | # This says that any line starting with whitespace belongs to the previous line. 48 | # 49 | # Another example is C line continuations (backslash). Here's how to do that: 50 | # [source,ruby] 51 | # filter { 52 | # multiline { 53 | # pattern => "\\$" 54 | # what => "next" 55 | # } 56 | # } 57 | # 58 | # This says that any line ending with a backslash should be combined with the 59 | # following line. 60 | # 61 | class LogStash::Filters::Multiline < LogStash::Filters::Base 62 | 63 | config_name "multiline" 64 | 65 | # The field name to execute the pattern match on. 66 | config :source, :validate => :string, :default => "message" 67 | 68 | # Allow duplcate values on the source field. 69 | config :allow_duplicates, :validate => :boolean, :default => true 70 | 71 | # The expression to match. The same matching engine as the 72 | # <> is used, so the expression can contain 73 | # a plain regular expression or one that also contains grok patterns. 74 | config :pattern, :validate => :string, :required => true 75 | 76 | # If the pattern matched, does event belong to the next or previous event? 77 | config :what, :validate => ["previous", "next"], :required => true 78 | 79 | # Negate the regexp pattern ('if not matched') 80 | config :negate, :validate => :boolean, :default => false 81 | 82 | # The stream identity is how the multiline filter determines which stream an 83 | # event belongs to. This is generally used for differentiating, say, events 84 | # coming from multiple files in the same file input, or multiple connections 85 | # coming from a tcp input. 86 | # 87 | # The default value here is usually what you want, but there are some cases 88 | # where you want to change it. One such example is if you are using a tcp 89 | # input with only one client connecting at any time. If that client 90 | # reconnects (due to error or client restart), then logstash will identify 91 | # the new connection as a new stream and break any multiline goodness that 92 | # may have occurred between the old and new connection. To solve this use 93 | # case, you can use `%{@source_host}.%{@type}` instead. 94 | config :stream_identity , :validate => :string, :default => "%{host}.%{path}.%{type}" 95 | 96 | # Logstash ships by default with a bunch of patterns, so you don't 97 | # necessarily need to define this yourself unless you are adding additional 98 | # patterns. 99 | # 100 | # Pattern files are plain text with format: 101 | # [source,ruby] 102 | # NAME PATTERN 103 | # 104 | # For example: 105 | # [source,ruby] 106 | # NUMBER \d+ 107 | config :patterns_dir, :validate => :array, :default => [] 108 | 109 | # The maximum age an event can be (in seconds) before it is automatically 110 | # flushed. 111 | config :max_age, :validate => :number, :default => 5 112 | 113 | # Call the filter flush method at regular interval. 114 | # Optional. 115 | config :periodic_flush, :validate => :boolean, :default => true 116 | 117 | # Register default pattern paths 118 | @@patterns_path = Set.new 119 | @@patterns_path += [LogStash::Patterns::Core.path] 120 | 121 | MULTILINE_TAG = "multiline" 122 | 123 | public 124 | def initialize(config = {}) 125 | super 126 | 127 | # this filter cannot be parallelized because message order 128 | # cannot be garanteed across threads, line #2 could be processed 129 | # before line #1 130 | @threadsafe = false 131 | 132 | # this filter needs to keep state 133 | @pending = Hash.new 134 | end # def initialize 135 | 136 | public 137 | def register 138 | require "grok-pure" # rubygem 'jls-grok' 139 | 140 | @grok = Grok.new 141 | 142 | @patterns_dir = @@patterns_path.to_a + @patterns_dir 143 | @patterns_dir.each do |path| 144 | path = File.join(path, "*") if File.directory?(path) 145 | Dir.glob(path).each do |file| 146 | @logger.info("Grok loading patterns from file", :path => file) 147 | @grok.add_patterns_from_file(file) 148 | end 149 | end 150 | 151 | @grok.compile(@pattern) 152 | 153 | case @what 154 | when "previous" 155 | class << self; alias_method :multiline_filter!, :previous_filter!; end 156 | when "next" 157 | class << self; alias_method :multiline_filter!, :next_filter!; end 158 | else 159 | # we should never get here since @what is validated at config 160 | raise(ArgumentError, "Unknown multiline 'what' value") 161 | end # case @what 162 | 163 | @logger.debug("Registered multiline plugin", :type => @type, :config => @config) 164 | end # def register 165 | 166 | public 167 | def filter(event) 168 | match = event.get(@source).is_a?(Array) ? @grok.match(event.get(@source).first) : @grok.match(event.get(@source)) 169 | match = (match && !@negate) || (!match && @negate) # add negate option 170 | 171 | @logger.debug? && @logger.debug("Multiline", :pattern => @pattern, :message => event.get(@source), :match => match, :negate => @negate) 172 | 173 | multiline_filter!(event, match) 174 | 175 | filter_matched(event) unless event.cancelled? 176 | end # def filter 177 | 178 | # flush any pending messages 179 | # called at regular interval without options and at pipeline shutdown with the :final => true option 180 | # @param options [Hash] 181 | # @option options [Boolean] :final => true to signal a final shutdown flush 182 | # @return [Array] list of flushed events 183 | public 184 | def flush(options = {}) 185 | # note that thread safety concerns are not necessary here because the multiline filter 186 | # is not thread safe thus cannot be run in multiple filterworker threads and flushing 187 | # is called by the same thread 188 | 189 | # select all expired events from the @pending hash into a new expired hash 190 | # if :final flush then select all events 191 | expired = @pending.inject({}) do |result, (key, events)| 192 | unless events.empty? 193 | age = Time.now - events.first.get("@timestamp").time 194 | result[key] = events if (age >= @max_age) || options[:final] 195 | end 196 | result 197 | end 198 | 199 | # return list of uncancelled expired events 200 | expired.map do |key, events| 201 | @pending.delete(key) 202 | event = merge(events) 203 | event.uncancel 204 | filter_matched(event) 205 | event 206 | end 207 | end # def flush 208 | 209 | public 210 | def close 211 | # nothing to do 212 | end 213 | 214 | private 215 | 216 | def previous_filter!(event, match) 217 | key = event.sprintf(@stream_identity) 218 | pending = @pending[key] ||= [] 219 | 220 | if match 221 | # previous previous line is part of this event. append it to the event and cancel it 222 | event.tag(MULTILINE_TAG) 223 | pending << event 224 | event.cancel 225 | else 226 | # this line is not part of the previous event if we have a pending event, it's done, send it. 227 | # put the current event into pending 228 | unless pending.empty? 229 | tmp = event.to_hash_with_metadata 230 | merged_events = merge(pending) 231 | event.overwrite(merged_events) 232 | event.set("@metadata", merged_events.get("@metadata")) # Override does not copy the metadata 233 | pending.clear # avoid array creation 234 | pending << LogStash::Event.new(tmp) 235 | else 236 | pending.clear # avoid array creation 237 | pending << event 238 | event.cancel 239 | end 240 | end # if match 241 | end 242 | 243 | def next_filter!(event, match) 244 | key = event.sprintf(@stream_identity) 245 | pending = @pending[key] ||= [] 246 | 247 | if match 248 | # this line is part of a multiline event, the next line will be part, too, put it into pending. 249 | event.tag(MULTILINE_TAG) 250 | pending << event 251 | event.cancel 252 | else 253 | # if we have something in pending, join it with this message and send it. 254 | # otherwise, this is a new message and not part of multiline, send it. 255 | unless pending.empty? 256 | merged_events = merge(pending << event) 257 | event.overwrite(merged_events) 258 | event.set("@metadata", merged_events.get("@metadata")) # Override does not copy the metadata 259 | pending.clear 260 | end 261 | end # if match 262 | end 263 | 264 | # merge a list of events. @timestamp for the resulting merged event will be from 265 | # the "oldest" (events.first). all @source fields will be deduplicated depending 266 | # on @allow_duplicates and joined with \n. all other fields will be deduplicated. 267 | # @param events [Array] the list of events to merge 268 | # @return [Event] the resulting merged event 269 | def merge(events) 270 | dups_key = @allow_duplicates ? @source : nil 271 | 272 | data = events.inject({}) do |result, event| 273 | self.class.event_hash_merge!(result, event.to_hash_with_metadata, dups_key) 274 | end 275 | 276 | # merged event @timestamp is from first event in sequence 277 | data["@timestamp"] = Array(data["@timestamp"]).first 278 | # collapse all @source field values 279 | data[@source] = Array(data[@source]).join("\n") 280 | LogStash::Event.new(data) 281 | end 282 | 283 | # merge two events data hash, src into dst and handle duplicate values for dups_key 284 | # @param dst [Hash] the event to merge into, dst will be mutated 285 | # @param src [Hash] the event to merge in dst 286 | # @param dups_key [String] the field key to keep duplicate values 287 | # @return [Hash] mutated dst 288 | def self.event_hash_merge!(dst, src, dups_key = nil) 289 | src.each do |key, svalue| 290 | dst[key] = if dst.has_key?(key) 291 | dvalue = dst[key] 292 | 293 | if dvalue.is_a?(Hash) && svalue.is_a?(Hash) 294 | event_hash_merge!(dvalue, svalue, dups_key) 295 | else 296 | v = (dups_key == key) ? Array(dvalue) + Array(svalue) : Array(dvalue) | Array(svalue) 297 | # the v result is always an Array, if none of the fields were arrays and there is a 298 | # single value in the array, return the value, not the array 299 | dvalue.is_a?(Array) || svalue.is_a?(Array) ? v : (v.size == 1 ? v.first : v) 300 | end 301 | else 302 | svalue 303 | end 304 | end 305 | 306 | dst 307 | end # def self.hash_merge 308 | 309 | end # class LogStash::Filters::Multiline 310 | -------------------------------------------------------------------------------- /logstash-filter-multiline.gemspec: -------------------------------------------------------------------------------- 1 | Gem::Specification.new do |s| 2 | 3 | s.name = 'logstash-filter-multiline' 4 | s.version = '3.0.4' 5 | s.licenses = ['Apache License (2.0)'] 6 | s.summary = "This filter will collapse multiline messages from a single source into one Logstash event." 7 | s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program" 8 | s.authors = ["Elastic"] 9 | s.email = 'info@elastic.co' 10 | s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html" 11 | s.require_paths = ["lib"] 12 | 13 | # Files 14 | s.files = Dir["lib/**/*","spec/**/*","*.gemspec","*.md","CONTRIBUTORS","Gemfile","LICENSE","NOTICE.TXT", "vendor/jar-dependencies/**/*.jar", "vendor/jar-dependencies/**/*.rb", "VERSION", "docs/**/*"] 15 | 16 | # Tests 17 | s.test_files = s.files.grep(%r{^(test|spec|features)/}) 18 | 19 | # Special flag to let us know this is actually a logstash plugin 20 | s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" } 21 | 22 | # Gem dependencies 23 | s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99" 24 | s.add_runtime_dependency 'logstash-patterns-core' 25 | s.add_runtime_dependency 'jls-grok', '~> 0.11.0' 26 | 27 | s.add_development_dependency 'logstash-filter-mutate' 28 | s.add_development_dependency 'logstash-devutils' 29 | s.add_development_dependency 'insist' 30 | end 31 | 32 | -------------------------------------------------------------------------------- /spec/filters/multiline_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | require "logstash/devutils/rspec/spec_helper" 4 | require "insist" 5 | require "logstash/filters/multiline" 6 | 7 | describe LogStash::Filters::Multiline do 8 | 9 | describe "simple multiline" do 10 | config <<-CONFIG 11 | filter { 12 | multiline { 13 | periodic_flush => false 14 | pattern => "^\\s" 15 | what => previous 16 | } 17 | } 18 | CONFIG 19 | 20 | sample [ "hello world", " second line", "another first line" ] do 21 | expect(subject).to be_a(Array) 22 | insist { subject.size } == 2 23 | insist { subject[0].get("message") } == "hello world\n second line" 24 | insist { subject[1].get("message") } == "another first line" 25 | end 26 | end 27 | 28 | describe "multiline using grok patterns" do 29 | config <<-CONFIG 30 | filter { 31 | multiline { 32 | pattern => "^%{NUMBER} %{TIME}" 33 | negate => true 34 | what => previous 35 | } 36 | } 37 | CONFIG 38 | 39 | sample [ "120913 12:04:33 first line", "second line", "third line" ] do 40 | insist { subject.get("message") } == "120913 12:04:33 first line\nsecond line\nthird line" 41 | end 42 | end 43 | 44 | describe "multiline safety among multiple concurrent streams" do 45 | config <<-CONFIG 46 | filter { 47 | multiline { 48 | pattern => "^\\s" 49 | what => previous 50 | } 51 | } 52 | CONFIG 53 | 54 | count = 50 55 | stream_count = 3 56 | 57 | # first make sure to have starting lines for all streams 58 | eventstream = stream_count.times.map do |i| 59 | stream = "stream#{i}" 60 | lines = [LogStash::Event.new("message" => "hello world #{stream}", "host" => stream, "type" => stream)] 61 | lines += rand(5).times.map do |n| 62 | LogStash::Event.new("message" => " extra line in #{stream}", "host" => stream, "type" => stream) 63 | end 64 | end 65 | 66 | # them add starting lines for random stream with sublines also for random stream 67 | eventstream += (count - stream_count).times.map do |i| 68 | stream = "stream#{rand(stream_count)}" 69 | lines = [LogStash::Event.new("message" => "hello world #{stream}", "host" => stream, "type" => stream)] 70 | lines += rand(5).times.map do |n| 71 | stream = "stream#{rand(stream_count)}" 72 | LogStash::Event.new("message" => " extra line in #{stream}", "host" => stream, "type" => stream) 73 | end 74 | end 75 | 76 | events = eventstream.flatten.map{|event| event.to_hash} 77 | 78 | sample events do 79 | expect(subject).to be_a(Array) 80 | insist { subject.size } == count 81 | 82 | subject.each_with_index do |event, i| 83 | insist { event.get("type") == event.get("host") } == true 84 | stream = event.get("type") 85 | insist { event.get("message").split("\n").first } =~ /hello world / 86 | insist { event.get("message").scan(/stream\d/).all?{|word| word == stream} } == true 87 | end 88 | end 89 | end 90 | 91 | 92 | describe "multiline add/remove tags and fields only when matched" do 93 | config <<-CONFIG 94 | filter { 95 | mutate { 96 | add_tag => "dummy" 97 | } 98 | multiline { 99 | add_tag => [ "nope" ] 100 | remove_tag => "dummy" 101 | add_field => [ "dummy2", "value" ] 102 | pattern => "an unlikely match" 103 | what => previous 104 | } 105 | } 106 | CONFIG 107 | 108 | sample [ "120913 12:04:33 first line", "120913 12:04:33 second line" ] do 109 | expect(subject).to be_a(Array) 110 | insist { subject.size } == 2 111 | 112 | subject.each do |s| 113 | insist { s.get("tags").include?("nope") } == true 114 | insist { s.get("tags").include?("dummy") } == false 115 | insist { s.include?("dummy2") } == true 116 | end 117 | end 118 | end 119 | 120 | describe "regression test for GH issue #1258" do 121 | config <<-CONFIG 122 | filter { 123 | multiline { 124 | pattern => "^\s" 125 | what => "next" 126 | } 127 | } 128 | CONFIG 129 | 130 | sample [ " match", "nomatch" ] do 131 | expect(subject).to be_a(LogStash::Event) 132 | insist { subject.get("message") } == " match\nnomatch" 133 | end 134 | end 135 | 136 | describe "multiple match/nomatch" do 137 | config <<-CONFIG 138 | filter { 139 | multiline { 140 | pattern => "^\s" 141 | what => "next" 142 | } 143 | } 144 | CONFIG 145 | 146 | sample [" match1", "nomatch1", " match2", "nomatch2"] do 147 | expect(subject).to be_a(Array) 148 | insist { subject.size } == 2 149 | insist { subject[0].get("message") } == " match1\nnomatch1" 150 | insist { subject[1].get("message") } == " match2\nnomatch2" 151 | end 152 | end 153 | 154 | describe "keep duplicates by default on message field" do 155 | config <<-CONFIG 156 | filter { 157 | multiline { 158 | pattern => "^\s" 159 | what => "next" 160 | } 161 | } 162 | CONFIG 163 | 164 | sample [" match1", " match1", "nomatch1", " 1match2", " 2match2", " 1match2", "nomatch2"] do 165 | expect(subject).to be_a(Array) 166 | insist { subject.size } == 2 167 | insist { subject[0].get("message") } == " match1\n match1\nnomatch1" 168 | insist { subject[1].get("message") } == " 1match2\n 2match2\n 1match2\nnomatch2" 169 | end 170 | end 171 | 172 | describe "remove duplicates using :allow_duplicates => false on message field" do 173 | config <<-CONFIG 174 | filter { 175 | multiline { 176 | allow_duplicates => false 177 | pattern => "^\s" 178 | what => "next" 179 | } 180 | } 181 | CONFIG 182 | 183 | sample [" match1", " match1", "nomatch1", " 1match2", " 2match2", " 1match2", "nomatch2"] do 184 | expect(subject).to be_a(Array) 185 | insist { subject.size } == 2 186 | insist { subject[0].get("message") } == " match1\nnomatch1" 187 | insist { subject[1].get("message") } == " 1match2\n 2match2\nnomatch2" 188 | end 189 | end 190 | 191 | describe "keep duplicates only on @source field" do 192 | config <<-CONFIG 193 | filter { 194 | multiline { 195 | source => "foo" 196 | pattern => "^\s" 197 | what => "next" 198 | } 199 | } 200 | CONFIG 201 | 202 | sample [ 203 | {"message" => "bar", "foo" => " match1"}, 204 | {"message" => "bar", "foo" => " match1"}, 205 | {"message" => "baz", "foo" => "nomatch1"}, 206 | {"foo" => " 1match2"}, 207 | {"foo" => " 2match2"}, 208 | {"foo" => " 1match2"}, 209 | {"foo" => "nomatch2"} 210 | ] do 211 | expect(subject).to be_a(Array) 212 | insist { subject.size } == 2 213 | insist { subject[0].get("foo") } == " match1\n match1\nnomatch1" 214 | insist { subject[0].get("message") } == ["bar", "baz"] 215 | insist { subject[1].get("foo") } == " 1match2\n 2match2\n 1match2\nnomatch2" 216 | end 217 | end 218 | 219 | describe "fix dropped duplicated lines" do 220 | # as reported in https://github.com/logstash-plugins/logstash-filter-multiline/issues/3 221 | 222 | config <<-CONFIG 223 | filter { 224 | multiline { 225 | pattern => "^START" 226 | what => "previous" 227 | negate=> true 228 | } 229 | } 230 | CONFIG 231 | 232 | messages = [ 233 | "START", 234 | "", 235 | "Foo", 236 | "", 237 | "", 238 | "Foo", 239 | "", 240 | "START", 241 | ] 242 | sample messages do 243 | expect(subject).to be_a(Array) 244 | insist { subject.size } == 2 245 | insist { subject[0].get("message") } == messages[0..-2].join("\n") 246 | end 247 | end 248 | 249 | 250 | describe "keeps metadata fields after two consecutive non multline lines" do 251 | config <<-CONFIG 252 | filter { 253 | mutate { add_field => { "[@metadata][index]" => "logstash-2015.11.19" } } 254 | multiline { 255 | pattern => "^%{NUMBER}" 256 | what => "previous" 257 | } 258 | mutate { add_field => { "[@metadata][type]" => "foo" } } 259 | } 260 | CONFIG 261 | 262 | sample ["line1", "line2"] do 263 | expect(subject).to be_a(Array) 264 | expect(subject[0].get("@metadata")).to include("index"=>"logstash-2015.11.19") 265 | expect(subject[1].get("@metadata")).to include("index"=>"logstash-2015.11.19") 266 | expect(subject[0].get("@metadata")).to include("type"=>"foo") 267 | expect(subject[1].get("@metadata")).to include("type"=>"foo") 268 | end 269 | end 270 | 271 | describe "keeps metadata fields after two consecutive non multline lines" do 272 | config <<-CONFIG 273 | filter { 274 | mutate { add_field => { "[@metadata][index]" => "logstash-2015.11.19" } } 275 | multiline { 276 | pattern => "^%{NUMBER}" 277 | what => "next" 278 | } 279 | mutate { add_field => { "[@metadata][type]" => "foo" } } 280 | } 281 | CONFIG 282 | 283 | sample ["line1", "line2"] do 284 | expect(subject).to be_a(Array) 285 | expect(subject[0].get("@metadata")).to include("index"=>"logstash-2015.11.19") 286 | expect(subject[1].get("@metadata")).to include("index"=>"logstash-2015.11.19") 287 | expect(subject[0].get("@metadata")).to include("type"=>"foo") 288 | expect(subject[1].get("@metadata")).to include("type"=>"foo") 289 | end 290 | end 291 | 292 | end 293 | --------------------------------------------------------------------------------