Generates a detailed notification via discord when crowdsec makes a ban decision.
The notification includes details about the malicous IP, including geolocation, and will present a static map image of the approximate location in the notification.
It also includes all the target uris, which is very helpful when debugging false positives, so that you can better create whitelists / parsers.
- Need an API Key from Geoapify, it was the only service I could find with a free tier static maps API.
Pass this API key to crowdsec via environment variable with
GEOAPIFY_API_KEY: ${GEOAPIFY_API_KEY}(refer to sample compose.yaml) - Optional: For more advanced statistics like Malicousness Score and more detailed geolocation, you will need access to the Crowdsec CTI Smoke database. You can get access to this for free, up to 30 queries/day. You need to generate a CTI API Key on the Crowdsec Console. Once you have your API Key, you will need to configure crowdsec to use it. An example entry in
config.yaml(in this case you would also need to set the env variableCTI_API_KEY, or you would manually paste the key in the config file)
api:
cti:
key: ${CTI_API_KEY}
cache_timeout: 60m
cache_size: 50
enabled: true
log_level: debug- Need to create a discord webhook, and take note of the webhook ID and token. The url will be of the form
https://discord.com/api/webhooks/${DISCORD_WEBHOOK_ID}/${DISCORD_WEBHOOK_TOKEN}Pass these to crowdsec as environment variables as well, again refer to the sample compose.yaml
environment:
GEOAPIFY_API_KEY: ${GEOAPIFY_API_KEY}
DISCORD_WEBHOOK_ID: ${DISCORD_WEBHOOK_ID}
DISCORD_WEBHOOK_TOKEN: ${DISCORD_WEBHOOK_TOKEN}
# If using CTI API
CTI_API_KEY: ${CTI_API_KEY}- Map the notification file (
discord.yaml) to crowdsec at/etc/crowdsec/notifications/discord.yaml. Again rever tocompose.yaml
volumes:
- ./notifications/discord.yaml:/etc/crowdsec/notifications/discord.yaml- Don't forget to create a
.envfile with the contents of the env variables
GEOAPIFY_API_KEY=some-api-key
DISCORD_WEBHOOK_ID=some-webhook-id
DISCORD_WEBHOOK_TOKEN=some-webhook-token
# If using CTI API
CTI_API_KEY=api-key-from-crowdsec-console- Update the mapped
profiles.yamlto include thediscordnotifier, here is an example
name: default_ip_remediation
filters:
- Alert.Remediation == true && Alert.GetScope() == "Ip"
decisions:
- type: ban
duration: 168h
notifications:
# - slack_default # Set the webhook in /etc/crowdsec/notifications/slack.yaml before enabling this.
# - splunk_default # Set the splunk url and token in /etc/crowdsec/notifications/splunk.yaml before enabling this.
# - http_default # Set the required http parameters in /etc/crowdsec/notifications/http.yaml before enabling this.
# - email_default # Set the required email parameters in /etc/crowdsec/notifications/email.yaml before enabling this.
- discord
on_success: break- Test by manually banning an IP and it should generate a notification
docker exec crowdsec cscli decisions add --ip 192.168.1.10 -d 10m





hi, the map not showing in discord notification.