Class: Lssvcevents

Inherits:
Object
  • Object
show all
Defined in:
lib/HMC/lssvcevents.rb

Overview

Fantastic class to analyze events from HMCs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string = nil, hmc_name = nil) ⇒ Lssvcevents

Returns a new instance of Lssvcevents.



8
9
10
11
12
13
# File 'lib/HMC/lssvcevents.rb', line 8

def initialize(string = nil, hmc_name = nil)
  @events = []
  @errors = []

  parse(string, hmc_name) unless string.nil?
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



6
7
8
# File 'lib/HMC/lssvcevents.rb', line 6

def errors
  @errors
end

#eventsObject (readonly)

Returns the value of attribute events.



5
6
7
# File 'lib/HMC/lssvcevents.rb', line 5

def events
  @events
end

Instance Method Details

#countObject



49
50
51
# File 'lib/HMC/lssvcevents.rb', line 49

def count
  @events.count
end

#parse(string, hmc_name) ⇒ Object



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
40
41
42
43
44
45
46
47
# File 'lib/HMC/lssvcevents.rb', line 15

def parse(string, hmc_name)
  return true if string =~ /^No results were found./

  if string =~ /An unknown error occurred while trying to perform this command. Retry the command. If the error persists, contact your software support representative/
    @errors.push(hmc: hmc_name, error: 'An unknown error occurred while trying to perform this command. Retry the command. If the error persists, contact your software support representative')
    return true
  end

  string.split("\n").each do |line|
    entry = Lssvcenevents_entry.new(line, hmc_name)

    if @events.count.zero?
      @events.push(entry)
      next
    end

    event_id = 0
    @events.each_with_index do |event, id|
      if event.compare(entry)
        event_id = id
        break
      end
    end

    if event_id > 0
      @events[event_id].hmc_add(hmc_name)
    else
      @events.push(entry)
    end
  end

  true
end

#parse_csv(string) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/HMC/lssvcevents.rb', line 53

def parse_csv(string)
  return true if string.nil?

  headers = ''
  line_nr = 0
  lines = string.split("\n")
  lines.each do |line|
    if line_nr.zero?
      headers = line
      line_nr += 1
      next
    end

    entry = Lssvcenevents_entry.new
    entry.parse_from_csv(headers, line)

    event_id = -1
    @events.each_with_index do |event, id|
      if event.compare(entry, %w[hmcs_name problem_num last_time refcode sys_name failing_mtms machine_type machine_model status text phm_num])
        event_id = id
        puts "Event ID #{id} found"
        next
      end
    end

    @events[event_id].parse_from_csv(headers, line) if event_id >= 0
    line_nr += 1
  end

  true
end