Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Is there any way we can schedule events to alerts.

Hi,

IS THERE A WAY THAT WE BE ALERTED BY A MAIL WHEN THERE IS A SPECIFIC EVENT iD...iS THERE A WAY TO BE INFORMED...wHEN THERE IS SAY "528" THEN I HAVE TO RECEIVE A MAIL...

REGARDS
SHARATH
Avatar of tigermatt
tigermatt
Flag of United Kingdom of Great Britain and Northern Ireland image

Download and configure filters and send method using eventreporter or something similar.

http://www.adiscon.com/Common/en/News/EventReporter-2007-08-22.php
Avatar of ghostdog74
ghostdog74

here's a vbscript:

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

Set colLoggedEvents = objWMIService.ExecQuery _
    ("Select * from Win32_NTLogEvent Where Logfile = 'Application'")

For Each objEvent in colLoggedEvents
    If objEvent.EventCode = "1000" Then
          Wscript.Echo "Category: " & objEvent.Category
          Wscript.Echo "Computer Name: " & objEvent.ComputerName         
          Wscript.Echo "Message: " & objEvent.Message
          Wscript.Echo "Record Number: " & objEvent.RecordNumber
          Wscript.Echo "Source Name: " & objEvent.SourceName
          Wscript.Echo "Time Written: " & objEvent.TimeWritten
          Wscript.Echo "Event Type: " & objEvent.Type
          Wscript.Echo "User: " & objEvent.User
          MSG = objEvent.Category & vbCrLf & objEvent.ComputerName      & vbCrLf & objEvent.Type & _
          objEvent.User & vbCrLf & objEvent.User & vbcrlf
          
    End If
    sendEmail(MSG)
Next

Sub sendEmail(msg)
      On Error Resume Next
      RCP = "emailaddress"
      SUBJECT = "subject"      
      Set Outlook = CreateObject("Outlook.Application")
      Set MAPI = Outlook.GetNameSpace("MAPI")
      Set NewMail = Outlook.CreateItem(0)
      NewMail.Subject = SUBJECT
      NewMail.Body = msg
      NewMail.Recipients.Add RCP      
      MAPI.Logon "profile", "password"
      NewMail.Send
      MAPI.Logoff
End Sub
Avatar of bsharath

ASKER

Hi,.
What are the changes i need to do.?
hi sometimes you may not have outlook..so you may want to try command line email client like blat. http://www.i386.info/software/blat189.zip.


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

' you need to change here, for specific event logs you want to search. eg Application, Security etc
Set colLoggedEvents = objWMIService.ExecQuery _
    ("Select * from Win32_NTLogEvent Where Logfile = 'Application'")

For Each objEvent in colLoggedEvents
    If objEvent.EventCode = "528" Then
          'Wscript.Echo "Category: " & objEvent.Category
          'Wscript.Echo "Computer Name: " & objEvent.ComputerName        
          'Wscript.Echo "Message: " & objEvent.Message
          'Wscript.Echo "Record Number: " & objEvent.RecordNumber
          'Wscript.Echo "Source Name: " & objEvent.SourceName
          'Wscript.Echo "Time Written: " & objEvent.TimeWritten
          'Wscript.Echo "Event Type: " & objEvent.Type
          'Wscript.Echo "User: " & objEvent.User
          MSG = objEvent.Category & vbCrLf & objEvent.ComputerName      & vbCrLf & objEvent.Type & _
          objEvent.User & vbCrLf & objEvent.User & vbcrlf
          Wscript.Echo  MSG   'MSG is just the entire alert message you want to send thru email
    End If
Next

in MSDOS batch:

@echo off
cscript /nologo myscript.vbs > newfile
blat [ see the blat help for syntax ] newfile
Hi,

I have blat.exe in the c:\
Where should i mention the email id?
Even 528 is for when a user connects through Mstsc.Am i right.
Can you set the script according to the event.So that i can test to understand..
Should i create a bat file later with this code.?
@echo off
cscript /nologo myscript.vbs > newfile
blat [ see the blat help for syntax ] newfile
hi
a slight amendment:

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

' you need to change here, for specific event logs you want to search. eg Application, Security etc
Set colLoggedEvents = objWMIService.ExecQuery _
    ("Select * from Win32_NTLogEvent Where Logfile = 'Application'")
MSG=""
For Each objEvent in colLoggedEvents
    If objEvent.EventCode = "1800" Then
          'Wscript.Echo "Category: " & objEvent.Category
          'Wscript.Echo "Computer Name: " & objEvent.ComputerName        
          'Wscript.Echo "Message: " & objEvent.Message
          'Wscript.Echo "Record Number: " & objEvent.RecordNumber
          'Wscript.Echo "Source Name: " & objEvent.SourceName
          'Wscript.Echo "Time Written: " & objEvent.TimeWritten
          'Wscript.Echo "Event Type: " & objEvent.Type
          'Wscript.Echo "User: " & objEvent.User
          MSG = MSG & vbCrLf & objEvent.Category & vbCrLf & objEvent.ComputerName & vbCrLf & objEvent.Type & _
          objEvent.User & vbCrLf & objEvent.User & vbcrlf
         
    End If
   
Next
Wscript.Echo  MSG   'MSG is just the entire alert message you want to send thru email


in the DOS batch file:

@echo off
cscript /nologo myscript.vbs > file_to_send
blat file_to_send  -to somewhere@outthere.com -server <yoursmtpserver>

Please read the blat documents for usage and syntax. also make sure you have SMTP server set up in your environment.
Hi,

I have changed this line.

    If objEvent.EventCode = "8226" Then
And created a bat file with the blat commands as mentioned by you.
I get a file creates and the data is like this.

0
DEV-CHEN-MRD100
Error

Say 100's of same data.

I have been just running the bat file should i schedule it and wait for an event to generate to check.?
Any help ....

tigermatt the links that you have posted is not complete and no one has tryed and suceeded.
So can i get any more option.I dont want software andy scripts that can do this...

ghostdog74 i think we are in some stage but not able figure why i dont get an alert...
bsharath, pls check your event logs with the event viewer...check those of 8226, are there many of such events?
Hi,

I even changed the event loggs but no luck
Sharath, try this script:

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

' you need to change here, for specific event logs you want to search. eg Application, Security etc
Set colLoggedEvents = objWMIService.ExecQuery _
    ("Select * from Win32_NTLogEvent Where Logfile = 'Application' AND EventCode = '8226'")
MSG=""
For Each objEvent in colLoggedEvents
      MSG = MSG & vbCrLf & _
            "Category: " & objEvent.Category & vbCrLf & _
            "Computer: " & objEvent.ComputerName & vbCrLf & _
            "Event Type: " & objEvent.Type & VbCrLf & _
            "Username: " & objEvent.User & vbCrLf
Next
Wscript.Echo  MSG
'==============

Regards,

Rob.
Rob can the same be logged to a file and even send a mail.
So that i can schedule this to run every 1 hr or so...
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial