Is there a way to test Elasticsearch mutate locally? - elasticsearch

I have written as a grok mutate as below to remove a particular pattern:
mutate {
gsub => [ "message", "\nmytestpattern", "" ]
}
But I am unable to test it locally without pushing the code to a logstash pipeline .
Is there a way we can test mutate functions locally to see if the gsub is working as expected ?

You may use the Stack Management > Ingest Pipelines feature of Kibana. From there, you can create a new pipeline, add a gsub processor with your desired configuration, and then rely on the feature "Test pipeline" to verify how the processor behaves with some sample documents you provide

Related

Grok works in the debugger, but does not work in logstash.conf

I'm trying to extract two fields from my unstructured logs logstash. My log messages look like this:
[2/9/2022 7:32:16 PM] logmessage
I have this Grok:
grok {
match => { "message" => "\[(?<app_log_date>\d{1,2}/\d{1,2}/\d{4} (1[0-2]|0?[1-9]):[0-5][0-9]:[1-9][0-9] (AM|PM))\] %{GREEDYDATA:app_message}" }
}
When I put this in the Grok debugger, it works perfectly fine, but when I put this in my logstash.conf, it produces malformed messages in my ElasticSearch output and a _grokparsefailure. Any idea what I'm doing wrong here? Do I need to escape the brackets?
I just checked my logs in the morning and looks like they are getting parsed correctly! Not sure if it was my test logs that I was forcing via VS Code or what, but it is working as indented now.

Managing the output of logstash pipelines

We're trying to add a field for all pipelines in a LogStash server (we have 6 on-premise logstash, 3 in each country).
In specific we're trying to add a field from environment variables to mark the output of a pipeline with a suffix in the index, for example (us, eu), but we have many pipelines (approximately 145 by country) and the main idea isn't adding this environment variable in all outputs plugins, also that is not mandatory so if someone forgets to add the environment variable we'll have serious problems.
Then, we're trying to find a method to add this field automatically in each output without add this environment variable, in your experience is it possible in logstash "world" attach a suffix in an index in an output plugin?
example
output {
elasticsearch {
hosts => localhost
manage_template => false
index => "index-%{+YYYY.MM.dd}_${COUNTRY_VARIABLE}"
}
}
I want to add ${COUNTRY_VARIABLE} automatically before sending the document.
It's not possible to do this in elasticsearch because that is mounted in aws and the traffic to check all possible hosts inputs from logstash is a cost that we don't want to have it.
Sure, this will work. If you add a fallback value to the env var, you're fine in the case someone forgot to define one: ${COUTRY_VARIABLE:XX}
output {
elasticsearch {
hosts => localhost
manage_template => false
index => "index-%{+YYYY.MM.dd}_${COUNTRY_VARIABLE:ABC}"
}
}
See here for more background on env vars in logstash.

How to access ruby code variables in the output section of logstash conf

I am working to create dynamic logstash buckets based on date formulas. My objective is to be able to dynamically calculate the date of a logstash bucket based on a defined variable in the incoming log file.
For this, I am currently testing with a single .conf file that contains the input, filter (with ruby code) and output section. I am pushing the output to my elasticsearch setup. I have worked out the formulas and tested the same in regular ruby through 'irb' and the formulas are working as expected.
I am lost when it comes to be able to access a variable which is present in the filter section in the output section.
I have successfully used the following syntax in the output section to reference the year/month/date:
output {
elasticsearch {
hosts => [ "localhost:9200" ]
user => elastic
password => "bar"
index => "foo-%{+YYYY.MM.dd}"
}
}
I would try the "%{variable}" syntax

Logstash multiline filter fragments logs

I'm trying to use the multiline filer to combine a fairly long java exception stack trace along with the main log message. I'm using the example shown here https://gist.github.com/smougenot/3182192
Following is my code:
input{
stdin{}
}
filter{
multiline {
pattern => "(^.+Exception: .+)|(^\s+at .+)|(^\s+... \d+ more)|(^\s*Caused by:.+)"
what => "previous"
}
}
However, instead of combining the stacktrace into one event, it is automatically fragmented into multiple different logs.
I can't seem to understand why? I have tried using codec instead of filter, yet the problem exists.

Logstash giving Exception when searching any keyword on UI

Started logstash with config set as embedded=true for elasticsearch. Getting following exception:
NativeException: org.elasticsearch.action.search.SearchPhaseExecutionException: Failed to execute phase [initial], No indices / shards to search on, requested indices are []
whenever tried to search any keyword on UI.
Currently we are trying to test with static log files(copied from some server), not ever growing log files.
Any help on this will be appreciated.
I was having the same issue and the reason was that I was using a grok filter using the same capture name twice for different patterns, e.g.
filter{
grok {
type => "foo"
keep_empty_captures => true
pattern => [
"(?<bar>/file/path/a)",
"(?<bar>/file/path/b)"
]
}
}
I replaced the second <bar> with a <qux> and the error disappeared.

Resources