Eventlog - reading back 100hrs and changing to readable time

require ‘time’
require ‘Win32API’
require “win32/eventlog”
include Win32

handle = EventLog.open(“Application”)

handle.total_records # e.g. 916
handle.oldest_record_number # e.g. 1

def message_box(msg=’’,title=‘EventLog’,button=0)
api = Win32API.new(‘user32’,‘MessageBox’,[‘L’, ‘P’, ‘P’, ‘L’],‘I’)
r = api.call(0,msg,title,0)
return r
end

def data_select
each log[“time_written”] do |log|
time.parse: ri time.parse
if
[0] == <= time.now -360000
[0] = time_written
else
print “this is not working”
end
end

def time_format
each log[“time_written”] do |log|
Time.strftime("%d-%m-%Y %I%H:%M %p")
end
#today = Time.now
#today -= 360000
#sTime = Time.now.strftime("%d-%m-%Y %I%H:%M %p")
return Time
end

def html_header(title)
html = “”
html += “#{title}”
html += “\n”
return html
end

def html_heading1(heading)
html = “

#{heading}

\n”
return html
end

def html_table
html = “

\n”
return html
end

def html_table_headings
html = “

\n”
return html
end

def html_table_data(record_number, time_written, event_type,
description)
html =

\n”
return html
end

event_type1 = {:event_type => EventLog::INFO}
event_type2 = {:event_type => EventLog::WARN}
event_type3 = {:event_type => EventLog::ERROR}

print “What type of eventlog do you require [info/warn/error]?”
answer = gets.chomp.downcase

if answer == “info”
event_selected = event_type1
elsif answer == “warn”
event_selected = event_type2
elsif answer == “error”
event_selected = event_type3
else answer == “”
print “Sorry this is not an option … Closing EventLog Script…”
end

html_file = File.open(‘report.htm’,‘w’)
html = html_header(“Windows EventLog”)
html += html_heading1(“Windows EventLog”)
html += html_table
html += html_table_headings

handle.read(event_selected[“event_type”], [“time_written”] ){ |log|

data_select

time_format

record_number = log["record_number"]
time_written = log["time_written"]
event_type = log["event_type"]
description = log["description"]

html += html_table_data(record_number, time_written, event_type,
description)

}

html += “\n

RecNo: Time Recorded: Record
Type:
Description:
#{record_number} #{time_written} #{event_type} #{description}

html_file.printf("%s", html)
html_file.close

handle.close

message_box(“Congrats. The EventLog is now viewable in HTML.”)

AM I ON THE RIGHT TRACK OR CAN SOMEONE GIVE ME A SOLUTION FOR THE ABOVE
SUBJECT WHAT HAS BEEN ASKED IS THAT WE READ IN THE LAST 100HRS OF THE
EVENT LOG AND CONVERT THE TIME TO STANDARDIZED FORMAT THAT IS READABLE
BY THE COMMON MAN INTO A HTML DOCUMENT… PLEASE HELP I AM STUCK AS IM
NOT SURE IF THIS IS AN ARRAY IN STRING FORMAT OR AS AN OBJECT
(SPECIFICALLY AS A TIME ONE)… ANY HELP WOULD BE GREAT THANKS IN
ADVANCE

STUDENT

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs