上 zabbix 创建用户及告警媒介设置,配置邮件告警发送qq邮箱/163( 二 )


ok,邮箱可以通了;
#接下来配置告警发送的脚本#先查看一下邮件配置文件所在位置,进入到server配置文件里查看[root@localhost ~]# vim /etc/zabbix/zabbix_server.conf!!!!!!!!!!!!!!!!!!!!!#***但是我这里zabbix-server是安装在docker容器里的***[root@localhost ~]# docker exec -it xkdzabbix/bin/bashbash-5.0# vi /etc/zabbix/zabbix_server.conf bash-5.0# exitAlertScriptsPath=/usr/lib/zabbix/alertscripts[root@localhost ~]#[root@localhost ~]# cd /usr/lib/zabbix/alertscripts[root@localhost alertscripts]#ls[root@localhost alertscripts]#vim mail.sh
脚本文件内容如下
#!/bin/bashSENT_TO=$1告警的接受人SENT_SUBJECT=$2标题SENT_CONTENT=$3Bodyecho "$SENT_CONTENT"|mailx -s "$SENT_SUBJECT" $SENT_TO
按“:x”,保存退出;
[root@ ~]#exec -it/bin/bash
bash-5.0# chmod a+x mail.sh
bash-5.0# vi mail.sh
bash-5.0# ./mail.sh“ test2” “test two”
#给脚本添加权限bash-5.0# chmod a+x mail.shbash-5.0# vi mail.shbash-5.0# ./mail.sh1134298123@qq.com "zabbix test2" "test two"./mail.sh: line 7: mailx: command not found如果zabbix-server是直接部署在虚拟机里的,那么这里就可以直接成功了!下面是针对server装在docker容器里的问题
!!! !!! !!!
就在我以为一切都很完美的时候;
报错了,mailx找不到,
我忘了我的服务是在里面的,而前面我是把mailx安装在了虚拟机上,容器里根本没有mailx;
那我在里安装一下***,我不知道是否是应该安装这个,网上也找不到,有谁知道,评论告诉我一下,我安装完,进入里执行脚本依然报错,***
[root@localhost ~]# docker search heirloom-mailxNAMEDESCRIPTIONSTARSOFFICIALAUTOMATEDcorentinaltepe/heirloom-mailxHeirloom-mailx in Alpine to easily send emai…5fezzz/php-fpmphp8.0-fpm(latest) image for nextcloud:Ser…1[OK]harobed/docker-heirloom-mailxheirloom-mailx Alpine Docker image0[OK]teamidefix/vault-mailxVault + heirloom-mailx0asproat/debian-mailxDebian stretch with heirloom-mailx0[root@localhost ~]# docker pull corentinaltepe/heirloom-mailxUsing default tag: latestlatest: Pulling from corentinaltepe/heirloom-mailx97518928ae5f: Already exists 6bac87e09cbb: Pull complete Digest: sha256:671585c532fa92145b436d66e735cc5f4d64bf80d2cc1efc3def736debef4c41Status: Downloaded newer image for corentinaltepe/heirloom-mailx:latestdocker.io/corentinaltepe/heirloom-mailx:latest
下图为-没有安装在里可以执行脚本,就会成功;
错误
[root@localhost ~]# docker exec -it xkdzabbix /bin/bash bash-5.0# ./mail.sh1134298123@qq.com "zabbix test2" "test two"bash: ./mail.sh: No such file or directorybash-5.0# cd /usr/lib/zabbix/alertscriptsbash-5.0# ./mail.sh1134298123@qq.com "zabbix test2" "test two"./mail.sh: line 6: mailx: command not foundbash-5.0# exit
记录一下错误,后面再搞,关于安装的这个-mailx配置文件,和上面mail.rc是一样的