(3) add mail alarm configuration and mail alarm Configuration

Source: Internet
Author: User

(3) add mail alarm configuration and mail alarm Configuration

Everyone should be mentally focused. monitoring is not just to check the server status. Although it is also one of the purposes of monitoring, it is definitely not all. The purpose of monitoring is definitely to give early warnings, even if an alarm occurs, zabbix also supports alarm rules. Now we will introduce the traditional email alarm addition. The alarm will be introduced later.


Add email alert configuration:

The principle of zabbix mail alarm is actually to call the script, and then the script sends an email via the mail function. The alarm described later is also done through the script call interface.

Therefore, the key to alarm is the script. In fact, many articles have written the zabbix email alarm function and many scripts can be referenced, but most versions are old and not necessarily applicable, next let's take a look at the script.

Traditionally, most of the monitored servers are linux systems, so almost all of them were bash shells. Now python scripts are available, which is quite convenient to use. Let's give a rough look at the traditional methods, next we will focus on the python script:

12345678910111213 # Download related software firstyum install -y sendmail postfix mailx# Test whether email can be sentecho "zabbix test mail" |mail -s "zabbix" 2XXXXXXX@qq.com# Compile scriptsvim sendmail.sh#!/bin/bash#echo "$3" | mail -s "$2" $1messages=`echo $3 | tr '\r\n' '\n'`subject=`echo $2 | tr '\r\n' '\n'`echo "${messages}" | mail -s "${subject}" $1 >>/tmp/sendmail.log 2>&1# Testbash sendmail.sh 2XXXXXXX@qq.com zabbix fuckyou

Next we will look at the python script.

Email script:

Before using python, you must install python first, and then the relevant Runtime Library smtplib. python's smtplib provides a very convenient way to send emails. It encapsulates the smtp protocol.

12345678910111213141516171819202122232425262728293031323334 vim sendmail2.py#!/usr/bin/python#coding:utf-8import smtplibfrom email.mime.text import MIMETextimport sys# configure your own parameters here# Smtp address of the following email addressmail_host = 'smtp.exmail.qq.com'# The email address used for sending emails is displayed in the sender's header (otherwise, your emails will be treated as spam emails)mail_user = 'XXX@qq.com'# Password of the email abovemail_pass = 'XXXXX'# Master website address of the smtp address abovemail_postfix = 'exmail.qq.com'def send_mail(to_list,subject,content):    me = mail_user+"<"+mail_user+"@"+mail_postfix+">"    msg = MIMEText(content, 'plain''utf-8')    # The 'utf-8' parameter must be used. Otherwise, the default value is us-ascii. garbled characters are displayed in Chinese on some mail clients.    msg['Subject'= subject    msg['From'= me    msg['to'= to_list    try:        = smtplib.SMTP()        s.connect(mail_host)        s.login(mail_user,mail_pass)        s.sendmail(me,to_list,msg.as_string())        s.close()        return True    except Exception,e:        print str(e)        return Falseif __name__ == "__main__":    send_mail(sys.argv[1], sys.argv[2], sys.argv[3])

This script mainly changes four items:

# Smtp address of the following email address
Mail_host = 'smtp .exmail.qq.com'
# The email address used for sending emails is displayed in the sender's header (otherwise, your emails will be treated as spam emails)
Mail_user = 'xxx @ qq.com'
# Password of the email above
Mail_pass = 'xxxxx'
# Master website address of the smtp address above
Mail_postfix = 'exmail .qq.com'

This script requires three parameters to be input for the operation. Just separate them with spaces.

The first is the email address to be sent,

The second is the mail title,

The third is the email content.

It can be used after modification. Please try:

Python sendmail2.py 2XXXXXXX@qq.com test 'ha ha Ha'

The email is complete.

Check the zabbix_server script location:

12 cat /usr/local/zabbix/etc/zabbix_server.conf |grep AlertScriptsPath=AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts

This directory is where the email script is stored. If you haven't set it before, restart zabbix_server after setting it.

In zabbix_web settings:

After the script is ready, you have to go to the web to set the alarm calling rules. It depends on the illustration (very troublesome...). I won't talk about how to log on.

: Click Manage-alarm media type-create media type

Then enter:

Name: What do you like

Type: script

Script Name: The name of your script. The name I just changed is sendmail2.py.

Script parameter: {ALERT. SENDTO}, {ALERT. SUBJECT}, {ALERT. MESSAGE} (required. You do not need to modify the three parameters), which are the three parameters required by the script: Recipient address, topic, and details, it is the three parameters of the test script.

Ps: After zabbix3.X is installed by many people, the scripts written cannot be sent successfully, but can be executed manually. This is because after Zabbix3.X, you can customize parameters, so if you do not write a parameter, it will not pass the parameter. This problem does not exist in 2.x. By default, three parameters are passed.

The alarm type has been created. Of course, you need to set the recipient, and then:

Click Manage-user-User Name

If you want to create a username independently, you can directly use admin

After entering the user interface, click <alarm media>-<add>

Add the address for receiving alarms. A box is displayed.

This box is where the email address is added:

Type: select the one you just created in <alert media type>. Here is pymail.

Recipient: your email address

When enabled: it is the validity period of email receiving. Adjust it if the email is harassed too frequently.

Click <add> to save the remaining two items.

Then, the page is displayed and you can click <Update>.

Finally, create an alarm action to trigger the alarm:

Click Configure-action-create action (Note: trigger)

Next, go to another interface. Here we will focus on the second page <operations>. The <action> On the first page is just to change the name, and then let's look at the example in the next figure.


Note that this is a modified information example. Unlike the default one, it is more intuitive and easier to read than the default one,

Default operation step Duration: adjusted as needed, not described in detail

Default recipient: it is actually the alarm title, which is set:

Fault {TRIGGER. STATUS}, server: {HOST. NAME1} occurred: {TRIGGER. NAME} fault !.

The default information is the alarm content, which is set:

Alert HOST: {HOST. NAME1}
Alert TIME: {EVENT. DATE} {EVENT. TIME}
Alert Level: {TRIGGER. SEVERITY}
Alert Information: {TRIGGER. NAME}
Alert item: {TRIGGER. KEY1}
Problem details: {ITEM. NAME}: The VALUE is {ITEM. VALUE}
Current STATUS: {TRIGGER. STATUS }:{ ITEM. VALUE1}
Event id: {EVENT. ID}

Then, the following dialog box is displayed by clicking the <action> <New> dialog box <Operation Details> below,

The main task is to select the group and user to be sent. The email address we just set is in admin, so here we set the user group and user admin of zabbix admin, then <send only> set it to the name pymail of <alarm media>.

Next to the top <operation> button <recovery operation>, it is basically the same as the <operation> button.

Similar to the above, the default receiver and default information are slightly different.

Default recipient: Recovery title:

{TRIGGER. STATUS }:{ TRIGGER. NAME} restored {TRIGGER. STATUS}, server: {HOSTNAME1 }:{ TRIGGER. NAME} recovered!

Default information: Recovery content:

Alert HOST: {HOST. NAME1}
Alert TIME: {EVENT. DATE} {EVENT. TIME}
Alert Level: {TRIGGER. SEVERITY}
Alert Information: {TRIGGER. NAME}
Alert item: {TRIGGER. KEY1}
Problem details: {ITEM. NAME}: The VALUE is {ITEM. VALUE}
Current STATUS: {TRIGGER. STATUS }:{ ITEM. VALUE1}
Event id: {EVENT. ID}

Now, the alarm settings are complete. Next, let's test and stop the zabbix_agent of the client. However, the alarm takes 5 minutes. You can also set other parameters, this is a step-by-step exploration.

Source: http://blog.51cto.com/arthur376/1878237

View comments

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.