about the mail alarm, there are many programs, the choice here is the stability is good, use more Msmtp+mutt scheme.
This program has a good place is not to build a separate mail server, you can use the third-party mail, this method can not only effectively solve the unknown email address is processed as spam, but also due to third-party stability services to provide alarm accuracy and timeliness.
In fact, the key point is that MSMTP can use Gmail.
We need two components msmtp and mutt, where MSMTP is the key to sending email, mutt to optimize MSMTP.
"Msmtp"
sudo apt-get install-y msmtp
Configure MSMTP
Touch/var/log/msmtp.log
Vim ~/.MSMTPRC
Account Default
Host Smtp.126.com
Port 25
From [email protected]
Auth Login
TLS off
User [email protected]
Password xxxxxxx
Logfile/var/log/msmtp.log
chmod. MSMTPRC
Chown Zabbix.zabbix/var/log/zabbix-r
Chown Zabbix.zabbix/var/log/msmtp.log
chmod 777/var/log/msmtp.log
"Mutt"
Installation
sudo apt-get install-y Mutt
sudo mv/etc/muttrc/etc/muttrc.back
sudo vim/etc/muttrc
Set sendmail= "/usr/bin/msmtp" #你的msmtp命令路径
Set Use_from=yes
Set Realname= "[Email protected]"
Set editor= "Vim"
Test message
echo "Hello Zabbix" | Mutt-s "Zabbix test" [email protected]
"Zabbix Configuration"
Modify the script location path for Zabbix
sudo vim/etc/zabbix/zabbix_server.conf
alertscriptspath=/usr/local/zabbix/scripts/
Restart Zabbix
sudo service zabbix-server restart
sudo mkdir-p/usr/local/zabbix/scripts/
sudo chown zabbix.zabbix/usr/local/zabbix-r
sudo vim/usr/local/zabbix/scripts/mail.sh
#!/bin/sh
echo "$ $" | Mutt-s "$" $
sudo chown Zabbix.zabbix mail.sh
sudo chmod 777 mail.sh
Test scripts
./mail.sh [Email protected] Zabbix Test Hello Zabbix
The Zabbix Web interface sends mailboxes through media settings in the top-right corner of the profile
Configure how mail is sent via email in the Administrator-media types of the toolbar
Type Select Script
Name is mail.sh
PS: The Web configuration of the alarm system teaches complexity and is discussed in detail in the next section on MySQL and system-based alarms. This section will only implement the underlying alarm function.
"Questions about package installation Zabbix cannot be alerted"
If the log and the database are displayed Zabbix sent the message but you did not receive the email.
To exclude spam from being masked, that's the problem with Zabbix itself. There is no such solution on the web, but it can be analyzed to find out where the problem lies.
Analyze the problem:
1.zabbix has no problem with permissions, the script has been given the highest permissions and the owning group and user are Zabbix.
2. The script itself can be sent and received correctly if the user executes directly with Ubuntu. Then the problem of excluding the script itself.
3. Since Zabbix's log and DB show that Mail has been send, it means at least Zabbix is doing sendmail, but there is no successful send. The root of the problem is in the process of Zabbix send mail.
4. We know that Mutt is calling MSMTP to send an email, so the process of sending mail is Zabbix.
Trigger Alarm->zabbix User calls bash-> execute mail.sh script
If the execution succeeds, the send must succeed and the message will not be received if the execution fails.
test and resolve issues
1. Manually log in to Zabbix user to simulate Zabbix send mail, we found that the first step will be wrong, because Ubuntu Apt-get install Zabbix when the Zabbix user automatically created by default does not have home directory and login Shell, Then at least you should give Zabbix the permission to call bash, otherwise Zabbix users will not be able to successfully execute mail.sh scripts.
Here's how to fix it:
sudo vim/etc/passwd
Change the last/bin/false of the Zabbix line to/bin/bash.
After saving the exit, this time with sudo su-zabbix switch to Zabbix, although there is no home directory but there is a login shell.
2. Perform mail.sh test
./mail.sh [Email protected] Zabbix Test Hello Zabbix
Tips
Msmtp:account Default not found:no configuration file available
Error sending message, child exited 78 ().
Could not send the message.
Through to MSMTP we understand that in the practical apt-get installation of MSMTP, Its configuration file is called by default in the current user's home directory under the. MSMTPRC, although we created it under Ubuntu user. MSMTPRC but Zabbix directory does not have this file, so Zabbix still can not be practical msmtp.
here's how to fix it:
sudo Mkdir/home/zabbix
sudo chown zabbix.zabbix-r/home/zabbix
sudo vim/etc/passwd
Change the/var/lib/zabbix of Zabbix to/home/zabbix
sudo CP/HOME/UBUNTU/.MSMTPRC/HOME/ZABBIX/.MSMTPRC
Chown ZABBIX.ZABBIX/HOME/ZABBIX/.MSMTPRC
chmod 600/HOME/ZABBIX/.MSMTPRC
execute the test script again through Zabbix user, success!
Setup and elimination of "Zabbix series" Alarm system