{
  "id": "VbL8CupBzmcRolP4",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Error Log Monitor with Slack Alerts & Auto Bug Ticket Creation",
  "tags": [],
  "nodes": [
    {
      "id": "44f0eba7-b92a-47f0-a7b0-c90eb5d9e8f0",
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -480,
        60
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "19a920cb-28da-4388-80f2-a1b7bd87badb",
      "name": "Set Config",
      "type": "n8n-nodes-base.set",
      "position": [
        -260,
        160
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "cf9f1b38-541c-4311-9fea-c66d7fd39473",
      "name": "Read Error Logs",
      "type": "n8n-nodes-base.ssh",
      "position": [
        -40,
        160
      ],
      "parameters": {
        "command": "tail -n 50 /var/log/application/error.log | grep -E '(CRITICAL|ERROR|FATAL)' || echo 'No critical errors found'",
        "authentication": "privateKey"
      },
      "credentials": {
        "sshPrivateKey": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "87962f71-2a7b-4913-b660-c3b1d7ee328d",
      "name": "Parse Logs",
      "type": "n8n-nodes-base.code",
      "position": [
        400,
        160
      ],
      "parameters": {
        "jsCode": "const logOutput = $input.first().json.stdout || '';\nconst lines = logOutput.split('\\n').filter(line => line.trim() !== '' && line !== 'No critical errors found');\n\nconst errors = [];\n\nlines.forEach((line, index) => {\n  let errorLevel = 'ERROR';\n  \n  if (line.includes('CRITICAL') || line.includes('FATAL')) {\n    errorLevel = 'CRITICAL';\n  }\n  \n  const timestamp = new Date().toISOString();\n  const errorId = `ERR-${Date.now()}-${index}`;\n  \n  errors.push({\n    id: errorId,\n    level: errorLevel,\n    message: line.trim(),\n    timestamp: timestamp,\n    raw_log: line\n  });\n});\n\nreturn errors.map(error => ({ json: error }));"
      },
      "typeVersion": 2
    },
    {
      "id": "093e59c5-8c25-4c70-9f61-418cfded5f40",
      "name": "IF Critical Error",
      "type": "n8n-nodes-base.if",
      "position": [
        620,
        160
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "={{ $json.level }}",
            "operation": "equal",
            "rightValue": "CRITICAL"
          }
        }
      },
      "typeVersion": 2
    },
    {
      "id": "0ca2c626-4dd7-42f8-837d-559c9df7657b",
      "name": "Send Slack Alert",
      "type": "n8n-nodes-base.slack",
      "position": [
        840,
        -180
      ],
      "parameters": {
        "text": "\ud83d\udea8 CRITICAL ERROR DETECTED",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "C0987654"
        },
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "05e1b571-702b-4744-a3b7-38300058e3ff",
      "name": "Create Jira Ticket",
      "type": "n8n-nodes-base.jira",
      "position": [
        840,
        160
      ],
      "parameters": {
        "project": {
          "mode": "name",
          "value": "BUG"
        },
        "summary": "Critical Error: {{ $json.id }}",
        "issueType": {
          "mode": "name",
          "value": "Bug"
        },
        "additionalFields": {
          "labels": [
            "auto-generated",
            "critical-error"
          ],
          "priority": {
            "mode": "name",
            "value": "Highest"
          },
          "description": "**Error Details:**\\n\\nError ID: {{ $json.id }}\\nLevel: {{ $json.level }}\\nTimestamp: {{ $json.timestamp }}\\n\\n**Error Message:**\\n```\\n{{ $json.message }}\\n```\\n\\n**Raw Log:**\\n```\\n{{ $json.raw_log }}\\n```\\n\\n*This ticket was automatically created by the Error Monitoring System.*"
        }
      },
      "credentials": {
        "jiraSoftwareCloudApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "0b13473e-63de-4874-8d9e-843cc8e51c1d",
      "name": "Send Non-Critical Alert",
      "type": "n8n-nodes-base.slack",
      "position": [
        860,
        520
      ],
      "parameters": {
        "text": "\u26a0\ufe0f Error Detected: {{ $json.level }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "C098765"
        },
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "4374ae68-f2a2-46f1-82e9-a98e3dc7886f",
      "name": "Wait For All Logs",
      "type": "n8n-nodes-base.wait",
      "position": [
        180,
        160
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "d90c28f1-6013-4e04-b676-7f8d831ab1d3",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -280,
        40
      ],
      "parameters": {
        "color": 5,
        "width": 160,
        "height": 280,
        "content": "Configures basic parameters"
      },
      "typeVersion": 1
    },
    {
      "id": "7e3948e4-5ac8-4a98-a45d-5c8097208b46",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -500,
        -20
      ],
      "parameters": {
        "color": 4,
        "width": 150,
        "height": 220,
        "content": "For testing"
      },
      "typeVersion": 1
    },
    {
      "id": "702b64fb-c7b9-44b6-9d5f-d3597a2d366b",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -500,
        300
      ],
      "parameters": {
        "color": 3,
        "width": 150,
        "height": 220,
        "content": "Runs every 5 minutes automatically"
      },
      "typeVersion": 1
    },
    {
      "id": "0ba8b489-3f92-4d0a-93f7-121aaca95771",
      "name": "Schedule Every 5min",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -480,
        380
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "2250de6b-468a-49bb-a6ef-76be482fe3a9",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        360,
        40
      ],
      "parameters": {
        "color": 3,
        "width": 160,
        "height": 280,
        "content": "JavaScript code to parse and categorize errors"
      },
      "typeVersion": 1
    },
    {
      "id": "2231a875-1367-47d0-aab0-7a4fcc03fe5c",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        140,
        40
      ],
      "parameters": {
        "color": 6,
        "width": 160,
        "height": 280,
        "content": "Wait for all error logs read"
      },
      "typeVersion": 1
    },
    {
      "id": "f3c58543-431e-40aa-9e30-f5bc0a181c0d",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -60,
        40
      ],
      "parameters": {
        "width": 160,
        "height": 280,
        "content": "SSH into server and reads error logs"
      },
      "typeVersion": 1
    },
    {
      "id": "8e5766d8-d40b-4867-8a17-88fdf9a40b29",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        840,
        400
      ],
      "parameters": {
        "color": 5,
        "width": 160,
        "height": 260,
        "content": "Sends simple alert for non-critical errors"
      },
      "typeVersion": 1
    },
    {
      "id": "c71bc4f9-a96e-4b08-beba-5b3c3bce86c7",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        820,
        40
      ],
      "parameters": {
        "width": 160,
        "height": 260,
        "content": "Auto-creates bug ticket for critical errors"
      },
      "typeVersion": 1
    },
    {
      "id": "fa119483-66e9-40e5-9e50-4837807f50e0",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        800,
        -300
      ],
      "parameters": {
        "color": 6,
        "width": 160,
        "height": 280,
        "content": " Sends detailed alert for critical errors"
      },
      "typeVersion": 1
    },
    {
      "id": "7f07dd84-a237-4b62-9e32-7b431c844152",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        580,
        40
      ],
      "parameters": {
        "color": 4,
        "width": 160,
        "height": 280,
        "content": "Filters critical errors from regular errors\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "9ee70159-d6b0-4271-bda9-3ab79401d38e",
  "connections": {
    "Parse Logs": {
      "main": [
        [
          {
            "node": "IF Critical Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Config": {
      "main": [
        [
          {
            "node": "Read Error Logs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Set Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Error Logs": {
      "main": [
        [
          {
            "node": "Wait For All Logs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Slack Alert": {
      "main": [
        []
      ]
    },
    "IF Critical Error": {
      "main": [
        [
          {
            "node": "Send Slack Alert",
            "type": "main",
            "index": 0
          },
          {
            "node": "Create Jira Ticket",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Non-Critical Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait For All Logs": {
      "main": [
        [
          {
            "node": "Parse Logs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Jira Ticket": {
      "main": [
        []
      ]
    },
    "Schedule Every 5min": {
      "main": [
        [
          {
            "node": "Set Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Non-Critical Alert": {
      "main": [
        []
      ]
    }
  }
}