Zabbix进阶2--接入DeepSeek分析问题并提供解决方案

背景

由于现在AI的爆火,怎么有效使用AI来提高我们的工作成了很关键的一点,用好了,工作都能少做很多,所以我们尝试在Zabbix中接入DeepSeek来获取报警的相关知识

参考文章: https://blog.zabbix.com/creating-a-personal-assistant-in-zabbix-with-artificial-intelligence/29596/

文章中使用了Gemini,而我们这回选择改成Deepseek,看能不能实现相同的功能

步骤

创建script

Alert -> Script

创建一个手动执行的script,也就是说只有当你手动选择执行script的时候才能够运行该脚本

修改timeout

timeout参数必须修改,尤其是推理模型的时候,因为可能网络问题或者性能问题,默认的30s timeout时间是不够的,所以咱们尽可能改大一点,60s最大

修改Parameters参数

在Parameters中输入以下两个参数:

  • alert_subject, {TRIGGER.NAME}, 即alert的名称,用来分析报错原因,所以alert的名称需要设置的正确
  • api_key: API token, sk-xxxxx
  • model: 模型名称

编辑脚本内容

在Script中输入以下内容

值得一说的是,这个是接入了阿里云的deepseep,如果你接入的是其他的平台,记得修改API地址以及接口格式

复制代码
var DeepSeek = {
    params: {},
    setParams: function (params) {
        if (typeof params !== 'object') {
            return;
        }
        DeepSeek.params = params;
        if (typeof DeepSeek.params.api_key !== 'string' || DeepSeek.params.api_key === '') {
            throw 'API key for DeepSeek is required.';
        }
        DeepSeek.params.url = 'https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions';
    },
    request: function (data) {
        if (!DeepSeek.params.api_key) {
            throw 'API key is missing.';
        }
        var request = new HttpRequest();
		request.addHeader('Content-Type: application/json');
        request.addHeader('Authorization: Bearer ' + DeepSeek.params.api_key);
        var response = request.post(DeepSeek.params.url, JSON.stringify(data));

        if (request.getStatus() < 200 || request.getStatus() >= 300) {
            throw 'DeepSeek API request failed with status code ' + request.getStatus() + '.';
        }

        try {
            response = JSON.parse(response);
        } catch (error) {
            Zabbix.log(4, '[ DeepSeek Webhook ] Failed to parse response.');
            response = null;
        }
        return response;
    }
};

try {
    var params = JSON.parse(value),
        data = {},
        result = "",
        required_params = ['alert_subject'];

    Object.keys(params).forEach(function (key) {
        if (required_params.indexOf(key) !== -1 && params[key] === '') {
            throw 'Parameter "' + key + '" cannot be empty.';
        }
    });

    data = {
        "model": "deepseek-v3",  // 指定模型
        "messages": [
            {
                "role": "user",
                "content": "Alert : " + params.alert_subject + " occurred on Zabbix. " +
                    "Suggest possible causes and solutions to resolve this issue. " +
                    "Provide concise points (10 lines max) including root causes, debug commands, and mitigation steps."
            }
        ]
    };

    DeepSeek.setParams({api_key: params.api_key});
	Zabbix.log(3, '[ DeepSeek debug ] ' + data);
    var response = DeepSeek.request(data);

    if (response && response.choices && response.choices.length > 0) {
        result = response.choices[0].message.content.trim();
    } else {
        throw 'No valid response from DeepSeek.';
    }

    return result;

} catch (error) {
    Zabbix.log(3, '[ DeepSeek Webhook ] ERROR: ' + error);
    throw 'Sending failed: ' + error;
}

测试脚本是否工作

Monitoring -> Problems中,随便找一个问题,点击问题,会出现刚刚创建的script选项

总结

这个个人感觉只是一个初阶版,只能根据该问题的title进行分析并给出对应的建议,无法结合其他信息进一步分析

而且,由于网络问题,API很容易超时,导致无法展示结果,因此对API的性能和网络有较高要求

相关推荐
行云流水剑15 分钟前
【学习记录】在 Ubuntu 中将新硬盘挂载到 /home 目录的完整指南
服务器·学习·ubuntu
藥瓿亭20 分钟前
K8S认证|CKS题库+答案| 7. Dockerfile 检测
运维·ubuntu·docker·云原生·容器·kubernetes·cks
搬码临时工1 小时前
如何把本地服务器变成公网服务器?内网ip网址转换到外网连接访问
运维·服务器·网络·tcp/ip·智能路由器·远程工作·访问公司内网
vortex51 小时前
探索 Shell:选择适合你的命令行利器 bash, zsh, fish, dash, sh...
linux·开发语言·bash·shell·dash
GalaxyPokemon1 小时前
LeetCode - 148. 排序链表
linux·算法·leetcode
Guheyunyi1 小时前
监测预警系统重塑隧道安全新范式
大数据·运维·人工智能·科技·安全
懒羊羊大王呀2 小时前
Ubuntu20.04中 Redis 的安装和配置
linux·redis
鳄鱼杆2 小时前
服务器 | Centos 9 系统中,如何部署SpringBoot后端项目?
服务器·spring boot·centos
杰哥技术分享2 小时前
在 CentOS 上安装 Docker 和 Docker Compose 并配置使用国内镜像源
linux·docker·centos
知更鸟呆呆2 小时前
【Linux操作系统】基础开发工具(yum、vim、gcc/g++)
linux·运维·vim