L'auteur
Mike Gagnon Canada Membre Simple # 0000000025 enregistré le 14/10/2004 Gagnon Mike Pointe Cla H9R 3K8 de la société Carver Technologies Inc. Fiche personnelle
Note des membres
pas de note
Contributions > 09 - Automation > WMI (Windows Management Instrumentation)
Une fonction qui permet surveiller le log d'evènements
# 0000000153
ajouté le 28/02/2005 19:14:13 et modifié le 29/03/2006
consulté 7394 fois
Niveau
initié Version(s) Foxpro : VFP 9.0 VFP 8.0 VFP 7.0
Description
Cette fonction pourrait mes dans la taches et demarrer à toutes les
heures et si le log d'évenement recontre un erreur, il fait parvenir un
courriel à l'administrateur.
Code source :
Local dtmStart, SearchEventStart
Local objWMIService, colEvents, objEvent, EventTime
Local objMessage, eventCounted
vbCrLf =Chr (13)+Chr (10)
eMailAddress = "mgagnon@suntelecom.net"
MinutesToSearchWithin = -2
objMessage = Createobject ("CDO.Message" )
objMessage.Sender = eMailAddress
objMessage.To = eMailAddress
dtmStart = Createobject ("WbemScripting.SWbemDateTime" )
SearchEventStart = Ttoc (Datetime ()-3600)
dtmStart.SetVarDate(SearchEventStart, .T. )
objWMIService = Getobject ("winmgmts:" + "{impersonationLevel=impersonate}!\\.\root\cimv2" )
colEvents = objWMIService.ExecQuery("Select * from Win32_NTLogEvent Where Type = 'error' And Logfile = 'System' And TimeWritten >= '" + SearchEventStart + "'" )
For Each objEvent In colEvents
objMessage.TextBody = "Category: " + Transform (objEvent.Category)
EventTime = objEvent.TimeWritten
EventTime=WMIDateStringToDate(EventTime )
objMessage.TextBody = objMessage.TextBody + vbCrLf + "Time: " + Transform (EventTime)
objMessage.Subject = "Error Event in " + objEvent.SourceName + " on " + objEvent.ComputerName + " at " + Transform (EventTime)
objMessage.TextBody = objMessage.TextBody + vbCrLf + "EventCode: " + Transform (objEvent.EventCode)
objMessage.TextBody = objMessage.TextBody + vbCrLf + "Message: " + objEvent.Message
objMessage.TextBody = objMessage.TextBody + vbCrLf + "RecordNumber: " + Transform (objEvent.RecordNumber)
objMessage.TextBody = objMessage.TextBody + vbCrLf + "SourceName: " + objEvent.SourceName
objMessage.TextBody = objMessage.TextBody + vbCrLf + "Type: " + objEvent.Type
objMessage.TextBody = objMessage.TextBody + vbCrLf + "User: " + objEvent.User
Next
objMessage.Send
Function WMIDateStringToDate(dtmInstallDate)
Private ldRetVal
Return Ctot (Substr (dtmInstallDate, 5, 2) + '/' + Substr (dtmInstallDate, 7, 2) + '/' + Left (dtmInstallDate, 4) + ' ' +;
SUBSTR (dtmInstallDate, 9, 2) + ':' + Substr (dtmInstallDate, 11, 2) + ':' + Substr (dtmInstallDate,13, 2))
Endfunc
Commentaires
Aucun commentaire enregistré ...