How to Set a script alarm for Zabbix and a zabbix script alarm?

Source: Internet
Author: User

How to Set a script alarm for Zabbix and a zabbix script alarm?

Set the alert script path

# Vim/etc/zabbix/zabbix_server.conf
AlertScriptsPath =/usr/lib/zabbix/alertscripts

 

Create script

Here, only one simple script is used for testing.

# Cat zabbix_syslog.py

#!/usr/bin/pythonimport sys,timeprint sys.argvnow=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())f= open(r'/tmp/syslog_test.txt', 'a+')f.write(now+" ")for line in sys.argv:    f.write(line+" ")f.write("\n")f.close()

Note: The script must be in the AlertScriptsPath path and be executable.


Set alert media

Administration-> Media types-> create media type

Note: Select Script as the Type.

 

Associate alert media with users

Administration-> Users

Click Admin. You can also create a user for association.

Media-> Add

Type select the name defined in the alarm Media

 

Create Action

Configuration-> Actions-> Create action

Here, the server restart Trigger in the "Template OS Linux" Template of Zabbix is used as the Action object.

 

 

 

 

Test

Restart node1

[Root @ node1 ~] # Init 6

 

Verify Test Results

First, check whether Action is generated.

Administration-> Audit

 

Check whether the alert information is written to the file.

[Root @ node3 ~] # Cat/tmp/syslog_test.txt 18:28:30/usr/lib/zabbix/alertscripts/routing slowtech@126.com PROBLEM: node1 has just been restarted node1 ^ 192.168.244.10 ^ PROBLEM ^ Warning ^ host restart Host: node1 (node1 has just been restarted)
18:28:30/usr/lib/zabbix/alertscripts/zabbix_syslog.py slowtech@126.com OK: node1 has just been restarted node1 ^ 192.168.244.10 ^ OK ^ Warning ^ host restart recovery Host: node1 (node1 has just been restarted)

 

The script alert configuration is successful. Haha, you suddenly think that you do not need to set a Recovery message for the restart alert, because the alert itself means that the server is successfully started.

 

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.