rubylogparser
by Jim Clark ([email protected])
http://rubyforge.org/projects/rubylogparser/

== DESCRIPTION:

The RubyLogParser library is used for interacting with Microsoft's Log Parser
tool (http://www.microsoft.com/downloads/results.aspx?freetext=Log%20Parser).

Log Parser is a powerful, versatile tool that provides universal query
access to text-based data such as log files, XML files and CSV files, as
well as key data sources on the Windows operating system such as the
Event Log, the Registry, the file system, and Active Directory.

The most important benefit of using this library is that the Log Parser
output can be returned in arrays or hashes for further processing in Ruby.

== FEATURES/PROBLEMS:

The rubylogparser gem allows complete control over the Log Parser executable.
Although charts, XML files, log file formats and other output formats are
possible, the main goal is to scrape the Log Parser output into Ruby data
structures for further processing. Currently, arrays and hashes are supported.

See the following synopsis for a quick code sample or for a more detailed
explanation, check out the GUIDE[link://files/GUIDE_txt.html].
Also, check out the EXAMPLES[link://files/EXAMPLES_txt.html] file.

== SYNOPSIS:

The following code will search the c:\win*.* directory (matching c:\windows or
c:\winnt on most systems) for the 10 largest files. It make take a couple of
minutes to run. The input for Log Parser is the file system ('FS') and output
is directed to standard output (STDOUT) in comma separated value ('CSV') format
which is where the rubylogparser gem scrapes the Log Parser output from. Data
is returned in a hash with the hash keys corresponding to the selected fields in
the SQL statement.

require 'rubylogparser.rb'
lp = RubyLogParser.new
lp.open_query('FS', 'Select Top 10 name, size INTO STDOUT from c:/win*.* ORDER BY size DESC', 'CSV', nil)
while hash = lp.read_hash do
p " #hash['Name']hash['Name'].ljust(60) #hash['Size']hash['Size'].rjust(12)\n"
end

== REQUIREMENTS:

Testing was done in the following environment:

* ruby 1.8.6

* Microsoft Log Parser 2.2

Other software versions may work but are completely untested. I have used and tested
the examples on Windows XP and Windows Server 2008.

== INSTALL:

To use this library, first make sure that you have Microsoft's Log Parser tool
installed in your system. If you choose not to use the default install location,
make sure to add the directory where the logparser.exe executable is installed
in on the path.

Next, install the gem using "gem install -r rubylogparser"

RubyLogParser will automatically search for the Log Parser executable in these
locations:

* c:\Program Files\IIS Resources\Log Parser 2.2\LogParser.exe (Default install location for the IIS Resource Kit)

* c:\Program Files\Log Parser 2.2\LogParser.exe (Default location when downloaded and installed without the IIS Resource kit)

* c:\Program Files (x86)\Log Parser 2.2\LogParser.exe (Default location for 64-bit Windows Server 2008 install)

* LogParser.exe on the path somewhere

If the LogParser.exe executable cannot be found, the "test_valid_executable"
test will fail. If not installed in a default location, adding the installation
directory to the path is the easiest way to allow the executable to be found.

== ACKNOWLEDGEMENTS:

Thank you to Ryan Davis for guidance and troubleshooting and making this
library better.

== LICENSE:

(The MIT License)

Copyright (c) 2008 Jim Clark ([email protected])

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.