<commit_before>Jenkins Logstash Plugin
=======================

Travis: [![Build Status](https://travis-ci.org/jenkinsci/logstash-plugin.svg?branch=master)](https://travis-ci.org/jenkinsci/logstash-plugin)
Jenkins: [![Build Status](https://ci.jenkins.io/job/Plugins/job/logstash-plugin/job/master/badge/icon)](https://ci.jenkins.io/job/Plugins/job/logstash-plugin/job/master/)

This plugin adds support for sending a job's console log to Logstash indexers such as [Elastic Search](https://www.elastic.co/products/elasticsearch), 
[Logstash](https://www.elastic.co/de/products/logstash), [RabbitMQ](https://www.rabbitmq.com), 
[Redis](https://redis.io/) or to Syslog.

* use [Jira](https://issues.jenkins.io) to report issues / feature requests

Install
=======

* Search for 'Logstash' in your Jenkins plugin manager

Configure
=========

Supported methods of input/output:

* ElasticSearch (REST API)
* Logstash TCP input
* Redis (format => 'json_event')
* RabbitMQ (mechanism => PLAIN)
* Syslog (format => cee/json ([RFC-5424](https://tools.ietf.org/html/rfc5424),[RFC-3164](https://tools.ietf.org/html/rfc3164)), protocol => UDP)

Pipeline
========

Logstash plugin can be used as a publisher in pipeline jobs to send the whole log as a single document.

```Groovy
 node('master') {
        sh'''
        echo 'Hello, world!'
        '''
        logstashSend failBuild: true, maxLines: 1000
 }
```

It can be used as a wrapper step to send each log line separately.

Note: when you combine with timestamps step, you should make the timestamps the outermost block. Otherwise you get the timestamps as part of the log lines, basically duplicating the timestamp information.

```Groovy
timestamps {
  logstash {
    node('somelabel') {
      sh'''
      echo 'Hello, World!'
      '''
    }
  }
}
```

Enable Globally
=======

You can enable this plugin globally in the Jenkins system configuration page, 
or with the [configuration as code](https://plugins.jenkins.io/configuration-as-code/) plugin: 

```yaml
unclassified:
  logstashConfiguration:
    enableGlobally: true
    enabled: true
    logstashIndexer:
        logstash:
            host: "localhost"
            port: 9200
```

JobProperty
=======

This component streams individual log lines to the indexer for post-processing, 
along with any build data that is available at the start (some information such as the build status is unavailable or incomplete).

Post-Build Publisher
=======

This component pushes the tail of the job's log to the indexer for post-processing, 
along with all build data at the time the post-build action had started (if any post-build actions are scheduled after this plugin they will not be recorded).

JSON Payload Format<commit_msg>Docs migration: add pipeline example<commit_after>Jenkins Logstash Plugin
=======================

Travis: [![Build Status](https://travis-ci.org/jenkinsci/logstash-plugin.svg?branch=master)](https://travis-ci.org/jenkinsci/logstash-plugin)
Jenkins: [![Build Status](https://ci.jenkins.io/job/Plugins/job/logstash-plugin/job/master/badge/icon)](https://ci.jenkins.io/job/Plugins/job/logstash-plugin/job/master/)

This plugin adds support for sending a job's console log to Logstash indexers such as [Elastic Search](https://www.elastic.co/products/elasticsearch), 
[Logstash](https://www.elastic.co/de/products/logstash), [RabbitMQ](https://www.rabbitmq.com), 
[Redis](https://redis.io/) or to Syslog.

* use [Jira](https://issues.jenkins.io) to report issues / feature requests

Install
=======

* Search for 'Logstash' in your Jenkins plugin manager

Configure
=========

Supported methods of input/output:

* ElasticSearch (REST API)
* Logstash TCP input
* Redis (format => 'json_event')
* RabbitMQ (mechanism => PLAIN)
* Syslog (format => cee/json ([RFC-5424](https://tools.ietf.org/html/rfc5424),[RFC-3164](https://tools.ietf.org/html/rfc3164)), protocol => UDP)

Pipeline
=========

Publisher
---------

Logstash plugin can be used as a publisher in pipeline jobs to send the
tail of the log as a single document.

**Example for publisher in pipeline**

```Groovy
node('master') {
    sh'''
        echo 'Hello, world!'
    '''
    logstashSend failBuild: true, maxLines: 1000
}
```

Note: Due to the way logging works in pipeline currently, the
logstashSend step might not transfer the lines logged directly before
the step is called. Adding a sleep of 1 second might help here.

Note: In order to get the the result set in pipeline it must be [set
before the logstashSend
step](https://support.cloudbees.com/hc/en-us/articles/218554077-How-to-set-current-build-result-in-Pipeline-).

Note: the `logstashSend` step requires a node to run.

Step with Block
---------------

It can be used as a wrapper step to send each log line separately.

Once the result is set, it will appear in the data sent to the indexer.

Note: when you combine with timestamps step, you should make the
timestamps the outermost block. Otherwise you get the timestamps as
part of the log lines, basically duplicating the timestamp information.

**Example for pipeline step**

```Groovy
timestamps {
  logstash {
    node('somelabel') {
      sh'''
        echo 'Hello, World!'
      '''
      try {
        // do something that fails
        sh "exit 1"
        currentBuild.result = 'SUCCESS'
      } catch (Exception err) {
        currentBuild.result = 'FAILURE'
      }    
    }
  }
}
```

Note: Information on which agent the steps are executed is not available
at the moment.

Enable Globally
=======

You can enable this plugin globally in the Jenkins system configuration page, 
or with the [configuration as code](https://plugins.jenkins.io/configuration-as-code/) plugin: 

```yaml
unclassified:
  logstashConfiguration:
    enableGlobally: true
    enabled: true
    logstashIndexer:
        logstash:
            host: "localhost"
            port: 9200
```

JobProperty
=======

This component streams individual log lines to the indexer for post-processing, 
along with any build data that is available at the start (some information such as the build status is unavailable or incomplete).

Post-Build Publisher
=======

This component pushes the tail of the job's log to the indexer for post-processing, 
along with all build data at the time the post-build action had started (if any post-build actions are scheduled after this plugin they will not be recorded).

JSON Payload Format
{'fraction_non_alphanumeric': 0.12429819089207736, 'fraction_numerical': 0.009201497192763568, 'mean_word_length': 3.8546555639666917, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 25, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '159518', 'n_tokens_mistral': 2014, 'n_tokens_neox': 1880, 'n_words': 665}