Zabbix 4.0 使用笔记

 

自定义监控项
1.确认需监控内容 (例如:登陆用户数)
2.确认监控方法(例如:脚本)
3.编写脚本
vi /etc/zabbix/custom_shell/current_login_user.sh
# who | wc -l
4.添加KeyValuse
# vi /etc/zabbix/zabbix_agent.d/system_loginuser.conf
UserParameter=system.loginuser,bash /etc/zabbix/custom_shell/current_login_user.sh

# systemctl restart zabbix-agent
5.Server端get测试
# zabbix_get -s 192.168.99.100 -k 'system.loginuser'
4.Server WebUI 添加监控项
配置>模板>监控项>创建监控项

 

添加报警

A:邮件报警
1:管理>报警媒介类型>Email 设置
  SMTP SERVER :smtp.qiye.aliyun.com
  SMTP PORT: 465
  SMTP电邮: ZABBIX@cnblog.com
  安全链接: SSL/TLS
  SSL验证对端: Y
  SSL验证主机: Y
  认证:用户名和密码

2:用户基本资料
  报警媒介:Email
  收件人:LeBronJames@cnblog.com
  当启用时: xx-xx
  Status : 已启用

3:配置>动作>创建动作 ( 可选 )
  动作:名称+条件
  操作:步骤+细节

4:报警媒介类型
  状态:已启用
  用于动作中: Action Name
  细节: xxxxxxxx

5:触发报警后确认
  报表>动作日志

B:企业微信报警

1: 注册企业微信添加自定义应用
https://work.weixin.qq.com/

2: 记录接口信息
--corpid= xxxxxxxxxx (企业ID)
--agentid= 1000003 (自定义应用ID)
--corpsecret= xxxxxxxxxxxxxx(自定义应用 Secret)
--toparty= 2 (部门ID)

3: 查看配置文件确认脚本存放路径
# grep -Ev '^$|#' /etc/zabbix/zabbix_server.conf
AlertScriptsPath=/usr/lib/zabbix/alertscripts

4: 下载OneOaaS 脚本
# wget https://github.com/OneOaaS/weixin-alert/archive/master.zip
# unzip master.zip
weixin_linux_amd64 (发单人)
weixin_linux_amd64_toparty (发部门)
# chown zabbix:zabbix /usr/lib/zabbix/alertscripts/weixin_toparty
# chmod 755 /usr/lib/zabbix/alertscripts/weixin_toparty

https://github.com/OneOaaS/weixin-alert
支持Zabbix的告警,使用方法见微信公众号 http://url.cn/4A37R4z
-----------------------------
脚本位置
wget https://raw.githubusercontent.com/OneOaaS/weixin-alert/master/weixin_linux_amd64
cp weixin_linux_amd64 /etc/zabbix/alertscripts/weixin
chmod 755 /etc/zabbix/alertscripts/weixin
chown zabbix:zabbix /etc/zabbix/alertscripts/weixin

脚本测试
/etc/zabbix/alertscripts/weixin --corpid=wxee***********81aa --corpsecret=Mm0mHwI8iVsjA*JUGySxOFMIlbosoVEkWIEiw --msg="您好</br>告警测试" --user=oneoaas --agentid=1000003
返回数据:
{"errcode":0,"errmsg":"ok","invaliduser":""}

查看帮助
./weixin_linux_amd64 --help
Usage of ./weixin_linux_amd64:
  -agentid string
        agentid
  -author string
        http://www.oneoaas.com
  -corpid string
        corpid
  -corpsecret string
        corpsecret
  -msg string
        Send Message
  -user string
        which user to send msg
        
支持群组发送
Usage of weixin_linux_amd64_toparty:
  -agentid string
        agentid
  -author string
        http://www.oneoaas.com
  -corpid string
        corpid
  -corpsecret string
        corpsecret
  -msg string
        Send Message
  -toparty string
        which toparty to send msg
  -totag string
        which totag to send msg
  -user string
        which user to send msg

        其中toparty,totag,user三个参数任选其一发送即可    
Github Readme

5: 测试脚本

#/usr/lib/zabbix/alertscripts/weixin_toparty --corpid=****************** --corpsecret=***************** --msg="Hello </br>Alert Test" --toparty=2 --agentid=1000003
{"errcode":0,"errmsg":"ok","invaliduser":""}

6: WEBUI 添加报警媒介类型

 

 7: 用户基本资料增加报警媒介

 8: 客户端确认

 

 

 

 

posted @ 2020-07-21 15:58  tamatama  阅读(440)  评论(0)    收藏  举报
GO TOP