Wazuh使用企业微信机器人预警

vim /var/ossec/etc/ossec.conf 
 <integration>
    <name>custom-wechat</name>
    <hook_url>WEBHOOK</hook_url>
    <level>12</level>
    <api_key>APIKEY</api_key> <!-- Replace with your external service API key -->
    <alert_format>json</alert_format>
  </integration>

只有name属性是必填的,该参数值是自定义脚本文件的文件名
自定义脚本必须要以"custom-"作为文件名的前缀,可以是shell或python脚本文件
自定义脚本必须读取和解析处理命令行参数,其中参数1对应着包含报警消息内容的文件、参数2对应着api_key的值、参数3对应着hook_url的值。

cat /var/ossec/integrations/custom-wechat

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
import json
import sys
import wechat_work_webhook


# 替换为你的企业微信webhook URL
webhook_url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key="
wechat = wechat_work_webhook.connect(webhook_url)


# 读取配置参数
alert_file = open(sys.argv[1])
# 读取告警文件
alert_json = json.loads(alert_file.read())
alert_file.close()

alert_level = alert_json['rule']['level']
ruleid = alert_json['rule']['id']
description = alert_json['rule']['description']
agentid = alert_json['agent']['id']
agentname = alert_json['agent']['name']
#wechat.markdown(u'<font color=\"warning\">告警</font> \n'+"HostName: "+agentname+"\n"+"AlertLevel: "+str(alert_level)+"\n"+"Description: "+description)
wechat.markdown(u'<font color=\"warning\">告警</font> \n'+u'主机名: '+agentname+"\n"+u"告警级别: "+str(alert_level)+"\n"+u"告警内容: "+description)
#wechat.text('test',['@all'])

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值