Automazione IT con n8n: flussi, integrazioni e workflow pratici

2026-02-12T18:00:00.000Z

Cos'è n8n e perché usarlo

n8n (pronunciato "n-eight-n") è una piattaforma di workflow automation open-source, self-hostable. Alternativa a Zapier e Make, ma senza limiti di esecuzioni e con il pieno controllo dei dati.

Vantaggi rispetto alle alternative cloud

| Feature | n8n self-hosted | Zapier | Make | |---------|----------------|--------|------| | Costo mensile | ~0€ (solo hosting) | 49-69€ | 9-29€ | | Esecuzioni/mese | Illimitate | 2.000-50.000 | 10.000-40.000 | | Dati sulla tua infrastruttura | ✅ | ❌ | ❌ | | Codice custom (JS/Python) | ✅ | Limitato | Limitato | | API privata/interna | ✅ | Difficile | Difficile |


Installazione con Docker

# docker-compose.yml
version: '3.8'
services:
  n8n:
    image: n8nio/n8n:latest
    restart: always
    ports:
      - "5678:5678"
    environment:
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER=admin
      - N8N_BASIC_AUTH_PASSWORD=cambiami
      - N8N_HOST=n8n.tuodominio.com
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - WEBHOOK_URL=https://n8n.tuodominio.com/
      - GENERIC_TIMEZONE=Europe/Rome
    volumes:
      - n8n_data:/home/node/.n8n
    
volumes:
  n8n_data:
docker-compose up -d
# Accedi su http://localhost:5678

Workflow n8n Onboarding Utenti Flusso di onboarding automatico in n8n: dal trigger (form/email) alla creazione utente in Entra ID, assegnazione licenze e notifica su Teams. Tempo totale: ~45 secondi.

Workflow 1: Onboarding automatico utenti

Questo workflow crea automaticamente un nuovo utente in Active Directory / Entra ID quando arriva una richiesta via form o email.

Trigger (Form/Email/Teams)
    ↓
Validazione dati
    ↓
Crea utente in Entra ID (Microsoft Graph API)
    ↓
Assegna licenze M365
    ↓
Crea mailbox Exchange
    ↓
Aggiunge a gruppi di sicurezza
    ↓
Invia credenziali via email sicura
    ↓
Notifica su Teams/Discord

Configurazione Microsoft Graph API

Prima di tutto, registra un'app in Entra ID:

Entra ID → App registrations → New registration
→ API permissions → Microsoft Graph:
  - User.ReadWrite.All
  - Group.ReadWrite.All  
  - Directory.ReadWrite.All
→ Grant admin consent

Nodo HTTP Request per creare utente

{
  "method": "POST",
  "url": "https://graph.microsoft.com/v1.0/users",
  "headers": {
    "Authorization": "Bearer {{ $node['Get Token'].json.access_token }}",
    "Content-Type": "application/json"
  },
  "body": {
    "displayName": "{{ $json.nome }} {{ $json.cognome }}",
    "userPrincipalName": "{{ $json.username }}@tuazienda.com",
    "mailNickname": "{{ $json.username }}",
    "accountEnabled": true,
    "passwordProfile": {
      "forceChangePasswordNextSignIn": true,
      "password": "{{ $node['Genera Password'].json.password }}"
    },
    "department": "{{ $json.reparto }}",
    "jobTitle": "{{ $json.ruolo }}"
  }
}

Workflow 2: Monitoring infrastruttura con alert

Cron (ogni 5 min)
    ↓
HTTP Request → check servizi (Proxmox, NAS, n8n, etc.)
    ↓
IF → servizio down?
    ↓ Yes
Aggiungi a lista downtime
    ↓
Notifica Discord/Telegram
    ↓
Apri ticket automatico

Script di check servizi

// Nodo "Code" in n8n
const services = [
  { name: 'Proxmox', url: 'https://proxmox.interno:8006' },
  { name: 'NAS', url: 'http://nas.interno:5000' },
  { name: 'n8n', url: 'http://localhost:5678/healthz' },
];

const results = [];
for (const svc of services) {
  try {
    const resp = await $http.get(svc.url, { timeout: 5000 });
    results.push({ ...svc, status: 'UP', code: resp.status });
  } catch (e) {
    results.push({ ...svc, status: 'DOWN', error: e.message });
  }
}

return results.map(r => ({ json: r }));

Workflow 3: Offboarding automatico

Trigger (data licenziamento da HR)
    ↓
Disabilita account AD/Entra ID
    ↓
Revoca sessioni attive (Graph API)
    ↓
Blocca accessi condizionali
    ↓
Backup email → SharePoint
    ↓
Rimuovi da tutti i gruppi
    ↓
Disassegna licenze
    ↓
Programma cancellazione account (30gg)
    ↓
Report finale HR + manager

Integrazioni utili per SysAdmin

Microsoft Teams

// Webhook Teams per notifiche
{
  "@type": "MessageCard",
  "@context": "http://schema.org/extensions",
  "summary": "Alert infrastruttura",
  "themeColor": "FF0000",
  "title": "🚨 {{ $json.service }} è DOWN",
  "text": "Rilevato alle {{ $now.format('HH:mm') }}"
}

Notifica Discord

// Nodo Discord in n8n
{
  "content": "",
  "embeds": [{
    "title": "🔴 Alert: {{ $json.service }}",
    "description": "Il servizio è irraggiungibile",
    "color": 15158332,
    "timestamp": "{{ $now.toISO() }}",
    "fields": [
      { "name": "Server", "value": "{{ $json.host }}", "inline": true },
      { "name": "Errore", "value": "{{ $json.error }}", "inline": true }
    ]
  }]
}

Best Practice

  • Usa credenziali n8n per le API key (non hardcodarle nei workflow)
  • Abilita il log di ogni esecuzione — fondamentale per il debug
  • Timeout sui nodi HTTP — evita workflow bloccati
  • Error handling — sempre un nodo "On Error" nei workflow critici
  • Backup regolare della cartella /home/node/.n8n
  • Non esporre n8n su internet senza autenticazione — usa Cloudflare Access

Risorse