1)、vim /etc/zabbix/alertscripts/smail.pl
#!/usr/bin/perl
use Net::SMTP;
use HTTP::Date qw(time2iso str2time time2iso time2isoz);
sub send_mail{
if ( $#ARGV < 2 ){
print "please input 收件人 主题 内容!\n";
exit(-1);
}
my $name= $ARGV[2];
my $CurrTime = time2iso(time());
my $to_address = shift;
my $mail_user = '邮箱用户名';
my $mail_pwd = '邮箱密码';
my $mail_server = 'smtp.exmail.qq.com';
my $from = "From: $mail_user\n";
my $subject = "Subject:$ARGV[1]";
my $info = "$CurrTime--$name ";
my $message = <<CONTENT;
$info
CONTENT
my $smtp = Net::SMTP->new($mail_server);
$smtp->auth($mail_user, $mail_pwd) || die "Auth Error! $!";
$smtp->mail($mail_user);
$smtp->to($to_address);
$smtp->data(); # begin the data
$smtp->datasend($from); # set user
$smtp->datasend($subject); # set subject
$smtp->datasend("\n\n");
$smtp->datasend("$message\n"); # set content
$smtp->dataend();
$smtp->quit();
};
$receive=$ARGV[0];
@arr_mail=( "$receive");
foreach (@arr_mail){
send_mail $_;
};
2)、设置 administration-> media types -> create media type
3)、设置 Configuration -> Actions -> create Action ( trigger )
4)、设置 group 权限 或者 user 权限 Administration -> users