Announcement

Collapse
No announcement yet.

script to monitor specific event log then send email to users

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • script to monitor specific event log then send email to users

    OK so far i have a script that gives me a pop up message when the specific event is logged. what i need is when this event is logged for an email to be sent to specific users. what i have so far is below, any help would be appreciated

    __________________________________________________ ____________
    strComputer = "testcomputer"
    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 = '0' ")
    Do
    Set objLatestEvent = colMonitoredEvents.NextEvent
    strAlertToSend = objLatestEvent.TargetInstance.User _
    & " Siebel Application Crash file has been generated."
    Wscript.Echo strAlertToSend
    Loop
    __________________________________________________ ____________

  • #2
    Re: script to monitor specific event log then send email to users

    I think BMail, mentioned in another thread in this forum, might solve you the problem.
    What do you think?

    Sorin Solomon


    In order to succeed, your desire for success should be greater than your fear of failure.
    -

    Comment


    • #3
      Re: script to monitor specific event log then send email to users

      ok so far what I have is two work parts, now i need to get them together.

      First i have a script that notifies you when a particular event is logged(event.vbs). the second part is a script that send a specified message to a specific recipient(email.vbs). How can i run the the email.vbs file from the events.vbs when it finds this event has been logged.

      _________________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________________________ ________

      some how i want this email.vbs to be loading in or from the event.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) = "[email protected]"
      recips(2) - "[email protected]"
      With doc
      .form = "Memo"
      .subject = subj
      .sendto = "<[email protected]"
      .body = bdy
      .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________________________ ________

      any help would be appreciated, i have attached both files for your viewing
      Attached Files

      Comment


      • #4
        Re: script to monitor specific event log then send email to users

        Use a bat script to call the scripts.

        EX.

        @ECHO OFF
        Call event.vbs
        Call email.vbs

        This way email.vbs will wait till event.vbs is completly done.

        Comment


        • #5
          Re: script to monitor specific event log then send email to users

          I got it to work, used pieces from different places the script is below.

          __________________________script__________________ _______________
          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 = "[email protected]"
          objEmail.To = "[email protected]"
          objEmail.cc = "[email protected]"
          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
          __________________________script__________________ _______________


          works pretty good, it monitors events in real time and when the specific event occurs the selected reciepents recieve an email.

          It works almost too good because now my supervisor want to just get on or two notifications a day with a count of how many times the event has occured.

          Comment

          Working...
          X