Skip to content

Commit 220e7a1

Browse files
authored
Merge pull request #232177 from yelevin/patch-1
Adding another example
2 parents 1fb488a + 4b32796 commit 220e7a1

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

articles/sentinel/connect-logstash.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,58 @@ Here are some sample configurations that use a few different options.
144144
}
145145
```
146146

147+
- A more advanced configuration to parse a custom timestamp and a JSON string from unstructured text data and log a selected set of fields into Log Analytics with the extracted timestamp:
148+
149+
```ruby
150+
# Example log line below:
151+
# Mon Nov 07 20:45:08 2022: { "name":"_custom_time_generated", "origin":"test_microsoft", "sender":"[email protected]", "messages":1337}
152+
# take an input
153+
input {
154+
file {
155+
path => "/var/log/test.log"
156+
}
157+
}
158+
filter {
159+
# extract the header timestamp and the Json section
160+
grok {
161+
match => {
162+
"message" => ["^(?<timestamp>.{24}):\s(?<json_data>.*)$"]
163+
}
164+
}
165+
# parse the extracted header as a timestamp
166+
date {
167+
id => 'parse_metric_timestamp'
168+
match => [ 'timestamp', 'EEE MMM dd HH:mm:ss yyyy' ]
169+
timezone => 'Europe/Rome'
170+
target => 'custom_time_generated'
171+
}
172+
json {
173+
source => "json_data"
174+
}
175+
}
176+
# output to a file for debugging (optional)
177+
output {
178+
file {
179+
path => "/tmp/test.txt"
180+
codec => line { format => "custom format: %{message} %{custom_time_generated} %{json_data}"}
181+
}
182+
}
183+
# output to the console output for debugging (optional)
184+
output {
185+
stdout { codec => rubydebug }
186+
}
187+
# log into Log Analytics
188+
output {
189+
microsoft-logstash-output-azure-loganalytics {
190+
workspace_id => '[REDACTED]'
191+
workspace_key => '[REDACTED]'
192+
custom_log_table_name => 'RSyslogMetrics'
193+
time_generated_field => 'custom_time_generated'
194+
key_names => ['custom_time_generated','name','origin','sender','messages']
195+
}
196+
}
197+
```
198+
147199
> [!NOTE]
148200
> Visit the output plugin [GitHub repository](https://github.com/Azure/Azure-Sentinel/tree/master/DataConnectors/microsoft-logstash-output-azure-loganalytics) to learn more about its inner workings, configuration, and performance settings.
149201

0 commit comments

Comments
 (0)