Skip to content

Instantly share code, notes, and snippets.

@LaurenceJJones
Last active June 12, 2023 19:31
Show Gist options
  • Save LaurenceJJones/059bd071caa8690b20d7eb18a44dca48 to your computer and use it in GitHub Desktop.
Save LaurenceJJones/059bd071caa8690b20d7eb18a44dca48 to your computer and use it in GitHub Desktop.
crowdsec lights
#!/bin/bash
### Prequesites
## jq curl
###
### Variables
LAPI="http://127.0.0.1:8080"
ORIGINS="crowdsec,cscli" ## Comma separated list of ORIGINS ## Dont include CAPI as capi will flush every 2 hours and will make your lights go wild
API_KEY=""
STARTUP=true ## Fetches all decisions on startup if true
while true; do
RES=$(curl -s -H 'Accept: application/json' -H "X-Api-Key: $API_KEY" "$LAPI/v1/decisions/stream?startup=$STARTUP&origins=$ORIGINS")
STARTUP=false
for row in $(echo "$RES" | jq -r '.new'); do
## TODO: Add your own logic here to increase
echo "New decision: $row"
done
for row in $(echo "$RES" | jq -r '.deleted'); do
## TODO: Add your own logic here to decrease
echo "Deleted decision: $row"
done
sleep 60
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment