2016-04-27 10 views
2

私はこのようになりますのRsyslog構成を有している:ソースタグがesblogある場合ダイナミックのRsyslogテンプレート

template(name="extract" type="string" string="%msg:R:/(?:"(level)":")((\\"| 

[^"])*)"/g–end%") 

if $InputFileTag == 'esblog' then { 
    set $!level = exec_template("extract"); 
} else { 
    set $!level = $syslogseverity-text; 
} 

template(name="json_lines" type="list") { 
    constant(value="{") 
     constant(value="\"@timestamp\":\"")  property(name="timereported" dateFormat="rfc3339") 
     constant(value="\",\"host\":\"")  property(name="hostname") 
     constant(value="\",\"json.level\":\"") property(name="$!level" format="json") 
     constant(value="\",\"facility\":\"") property(name="syslogfacility-text") 
     constant(value="\",\"tag\":\"") property(name="syslogtag" format="json") 
     constant(value="\",\"message\":\"") property(name="msg" format="json") 
    constant(value="\"}") 
} 

は基本的に、私は外の重症度を引っ張って「抽出物」から、この正規表現を使用したいですログメッセージそれ以外の場合は、デフォルトの重大度を使用します。次に、その変数をjson.levelラベルの中で使用して、送信メッセージにテンプレートを1つだけ必要とします。しかし、これはまだ動作するように運がない。正規表現と

サンプルメッセージ:https://regex101.com/r/lN4tD4/1

ERROR LOGの正規表現を変えるだけ必要

0341.407068000:main thread : error: can not find regex end in: '(?:"level":")(\"|[^"]*)"–end%' 
0341.407084000:main thread : PROP_INVALID for name '' 
0341.407097000:main thread : Called LogMsg, msg: error during parsing file /etc/rsyslog.conf, on or before line 32: invalid property '' 
0341.407195000:main thread : Called LogMsg, msg: error during parsing file /etc/rsyslog.conf, on or before line 32: error processing template object 
0341.407350000:main thread : Called LogMsg, msg: error during parsing file /etc/rsyslog.conf, on or before line 33: exec_template(): template 'extract' 

答えて

1

template(name="extract" type="string" string="%msg:R,ERE,2,DFLT:(\"level\":\")(\\\"|[^\"]*)\"--end%") 


if $programname contains "esb-log" then { 
    set $!level = exec_template("extract"); 
} else { 
    set $!level = $syslogseverity-text; 
} 

オンラインのRsyslog正規表現ツール:http://www.rsyslog.com/regex/

関連する問題