Class: Updawg::ResultSet

Inherits:
Array
  • Object
show all
Defined in:
lib/updawg/results.rb

Instance Method Summary collapse

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/updawg/results.rb', line 13

def error?
  map { |result| result.error? }.any?
end

#errorsObject



17
18
19
# File 'lib/updawg/results.rb', line 17

def errors
  select { |result| result.error? }
end

#nagios_report!(stream = STDOUT) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/updawg/results.rb', line 49

def nagios_report!(stream = STDOUT)
  if error?
    status = "CRITICAL"
    service = errors.first
    message = " #{service.name} #{service.message}"
  elsif warning?
    status ||= "WARNING" 
    service = warnings.first
    message = " #{service.name} #{service.message}"
  else
    status ||= "OK"
    message = ""
  end
  
  warning_count = warnings.size
  error_count = errors.size
  passed_count = size - error_count - warning_count
         
  service_output = ["#{status}#{message}", "OK:#{passed_count} WRN:#{warning_count} CRT:#{error_count}"]
  stream.write "#{service_output.join("; ")}\n"
  stream.write to_text
  return exit(2) if error?
  return exit(1) if warning?
  exit(0)
end

#statusObject



25
26
27
28
29
# File 'lib/updawg/results.rb', line 25

def status
  return :error if error?
  return :warning if warning?
  :pass
end

#success?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/updawg/results.rb', line 5

def success?
  map { |result| result.success? }.all?
end

#to_html(builder = Builder::XmlMarkup.new) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/updawg/results.rb', line 31

def to_html(builder = Builder::XmlMarkup.new)
  builder.table('class' => status.to_s) do |b|
    each do |result|
      b.tr('class' => result.status.to_s) do |tr|
        tr.td(result.name, 'class' => 'name')
        tr.td(result.message, 'class' => 'message')
        tr.td(result.status_text, 'class' => 'status')
      end
    end
  end
end

#to_textObject



43
44
45
46
47
# File 'lib/updawg/results.rb', line 43

def to_text
  map do |r|
    "#{r.status_text}\t#{r.name} - #{r.message}\n"
  end.join
end

#warning?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/updawg/results.rb', line 9

def warning?
  map { |result| result.warning? }.any? && !error?
end

#warningsObject



21
22
23
# File 'lib/updawg/results.rb', line 21

def warnings 
  select { |result| result.warning? }
end