关于zabbix:zabbixweboperate

12次阅读

共计 2510 个字符,预计需要花费 7 分钟才能阅读完成。

1、切换页面中文

页面右上角人物图标[Admin (Zabbix Administrator]---User----Language---Chinese(zh_CN)---Update

2、显示中文字符乱码
从 windows 机器拷贝一份字体文件 (如:simkai.ttf) 到 /var/www/html/zabbix/fonts/ 目录下
vi /var/www/html/zabbix/include/defines.inc.php

define('ZBX_GRAPH_FONT_NAME',         'graphfont')  -->  define('ZBX_GRAPH_FONT_NAME',         'simkai')
define('ZBX_FONT_NAME', 'graphfont');   -->    define('ZBX_FONT_NAME', 'simkai');

3、增加监控主机
配置 -- 主机 -- 创立主机    agent 代理程序的接口:IP 地址填写客户端 ip 地址
模版 -- 抉择 -- 抉择 -- 增加 -- 增加

4、导入导出模版
导出:配置 -- 模版 -- 抉择模版 -- 导出
导入:配置 -- 模版 -- 导入 -- 抉择模版文件 -- 导入

5、微信告警
cat /etc/zabbix/zabbix_server.conf |grep 'AlertScriptsPath'
将微信脚本搁置到 AlertScriptsPath 指定的地位

vi wechat.py

<code>

#!/usr/bin/python
#_*_coding:utf-8 _*_


import urllib,urllib2
import json
import sys
import json

reload(sys)
sys.setdefaultencoding('utf-8')


def gettoken(corpid,corpsecret):
    gettoken_url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' + corpid + '&corpsecret=' + corpsecret
#    print  gettoken_url
    try:
        token_file = urllib2.urlopen(gettoken_url)
    except urllib2.HTTPError as e:
        print e.code
        print e.read().decode("utf8")
        sys.exit()
    token_data = token_file.read().decode('utf-8')
    token_json = json.loads(token_data)
    token_json.keys()
    token = token_json['access_token']
    return token



def senddata(access_token,user,subject,content):

    send_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + access_token
    send_values = {
        "touser":user,
        "toparty":"1",
        "msgtype":"text",
        "agentid":"xxx",     #利用 id
        "text":{"content":subject + '\n' + content},
        "safe":"0"
        }
#    send_data = json.dumps(send_values, ensure_ascii=False)
    send_data = json.dumps(send_values, ensure_ascii=False).encode('utf-8')
    send_request = urllib2.Request(send_url, send_data)
    response = json.loads(urllib2.urlopen(send_request).read())
    print str(response)


if __name__ == '__main__':
    user = str(sys.argv[1])         #zabbix 传过来的第一个参数
    subject = str(sys.argv[2])      #zabbix 传过来的第二个参数
    content = str(sys.argv[3])      #zabbix 传过来的第三个参数

    corpid =  'xxxx'
    corpsecret = 'xxxx'
    accesstoken = gettoken(corpid,corpsecret)
    senddata(accesstoken,user,subject,content)

</code>

 chmod 755 wechat.py

zabbix-web 页面
治理--报警媒介类型--创立媒体类型

名称:wechat
类型:脚本
脚本名称:wechat.py
脚本参数:{ALERT.SENDTO}
{ALERT.SUBJECT}
{ALERT.MESSAGE}

治理--用户--Admin--报警媒介--增加
类型:wechat
收件人:微信号


配置--动作--事件源(触发器)--创立动作
动作:名字随便
操作:默认接管人:python 脚本的第二个参数(如:======= 告警告诉 =========)默认信息:环境:小机房
               主机: {HOSTNAME1}
               信息: {TRIGGER.NAME}
               我的项目: {TRIGGER.KEY1}
               详情: {ITEM.NAME}:{ITEM.VALUE}
               内容: {TRIGGER.STATUS}
               工夫: {EVENT.DATE} {EVENT.TIME}
     操作:新的
         步骤持续时间:60
         发送到用户:Admin
         仅送到:wechat

复原操作:默认接管人:python 脚本的第二个参数(如:======= 告警告诉 =========)默认信息:环境:小机房
               主机: {HOSTNAME1}
               信息: {TRIGGER.NAME}
               我的项目: {TRIGGER.KEY1}
               详情: {ITEM.NAME}:{ITEM.VALUE}
               内容: {TRIGGER.STATUS}
               工夫: {EVENT.DATE} {EVENT.TIME}
     操作:新的
         操作类型:发送音讯
         发送到用户:Admin
         仅送到:wechat

正文完
 0