Monitor Event Viewer on Multiple SQL ServersFebruary 11, 2004 In the typical IT department, an un-avoidable task is to monitor the Event Log on all of the servers. It is tedious to go through all the logs one by one, on a daily basis. In this article, the methods presented will help in monitoring the Event Viewer on many servers from a single place. In addition, I am going to discuss three different ways to monitor Event Log on a list of servers and store the output either in a .CSV file or on a database table. These methods fetch all of those errors and warnings that occurred in the last 24 hours. Method 1:This method checks the Event Log for Errors and Warnings on all of the servers listed in the text file and create a .csv output file. Let's say we have 3 servers and need to monitor the Event log on all of those servers. Step1: Create a folder C:\EventLog and create a text file c:\EventLog\Serverlist.txt with a list of server names. Example: SQL2K Step2: Copy and paste the code below into c:\EventLog\monitoreventlogtocsv.vbs. 'Objective: Find Errors and Warnings in Event Log on all the listed servers and write the output to a .csv file
'Author: MAK
'Contact: mak_999@yahoo.com
On error resume next
Const CONVERT_TO_LOCAL_TIME = True
Set iFSO = CreateObject("Scripting.FilesyStemObject")
Set oFSO = CreateObject("Scripting.FilesyStemObject")
InputFile="c:\EventLog\Serverlist.txt"
Outputfile="c:\EventLog\EventlogOutput_" + cstr(Month(now()))+"_"+cstr(day(now()))+".csv"
Set ofile = ofso.createTextFile(OutputFile, True)
Set ifile = iFSO.OpenTextFile(inputfile)
Const MBCONVERSION= 1048576
ofile.writeline "LogType,Category,ComputerName,Message,SourceName,TimeWritten,Type,User"
Do until ifile.AtEndOfLine
strComputer = ifile.ReadLine
Set objService =GetObject("winmgmts:{impersonationLevel=impersonate,"& "(Security)}!root\cimv2")
Set objWMICol = objService.ExecQuery("SELECT Currenttimezone FROM Win32_ComputerSystem")
For Each objComputer In objWMICol
nTimeZone = objComputer.Currenttimezone
Next
string1=""
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" &
Step3: Execute c:\EventLog\monitoreventlogtocsv.vbs. When we execute this VB script, it will create a time stamped, comma separated value file on c:\Evenlog\EventlogOutput_1_22.csv that will contain details similar to those below. LogType,Category,ComputerName,Message,SourceName,TimeWritten,Type,User Application,0,SQL2K, ,Microsoft Internet Explorer,'20040122190940.000000-300',error,N/A System,0,SQL2K,DCOM Can't communicate ,DCOM,'20040122223203.000000-300',error,AMERICAS\Administrator System,0,SQL2K,DCOM Can't communicate ,DCOM,'20040122223142.000000-300',error,AMERICAS\Administrator Application,0,YUKON,Windows cannot determine the user or computer name. Return value (1722).,Userenv, Step4: Click OK on the Message box.
|