Logstash with xpack and filebeat

hi, i am sending logs with filebeat to logstash and also i've installed xpack, i made the necessary configurations

  • creation of the built in user
  • editing the logstash.yml, uncomment the lines
    xpack.monitoring.enabled: true
    xpack.monitoring.elasticsearch.username: logstash_system
    xpack.monitoring.elasticsearch.password: mypassword
  • editing the logstash-output.conf file, adding the user and the password
output {
      elasticsearch {
        hosts => ["myIpAddress:9200"]
        index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"
        user => "logstash_system"
        password => "mypassword"
        document_type => "%{[@metadata][type]}"
      }
    }
  • after running the command systemctl status -l logstash
> Jun 26 12:14:25 sd-131865 logstash[13957]: [2019-06-26T12:14:25,759][INFO ][logstash.javapipeline    ] Starting pipeline {:pipeline_id=>"main", "pipeline.workers"=>2, "pipeline.batch.size"=>125, "pipeline.batch.delay"=>50, "pipeline.max_inflight"=>250, :thread=>"#<Thread:0x3941c0dc run>"}
> Jun 26 12:14:28 sd-131865 logstash[13957]: [2019-06-26T12:14:28,037][INFO ][logstash.inputs.beats    ] Beats inputs: Starting input listener {:address=>"0.0.0.0:5044"}
> Jun 26 12:14:28 sd-131865 logstash[13957]: [2019-06-26T12:14:28,079][INFO ][logstash.javapipeline    ] Pipeline started {"pipeline.id"=>"main"}
> Jun 26 12:14:28 sd-131865 logstash[13957]: [2019-06-26T12:14:28,512][INFO ][logstash.agent           ] Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]}
> Jun 26 12:14:28 sd-131865 logstash[13957]: [2019-06-26T12:14:28,601][INFO ][org.logstash.beats.Server] Starting server on port: 5044
> Jun 26 12:14:29 sd-131865 logstash[13957]: [2019-06-26T12:14:29,864][INFO ][logstash.agent           ] Successfully started Logstash API endpoint {:port=>9600}
> root@sd-131865:~#

this is the logstash log :

> [2019-06-26T12:14:25,759][INFO ][logstash.javapipeline    ] Starting pipeline {:pipeline_id=>"main", "pipeline.workers"=>2, "pipeline.batch.size"=>125, "pipeline.batch.delay"=>50, "pipeline.max_inflight"=>250, :thread=>"#<Thread:0x3941c0dc run>"}
> [2019-06-26T12:14:28,037][INFO ][logstash.inputs.beats    ] Beats inputs: Starting input listener {:address=>"0.0.0.0:5044"}
> [2019-06-26T12:14:28,079][INFO ][logstash.javapipeline    ] Pipeline started {"pipeline.id"=>"main"}
> [2019-06-26T12:14:28,512][INFO ][logstash.agent           ] Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]}
> [2019-06-26T12:14:28,601][INFO ][org.logstash.beats.Server] Starting server on port: 5044
> [2019-06-26T12:14:29,864][INFO ][logstash.agent           ] Successfully started Logstash API endpoint {:port=>9600}

but filebeat can't connect to logstash and acn't receive anything

@markov, Please refer the below discussion over ELK. It may help you.

discussion

Thanks.

i followed the documentation Configuring Logstash to use Basic Authentication section and it Successfully started Logstash:

> Jun 26 12:59:16 sd-131865 logstash[14299]: [2019-06-26T12:59:16,569][INFO ][logstash.javapipeline    ] Starting pipeline {:pipeline_id=>"main", "pipeline.workers"=>2, "pipeline.batch.size"=>125, "pipeline.batch.delay"=>50, "pipeline.max_inflight"=>250, :thread=>"#<Thread:0x10e7f74b run>"}
> Jun 26 12:59:18 sd-131865 logstash[14299]: [2019-06-26T12:59:18,847][INFO ][logstash.inputs.beats    ] Beats inputs: Starting input listener {:address=>"0.0.0.0:5044"}
> Jun 26 12:59:18 sd-131865 logstash[14299]: [2019-06-26T12:59:18,939][INFO ][logstash.javapipeline    ] Pipeline started {"pipeline.id"=>"main"}
> Jun 26 12:59:19 sd-131865 logstash[14299]: [2019-06-26T12:59:19,360][INFO ][org.logstash.beats.Server] Starting server on port: 5044
> Jun 26 12:59:19 sd-131865 logstash[14299]: [2019-06-26T12:59:19,489][INFO ][logstash.agent           ] Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]}
> Jun 26 12:59:20 sd-131865 logstash[14299]: [2019-06-26T12:59:20,820][INFO ][logstash.agent           ] Successfully started Logstash API endpoint {:port=>9600}

but the filebeat also won't connect it said :
Failed to connect to backoff(async(tcp://..................))
thanks

@markov,

Can you please paste your filebeat.yml configuration?

Thanks.

> ###################### Filebeat Configuration Example #########################
> 
> # This file is an example configuration file highlighting only the most common
> # options. The filebeat.reference.yml file from the same directory contains all the
> # supported options with more comments. You can use it as a reference.
> #
> # You can find the full configuration reference here:
> # https://www.elastic.co/guide/en/beats/filebeat/index.html
> 
> # For more available modules and options, please see the filebeat.reference.yml sample
> # configuration file.
> 
> #=========================== Filebeat inputs =============================
> 
> filebeat.inputs:
> 
> # Each - is an input. Most options can be set at the input level, so
> # you can use different inputs for various configurations.
> # Below are the input specific configurations.
> 
> - type: log
> 
>   # Change to true to enable this input configuration.
>   enabled: true
> 
>   # Paths that should be crawled and fetched. Glob based paths.
>   paths:
>     - /home/drioui/Bureau/GID/*.log
>     #- c:\programdata\elasticsearch\logs\*
> 
>   # Exclude lines. A list of regular expressions to match. It drops the lines that are
>   # matching any regular expression from the list.
>   #exclude_lines: ['^DBG']
> 
>   # Include lines. A list of regular expressions to match. It exports the lines that are
>   # matching any regular expression from the list.
>   #include_lines: ['^ERR', '^WARN']
> 
>   # Exclude files. A list of regular expressions to match. Filebeat drops the files that
>   # are matching any regular expression from the list. By default, no files are dropped.
>   #exclude_files: ['.gz$']
> 
>   # Optional additional fields. These fields can be freely picked
>   # to add additional information to the crawled log files for filtering
>   #fields:
>   #  level: debug
>   #  review: 1
> 
>   ### Multiline options
> 
>   # Multiline can be used for log messages spanning multiple lines. This is common
>   # for Java Stack Traces or C-Line Continuation
> 
>   # The regexp Pattern that has to be matched. The example pattern matches all lines starting with [
>   #multiline.pattern: ^\[
> 
>   # Defines if the pattern set under pattern should be negated or not. Default is false.
>   #multiline.negate: false
> 
>   # Match can be set to "after" or "before". It is used to define if lines should be append to a pattern
>   # that was (not) matched before or after or as long as a pattern is not matched based on negate.
>   # Note: After is the equivalent to previous and before is the equivalent to to next in Logstash
>   #multiline.match: after
> 
> 
> #============================= Filebeat modules ===============================
> 
> filebeat.config.modules:
>   # Glob pattern for configuration loading
>   path: ${path.config}/modules.d/*.yml
> 
>   # Set to true to enable config reloading
>   reload.enabled: false
> 
>   # Period on which files under path should be checked for changes
>   #reload.period: 10s
> 
> #==================== Elasticsearch template setting ==========================
> 
> setup.template.settings:
>   index.number_of_shards: 1
>   #index.codec: best_compression
>   #_source.enabled: false
> 
> #================================ General =====================================
> 
> # The name of the shipper that publishes the network data. It can be used to group
> # all the transactions sent by a single shipper in the web interface.
> #name:
> 
> # The tags of the shipper are included in their own field with each
> # transaction published.
> #tags: ["service-X", "web-tier"]
> 
> # Optional fields that you can specify to add additional information to the
> # output.
> #fields:
> #  env: staging
> 
> 
> #============================== Dashboards =====================================
> # These settings control loading the sample dashboards to the Kibana index. Loading
> # the dashboards is disabled by default and can be enabled either by setting the
> # options here or by using the `setup` command.
> #setup.dashboards.enabled: false
> 
> # The URL from where to download the dashboards archive. By default this URL
> # has a value which is computed based on the Beat name and version. For released
> # versions, this URL points to the dashboard archive on the artifacts.elastic.co
> # website.
> #setup.dashboards.url:
> #============================== Kibana =====================================
> 
> # Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API.
> # This requires a Kibana endpoint configuration.
> #setup.kibana:
> 
>   # Kibana Host
>   # Scheme and port can be left out and will be set to the default (http and 5601)
>   # In case you specify and additional path, the scheme is required: http://localhost:5601/path
>   # IPv6 addresses should always be defined as: https://[2001:db8::1]:5601
>   #host: "localhost:5601"
> 
>   # Kibana Space ID
>   # ID of the Kibana Space into which the dashboards should be loaded. By default,
>   # the Default Space will be used.
>   #space.id:
> 
> #============================= Elastic Cloud ==================================
> 
> # These settings simplify using filebeat with the Elastic Cloud (https://cloud.elastic.co/).
> 
> # The cloud.id setting overwrites the `output.elasticsearch.hosts` and
> # `setup.kibana.host` options.
> # You can find the `cloud.id` in the Elastic Cloud web UI.
> #cloud.id:
> 
> # The cloud.auth setting overwrites the `output.elasticsearch.username` and
> # `output.elasticsearch.password` settings. The format is `<user>:<pass>`.
> #cloud.auth:
> 
> #================================ Outputs =====================================
> 
> # Configure what output to use when sending the data collected by the beat.
> 
> #-------------------------- Elasticsearch output ------------------------------
> #output.elasticsearch:
>   # Array of hosts to connect to.
>   # hosts: ["localhost:9200"]
> 
>   # Optional protocol and basic auth credentials.
>   #protocol: "https"
>   #username: "elastic"
>   #password: "changeme"
> 
> #----------------------------- Logstash output --------------------------------
> output.logstash:
>   # The Logstash hosts
>   hosts: ["myipAddress:5044"]
> 
>   # Optional SSL. By default is off.
>   # List of root certificates for HTTPS server verifications
>   #ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]
> 
>   # Certificate for SSL client authentication
>   #ssl.certificate: "/etc/pki/client/cert.pem"
> 
>   # Client Certificate Key
>   #ssl.key: "/etc/pki/client/cert.key"
> 
> #================================ Processors =====================================
> 
> # Configure processors to enhance or manipulate events generated by the beat.
> 
> processors:
>   - add_host_metadata: ~
>   - add_cloud_metadata: ~
> 
> #================================ Logging =====================================
> 
> # Sets log level. The default log level is info.
> # Available log levels are: error, warning, info, debug
> logging.level: debug
> 
> # At debug level, you can selectively enable logging only for some components.
> # To enable all selectors use ["*"]. Examples of other selectors are "beat",
> # "publish", "service".
> #logging.selectors: ["*"]
> 
> #============================== Xpack Monitoring ===============================
> # filebeat can export internal metrics to a central Elasticsearch monitoring
> # cluster.  This requires xpack monitoring to be enabled in Elasticsearch.  The
> # reporting is disabled by default.
> 
> # Set to true to enable the monitoring reporter.
> #xpack.monitoring.enabled: false
> 
> # Uncomment to send the metrics to Elasticsearch. Most settings from the
> # Elasticsearch output are accepted here as well. Any setting that is not set is
> # automatically inherited from the Elasticsearch output configuration, so if you
> # have the Elasticsearch output configured, you can simply uncomment the
> # following line.
> #xpack.monitoring.elasticsearch:
> 
> #================================= Migration ==================================
> 
> # This allows to enable 6.7 migration aliases
> #migration.6_to_7.enabled: true

@markov, filebeat.yml file configuration seems fine. Are you able to telnet your logstash server from client machine (where you installed filebeat) on port 5044. Please run below command from your filebeat machine:

$ telnet logstash_server_ip 5044

If not able to telnet open your firewall rule else please provide some more error logs.

Also please provide the output of below command from logstash server:

$ netstat -an|grep 5044

Thanks.

this is the logstash-plain.log

[2019-06-26T13:37:42,604][ERROR][logstash.outputs.elasticsearch] Encountered a retryable error. Will Retry with exponential backoff {:code=>403, :url=>"http://51.15.188.74:9200/_bulk"}

root@sd-131865:~# netstat -an|grep 5044
tcp6       0      0 :::5044                 :::*                    LISTEN
tcp6       0      0 xx.xxx.xx.xx:5044       105.188.133.167:50718   ESTABLISHED
:~$ telnet logstash_server_ip 5044
Trying logstash_server_ip...
Connected to logstash_server_ip.
Escape character is '^]'.
Connection closed by foreign host.

@markov,

From above output seems your are getting traffic at logstash server from your one machine i.e 105.188.133.167

If its true then you need to setup your filebeat according to that server.

Thanks.

yes that's it, and i've configured filebeat to send to logstash server with the ip xx.xxx.xx.xx, i think everything is ok but !!!!!!!!

@markov,

Please verify your logstash configuration also. Its should be look like below:

input {
  beats {
    port => 5044
  }
}

filter {
  if [type] == "syslog" {
    grok {
      match => { "message" => "%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?: %{GREEDYDATA:syslog_message}" }
      add_field => [ "received_at", "%{@timestamp}" ]
      add_field => [ "received_from", "%{host}" ]
    }
    syslog_pri { }
    date {
      match => [ "syslog_timestamp", "MMM  d HH:mm:ss", "MMM dd HH:mm:ss" ]
    }
  }
}


output {
  elasticsearch {
    hosts => ["192.168.56.4:9200"]
    user => "logstash_internal"
    password => "admin@123"
    sniffing => true
    manage_template => false
    index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"
    document_type => "%{[@metadata][type]}"
  }
}

You should have user => "logstash_internal" and password in output filter of logstash.

Hope so it will fix your issue.

Thanks.

02-beats-input.conf

input {
  beats {
    port => 5044
 }
}

10-syslog-filter.conf

filter {
     if [source] =~ "gid" {
        grok {
            match => {"message" => "%{TIMESTAMP_ISO8601:timestamp}\|(\[%{BASE10NUM:nbr}\])\|%{IPORHOST:ClientIP}\|%{USERNAME:User};%{DATA:Node}\|%{URIPATH:Url}\|%{NOTS$
        }
     }else if [source] =~ "server" {

        grok {
            match =>{ "message" => [

                "(?m)%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:Loglevel} \[(?<Classname>[^\]]+)\] %{GREEDYDATA:Message}",
                "%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:Loglevel}  \[(?<Classname>[^\]]+)\] %{WORD:n} \| %{NUMBER:number} \| %{WORD:b} \| %{DATA:Url} \| %{GREEDYDAT$
                "%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:Loglevel}  \[(?<Classname>[^\]]+)\] %{GREEDYDATA:Message}"] }
        }
      }
  date {match => [ "timestamp" , "MMM dd yyyy HH:mm:ss","MMM d yyyy HH:mm:ss", "ISO8601" ]
      target => "@timestamp"}

  mutate {
        remove_field => [ "[beat][name]", "[beat][version]", "[beat][hostname]", "[host][architecture]", "[host][containerized]", "[host][id]", "[host][name]", "[host]$
  }
}

30-elasticsearch-output.conf

output {
  elasticsearch {
    hosts => ["myIpAdress:9200"]
    index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"
    user => "logstash_internal"
    password => "admin10@"
    document_type => "%{[@metadata][type]}"
  }
}

it's all working before integrating the xpack for security reasons

retrying failed action with response code: 403 ({"type"=>"security_exception", "reason"=>"action [indices:admin/create] is unauthorized for user [logstash_internal]"})

@markov,

Please follow the below documentation. You need to assign logstash_writer role to logstash_internal user. Please read document and follow it.

document

Thanks.

the documentation said that i have to configure credentials separately for each of the Elasticsearch plugins in my Logstash .conf file; is that mean :
input.conf

> input {
>   beats {
>     port => 5044
>    }
>   elasticsearch {
>     hosts => ["ipadress:9200"]
>     user => "logstash_internal"
>     password => "admin@"
>   }
>  }

filter.conf

> filter {
>   elasticsearch {
>     hosts => ["ipadress:9200"]
>     user => "logstash_internal"
>     password => "admin@"
>   }
> 
>      if [source] =~ "gid" {
>         grok {
>             match => {"message" => "%{TIMESTAMP_ISO8601:timestamp}\|(\[%{BASE10NUM:nbr}\])\|%{IPORHOST:ClientIP}\|%{USERNAME:User};%{DATA:Node}\|%{URIPATH:Url}\|%{NOTS$
>         }
>      }else if [source] =~ "server" {
> 
>         grok {
>             match =>{ "message" => [
> 
>                 "(?m)%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:Loglevel} \[(?<Classname>[^\]]+)\] %{GREEDYDATA:Message}",
>                 "%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:Loglevel}  \[(?<Classname>[^\]]+)\] %{WORD:n} \| %{NUMBER:number} \| %{WORD:b} \| %{DATA:Url} \| %{GREEDYDAT$
>                 "%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:Loglevel}  \[(?<Classname>[^\]]+)\] %{GREEDYDATA:Message}"] }
>         }
>       }
>   date {match => [ "timestamp" , "MMM dd yyyy HH:mm:ss","MMM d yyyy HH:mm:ss", "ISO8601" ]
>       target => "@timestamp"}
> 
>   mutate {
>         remove_field => [ "[beat][name]", "[beat][version]", "[beat][hostname]", "[host][architecture]", "[host][containerized]", "[host][id]", "[host][name]", "[host]$
>   }
> }

output.conf

> output {
>   elasticsearch {
>     hosts => ["ipadress:9200"]
>     index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"
>     user => "logstash_internal"
>     password => "admin@"
>     document_type => "%{[@metadata][type]}"
>   }
>   stdout { codec => rubydebug }
> }

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.