Nossos registros são enviados de nossos aplicativos para o rsyslog em execução no mesmo host. O Rsyslog então encaminha as mensagens para a Sumo Logic.
Precisamos adicionar alguns metadados às nossas mensagens de log no campo de dados estruturados. Alguns de nossos aplicativos já usam dados estruturados, portanto, não podemos simplesmente substituir a propriedade de dados estruturados em nosso modelo.
Além disso, a propriedade% STRUCTURED-DATA% inclui os colchetes de abertura e fechamento, portanto, não podemos colocar algo como [%STRUCTURED-DATA% newmetadata]
no modelo.
De acordo com a documentação do substituto de propriedade , nossas opções são usar FromChar
e ToChar
ou expressões regulares. Eu verifiquei a fonte e confirmei que ToChar
não pode contar para trás desde o final.
Eu usei a ferramenta rsyslog regex para criar o seguinte modelo:
template(name="metadata_syslog" type="string" string="<%PRI%>1 %TIMESTAMP:::date-rfc3339% %HOSTNAME% %APP-NAME% %PROCID% %MSGID% [%STRUCTURED-DATA:R,ERE,1,FIELD:\[([^]]*)\]--end% extrafield=value] %msg%\n")
Do seguinte exemplo de evento
<142>1 2016-03-31T17:30:20.007Z some.host.name service/prod/app/foo_v2 - Audit [mdc@xxxxx category="io.service.segment.IndexIO$DefaultIndexIOHandler" thread="foo_v2-incremental-persist"] Processing file[dim_device.drd]
a ferramenta regex analisou corretamente os dados estruturados sem os colchetes.
Quando eu usei este template no rsyslog, eu recebo um erro de sintaxe sobre a% PRI% part (saída de depuração):
Reading a token: 9936.286569660:main thread : Called LogMsg, msg: error during parsing file /etc/rsyslog.d/21-logging.conf, on or before line 4: invalid character '"' in object definition - is there an invalid escape sequence somewhere?
rsyslogd: error during parsing file /etc/rsyslog.d/21-logging.conf, on or before line 4: invalid character '"' in object definition - is there an invalid escape sequence somewhere? [v8.17.0 try http://www.rsyslog.com/e/2207 ]
9936.286590559:main thread : Called LogMsg, msg: error during parsing file /etc/rsyslog.d/21-logging.conf, on or before line 4: invalid character '<' in object definition - is there an invalid escape sequence somewhere?
rsyslogd: error during parsing file /etc/rsyslog.d/21-logging.conf, on or before line 4: invalid character '<' in object definition - is there an invalid escape sequence somewhere? [v8.17.0 try http://www.rsyslog.com/e/2207 ]
9936.286606008:main thread : Called LogMsg, msg: error during parsing file /etc/rsyslog.d/21-logging.conf, on or before line 4: invalid character '%' in object definition - is there an invalid escape sequence somewhere?
rsyslogd: error during parsing file /etc/rsyslog.d/21-logging.conf, on or before line 4: invalid character '%' in object definition - is there an invalid escape sequence somewhere? [v8.17.0 try http://www.rsyslog.com/e/2207 ]
Next token is token NAME ()
9936.286632522:main thread : Called LogMsg, msg: error during parsing file /etc/rsyslog.d/21-logging.conf, on or before line 4: syntax error on token 'PRI'
rsyslogd: error during parsing file /etc/rsyslog.d/21-logging.conf, on or before line 4: syntax error on token 'PRI' [v8.17.0 try http://www.rsyslog.com/e/2207 ]
Error: popping token '=' ()
Stack now 0 1 5 28 52
Error: popping token NAME ()
Stack now 0 1 5 28
Error: popping nterm nvlst ()
Stack now 0 1 5
Error: popping token BEGIN_TPL ()
Stack now 0 1
Error: popping nterm conf ()
Stack now 0
Cleanup: discarding lookahead token NAME ()
Stack now 0
9936.286780810:main thread : Called LogMsg, msg: CONFIG ERROR: could not interpret master config file '/etc/rsyslog.conf'.
rsyslogd: CONFIG ERROR: could not interpret master config file '/etc/rsyslog.conf'. [v8.17.0 try http://www.rsyslog.com/e/2207 ]