zoukankan      html  css  js  c++  java
  • Zabbix 告警内容配置

     

    #配置媒介告警类型

     #-------------------------------------------------------------------------------------------------------

     

    #---------------------------------------------------------------------------------------------------------------------

     请注意该2个脚本chmod +x 

    如果python脚本执行有问题的话,请检查/tmp/weixin.log的属组,应该为zabbix

     [root@nod02 ~]# cd /usr/lib/zabbix/alertscripts/

    mail_163.py

     1 #!/usr/bin/python  
     2 #coding:utf-8  
     3 import smtplib  
     4 from email.mime.text import MIMEText  
     5 import sys  
     6 mail_user = 'c4kaichen@163.com'
     7 mail_pass = '授权码邮箱'  
     8 
     9 def send_mail(to_list,subject,content):  
    10     me = "zabbix 监控告警平台"+"<"+mail_user+">"
    11     msg = MIMEText(content, 'plain', 'utf-8')  
    12     msg['Subject'] = subject  
    13     msg['From'] = me  
    14     msg['to'] = to_list  
    15     try:  
    16         s = smtplib.SMTP("smtp.163.com", 25)  
    17         s.login(mail_user,mail_pass)  
    18         s.sendmail(me,to_list,msg.as_string())  
    19         s.close()  
    20         return True  
    21     except Exception,e:  
    22         print str(e)  
    23         return False  
    24 if __name__ == "__main__":  
    25     send_mail(sys.argv[1], sys.argv[2], sys.argv[3])
    View Code

    weixin.py

     1 #!/usr/bin/env python
     2 #-*- coding: utf-8 -*-
     3 #author: yanggd
     4 #date: 2018-04-20
     5 #comment: zabbix接入微信报警脚本
     6 
     7 import requests
     8 import sys
     9 import os
    10 import json
    11 import logging
    12 
    13 logging.basicConfig(level = logging.DEBUG, format = '%(asctime)s, %(filename)s, %(levelname)s, %(message)s',
    14                 datefmt = '%a, %d %b %Y %H:%M:%S',
    15                 filename = os.path.join('/tmp','weixin.log'),
    16                 filemode = 'a')
    17 
    18 corpid='ww7dd0074bd8b006f9'
    19 appsecret='8gPCvguwomL0WMej8fcghxQgOY-y0LlGQsAicaDHvA8'
    20 agentid=1000002
    21 #获取accesstoken
    22 token_url='https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' + corpid + '&corpsecret=' + appsecret
    23 req=requests.get(token_url)
    24 accesstoken=req.json()['access_token']
    25 
    26 #发送消息
    27 msgsend_url='https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + accesstoken
    28 
    29 touser=sys.argv[1]
    30 subject=sys.argv[2]
    31 #toparty='3|4|5|6'
    32 message=sys.argv[2] + "
    
    " +sys.argv[3]
    33 
    34 params={
    35         "touser": touser,
    36 #       "toparty": toparty,
    37         "msgtype": "text",
    38         "agentid": agentid,
    39         "text": {
    40                 "content": message
    41         },
    42         "safe":0
    43 }
    44 
    45 req=requests.post(msgsend_url, data=json.dumps(params))
    46 
    47 logging.info('sendto:' + touser + ';;subject:' + subject + ';;message:' + message)                                                                              
    View Code

     参照https://www.jb51.net/article/100086.htm

     如果pip有问题

    请参照http://www.cnblogs.com/nodchen/p/9432067.html

    #####################################################

    请注意有个动作一定要勾上

  • 相关阅读:
    5. JVM虚拟机栈
    4. 程序计数器
    3. JVM运行时数据区
    2. 类加载
    1. JVM体系结构
    SpringCloud 网关组件Gateway
    SpringCloud Hystrix断路器的基本使用
    SpringCloud Ribbon和Feign 的使用和源码分析
    反向代理的概念
    事务mysql
  • 原文地址:https://www.cnblogs.com/nodchen/p/9432726.html
Copyright © 2011-2022 走看看