概述
zabbix媒介类型包括mail、sms、自定义脚本,我们用的最多的还是脚本媒介,再次我们就不讲另外两个媒介了。当事件通知到脚本,会传递三个参数它,分别为$1(发送给谁) $2(标题) $3(内容)。例如发送邮件给support@ttlsa.com,标题为nginx离线,内容是IP地址:1.1.1.1,nginx离线,请立即处理。
媒介配置
点击administrator->media types->create media types文章源自运维生存时间-https://www.ttlsa.com/zabbix/zabbix-custom-alertscripts/
Name:触发器名称
Type:介质类型
script name:脚本名称(需要先定义AlertScriptsPath,mail.sh放在这个目录下,写绝路路径没用)
Enabled:状态文章源自运维生存时间-https://www.ttlsa.com/zabbix/zabbix-custom-alertscripts/
配置AlertScriptsPath
# mkdir /usr/local/zabbix-2.2.1/alertscripts # cat /usr/local/zabbix-2.2.1/etc/zabbix_server.conf| grep -i aler AlertScriptsPath=/usr/local/zabbix-2.2.1/alertscripts
脚本编写
# cd /usr/local/zabbix-2.2.1/alertscripts # cat mail.sh #!/bin/sh to=$1 subject=$2 body=$3 /usr/local/bin/sendEmail -f support@ttlsa.com -t "$to" -s smtp.ttlsa.com -u "$subject" -o message-content-type=html -o message-charset=utf8 -xu monitor@ttlsa.com -xp123456 -m "$body" 2>>/tmp/22.log
备注:sendEmail需要额外安装,请参考《sendEmail发送邮件》文章源自运维生存时间-https://www.ttlsa.com/zabbix/zabbix-custom-alertscripts/
用户媒介
给用户指定媒介:文章源自运维生存时间-https://www.ttlsa.com/zabbix/zabbix-custom-alertscripts/
*点击Administration→Users->打开用户属性表单->在Media tab点击Add文章源自运维生存时间-https://www.ttlsa.com/zabbix/zabbix-custom-alertscripts/
参数介绍文章源自运维生存时间-https://www.ttlsa.com/zabbix/zabbix-custom-alertscripts/
Type:选择媒介类型,这边选自定义媒介文章源自运维生存时间-https://www.ttlsa.com/zabbix/zabbix-custom-alertscripts/
Send to:发送到哪,例如monitor@ttlsa.com,他就是脚本中的$1文章源自运维生存时间-https://www.ttlsa.com/zabbix/zabbix-custom-alertscripts/
When active:报警时间限定,例如1-5,09:00-18:00,只有工作日的9点到18点才会通知,实际工作中,我们应该是相反。文章源自运维生存时间-https://www.ttlsa.com/zabbix/zabbix-custom-alertscripts/
Use if severity:严重性类型,只接收指定的类型,例如info不想接收,那我不勾选即可。文章源自运维生存时间-https://www.ttlsa.com/zabbix/zabbix-custom-alertscripts/
Status:媒介状态Enabled - 启用中.Disabled - 已禁用.文章源自运维生存时间-https://www.ttlsa.com/zabbix/zabbix-custom-alertscripts/
最后
自定义脚本搞定,后面教程将会用到指定脚本来报警。请继续关注ttlsa.com。文章源自运维生存时间-https://www.ttlsa.com/zabbix/zabbix-custom-alertscripts/ 文章源自运维生存时间-https://www.ttlsa.com/zabbix/zabbix-custom-alertscripts/

4F
你好,我想请教下,自定义的报警脚本是不是只能传3个zabbix的宏?{ALERT.MESSAGE}{ALERT.SENDTO}{ALERT.SUBJECT} 这3个?我测试了下其他宏,都不生效
3F
$1是to,你写成路径有什么意义呢?
2F
您好,我sendto能否写为文件路径?脚本写成echo "$2:$3" << $1/problem.log ?
1F
$1能不能自定义收件人,让系统判断是哪台机器发生的故障,就发送给谁,而不是固定的几个收件人
B1
@ wood 这在少量服务器是可以实现的,但是数量多就很难处理了
例如有1000台机器,分别属于500个用户,那就需要配置500个action?而且更改用户的话还要另外修改action
来自外部的引用