Creating JSON content in irule

Hello.

I’m using an irule to send traffic logs to a remote syslog server, using JSON format. Currently I’m creating JSON content manually, using format function, ie:

set message [format {{ "key1":"%s", "key2":"%s", ... }} $value1 $value2 ... ]
HSL::send $hsl $message

However, this is a bit painful, especially as the number of key/value pairs rise, and doesn’t handle internal escaping of characters inside values. Is there a better way to create JSON content in irule ?

Hello Guillaume.

You could use a request-logging and set a JSON format in the request-logging template.

Regards,

Dario.

Hello Dario, thanks for the suggestion. Unfortunately, this will only work for HTTP traffic, whereas I have other kind of traffic to report, such as SMTP, IMAP, POP, etc…