Poiché OVH non supporta l'invio diretto dei log di Anti-DDoS tramite Webhook personalizzati sulle proprie impostazioni di default, il procedimento richiede tre passaggi:
- Creare il Webhook su Discord
Generare le chiavi API su OVHcloud
Impostare lo script di monitoraggio
Apri Discord e vai nel canale in cui vuoi ricevere gli avvisi.
Clicca sull'icona dell'ingranaggio (Impostazioni del canale) e seleziona Integrazioni.
Clicca su Webhook e poi su Nuovo Webhook.
Dai un nome al bot (es. OVH DDoS Alert) e copia l'URL del Webhook.
Step 2: Generare le API Key su OVHcloud
Per consentire allo script di leggere lo stato della protezione Anti-DDoS:
Vai sulla pagina di creazione token API OVH: https://eu.api.ovh.com/createToken/
Inserisci le tue credenziali OVH.
Configura le autorizzazioni di lettura (GET) per i servizi IP:
Code: Select all
GET /ip/*Step 3: Configurare lo Script di Monitoraggio
Puoi eseguire questo script in Python su un piccolo VPS o un server sempre acceso (cron job ogni 1-2 minuti).
Pre-requisiti
Aggiorna i pacchetti e installa python3-pip e python3-venv:
Code: Select all
apt update && apt install -y python3-pip python3-venvCode: Select all
python3 -m venv /root/ovh_envCode: Select all
/root/ovh_env/bin/pip install ovh requestsCode: Select all
nano ovh_ddos_discord.pyCode: Select all
import requests
import ovh
# Configurazione Discord
DISCORD_WEBHOOK_URL = "INSERISCI_QUI_URL_WEBHOOK_DISCORD"
# Configurazione API OVH
client = ovh.Client(
endpoint='ovh-eu',
application_key='INSERISCI_APP_KEY',
application_secret='INSERISCI_APP_SECRET',
consumer_key='INSERISCI_CONSUMER_KEY',
)
# Inserisci qui entrambi i tuoi IP
TARGET_IPS = [
"192.0.2.1",
"192.0.2.2"
]
def send_discord_alert(ip, title, description, color):
payload = {
"embeds": [{
"title": title,
"description": description,
"color": color,
"footer": {"text": f"Sistema di Protezione OVH Anti-DDoS | IP: {ip}"}
}]
}
requests.post(DISCORD_WEBHOOK_URL, json=payload)
def check_ddos():
for ip in TARGET_IPS:
try:
# Controlla la mitigazione per ciascun IP
ip_info = client.get(f'/ip/{ip}/mitigation/{ip}')
if ip_info and ip_info.get('auto'):
send_discord_alert(
ip,
" ATTACCO DDOS RILEVATO",
f"Un attacco DDoS è attualmente in corso sull'IP `{ip}`. La mitigazione automatica di OVH è **ATTIVA**.",
15158332
)
except ovh.exceptions.APIError:
# Nessuna mitigazione attiva per questo IP
pass
if __name__ == "__main__":
check_ddos()Apri il file ed inserisci l'URL del tuo Webhook Discord in DISCORD_WEBHOOK_URL.
Sostituisci "INSERISCI_IP_1" e "INSERISCI_IP_2" con i tuoi indirizzi IP reali.
Installa le librerie se non l'hai già fatto: pip install ovh requests.
Aggiungi il file al tuo crontab per farlo girare ogni minuto:
Code: Select all
crontab -eCode: Select all
* * * * * /root/ovh_env/bin/python3 /percorso/del/file/ovh_ddos_discord.pyCode: Select all
/root/ovh_env/bin/python3 /root/ovh_ddos_discord.pySe vuoi fare un test per verificare che l'URL del Webhook funzioni davvero e che il messaggio arrivi su Discord, puoi eseguire questo comando veloce dal terminale per inviare un messaggio di prova manuale:
Code: Select all
curl -H "Content-Type: application/json" -X POST -d '{"content": " Test Webhook Discord funzionante!"}' "INSERISCI_QUI_IL_TUO_WEBHOOK_DISCORD"Nel caso si volessero 2 webhook separati:
Code: Select all
import json
import os
import requests
import ovh
# ==========================================
# CONFIGURATION
# ==========================================
# Add your Discord Webhook URLs here
DISCORD_WEBHOOKS = [
"https://discord.com/api/webhooks/1",
"INSERISCI_QUI_IL_SECONDO_WEBHOOK_DISCORD"
]
# OVH API Credentials
APPLICATION_KEY = "xxxxxxxxxxxxxxxxxxx"
APPLICATION_SECRET = "xxxxxxxxxxxxxxxxxxxxxxxx"
CONSUMER_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# IP Addresses to monitor
TARGET_IPS = [
"192.168.0.1",
"192.168.0.2"
]
# Local file to save state (prevents spamming notifications every minute)
STATUS_FILE = "ddos_status.json"
# ==========================================
# SCRIPT LOGIC
# ==========================================
client = ovh.Client(
endpoint='ovh-eu',
application_key=APPLICATION_KEY,
application_secret=APPLICATION_SECRET,
consumer_key=CONSUMER_KEY,
)
def load_status():
"""Loads previous status from JSON file."""
if os.path.exists(STATUS_FILE):
try:
with open(STATUS_FILE, "r") as f:
return json.load(f)
except Exception:
return {}
return {}
def save_status(status):
"""Saves current status to JSON file."""
with open(STATUS_FILE, "w") as f:
json.dump(status, f)
def send_discord_alert(title, description, color, ip):
"""Sends Embed message to all Discord Webhooks in the list."""
payload = {
"embeds": [{
"title": title,
"description": description,
"color": color,
"footer": {"text": f"OVH Anti-DDoS Protection System | IP: {ip}"}
}]
}
for webhook_url in DISCORD_WEBHOOKS:
# Skips placeholders if not filled
if "INSERISCI_QUI" in webhook_url:
continue
try:
response = requests.post(webhook_url, json=payload)
response.raise_for_status()
except Exception as e:
print(f"Error sending Discord notification: {e}")
def check_ddos():
previous_status = load_status()
current_status = {}
for ip in TARGET_IPS:
is_under_attack = False
try:
# Query OVH API for IP mitigation status
ip_info = client.get(f'/ip/{ip}/mitigation/{ip}')
# If automatic mitigation is active, IP is under attack
if ip_info and ip_info.get('auto'):
is_under_attack = True
except ovh.exceptions.APIError:
# API returns error/404 if no mitigation is active for the IP
is_under_attack = False
current_status[ip] = is_under_attack
was_under_attack = previous_status.get(ip, False)
# 1. ATTACK STARTED: Wasn't under attack before, but IS now
if is_under_attack and not was_under_attack:
send_discord_alert(
title=" DDOS ATTACK DETECTED",
description=f"A DDoS attack is currently ongoing on IP `{ip}`.\nOVH automatic mitigation is **ACTIVE**.",
color=15158332, # Red
ip=ip
)
# 2. ATTACK ENDED: Was under attack before, but IS NOT anymore
elif not is_under_attack and was_under_attack:
send_discord_alert(
title=" DDOS ATTACK ENDED",
description=f"The DDoS attack on IP `{ip}` has ended.\nTraffic has returned to normal.",
color=3066993, # Green
ip=ip
)
# Save current status to file
save_status(current_status)
if __name__ == "__main__":
check_ddos()
