Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Zabbix3.2.1 email alarm

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

zabbix monitoring server and client have been deployed, monitored hosts have been added, and Zabiix monitoring is running normally.

Set email alarm on Zabbix server. When monitored host is down or trigger preset value is reached, alarm email will be automatically sent to specified mailbox.

Specific operation:

The following operations are performed on the Zabbix monitoring server

Then install those two dependencies, the command is:

yum install perl-Net-SSLeay perl-IO-Socket-SSL -y

Extract the software, copy sendemail to/usr/local/bin/, add executable permissions, and modify users and groups.

[root@mysqla ~]# tar zxf sendEmail-v1.56.tar.gz

[root@mysqla ~]# cd sendEmail-v1.56/

[root@mysqla sendEmail-v1.56]# cp sendEmail /usr/local/bin/sendEmail

[root@mysqla sendEmail-v1.56]# chown zabbix:zabbix /usr/local/bin/sendEmail

[root@mysqla sendEmail-v1.56]# ll /usr/local/bin/sendEmail

-rwxr-xr-x. 1 zabbix zabbix 80213 Nov 21 21:26 /usr/local/bin/sendEmail

Run # /usr/local/bin/sendEmail -h to see help for sendEmail

#/usr/local/bin/sendEmail -f bpcyh2@126.com -t bpcyh2@126.com -s smtp.126.com -u "hello" -o message-content-type=html -o message-charset=utf8 -xu bpcyh2@126.com -xp 123abc -m "abcfdd"

Command Main Options Description:

/usr/local/bin/sendEmail #Command main program

-f from@126.com #sender mailbox

-t to@126.com #recipient mailbox

-s smtp.126.com #smtp server for sender mailbox

-u "I am the subject of the message" #The subject of the message

-o message-content-type=html #Format of the message content,html means it is html format

-o message-charset=utf8 #Message content encoding

-xu from@126.com #username of sender mailbox

-xp WEE78@12l$ #sender email password

-m "I am the content of the message" #The specific content of the message

Go to/usr/local/zabbix/share/zabbix/alertscripts/directory

Then create the alarm script sendmail.sh in this directory

[root@mysqla alertscripts]# vi mail.sh

Here's what the script looks like (colored parts are your email and password, -f and-xu parameters followed by email, -xp followed by authorization code)

#!/ bin/bash

to=$1

subject=$2

body=$3

/usr/local/bin/sendEmail -o tls=auto -f bpcyh2@126.com -t "$to" -s smtp.126.com -u "$subject" -o message-content-type=html -o message-charset=utf8 -xu bpcyh2@126.com -xp 123abc -m "$body"

[root@mysqla alertscripts]# chmod +x mail.sh

Execute Script Test Send Email

[root@mysqla alertscripts]# ./ mail.sh bpcyh2@126.com test 123

*******************************************************************

Using the default of SSL_verify_mode of SSL_VERIFY_NONE for client

is deprecated! Please set SSL_verify_mode to SSL_VERIFY_PEER

together with SSL_ca_file|SSL_ca_path for verification.

If you really don't want to verify the certificate and keep the

connection open to Man-In-The-Middle attacks please set

SSL_verify_mode explicitly to SSL_VERIFY_NONE in your application.

*******************************************************************

at /usr/local/bin/sendEmail line 1906.

invalid SSL_version specified at /usr/share/perl5/vendor_perl/IO/Socket/SSL.pm line 415

Note: The first error occurred during the Send Mail test

The reason is that the ssl version of senemail software is incompatible with perl5. This problem can be solved by modifying the contents of senemail.

Solution:

The contents of line 1906 in senemail, from

if (! IO::Socket::SSL->start_SSL($SERVER, SSL_version => 'SSLv3 TLSv1')) {

modified to

if (! IO::Socket::SSL->start_SSL($SERVER)) {

That is, do not specify the SSL version, let the program choose its own

Whether you use 163/126 mailbox or qq mailbox, you must open pop3 service, and 126/qq mailbox also requires the use of third-party clients to send mail is to use authorization code login, use account password verification, there will be the following picture error.

sendEmail[5102]: ERROR => ERROR => SMTP-AUTH: Authentication to smtp.126.com:25 failed.

As for the authorization code of the mailbox, log in to the mailbox 126 to set it up.

After processing the above two problems, you can send emails normally as shown below.

[root@mysqla alertscripts]# ./ mail.sh bpcyh2@126.com test 123

Nov 21 22:50:47 mysqla sendEmail[5195]: Email was sent successfully!

zabbix web-side configuration

After configuring the email script above, you need to add alarm media on the web side. In the web page Management, Alarm Media Type page, click Create Media Type on the right.

Enter the Create page, enter the name "Mail Alert Script," select the script type, select mail.sh as the name, click Add button, and add three script parameters,{ALERT.SENDTO},{ALERT.SUBJECT},{ALERT.MESAGE}, for to, subject and body in mail.sh respectively. After adding, click the Add button below, and our alarm media will be created.

Once the alert medium is created, we need to associate the alert medium with our users. Click Manage, User, and then select our User admin. You can also create a new user. Click on the user name to enter the user configuration interface. Click the alarm medium, then click Add, select the email alarm script we created in the previous step, enter the recipient, select the alarm time and type, and then click Add to associate the created alarm medium with our user.

What we need to do now is create a trigger action that triggers when the system fails, and then send an alert email to our mailbox. Click Configure, select Action, and then click Create Action on the right.

Write the action name and trigger condition we defined in the action name page

Set "Action"

Steps 1-3, i.e. starting with 1 and ending with 3. Once a failure occurs, the Email.sh script is executed to generate an alarm email to zabbix users.

If the failure lasts for 1 hour, it will only send 3 times, and the first 3 times (i.e., the first 3 times) will be sent to zabbix users, and the time interval is 0 seconds.

If changed to 1-0, 0 means no limit. Send Unlimited

Set "Recovery Action"

After adding it, you can see the name of the action we added and the status of the action enabled.

Check if status is displayed to enable

In the action log, you can see the sending status, indicating that it has been delivered, and you can.

alarm test

Close the zabbix_agent process on server 192.168.129.88.

It is found that the failure alarm email can be received normally

Finally, click "Report"->"Action Log" to see the number of times the action was triggered (on the right, you can also see the email sending status "Sent").

----------------------------------------------------------------------------------------------

Today's movie "Godfather I II III"

A great man is not born great, but grows great.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 240

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report