{"id":30092697,"url":"https://github.com/viniciushammett/n8n-devops-lab","last_synced_at":"2026-04-16T10:32:55.387Z","repository":{"id":308819440,"uuid":"1034214177","full_name":"viniciushammett/n8n-devops-lab","owner":"viniciushammett","description":"Lab de n8n para DevOps/SRE: automação de incidentes, digests de SLO e webhooks, rodando em Docker (Postgres+Redis, queue mode). ","archived":false,"fork":false,"pushed_at":"2025-08-08T04:04:59.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-08T05:27:26.050Z","etag":null,"topics":["automation","cron","devops","docker","docker-compose","incident-management","n8n","postgres","redis","sre","webhook","workflows"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/viniciushammett.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-08T03:24:37.000Z","updated_at":"2025-08-08T04:05:02.000Z","dependencies_parsed_at":"2025-08-08T05:39:59.737Z","dependency_job_id":null,"html_url":"https://github.com/viniciushammett/n8n-devops-lab","commit_stats":null,"previous_names":["viniciushammett/n8n-devops-lab"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/viniciushammett/n8n-devops-lab","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viniciushammett%2Fn8n-devops-lab","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viniciushammett%2Fn8n-devops-lab/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viniciushammett%2Fn8n-devops-lab/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viniciushammett%2Fn8n-devops-lab/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/viniciushammett","download_url":"https://codeload.github.com/viniciushammett/n8n-devops-lab/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viniciushammett%2Fn8n-devops-lab/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31882204,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T09:23:21.276Z","status":"ssl_error","status_checked_at":"2026-04-16T09:23:15.028Z","response_time":69,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","cron","devops","docker","docker-compose","incident-management","n8n","postgres","redis","sre","webhook","workflows"],"created_at":"2025-08-09T08:03:04.766Z","updated_at":"2026-04-16T10:32:55.353Z","avatar_url":"https://github.com/viniciushammett.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"## 🔧 Pré-requisitos\n\n* Docker e Docker Compose\n* `curl` para testes\n* Porta `5678` livre\n\n---\n\n## 🚀 Subir o ambiente local\n\n1. Copie o arquivo `.env.example` para `.env` e ajuste se necessário:\n\n   ```bash\n   cp .env.example .env\n   ```\n2. Suba os serviços:\n\n   ```bash\n   docker compose up -d\n   ```\n3. Acesse o editor do n8n: **[http://localhost:5678](http://localhost:5678)**\n\n   \u003e Se `N8N_BASIC_AUTH` estiver ativo, use as credenciais definidas no `.env`. No primeiro acesso o n8n pedirá para criar o **usuário admin**.\n\n---\n\n## 🧪 Workflow 0 — Hello Webhook (aquecimento)\n\n**Objetivo:** receber um JSON, transformar e responder algo útil.\n\n**Passo a passo (UI):**\n\n1. **Create → New Workflow** → renomeie para `hello-webhook`.\n2. **Webhook (Trigger)**\n\n   * *HTTP Method*: `POST`\n   * *Path*: `hello-lab`\n   * *Response*: **Using Respond to Webhook Node**\n   * Clique **Execute Workflow** (modo Test).\n3. **Function / Code** → cole:\n\n   ```js\n   // items[0].json contém o corpo do POST\n   const name = (items[0].json.name || \"Dev\");\n   return [{\n     json: {\n       message: `Olá, ${name}! Workflow no ar.`,\n       timestamp: new Date().toISOString()\n     }\n   }];\n   ```\n4. **Respond to Webhook**\n\n   * *Respond With*: `JSON`\n   * *Response Body*: `{{$json}}`\n5. **Testar (URL de Test)**:\n\n   ```bash\n   curl -X POST http://localhost:5678/webhook-test/hello-lab \\\n     -H \"Content-Type: application/json\" \\\n     -d '{\"name\":\"Seu Nome\"}'\n   ```\n6. **Activate** o workflow e use a URL de produção:\n\n   ```bash\n   curl -X POST http://localhost:5678/webhook/hello-lab \\\n     -H \"Content-Type: application/json\" \\\n     -d '{\"name\":\"Seu Nome\"}'\n   ```\n\n---\n\n## 🛠️ Workflow 1 — Ingestão de Incidente (DevOps)\n\n**Objetivo:** simular um alerta que vira *notificação* e *ticket* (mocks).\n\n**Passo a passo (UI):**\n\n1. **New Workflow** → `incident-ingest-lab`.\n2. **Webhook (Trigger)**\n\n   * *Method*: `POST`\n   * *Path*: `incident-lab`\n   * Espera: `service`, `severity`, `message`, `runbookUrl`\n3. **Function / Code** (normalização):\n\n   ```js\n   const { service, severity, message, runbookUrl } = items[0].json;\n   const sev = (severity || \"info\").toLowerCase();\n   const sevOrder = { critical: 4, high: 3, medium: 2, low: 1, info: 0 };\n   const priority = sevOrder[sev] \u003e= 3 ? \"P1\" : (sevOrder[sev] === 2 ? \"P2\" : \"P3\");\n   return [{\n     json: {\n       title: `[${priority}] ${service || \"unknown\"} - ${message || \"no message\"}`,\n       severity: sev, priority, service: service || \"unknown\",\n       runbookUrl: runbookUrl || null,\n       createdAt: new Date().toISOString()\n     }\n   }];\n   ```\n4. **HTTP Request** (Mock Slack)\n\n   * *Method*: `POST`\n   * *URL*: `https://httpbin.org/post`\n   * *JSON Body*:\n\n     ```json\n     { \"channel\": \"#devops\", \"text\": \"{{$json.title}}\" }\n     ```\n5. **HTTP Request** (Mock Jira)\n\n   * *Method*: `POST`\n   * *URL*: `https://httpbin.org/post`\n   * *JSON Body*:\n\n     ```json\n     {\n       \"projectKey\": \"OPS\",\n       \"summary\": \"{{$json.title}}\",\n       \"labels\": [\"n8n\",\"incident\"],\n       \"custom\": {\n         \"severity\": \"{{$json.severity}}\",\n         \"service\": \"{{$json.service}}\",\n         \"runbookUrl\": \"{{$json.runbookUrl}}\"\n       }\n     }\n     ```\n6. **Respond to Webhook**\n\n   * *Response Body*:\n\n     ```json\n     {\n       \"status\": \"queued\",\n       \"title\": \"{{$json.title}}\",\n       \"severity\": \"{{$json.severity}}\",\n       \"service\": \"{{$json.service}}\"\n     }\n     ```\n7. **Ativar e testar**:\n\n   ```bash\n   curl -X POST http://localhost:5678/webhook/incident-lab \\\n     -H \"Content-Type: application/json\" \\\n     -d '{\"service\":\"checkout\",\"severity\":\"high\",\"message\":\"Taxa de erro \u003e 5%\",\"runbookUrl\":\"https://runbooks/checkout\"}'\n   ```\n\n\u003e Depois troque os mocks por **Slack Incoming Webhook** real e **Jira/ServiceNow** (com *Credentials* no n8n).\n\n---\n\n## ⏱️ Workflow 2 — Digest diário de SLO\n\n**Objetivo:** todo dia às 9h, consolidar métricas e postar um resumo (mock).\n\n**Passo a passo (UI):**\n\n1. **New Workflow** → `slo-digest-lab`.\n2. **Schedule (Cron)**: *Minutes* `0`, *Hours* `9` (ajuste o fuso).\n3. **HTTP Request** (mock métricas):\n\n   * *URL*: `https://httpbin.org/anything`\n4. **Function / Code** (error budget simulado):\n\n   ```js\n   const target = 0.999, actual = 0.997;\n   const errorBudget = (1 - target);\n   const consumed = (1 - actual);\n   const remaining = Math.max(errorBudget - consumed, 0);\n   return [{ json: { target, actual, errorBudget, consumed, remaining } }];\n   ```\n5. **HTTP Request** (Mock Slack):\n\n   * *URL*: `https://httpbin.org/post`\n   * *JSON Body*:\n\n     ```json\n     {\n       \"channel\":\"#sre-digest\",\n       \"text\":\"SLO: alvo={{$json.target}}, atual={{$json.actual}}, restante={{$json.remaining}}\"\n     }\n     ```\n\n---\n\n## 🧪 Testes rápidos (`docs/test-requests.http`)\n\n```http\n### Hello webhook\nPOST http://localhost:5678/webhook/hello-lab\nContent-Type: application/json\n\n{\"name\":\"Vinicius\"}\n\n### Incident ingest\nPOST http://localhost:5678/webhook/incident-lab\nContent-Type: application/json\n\n{\"service\":\"checkout\",\"severity\":\"high\",\"message\":\"Taxa de erro \u003e 5%\",\"runbookUrl\":\"https://runbooks/checkout\"}\n```\n\n\u003e Dica: na UI, use **Test URL** enquanto constrói e só então **Activate** para trocar para `/webhook/...`.\n\n---\n\n## 📦 Versionando workflows (para o GitHub)\n\n* No editor: **Workflow → Export** e salve o `.json` em `./workflows/` (ex.: `incident-ingest-lab.json`).\n* Comite `docker-compose.yml`, `.env.example`, `README.md`, `docs/` e `workflows/*.json`.\n* **Nunca** commite `.env` real ou segredos.\n\n---\n\n## ⚙️ Executando com arquivos de ambiente dedicados (`--env-file`)\n\nSe preferir organizar seus ambientes em arquivos separados (ex.: `env/n8n.local.env`):\n\n```bash\nmkdir -p env\ncp .env.example env/n8n.local.env\ndocker compose --env-file env/n8n.local.env up -d\n```\n\n\u003e Mantenha variantes como `env/n8n.dev.env`, `env/n8n.prod.env` e escolha com `--env-file`.\n\n---\n\n## 🔐 Boas práticas (mesmo no lab)\n\n* Defina `N8N_ENCRYPTION_KEY` e use volume persistente para `/home/node/.n8n`.\n* Troque mocks por integrações reais via **Credentials**.\n* Configure **retries/backoff** e ramos de **Error** para robustez.\n* Separe ambientes e parametrize por **ENV**.\n\n---\n\n## 🗂️ `.gitignore` sugerido\n\n```gitignore\n# Env files\n.env\n.env.*\nenv/*.env\n.env/*.env\n\n# n8n local data (se mapear volume)\nn8n_data/\nhome/node/.n8n/\n\n# OS/Editor\n.DS_Store\nThumbs.db\n.idea/\n.vscode/\n```\n\n---\n\n## 📄 Licença\n\nEste projeto usa a licença **MIT**. Veja [LICENSE](./LICENSE).\n\n---\n\nFeito com ❤️ para prática de DevOps/SRE com n8n.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fviniciushammett%2Fn8n-devops-lab","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fviniciushammett%2Fn8n-devops-lab","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fviniciushammett%2Fn8n-devops-lab/lists"}