码迷,mamicode.com
首页 > 其他好文 > 详细

Smokeping 使用外部邮箱发送告警邮件

时间:2014-06-15 23:50:57      阅读:1262      评论:0      收藏:0      [点我收藏+]

标签:des   style   class   code   java   http   

转自:http://www.humen1.net/2013/11/669


smokeping 默认用sendmail发邮件,这样不好。

改了一下源码 这样可以使用 我QQ的smtp server来发告警邮件了

首先需要安装 Authen::SASL 模块(auth 需要用的) 我用CPAN装的,不细说了

修改 smokeping/lib/Smokeping.pm

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#头上加
 
use Authen::SASL;
 
#定位到sendmail函数,改成下面这样
 
sub sendmail ($$$){
 
my $from = shift;
 
my $to = shift;
 
$to = $1 if $to =~ /<(.*?)>/;
 
my $body = shift;
 
if ($cfg->;{General}{mailhost} and
 
my $smtp = Net::SMTP->new([split /\s*,\s*/, $cfg->{General}{mailhost}],Timeout=>5) ){
 
$smtp->auth(split(/\s*,\s*/, $cfg->{General}{mailusr}),split(/\s*,\s*/, $cfg->{General}{mailpwd}));
 
$smtp->mail($from);
 
$smtp->to(split(/\s*,\s*/, $to));
 
$smtp->data();
 
$smtp->datasend($body);
 
$smtp->dataend();
 
$smtp->quit;
 
} elsif ($cfg->{General}{sendmail} or -x "/usr/lib/sendmail"){
 
open (M, "|-") || exec (($cfg->{General}{sendmail} || "/usr/lib/sendmail"),"-f",$from,$to);
 
print M $body;
 
close M;
 
} else {
 
warn "ERROR: not sending mail to $to, as all methodes failed\n";
 
}
 
}
 
#找到  ‘_vars =>‘ ,把 mailusr mailpwd  加进去。不然不能启动哦!General configuration values valid for the whole SmokePing setup.
 
DOC
_vars =>
[ qw(owner imgcache imgurl datadir dyndir pagedir piddir sendmail offset
 
smokemail cgiurl mailhost mailusr mailpwd snpphost contact display_name
 
syslogfacility syslogpriority concurrentprobes changeprocessnames tmail
 
changecgiprogramname linkstyle precreateperms ) ],

然后修改配置文件
/etc/config

1
2
3
4
5
6
7
mailhost = smtp.qq.com
mailusr = noreply@qq.com<script type="text/javascript">
/* <![CDATA[ */
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1].previousSibling;a=l.getAttribute(‘data-cfemail‘);if(a){s=‘‘;r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})();
/* ]]> */
</script>
mailpwd = xxxxxxxxx

Smokeping 使用外部邮箱发送告警邮件,布布扣,bubuko.com

Smokeping 使用外部邮箱发送告警邮件

标签:des   style   class   code   java   http   

原文地址:http://www.cnblogs.com/Oover/p/3785233.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!