Linux服务管理-zabbix监控邮箱告警配置

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

在这里插入图片描述
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值