I believe that the main purpose of the use of Zabbix is to be monitored when the machine fails, can be Zabbix to get the first time alarm alert. Zabbix commonly used alarm media has email, SMS, Jabber and scripts, which script type is the most flexible, especially when the mail server, SMS server is not the same server with Zabbix server, the custom script basically become our only reliable way.
In this article, we will install the mail client on the Zabbix server, and script the alarm information sent out through the mail, if you want to do SMS reminders, reminders, the technical path is the same.
Installing MSMTP
MSMTP is an SMTP client that can send mail to the SMTP server with an official website address of http://msmtp.sourceforge.net/index.html.
- Download and install MSMTP
cd/usr/local/srcwget http://sourceforge.net/projects/msmtp/files/msmtp/1.4.32/ Msmtp-1.4.32.tar.bz2/downloadtar jxvf msmtp-1.4. . Tar . BZ2CD msmtp-1.4. + . /configure--prefix=/usr/local/msmtpmake make andinstall
mkdir –p/usr/local/msmtp/etcvi /usr/local/msmtp/etc/msmtprc# Add the following: account default Host SMTP. 163 . com - from [email protected] 163 . com Login TLS offuser xxx password xxx /var/log/mmlog
chmod 777/var/log/mmlog
/USR/LOCAL/MSMTP/BIN/MSMTP [email protected]163cat /usr/local/msmtp/Msmtp.log # Check the 163 mailbox to see if the letter is received.
Installing Mutt
Mutt is an email client, it can not send mail directly, more is to undertake the management of the email function, and msmtp can be used with. Its official address is: http://www.mutt.org/
To find out more about Mutt and MSMTP, see the following address: Http://msmtp.sourceforge.net/doc/msmtp.html#Using-msmtp-with-Mutt
- Download and install Mutt
cd/usr/local/srcwgetFTP://ftp.mutt.org/pub/mutt/mutt-1.5.24.tar.gz tar xvf mutt-1.5. A. Tar . GZCD Mutt-1.5. - . /configure–prefix=/usr/local/Muttmake doinstall
vi /usr/local/mutt/etc/muttrc# Add the following lines at the end: Set sendmail="/usr/local/msmtp/bin/msmtp "set Use_from=yesset realname="xxx"set from [Email protected] 163 . Comset Envelope_from=yes
Echo " Hello,world " " Test Mail " [Email protected] 163 . com# the above statement will send a message titled "Test Mail" with the content "Hello,world" and the recipient [email protected] to check if the mailbox can receive mail
Now that the mail client has been configured, how does Zabbix send the alarm message to mutt? We only need to write the following script:
cd/usr/local/zabbix/share/zabbix/alertscriptsTouch notification. SH chmod +x notification. SH VI Notification. SH #添加如下内容 #!/bin/bashecho "$3"| /usr/local/mutt/bin/mutt-s "$2" $1
Where $ $ is the recipient address for Zabbix, which is the message header, and $ $ for the message content.
and the above path/usr/local/zabbix/share/zabbix/alertscripts is the default Zabbix script call path, when there is alarm information, Zabbix will find and invoke the specified script under the path, such as our custom notification.sh script.
In the next article, we will show you how to complete the alarm alert process setup in the Zabbix server interface.
[Original] Zabbix learning Journey four: Mail client Installation