Skip to content

Instantly share code, notes, and snippets.

@renshuki
Last active January 24, 2020 07:40
Show Gist options
  • Save renshuki/a9cde3196c2a6c84bbcacb20726907a7 to your computer and use it in GitHub Desktop.
Save renshuki/a9cde3196c2a6c84bbcacb20726907a7 to your computer and use it in GitHub Desktop.
Logstash pipeline configuration - split CSV columns into multiple events

CSV Sample

col1,col2,col3
0,1,2
3,4,5
6,7,8

Code

input {
	file {
		path => "file.csv"
		start_position => "beginning"
		sincedb_path => "/dev/null"
	}
}

filter {
	csv { autodetect_column_names => true }
	ruby {
		code => "
		event.set('type', [
			'col1',
			'col2',
			'col3'
		])"
	}
  
	split { field => "type" }

	if [type] == "col1" and [col1] { mutate { add_field => { "value" => "%{col1}" } } }
	else if [type] == "col2" and [col2] { mutate { add_field => { "value" => "%{col2}" } } }
        else if [type] == "col3" and [col3] { mutate { add_field => { "value" => "%{col3}" } } }
}


output {
	stdout { codec => rubydebug }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment