8
n8n 中文网amn8n.com

SSL监控

高级

这是一个SecOps领域的自动化工作流,包含 16 个节点。主要使用 If, Code, EmailSend, HttpRequest, GoogleSheets 等节点。 使用Google表格和邮件警报监控SSL证书到期

前置要求
  • 可能需要目标 API 的认证凭证
  • Google Sheets API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "KUuDj4PoKCazr0Wb",
  "meta": {
    "instanceId": "c43146c2c6d67aeacc15c710823dc496f4ee6c5a4df68199ab05eca2c2dd0b05",
    "templateCredsSetupCompleted": true
  },
  "name": "SSL 监控",
  "tags": [],
  "nodes": [
    {
      "id": "da9f42ab-bb5a-4d32-850b-ce08e2804700",
      "name": "获取 SSL",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        800,
        880
      ],
      "parameters": {
        "url": "=https://ssl-checker.io/api/v1/check/{{ $json.Link.replace(/^https?:\\/\\//, \"\").replace(/\\/$/, \"\") }}",
        "options": {},
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {}
          ]
        }
      },
      "typeVersion": 4.2,
      "alwaysOutputData": true
    },
    {
      "id": "08b036d0-7f3a-498a-a40e-3e655a651232",
      "name": "循环",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        440,
        540
      ],
      "parameters": {
        "options": {
          "reset": false
        }
      },
      "typeVersion": 3
    },
    {
      "id": "7b3979db-434a-4e45-9735-f16020beac14",
      "name": "更新电子表格中的 SSL",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1460,
        1100
      ],
      "parameters": {
        "columns": {
          "value": {
            "Name": "={{ $('Get Website List').item.json.Name }}",
            "SSL Issued On": "={{ $json.result.valid_from }}",
            "SSL Expired On": "={{ $json.result.valid_till }}"
          },
          "schema": [
            {
              "id": "No",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "No",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Link",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Link",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "SSL Issued On",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "SSL Issued On",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "SSL Expired On",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "SSL Expired On",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "SSL Status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "SSL Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "string",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Name"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "url",
          "value": "https://docs.google.com/spreadsheets/d/1-8BOhL2xpJtVJeH6rrLcgegFXkq2NtqjChSp2DrCqoM/edit#gid=0",
          "__regex": "https:\\/\\/docs\\.google\\.com\\/spreadsheets\\/d\\/[0-9a-zA-Z\\-_]+.*\\#gid=([0-9]+)"
        },
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": "https://docs.google.com/spreadsheets/d/1-8BOhL2xpJtVJeH6rrLcgegFXkq2NtqjChSp2DrCqoM/edit?usp=drivesdk",
          "__regex": "https:\\/\\/(?:drive|docs)\\.google\\.com(?:\\/.*|)\\/d\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)"
        },
        "authentication": "serviceAccount"
      },
      "credentials": {
        "googleApi": {
          "id": "hieVDK2geFfUQ5r3",
          "name": "Google Service Account account"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "652529e3-a42d-4786-b5ff-efc56cdd1b75",
      "name": "每周一触发",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -420,
        680
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "triggerAtDay": [
                1
              ],
              "triggerAtHour": 7
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "38845019-8a36-499f-9904-e8b11d1abcfd",
      "name": "SSL 状态不佳?",
      "type": "n8n-nodes-base.if",
      "position": [
        1200,
        420
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "3dfd4edd-6a4d-4a41-b2f3-647bc7308aaa",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.message }}",
              "rightValue": "All Good"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "98615825-9ba9-4a56-a6c9-a4c49ceeb79c",
      "name": "获取网站列表",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -40,
        680
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1FWZ8vT5bMQXxDToguBW30LjQV_8sU9UN1wXk-2vCFTE/edit#gid=0",
          "cachedResultName": "List"
        },
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": "https://docs.google.com/spreadsheets/d/1FWZ8vT5bMQXxDToguBW30LjQV_8sU9UN1wXk-2vCFTE/edit?usp=sharing"
        },
        "authentication": "serviceAccount"
      },
      "credentials": {
        "googleApi": {
          "id": "hieVDK2geFfUQ5r3",
          "name": "Google Service Account account"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "fac5d72b-37b1-42ad-905e-daf3d7b8f93b",
      "name": "代码",
      "type": "n8n-nodes-base.code",
      "position": [
        800,
        440
      ],
      "parameters": {
        "jsCode": "// Get the current date and time\nconst now = new Date();\n\n// Set the threshold (in days) for SSL expiration warning\nconst thresholdDays = 14;\n\n// Filter the input data to only include entries where the SSL certificate\n// expires within the threshold (i.e., 14 days or fewer from today)\nconst filtered = $input.all().filter(item => {\n  const expiry = new Date(item.json[\"SSL Expired On\"]);\n  const daysLeft = (expiry - now) / (1000 * 60 * 60 * 24); // Convert milliseconds to days\n  return daysLeft <= thresholdDays;\n});\n\n// If no certificates are expiring soon, return a simple \"All Good\" message\nif (filtered.length === 0) {\n  return [\n    {\n      json: {\n        message: \"All Good\"\n      }\n    }\n  ];\n} else {\n  // If some certificates are expiring soon, build a message listing them\n  const websiteNames = filtered.map(entry => {\n    const daysLeft = Math.ceil((new Date(entry.json[\"SSL Expired On\"]) - now) / (1000 * 60 * 60 * 24));\n    return `- ${entry.json.Name} (expires in ${daysLeft} days)`;\n  }).join('\\n');\n\n  // Create the final message to return\n  const message = `SSL certificates expiring soon:\\n${websiteNames}`;\n\n  return [\n    {\n      json: {\n        message: message\n      }\n    }\n  ];\n}\n"
      },
      "typeVersion": 2
    },
    {
      "id": "cb3170e5-448a-4310-8e16-68d3db5e831e",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -500,
        480
      ],
      "parameters": {
        "width": 260,
        "height": 360,
        "content": "## 每周触发器"
      },
      "typeVersion": 1
    },
    {
      "id": "ffa881ff-90d1-4909-bc30-4492de897a26",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -120,
        480
      ],
      "parameters": {
        "width": 260,
        "height": 360,
        "content": "## 获取网站 URL"
      },
      "typeVersion": 1
    },
    {
      "id": "7133cfce-67a8-4527-b731-78afe30ecb64",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        720,
        660
      ],
      "parameters": {
        "width": 260,
        "height": 360,
        "content": "## 获取 SSL 状态"
      },
      "typeVersion": 1
    },
    {
      "id": "f3752261-5bea-48c7-8058-d37b7165427c",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1300,
        720
      ],
      "parameters": {
        "width": 400,
        "height": 560,
        "content": "## 更新电子表格"
      },
      "typeVersion": 1
    },
    {
      "id": "77fb04f5-94bf-4536-9095-2d67781a3fa8",
      "name": "便签说明4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        720,
        60
      ],
      "parameters": {
        "width": 260,
        "height": 520,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "3d732b6d-fb05-4872-afe5-df13ed0b5ab2",
      "name": "便签说明5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1120,
        120
      ],
      "parameters": {
        "width": 260,
        "height": 440,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "6c0f7e6c-5a41-48d0-84e2-4ba058160809",
      "name": "便签 6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1480,
        120
      ],
      "parameters": {
        "width": 260,
        "height": 440,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "69aa3a4f-2b96-446b-b221-ab808912d8ef",
      "name": "发送邮件警报",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        1560,
        400
      ],
      "webhookId": "ef8c71c7-bf7e-4749-adbb-a66d19161c89",
      "parameters": {
        "text": "={{ $json.message }}",
        "options": {},
        "subject": "⚠️ ALERT!! SSL EXPIRED",
        "toEmail": "example@gmail.com, example2@gmail.com",
        "fromEmail": "admin@balimandira.com",
        "emailFormat": "text"
      },
      "credentials": {
        "smtp": {
          "id": "ZBpj1LGDDnZEdwLw",
          "name": "SMTP account"
        }
      },
      "retryOnFail": true,
      "typeVersion": 2.1
    },
    {
      "id": "3f2e390b-882f-45fe-9855-dfd1542ed188",
      "name": "便签 7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1120,
        320
      ],
      "parameters": {
        "width": 560,
        "height": 640,
        "content": "# 🔒 SSL 监控工作流"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "timezone": "Asia/Singapore",
    "callerPolicy": "workflowsFromSameOwner",
    "executionOrder": "v1"
  },
  "versionId": "12e76c0c-93fb-4b34-8c87-44a0ecaca1ed",
  "connections": {
    "Code": {
      "main": [
        [
          {
            "node": "SSL Not Good?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get SSL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get SSL": {
      "main": [
        [
          {
            "node": "Update SSL in Spreadsheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SSL Not Good?": {
      "main": [
        [
          {
            "node": "Send Email Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Website List": {
      "main": [
        [
          {
            "node": "Loop",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Trigger Every Monday": {
      "main": [
        [
          {
            "node": "Get Website List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update SSL in Spreadsheet": {
      "main": [
        [
          {
            "node": "Loop",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

高级 - 安全运维

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量16
分类1
节点类型8
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者
Agus Narestha

Agus Narestha

@agusnarestha

Automation enthusiast

外部链接
在 n8n.io 查看

分享此工作流