0

我有一个 Windows 2003 Server,它使用 IIS 来托管旧版 ASP.NET Web 服务,该服务连接到我无法控制的远程 Oracle 数据库服务器上的数据库。问题是数据库服务器每隔一两周就会关闭一次,但大约 5 分钟后就会恢复。然后,我必须重新启动 IIS 以删除任何损坏的连接,然后我的 Web 服务才能再次工作。

当发生特定错误代码(在这种情况下,它将是 ORA 类型错误,但我可以获得 Windows 错误代码)时,触发事件的最佳方法是什么(即给我自己发送电子邮件和/或重置 IIS)?

IIS设置?

任务调度器?(仅限于计划任务,我相信在 Windows 2003 服务器上,例如每天/每周/每月等)

Powershell脚本?

其他选择?

我知道在 Windows 2008 Server 中,您可以配置任务计划程序以在服务器在其错误日志中遇到某些错误代码时触发事件......但我在 Windows 2003 Server 的任务计划程序中找不到类似的东西。

谢谢。

4

1 回答 1

0

我编写了一个 powershell shell 脚本来监控 sql server 错误日志并报告特定错误。我存储了上次停止阅读的位置,然后在下次运行脚本时从该点继续。这是实际读取日志的部分。然后,您只需将位置存储在某个临时文件中并将其作为计划任务运行。如果发生错误甚至重新启动某些服务,请发送电子邮件。

$path = $logs.file
Write-Host $path
if($currentLog.lastpos -ne $null){$pos = $currentLog.lastpos}
else{$pos = 0}
if($logs.enc -eq $null){$br = New-Object System.IO.BinaryReader([System.IO.File]::Open($path, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::ReadWrite))}
else{
    $encoding = $logs.enc.toUpper().Replace('-','')
    if($encoding -eq 'UTF16'){$encoding = 'Unicode'}
    $br = New-Object System.IO.BinaryReader([System.IO.File]::Open($path, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::ReadWrite), [System.Text.Encoding]::$encoding)
}
$required = $br.BaseStream.Length - $pos
if($required -lt 0){
    $pos = 0
    $required = $br.BaseStream.Length
}
if($required -eq 0){$br.close(); return $null}
$br.BaseStream.Seek($pos, [System.IO.SeekOrigin]::Begin)|Out-Null
$bytes = $br.ReadBytes($required)
$result = [System.Text.Encoding]::Unicode.GetString($bytes)
$split = $result.Split("`n")
foreach($s in $split)
{
    if($s.contains("  Error:"))
    {
        #Filter events here
    }
}
$currentLog.lastpos = $br.BaseStream.Position 
$br.close()
于 2012-07-13T10:28:13.870 回答