我有一台Windows 2003 Server,它使用IIS来托管传统的ASP.NET Web服务,该服务连接到我无法控制的远程Oracle数据库服务器上的数据库。问题是数据库服务器每两周都会出现故障,但大约5分钟后会恢复。在我的Web服务再次运行之前,我必须重新启动IIS以删除任何损坏的连接。
在发生特定错误代码时触发事件(即通过电子邮件发送自己和/或重置IIS)的最佳方法是什么(在这种情况下,它将是ORA类型错误,但我可以获取Windows错误代码) ?
IIS设置?
任务计划程序? (仅限于计划任务我相信Windows 2003服务器,例如每天/每周/每月等)
Powershell Script?
其他选择?
我知道在Windows 2008 Server中,您可以将任务计划程序配置为在服务器的错误日志中遇到某些错误代码时触发事件...但我在Windows 2003的任务计划程序中找不到这样的内容服务器
感谢。
答案 0 :(得分:0)
我写了一个powershell shell脚本来监视sql server errorlog并报告特定错误。我存储了上次停止阅读的位置,然后在下次运行脚本时从那一点开始继续。这是实际读取日志的部分。然后,您只需将位置存储在某个临时文件中,并将其作为计划任务运行。如果发生错误,请发送电子邮件,甚至重新启动某些服务。
$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()