Class: MonitorType_FluidDb
- Inherits:
-
MonitorType_Threshold
- Object
- MonitorType
- MonitorType_Threshold
- MonitorType_FluidDb
- 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
-
#initialize(params) ⇒ MonitorType_FluidDb
constructor
Constructor: Extract parameters.
- #process ⇒ Object
-
#sanitise ⇒ Object
Create the connection to the db, and get the value This ensures that all params are correct.
Methods inherited from MonitorType_Threshold
Methods inherited from MonitorType
Constructor Details
#initialize(params) ⇒ MonitorType_FluidDb
Constructor: Extract parameters
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/MonitorType/FluidDb.rb', line 39 def initialize( params ) super( params ) if params[:uri].nil? then puts "*** FluidDb parameter missing, uri" puts "*** :uri => <uri pointing to db to be monitored>" abort end begin @uri = URI.parse( params[:uri] ) rescue URI::InvalidURIError=>e puts "*** FluidDb encountered an error while parsing the uri" puts "*** uri: #{params[:uri]}" puts "*** Please fix the uri and run again" abort() end if params[:sql].nil? then puts "*** FluidDb parameter missing, sql" puts "*** :sql => <sql statement, producing a single column, single row which yeidls a number>" abort end @sql = params[:sql] self.sanitise rescue MonitorTypeExceptionHandled => e puts e. abort() end |
Instance Method Details
#process ⇒ Object
67 68 69 70 71 |
# File 'lib/MonitorType/FluidDb.rb', line 67 def process value = @fluidDb.queryForValue( @sql, [] ) self.check( value, "Checking result of sql query, #{@sql}" ) end |
#sanitise ⇒ Object
Create the connection to the db, and get the value This ensures that all params are correct.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/MonitorType/FluidDb.rb', line 14 def sanitise begin @fluidDb = FluidDb.Db( @uri ) rescue Exception=>e puts "*** FluidDb encountered an error while connecting to the db" puts "*** Error: #{e.}" puts "*** uri: #{@uri}" puts "*** Please fix the error and run again" abort() end begin value = @fluidDb.queryForValue( @sql, [] ) rescue Exception=>e puts "*** FluidDb encountered an error while running the sql" puts "*** sql: #{@sql}" puts "*** Please fix the query and run again" abort() end end |