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

Zabbix Monitoring client and realizing email and Wechat alarm

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Blog outline:

First, install Zabbix agent terminal

Log in to the web interface to add an agent host

3. Zabbix monitors MySQL database

4. Configure mail alarm

Configure WeCom to report to the police

Note: this article is based on the blog post: the environment in which the zabbix monitoring server is deployed.

All the software used in this blog post is available on this link: Zabbix package

First, install Zabbix agent terminal

Here I started a server with an IP of 192.168.20.3 to act as an agent.

[root@agent ~] # tar zxf zabbix-3.2.1.tar.gz-C / usr/src/ [root@agent ~] # cd / usr/src/zabbix-3.2.1/ [root@agent zabbix-3.2.1] #. / configure-- prefix=/usr/local/zabbix-- enable-agent & & make & & make install [root@agent zabbix-3.2.1] # useradd zabbix- M-s / sbin/nologin # modify the startup script [root@agent Zabbix-3.2.1] # cp misc/init.d/fedora/core/zabbix_agentd / etc/init.d/ [root@agent ~] # sed-I sed Baseir =\ / usr\ / local/BASEDIR=\ / usr\ / local\ / zabbix/g' / etc/init.d/zabbix_agentd [root@agent ~] # sed-I's zabbix/g' =\ / tmp\ / $BINARY_NAME.pid/PIDFILE=$BASEDIR\ / logs\ / $BINARY_NAME.pid/g' / etc/init. D/zabbix_agentd [root@agent ~] # chmod + x/etc/ init.d/zabbix_agentd# modify the configuration file [root@agent ~] # cd / usr/local/zabbix/etc/ [root@agent etc] # sed-I usr # PidFile=\ / tmp\ / zabbix_agentd.pid/PidFile=\ / local\ / zabbix\ / logs\ / zabbix_agentd.pid/g' zabbix_ agentd.confession [root @ agent etc] # sed-I's password LogFile =\ / tmp\ / zabbix_agentd.log/LogFile=\ / usr\ / local\ / zabbix\ / logs\ / zabbix_agentd.log/g' zabbix_ agentd.confession [root @ agent etc] # sed-I 's/ServerActive=127.0.0.1/ServerActive=192.168 zabbix_ agentd.confession [root @ agent etc] # sed-I' s/ServerActive=127.0.0.1/ServerActive=192.168 .20.2 / g 'zabbix_ agentd.confession [root @ agent etc] # sed-I' s/Hostname=Zabbix server/Hostname=192.168.20.3/g' zabbix_ agentd.confession [root @ agent etc] # Timeout=3/Timeout=15/g' zabbix_ agentd.confession [root @ agent etc] # sed-I 'agentd.confession # Include=\ / usr\ / local\ / etc\ / zabbix_agentd.conf.d\ / Include=\ / usr\ / zabbix\ / etc\ / zabbix _ agentd.conf.d\ / / g 'zabbix_ agentd.confession [root @ agent etc] # egrep-v' ^ $| ^ # 'zabbix_agentd.conf # confirm the changed configuration file PidFile=/usr/local/zabbix/logs/zabbix_agentd.pidLogFile=/usr/local/zabbix/logs/zabbix_agentd.logServer=192.168.20.2ListenPort=10050ServerActive=192.168.20.2Hostname=192.168.20.3Timeout=15Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/ [root @ agent etc] # mkdir / usr / local/zabbix/logs [root@agent etc] # chown-R zabbix:zabbix / usr/local/zabbix/ [root@agent etc] # / etc/init.d/zabbix_agentd start # launch agent II, Log in to the web interface to add an agent host

Log in to the Zabbix server side and do the following to monitor the Agent side that you just configured.

3. Zabbix monitors MySQL database

The following is done on the MySQL side of the new configuration (deploy the MySQL database yourself, and there is a scripted way to install the server database in the link at the beginning of the blog post).

# copy the MySQL monitoring script [root@agent etc] # cd / usr/src/zabbix-3.2.1/conf/zabbix_agentd/ [root @ agent zabbix_agentd] # cp userparameter_mysql.conf / usr/local/zabbix/etc/zabbix_agentd.conf.d/ [root @ agent zabbix_agentd] # cd / usr/local/zabbix/etc/# provided by Zabbix The account [root@agent etc] # cat > .my.cnf [client] > host=192.168.20.3 > user=test > password=123.com > socket=/usr/local/mysql/mysql.sock > EOF# modifies the MySQL monitoring script [root@agent ~] # cd / usr/local/zabbix/etc/zabbix_agentd.conf.d [root@agent zabbix_agentd.conf.d] # sed-I 's/mysql-N /\ / usr\ / local\ / bin\ / mysql-N / g 'userparameter_mysql.conf [root@agent zabbix_agentd.conf.d] # sed-I' s/mysql-V /\ / usr\ / local\ / bin\ / mysql-V root@agent zabbix_agentd.conf.d g'userparameter_mysql.conf [root@agent zabbix_agentd.conf.d] # sed-I 's/mysqladmin ping/\ / usr\ / local\ / bin\ / mysqladmin ping/g' userparameter_mysql.conf [root@agent zabbix_agentd.conf.d] # sed-I' s Universe Home =\ / var\ / lib\ / zabbix/HOME=\ / usr\ / local\ / zabbix\ / etc\ / g 'userparameter_mysql.conf # restart the agent service Make the change effective [root@agent zabbix_agentd.conf.d] # / etc/init.d/zabbix_agentd restart# authorization database user [root@agent ~] # mysql-uroot-p123 mysql > grant all on *. * to test@'192.168.20.%' identified by '123.comm' The Zabbix-servre side tests whether the MySQL status of the server can be collected: [root@zabbix logs] # zabbix_get-s 192.168.20.3-p 10050-k "mysql.status [Uptime]" 728# the number that can be seen when executing the above command on the server side is the status related to the database

Go back to the web page of Zabbix and add the MySQL database monitoring template

Select the MySQL template:

Check the added MySQL monitoring information (if there is no information, you will need to wait a moment):

4. Configure mail alarm

All of the following actions need to be configured on the Zabbix server side

[root@zabbix] # yum-y install perl-Net-SSLeay perl-IO-Socket-SSL [root@zabbix ~] # tar zxf sendEmail-v1.56.tar.gz-C / usr/src/ [root@zabbix ~] # cp / usr/src/sendEmail-v1.56/sendEmail / usr/local/bin/ [root@zabbix ~] # chown zabbix:zabbix / usr/local/bin/sendEmail [root@zabbix ~] # vim / usr/local/bin/sendEmail if (! IO::Socket::SSL- > start_SSL ($SERVER) {# Jump to line 1906, modify as above, and then save exit

Before performing the next operation, you need to have the authorization code of your own mailbox. Here, take QQ (163or Sina) as an example.

Follow the prompts to send messages:

All you need is the following authorization code:

Write email alarm script on # Zabbix Server [root@zabbix alertscripts] # pwd # all scripts must be in this directory / usr/local/zabbix/share/zabbix/alertscripts [root@zabbix alertscripts] # vim SendEmail.sh # script is as follows: #! / bin/bashto=$1subject=$2body=$3/usr/local/bin/sendEmail-o tls=auto-f 916551516@qq.com-t "$to"-s smtp.qq.com-u "$subject"-o message-content-type=html-o message-charset=utf8 -xu 916551516@qq.com-xp xphunzguzeibdag-m "$body" # items are explained as follows: # / 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 of sender mailbox #-u "I am the subject of the message": message title #-o message-content-type=html: format of the message content Html indicates that it is in html format #-o message-charset=utf8: message content code #-xu from@126.com: user name of the sender's mailbox #-xp WEE78@12l$ # sender's mailbox authorization code (the authorization code I just generated) #-m "I am the content of the message": test whether the message can be sent successfully [root@zabbix alertscripts] # chmod + x SendEmail.sh # give script execution permission [root@zabbix logs] # sh SendEmail.sh 916551516@qq.com test 123456Nov 09 22:17:55 zabbix sendEmail [9970]: Email was sent successfully!

The email I received is as follows:

Go back to the web interface and add alarm media

Confirm that alarm media have been added:

Associate the alarm medium to the user

Create a trigger action

Set the restore Operation

Configure the actions to be taken when the failure recovers:

Configure trigger

Make sure you can see the trigger we configured:

Alarm test:

If the zabbix_agent process of the agent server is turned off, the mailbox can receive mail, which means that the configuration is correct.

# perform the following operations on the agent server [root@agent ~] # / etc/init.d/zabbix_agentd stop # close the agent process

At this point, you can receive the alarm email as follows:

Configure WeCom to report to the police

Search for WeCom on the web and log in to WeCom and register yourself, then do the following:

Create an application:

After the application is successfully created, the application information is displayed as follows:

Focus on recording the Agent and Secret of this application above for later configuration.

View enterprise ID, department ID, user account and other information:

Enterprise ID:

Department ID:

User account number:

The above information will be used in the future.

Get the Wechat alarm script on Zabbix server. [root@zabbix alertscripts] # pwd/usr/local/zabbix/share/zabbix/alertscripts [root@zabbix alertscripts] # wget https://www.ixdba.net/zabbix/weixin_linux_amd64# if the above address is invalid You can also obtain [root@zabbix alertscripts] # mv weixin_linux_amd64 weixin # change the name [root@zabbix alertscripts] # chmod 755 weixin # from the link at the beginning of the blog post and give the executive permission [root@zabbix alertscripts] # echo "AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts" > > / usr/local/zabbix/etc/zabbix_server.conf# to append the above to the Zabbix main configuration file # to test whether the script is available Execute the following command (the corresponding value needs to be modified): [root@zabbix alertscripts] #. / weixin-- corpid=ww829ec5c69739bbee-- corpsecret=n0CcdnCzqQHUlJSdPC8C_VDr4XXzizK2sjDMUkng0b0-- msg= "Wechat alarm Test"-- user=LvJianZhao-- agentid=1000004 {"errcode": 0, "errmsg": "ok", "invaliduser": ""} # what needs to be modified is as follows: # Enterprise ID in corpid= Enterprise account # corpsecret: here is the ID;# agentid of the Secret in our self-built application: the AgentId;# msg in our self-built application: the content of the message to be sent; # user: the user account to which we accept the message. Note that it is the account in the member details page of Wechat Enterprise account.

After the execution is completed, if there is no error, then we can receive the alarm message of this command on WeChat at work, as follows:

Log in to the web interface and create a Wechat alarm medium

Associate to the Zabbix administrative user:

Pay attention to the above recipient settings, this recipient is in the Wechat enterprise account backstage, the details of the members under the address book to see the account, be sure to write it wrong.

Confirm that the following has been added:

Configuration action

The above information can be copied from the following:

Server: {HOST.NAME} occurrence: {TRIGGER.NAME} Fault alarm Host: {HOST.NAME} alarm address: {HOST.IP} Monitoring Project: {ITEM.NAME} Monitoring value: {ITEM.LASTVALUE} alarm level: {TRIGGER.SEVERITY} current status: {TRIGGER.STATUS} alarm Information: {TRIGGER.NAME} alarm time: {EVENT.DATE} {EVENT.TIME} event ID: {EVENT.ID}

After adding, it is as follows:

Configure the restore operation:

The content added above can be copied from the following:

Server: {HOST.NAME}: {TRIGGER.NAME} failure restored alarm host: {HOST.NAME} alarm address: {HOST.IP} Monitoring Project: {ITEM.NAME} Monitoring value: {ITEM.LASTVALUE} alarm level: {TRIGGER.SEVERITY} current status: {TRIGGER.STATUS} alarm Information: {TRIGGER.NAME} alarm time: {EVENT.DATE} {EVENT.TIME} recovery time: {EVENT.RECOVERY.DATE} {EVENT .RECOVERY.time} duration: {EVENT.AGE} event ID: {EVENT.ID}

When you are sure, click add:

At this point, the configuration of Wechat alarm integration Zabbix is complete, as follows:

Test Wechat alarm function: # perform the following operations in agent to simulate the fault [root@agent ~] # / etc/init.d/zabbix_agentd stop

After shutting down the agent end, the following message will be received later on WeChat at work (email will also be received):

# start the agent and test the recovery operation: [root@agent ~] # / etc/init.d/zabbix_agentd start

WeCom received the following message:

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: 0

*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

Servers

Wechat

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

12
Report