Microsoft’s LogParser tool is hot. I’ve been meaning to check out this tool for a few months but I never had time until recently.
LogParser, which uses a SQL engine for its queries, can query a
impressive array of input formats. Some of those formats are IIS logs,
csv files, XML files, Windows Event Logs, the Active Directory, the
registry, the filesystem, and more! The output formats that it
generates are equally impressive. Those include GIF charts, datagrids,
direct import into SQL Server, XML, and more.
If that wasn’t enough, the tool is completely scriptable using JavaScript, VBScript, or C# and VB.NET.
Yesterday, I was just hacking around figuring out the syntax and today
I wrote a full blown script to query my Active Directory to retrieve
all of the server objects. Based on that record set, then I query the
Application and System event logs on each server looking for only
warnings and errors.
Here is a snippet of the code to select objects out of the Active
Directory. I’ve replaced my domain with the fictional contoso.com
domain:
adQuery = “SELECT cn, operatingSystem, operatingSystemServicePack FROM
LDAP://contoso.com/DC=contoso,DC=com WHERE operatingSystem LIKE
‘server’ ORDER BY cn”
Below is the snippet of code that is used to query the event logs on each server:
“
SELECT TimeGenerated, EventID, EventLog, EventTypeName, SourceName,
Message
FROM \” & record.getValue(“cn”) & “Application
WHERE
EventTypeName
NOT LIKE ‘
Information’
AND TimeGenerated >=
TO_LOCALTIME(
SUB,
TIMESTAMP))
ORDER BY
TimeGenerated
DESC”
For those with experience in any kind of
SQL programming, the queries
will come as second nature. For those without, I can easily say that
SQL programming is by far the easiest language to pick up so it’ll be
no time before you’re hacking out your own queries. If you get stuck,
there is an
unofficial LogParser web site with all sorts of goodies.
I’ve made the
full source code
for my script to query event logs for download. I should note that I’m
not a programmer by trade so there might be a more elegant way to do
what I did. If you find any mistakes in my code or find a better way to
do something let me know.
Note: The zip file contains two files. One is a .wsf file and one is a
.vbs file. The .wsf file is a workspace file and it “includes” the .vbs
file. The .vbs file should be placed in the c:scriptslib directory
but you can change that. Usually, I follow this directory structure for
scripts:
C:
—Scripts (place script files here)
-——-Logs (logs get generated here)
-——Lib (include files are kept here)
Although I have provided the scripts for download, you are taking
responsibility if you run them on your computer and or network.