Class: Hostmon::Models::Report
- Defined in:
- lib/hostmon/models/report.rb
Constant Summary collapse
- @@report_base =
""
- @@status_map =
{ :CHECK_OK => 0b000000, :CHECK_FAILED => 0b000001, :FAILED_MISSING_PRELUDE => 0b000100, :FAILED_STDERR_NONEMPTY => 0b001000, :FAILED_BAD_EXIT_STATUS => 0b010000, :FAILED_SKIPPED => 0b100000 }
Instance Attribute Summary collapse
-
#cluster ⇒ Object
readonly
Returns the value of attribute cluster.
-
#exit_status ⇒ Object
readonly
Returns the value of attribute exit_status.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Class Method Summary collapse
Instance Method Summary collapse
-
#body ⇒ Object
fixme rewrite to stdout stderr etc.
- #check_failed? ⇒ Boolean
- #delete ⇒ Object
- #failed? ⇒ Boolean
-
#hostlint_id ⇒ Object
this is actually a property of a host.
-
#initialize(hsh) ⇒ Report
constructor
A new instance of Report.
- #int_status ⇒ Object
- #ok? ⇒ Boolean
- #report_dir ⇒ Object
- #report_fname ⇒ Object
-
#to_yaml ⇒ Object
dammit.
- #write ⇒ Object
Methods inherited from Base
#<=>, #[], all, each, find, #to_s
Constructor Details
#initialize(hsh) ⇒ Report
Returns a new instance of Report.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/hostmon/models/report.rb', line 22 def initialize (hsh) @name = hsh[:name] @status = hsh[:status] @timestamp = Time.parse(hsh[:timestamp]) @exit_status = hsh[:exit_status] @stdout = hsh[:stdout] @stderr = hsh[:stderr] @host = hsh[:host] @cluster = hsh[:cluster] h = Host.absorb(self) Check.absorb(name, h) end |
Instance Attribute Details
#cluster ⇒ Object (readonly)
Returns the value of attribute cluster.
20 21 22 |
# File 'lib/hostmon/models/report.rb', line 20 def cluster @cluster end |
#exit_status ⇒ Object (readonly)
Returns the value of attribute exit_status.
19 20 21 |
# File 'lib/hostmon/models/report.rb', line 19 def exit_status @exit_status end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
20 21 22 |
# File 'lib/hostmon/models/report.rb', line 20 def host @host end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/hostmon/models/report.rb', line 19 def name @name end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
19 20 21 |
# File 'lib/hostmon/models/report.rb', line 19 def status @status end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
19 20 21 |
# File 'lib/hostmon/models/report.rb', line 19 def stderr @stderr end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
19 20 21 |
# File 'lib/hostmon/models/report.rb', line 19 def stdout @stdout end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
19 20 21 |
# File 'lib/hostmon/models/report.rb', line 19 def @timestamp end |
Class Method Details
.report_base=(dir) ⇒ Object
7 8 9 |
# File 'lib/hostmon/models/report.rb', line 7 def self.report_base= (dir) @@report_base = dir end |
Instance Method Details
#body ⇒ Object
fixme rewrite to stdout stderr etc
52 53 54 |
# File 'lib/hostmon/models/report.rb', line 52 def body CGI::escapeHTML(@stdout) end |
#check_failed? ⇒ Boolean
47 48 49 |
# File 'lib/hostmon/models/report.rb', line 47 def check_failed? int_status > 1 end |
#delete ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'lib/hostmon/models/report.rb', line 98 def delete if File.exist?(report_fname) puts "delete #{report_fname}" FileUtils.rm(report_fname) else puts "report #{report_fname} not on disk" end end |
#failed? ⇒ Boolean
43 44 45 |
# File 'lib/hostmon/models/report.rb', line 43 def failed? int_status == 1 end |
#hostlint_id ⇒ Object
this is actually a property of a host
57 58 59 |
# File 'lib/hostmon/models/report.rb', line 57 def hostlint_id Digest::SHA1.hexdigest("#{@name}#{@host}#{@cluster}")[0..7] end |
#int_status ⇒ Object
35 36 37 |
# File 'lib/hostmon/models/report.rb', line 35 def int_status @status.map {|x| @@status_map[x]}.inject(:|) end |
#ok? ⇒ Boolean
39 40 41 |
# File 'lib/hostmon/models/report.rb', line 39 def ok? int_status == 0 end |
#report_dir ⇒ Object
75 76 77 |
# File 'lib/hostmon/models/report.rb', line 75 def report_dir File.join(@@report_base, @name.split("."), @cluster, @host) end |
#report_fname ⇒ Object
79 80 81 82 |
# File 'lib/hostmon/models/report.rb', line 79 def report_fname File.join(report_dir, "report_#{@timestamp.strftime("%F-%T")}.yaml") end |
#to_yaml ⇒ Object
dammit
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/hostmon/models/report.rb', line 62 def to_yaml { :name => @name, :status => @status, :timestamp => @timestamp.to_s, :exit_status => @exit_status, :stdout => @stdout, :stderr => @stderr, :host => @host, :cluster => @cluster }.to_yaml end |
#write ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/hostmon/models/report.rb', line 84 def write if File.exist?(report_fname) puts "#{report_fname} already exists" else unless File.directory?(report_dir) FileUtils.mkdir_p(report_dir) end puts "write #{report_fname}" File.open(report_fname, "w") do |f| f.puts(to_yaml) end end end |