第1步:创建发送短信脚本 由于我们公司是用的语音短信,不需要报警内容,所以脚本无需传任何参数,如果是用的文字短信,请自行修改脚本。其实无论是语音短信还是文字短信,脚本内容大体上是一样的,只是少了报警内容而已,少了往脚本里传个参数而已。 vim /data/zabbix/share/zabbix/alertscripts/sms.pl
#!/usr/bin/perl -w
use strict;
use LWP::Simple;
use URI::Escape;
use Encode;
my $content = 'xxxxxx'; # 语音短信内容编号
my $prdid = 'xxxxxxx';
my @mobile = ('138xxxxxxxx','186xxxxxxxx'); # 接收语音短信的手机号
my $log_control = 1; # a switch of log
my $username = 'xuad'; # your sms service username
my $password = '12345678'; # your sms service password
my $number = 0;
while($number < 2){
my $result = get "http://<发送短信的URL地址>sname=$username&spwd=$password&scorpid=&sprdid=$prdid&sdst=$mobile[$number]&smsg=$content";
if($log_control) {
my $fh;
open($fh, '>> /data/zabbix/logs/sms.log') or die "can't open log: $!"; # make sure have permission
print $fh join(' ', time, encode('utf8',$result), "\n");
close $fh;
}
$number = $number + 1;
}