-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🪄 jq trick > group and count by severity 📊 #8
Comments
@mbarre 😺 |
grype nginx:latest -o json --file grype.json
cat grype.json | jq '.matches[].vulnerability.severity' | sort | uniq -c
7 "Critical"
23 "High"
10 "Low"
22 "Medium"
82 "Negligible"
9 "Unknown" c pas du json, mais ca permet de decouvrir |
💡 even shorter, and without temporary file : grype nginx:latest -o json | \
jq '.matches[].vulnerability.severity' \
| sort \
| uniq -c 👇
|
jq '[.matches[].vulnerability | {severity : .severity} ]| group_by(.severity)[] |.[0] + { count: length } ' {
"severity": "Critical",
"count": 8
}
{
"severity": "High",
"count": 26
}
{
"severity": "Low",
"count": 10
}
{
"severity": "Medium",
"count": 24
}
{
"severity": "Negligible",
"count": 82
}
{
"severity": "Unknown",
"count": 4
} |
je teste ça ! |
👌 Can you also please provide (pure
|
I think the next step will be to make a PR to feed JQ_TRICKS.md 👏 🏅 @mbarre |
❯ cat grype.json | jq -r '[[.matches[].vulnerability | {severity : .severity}] | group_by(.severity)[] | .[0] + {count: length}] ' [
{
"severity": "Critical",
"count": 8
},
{
"severity": "High",
"count": 26
},
{
"severity": "Low",
"count": 10
},
{
"severity": "Medium",
"count": 24
},
{
"severity": "Negligible",
"count": 82
},
{
"severity": "Unknown",
"count": 4
}
] |
🤑 you git it ! Just drop PRs on the tricks now 🚀 🙏 |
cat grype.json | jq -r '[.matches[].vulnerability | {severity}] | group_by(.severity) | [.[] | {severity: .[0].severity, count: . | length}]| to_entries as $row | ( ( map(keys_unsorted ) | add | unique ) as $cols | ( [$cols] | flatten) , ( $row | .[] as $onerow | $onerow |( [ ( $cols | map ($onerow.value[.] as $v | $v ) ) ]| flatten ) ) ) | @csv '
cat grype.json | jq -r '[.matches[].vulnerability | {severity}] | group_by(.severity) | [.[] | {severity: .[0].severity, count: . | length}]| to_entries as $row | ( ( map(keys_unsorted ) | add | unique ) as $cols | ( [$cols] | flatten) , ( $row | .[] as $onerow | $onerow |( [ ( $cols | map ($onerow.value[.] as $v | $v ) ) ]| flatten ) ) ) | @tsv '
|
Afert some integration tests, it appears that it would be much more optimal to get the output like following :
👉 Can you please put columns in the following order :
|
cat grype.json | jq -r '[.matches[].vulnerability | {severity}] | group_by(.severity) | [.[] | {severity: .[0].severity, count: . | length}]|(.[0] | keys_unsorted) as $keys | ([$keys] + map([.[ $keys[] ]])) [] | @csv'
|
Provide the
jq
query that takes in input agrype -o json
command and returnssee Group vulnerabilities by severity
🐦 Tweet
:
The text was updated successfully, but these errors were encountered: