Prerequisites:
(1) The zabbix server has been successfully installed and run.
(2) The zabbix client has been successfully created and runs.
1. Download and install msmtp Software
WgetHttp://sourceforge.net/projects/msmtp/files/msmtp/1.4.32/msmtp-1.4.32.tar.bz2/download
Tar jxvf msmtp-1.4.32.tar.bz2
Cd msmtp-1.4.32
./Configure -- prefix =/usr/local/msmtp
Make
Make install
2. manually create a configuration file and enter an external smtp address
Mkdir-p/usr/local/msmtp/etc
Vi/usr/local/msmtp/etc/msmtprc
Add the following content
Account default
Host smtp.sohu.com # Your Email sending server
Port 25
From zabbix2014@sohu.com # from which mailbox
Auth login
Tls off
User zabbix2014 # email user name
Password xxxxx-xxx # email password. If you feel insecure, you can change the file to the 600 attribute.
Logfile/var/log/mmlog
Save and exit.
3. perform a simple test.
/Usr/local/msmtp/bin/msmtp zabbix2014@sohu.com
Hello, test
Ctrl d
Cat/usr/local/msmtp. log to check whether the operation is successful.
Then go to sohu's mailbox to see if the email has been received
The following error is reported:
[Root @ cache-2 msmtp-1.4.32] #/usr/local/msmtp/bin/msmtp zabbix2014@sohu.com
Msmtp: authentication failed (method LOGIN)
Msmtp: server message: 535 5.7.0 Invalid result
Msmtp: cocould not send mail (account default from/usr/local/msmtp/etc/msmtprc)
Install the mutt component after Google
4. Install MUTT below. If it is CentOS, use yum directly.
Yum install mutt
After the installation is complete, manually create a configuration file for him,
Vim/etc/Muttrc
Setsendmail = "/usr/local/msmtp/bin/msmtp" # Your msmtp command path
Set use_from = yes
Set realname = "zabbix2014@sohu.com"
Set editor = "vim"
Just four simple lines.
Okay. Let's test it!
Test: echo "test mail" | mutt-s "test" zabbix2014@sohu.com
OK. After testing, you can receive the email you have sent, as shown below:
Echo "test mail 2014 content tom 2" | mutt-s "test 2014 title2" zabbix2014@sohu.com
5. Create a zabbix script for sending emails.
Place the script anywhere, but make sure zabbix can be found!
1) vim/usr/bin/zabbix2014 and write the following content:
#! /Bin/bash
Echo "$3" | mutt-s "$2" $1 #$3 indicates the mail content, $2 indicates the mail title, and $1 indicates the recipient
(2) chmod a + x/usr/bin/zabbix2014
6. zabbix Configuration
(1) Create meida types
1. log on to zabbix, go to "Administration"> "Media types", and click "Create Media Type" in the upper right corner ". Enter "mediatype-zabbix2014" or another name for Description, select "Script" for Type, and enter "zabbix2014" for "Script ".
2. Click save to save, as shown in:
7. Create actions
1. log on to zabbix, go to "Configation"> "Actions", and click "Create Actions" in the upper right corner ". Enter Name "action-zabbix2014", others click the "New" button under "Action Operations" by default, "Operation Type" select "Send message ", "Send Message to" select one or more user groups to Send messages, "Send only to" select the mediatype-zabbix2014 we added earlier.
2. Click save to save, as shown in:
8. zabbix User Configuration
Log on to zabbix and go to "Adimistration"> "Users". Select a user in the Members column of the group in which the message is to be sent, for example, AdminZabbix.
Click "Add" at the bottom of the "Media" section of the User Information Modification interface.
Select "mediatype-zabbix2014" for Type, set "Send to" to the recipient address, and click "Add.
Click "Save" to Save the configuration. As shown in:
9. test and verify whether the mail sending function is normal.
PS: the implementation of this verification alert, please refer to the http://blog.csdn.net/mchdba/article/details/24540017 that describes how mysql. ping_test is established and effective.
9.1 go to the mysql service on the stop server, and an alarm will be triggered later.
[Root @ db-m2-slave-1 ~] # Service mysql stop
Shutting downMySQL... [OK]
[Root @ db-m2-slave-1 ~] #
But we didn't receive an email, so we need to check the events to see if there is any prompt why the email cannot be sent. Go to the directoryMonitoring-> EventsGroup (select All) Host (select the database Host to be monitored) Source (select Trigger ).
Open the link in the leftmost column 02 May 2014 12:34:06,
See the prompt:
/Usr/local/zabbix/scripts/zabbix2014: [2] Nosuch file or directory
Remember to place the script in/usr/bin/zabbix2014. Therefore, place the script in the directory required by the prompt and directly perform the mv:
Mv/usr/bin/zabbix2014/usr/local/zabbix/scripts/zabbix2014
Then you will see the new alarm PROBLEM information. The email has been sent out, for example:
9.2 Change the email address to 139 mailbox, and implement the free SMS alarm function.
Go to the directory,AdministrationUsers Zabbix administrators Users (1) AdminZabbix (leftmost column) Media (select the middle column)-> mediatype-zabbix2014 (select mediatype used by Trigger) Edit (click to modify) send to (enter 139 email in the input box, such as xxx@139.com), as shown in ::
9.3 switch to 139 mailbox to verify the SMS sending Function
Register your 139 email address, open email, stop, and start mysql process services on the database, and you will receive an alarm email and Text Message notification. The alarm email is as follows:
Remember to enable the SMS prompt function. SMS is free of charge.
9.4 how to enable zabbix to continue sending alarm information until it returns to normal.
Go to the directory and check the host TriggerName (for example, check_mysql_status) in the Multiple PROBLEM events generation column to Save. As shown in:
10 conclusion:
For the first time, zabbix's email alarm experiment was successful. After a great deal of time, I also consulted many friends. I would like to thank them. Below are a lot of in-depth things about zabbix that need to be further studied.
And work hard.
References:Http://bbs.hx95.com/read-htm-tid-181423.html
Attach the suggestion of Beijing soy sauce emperor, how to verify trigger alarm success:
It is easy to verify the validity of a trigger:
FirstTrigger has an events option on the monitor interface. You can click the ip address of the machine to see if the trigger you have defined has occurred.
Second,Second, if a trigger occurs, check whether the script or media call is successful. If yes, add logs to the script.