Last active
July 25, 2024 16:56
-
-
Save DavidHoenisch/74891a33b93331c852c095d0d0c505db to your computer and use it in GitHub Desktop.
Automatically create github issues with the results from a trivy scan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| trivy config . --format json | jq -c '.Results.[]| select(.Misconfigurations != null) |.Misconfigurations.[]' | zq -j 'cut Message, Resolution, Severity, CauseMetadata.Resource' - | parallel --delimiter '\\n' --quote issuefromscan |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| function create_issue() { | |
| local input_json="$1" | |
| TITLE=$(echo "$input_json" | jq -r '.Message') | |
| SEVERITY=$(echo "$input_json" | jq -r '.Severity') | |
| RESOLUTION=$(echo "$input_json" | jq -r '.Resolution') | |
| CAUSE=$(echo "$input_json" | jq -r '.CauseMetadata.Resource') | |
| BODYFINAL=$(printf "Severity: %s\nHow to fix:\n%s\nRoot Cause:\n%s" "$SEVERITY" "$RESOLUTION" "$CAUSE") | |
| echo "$BODYFINAL" | |
| gh issue create --title "$TITLE" --body "$BODYFINAL" | |
| } | |
| if [ -z "$1" ]; then | |
| echo "no input" | |
| exit 1 | |
| fi | |
| create_issue "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment