zoukankan      html  css  js  c++  java
  • Zabbix如何设置脚本告警

    设置告警脚本的路径

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

    创建脚本

    在这里,仅以一个简单脚本进行测试

    # 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("
    ")
    f.close()

    注:该脚本需在AlertScriptsPath路径下,且需可执行权限。


    设置告警介质

    Administration-> Media types-> create media type

    注意:Type需选择为Script

    将告警介质与用户关联

    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,因为告警本身就意味着服务器启动成功了。

  • 相关阅读:
    Charles:rewrite重写功能
    Vue中provide和inject 用法
    vue中install方法
    vue自定义组件(通过Vue.use()来使用)即install的使用
    Eelectron 中的remote模块
    理解Vue中的Render渲染函数
    Vue.js中this.$nextTick()的使用
    postman请求本地接口Error: connect ECONNREFUSED 127.0.0.1:8083
    1016 Phone Bills (25 分)
    CF842E Nikita and game
  • 原文地址:https://www.cnblogs.com/ivictor/p/6761167.html
Copyright © 2011-2022 走看看