linelog get quoted string on demand
Lineconnect
nabble at felix.world
Fri Jun 18 17:42:43 CEST 2021
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
More information about the Freeradius-Users
mailing list