宿主机监控
#使用的模块 use URI::Escape; use LWP::Simple; use HTML::HeadParser; use Encode qw/encode decode/; use Time::HiRes qw(gettimeofday); use strict; use Switch; #阀值 my $cpuvale=2; my $diskvale=700; my $memoryvale=95; my $iovale=800; my $powervale="已打开电源"; #日志 my $logfile="e:/amos/info.log"; #找出监控项 my $var="监控"; my $title=(split($var,$ARGV[2]))[1]; #获取时间 my ($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst) = localtime(); $year += 1900; $mon++; my $date = "$year-$mon-$day $hour:$min:$sec"; print $date, "\n"; #程序 my $command="c:\windows\system32\cmd.exe /c e:\amos\mon.pl {targetName} {target} {alarmName} {triggeringSummary} {declaringSummary} {oldStatus} {newStatus}"; #运维人员电话 my @OP_PHONE=(15121132075,13817488875,15800329316); #my @OP_PHONE=(15800329316); #system("echo $ARGV[0] $ARGV[1] $ARGV[2] $ARGV[3] $ARGV[4] $ARGV[5] $ARGV[6] $ARGV[7] $date >> $logfile"); sub sendmail { my $val="$_[0]"; my $vale="$_[1]"; if ($val =~ /[0-9].*/) { print "ninao\n"; if ( $val > $vale ) { #消息 my $msg="vcenter $ARGV[0] $title\_$vale use:$ARGV[6]\n $date"; my $sendmsg=uri_escape($msg); foreach my $phone(@OP_PHONE) { my $msgurl="http://192.168.6.13/fetion.php?phone=$phone&msg=$sendmsg"; get("$msgurl"); #日志 system("echo $phone $ARGV[0] $ARGV[1] $ARGV[2] $ARGV[3] $ARGV[4] $ARGV[5] $ARGV[6] $ARGV[7] $date >> $logfile"); } } } else { print "nishishui?\n"; if ( $val =~ $vale ) { #消息 my $msg="vcenter $ARGV[0] $title\_connect state:connected ok!\n $date"; my $sendmsg=uri_escape($msg); foreach my $phone(@OP_PHONE) { my $msgurl="http://192.168.6.13/fetion.php?phone=$phone&msg=$sendmsg"; get("$msgurl"); #日志 system("echo $phone $ARGV[0] $ARGV[1] $ARGV[2] $ARGV[3] $ARGV[4] $ARGV[5] $ARGV[6] $ARGV[7] $date >> $logfile"); } } else { #消息 my $msg="vcenter $ARGV[0] $title\_connect state:connected error!\n $date"; my $sendmsg=uri_escape($msg); foreach my $phone(@OP_PHONE) { my $msgurl="http://192.168.6.13/fetion.php?phone=$phone&msg=$sendmsg"; get("$msgurl"); #日志 system("echo $phone $ARGV[0] $ARGV[1] $ARGV[2] $ARGV[3] $ARGV[4] $ARGV[5] $ARGV[6] $ARGV[7] $date >> $logfile"); } } } } sub mon { my $string="$ARGV[6]"; my ($digit) = $string =~ /^(\d+)/; my $val="$digit"; my $vale="${title}vale"; my $vale=eval "\$$vale"; print "$vale\n"; print "$val\n"; sendmail($val,$vale); } sub mon_power { my $val="$ARGV[5]"; my $vale="${title}vale"; print "$vale\n"; my $vale=eval "\$$vale"; print "vale=$vale\n"; print "val=$val\n"; sendmail($val,$vale); } sub mon_all { if ($title=~"power") { mon_power(); print "\nit is $title"; } else { mon(); print "\nit is not power"; } } mon_all()