feat: 新增设备巡检模块实现完整的巡检告警功能

新增设备巡检模块核心功能,包括:
- 巡检数据存储与调度系统
- 华为/H3C交换机及Linux服务器采集器
- 设备扩展配置与告警规则管理
- 主机详情页巡检配置入口
- 产品名称自定义设置功能
- 网络设备SSH exec通道兼容处理
This commit is contained in:
2026-10-09 10:37:48 +08:00
parent 9202506c46
commit c64e00d835
75 changed files with 12087 additions and 446 deletions

View File

@@ -0,0 +1,189 @@
"use strict";
/**
* 设备类型数据模型 + 预置数据
*
* 设备类型(device_catalog):定义一类设备的采集能力和默认配置。
* 预置 6 种设备类型,用户可在界面上新增。
*/
const { DEVICE_CATALOG_TYPES, ALERT_LEVELS, DEVICE_TIERS } = require("./types.cjs");
/**
* 默认告警阈值 - 用于设备类型的预置配置
* 格式:{ metric, operator, threshold, level, duration }
*/
const DEFAULT_THRESHOLDS = {
linux: [
{ metric: "cpu_usage", operator: ">", threshold: "80", level: ALERT_LEVELS.CRITICAL, duration: 1 },
{ metric: "cpu_usage", operator: ">", threshold: "70", level: ALERT_LEVELS.WARNING, duration: 2 },
{ metric: "memory_usage", operator: ">", threshold: "85", level: ALERT_LEVELS.CRITICAL, duration: 1 },
{ metric: "memory_usage", operator: ">", threshold: "75", level: ALERT_LEVELS.WARNING, duration: 2 },
{ metric: "online", operator: "==", threshold: "false", level: ALERT_LEVELS.CRITICAL, duration: 1 },
],
windows: [
{ metric: "cpu_usage", operator: ">", threshold: "80", level: ALERT_LEVELS.CRITICAL, duration: 1 },
{ metric: "cpu_usage", operator: ">", threshold: "70", level: ALERT_LEVELS.WARNING, duration: 2 },
{ metric: "memory_usage", operator: ">", threshold: "85", level: ALERT_LEVELS.CRITICAL, duration: 1 },
{ metric: "memory_usage", operator: ">", threshold: "75", level: ALERT_LEVELS.WARNING, duration: 2 },
{ metric: "online", operator: "==", threshold: "false", level: ALERT_LEVELS.CRITICAL, duration: 1 },
],
huawei_h3c_switch: [
{ metric: "cpu_usage", operator: ">", threshold: "80", level: ALERT_LEVELS.CRITICAL, duration: 1 },
{ metric: "cpu_usage", operator: ">", threshold: "70", level: ALERT_LEVELS.WARNING, duration: 2 },
{ metric: "memory_usage", operator: ">", threshold: "85", level: ALERT_LEVELS.CRITICAL, duration: 1 },
{ metric: "memory_usage", operator: ">", threshold: "75", level: ALERT_LEVELS.WARNING, duration: 2 },
{ metric: "online", operator: "==", threshold: "false", level: ALERT_LEVELS.CRITICAL, duration: 1 },
],
cisco_switch: [
{ metric: "cpu_usage", operator: ">", threshold: "80", level: ALERT_LEVELS.CRITICAL, duration: 1 },
{ metric: "cpu_usage", operator: ">", threshold: "70", level: ALERT_LEVELS.WARNING, duration: 2 },
{ metric: "memory_usage", operator: ">", threshold: "85", level: ALERT_LEVELS.CRITICAL, duration: 1 },
{ metric: "memory_usage", operator: ">", threshold: "75", level: ALERT_LEVELS.WARNING, duration: 2 },
{ metric: "online", operator: "==", threshold: "false", level: ALERT_LEVELS.CRITICAL, duration: 1 },
],
huawei_firewall: [
{ metric: "cpu_usage", operator: ">", threshold: "80", level: ALERT_LEVELS.CRITICAL, duration: 1 },
{ metric: "memory_usage", operator: ">", threshold: "85", level: ALERT_LEVELS.CRITICAL, duration: 1 },
{ metric: "online", operator: "==", threshold: "false", level: ALERT_LEVELS.CRITICAL, duration: 1 },
],
fortinet_firewall: [
{ metric: "cpu_usage", operator: ">", threshold: "80", level: ALERT_LEVELS.CRITICAL, duration: 1 },
{ metric: "memory_usage", operator: ">", threshold: "85", level: ALERT_LEVELS.CRITICAL, duration: 1 },
{ metric: "online", operator: "==", threshold: "false", level: ALERT_LEVELS.CRITICAL, duration: 1 },
],
};
/**
* 预置设备类型列表
* 每条记录对应一条 device_catalog 数据
*/
const PRESET_DEVICE_CATALOG = [
{
id: "linux",
type_key: DEVICE_CATALOG_TYPES.LINUX,
name: "Linux 服务器",
vendor: "Linux",
adapter_class: "LinuxServerAdapter",
supported_metrics: [
"cpu_usage",
"memory_usage",
"disk_usage",
"load_avg",
"uptime",
"process_count",
"online",
],
default_thresholds: DEFAULT_THRESHOLDS.linux,
default_interval: 5, // 默认 5 分钟
description: "通用 Linux 服务器,支持 Ubuntu/CentOS/Debian/Alpine 等发行版",
preset: true,
},
{
id: "windows",
type_key: DEVICE_CATALOG_TYPES.WINDOWS,
name: "Windows 服务器",
vendor: "Microsoft",
adapter_class: "WindowsServerAdapter",
supported_metrics: [
"cpu_usage",
"memory_usage",
"disk_usage",
"uptime",
"process_count",
"service_status",
"online",
],
default_thresholds: DEFAULT_THRESHOLDS.windows,
default_interval: 5,
description: "Windows Server 2012/2016/2019/2022,通过 SSH + PowerShell 采集",
preset: true,
},
{
id: "huawei_h3c_switch",
type_key: DEVICE_CATALOG_TYPES.HUAWEI_H3C_SWITCH,
name: "华为/H3C 交换机",
vendor: "华为/H3C",
adapter_class: "HuaweiH3CSwitchAdapter",
supported_metrics: [
"cpu_usage",
"memory_usage",
"port_status",
"power_status",
"fan_status",
"device_info",
"online",
],
default_thresholds: DEFAULT_THRESHOLDS.huawei_h3c_switch,
default_interval: 10, // 交换机默认 10 分钟
description: "华为 S3000/S5000/S7000/S9000 系列、H3C S5100/S5500 等交换机",
preset: true,
},
{
id: "cisco_switch",
type_key: DEVICE_CATALOG_TYPES.CISCO_SWITCH,
name: "Cisco 交换机",
vendor: "Cisco",
adapter_class: "CiscoSwitchAdapter",
supported_metrics: [
"cpu_usage",
"memory_usage",
"port_status",
"power_status",
"fan_status",
"online",
],
default_thresholds: DEFAULT_THRESHOLDS.cisco_switch,
default_interval: 10,
description: "Cisco Catalyst 2960/3650/3850/4500/6500 等交换机",
preset: true,
},
{
id: "huawei_firewall",
type_key: DEVICE_CATALOG_TYPES.HUAWEI_FIREWALL,
name: "华为防火墙",
vendor: "华为",
adapter_class: "HuaweiFirewallAdapter",
supported_metrics: [
"cpu_usage",
"memory_usage",
"session_count",
"online",
],
default_thresholds: DEFAULT_THRESHOLDS.huawei_firewall,
default_interval: 5, // 防火墙重要,默认 5 分钟
description: "华为 USG 系列防火墙",
preset: true,
},
{
id: "fortinet_firewall",
type_key: DEVICE_CATALOG_TYPES.FORTINET_FIREWALL,
name: "飞塔防火墙",
vendor: "Fortinet",
adapter_class: "FortinetFirewallAdapter",
supported_metrics: [
"cpu_usage",
"memory_usage",
"session_count",
"online",
],
default_thresholds: DEFAULT_THRESHOLDS.fortinet_firewall,
default_interval: 5,
description: "Fortinet FortiGate 系列防火墙",
preset: true,
},
];
/**
* 获取预置设备类型数据
* @returns {Array}
*/
function getPresetCatalog() {
return JSON.parse(JSON.stringify(PRESET_DEVICE_CATALOG));
}
module.exports = {
PRESET_DEVICE_CATALOG,
DEFAULT_THRESHOLDS,
getPresetCatalog,
};