從 VPX_TASK 中抓取 Clone VM 的動作

2013-11-06 10:59
#!/usr/bin/perl
use LWP;
use URI::Escape;
use Time::Local;
use Time::localtime;
 
 
#my $vmlog = 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,';
 
my $vmlog = 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, - 600, GETDATE()) AND [NAME] like '%clone'" -W -s,|;
 
print $vmlog;
 
 
HttpSendMsg('https://172.30.0.87:16888/smsmt/sendAlarm.jsp','2000','400',vmclone,'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;
}