设置告警脚本的路径node
# vim /etc/zabbix/zabbix_server.conf
AlertScriptsPath=/usr/lib/zabbix/alertscriptspython
建立脚本vim
在这里,仅以一个简单脚本进行测试服务器
# cat zabbix_syslog.py测试
#!/usr/bin/python import sys,time print sys.argv now=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()
注:该脚本需在AlertScriptsPath路径下,且需可执行权限。spa
设置告警介质rest
Administration-> Media types-> create media typecode
注意:Type需选择为Scriptserver
将告警介质与用户关联对象
Administration -> Users
点击 Admin,也能够新建用户进行关联
Media -> Add
type选择告警介质中定义的name
建立Action
Configuration -> Actions -> Create action
在这里,以Zabbix自带的“Template OS Linux”模板中的服务器重启的Trigger做为Action的对象
测试
重启node1
[root@node1 ~]# init 6
验证测试结果
首先查看Action是否产生
Administration -> Audit
查看告警信息是否写入到文件中
[root@node3 ~]# cat /tmp/syslog_test.txt 2017-04-25 18:28:30 /usr/lib/zabbix/alertscripts/zabbix_syslog.py slowtech@126.com PROBLEM: node1 has just been restarted node1^192.168.244.10^PROBLEM^Warning^主机重启 主机:node1(node1 has just been restarted)
2017-04-25 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^主机重启恢复 主机:node1(node1 has just been restarted)
脚本告警配置成功,哈哈,忽然想到,对于重启的告警无需设置Recovery message,由于告警自己就意味着服务器启动成功了。