監控 vCenter 的 Task 行為
2013-11-06 14:16
1. vmclone.pl
#!/usr/bin/perl
use LWP;
use URI::Escape;
use Time::Local;
use Time::localtime;
#my $vmclone = qx 'sqlcmd -Q "SELECT TOP 10 [TASK_ID],[NAME],[DESCRIPTIONID],[ENTITY_NAME],[COMPLETE_STATE],[QUEUE_TIME],[START_TIME],[COMPLETE_TIME],[USERNAME] FROM [VC].[dbo].[VPX_TASK]" -W -s,';
qx |sqlcmd -Q "SELECT dateadd(hour,8,[START_TIME]) as STARTTIME,[USERNAME], RIGHT([Name], 20) as ACTION ,[ENTITY_NAME],[COMPLETE_STATE] FROM [VC].[dbo].[VPX_TASK] WHERE [START_TIME] > DATEADD(MINUTE, - 485, GETDATE()) AND [NAME] like '%clone'" -W -s, -o c:\vmclone.txt|;
my $vmcount = 0;
$file = "c:\vmclone.txt";
open (GLOBAL, "$file") || die "$!n";
my @content = ;
close (GLOBAL);
foreach (@content)
{
if ( /[\dddd-dd-dd]/ and $_ != /!\(/ )
{
#print $_;
HttpSendMsg('https://172.30.0.87:16888/smsmt/sendAlarm.jsp','6927','400',$_,'BIG5');
}
}
sub HttpSendMsg
{
my($server,$group,$level,$msgbody,$encoding)=@_;
my($url)=sprintf('%s?grp=%s&level=%s&msg=%s&encoding=%s',
$server,$group,$level,uri_escape($msgbody),$encoding);
#print $url;
my($browser)=LWP::UserAgent->new() || return -99999;
my($webresult)=$browser->request(HTTP::Request->new(GET=>$url));
if (!$webresult->is_success)
{ #?¢G|¡L¢D\
my($statusline)=$webresult->status_line;
my($statuscode,$statustext)=$statusline=~/^(.*) (.*)$/;
return -100000-$statuscode;
}
my($msgid)=$webresult->content=~/^msgid= *([\d\-]+)\s/i;
return $msgid;
}
2. vmclone.bat
@ECHO OFF
CD C:\strawberry\perl\bin
START perl.EXE -w C:\vmclone.pl
EXIT