linelog get quoted string on demand
Hi Folks, i've edited the linelog module(also with help from this forum) to get a json log file(sample): ``` linelog log_general_message { format = "%t Log for %{jsonquote:%{User-Name}}" filename = ${logfile} permissions = 0644 reference = "messages.%{%{Packet-Type}:-format}" messages { Access-Request = "{\"Datetime\": \"%t\",\"Packet-Type\": \"%{Packet-Type}\",\"TLS-Cert-Issuer\": \"%{jsonquote:%{TLS-Client-Cert-Issuer}}\"}" } } ``` which results in: ``` {"Datetime": "Fri Jun 18 15:18:30 2021","Packet-Type": "Access-Request","TLS-Cert-Issuer": "/O=sample/OU=sample/CN=sample"} ``` It works fine. I've also such entries to log the Access-Acecpt, Reject and challange with other variables. Those variables are not always filled so it would be perfect to set them to null to eayseli remove those entries in the later log parsing. It's in general also possible with the conditional syntax '%{%{Foo}:-bar}'. The problem comes when the variable is filled then because it don't get quotet. Sample to understand what i mean: ``` linelog log_general_message { format = "%t Log for %{jsonquote:%{User-Name}}" filename = ${logfile} permissions = 0644 reference = "messages.%{%{Packet-Type}:-format}" messages { Access-Request = "{\"Datetime\": \"%t\",\"Packet-Type\": \"%{Packet-Type}\",\"TLS-Cert-Issuer\": %{jsonquote:%{%{TLS-Client-Cert-Issuer}:-null}}" } } ``` results in ``` {"Datetime": "Fri Jun 18 15:18:30 2021","Packet-Type": "Access-Request","TLS-Cert-Issuer": null} ``` which is perfect. But when %{TLS-Client-Cert-Issuer} is filled it results in a not valid json file because it's not in quotes: ``` {"Datetime": "Fri Jun 18 15:18:30 2021","Packet-Type": "Access-Request","TLS-Cert-Issuer": /O=sample/OU=sample/CN=sample} ``` Does anyone have a idea how the contitional syntax could be used to get a quoted string when a variable is filled but a not quoted string 'null' when not? Best regards, lineconnect
results in ``` {"Datetime": "Fri Jun 18 15:18:30 2021","Packet-Type": "Access-Request","TLS-Cert-Issuer": null} ``` which is perfect. But when %{TLS-Client-Cert-Issuer} is filled it results in a not valid json file because it's not in quotes:
``` {"Datetime": "Fri Jun 18 15:18:30 2021","Packet-Type": "Access-Request","TLS-Cert-Issuer": /O=sample/OU=sample/CN=sample} ```
Does anyone have a idea how the contitional syntax could be used to get a quoted string when a variable is filled but a not quoted string 'null' when not?
No. you'd need to create the value outside of linelog, assign it to a temporary string, and then use that. If you wrap the assignment and linelog call in a policy, and then call the policy instead of linelog, that'd be the cleanest way to do what you want. -Arran
No. you'd need to create the value outside of linelog, assign it to a temporary string, and then use that. Sure, but good to know that i've not overseen something obvious.
If you wrap the assignment and linelog call in a policy, and then call the policy instead of linelog, that'd be the cleanest way to do what you want.
Thanks for you hint. Regards, Lineconnect
participants (3)
-
Arran Cudbard-Bell -
Lineconnect -
lineconnect