我想修改 IIS 日志以進一步傳輸到目的地。現在我正在使用 xm_csv 模塊決議 IIS 日志,就像在模板中一樣。UndefValue 被禁用以不為空。
如何與來自 w3c_parser 的決議資料進行互動?
比如我想組合成一個變數 $request = '"' $cs-method ' ' $cs-uri-stem ' ' $cs-version '"'; 這樣的值,但我得到一個錯誤。當我嘗試將 w3c_parser 中的欄位寫入 $raw_event 時,我也會收到錯誤訊息。添加任何其他資料都不會出錯。
例如$raw_event = $c-ip ——錯誤
$raw_event = $EventTime ' ' $http_host -- 沒有錯誤
下面的示例錯誤、日志和組態檔
2022-03-23 16:49:56 錯誤無法決議 C:\Program Files\nxlog\conf\nxlog.conf:59 處的 Exec 塊;無法決議 C:\Program Files\nxlog\conf\nxlog.conf 中第 71 行字符 32 處的陳述句;語法錯誤,意外 ,預期 (
2022-03-23 16:49:56 錯誤模塊 'iis_w3c' 有配置錯誤,未添加到 C:\Program Files\nxlog\conf\nxlog.conf:84 中的路由 'uds_to_file'
2022-03-23 16:49:56 錯誤路由 uds_to_file 在沒有輸入模塊的情況下不起作用,在 C:\Program Files\nxlog\conf\nxlog.conf:84 中被忽略
2022-03-23 16:49:56 警告未定義路線!
2022-03-23 16:49:56 警告未啟動未使用的模塊 iis_w3c
2022-03-23 16:49:56 警告未啟動未使用的模塊檔案
2022-03-23 16:49:56 INFO nxlog-ce-3.0.2272 開始
當前日志格式
date time s-computername s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs-version cs(User-Agent) cs(Cookie) cs(Referer) cs-host sc-status sc-bytes cs-bytes time-taken
2022-03-23 08:00:01 HOST.DOMAIN 99.XX.XX.4 GET /AnalyticsService - 443
- XX.XX.XX.XXX HTTP/1.1 Zabbix - - site.host.domain 200 3918 144 4
Required log format
$http_host $remote_addr $remote_user [$time_local] UNIX-TIME-$msec "$request" $status "$sent_http_content_type" $body_bytes_sent "$http_referer" "$http_user_agent" "$http_cookie" $request_time "$upstream_addr" NGINX-CACHE-$upstream_cache_status "$request_id" "$request_body"
host.domain 99.99.99.249 - [11/Mar/2022:20:09:56 0300] UNIX-TIME-1647018596.031 "GET /api/company.php?id=853747 HTTP/1.1" 200 "text/xml; 字符集= UTF-8“1455” - “ - ”“” - “20B6B325EA192383CB1244412247C5EA = 3002538F353C9DAAB4F742176830404989A840; ETPSID = F488B343A23D1A4A23323A23D1A4A23322089A0”0.059 0.059“10.10.10.111:80”nginx-cache--“D0B5AC12CF82671067AA5E6C5C” - “
Panic Soft
#NoFreeOnExit TRUE
define ROOT C:\Program Files\nxlog
define CERTDIR %ROOT%\cert
define CONFDIR %ROOT%\conf\nxlog.d
define LOGDIR %ROOT%\data
define LOGFILE %LOGDIR%\nxlog.log
LogFile %LOGFILE%
Moduledir %ROOT%\modules
CacheDir %ROOT%\data
Pidfile %ROOT%\data\nxlog.pid
SpoolDir %ROOT%\data
<Extension _syslog>
Module xm_syslog
</Extension>
<Extension fileop>
Module xm_fileop
</Extension>
<Extension _charconv>
Module xm_charconv
AutodetectCharsets iso8859-2, utf-8, utf-16, utf-32
</Extension>
<Extension _exec>
Module xm_exec
</Extension>
#Create the parse rule for IIS logs. You can copy these from the header of the IIS log file.
<Extension w3c_parser>
Module xm_csv
Fields $date, $time, $s-computername, $s-ip, $cs-method, $cs-uri-stem, $cs-uri-query, $s-port, $cs-username, $c-ip, $cs-version, $cs(User-Agent), $cs(Cookie), $cs(Referer), $cs-host, $sc-status, $sc-bytes, $cs-bytes, $time-taken
FieldTypes string, string, string, string, string, string, string, integer, string, string, string, string, string, string, string, integer, integer, integer, integer
Delimiter ' '
EscapeChar '"'
QuoteChar '"'
EscapeControl FALSE
# UndefValue -
</Extension>
<Extension w3c_out>
Module xm_csv
Fields $http_host, $c-ip, $cs-username, $EventTime1, $sc-status, $Unix
FieldTypes string, string, string, string, string, string
Delimiter ' '
# UndefValue -
QuoteMethod None
</Extension>
<Input iis_w3c>
Module im_file
File 'C:\inetpub\logs\LogFiles\W3SVC1\u_ex*.log'
SavePos TRUE
<Exec>
if $raw_event =~ /^#/ drop();
else
{
w3c_parser->parse_csv();
$EventTime = parsedate($date " " $time);
$EventTime = $EventTime (3 * 3600);
$EventTime1 = strftime($EventTime, '[%d/%b/%Y:%H:%M:%S]');
# $EventTime1 = '$EventTime1' ' 0003]';
$Unix = integer($EventTime);
$Unix = 'UNIX-TIME-' $Unix;
$http_host = "site.host.domain";
# $request = '"' $cs-method ' ' $cs-uri-stem ' ' $cs-version '"';
# $request = $cs-method;
w3c_out->to_csv();
}
</Exec>
</Input>
<Output file>
Module om_file
File 'C:\inetpub\logs\LogFiles\Parser\w3c.txt'
</Output>
<Route uds_to_file>
Path iis_w3c => file
</Route>
uj5u.com熱心網友回復:
讓我們從 conf 檔案中的 NXLog 語言開始。不允許使用顯式格式的破折號 - 您可以查看: https ://nxlog.co/docs/nxlog-ce/nxlog-reference-manual.html#lang_fields
因此,需要使用花括號來達到目標?? ( {})。如果我正確理解您的問題,這可能有助于解決您的大部分問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/452161.html
