====== Output of control commands using the JSON format ======
{{indexmenu_n>11}}
To simplify parsing command output when integrating with external platforms and web applications, ''fdpi_ctrl'' supports JSON output.
To enable JSON output, specify the following additional command-line parameter:
--outformat json
For convenient JSON processing, we recommend installing the ''jq'' utility:
yum install epel-release
yum-config-manager --disable epel
yum --enablerepo epel install jq
Examples:
- Pretty-print the command output: fdpi_ctrl list all profile --policing --outformat json | jq .
- Display statistics for different policing profiles: fdpi_ctrl list all --policing --outformat json | jq '.lpolicings[].description.name' | sort | uniq -c or produce the same statistics in JSON format using ''jq'': fdpi_ctrl list all --policing --outformat json | jq '[{ name: .lpolicings[].description.name, login: .login }] | group_by(.name) | .[] | { name: .[0].name, count: . | length }'
- For repeated use, this command can be wrapped in a Bash function: function fdpi_policing_stat() { fdpi_ctrl list all --policing --outformat json | jq '[{ name: .lpolicings[].description.name, login: .login }] | group_by(.name) | .[] | { name: .[0].name, count: . | length }'; } and then simply invoked from the command line: fdpi_policing_stat
To make such functions permanently available, save them in the ''.bash_profile'' file.