class MonitorTypeFluidDb

A database class for checking a single number against a threshold. For example,

get the max timestamp from a table as a date.
subtract this from now
=> check that the number is not greater than 2

Public Instance Methods

derived_value() click to toggle source
# File lib/monitor_type/fluiddb.rb, line 54
def derived_value
  @fluid_db.query_for_value(@sql, [])
rescue StandardError
  string = "*** FluidDb encountered an error while running the sql\n" \
           "*** sql: #{@sql}\n" \
           "*** Please fix the query and run again\n"
  raise MonitorTypeExceptionHandled, string
end
extract_params() click to toggle source

Extract parameters

@param [String] uri Connection string to db @param [String] sql SQL statement to gather a single value

# File lib/monitor_type/fluiddb.rb, line 13
def extract_params
  if @params[:uri].nil?
    string = "*** FluidDb parameter missing, uri\n" \
             "*** :uri => <uri pointing to db to be monitored>"
    fail MonitorTypeParameterMissingError, string
  end
  begin
    @uri = URI.parse(@params[:uri])
  rescue URI::InvalidURIError
    string = '*** FluidDb encountered an error while parsing the uri' \
             "*** uri: #{@params[:uri]}" \
             "*** Please fix the uri and run again"
    raise MonitorTypeParameterMissingError, string
  end

  if @params[:sql].nil?
    string = '*** FluidDb parameter missing, sql' \
             "*** :sql => <sql statement, producing a single " \
             'column, single row which yeidls a number>'
    fail MonitorTypeParameterMissingError, string
  end
  @sql = @params[:sql]
  @context_sentence = "Checking result of sql query, #{@sql}"
end
setup() click to toggle source

Create the connection to the db, and get the value This ensures that all params are correct.

# File lib/monitor_type/fluiddb.rb, line 40
def setup
  begin
    @fluid_db = FluidDb2.db(@uri)
  rescue StandardError => e
    string = "*** FluidDb encountered an error while connecting to the db\n" \
             "*** Error: #{e.message}\n" \
             "*** uri: #{@uri}\n" \
             "*** Please fix the error and run again\n"
    raise MonitorTypeExceptionHandled, string
  end

  @params[:fluidDb] = @fluid_db
end
teardown() click to toggle source
# File lib/monitor_type/fluiddb.rb, line 63
def teardown
  @fluid_db.close
end