Notify via a webhook, in this case Discord, when ClamAV detects an infected file.

Tiempo de lectura: 2 minutos

To set up notifications through Discord when ClamAV detects a virus, you can follow these general steps.

Keep in mind that these steps are a guide and may require adjustments based on your specific environment and preferences.

1. Create a Discord Webhook:

  1. Open your Discord server and select the channel where you want to receive notifications.
  2. Click the gear icon to access the server settings.
  3. Select “Integrations” in the left sidebar.
  4. Click “Create an integration” and choose “Webhook”.
  5. Give the webhook a name, choose a channel, and upload an image if desired.
  6. Copy the generated webhook URL. You’ll use it to send notifications from ClamAV.

2. Modify the ClamAV Command to Send Notifications:

You’ll need to modify the ClamAV command to send notifications to the Discord webhook when it detects a virus. Here’s a basic example using curl to send a POST request to the webhook:

docker exec clamav clamscan --infected --recursive /data/html /data/html2 \
  && curl -H "Content-Type: application/json" -X POST -d '{"content": "A virus has been detected with ClamAV!"}' <WEBHOOK_URL>

Replace <WEBHOOK_URL> with the webhook URL you obtained in the previous step.

This command performs the scan with ClamAV, and if no viruses are found, it does nothing more. But if a virus is found, after performing the scan, it sends a notification to the Discord webhook.

You can use this command to send the notification regardless of whether it finds a virus or not:

docker exec clamav clamscan --infected --recursive /data/html /data/html2 ; \
curl -H "Content-Type: application/json" -X POST -d '{"content": "A ClamAV scan has been executed!"}' <WEBHOOK_URL>

To display the scan result in the console:

docker exec clamav clamscan --infected --recursive /data/html data/html2 2>&1  \
  tr -d '\r'  \
  curl -X POST -d "content=$(</dev/stdin)" <WEBHOOK_URL>

3. Automate and Schedule Notifications:

You can automate and schedule this command to run periodically. You can use cron jobs, scheduled tasks, or any other automation tool you prefer.

Important Notes:

  • Ensure you have proper permissions to run the commands and access necessary settings.
  • You can customize the content and format of notifications according to your preferences.

Remember, this is just one way to integrate notifications into Discord, and there are various ways to achieve it. Depending on your environment and preferences, you may explore other tools and methods. Also, consider the

Leave a Comment