{
  "workflow": {
    "id": 5406,
    "name": "Automated server log cleanup via email alerts with SSH - Nginx, Docker, System",
    "views": 1075,
    "recentViews": 0,
    "totalViews": 1075,
    "createdAt": "2025-06-27T10:32:16.522Z",
    "description": "This n8n workflow monitors email alerts for disk utilization exceeding 80%, extracts the server IP, logs into the server, and purges logs from Nginx, PM2, Docker, and system files to clear disk space.\n\n### Key Insights\n\n- Ensure email alerts are consistently formatted with server IP details.  \n- SSH access must be properly configured to avoid authentication failures.\n\n### Workflow Process\n\n1. Initiate the workflow with the `Check Disk Alert Emails` node when an email triggers on high disk usage.  \n2. Parse the email to extract the server IP using the `Extract Server IP from Email` node.  \n3. Set up SSH credentials and paths manually with the `Prepare SSH Variables` node.  \n4. Execute cleanup commands to delete logs from Nginx, PM2, Docker, and system files using the `Run LogCleanup Commands via SSH` node.\n\n### Usage Guide\n\n- Import the workflow into n8n and configure email and SSH credentials.  \n- Test with a sample email alert to verify IP extraction and log deletion.\n\n### Prerequisites\n\n- Email service (e.g., IMAP or API) for alert monitoring  \n- SSH access with valid credentials  \n\n### Customization Options\n\nModify the `Prepare SSH Variables` node to target specific log directories or adjust cleanup commands for different server setups.",
    "workflow": {
      "id": "4Y5VQwUUo7uqPPL1",
      "meta": {
        "instanceId": "dd69efaf8212c74ad206700d104739d3329588a6f3f8381a46a481f34c9cc281",
        "templateCredsSetupCompleted": true
      },
      "name": "Auto Disk Cleanup via Email Alert – Server Log Purge Workflow",
      "tags": [],
      "nodes": [
        {
          "id": "8c1aac94-9e6a-4b14-a177-3a00644ea232",
          "name": "Check Disk Alert Emails\t",
          "type": "n8n-nodes-base.emailReadImap",
          "position": [
            0,
            0
          ],
          "parameters": {
            "options": {
              "customEmailConfig": "[\"UNSEEN\", [\"SUBJECT\", \"disk\"]]"
            }
          },
          "credentials": {
            "imap": {
              "id": "credential-id",
              "name": "imap Credential"
            }
          },
          "typeVersion": 2
        },
        {
          "id": "025c2c15-f693-4b53-8433-4d641526d11a",
          "name": "Extract Server IP from Email\t",
          "type": "n8n-nodes-base.code",
          "position": [
            220,
            0
          ],
          "parameters": {
            "jsCode": "const subject = $input.first().json.subject;\n\nif (subject && (subject.toLowerCase().includes(\"disk-YOUR_OPENAI_KEY_HERE\") || subject.toLowerCase().includes(\"disk utilization\"))) {\n  const ipMatch = subject.match(/(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}):9100/);\n  const server_ip = ipMatch ? ipMatch[1] : '';\n  return [{ json: { server_ip } }];\n} else {\n  // Stop workflow if subject doesn't match\n  return [];\n}"
          },
          "typeVersion": 2
        },
        {
          "id": "723c7067-fe88-4b8b-b1ff-38c9eb662641",
          "name": "Prepare SSH Variables\t",
          "type": "n8n-nodes-base.set",
          "position": [
            440,
            0
          ],
          "parameters": {
            "options": {},
            "assignments": {
              "assignments": [
                {
                  "id": "49c16fb1-4b84-46a7-bb50-5e1fa7f59664",
                  "name": "pwd",
                  "type": "string",
                  "value": "password"
                },
                {
                  "id": "c16557bd-7ef6-4049-a634-a5b207a92fd6",
                  "name": "server_user",
                  "type": "string",
                  "value": "user"
                },
                {
                  "id": "fd8c4253-8ab2-4094-9a72-78ef782d89d3",
                  "name": "server_ip",
                  "type": "string",
                  "value": "={{ $input.first().json.server_ip }}"
                }
              ]
            }
          },
          "typeVersion": 3.4
        },
        {
          "id": "7ef2b2b6-5880-4fc1-93fa-b76c3c75effa",
          "name": "Run Log Cleanup Commands via SSH\t",
          "type": "n8n-nodes-base.ssh",
          "position": [
            660,
            0
          ],
          "parameters": {
            "command": "=echo '{{ $json.pwd }}' | sudo -S su - jenkins -c \"ssh {{ $json.server_user }}@{{ $json.server_ip }} 'sudo rm -rf /var/log/*.gz && sudo rm -rf /var/log/*.1 && sudo rm -rf /var/log/nginx/*.log && sudo rm -rf /var/log/apache2/*.log && sudo journalctl --vacuum-size=200M && sudo apt-get clean && sudo apt-get autoclean && docker builder prune -af && docker system df && sudo apt-get autoremove -y'\""
          },
          "credentials": {
            "sshPassword": {
              "id": "credential-id",
              "name": "sshPassword Credential"
            }
          },
          "typeVersion": 1
        },
        {
          "id": "0935c618-237c-4630-9087-80b757a78a9c",
          "name": "Sticky Note",
          "type": "n8n-nodes-base.stickyNote",
          "position": [
            -20,
            -140
          ],
          "parameters": {
            "width": 160,
            "height": 300,
            "content": "Triggers when an alert email about disk usage is received.\n"
          },
          "typeVersion": 1
        },
        {
          "id": "d4efc5ab-9003-4d42-a49c-6ac4c376c9cb",
          "name": "Sticky Note1",
          "type": "n8n-nodes-base.stickyNote",
          "position": [
            180,
            -140
          ],
          "parameters": {
            "color": 3,
            "width": 170,
            "height": 300,
            "content": "Parses the email body to extract the target server's IP address.\n"
          },
          "typeVersion": 1
        },
        {
          "id": "adf3341f-4319-40cc-bf97-8917a2bb5c44",
          "name": "Sticky Note2",
          "type": "n8n-nodes-base.stickyNote",
          "position": [
            400,
            -140
          ],
          "parameters": {
            "color": 4,
            "width": 170,
            "height": 300,
            "content": "Manually set or map credentials, paths, or other config values.\n"
          },
          "typeVersion": 1
        },
        {
          "id": "4c933879-5907-4616-8902-42cfb2d73edc",
          "name": "Sticky Note3",
          "type": "n8n-nodes-base.stickyNote",
          "position": [
            620,
            -140
          ],
          "parameters": {
            "color": 6,
            "width": 170,
            "height": 300,
            "content": "Executes cleanup commands (Nginx, PM2, Docker, system logs).\n\n"
          },
          "typeVersion": 1
        }
      ],
      "active": false,
      "pinData": {},
      "settings": {
        "executionOrder": "v1"
      },
      "versionId": "fbb7d480-4bbd-4240-9e95-459b563adba4",
      "connections": {
        "Prepare SSH Variables\t": {
          "main": [
            [
              {
                "node": "Run Log Cleanup Commands via SSH\t",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Check Disk Alert Emails\t": {
          "main": [
            [
              {
                "node": "Extract Server IP from Email\t",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Extract Server IP from Email\t": {
          "main": [
            [
              {
                "node": "Prepare SSH Variables\t",
                "type": "main",
                "index": 0
              }
            ]
          ]
        }
      }
    },
    "lastUpdatedBy": 29,
    "workflowInfo": {
      "nodeCount": 8,
      "nodeTypes": {
        "n8n-nodes-base.set": {
          "count": 1
        },
        "n8n-nodes-base.ssh": {
          "count": 1
        },
        "n8n-nodes-base.code": {
          "count": 1
        },
        "n8n-nodes-base.stickyNote": {
          "count": 4
        },
        "n8n-nodes-base.emailReadImap": {
          "count": 1
        }
      }
    },
    "status": "published",
    "user": {
      "name": "Oneclick AI Squad",
      "username": "oneclick-ai",
      "bio": "The AI Squad Initiative is a pioneering effort to build, automate and scale AI-powered workflows using n8n.io. Our mission is to help individuals and businesses integrate AI agents seamlessly into their daily operations  from automating tasks and enhancing productivity to creating innovative, intelligent solutions. We design modular, reusable AI workflow templates that empower creators, developers and teams to supercharge their automation with minimal effort and maximum impact.",
      "verified": true,
      "links": [
        "https://www.oneclickitsolution.com/"
      ],
      "avatar": "https://gravatar.com/avatar/848fca91367142f65f9e5c55d64e5c9952b160d7b060d103b52aa343c6bc7b3d?r=pg&d=retro&size=200"
    },
    "nodes": [
      {
        "id": 10,
        "icon": "fa:inbox",
        "name": "n8n-nodes-base.emailReadImap",
        "codex": {
          "data": {
            "resources": {
              "generic": [
                {
                  "url": "https://n8n.io/blog/build-your-own-virtual-assistant-with-n8n-a-step-by-step-guide/",
                  "icon": "👦",
                  "label": "Build your own virtual assistant with n8n: A step by step guide"
                }
              ],
              "primaryDocumentation": [
                {
                  "url": "https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.emailimap/"
                }
              ],
              "credentialDocumentation": [
                {
                  "url": "https://docs.n8n.io/integrations/builtin/credentials/imap/"
                }
              ]
            },
            "categories": [
              "Communication",
              "Core Nodes"
            ],
            "nodeVersion": "1.0",
            "codexVersion": "1.0",
            "subcategories": {
              "Core Nodes": [
                "Other Trigger Nodes"
              ]
            }
          }
        },
        "group": "[\"trigger\"]",
        "defaults": {
          "name": "Email Trigger (IMAP)",
          "color": "#44AA22"
        },
        "iconData": {
          "icon": "inbox",
          "type": "icon"
        },
        "displayName": "Email Trigger (IMAP)",
        "typeVersion": 2,
        "nodeCategories": [
          {
            "id": 6,
            "name": "Communication"
          },
          {
            "id": 9,
            "name": "Core Nodes"
          }
        ]
      },
      {
        "id": 38,
        "icon": "fa:pen",
        "name": "n8n-nodes-base.set",
        "codex": {
          "data": {
            "alias": [
              "Set",
              "JS",
              "JSON",
              "Filter",
              "Transform",
              "Map"
            ],
            "resources": {
              "generic": [
                {
                  "url": "https://n8n.io/blog/learn-to-automate-your-factorys-incident-reporting-a-step-by-step-guide/",
                  "icon": "🏭",
                  "label": "Learn to Automate Your Factory's Incident Reporting: A Step by Step Guide"
                },
                {
                  "url": "https://n8n.io/blog/2021-the-year-to-automate-the-new-you-with-n8n/",
                  "icon": "☀️",
                  "label": "2021: The Year to Automate the New You with n8n"
                },
                {
                  "url": "https://n8n.io/blog/automatically-pulling-and-visualizing-data-with-n8n/",
                  "icon": "📈",
                  "label": "Automatically pulling and visualizing data with n8n"
                },
                {
                  "url": "https://n8n.io/blog/database-monitoring-and-alerting-with-n8n/",
                  "icon": "📡",
                  "label": "Database Monitoring and Alerting with n8n"
                },
                {
                  "url": "https://n8n.io/blog/automatically-adding-expense-receipts-to-google-sheets-with-telegram-mindee-twilio-and-n8n/",
                  "icon": "🧾",
                  "label": "Automatically Adding Expense Receipts to Google Sheets with Telegram, Mindee, Twilio, and n8n"
                },
                {
                  "url": "https://n8n.io/blog/no-code-ecommerce-workflow-automations/",
                  "icon": "store",
                  "label": "6 e-commerce workflows to power up your Shopify s"
                },
                {
                  "url": "https://n8n.io/blog/how-to-build-a-low-code-self-hosted-url-shortener/",
                  "icon": "🔗",
                  "label": "How to build a low-code, self-hosted URL shortener in 3 steps"
                },
                {
                  "url": "https://n8n.io/blog/automate-your-data-processing-pipeline-in-9-steps-with-n8n/",
                  "icon": "⚙️",
                  "label": "Automate your data processing pipeline in 9 steps"
                },
                {
                  "url": "https://n8n.io/blog/how-to-get-started-with-crm-automation-and-no-code-workflow-ideas/",
                  "icon": "👥",
                  "label": "How to get started with CRM automation (with 3 no-code workflow ideas"
                },
                {
                  "url": "https://n8n.io/blog/5-tasks-you-can-automate-with-notion-api/",
                  "icon": "⚡️",
                  "label": "5 tasks you can automate with the new Notion API "
                },
                {
                  "url": "https://n8n.io/blog/automate-google-apps-for-productivity/",
                  "icon": "💡",
                  "label": "15 Google apps you can combine and automate to increase productivity"
                },
                {
                  "url": "https://n8n.io/blog/how-uproc-scraped-a-multi-page-website-with-a-low-code-workflow/",
                  "icon": " 🕸️",
                  "label": "How uProc scraped a multi-page website with a low-code workflow"
                },
                {
                  "url": "https://n8n.io/blog/building-an-expense-tracking-app-in-10-minutes/",
                  "icon": "📱",
                  "label": "Building an expense tracking app in 10 minutes"
                },
                {
                  "url": "https://n8n.io/blog/the-ultimate-guide-to-automate-your-video-collaboration-with-whereby-mattermost-and-n8n/",
                  "icon": "📹",
                  "label": "The ultimate guide to automate your video collaboration with Whereby, Mattermost, and n8n"
                },
                {
                  "url": "https://n8n.io/blog/5-workflow-automations-for-mattermost-that-we-love-at-n8n/",
                  "icon": "🤖",
                  "label": "5 workflow automations for Mattermost that we love at n8n"
                },
                {
                  "url": "https://n8n.io/blog/learn-to-build-powerful-api-endpoints-using-webhooks/",
                  "icon": "🧰",
                  "label": "Learn to Build Powerful API Endpoints Using Webhooks"
                },
                {
                  "url": "https://n8n.io/blog/how-a-membership-development-manager-automates-his-work-and-investments/",
                  "icon": "📈",
                  "label": "How a Membership Development Manager automates his work and investments"
                },
                {
                  "url": "https://n8n.io/blog/a-low-code-bitcoin-ticker-built-with-questdb-and-n8n-io/",
                  "icon": "📈",
                  "label": "A low-code bitcoin ticker built with QuestDB and n8n.io"
                },
                {
                  "url": "https://n8n.io/blog/how-to-set-up-a-ci-cd-pipeline-with-no-code/",
                  "icon": "🎡",
                  "label": "How to set up a no-code CI/CD pipeline with GitHub and TravisCI"
                },
                {
                  "url": "https://n8n.io/blog/benefits-of-automation-and-n8n-an-interview-with-hubspots-hugh-durkin/",
                  "icon": "🎖",
                  "label": "Benefits of automation and n8n: An interview with HubSpot's Hugh Durkin"
                },
                {
                  "url": "https://n8n.io/blog/how-goomer-automated-their-operations-with-over-200-n8n-workflows/",
                  "icon": "🛵",
                  "label": "How Goomer automated their operations with over 200 n8n workflows"
                },
                {
                  "url": "https://n8n.io/blog/aws-workflow-automation/",
                  "label": "7 no-code workflow automations for Amazon Web Services"
                }
              ],
              "primaryDocumentation": [
                {
                  "url": "https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.set/"
                }
              ]
            },
            "categories": [
              "Core Nodes"
            ],
            "nodeVersion": "1.0",
            "codexVersion": "1.0",
            "subcategories": {
              "Core Nodes": [
                "Data Transformation"
              ]
            }
          }
        },
        "group": "[\"input\"]",
        "defaults": {
          "name": "Edit Fields"
        },
        "iconData": {
          "icon": "pen",
          "type": "icon"
        },
        "displayName": "Edit Fields (Set)",
        "typeVersion": 3,
        "nodeCategories": [
          {
            "id": 9,
            "name": "Core Nodes"
          }
        ]
      },
      {
        "id": 490,
        "icon": "fa:terminal",
        "name": "n8n-nodes-base.ssh",
        "codex": {
          "data": {
            "alias": [
              "remote"
            ],
            "resources": {
              "primaryDocumentation": [
                {
                  "url": "https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.ssh/"
                }
              ]
            },
            "categories": [
              "Core Nodes",
              "Development"
            ],
            "nodeVersion": "1.0",
            "codexVersion": "1.0",
            "subcategories": [
              "Helpers"
            ]
          }
        },
        "group": "[\"input\"]",
        "defaults": {
          "name": "SSH",
          "color": "#000000"
        },
        "iconData": {
          "icon": "terminal",
          "type": "icon"
        },
        "displayName": "SSH",
        "typeVersion": 1,
        "nodeCategories": [
          {
            "id": 5,
            "name": "Development"
          },
          {
            "id": 9,
            "name": "Core Nodes"
          }
        ]
      },
      {
        "id": 565,
        "icon": "fa:sticky-note",
        "name": "n8n-nodes-base.stickyNote",
        "codex": {
          "data": {
            "alias": [
              "Comments",
              "Notes",
              "Sticky"
            ],
            "categories": [
              "Core Nodes"
            ],
            "nodeVersion": "1.0",
            "codexVersion": "1.0",
            "subcategories": {
              "Core Nodes": [
                "Helpers"
              ]
            }
          }
        },
        "group": "[\"input\"]",
        "defaults": {
          "name": "Sticky Note",
          "color": "#FFD233"
        },
        "iconData": {
          "icon": "sticky-note",
          "type": "icon"
        },
        "displayName": "Sticky Note",
        "typeVersion": 1,
        "nodeCategories": [
          {
            "id": 9,
            "name": "Core Nodes"
          }
        ]
      },
      {
        "id": 834,
        "icon": "file:code.svg",
        "name": "n8n-nodes-base.code",
        "codex": {
          "data": {
            "alias": [
              "cpde",
              "Javascript",
              "JS",
              "Python",
              "Script",
              "Custom Code",
              "Function"
            ],
            "details": "The Code node allows you to execute JavaScript in your workflow.",
            "resources": {
              "primaryDocumentation": [
                {
                  "url": "https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.code/"
                }
              ]
            },
            "categories": [
              "Development",
              "Core Nodes"
            ],
            "nodeVersion": "1.0",
            "codexVersion": "1.0",
            "subcategories": {
              "Core Nodes": [
                "Helpers",
                "Data Transformation"
              ]
            }
          }
        },
        "group": "[\"transform\"]",
        "defaults": {
          "name": "Code"
        },
        "iconData": {
          "type": "file",
          "fileBuffer": "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTEyIiBoZWlnaHQ9IjUxMiIgdmlld0JveD0iMCAwIDUxMiA1MTIiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMF8xMTcxXzQ0MSkiPgo8cGF0aCBkPSJNMTcwLjI4MyA0OEgxOTYuNUMyMDMuMTI3IDQ4IDIwOC41IDQyLjYyNzQgMjA4LjUgMzZWMTJDMjA4LjUgNS4zNzI1OCAyMDMuMTI3IDAgMTk2LjUgMEgxNzAuMjgzQzEyNi4xIDAgOTAuMjgzIDM1LjgxNzIgOTAuMjgzIDgwVjE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ggNDQ5LjY3MyAzNjAuNjUyIDQ2NCAzNDIuOTc5IDQ2NEgzMTdDMzEwLjM3MyA0NjQgMzA1IDQ2OS4zNzMgMzA1IDQ3NlY1MDBDMzA1IDUwNi42MjcgMzEwLjM3MyA1MTIgMzE3IDUxMkgzNDIuOTc5QzM4Ny4xNjEgNTEyIDQyMi45NzggNDc2LjE4MyA0MjIuOTc4IDQzMlYzMzZDNDIyLjk3OCAzMDUuMDcyIDQ0OC4wNTEgMjgwIDQ3OC45NzkgMjgwSDQ5MEM0OTYuNjI3IDI4MCA1MDIgMjc0LjYyOCA1MDIgMjY4VjI0NEM1MDIgMjM3LjM3MyA0OTYuNjI4IDIzMiA0OTAgMjMyTDQ3OC45NzkgMjMyQzQ0OC4wNTEgMjMyIDQyMi45NzggMjA2LjkyOCA0MjIuOTc4IDE3NlY4MEM0MjIuOTc4IDM1LjgxNzIgMzg3LjE2MSAwIDM0Mi45NzkgMEgzMTdDMzEwLjM3MyAwIDMwNSA1LjM3MjU4IDMwNSAxMlYzNloiIGZpbGw9IiNGRjk5MjIiLz4KPC9nPgo8ZGVmcz4KPGNsaXBQYXRoIGlkPSJjbGlwMF8xMTcxXzQ0MSI+CjxyZWN0IHdpZHRoPSI1MTIiIGhlaWdodD0iNTEyIiBmaWxsPSJ3aGl0ZSIvPgo8L2NsaXBQYXRoPgo8L2RlZnM+Cjwvc3ZnPgo="
        },
        "displayName": "Code",
        "typeVersion": 2,
        "nodeCategories": [
          {
            "id": 5,
            "name": "Development"
          },
          {
            "id": 9,
            "name": "Core Nodes"
          }
        ]
      }
    ],
    "categories": [
      {
        "id": 16,
        "name": "DevOps"
      }
    ],
    "image": []
  }
}