Logstash not adding fields - logstash

I am using Logstash 1.4.2 and I have the following conf file.
I would expect to see in Kibana in the "Fields" section on the left the options for "received_at" and "received_from" and "description", but I don't.
I see
#timestamp
#version
_id
_index
_type host path
I do see in the _source section on the right side the following...
received_at:2015-05-11 14:19:40 UTC received_from:PGP02 descriptionError1!
So home come these don't appear in the list of "Popular Fields"?
I'd like to filter the right side to not show EVERY field in the _source section on the right. Excuse the redaction blocks.
input
{
file {
path => "C:/ServerErrlogs/office-log.txt"
start_position => "beginning"
sincedb_path => "c:/tools/logstash-1.4.2/office-log.sincedb"
tags => ["product_qa", "office"]
}
file {
path => "C:/ServerErrlogs/dis-log.txt"
start_position => "beginning"
sincedb_path => "c:/tools/logstash-1.4.2/dis-log.sincedb"
tags => ["product_qa", "dist"]
}
}
filter {
grok {
match => ["path","%{GREEDYDATA}/%{GREEDYDATA:filename}\.log"]
match => [ "message", "%{TIMESTAMP_ISO8601:logdate}: %{LOGLEVEL:loglevel} (?<logmessage>.*)" ]
add_field => [ "received_at", "%{#timestamp}" ]
add_field => [ "received_from", "%{host}" ]
}
date {
match => [ "logdate", "ISO8601", "yyyy-MM-dd HH:mm:ss,SSSSSSSSS" ]
}
#logdate is now parsed into timestamp, remove original log message too
mutate {
remove_field => ['message', 'logdate' ]
add_field => [ "description", "Error1!" ]
}
}
output {
elasticsearch {
protocol => "http"
host => "0.0.0.x"
}
}
Update:
I have tired searching with a query like:
tags: data AND loglevel : INFO
then saving this query, and then reloading the page.
But still I don't see loglevel appearing as 'Popular Fields'

If the fields don't appear on the left side, it's probably a kibana caching problem. Go to Settings->Indices, select your index, and click the orange Refresh button.

I had the same issue with logstash not adding fields and after quite a lot of searching and testing other things, suddenly I had the solution (but I´am using the logstash-logback-encoder, so I have JSON already - if you don´t, then you need to transform things into JSON in the logstash "input"-phase).
I added a "json" plugin-filter, that did the magic for me:
filter {
json {
source => "message"
}
}

Related

How to get the content of only one field in logstash

I'm working on syslogs that I receive through the network, but I receive them in a different format because of the fact it travels by the network.
So the real syslog is in a field named "message", and I'd like to make a filter to get the content of "message" and also filter him and send it to a file.
Actually this is how the data looks like :
{"#timestamp":"2020-10-12T14:17:16.944Z","message":"<190>key1=\"value1\" key2=\"value2\"","otherKey1":"otherValue1","otherKey2":"otherValue2"}
And here is my actual configuration file :
input{
file{
path => "/var/log/logstash/syslog.txt"
start_position => "beginning"
}
}
filter{
if ("" in [message]){
kv{
value_split => "="
}
mutate{
add_field => {"timestamp" => "%{date} %{time}"}
}
date{
match => ["timestamp", "ISO8601", "yyyy-MM-dd HH:mm:ss"]
target => "#timestamp"
locale => "fr"
}
mutate{
remove_field => ["date", "time", "timestamp"]
}
geoip{
source => "remip"
}
}
}
output{
file{
path => "/var/log/logstash/systest.txt"
}
}
Many thanks in advance for any help or advice !
For your situation, you need to jsut keep the fiels message in the event.
You can do this with the prune filter which enable a whitelist mechanism.
So add this in your filter :
prune {
whitelist_names => ["^message$"]
}
After this, only this field must be written in the file.

Fields parsed from log path not added in logstash

I'm parsing multiple log files with logstash - and want to add fields based on the path of the files to my output. Here are the relevant parts of the config file:
input {
file {
path => "/mnt/logs/**/console-20200108*.log"
type => "tomcat"
start_position => "beginning"
sincedb_path => "/dev/null"
}
}
filter {
if [type] == "tomcat" {
grok {
patterns_dir => "/usr/share/logstash/patterns"
match => {
"message" => [ "%{TOMCAT_LOG_1}", "%{TOMCAT_LOG_2}" ]
"path" => "\/mnt\/logs\/%{DATA:site}\/%{DATA:version}\/node%{NUMBER:node}\/store\/tomcat\/%{DATA:file}\.log"
}
}
}
}
Here's a sample output:
{
"level" => "INFO",
"type" => "tomcat",
"data" => "Finished indexer cronjob.\r",
"timestamp" => "08-Jan-2020 11:00:05.860",
"qualifier1" => "[update-backofficeIndex-CronJob::ServicelayerJob]",
"#timestamp" => 2020-01-08T11:04:47.364Z,
"path" => "/mnt/logs/protec/qa/node1/store/tomcat/console-20200108.log",
"qualifier3" => "[SolrIndexerJob]",
"host" => "elk",
"#version" => "1",
"message" => "INFO | jvm 1 | srvmain | 08-Jan-2020 11:00:05.860 INFO [update-backofficeIndex-CronJob::ServicelayerJob] (update-backofficeIndex-CronJob) [SolrIndexerJob] Finished indexer cronjob.\r",
"qualifier2" => "(update-backofficeIndex-CronJob)"
}
Based on this, I was expecting to get relevant fields from parsing the message and a few more fields from parsing the path. Yet, I none of the fields from "path" parsing are added.
What am I missing? How do I add site, version, node and file fields?
Creating an answer from a comment that solved the problem (hence community wiki).
Apparently it might be coming from the break_on_match option, which defaults to true. From the doc:
The first successful match by grok will result in the filter being finished. So if %{TOMCAT_LOG_1} or %{TOMCAT_LOG_2} match, it won't try to match the path field

Removing unwanted fields in Logstash configuration file

I'm building a ELK Setup and its working fine , however i'm getting into a situation where i want to remove certain fields from by system-log data while processing through logstash like remove_field & remove_tag which i've defined in my logstash configuration file but that's not working.
Looking for any esteem and expert advice to correct the config to make it running, thanks very much in advanced.
My logstash configuration file:
[root#sandbox-prd~]# cat /etc/logstash/conf.d/syslog.conf
input {
file {
path => [ "/data/SYSTEMS/*/messages.log" ]
start_position => beginning
sincedb_path => "/dev/null"
max_open_files => 64000
type => "sj-syslog"
}
}
filter {
if [type] == "sj-syslog" {
grok {
match => { "message" => "%{SYSLOGTIMESTAMP:syslog_timestamp } %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?: %{GREEDYDATA:syslog_message}" }
add_field => [ "received_at", "%{#timestamp}" ]
remove_field => ["#version", "host", "_type", "_index", "_score", "path"]
remove_tag => ["_grokparsefailure"]
}
syslog_pri { }
date {
match => [ "syslog_timestamp", "MMM d HH:mm:ss", "MMM dd HH:mm:ss" ]
}
}
}
output {
if [type] == "sj-syslog" {
elasticsearch {
hosts => "sandbox-prd02:9200"
manage_template => false
index => "sj-syslog-%{+YYYY.MM.dd}"
document_type => "messages"
}
}
}
Data sample appearing on the Kibana Portal
syslog_pid:6662 type:sj-syslog syslog_message:(root) CMD (LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok) syslog_severity:notice syslog_hostname:dbaprod01 syslog_severity_code:5 syslog_timestamp:Feb 11 10:25:02 #timestamp:February 11th 2019, 23:55:02.000 message:Feb 11 10:25:02 dbaprod01 CROND[6662]: (root) CMD (LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok) syslog_facility:user-level syslog_facility_code:1 syslog_program:CROND received_at:February 11th 2019, 10:25:03.353 _id:KpHo2mgBybCgY5IwmRPn _type:messages
_index:sj-syslog-2019.02.11 _score: -
MY Resource Details:
OS version : Linux 7
Logstash Version: 6.5.4
You can't remove _type and _index, those are metadata fields needed by elasticsearch to work, they have information about your index name and the mapping of your data, the _score field is also a metadata field, generated at search time, it's not on your document.

In Kibana, I have fields that contains a question mark `?` not showing in metric field

In Kibana, I have fields that contains a question mark ?. The goal is to create a filter that excludes all entries containing a question mark in the field. So, when i'm trying to create a metric under Aggregation with Term those fields which are in ? mark are not visible there, Please help to understand to a newbie ..
Below is the logstash.conf with the filters i'm using along with screen shot i have attached, please suggest what mistake i'm doing and what can be done..
I have ELK version : 6.2.x
# cat logstash-syslog.conf
input {
file {
path => [ "/scratch/rsyslog/*/messages.log" ]
type => "syslog"
}
file {
path => [ "/scratch/rsyslog/Aug/messages.log" ]
type => "apic_logs"
}
}
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}" ]
remove_field => ["#version", "host", "message", "_type", "_index", "_score", "path"]
}
syslog_pri { }
date {
match => [ "syslog_timestamp", "MMM d HH:mm:ss", "MMM dd HH:mm:ss" ]
}
}
if [type] == "apic_logs" {
grok {
match => { "message" => "%{CISCOTIMESTAMP:syslog_timestamp} %{CISCOTIMESTAMP} %{SYSLOGHOST:syslog_hostname} (?<prog>[\w._/%-]+) %{SYSLOG5424SD:f1}%{SYSLOG5424SD:f2}%{SYSLOG5424SD:f3}%{SYSLOG5424SD:f4}%{SYSLOG5424SD:f5} %{GREEDYDATA:syslog_message}" }
add_field => [ "received_at", "%{#timestamp}" ]
remove_field => ["#version", "host", "message", "_type", "_index", "_score", "path"]
}
}
}
output {
if [type] == "syslog" {
elasticsearch {
hosts => "noida-elk:9200"
manage_template => false
index => "syslog-%{+YYYY.MM.dd}"
document_type => "messages"
}
}
}
output {
if [type] == "apic_logs" {
elasticsearch {
hosts => "noida-elk:9200"
manage_template => false
index => "apic_logs-%{+YYYY.MM.dd}"
document_type => "messages"
}
}
}
I fixed my issue!
Why do I see the symbol ? by fields in the Kibana Discover page
When you open the Discover page in Kibana, you might see a question mark ? by fields that are listed in the available fields section instead of the character t. When you reload the list of fields, the type of fields is analyzed, and the question mark ? is replaced by the character t.
Be sure to check Mark the box include system indices at the extreme right in the below screen shot.
Rearranging field columns in the table
You can rearrange the field columns in the table. Mouse over the header of the column you want to move, and click the Move column to the left button or the Move column to the right button.
Reloading the list of fields
Complete the following steps to reload the list of fields that are displayed in Kibana:
Select the Management page, then select Index Patterns to list the indexes that are available.
Select the index pattern for your space to see every field and the field's associated core type as recorded by Elasticsearch.
Click the Reload field list button Reload field list to reload the index pattern fields.
The list of fields is refreshed.
In case if you are using kibana , make sure after re-creating the index you are refreshing it, speically when you add new fields to it. This refresh is available under management section of Kibana against each index pattern.
"?" - represents a column available , but not part of elastic index until you do a refresh.
None of the other answers worked for me - take a look at this link though:
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html#docs-update-by-query
This did work, at least some of the time! Execute (ES/OpenSearch API sandbox in Console):
POST my-index-000001/_update_by_query?conflicts=proceed
or via curl
curl -X POST "localhost:9200/my-index-000001/_update_by_query?conflicts=proceed&pretty"
Note! This did work for me (along with Index-Pattern re-creation) in AWS OpenSearch.

Retrieving RESTful GET parameters in logstash

I am trying to get logstash to parse key-value pairs in an HTTP get request from my ELB log files.
the request field looks like
http://aaa.bbb/get?a=1&b=2
I'd like there to be a field for a and b in the log line above, and I am having trouble figuring it out.
My logstash conf (formatted for clarity) is below which does not load any additional key fields. I assume that I need to split off the address portion of the URI, but have not figured that out.
input {
file {
path => "/home/ubuntu/logs/**/*.log"
type => "elb"
start_position => "beginning"
sincedb_path => "log_sincedb"
}
}
filter {
if [type] == "elb" {
grok {
match => [ "message", "%{TIMESTAMP_ISO8601:timestamp}
%{NOTSPACE:loadbalancer} %{IP:client_ip}:%{NUMBER:client_port:int}
%{IP:backend_ip}:%{NUMBER:backend_port:int}
%{NUMBER:request_processing_time:float}
%{NUMBER:backend_processing_time:float}
%{NUMBER:response_processing_time:float}
%{NUMBER:elb_status_code:int}
%{NUMBER:backend_status_code:int}
%{NUMBER:received_bytes:int} %{NUMBER:sent_bytes:int}
%{QS:request}" ]
}
date {
match => [ "timestamp", "ISO8601" ]
}
kv {
field_split => "&?"
source => "request"
exclude_keys => ["callback"]
}
}
}
output {
elasticsearch { host => localhost }
}
kv will take a URL and split out the params. This config works:
input {
stdin { }
}
filter {
mutate {
add_field => { "request" => "http://aaa.bbb/get?a=1&b=2" }
}
kv {
field_split => "&?"
source => "request"
}
}
output {
stdout {
codec => rubydebug
}
}
stdout shows:
{
"request" => "http://aaa.bbb/get?a=1&b=2",
"a" => "1",
"b" => "2"
}
That said, I would encourage you to create your own versions of the default URI patterns so that they set fields. You can then pass the querystring field off to kv. It's cleaner that way.
UPDATE:
For "make your own patterns", I meant to take the existing ones and modify them as needed. In logstash 1.4, installing them was as easy as putting them in a new file the 'patterns' directory; I don't know about patterns for >1.4 yet.
MY_URIPATHPARAM %{URIPATH}(?:%{URIPARAM:myuriparams})?
MY_URI %{URIPROTO}://(?:%{USER}(?::[^#]*)?#)?(?:%{URIHOST})?(?:%{MY_URIPATHPARAM})?
Then you could use MY_URI in your grok{} pattern and it would create a field called myuriparams that you could feed to kv{}.

Resources