?
Solved

Is there any way we can schedule events to alerts.

Posted on 2007-09-30
17
Medium Priority
?
247 Views
Last Modified: 2010-04-16
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
0
Comment
Question by:bsharath
  • 8
  • 4
  • 2
  • +2
17 Comments
 
LVL 58

Expert Comment

by:tigermatt
ID: 19986852
This EE question seems to relate to you're talking about: http://www.experts-exchange.com/OS/Miscellaneous/Q_21399340.html#a13863496

-tigermatt
0
 
LVL 22

Expert Comment

by:65td
ID: 19986857
Download and configure filters and send method using eventreporter or something similar.

http://www.adiscon.com/Common/en/News/EventReporter-2007-08-22.php
0
 
LVL 58

Expert Comment

by:tigermatt
ID: 19986862
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:ghostdog74
ID: 19988803
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
0
 
LVL 11

Author Comment

by:bsharath
ID: 19988840
Hi,.
What are the changes i need to do.?
0
 
LVL 9

Expert Comment

by:ghostdog74
ID: 19989034
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
0
 
LVL 11

Author Comment

by:bsharath
ID: 19989085
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
0
 
LVL 9

Expert Comment

by:ghostdog74
ID: 19990037
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.
0
 
LVL 11

Author Comment

by:bsharath
ID: 20032355
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.

0
 
LVL 11

Author Comment

by:bsharath
ID: 20032474
I have been just running the bat file should i schedule it and wait for an event to generate to check.?
0
 
LVL 11

Author Comment

by:bsharath
ID: 20039858
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...
0
 
LVL 9

Expert Comment

by:ghostdog74
ID: 20040940
bsharath, pls check your event logs with the event viewer...check those of 8226, are there many of such events?
0
 
LVL 11

Author Comment

by:bsharath
ID: 20041185
Hi,

I even changed the event loggs but no luck
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 20054701
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.
0
 
LVL 11

Author Comment

by:bsharath
ID: 20054776
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...
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 2000 total points
ID: 20062506
Sure, try this (untested) code:

'==============
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

Set objFSO = CreateObject("Scripting.FileSystemObject")

strMessageFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "MsgFile.txt"
strBlatPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "Blat.exe"
strRecipient = "someone@somewhere.com"
strSMTPServer = "SMTPServerName"

strBlatPath = objFSO.GetFile(strBlatPath).ShortPath
Set objOutputFile = objFSO.CreateTextFile(strMessageFile, True)
objOutputFile.Write MSG
objOutputFile.Close
Set objOutputFile = Nothing
strMessageFile = objFSO.GetFile(strMessageFile).ShortPath
strCommand = "cmd /c " & strBlatPath & " " & strMessageFile & " -to " & strRecipient & " -server " & strSMTPServer
Set objShell = CreateObject("WScript.Shell")
objShell.Run strCommand, 1, True
'==============

Regards,

Rob.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick step-by-step overview of installing and configuring Carbonite Server Backup.
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question