bsharath
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
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
Download and configure filters and send method using eventreporter or something similar.
http://www.adiscon.com/Common/en/News/EventReporter-2007-08-22.php
http://www.adiscon.com/Common/en/News/EventReporter-2007-08-22.php
There's also this: https://www.experts-exchange.com/questions/21331384/Email-alerts-from-event-viewer.html
-tigermatt
-tigermatt
here's a vbscript:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper sonate}!\\ " & 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.Appl ication")
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
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper
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.Appl
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
ASKER
Hi,.
What are the changes i need to do.?
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=imper sonate}!\\ " & 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
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper
' 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
ASKER
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
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=imper sonate}!\\ " & 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.
a slight amendment:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper
' 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.
ASKER
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 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.
ASKER
I have been just running the bat file should i schedule it and wait for an event to generate to check.?
ASKER
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...
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?
ASKER
Hi,
I even changed the event loggs but no luck
I even changed the event loggs but no luck
Sharath, try this script:
'==============
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper sonate}!\\ " & 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.
'==============
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper
' 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.
ASKER
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...
So that i can schedule this to run every 1 hr or so...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Any help with these Q...'s
https://www.experts-exchange.com/questions/22886457/Event-retrieve-on-selected-dae-and-time-Pinging-Rob.html
https://www.experts-exchange.com/questions/22886392/Script-to-create-a-list-of-printers-and-have-a-no-selected-install-option.html
https://www.experts-exchange.com/questions/22864808/Any-way-to-Query-the-Ads-Users-properties-for-Mailbox-Rights.html
https://www.experts-exchange.com/questions/22863160/Need-to-change-the-sessions-tab-for-all-users-in-the-file.html
https://www.experts-exchange.com/questions/22886910/Need-to-create-a-survey-template-in-Ie-or-Outlook.html
https://www.experts-exchange.com/questions/22886457/Event-retrieve-on-selected-dae-and-time-Pinging-Rob.html
https://www.experts-exchange.com/questions/22886392/Script-to-create-a-list-of-printers-and-have-a-no-selected-install-option.html
https://www.experts-exchange.com/questions/22864808/Any-way-to-Query-the-Ads-Users-properties-for-Mailbox-Rights.html
https://www.experts-exchange.com/questions/22863160/Need-to-change-the-sessions-tab-for-all-users-in-the-file.html
https://www.experts-exchange.com/questions/22886910/Need-to-create-a-survey-template-in-Ie-or-Outlook.html
-tigermatt