Sha256: b497662aab51ab4e2bbf519253ff94987f5516c0b58f6c45dfd98fddc51563a5

Contents?: true

Size: 976 Bytes

Versions: 7

Compression:

Stored size: 976 Bytes

Contents

#!/usr/bin/env ruby

require 'ostruct'

##
# Representation of a check result, as it's popped off the beanstalk.
# 
# Provides several convience methods for querying the status of a result. 
#
# Convenience methods are used by the Notifier to determine whether a 
# notification needs to be sent out.
module Flapjack
  class Result < OpenStruct
  
    # Whether a check returns an ok status. 
    def ok?
      self.retval == 0
    end
  
    # Whether a check has a warning status.
    def warning?
      self.retval == 1
    end
  
    # Whether a check has a critical status.
    def critical?
      self.retval == 2
    end
  
    # Human readable representation of the check's return value.
    def status
      case self.retval
      when 0 ; "ok"
      when 1 ; "warning"
      when 2 ; "critical"
      end
    end
  
    # The id of a check result.
    def id
      # openstruct won't respond, so we have to manually define it
      @table[:id]
    end
  
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
auxesis-flapjack-0.4.10 lib/flapjack/result.rb
auxesis-flapjack-0.4.6 lib/flapjack/result.rb
auxesis-flapjack-0.4.8 lib/flapjack/result.rb
auxesis-flapjack-0.4.9 lib/flapjack/result.rb
flapjack-0.4.12 lib/flapjack/result.rb
flapjack-0.4.11 lib/flapjack/result.rb
flapjack-0.4.10 lib/flapjack/result.rb