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.