B
bgying
Unregistered / Unconfirmed
GUEST, unregistred user!
我新建了一个服务, 用于监控远程Web服务和其连接的数据库服务器的状态,
有关服务的建立和 CoInitialize(nil);
CoUnInitialize;我都注意到了,
正当我高兴的时候,发现如果我把被监控的asp改名或删除 那个mshttp都还是认为是以前的,
视若不见!But, 如果以前asp文件名不对, 当改名为正确的后却可以捕捉到!,但再改
成不正确的文件后却又捕捉不到了!
涉及到线程的同步吗?
下面是代码:
procedure Tthread_SYS.SysWatchUrl;
var
hh,mm,ss,ms:word;
str:string;
begin
TestHTTP := Txmlhttp40.Create(nil);
CoInitialize(nil);
try
TestHTTP.Connect;
except
on E: Exceptiondo
writelog(E.Message);
end;
TestHTTP.open('GET', Sys_Watch_URL, false);
TestHTTP.send();
ret1:=TestHTTP.responseText;
lastiswrong := iswrong;
if TestHTTP.status = 404 then
begin
wrong_msg :='SysWatch File Not found! Code:404, Time:' + datetimetostr(now());
iswrong :=true;
end;
if TestHTTP.status = 500 then
begin
wrong_msg := 'Sys Wrong Code:500, Time:' + datetimetostr(now());
lastiswrong := iswrong;
iswrong :=true;
end;
if ret1 = 'OK' then
iswrong := false;
if (pos('ERR',ret1)>0) then
begin
iswrong := true;
wrong_msg :=ret1 + ' Time:' + datetimetostr(now());
end;
if ret1 = '' then
begin
iswrong :=true;
wrong_msg :='SysWatch File Not found! Code:404, Time:' + datetimetostr(now());
end;
if lastiswrong then
str := 'lastiswrong:TRUE;'
else
str := 'lastiswrong:FALSE;';
if iswrong then
str := str + 'iswrong:TRUE Time:'
else
str := str + 'iswrong:FALSE Time:';
writelog(str + datetimetostr(now));
if not lastiswrong and iswrong then
begin
StartA:=now();
writeLog(wrong_msg);
//Send_Mobile_Msg(wrong_msg);
end
else
if lastiswrong and not iswrong then
begin
EndA:=now();
DecodeTime(EndA - StartA, hh, mm, ss, ms);
WriteLog('系统故障排除,恢复正常。Time:' + datetimetostr(now()) + ',累计时间:' +inttostr(hh)+ ':' + inttostr(mm) + ':' + inttostr(ss));
//Send_Mobile_Msg('System come back to running in gear.Time:' + datetimetostr(now()) + ',TotalTime:' +inttostr(hh)+ ':' + inttostr(mm) + ':' + inttostr(ss));
end;
TestHTTP.Disconnect;
TestHTTP.Destroy;
CoUnInitialize;
end;
有关服务的建立和 CoInitialize(nil);
CoUnInitialize;我都注意到了,
正当我高兴的时候,发现如果我把被监控的asp改名或删除 那个mshttp都还是认为是以前的,
视若不见!But, 如果以前asp文件名不对, 当改名为正确的后却可以捕捉到!,但再改
成不正确的文件后却又捕捉不到了!
涉及到线程的同步吗?
下面是代码:
procedure Tthread_SYS.SysWatchUrl;
var
hh,mm,ss,ms:word;
str:string;
begin
TestHTTP := Txmlhttp40.Create(nil);
CoInitialize(nil);
try
TestHTTP.Connect;
except
on E: Exceptiondo
writelog(E.Message);
end;
TestHTTP.open('GET', Sys_Watch_URL, false);
TestHTTP.send();
ret1:=TestHTTP.responseText;
lastiswrong := iswrong;
if TestHTTP.status = 404 then
begin
wrong_msg :='SysWatch File Not found! Code:404, Time:' + datetimetostr(now());
iswrong :=true;
end;
if TestHTTP.status = 500 then
begin
wrong_msg := 'Sys Wrong Code:500, Time:' + datetimetostr(now());
lastiswrong := iswrong;
iswrong :=true;
end;
if ret1 = 'OK' then
iswrong := false;
if (pos('ERR',ret1)>0) then
begin
iswrong := true;
wrong_msg :=ret1 + ' Time:' + datetimetostr(now());
end;
if ret1 = '' then
begin
iswrong :=true;
wrong_msg :='SysWatch File Not found! Code:404, Time:' + datetimetostr(now());
end;
if lastiswrong then
str := 'lastiswrong:TRUE;'
else
str := 'lastiswrong:FALSE;';
if iswrong then
str := str + 'iswrong:TRUE Time:'
else
str := str + 'iswrong:FALSE Time:';
writelog(str + datetimetostr(now));
if not lastiswrong and iswrong then
begin
StartA:=now();
writeLog(wrong_msg);
//Send_Mobile_Msg(wrong_msg);
end
else
if lastiswrong and not iswrong then
begin
EndA:=now();
DecodeTime(EndA - StartA, hh, mm, ss, ms);
WriteLog('系统故障排除,恢复正常。Time:' + datetimetostr(now()) + ',累计时间:' +inttostr(hh)+ ':' + inttostr(mm) + ':' + inttostr(ss));
//Send_Mobile_Msg('System come back to running in gear.Time:' + datetimetostr(now()) + ',TotalTime:' +inttostr(hh)+ ':' + inttostr(mm) + ':' + inttostr(ss));
end;
TestHTTP.Disconnect;
TestHTTP.Destroy;
CoUnInitialize;
end;