zabbix监控邮箱告警配置及自定义监控
1.在web界面配置
详情请看https://blog.csdn.net/Mzh_CSDN/article/details/107433532
2.通过脚本用系统账户发送邮件
//在服务端安装mailx
[root@localhost ~]# yum -y install mailx
[root@localhost ~]# vim /usr/local/etc/zabbix_server.conf
//搜索script
# Mandatory: no
# Default:
# AlertScriptsPath=${datadir}/zabbix/alertscripts
AlertScriptsPath=/usr/local/etc/zabbix/alertscripts //添加此行
[root@localhost ~]# chown -R zabbix.zabbix /usr/local/etc/zabbix
[root@localhost ~]# mkdir -p /usr/local/etc/zabbix/alertscripts
[root@localhost ~]# touch /usr/local/etc/zabbix/alertscripts/sendmail.sh
[root@localhost ~]# vim /usr/local/etc/zabbix/alertscripts/sendmail.sh
//添加以下内容
#!/bin/bash
SUBJECT=$(echo -e $2)
MESSAGE=$(echo -e $1)
echo "$MESSAGE" | /usr/bin/mail -s "$SUBJECT" $3
[root@localhost ~]# chmod +x /usr/local/etc/zabbix/alertscripts/sendmail.sh
//重启服务
[root@localhost ~]# pkill zabbix
[root@localhost ~]# zabbix_server
[root@localhost ~]# zabbix_agentd
登录zabbix进行配置
//在客户端修改/tmp/abc文件测试
[root@localhost ~]# echo 'akldnfad' > /tmp/abc
在zabbix上查看
在邮箱查看是否收到邮件
3.通过脚本用第三方邮箱发送邮件
//服务端修改配置文件
[root@localhost ~]# vim /etc/mail.rc
//添加以下内容
set from=xxx@qq.com //自己的邮箱
set smtp="smtp.qq.com"
set smtp-auth-user=xxx@qq.com //自己的邮箱
set smtp-auth-password=xxxxxx //邮箱授权码,不是登陆密码
set smtp-auth=login
[root@localhost ~]# systemctl restart postfix
在客户端改变/tmp/abc文件进行测试
[root@localhost ~]# echo 'sadlf;' > /tmp/abc
到邮箱查看发件邮箱是否为前面设置的
4. 自定义监控
自定义监控就是通过脚本监控你想要监控的内容,如服务进程
//编辑客户端配置文件
[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf
//搜索Unsafe并添加以下内容
# UnsafeUserParameters=0
UnsafeUserParameters=1 //添加该行
......
# Mandatory: no
# Default:
# UserParameter=
UserParameter=check_process[*],/bin/bash /scripts/check_process.sh $1 //添加改行
[root@localhost ~]# mkdir /scripts
[root@localhost ~]# vim /scripts/check_process.sh
//添加以下内容
#!/bin/bash
process_status=$(ps -ef|grep $1|grep -Ev "grep|$0"|wc -l)
if [ $process_status -eq 0 ];then
echo '1'
else
echo '0'
fi
[root@localhost ~]# chmod +x /scripts/check_process.sh
//重启服务
[root@localhost ~]# pkill zabbix
[root@localhost ~]# zabbix_agentd
//在服务端测试一下
[root@localhost ~]# zabbix_get -s 192.168.199.129 -k check_process[postfix]
0
[root@localhost ~]# zabbix_get -s 192.168.199.129 -k check_process[openssh]
1
[root@localhost ~]# ps -ef | grep postfix
root 8461 1 0 08:40 ? 00:00:00 /usr/libexec/postfix/master -w
postfix 8462 8461 0 08:40 ? 00:00:00 pickup -l -t unix -u
postfix 8463 8461 0 08:40 ? 00:00:00 qmgr -l -t unix -u
root 9238 1282 0 09:41 pts/0 00:00:00 grep --color=auto postfix
[root@localhost ~]# ps -ef | grep openssh
root 9240 1282 0 09:41 pts/0 00:00:00 grep --color=auto openssh
//停止客户端邮件服务测试
[root@localhost ~]# systemctl stop postfix