• zabbix邮件脚本报警


    #启动邮箱服务
    systemctl start postfix.service
    #配置用户的邮箱发送邮件
    vim /etc/mail.rc
    set from="xxx@xxx.com"
    set smtp="smtps://smtp.exmail.qq.com:465"
    set smtp-auth-user="xxx@xxx.com"
    set smtp-auth-password="xxxxxx"
    set smtp-auth=login
    set ssl-verify=ignore
    set nss-config-dir=/etc/pki/nssdb
    #测试发送邮件
    [root@VM_centos ~]# echo "messages" | mail -v -s "subject" yxxx@qq.com
    Resolving host smtp.exmail.qq.com . . . done.
    Connecting to 163.177.90.125:465 . . . connected.
    Error in certificate: Peer's certificate issuer is not recognized.
    Comparing DNS name: "pop.qq.com"
    Comparing DNS name: "ex.qq.com"
    Comparing DNS name: "imap.exmail.qq.com"
    Comparing DNS name: "rtx.exmail.qq.com"
    Comparing DNS name: "smtp.exmail.qq.com"
    SSL parameters: cipher=AES-128, keysize=128, secretkeysize=128,
    issuer=CN=GeoTrust RSA CA 2018,OU=www.digicert.com,O=DigiCert Inc,C=US
    subject=CN=pop.qq.com,OU=R&D,O=Shenzhen Tencent Computer Systems Company Limited,L=Shenzhen,ST=Gu
    220 smtp.qq.com Esmtp QQ Mail Server
    ...
    >>> QUIT
    221 Bye
    #解决证书解析报错
    #手动的获取QQ 邮箱的证书保存到本地指定的目录里以备调用和验证
    [root@VM_centos ~]# cd /etc/pki/nssdb/
    [root@VM_centos nssdb]# ls
    cert8.db cert9.db key3.db key4.db pkcs11.txt secmod.db
    [root@VM_centos nssdb]# echo -n | openssl s_client -connect smtp.exmail.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' >qq.crt
    depth=2 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert Global Root CA
    verify return:1
    depth=1 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = GeoTrust RSA CA 2018
    verify return:1
    depth=0 C = CN, ST = Guangdong, L = Shenzhen, O = Shenzhen Tencent Computer Systems Company Limited, OU = R&D, CN = pop.qq.com
    verify return:1
    DONE
    [root@VM_centos nssdb]# certutil -A -n "GeoTrust SSL CA" -t "C,," -d /etc/pki/nssdb -i qq.crt
    [root@VM_centos nssdb]# certutil -A -n "GeoTrust Global CA" -t "C,," -d /etc/pki/nssdb -i qq.crt
    [root@VM_centos nssdb]# certutil -L -d /etc/pki/nssdb
    #进入邮箱 SSL 证书存放目录,为了信任证书的标记操作
    [root@VM_centos nssdb]# certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
    Notice: Trust flag u is set automatically if the private key is present.
    #解决发送是附件
    #只要把行尾^M去掉,然后发送的话就不会是附件的形式了
    [root@VM_centos nssdb]# yum -y install dos2unix.x86_64
    [root@VM_centos nssdb]# vim /usr/lib/zabbix/alertscripts/sendmail.sh
    #!/bin/bash
    TMP_FILE=/usr/lib/zabbix/alertscripts/tmp_messages.txt
     
    echo $3 | tr ' ' ' ' > ${TMP_FILE} #把^M替换为
    # dos2unix ${TMP_FILE} #解决发送的邮件内容变成附件的问题 未解决
    subject=$2
    mail -s "${subject}" $1 >>/var/log/sendmail.log 2>&1 <${TMP_FILE}
     
    #注意权限是chown zabbix.zabbix
    #zabbix 管理---->报警媒介类型
    #查看zabbix脚本位置
    [root@VM_centos alertscripts]# grep alertscripts /etc/zabbix/zabbix_server.conf
    AlertScriptsPath=/usr/lib/zabbix/alertscripts
     
    本文是作者本人的笔记心得,如果有bug请评论留言; 如果本文对你有帮助,请点击【好文要顶】和【关注我】以示鼓励; 大家也可以关注我的微信订阅号【ysgxming】一起交流学习。
  • 相关阅读:
    基于Antlr4编写DSL
    【整理】ANTLR应用案例 | 在路上
    【整理】ANTLR应用案例 | 在路上
    The ANTLR Parser Generator
    ANTLR4权威参考手册
    ANTLR Examples
    ANTLRWorks: The ANTLR GUI Development Environment
    http://www.cnblogs.com/vowei/archive/2012/08/24/2654287.html
    写一个编译器
    写一个编译器
  • 原文地址:https://www.cnblogs.com/DemonAngel/p/9223789.html
Copyright © 2020-2023  润新知