UniFi控制器:检查并在新发布时升级
中级
这是一个DevOps, AI Summarization领域的自动化工作流,包含 11 个节点。主要使用 If, Ssh, Code, Telegram, HttpRequest 等节点。 通过SSH和Telegram通知自动化UniFi控制器更新
前置要求
- •Telegram Bot Token
- •可能需要目标 API 的认证凭证
- •OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"name": "UniFi控制器:检查并在新发布时升级",
"tags": [
{
"name": "SSH"
}
],
"nodes": [
{
"id": "e3552972-d4cd-40fd-8436-39b41a0e4123",
"name": "计划触发器",
"type": "n8n-nodes-base.scheduleTrigger",
"position": [
432,
288
],
"parameters": {
"rule": {
"interval": [
{
"triggerAtHour": 13,
"triggerAtMinute": 13
}
]
}
},
"typeVersion": 1.2
},
{
"id": "0aa8ec9d-4567-46e0-8271-8cc71c567ead",
"name": "HTTP请求",
"type": "n8n-nodes-base.httpRequest",
"position": [
624,
288
],
"parameters": {
"url": "https://dl.ui.com/unifi/debian/dists/stable/InRelease",
"options": {},
"responseFormat": "string"
},
"typeVersion": 4.2
},
{
"id": "2d7e4f46-02ff-48a5-8e2d-3908fd6f04fa",
"name": "提取代号+日期+时间比较",
"type": "n8n-nodes-base.code",
"position": [
864,
288
],
"parameters": {
"jsCode": "const inReleaseContent = $input.first().json.body || '';\n\n// Extract Codename\nconst codenameMatch = inReleaseContent.match(/^Codename:\\s*(.+)$/m);\nconst codename = codenameMatch ? codenameMatch[1].trim() : null;\n\n// Extract Date\nconst dateMatch = inReleaseContent.match(/^Date:\\s*(.+)$/m);\nconst dateString = dateMatch ? dateMatch[1].trim() : null;\n\nlet releaseTimestamp = null;\nlet changedInLast24h = false;\n\nif (dateString) {\n const parsedDate = new Date(dateString);\n if (!isNaN(parsedDate)) {\n releaseTimestamp = parsedDate.getTime();\n const now = Date.now();\n const diffHours = (now - releaseTimestamp) / (1000 * 60 * 60);\n changedInLast24h = diffHours <= 24;\n }\n}\n\nreturn [{ json: { codename, releaseDate: dateString, releaseTimestamp, changedInLast24h } }];"
},
"typeVersion": 2
},
{
"id": "d099755d-88bd-4ded-9206-3c84b0de25db",
"name": "条件判断:24小时内是否更改?",
"type": "n8n-nodes-base.if",
"position": [
1072,
288
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"caseSensitive": true,
"typeValidation": "loose"
},
"combinator": "and",
"conditions": [
{
"id": "35485051-ae36-4332-9e1d-4a73be0a044a",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
},
"leftValue": "={{ $json.changedInLast24h }}"
}
]
},
"looseTypeValidation": true
},
"typeVersion": 2.2
},
{
"id": "808ecc9c-50d2-442c-ad10-913f67e1b240",
"name": "更新软件包列表",
"type": "n8n-nodes-base.ssh",
"position": [
432,
512
],
"parameters": {
"cwd": "/root",
"command": "apt-get --allow-releaseinfo-change update",
"authentication": "privateKey"
},
"typeVersion": 1
},
{
"id": "b1f8686a-7c72-4283-baa4-3e43fe3e4ec9",
"name": "升级UniFi",
"type": "n8n-nodes-base.ssh",
"position": [
624,
512
],
"parameters": {
"cwd": "/root",
"command": "apt-get upgrade -y unifi",
"authentication": "privateKey"
},
"typeVersion": 1
},
{
"id": "1b892e4e-9f71-4537-abc1-4e135cac0f2c",
"name": "消息模型",
"type": "@n8n/n8n-nodes-langchain.openAi",
"position": [
464,
768
],
"parameters": {
"modelId": {
"__rl": true,
"mode": "list",
"value": "gpt-4.1-nano",
"cachedResultName": "GPT-4.1-NANO"
},
"options": {},
"messages": {
"values": [
{
"content": "=Please concisely summarize the performed UniFi update and what's new in this release.\n\nCodename: {{ $('Extract Codename + Date + Time Comparison').item.json.codename }}\nRelease date: {{ $('Extract Codename + Date + Time Comparison').item.json.releaseDate }}\n\napt-get update exit code: {{ $('Update package lists').item.json.code }}\napt-get upgrade exit code/stdout: {{ $('Upgrade UniFi').item.json.code }} / {{ $('Upgrade UniFi').item.json.stdout }}"
}
]
}
},
"typeVersion": 1.8
},
{
"id": "8439a184-315b-4282-a8fd-3bce2025ee8e",
"name": "通过Telegram通知",
"type": "n8n-nodes-base.telegram",
"position": [
800,
768
],
"parameters": {
"text": "=UniFi package updated:\n{{ $json.message && $json.message.content ? $json.message.content : 'Upgrade finished.' }}\n[Web interface](https://unifi.ui.com)",
"chatId": "={{ $env.TELEGRAM_CHAT_ID }}",
"additionalFields": {
"parse_mode": "Markdown"
}
},
"typeVersion": 1.2
},
{
"id": "1951d673-d0ed-4a1f-bd7d-dc1a24dd7d07",
"name": "便签:触发与检查",
"type": "n8n-nodes-base.stickyNote",
"position": [
400,
240
],
"parameters": {
"color": 5,
"width": 796,
"height": 220,
"content": "触发工作流并检查UniFi仓库是否在最近24小时内更新"
},
"typeVersion": 1
},
{
"id": "c9e311b8-b821-40ef-b014-c0a0a7552507",
"name": "便签:升级",
"type": "n8n-nodes-base.stickyNote",
"position": [
400,
480
],
"parameters": {
"color": 4,
"width": 572,
"height": 220,
"content": "通过SSH执行软件包升级(控制器主机需要apt访问权限和配置SSH密钥)"
},
"typeVersion": 1
},
{
"id": "691981f1-b61c-4b36-af6b-8ccdc92c57df",
"name": "便签:通知",
"type": "n8n-nodes-base.stickyNote",
"position": [
400,
736
],
"parameters": {
"width": 572,
"height": 220,
"content": "通过Telegram通知更新信息(可选使用LLM生成简短摘要)"
},
"typeVersion": 1
}
],
"active": false,
"settings": {
"executionOrder": "v1"
},
"connections": {
"HTTP Request": {
"main": [
[
{
"node": "Extract Codename + Date + Time Comparison",
"type": "main",
"index": 0
}
]
]
},
"Upgrade UniFi": {
"main": [
[
{
"node": "Message a model",
"type": "main",
"index": 0
}
]
]
},
"Message a model": {
"main": [
[
{
"node": "Notify via Telegram",
"type": "main",
"index": 0
}
]
]
},
"Schedule Trigger": {
"main": [
[
{
"node": "HTTP Request",
"type": "main",
"index": 0
}
]
]
},
"Update package lists": {
"main": [
[
{
"node": "Upgrade UniFi",
"type": "main",
"index": 0
}
]
]
},
"If: Changed within 24h?": {
"main": [
[
{
"node": "Update package lists",
"type": "main",
"index": 0
}
],
[]
]
},
"Extract Codename + Date + Time Comparison": {
"main": [
[
{
"node": "If: Changed within 24h?",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
中级 - 开发运维, AI 摘要总结
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
n8n自动更新
使用版本检查和Portainer Webhook自动化n8n更新
If
Code
Http Request
+2
12 节点Dominic Spatz
开发运维
Lighthouse报告
使用Lighthouse、Gemini AI、Telegram警报和Google Sheets监控核心网页指标
If
Code
Telegram
+6
13 节点Rully Saputra
开发运维
Degen Alpha
使用 OpenAI 的加密 Alpha 扫描器 - 链上和社交警报发送到 Telegram
If
Code
Merge
+9
38 节点Luka Zivkovic
加密货币交易
我的工作流程2
基于ScrapeGraphAI和Telegram的智能物联网设备健康监控
If
Code
Telegram
+3
13 节点vinci-king-01
开发运维
n8n更新
使用 Telegram 审批系统自动化 Docker 容器更新
If
Set
Ssh
+6
27 节点Jaber Zare
开发运维
SOL/USDT多时间框架AI市场分析器与交易系统(含Telegram审批)
使用Gemini AI、多时间框架分析和AFK Crypto自动化Solana交易
If
Code
Wait
+7
56 节点Jeff
加密货币交易