Chinaunix首页 | 论坛 | 博客
  • 博客访问: 43926
  • 博文数量: 19
  • 博客积分: 720
  • 博客等级: 上士
  • 技术积分: 231
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-21 15:19
文章分类

全部博文(19)

文章存档

2012年(2)

2011年(15)

2010年(2)

我的朋友

分类: PHP

2011-08-03 17:06:05

由于lvs 下的web不稳定,写了一个script来监控LVS的状态,使用perl的mail模板发信
bash脚本:
#!/bin/bash
lvs_list=`egrep -v "^ *#| bond" /etc/sysconfig/ha/lvs.cf  | awk '/address/{ print $3}'`
lvs_list_num=`egrep -v "^ *#| bond" /etc/sysconfig/ha/lvs.cf  | awk '/address/{ print $3}' | wc -l`
path=/home/infra/Monitor
cd $path
########  Check the lvs   ####################################################
cmd=`/sbin/ipvsadm -ln | awk '/Route/{ print $2 }' | awk -F: '{ print $1 }'`
N_url=`/sbin/ipvsadm -ln | awk '/Route/{ print $2 }' | wc -l`
if [ $lvs_list_num -eq $N_url ];then                ############# 判断当前web数量与路由表比对
:
else
case $N_url in
1)
for i in $lvs_list;do
if [ $i != "$cmd" ];then
perl mail.pl $i--2
fi
done
;;
2)
echo $lvs_list  >  $path/tmp.monitor1
echo $cmd       > $path/tmp.monitor2
tr -s " " "\n" < $path/tmp.monitor1 > $path/tmp.monitor3
tr -s " " "\n" < $path/tmp.monitor2 > $path/tmp.monitor4
i=`cat tmp.monitor3 tmp.monitor4 | sort | uniq -u`
perl mail.pl $i--1
;;
0)
echo  $lvs_list  > $path/tmp.monitor
i=`sed  -r 's/ /#/g'  $path/tmp.monitor`
perl mail.pl ALL-----$i
rm -rf $path/tmp.monitor
;;
esac
fi
exit

 

perl 邮件模板

 

  1. #! /usr/bin/perl -w
  2. use Net::SMTP;
  3. my ($a)=@ARGV;
  4. my $mailhost = "10.82.67.200";
  5. my $mailfrom = ;
  6. # the recipient list
  7. my @mailto = ();
  8. my $subject = " WEB ERROR ";
  9. my $text = "the webs status is : The $a shutting down !!";
  10. $smtp = Net::SMTP->new($mailhost, Hello => 'localhost', Timeout => 120, Debug => 1);
  11. # auth login, type your user name and password here
  12. # $smtp->auth('user','pass');
  13. foreach my $mailto (@mailto) {
  14. # Send the From and Recipient for the mail servers that require it
  15. $smtp->mail($mailfrom);
  16. $smtp->to($mailto);
  17. # Start the mail
  18. $smtp->data();
  19. # Send the header
  20. $smtp->datasend("To: $mailto\n");
  21. $smtp->datasend("From: $mailfrom\n");
  22. $smtp->datasend("Subject: $subject\n");
  23. $smtp->datasend("\n");
  24. # Send the message
  25. $smtp->datasend("$text\n\n");
  26. # Send the termination string
  27. $smtp->dataend();
  28. }
  29. $smtp->quit;

 

 

阅读(509) | 评论(0) | 转发(0) |
0

上一篇:linux 监控脚本

下一篇:常用 系统 DB 操作

给主人留下些什么吧!~~