Class: MonitorType_FluidDb

Inherits:
MonitorType_Threshold show all
Defined in:
lib/MonitorType/FluidDb.rb

Overview

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

Instance Method Summary collapse

Methods inherited from MonitorType_Threshold

#check, #initialize, #process

Methods inherited from MonitorType

#alert, #initialize, #process, #run, #teardown

Constructor Details

This class inherits a constructor from MonitorType_Threshold

Instance Method Details

#extractParamsObject

Extract parameters

Parameters:

  • uri (String)

    Connection string to db

  • sql (String)

    SQL statement to gather a single value



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/MonitorType/FluidDb.rb', line 16

def extractParams
       if @params[:uri].nil? then
           string = "*** FluidDb parameter missing, uri\n"
           string = "#{string}*** :uri => <uri pointing to db to be monitored>"
           raise MonitorTypeParameterMissingError.new(string)
       end
       begin
           @uri = URI.parse( @params[:uri] )
           rescue URI::InvalidURIError=>e
           string = "*** FluidDb encountered an error while parsing the uri"
           string = "#{string}*** uri: #{@params[:uri]}"
           string = "#{string}*** Please fix the uri and run again"
           raise MonitorTypeParameterMissingError.new(string)
       end

       if @params[:sql].nil? then
           string = "*** FluidDb parameter missing, sql"
           string = "#{string}*** :sql => <sql statement, producing a single column, single row which yeidls a number>"
           raise MonitorTypeParameterMissingError.new(string)
       end
       @sql = @params[:sql]

       @context_sentence = "Checking result of sql query, #{@sql}"

end

#getValueObject



59
60
61
62
63
64
65
66
67
68
# File 'lib/MonitorType/FluidDb.rb', line 59

def getValue
       begin
           return @fluidDb.queryForValue( @sql, [] )
           rescue Exception=>e
           string = "*** FluidDb encountered an error while running the sql\n"
           string = "#{string}*** sql: #{@sql}\n"
           string = "#{string}*** Please fix the query and run again\n"
           raise MonitorTypeExceptionHandled.new(string)
       end
end

#setupObject

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



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/MonitorType/FluidDb.rb', line 44

def setup

       begin
           @fluidDb = FluidDb.Db( @uri )
           rescue Exception=>e
           string = "*** FluidDb encountered an error while connecting to the db\n"
           string = "#{string}*** Error: #{e.message}\n"
           string = "#{string}*** uri: #{@uri}\n"
           string = "#{string}*** Please fix the error and run again\n"
           raise MonitorTypeExceptionHandled.new(string)
       end

       @params[:fluidDb] = @fluidDb
end