You can chosse nay name say eventlog_monitor.vbs.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate, (Security)}!\\" & _
strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("Select * from __instancecreationevent where " _
& "TargetInstance isa 'Win32_NTLogEvent' " _
& "and TargetInstance.EventCode = '1002' ")
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
strAlertToSend = objLatestEvent.TargetInstance.User _
& "ALERT!!! Event 1002 Siebel Application Crash file has been generated."
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "eventemailnotifier@test.org"
objEmail.To = "test@test.org"
objEmail.cc = "test@test.org"
objEmail.Subject = "TESTSERVER logged event ID 1002, crash file generated"
objEmail.Textbody = "On TESTSERVER an event ID 1002 has been logged and a crash file has been generated. TO check the crash file click on the attached link and this will bring you to the BIN directory where the crash file resides."
objEmail.AddAttachment "C:\bin.lnk"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"smarthost.smarthost.com"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
Loop
__________
===============================================================================
This is an alternative of the mentioned code. But I prefer the first one.
Create the first file event.vbs
_________________event.vbs________________________ ________
strComputer = "sbappdev01"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate, (Security)}!\\" & _
strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("Select * from __instancecreationevent where " _
& "TargetInstance isa 'Win32_NTLogEvent' " _
& "and TargetInstance.EventCode = '1002' ")
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
strAlertToSend = objLatestEvent.TargetInstance.User _
& "ALERT!!! Event 1002 Siebel Application Crash file has been generated."
Wscript.Echo strAlertToSend
Loop
_________________event.vbs________________________ ________
Create the second file email.vbs
_________________email.vbs________________________ ________
'**************************************
' Name: A++ Send Lotus Notes Email VBS S
' cript
' Description:Simple script to send a Lo
' tus Notes email. Can be modified to auto
' mate tasks on the server.
' By: Steven Jacobs
'
'This code is copyrighted and has ' limited warranties.Please see http://w
' ww.Planet-Source-Code.com/vb/scripts/Sho
' wCode.asp?txtCodeId=8815&lngWId=4 'for details. '**************************************
On Error Goto 0: sendLNMail()
Dim s
Dim db
Dim doc
Dim rtitem
Dim subj
Dim bdy
Dim recips(2)
'File System Object Decs
Dim fs
Dim fName
Dim path
Sub sendLNMail()
On Error Resume Next
'///////////////////////////////////////
' ////////////////////////////////
'Begin Error/Input Routines
'Created by Steven Jacobs
'2004
'///////////////////////////////////////
' ////////////////////////////////
'Get subject...if no subject, exit sub
subj = "Siebel Crash File"
if subj = "test" Then
MsgBox "You need a subject"
Exit Sub
End if
'Get body text...if no body text, exit s
' ub
bdy = "On Servertest Event ID 1002 has been logged, a crash file has been created in the BIN directory. Click on the attached link to open the BIN directory"
if bdy = "test" Then
MsgBox "You need body text"
Exit Sub
End if
Set fs = createobject("Scripting.FileSystemObject")
if fs Is Nothing Then
MsgBox "Could Not Create FileSystemObject",16,"File System Object Error."
endMe
Exit Sub
End if
fName = "C:\bin.lnk"
if fName = "" Then
MsgBox "Empty Path"
endMe
Exit Sub
End if
path = fs.GetAbsolutePathName(fName)
if Not fs.FileExists(path) Then
MsgBox "File does Not exist In directory you specified"
endMe
End if
'///////////////////////////////////////
' ////////////////////////////////
'End Error/Input Routines
'///////////////////////////////////////
' ////////////////////////////////
Set s = createobject("Notes.NotesSession")
if s Is Nothing Then
MsgBox "Could Not Create A Session Of Notes",16,"Notes Session Error."
endMe
Exit Sub
End if
'See if we can create the main object (s
' ession)
if Err.Number <> 0 Then
On Error Goto 0
MsgBox "Could Not create session 'Lotus Notes' from object"
Exit Sub
End if
Set db = s.getdatabase(s.getenvironmentstring("MailServer",True),s.getenvironmentstring("Mailfile",true))
'See if we can a handle on the mail file
'
if Err.Number <> 0 Then
On Error Goto 0
MsgBox "Could find or Get a handle on the mail file"
Exit Sub
End if
Set doc = db.createdocument
Set rtitem = doc.createrichtextitem("BODY")
recips(1) = "yourname@yourname.org"
recips(2) - "yourname@yourname.org"
With doc
.form = "Memo"
.subject = subj
.sendto = "
.postdate = Date
End With
call rtitem.embedobject(1454,"",fName)
doc.visible = True
doc.send False
'if we made it this far, alert the user
' the mail memo has been created and sent
endMe
End Sub
Sub endMe()
'clean objects/memory
Set s = nothing
Set db = nothing
Set doc = nothing
Set rtitem = nothing
Set fs = nothing
End Sub
_________________email.vbs________________________ ________
Create a bat file to execute the scripts in order, say log_execute.bat
=================
EX.
@ECHO OFF
Call event.vbs
Call email.vbs
=================
No comments:
Post a Comment