1

We currently have a Windows Server 2008 machine that we have configured with a Custom Task to send an email whenever an error occurs in a certain Event Log. The trigger works perfectly, and sends emails whenever we need them to.

HOWEVER, we cannot find a way to get the email to contain information about the error, particularly the error message. Is there any way to have the message change based on the contents of the event-log error?

2 Answers2

1

Maybe eventtriggers is your answer? I'm not too familiar with Server 2008 yet but I used to use eventtriggers all the time with 2003. Let's you do whatever you want since you can run any command or script you write.

http://www.petri.co.il/how-to-use-eventtriggersexe-to-send-e-mail-based-on-event-ids.htm

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/eventtriggers.mspx?mfr=true

Jordan W.
  • 1,403
  • 1
  • 13
  • 19
0

Use eventtriggers to trigger a VBscript to run. You can use a script like the following to send email with the recent errors, but I have not put this into production yet because it causes high CPU usage on the server in WMIPRVSE.EXE (I'm assuming this is the process that handles WMI queries).

WARNING: Following script causes high CPU usage and isn't ready for high usage/mission critical systems

strComputer = "."

Dim emailText
emailText = "An error has occurred on [server_name]. This email was generated by eventtriggers.exe on [server_name]. Run eventtriggers.exe /? at the command prompt on [server_name] for help with managing event triggers." & vbNewLine & vbNewLine & "Recent Errors:" & vbCrLf

Set objWMIService = GetObject("winmgmts:" _
  & "{impersonationLevel=impersonate}!\\" _
  & strComputer & "\root\cimv2")

Set colLoggedEvents = objWMIService.ExecQuery _
  ("Select * from Win32_NTLogEvent " _
    & "Where Type = 'Error'")

Dim count
count=0

For Each objEvent in colLoggedEvents
  emailText = emailText & "*****************************************************************************" & vbNewLine & vbNewLine & objEvent.Message & vbNewLine & vbNewLine
  count = count + 1
  If count > 4 then
    Exit For
  End If
Next

Set objEmail = CreateObject("CDO.Message")
objEmail.From = "server@company.com"
objEmail.To = "name@company.com"
objEmail.Subject = "Server Error"
objEmail.Textbody = emailText
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
        "[ENTER YOUR SERVER HERE]"
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send

Alternatively, check out this answer: Windows Event Log - email notification

Luke
  • 2,063
  • 7
  • 27
  • 30