Skip to content

syl5005/zabbix-wechat

Repository files navigation

zabbix-wechat


作者:superbigsea 邮箱:[email protected] qq群238705984

做出来的效果 http://mp.weixin.qq.com/s?__biz=MzIzNjUxMzk2NQ==&mid=2247484693&idx=1&sn=ae7482230a90476f912eaada2849c861&chksm=e8d7fad7dfa073c17b364e15fe4464d2b1f09a49fcc66906856e72ff15cc2b7fc183af7f225a&mpshare=1&scene=23&srcid=0228sGfPKDoLskzjzaMv5j1b#rd


Introduction

The purpose of this project is to build up an auto-notification alarm system which is compatible with most monitoring system,which includes the functions such as reminder alarm, alarm compression, alarm classification, alarm summary report etc... Readers need to have some experiences in linux, python, zabbix. Requires python3 support.

ScreenShots

Flow

Required components

1.An zabbix server alert scripts: Its function is to put the alarm information generated by zabbix server in a certain format.This scripts requires python3 support

2.Other components:mysql、redis(Used to cache wechat's token, you can also use memcacahed),tt server(Object storage,you can also use others like swift or ceph.)

3.A secondary domain with 80 and 1978 ports opened.

5.A WeChat Official Accounts (微信企业号). It can be registered in https://admin.wechat.com/ or https://qy.weixin.qq.com/  

Install and deployt

The entire installation configuration is rather complex,needing plenty of components.

1 Zabbix server alert scripts

(1) Install python3.4 and other components

 yum install python34 python34-pip python34-devel
pip3 install  pycrypto

(2) Generate an rsa key pair

ssh-keygen -b 4096 -t rsa -f /etc/zabbix/pub
mv /etc/zabbix/pub.pub /etc/zabbix/pub.key

(3) Move zabbix_alarm_script/all.py to zabbix alertscripts dir and edit it

zabbix_server_charturl = "http://127.0.0.1/zabbix/chart.php"  ##Zabbix server  chart api
ttserver = "http://www.example.com:1978"   ##The url for ttserver over internet.
server_url = "http://www.example.com/getvalue" ##The url for main process  over internet.

(4) Generate cookies

curl -c /tmp/zabbix_cookie -d "name=Admin&password=zabbix&autologin=1&enter=Sign+in"  http://127.0.0.1/zabbix/index.php

Change the username and passwd and zabbix url to your own setting.

(5)Config zabbix action

{TRIGGER.NAME}@@@{TRIGGER.DESCRIPTION}@@@{HOSTNAME}@@@{TRIGGER.SEVERITY}@@@{ITEM.ID}@@@{TRIGGER.STATUS}@@@{HOST.CONN}@@@{TRIGGER.HOSTGROUP.NAME}@@@{EVENT.ID}@@@

2 MySQL Server

yum install mariadb-server -y
systemctl enable mariadb
systemctl start mariadb
CREATE DATABASE `alarm` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; #
grant all privileges on *.* to alarm@localhost identified by 'alarm';

3 Redis server

yum install redis
systemctl enable redis
systemctl start redis

4 Ttserver

yum install bzip2-devel gcc zlib-devel -y
wget http://fallabs.com/tokyotyrant/tokyotyrant-1.1.41.tar.gz
wget http://fallabs.com/tokyocabinet/tokyocabinet-1.4.48.tar.gz
tar zxvf tokyocabinet-1.4.48.tar.gz
cd tokyocabinet-1.4.48
./configure
make && make install 
 tar zxvf tokyotyrant-1.1.41.tar.gz
 cd tokyotyrant-1.1.41
 ./configure
make && make install 
mkdir /ttdata/
./ttserver -port 1978 -thnum 8 -tout 30 -dmn -pid /ttdata/tt.pid -kl -log /ttdata/tt.log -le -ulog /ttdata -ulim 128m -sid 1 -rts /ttdata/tt.rts /ttdata/ttdb.tch

5 Python3+django and other configurations

 yum install python34 python34-pip python34-devel
pip3 install django  pymysql django_crontab redis  pycrypto

(1) Move the rsa private key which made in above to /etc/zabbix/pri.key

(2) Edit /etc/zabbix/wechat.conf

[wechat]
corp_id=******************
corp_secret=*******************
toparty=***********
agentid=*************
url=http://**************
[redis]
host=****
port=****

The top 4 configuration can be referenced  in  https://github.com/X-Mars/Zabbix-Alert-WeChat.

url:The url for main process over internet

(3) Database configuration

vim zabbixwechat/settings.py
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'alarm',                      # Or path to database file if using sqlite3.
        # The following settings are not used with sqlite3:
        'USER': 'alarm',
        'PASSWORD': 'alarm',
        'HOST': 'alarm',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '3306',                      # Set to empty string for default.
        'TEST_CHARSET': 'utf8',
        'TEST_COLLATION': 'utf8_general_ci',
    }
}

(4) Initialize the database

python3 manage.py makemigrations

(5) WeChat Official Accounts Configuration

The configuration of the permissions of the message,also reference https://github.com/X-Mars/Zabbix-Alert-WeChat If you want to add the Summary Table on the menu of Wechat: 1.add the trusted domain name 2 . add an jump to

https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7dec596b2599614c&redirect_uri=http%3a%2f%2f*********%2fall&response_type=code&scope=snsapi_base&state=1&connect_redirect=1#wechat_redirect in the configuration。 Replace ******* with the urlencode domain name

http://tool.chinaz.com/tools/urlencode.aspx This URL can encode the domain name

(6) Run

python3 manage.py runserver 0.0.0.0:80

Enjoy!!!

About

基于zabbix和微信的通用报警处理平台

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published