nxlog parse_csv 在 IIS 日志文件中出现奇数字符时失败

nxlog parse_csv 在 IIS 日志文件中出现奇数字符时失败

我正在解析 IIS 日志。

此错误显示在我的 nxlog 事件日志中:

2013-12-24 18:40:20 ERROR if-else failed at line 50, character 351 in C:\Program Files (x86)\nxlog\conf\nxlog.conf. statement execution has been aborted; procedure 'parse_csv' failed at line 50, character 225 in C:\Program Files (x86)\nxlog\conf\nxlog.conf. statement execution has been aborted; Invalid CSV input: '2012-06-20 14:31:37 10.1.0.16 GET /App_Themes/Authenticated/Styles/index.jsp - 80 - 192.168.0.93 "|dir 302 0 0 62'

这是日志文件中各行的更好视图

2012-06-20 14:31:37 10.1.0.16 GET /App_Themes/Authenticated/Styles/index.jsp - 80 - 192.168.0.93 |dir 302 0 0 62

这是我的 nxlog.conf 文件;我在第 51 行将其截断,因为其余部分只是路由。

define ROOT C:\Program Files (x86)\nxlog

Moduledir %ROOT%\modules
CacheDir %ROOT%\data
Pidfile %ROOT%\data\nxlog.pid
SpoolDir %ROOT%\data
LogFile %ROOT%\data\nxlog.log

SuppressRepeatingLogs TRUE
LogLevel INFO


#<Extension fileop>
#    Module      xm_fileop
#    <Schedule>
#        Every   1 hour
#        Exec    file_cycle('%ROOT%\data\nxlog.log', 5);
#    </Schedule>
#</Extension>

<Extension syslog>
    Module      xm_syslog
</Extension>

<Extension json>
    Module      xm_json
</Extension> 

<Extension w3c>
    Module      xm_csv
    Fields  $date, $time, $s-ip, $cs-method, $cs-uri-stem, $cs-uri-query, $s-port, $cs-username, $c-ip, $cs-User-Agent, $sc-status, $sc-substatus, $sc-win32-status, $time-taken
    FieldTypes  string, string, string, string, string, string, string, string, string, string, string, string, string, string
    Delimiter   ' '
    QuoteChar   '"'
    EscapeControl FALSE
    UndefValue  -
</Extension>


<Input iis_in>
    Module  im_file
    File    "f:\\iislogs\\u_*.log"
    ReadFromLast FALSE
    Exec    if $raw_event =~ /^#/ drop();                        \
                else                                             \
                {                                                \
                    w3c->parse_csv();                            \
                    $EventTime = parsedate($date + " " + $time); \
                    to_json(); \
                }
</Input>
  1. 这是我应该担心的事情吗?
  2. 这次的失败是因为“角色”吗?
  3. 我该如何避免这种情况?

编辑:进一步的研究表明,这可能是由于“cs(User-Agent)”字段中的字符编码错误造成的。不知道该怎么做。

#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) sc-status sc-substatus sc-win32-status time-taken
2012-02-04 22:09:37 10.1.0.16 GET /login.aspx - 80 - 192.168.0.93 +xa7 403 4 5 218
2012-02-04 22:09:37 10.1.0.16 GET /signup/ - 80 - 192.168.0.93 +xa7 302 0 0 15
2012-02-04 22:09:37 10.1.0.16 GET /signup/ - 80 - 192.168.0.93 " 302 0 0 15
2012-02-04 22:09:37 10.1.0.16 GET /signup/ - 80 - 192.168.0.93 ߧߢ 302 0 0 0
2012-02-04 22:09:37 10.1.0.16 GET /signup/ - 80 - 192.168.0.93 

答案1

目前还不清楚是否有字符是否包含在您的输入中。尝试将 QuoteChar 设置为双引号以外的其他字符。

相关内容