目录
------------------------- # 邮箱告警 ----------------------------------
1.安装mailx与postfix软件包
2.修改mailx配置文件
3. 创建文件夹
4. 编写mail-send.sh脚本
5. 将该脚本赋予执行权限
6. 进入web界面进行设置—> Alerts —> Media Types
7. 添加动作—> Alerts —> Actions —>Trigger Actions
8. 给用户添加邮箱告警 —> Users —>Users
9. 测试
------------------------- # SMS告警 ----------------------------------
1.上传脚本 sendsms.sh
2.为该脚本赋权限
3. 进入web界面进行设置—> Alerts —> Media Types
4. 添加动作—> Alerts —> Actions —>Trigger Actions
5. 给用户添加邮箱告警 —> Users —>Users
6.测试
------------------------- # 邮箱告警 ----------------------------------
1.安装mailx与postfix软件包
yum -y install postfix
yum -y install mailx
2.修改mailx配置文件
vim /etc/mail.rc
set ask askcc append dot save crt
ignore Received Message-Id Resent-Message-Id Status Mail-From Return-Path Via
set from=dba_alarm@xxx.com smtp=mail.xxx.com
set smtp-auth-user=dba_alarm@xxx.com smtp-auth-password=123456 smtp-auth=login
3. 创建文件夹
mkdir -p /usr/local/share/zabbix/alertscripts/
cd /usr/local/share/zabbix/alertscripts/
4. 编写mail-send.sh脚本
vim mail-send.sh
#!/bin/bash
messages=`echo $3 | tr '\\r\\n' '\\n'`
subject=`echo $2 | tr '\\r\\n' '\\n'`
echo "${messages}" | mailx -s "${subject}" $1
# ----------------------------------------------------------
5. 将该脚本赋予执行权限
chmod 777 mail-send.sh
chown -R zabbix:zabbix mail-send.sh
6. 进入web界面进行设置—> Alerts —> Media Types
7. 添加动作—> Alerts —> Actions —>Trigger Actions
8. 给用户添加邮箱告警 —> Users —>Users
9. 测试
------------------------- # SMS告警 ----------------------------------
1.上传脚本 sendsms.sh
#!/bin/bash
##########################################################################################
# send phone message
########################################################################################### message interface
HTTP_INTERFACE="http://xxx/message/rest/send"
# phones list
phones="$1"
# message content
content="$2"# send message to one mobile
function generate_post_data() {mobile=$1cat << EOF {"sourceKey":"08","bizCode":"OPERATION_ALARM_NOTICE","sign":"XXXXXXXXXXXXXXXXXXX","mobile":"$mobile","content":"$content"}
EOF}OLD_IFS=$IFS
IFS=","
# send message one by one
for item in $phones;docurl -H "Content-Type:application/json" -X POST --data "$(generate_post_data $item)" "$HTTP_INTERFACE"sleep 1
done
IFS=$OLD_IFS
cd /usr/local/share/zabbix/alertscripts/
2.为该脚本赋权限
chom 777 /usr/local/share/zabbix/alertscripts/sendsms.sh
3. 进入web界面进行设置—> Alerts —> Media Types
4. 添加动作—> Alerts —> Actions —>Trigger Actions
5. 给用户添加邮箱告警 —> Users —>Users
6.测试