1

I want to make a REST API call from rsyslog. This is how the curl command looks like

curl --request POST \
  --url http://10.1.1.1:9000/logforwarder \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '[
 {
   "text": "text1",
   "samplefield":"sample",
   "hostname": "eng.com",
   "appname": "RA"
 },
 {
   "text": "text2",
   "samplefield":"sample",
   "hostname": "eng.com",
   "appname": "RA"
 }
]'

How to achieve this from rsyslog.conf. Sadly the Rsyslog documentation is not so clear on this aspect. I have a template which formats the messages in the form of json and I want to send that json as a post request.

Sample template:

# define a template to specify which fields we send

template(name="jsonLogFormat" type="list" option.json="on") {
  constant(value="{")
  constant(value="\"@timestamp\":\"")
  property(name="timereported" dateFormat="rfc3339")
  constant(value="\",\"host\":\"")
  property(name="hostname")
  constant(value="\",\"severity\":\"")
  property(name="syslogseverity-text" caseConversion="upper")
  constant(value="\",\"syslog-tag\":\"")
  property(name="syslogtag")
  constant(value="\",\"message\":\"")
  property(name="msg")
  constant(value="\"}")
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.