none
Envio de log por email RRS feed

  • Pergunta

  •  

    Pessoal, tenho o script abaixo e funciona, só que eu gostaria que ele me enviasse o log mais recente, só que ele me envia apenas o primeiro log no caso antigo.

     

    '##################################### script envio de log backup###############################

     

    strComputer = "."
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set objEmail = CreateObject("CDO.Message")

     

    '### Coleta informacoes do event viewer ###

     

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

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

    For Each objEvent in colLoggedEvents

       
        Body = "Computer Name: " & objEvent.ComputerName & vbcrlf
        Body = Body & "Event Code: " & objEvent.EventCode & vbcrlf
        Body = Body & "Event Type: " & objEvent.Type & vbcrlf
        Body = Body & "Time Written: " & objEvent.TimeWritten & vbcrlf
        Body = Body & "Message: " & objEvent.Message & vbcrlf

    Next

    wscript.echo body

     

    '##### ENVIA EMAIL#####

     

    Set objEmail = CreateObject("CDO.Message")

    objEmail.From = xxxx@xxx.com.br
    objEmail.Subject = "Backup"
    objEmail.To = xxxx@xxx.com.br
    objEmail.Textbody = Body
    objEmail.Configuration.Fields.Update
    objEmail.Send

    '#############################################FIM#####################################

     

     

    Obrigado!!!!

    sexta-feira, 18 de janeiro de 2008 18:25

Respostas

Todas as Respostas

  • Vinicius me de uma luz!!!

    terça-feira, 22 de janeiro de 2008 10:49
  • Bom dia Fabio, tudo bem cara ??

     

    Intão, referente a esse seu script, deu certo ja ??

     

    Outra coisa, ele funciona em qualquer software de backup ou só no backup do Windows ??

     

    Abs.

    quarta-feira, 23 de janeiro de 2008 13:08
  •  

    Esse script funciona em outro software se ele gerar um log no eventid no event viewer.
    quinta-feira, 24 de janeiro de 2008 10:25
  • Fabio, tenta desse jeito aqui.Wink, eu usava dessa forma para monitorar o event viewer e funcionava que era uma beleza Big Smile

    strComputer = "."
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set objEmail = CreateObject("CDO.Message")

    UltLogon = ""

    '### Coleta informacoes do event viewer ###

     

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

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

    For Each Newlog in colLoggedEvents

    If Newlog.timewritten > UltLogon then

        Body = "Computer Name: " & objEvent.ComputerName & vbcrlf
        Body = Body & "Event Code: " & objEvent.EventCode & vbcrlf
        Body = Body & "Event Type: " & objEvent.Type & vbcrlf
        Body = Body & "Time Written: " & objEvent.TimeWritten & vbcrlf
        Body = Body & "Message: " & objEvent.Message & vbcrlf

    end if

    next

    wscript.echo body

     

    '##### ENVIA EMAIL#####

     

    Set objEmail = CreateObject("CDO.Message")

    objEmail.From = xxxx@xxx.com.br
    objEmail.Subject = "Backup"
    objEmail.To = xxxx@xxx.com.br
    objEmail.Textbody = Body
    objEmail.Configuration.Fields.Update
    objEmail.Send

    '#############################################FIM#####################################

    quinta-feira, 24 de janeiro de 2008 15:14
  • Laerte, agradeço por me ajudar,

     

    Na execução ocorreu um erro:

     

    linha:23

    Erro: Objeto Necessário: 'ObjEvent'

     

    Grato!

     

    quinta-feira, 24 de janeiro de 2008 18:35
  • Laerte, corrigi a mensagem de erro adcionando a linha que esta em negrito no script, só que ele me enviou todos os logs 8019, e não só o ultimo, sabe o que pode ser??

     

    Grato.

    strComputer = "."
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set objEmail = CreateObject("CDO.Message")

    UltLogon = ""

    '### Coleta informacoes do event viewer ###

     

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

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

     

    For Each objEvent in colLoggedEvents

    For Each Newlog in colLoggedEvents

    If Newlog.timewritten > UltLogon then

        Body = "Computer Name: " & objEvent.ComputerName & vbcrlf
        Body = Body & "Event Code: " & objEvent.EventCode & vbcrlf
        Body = Body & "Event Type: " & objEvent.Type & vbcrlf
        Body = Body & "Time Written: " & objEvent.TimeWritten & vbcrlf
        Body = Body & "Message: " & objEvent.Message & vbcrlf

    end if

    next

    wscript.echo body

     

    '##### ENVIA EMAIL#####

     

    Set objEmail = CreateObject("CDO.Message")

    objEmail.From = xxxx@xxx.com.br
    objEmail.Subject = "Backup"
    objEmail.To = xxxx@xxx.com.br
    objEmail.Textbody = Body
    objEmail.Configuration.Fields.Update
    objEmail.Send

    '#############################################FIM#####################################

    quinta-feira, 24 de janeiro de 2008 18:50
  • Fabio desculpa, já vi o erro aqui, só altera isso aqui no seu script que vai funcionar Wink

     

    If Newlog.timewritten > UltLogon then

        Body = ""

        Body = "Computer Name: " & objEvent.ComputerName & vbcrlf
        Body = Body & "Event Code: " & objEvent.EventCode & vbcrlf
        Body = Body & "Event Type: " & objEvent.Type & vbcrlf
        Body = Body & "Time Written: " & objEvent.TimeWritten & vbcrlf
        Body = Body & "Message: " & objEvent.Message & vbcrlf

    end if

    quinta-feira, 24 de janeiro de 2008 20:13
  •  

    Laerte, desculpe o enchimento de saco, mas ainda apresentou mensagem de erro. segue o script abaixo.

     

    strComputer = "."
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set objEmail = CreateObject("CDO.Message")

    UltLogon = ""

    '### Coleta informacoes do event viewer ###

     

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

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

     

    For Each objEvent in colLoggedEvents
    For Each Newlog in colLoggedEvents
    If Newlog.timewritten > UltLogon then

        Body = ""

        Body = "Computer Name: " & objEvent.ComputerName & vbcrlf
        Body = Body & "Event Code: " & objEvent.EventCode & vbcrlf
        Body = Body & "Event Type: " & objEvent.Type & vbcrlf
        Body = Body & "Time Written: " & objEvent.TimeWritten & vbcrlf
        Body = Body & "Message: " & objEvent.Message & vbcrlf

    end if

    next

    wscript.echo body

    '##### ENVIA EMAIL#####


    Set objEmail = CreateObject("CDO.Message")

    objEmail.From = xxx@xxx.com
    objEmail.Subject = "log"
    objEmail.To = aaa@aaa.com
    objEmail.Textbody = Body
    objEmail.Configuration.Fields.Update
    objEmail.Send

     

     

     

    quinta-feira, 24 de janeiro de 2008 20:47
  • Fabio tenta agora, desculpe, tinha editado o script errado Wink, é que estou sem poder testar onde estou agora Big Smile

    strComputer = "."
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set objEmail = CreateObject("CDO.Message")

    UltLogon = ""

    '### Coleta informacoes do event viewer ###

     

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

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

     

    For Each objEvent in colLoggedEvents
    If objEvent.timewritten > UltLogon then

        Body = ""

        Body = "Computer Name: " & objEvent.ComputerName & vbcrlf
        Body = Body & "Event Code: " & objEvent.EventCode & vbcrlf
        Body = Body & "Event Type: " & objEvent.Type & vbcrlf
        Body = Body & "Time Written: " & objEvent.TimeWritten & vbcrlf
        Body = Body & "Message: " & objEvent.Message & vbcrlf

    end if

    next

    wscript.echo body

    '##### ENVIA EMAIL#####


    Set objEmail = CreateObject("CDO.Message")

    objEmail.From = xxx@xxx.com
    objEmail.Subject = "log"
    objEmail.To = aaa@aaa.com
    objEmail.Textbody = Body
    objEmail.Configuration.Fields.Update
    objEmail.Send

    quinta-feira, 24 de janeiro de 2008 21:05
  •  

    Laerte, não apresentou erros porem ele continua enviando o primeiro log(mais antigo) e não o mais recente.

     

    Grato!

    quinta-feira, 24 de janeiro de 2008 23:11
  • Fabio,a gora testado e funcionando Big Smile, testei aqui e funcionou Wink, tava faltando repreencher a variavel UltLogon

    strComputer = "."
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set objEmail = CreateObject("CDO.Message")

    UltLogon = ""

    '### Coleta informacoes do event viewer ###

     

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

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


    For Each objEvent in colLoggedEvents
    If objEvent.timewritten > UltLogon then

        Body = ""

        Body = "Computer Name: " & objEvent.ComputerName & vbcrlf
        Body = Body & "Event Code: " & objEvent.EventCode & vbcrlf
        Body = Body & "Event Type: " & objEvent.Type & vbcrlf
        Body = Body & "Time Written: " & objEvent.TimeWritten & vbcrlf
        Body = Body & "Message: " & objEvent.Message & vbcrlf
        UltLogon = objEvent.timewritten

    end if

    next

    wscript.echo body

    Set objEmail = CreateObject("CDO.Message")

    objEmail.From = xxx@xxx.com
    objEmail.Subject = "log"
    objEmail.To = aaa@aaa.com
    objEmail.Textbody = Body
    objEmail.Configuration.Fields.Update
    objEmail.Send

    sexta-feira, 25 de janeiro de 2008 11:22
  •  

    Laerte, Perfeito!!!!

     

    Obrigado pela atenção!!!!

     

    Abraços!!!

    sexta-feira, 25 de janeiro de 2008 12:15
  • Disponha, estamos ae para ajudar Wink, mas não esqueça de classificar a resposta Wink

    sexta-feira, 25 de janeiro de 2008 12:26
  • Laerte, gostaria de sua ajuda caso tenha tempo:

     

    Preciso de um log que apenas verifique diariamente a pasta Sistema para procurar pelo evento 6008 que é de desligamento incorreto e que fosse enviado para o meu email.

     

    Sou totalmente leigo em vbscript e se você puder me ajudar ficarei eternamente grato.

     

    Abraços

     

    Limajr

    sexta-feira, 14 de março de 2008 00:33
  • Adalberto segue script, testa ae Wink

    strComputer = "."
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set objEmail = CreateObject("CDO.Message")

    UltLogon = ""

    '### Coleta informacoes do event viewer ###

    data = right("00" & datepart("d",now()),2) & right("00" & datepart("m",now()),2) & datepart("yyyy",now())

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

    Set colLoggedEvents = objWMIService.ExecQuery _
            ("Select * from Win32_NTLogEvent Where Logfile = 'System' and " _
                & "EventCode = '6008'")


    For Each objEvent in colLoggedEvents

    datalog = mid(Newlog.timewritten, 7,2) & mid(Newlog.timewritten, 5,2) & mid(Newlog.timewritten, 1,4)

    If datalog = data  then

        Body = Body & "Message: " & objEvent.Message & vbcrlf
    end if

    next

    wscript.echo body

    Set objEmail = CreateObject("CDO.Message")

    objEmail.From = remetente

    objEmail.Subject = "log"
    objEmail.To = destinatario

    objEmail.Textbody = Body

    objEmail.Configuration.Fields.Item _
     ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    objEmail.Configuration.Fields.Item _
     ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
    "seu_servidor_de_smtp"
    objEmail.Configuration.Fields.Item _
     ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    objEmail.Configuration.Fields.Update
    objEmail.Configuration.Fields.Update
    objEmail.Send

    sexta-feira, 14 de março de 2008 19:29
  • Laerte,

     

    No windows XP o script funcionou perfeitamente sem erros, mas no 2003 server ele tá dando erro:

     

    Script:   c:\log.vbs

    Linha:   21

    Caract: 1

    Erro:     Objeto Necessário: 'Newlog'

    Código: 800A01A8

    Origem: Erro de tempo de execução Microsoft VBscript

     

    strComputer = "."
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set objEmail = CreateObject("CDO.Message")

    UltLogon = ""

    '### Coleta informacoes do event viewer ###

    data = right("00" & datepart("d",now()),2) & right("00" & datepart("m",now()),2) & datepart("yyyy",now())

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

    Set colLoggedEvents = objWMIService.ExecQuery _
            ("Select * from Win32_NTLogEvent Where Logfile = 'System' and " _
                & "EventCode = '6008'")


    For Each objEvent in colLoggedEvents

    datalog = mid(Newlog.timewritten, 7,2) & mid(Newlog.timewritten, 5,2) & mid(Newlog.timewritten, 1,4)

    If datalog = data  then

        Body = Body & "Message: " & objEvent.Message & vbcrlf
    end if

    next

    wscript.echo body


    Set objEmail = CreateObject("CDO.Message")

    objEmail.From = "limajr@hardservice.com.br"

    objEmail.Subject = "log"
    objEmail.To = "limajr@hardservice.com.br"

    objEmail.Textbody = Body

    objEmail.Configuration.Fields.Item _
     ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    objEmail.Configuration.Fields.Item _
     ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.hardservice.com.br"
    objEmail.Configuration.Fields.Item _
     ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    objEmail.Configuration.Fields.Update
    objEmail.Configuration.Fields.Update
    objEmail.Send

     

     

    Abraços

     

    Adalberto

    domingo, 16 de março de 2008 03:24
  • Adalberto, está concertado o erro Wink

     

    strComputer = "."
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set objEmail = CreateObject("CDO.Message")

    UltLogon = ""

    '### Coleta informacoes do event viewer ###

    data = right("00" & datepart("d",now()),2) & right("00" & datepart("m",now()),2) & datepart("yyyy",now())

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

    Set colLoggedEvents = objWMIService.ExecQuery _
            ("Select * from Win32_NTLogEvent Where Logfile = 'System' and " _
                & "EventCode = '6008'")


    For Each Newlog in colLoggedEvents

    datalog = mid(Newlog.timewritten, 7,2) & mid(Newlog.timewritten, 5,2) & mid(Newlog.timewritten, 1,4)

    If datalog = data  then

        Body = Body & "Message: " & Newlog.Message & vbcrlf
    end if

    next


    Set objEmail = CreateObject("CDO.Message")

    objEmail.From = "limajr@hardservice.com.br"

    objEmail.Subject = "log"
    objEmail.To = "limajr@hardservice.com.br"

    objEmail.Textbody = Body

    objEmail.Configuration.Fields.Item _
     ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    objEmail.Configuration.Fields.Item _
     ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.hardservice.com.br"
    objEmail.Configuration.Fields.Item _
     ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    objEmail.Configuration.Fields.Update
    objEmail.Configuration.Fields.Update
    objEmail.Send

     

    segunda-feira, 17 de março de 2008 00:21
  • Funcionou Perfeitamente agora!

     

    Sem querer abusar e ja abusando!!!! Smile

     

     

    Existe alguma maneira do script só enviar o email caso tenha o event id 6008?

     

     

    Abraços

     

    E mais uma vez Muito Obrigado!

     

    Adalberto Junior

     

    segunda-feira, 17 de março de 2008 23:49
  • Pronto Adalberto só envia se tiver alguma coisa registrada no evento Wink só não esqueça se a resposta lhe ajudou não esqueça de marca-la Wink

    strComputer = "."

    Body = ""
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set objEmail = CreateObject("CDO.Message")

    UltLogon = ""

    '### Coleta informacoes do event viewer ###

    data = right("00" & datepart("d",now()),2) & right("00" & datepart("m",now()),2) & datepart("yyyy",now())

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

    Set colLoggedEvents = objWMIService.ExecQuery _
            ("Select * from Win32_NTLogEvent Where Logfile = 'System' and " _
                & "EventCode = '6008'")


    For Each Newlog in colLoggedEvents

    datalog = mid(Newlog.timewritten, 7,2) & mid(Newlog.timewritten, 5,2) & mid(Newlog.timewritten, 1,4)

    If datalog = data  then

        Body = Body & "Message: " & Newlog.Message & vbcrlf
    end if

    next

    If Body <> "" then
    Set objEmail = CreateObject("CDO.Message")

    objEmail.From = "limajr@hardservice.com.br"

    objEmail.Subject = "log"
    objEmail.To = "limajr@hardservice.com.br"

    objEmail.Textbody = Body

    objEmail.Configuration.Fields.Item _
     ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    objEmail.Configuration.Fields.Item _
     ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.hardservice.com.br"
    objEmail.Configuration.Fields.Item _
     ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    objEmail.Configuration.Fields.Update
    objEmail.Configuration.Fields.Update
    objEmail.Send

    end if
    terça-feira, 18 de março de 2008 12:34