Last active
March 3, 2020 18:25
-
-
Save deekayen/fd60aafe81e801372f9e15965f98afad to your computer and use it in GitHub Desktop.
Curl the Redlock Prism Cloud API to get alerts from last week then POST them into a Splunk HTTP event collector for alternate archival and analysis. Note the date calculation appends 3 digits of milliseconds from microtime for a total 13 digital epoch value.
This file contains 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 | |
# For Mac, date is BSD based. We like GNU date parsing, | |
# which comes with sideloading date as a renamed gdate util. | |
# Use Homebrew to install some utilities: https://brew.sh | |
# brew install coreutils jq | |
###################### | |
# SET VALUES FOR THESE | |
# Prisma Cloud config | |
API="api2.prismacloud.io" | |
# update the api key in the JWT call | |
# Splunk config | |
HEC="http://splunk.example.com:8088/services/collector" | |
TOKEN="ce40f9de-asdf-asdf-adsf-d80ce1add1ef" | |
# Note this is in millisecond format with three extra digits of microtime. | |
START=$(gdate -d '2 weeks ago Sunday 00:00:00' +%s000) | |
END=$(gdate -d '1 week ago Saturday 23:59:59' +%s999) | |
# END EDITABLE VARIABLES | |
######################## | |
echo "Logging in..." | |
JWT="$(curl -s --request POST \ | |
--url https://${API}/login \ | |
--header 'accept: application/json; charset=UTF-8' \ | |
--header 'content-type: application/json; charset=UTF-8' \ | |
--data '{"username":"76a0d9c6-asdf-asdf-asdf-6a928a492a93","password":"v2gST9ktKbgPiDfrlsJilIXvFxg="}' \ | |
| jq '.["token"]' \ | |
| tr -d '"')" | |
echo "GETing alerts for UNIX millisecond epoch ${START} to ${END}..." | |
curl -s --request GET \ | |
--url "https://${API}/alert?detailed=true&timeType=absolute&startTime=${START}&endTime=${END}" \ | |
--header 'accept: */*' \ | |
--header "x-redlock-auth: ${JWT}" \ | |
> "prisma_alerts_${START}_${END}.json" | |
LINES=$(cat "prisma_alerts_${START}_${END}.json" | jq -r '.[] | @base64' | wc -l | xargs) | |
echo "Found ${LINES} alerts..." | |
# Filesize | |
du -sh "prisma_alerts_${START}_${END}.json" | |
# jq outputs prettified JSON over multiple lines. | |
# Doing a base64 encode brings it back to a single line string | |
# so that we can treat split elements the same as loop rows. | |
for row in $(cat "prisma_alerts_${START}_${END}.json" | jq -r '.[] | @base64'); do | |
_decode() { | |
echo ${row} | base64 --decode | jq -r ${1} | |
} | |
printf "\nPOSTing $(_decode .'id') to Splunk HTTP Event Collector..." | |
echo $TIME | |
curl -k "${HEC}" \ | |
-H "Authorization: Splunk ${TOKEN}" \ | |
-d "{\"time\": $(_decode .'alertTime'), \"sourcetype\": \"_json\", \"event\": $(_decode)}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This version is designed to run on a Macbook, which uses slightly different utiltities and versions than what you might find on EL7.
To seed data from the start of the account, the bottom half might look something more like this: