csamuel (owner)

Forks

Revisions

gist: 123049 Download_button fork
public
Public Clone URL: git://gist.github.com/123049.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class Report
  
  BLANK = "".freeze
  
  class << self
    def publish(server, options = {})
      report = self.new
      report.process(options[:log], server)
    end
  end
  
  def initialize
    @output = ""
  end
  
  def process(input, server)
    @output = @header
    open_log(input, server).each_line do |line|
      line.scan(@regex).each do |matched|
        matched.each do |line_matched|
          @output << line_matched + "|"
        end
        @output << "#{server}\n"
      end
    end
    @output << "\n"
  end
  
  private
  def open_log(log, server)
    begin
      File.open("#{LOGS_DIR}/#{server}/#{log}.#{PROCESS_DATE}.log", "r")
    rescue
      puts "Could not read #{log} on #{server}."
      return BLANK
    end
  end
 
end