Git Product home page Git Product logo

zabbixalertget's Introduction

添加数据库收集告警信息
create table zabbix_problem_info (id varchar(20) NOT NULL ,alert_time timestamp without time zone NOT NULL, create_time timestamp without time zone NOT NULL, host varchar(100) NOT NULL , content varchar(2000) NOT NULL , value varchar(100) NOT NULL , item varchar(100) NOT NULL , CONSTRAINT zabbix_problem_info_pkey PRIMARY KEY (id));

添加action 设置告警信息
Default subject:  {"area":"local","TRIGGER.NAME":"{TRIGGER.NAME}","TIME":"{EVENT.DATE} {EVENT.TIME}","HOST":"{HOST.NAME}","VALUE":"{ITEM.VALUE}","ITEM":"{ITEM.NAME}"}

添加告警事件脚本
#!/usr/bin/python
#coding=utf-8


import os,sys
import psycopg2 , sys
import psycopg2.extras
from datetime import datetime
import random

try:
    _id = "AWS2" + str(datetime.now().strftime('%Y%m%d%H%M%S')) + str(random.randint(0,9))


    info = sys.argv[1]
    x = eval(info)

    content = x['TRIGGER.NAME']
    alert_time = x['TIME'].replace('.','-')
    host = x['HOST']
    value = x['VALUE']
    item = x['ITEM']


    create_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    conn = psycopg2.connect(host="0.0.0.0",port=5432,user="postgres" ,password="postgres" , database="zabbix")
    cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
    sql = 'INSERT INTO zabbix_problem_info(id, alert_time, create_time, host, content, value ,item) VALUES (%s, %s, %s, %s, %s, %s, %s)'
    values = (_id , alert_time , create_time , host , content , value ,item )
    cur.execute(sql , values)
    conn.commit()
    conn.close()
except Exception , e:
    conn.close()

zabbixalertget's People

Contributors

1182640071 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

zhuima

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.