input
{
file
{
path => "C:/logstash-7.16.2/Outbound/sample_*.csv"
start_position => "beginning"
}
}
filter
{
csv
{
separator => ","
skip_empty_rows=>true
skip_header=>true
columns => ["project","director","no_of_hours_per_day","hourly_avg_rate_based_on_previous_month_actual","apr_fte_new","may_fte_new","jun_fte_new","jul_fte_new","aug_fte_new",
"sep_fte_new","oct_fte_new","nov_fte_new","dec_fte_new","jan_fte_new","feb_fte_new","mar_fte_new","apr_fte_new","may_fte_new","jun_fte_new",
"jul_fte_new","aug_fte_new","sep_fte_new","fy_total"]
skip_empty_columns => "false"
}
if ([project] == "Project")
{
mutate
{
add_field =>
{
"[@metadata][header]" => "header"
}
}
}
if([project] =="")
{
drop{}
}
ruby { init => "@@currentfinanceyear='currentfinanceyear'"
code => "@@currentfinanceyear=event.get('apr_fte_new')"
}
ruby {code => "event.set('currentFY',@@currentfinanceyear)"}
date {match => [ "currentFY" , "MMM-yy" ,"yy-MMM"]
target => "mytime"}
ruby {code => "event.set('[year_epoch]', (1000*event.get('mytime').to_f).round(0))"}
mutate {remove_field => ['mytime']}
ruby { init => "@@nextfinanceyear='nextfinanceyear'"
code => "@@nextfinanceyear=event.get('oct_fte_new')"
}
ruby {code => "event.set('FY',@@nextfinanceyear)"}
date {match => [ "FY" , "MMM-yy" ,"yy-MMM"]
target => "mytime"}
ruby {code => "event.set('[nextyear_epoch]', (1000*event.get('mytime').to_f).round(0))"}
mutate {remove_field => ['mytime']}
mutate {
add_field => {
"concat"=>"_"
"document_id" => "%{project}%{concat}%{director}"
}
}
}
output
{
stdout { }
stdout { codec => rubydebug }
if "_csvparsefailure" not in [tags]
{
elasticsearch
{
index => "indexbacklog"
hosts => ["${ES_HOST}"]
action => "update"
doc_as_upsert => "true"
document_id => "%{document_id}"
}
}}
CSV input
|Project|Director|No. of Hours per Day|Hourly Average Rate Based on Previous Month Actual|Apr/24|May/24|Jun/24|Jul/24|Aug/24|Sep/24|Oct/24|Nov/24|Dec/24|Jan/25|Feb/25|Mar/25|Apr/25|May/25|Jun/25|Jul/25|Aug/25|Sep/25|F24 Total|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|abc|a|9.0| 25.00 | 6.0 | 6.0 | 6.00 | 6.00 | 6.00 | 7.00 | 7.00 | 8.00 | 8.00 | 8.00 | 9.00 | 10.00 | 11.00 | 11.00 | 11.00 | 11.00 | 12.00 | 13.00 | 1,536,359 |
|xyz|b|9.0| 58.60 | 5.0 | 5.00 | 6.00 | 7.00 | 7.00 | 7.00 | 8.00 | 9.00 | 9.00 | 9.00 | 9.00 | 10.00 | 11.00 | 11.00 | 12.00 | 13.00 | 14.00 | 15.00 | 355,322 |
|abc|c|9.0| 89.60 | 2.0 | 3.00 | 3.00 | 3.00 | 3.00 | 3.00 | 3.00 | 4.00 | 5.00 | 6.00 | 6.00 | 7.00 | 8.00 | 9.00 | 10.00 | 10.00 | 10.00 | 10.00 | 204,102 |
|abc|d|9.0| 57.00 | 2.0 | 2.00 | 3.00 | 3.00 | 3.00 | 3.00 | 3.00 | 4.00 | 5.00 | 5.00 | 6.00 | 6.00 | 7.00 | 7.00 | 7.00 | 8.00 | 8.00 | 8.00 | 172,965 |
|xyz|e|9.0| 23.30 | 33.0 | 34.00 | 34.00 | 34.00 | 35.00 | 35.00 | 35.00 | 35.00 | 35.00 | 36.00 | 36.00 | 36.00 | 37.00 | 38.00 | 38.00 | 39.00 | 40.00 | 41.00 | 207,603 |
I have data in CSV. where in march month data will start from apr/24 and end column will be sep/25 . now in next month it will be may/24 and column end will be oct/25. so every month these column header will change.Any idea how to handle this.
Thanks you in advance