This script checks the alert log for ORA-errors, transfers it to a local directory, and outputs the results to a file. There is no difference between a critical and a warning at this point. It should be noted that certain ORA-errors have been filtered out; you can add more to prevent false alarms.
# Script to send a mail if a ora error found. Called by alert_check.ps1#$EmailFrom = "hostname@client.com.au"$EmailTo = "someone@somewhere.com.au"$Subject = "CLIENT:PROD HOST:SID:Tablespace Space:WARNING"$Body = "ORA error or warning are foud"$SMTPServer = "client.smtp.com.au"$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("mail_username", "password");$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
This script checks the alert log for ORA-errors, transfers it to a local directory, and outputs the results to a file. There is no difference between a critical and a warning at this point. It should be noted that certain ORA-errors have been filtered out; you can add more to prevent false alarms.
Powershell script:
cd D:\scripts Remove-Item -Path "D:\scripts\logs\old_errors.txt" Rename-Item -Path "D:\scripts\logs\errors.txt" -NewName "D:\scripts\logs\old_errors.txt" Copy-Item -path "\quantumdb\diag\rdbms\cctl\cctl\trace\alert_cctl.log" -Destination "D:\scripts\logs" Get-Content .\logs\alert_cctl.log | Select-String -Pattern ORA- -Context 1,1 >.\logs\ora_errors.txt Get-Content .\logs\ora_errors.txt | Select-String -Pattern "ORA-2000|ORA-12609" -NotMatch >.\logs\errors_temp.txt Get-Content .\logs\errors_temp.txt | Select-String -Pattern ORA -Context 1,1 >.\logs\errors.txt Compare-Object (Get-Content "D:\scripts\logs\old_errors.txt") (Get-Content "D:\scripts\logs\errors.txt") | format-list | Out-File "D:\scripts\logs\new_errors.txt" if ($(get-item -path D:\scripts\logs\new_errors.txt).length -gt 2) {invoke-expression -Command .\sendmail_alert_log_att.ps1}
Save it as alert_check.ps1
Create batch file
Powershell.exe -Command "& 'D:\scripts\alert_check.ps1'"
save it as alert_log.bat
Create Email script
# Script to send a mail if a ora error found. Called by alert_check.ps1 # $EmailFrom = "hostname@client.com.au" $EmailTo = "someone@somewhere.com.au" $Subject = "CLIENT:PROD HOST:SID:Tablespace Space:WARNING" $Body = "ORA error or warning are foud" $SMTPServer = "client.smtp.com.au" $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25) $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("mail_username", "password"); $SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)