簡體   English   中英

Logstash凌亂的CSV文件

[英]Logstash Messy CSV File

我試圖用Logstash神交解析凌亂的CSV文件。

我最初使用的是CSV過濾器,但這意味着我必須首先在預處理中刪除一堆標頭數據。

理想情況下,由於其簡單性,我想再次使用CSV過濾器 我無法控制CSV文件的到達方式。 理想情況下,我希望Logstash能夠處理所有內容而無需任何預處理。

以下是我的CSV文件示例:

1,2,3,4,5,6,7
"text"
"text"

"01-Jan-2012"
"0123456789"

0,0,0,0,0,0,0,0,0,0

"col1Header",[...],col17Header"
"col1UoM",[...],col17UoM"

01-Jan-2012 11:00:01,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
01-Jan-2012 11:00:02,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
01-Jan-2012 11:00:03,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
01-Jan-2012 11:00:04,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

這是我的Logstash配置,它會產生注釋中顯示的錯誤:

input{
file{
    path => ["/opt/docs/*"]
    type => "log"
    start_position => "beginning"
    sincedb_path => "/dev/null"
    ignore_older => 0
    }
}
filter{
    grok{
        # error being returned here
        # error is: "Expected one of #, {, } at line 27, column 110 (byte 906) after filter{\n\t\n\n\t
# the regex following is to match all the header data that I don't want.
        match => {"header_data" => "(?<header_data>[0-9].*\n.*\n.*\n.*\n.*\n.*\n.*\n.*\n.*\n.*\n.*\n.*\n.*\n.*\n.*"\n)"}
    } # my plan was to then drop the header_data field (not implemented) and the data would be sent to the csv filter
    csv{
        columns => ["col17Header",[...],"col17Header]
    }
    mutate{
        convert => {"col2" => "float",[...] => "float","col17" => "float"}
    }
    date{
        match => ["col1","dd-MMM-YYYY HH:mm:ss"]
    }
}


output{
    elasticsearch{
        action => "index"
        hosts => ["192.168.1.118:9200"]
        index => "foo-logs"
    }
}

為清楚起見,這里產生了錯誤:

“在過濾器{\\ n \\ t \\ n \\ n \\ n \\ t之后的第27行第110行(字節906)中預期#,{,}#之后的正則表達式將匹配我不想要的所有標題數據。 match => {“header_data”=>“(?[0-9]。 \\ n。 \\ n。 \\ n。 \\ n。 \\ n。 \\ n。 \\ n。 \\ n。 \\ n。 \\ n。 \\ n 。 \\ n。 \\ n。 \\ n。*“\\ n)”}

我想刪除底部4行以上的所有數據。 我做了(我認為是低效的) 正則表達式模式來查找標題和CSV數據。

我需要的所有CSV文件都是我的示例文件中的最后4行,這就是我需要的所有數據。

我的想法是,我目前不打算以正確的方式做這件事,所以我願意接受任何建議。

在您的示例中,您想要的行具有唯一的模式:

^%{MONTHDAY}-%{MONTH}-%{YEAR}

那個模式的grok。 對於不匹配的行,您將獲得grokparsefailure,然后可以使用drop {}過濾器忽略它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM