Score:0

rsyslog: regex extract between 2 strings

cn flag

I want to extract a substring of msg field between 2 strings.

Example of the log: Test local logging: db=testdb,message

What I want is "testdb", so, the string between "db=" and ","

This is my configuration:

template(name="jsonTemplate"
         type="list"
         option.json="on") {
           constant(value="{")
             constant(value="\"timestamp\":\"")      property(name="timereported" dateFormat="rfc3339")
             constant(value="\",\"message\":\"")     property(name="msg")
             constant(value="\",\"host\":\"")        property(name="hostname")
             constant(value="\",\"severity\":\"")    property(name="syslogseverity-text")
             constant(value="\",\"facility\":\"")    property(name="syslogfacility-text")
             constant(value="\",\"syslogtag\":\"")   property(name="syslogtag")
             constant(value="\",\"database\":\"")    property(name="msg" regex.expression="(db=)(.*)(,)" regex.match="0" regex.type="ERE")
           constant(value="\"}")
         }

However, the result I got is: "db=testdb,", but I don't want "db=" and "," to appear.

I've tested several regex but didn't worked:

(?<=db=)(.*)(?=,) --> this works in https://regex101.com

I don't understand why the regex doesn't work.

Version: rsyslogd: version 8.24.0

Score:0
cn flag

Found the solution using the submatch 2:

property(name="msg" regex.expression="(db=)(.*)(,)" regex.submatch="2" regex.type="ERE")
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.