Zabbix Detailed: (c) Add mail alarm configuration

Source: Internet
Author: User

Everyone should be psychological bottom, do not monitor only to see the state of the server, although that is also one of the purposes of monitoring, but definitely not all, we do the purpose of monitoring is sure to want to alert, or even a problem on the alarm, there is no doubt Zabbix is also supporting the alarm rules, now to introduce the traditional add mail alarm, Alarms are also described later.


To add a message alert configuration :

About the principle of Zabbix mail alarm, is actually called the script, and then the script through the mail function to send outgoing mail, the following alarm is also called through the script interface to do.

Therefore, the key to the alarm, is the script, in fact, Zabbix mail alarm This feature many articles have written, there are many scripts can be consulted, but most of the version is older, not necessarily applicable, the following first to look at the script.

Traditionally, most of the servers monitored were Linux systems, so it was almost always a bash shell, and now Python scripts are available, and it's easy to use, roughly speaking the traditional way, followed by the Python script to explain:

#先下载相关软件yum install-y sendmail postfix mailx# test can email echo "Zabbix test Mail" |mail-s "Zabbix" [email protected] #编写脚本vim s Endmail.sh#!/bin/bash#echo "$" | Mail-s "$" $1messages= ' echo $ | Tr ' \ r \ n ' \ n ' subject= ' echo | Tr ' \ r \ n ' \ n ' echo ' ${messages} ' | Mail-s "${subject}" >>/tmp/sendmail.log 2>&1# test bash sendmail.sh [email protected] Zabbix fuckyou

Let's look at the python script below.

Script to send mail:

Before using, of course, to install Python first, then the relevant runtime Smtplib,python Smtplib provides a convenient way to send e-mail. It provides a simple encapsulation of the SMTP protocol.

Vim sendmail2.py#!/usr/bin/python#coding:utf-8import smtplibfrom email.mime.text import  mimetextimport sys# configure your own parameters here# the SMTP address of the mail address below Mail_ host =  ' smtp.exmail.qq.com ' #用来发邮件的邮箱, the sender looks up (otherwise your email will be treated as spam) mail_user =  ' [email  Protected] ' #上面邮箱的密码mail_pass  =  ' XXXXX ' #上面smtp地址的主网站地址mail_postfix  =  ' exmail.qq.com ' def  send_mail (to_list,subject,content):     me = mail_user+ "<" +mail_user+ "@" +mail_postfix+ ">"     msg = mimetext (content,  ' plain ',  ' utf-8 ')     #  must use ' utf-8 ' parameter, otherwise the default is us-ascii,  in some mail client Chinese will be displayed as garbled     msg[' Subject '] = subject    msg[' from '] = me    msg[' to '] = to_list    try:        s =  smtplib. SMTP ()  &nbsP;      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 4 items:

#下面邮件地址的smtp地址
Mail_host = ' smtp.exmail.qq.com '
#用来发邮件的邮箱, the sender looks up (otherwise your email will be treated as spam)
Mail_user = ' [email protected] '
#上面邮箱的密码
Mail_pass = ' XXXXX '
#上面smtp地址的主网站地址
Mail_postfix = ' exmail.qq.com '

This script needs to input three parameters to operate, the space separates is good

The first one is the e-mail address to send,

The second one is the message header,

The third one is the message content

You can use it after you change it, try it:

Python sendmail2.py [email protected] test ' ha ha ha '

The message was received and finished.

Confirm the location of the Zabbix_server script:

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, and if you haven't set it up before, restart Zabbix_server when you're done.

In Zabbix_web settings:

The script is ready to go to the web to set the alarm call rules, to see the diagram (very troublesome ah ...), how to login I will not say.

: Click Manage-Alarm Media type-Create media type

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/8A/E6/wKiom1g-hWqwWU_3AACNPk0FSG8365.png "style=" float: none; "title=" 1.png "alt=" Wkiom1g-hwqwwu_3aacnpk0fsg8365.png "/>

Then enter:

Name: What you like is what

Type: Script

Script Name: Just the name of your script, and the name I just changed is sendmail2.py.

Script parameters: {ALERT. SENDTO}, {ALERT. SUBJECT}, {ALERT. MESSAGE} (required, just three, do not change), for the script requires 3 parameters: the recipient address, subject, details, is the test script of the three parameters.

PS: Many people install zabbix3. After x, the script written has been sent unsuccessfully, and can be executed manually. This is because after the zabbix3.x, you can customize the parameters, so do not write parameters it will not pass parameters. This problem does not exist in version 2.x, which will pass 3 parameters by default.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/8A/E2/wKioL1g-hWrCliIFAABOrgiiHM8376.png "style=" float: none; "title=" 2.png "alt=" Wkiol1g-hwrcliifaaborgiihm8376.png "/>

The alarm type was created, and of course the recipient was set, and then it was:

Click Manage-User-user name

If you want to create a user name independently, but I do not want to be so troublesome, directly with the admin

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/8A/E3/wKioL1g-jBbhFXDxAABnIbuWBD8694.png "style=" float: none; "title=" 3.png "alt=" Wkiol1g-jbbhfxdxaabnibuwbd8694.png "/>

After entering the user interface to click < Alarm media >-< add >

is to add the address to receive the alarm, a box will pop up.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/8A/E7/wKiom1g-jBawkLQwAABOuV5V5PI436.png "style=" float: none; "title=" 4.png "alt=" Wkiom1g-jbawklqwaabouv5v5pi436.png "/>

This box is where you add your email address:

Type: Select you just in < alarm media type > created, here I am pymail

Recipient: Your e-mail address

When enabled: is the time to receive mail, feel harassed too often adjust it

Below two no tube, click < add > can be engraved

Then it will return to the interface, click < Update > on it.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/8A/E3/wKioL1g-jBeRWnFrAABg5f0Y6NM616.png "style=" float: none; "title=" 5.png "alt=" Wkiol1g-jberwnfraabg5f0y6nm616.png "/>

Finally, create an alarm action to let the alarm move up:

Click Configure-action-Create action (note is trigger)

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/8A/E3/wKioL1g-j77BqJMWAACAw00g8w4384.png "style=" float: none; "title=" 6.png "alt=" Wkiol1g-j77bqjmwaacaw00g8w4384.png "/>

Then go to another interface, where the focus is on page two < operations > there, the < action on the first page > just change the name and look at the example of the next image

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/8A/E3/wKioL1g-j76QvSe8AABbcLAWBzY313.png "style=" float: none; "title=" 7.png "alt=" Wkiol1g-j76qvse8aabbclawbzy313.png "/>

Note that this is a modified information case, and unlike the default, he is more intuitive and easier to read than the default,

Default Action Step Duration: On-demand adjustment, not detailed description

Default receiver: In fact, it is the alarm title, set here:

Fault {TRIGGER. STATUS}, Server: {HOST. NAME1} occurred: {Trigger.name} failed!.

Default information: Is the alarm content, here set to:

Alarm Host: {host. NAME1}
Alarm time: {EVENT. DATE} {EVENT. TIME}
Alarm level: {TRIGGER. SEVERITY}
Warning message: {trigger.name}
Alarm 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 box is clicked by clicking on the following < actions > inside < new > box < operation details;

Mainly is the choice needs to send the group and the user, just now we set the email address is in the admin's, then here is set obviously is the Zabbix Admin user group and the user admin, then < sends only to > to set to the < alarm medium > Name pymail.

Then, at the top < operation > Next door < Recovery action > there, roughly and < operation > consistent, here is not detail, everyone directly look at the picture.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/8A/E7/wKiom1g-kUPimG_8AADIPXQQAyU886.png "title=" 8.png " alt= "Wkiom1g-kupimg_8aadipxqqayu886.png"/>

Similar to the above, mainly is the default receiver and the default information has a small difference

Default recipient: restored title:

{TRIGGER. STATUS}: {trigger.name} recovery {TRIGGER. STATUS}, server: {HOSTNAME1}: {trigger.name} restored!

Default information: Restore content:

Alarm Host: {host. NAME1}
Alarm time: {EVENT. DATE} {EVENT. TIME}
Alarm level: {TRIGGER. SEVERITY}
Warning message: {trigger.name}
Alarm item: {TRIGGER. KEY1}
Problem details: {item.name}: The value is {ITEM. VALUE}
Current status: {TRIGGER. Status}:{item. VALUE1}
Event Id:{event.id}

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/8A/E3/wKioL1g-mRDR3RGTAACdCpyWRN0375.png "title=" 9.png " alt= "Wkiol1g-mrdr3rgtaacdcpywrn0375.png"/>

Here, the alarm setup is complete, and then the following to test, the client's zabbix_agent stop to see, but the time is longer, to 5 minutes before the alarm, you can set other parameters, this on their own slowly groping.

Zabbix Detailed: (c) Add mail alarm configuration

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.