pennate 发表于 2019-1-22 13:36:27

Zabbix sendEmail的部署步骤

  一、为什么要自定义邮件脚本报警?
  灵活,方便。可以自定义过滤信息。
  下面是使用不同方式的邮件报警,一个是利用sendEmail程序来发送报警邮件,第二个是利用python脚本来发送邮件。
  二、sendEmail的部署步骤
  1.官方介绍:http://caspian.dotconf.net/menu/Software/SendEmail/
  2.先下载安装包到本地,解压。
  # wget -c http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
  # tar zxf sendEmail-v1.56.tar.gz
  # cd sendEmail-v1.56
  # cp -a sendEmail /usr/local/bin/
  # chmod +x /usr/local/bin/sendEmail
  # file /usr/local/bin/sendEmail
  /usr/local/bin/sendEmail: a /usr/bin/perl -w script text executable
  3.看下sendemail命令的帮助信息
  # /usr/local/bin/sendEmail
  sendEmail-1.56 by Brandon Zehm
  Synopsis:sendEmail -f ADDRESS
  Required:
  -f ADDRESS                from (sender) email address
  * At least one recipient required via -t, -cc, or -bcc
  * Message body required via -m, STDIN, or -o message-file=FILE
  Common:
  -t ADDRESS    to email address(es)
  -u SUBJECT                message subject
  -m MESSAGE                message body

  -s SERVER[:PORT]          smtp mail>  Optional:
  -a   FILE       file attachment(s)
  -ccADDRESS    ccemail address(es)
  -bcc ADDRESS    bcc email address(es)
  -xuUSERNAME             username for SMTP authentication
  -xpPASSWORD             password for SMTP authentication
  Paranormal:
  -b BINDADDR[:PORT]      local host bind address
  -l LOGFILE                log to the specified file
  -v                        verbosity, use multiple times for greater effect
  -q                        be quiet (i.e. no STDOUT output)
  -o NAME=VALUE             advanced options, for details try: --help misc
  -o message-content-type=
  -o message-file=FILE         -o message-format=raw
  -o message-header=HEADER   -o message-
  -o reply-to=ADDRESS          -o timeout=SECONDS
  -o username=USERNAME         -o password=PASSWORD
  -o tls=         -o fqdn=FQDN
  Help:
  --help                  the helpful overview you're reading now

  --help addressing         explain addressing and>
  --help message            explain message body input and>  --help networking         explain -s, -b, etc
  --help output             explain logging and other output options
  --help misc               explain -o options, TLS, SMTP auth, and more
  4.安装下依赖
  # yum install perl-Net-SSLeay perl-IO-Socket-SSL -y
  5.简单的报警脚本mail
  新建#mkdir   /usr/lib/zabbix/alertscripts/
  # cd /usr/lib/zabbix/alertscripts/
  # cat mail.sh#!
  #!/bin/bash
  SMTP_server='smtp.163.com'    # SMTP服务器
  username='zabbix@163.com'   # 用户名
  password='zabbix'             # 密码(163客户端授权密码)
  from_email_address='zabbix@163.com' # 发件人Email地址
  to_email_address="$1"               # 收件人Email地址,zabbix传入的第一个参数
  message_subject_utf8="$2"         # 邮件标题,zabbix传入的第二个参数
  message_body_utf8="$3"            # 邮件内容,zabbix传入的第三个参数
  # 转换邮件标题为GB2312,解决邮件标题含有中文,收到邮件显示乱码的问题。
  message_subject_gb2312=`iconv -t GB2312 -f UTF-8
页: [1]
查看完整版本: Zabbix sendEmail的部署步骤