Class: Updawg::ResultSet
- Inherits:
-
Array
- Object
- Array
- Updawg::ResultSet
- Defined in:
- lib/updawg/results.rb
Instance Method Summary collapse
- #error? ⇒ Boolean
- #errors ⇒ Object
- #nagios_report!(stream = STDOUT) ⇒ Object
- #status ⇒ Object
- #success? ⇒ Boolean
- #to_html(builder = Builder::XmlMarkup.new) ⇒ Object
- #to_text ⇒ Object
- #warning? ⇒ Boolean
- #warnings ⇒ Object
Instance Method Details
#error? ⇒ Boolean
13 14 15 |
# File 'lib/updawg/results.rb', line 13 def error? map { |result| result.error? }.any? end |
#errors ⇒ Object
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 = " #{service.name} #{service.}" elsif warning? status ||= "WARNING" service = warnings.first = " #{service.name} #{service.}" else status ||= "OK" = "" end warning_count = warnings.size error_count = errors.size passed_count = size - error_count - warning_count service_output = ["#{status}#{}", "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 |
#status ⇒ Object
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
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., 'class' => 'message') tr.td(result.status_text, 'class' => 'status') end end end end |
#to_text ⇒ Object
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.}\n" end.join end |
#warning? ⇒ Boolean
9 10 11 |
# File 'lib/updawg/results.rb', line 9 def warning? map { |result| result.warning? }.any? && !error? end |
#warnings ⇒ Object
21 22 23 |
# File 'lib/updawg/results.rb', line 21 def warnings select { |result| result.warning? } end |