Class: MonitorType

Inherits:
Object
  • Object
show all
Defined in:
lib/MonitorType.rb

Direct Known Subclasses

MonitorType_Threshold

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ MonitorType

Returns a new instance of MonitorType.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/MonitorType.rb', line 8

def initialize( params )
    if params[:name].nil? then
        puts "*** Monitor parameter missing, name"
        puts "*** :name => <name of monitor>"
        abort
    end
    @name = params[:name]
    @email = params[:email]
    
    cron_string = params[:cron] || "0 1 * * *"
    @cron = CronParser.new(cron_string)
    @next = Time.now - 1
    
    log "Loaded Monitor, #{@name}."
end

Instance Method Details

#alert(string) ⇒ Object



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

def alert( string )
       body = "#{@name} tripped.\n#{string}"
       puts "*** "
  if !@email.nil? then
    Alert_Email.new( @email, body ).Send
           puts "Emailed, @email, Body, #{body}"
           else
           puts body
  end
end

#processObject



28
29
30
# File 'lib/MonitorType.rb', line 28

def process
    raise "Method needs to be overridden"
end

#runObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/MonitorType.rb', line 32

def run
    if Time.now > @next then
        begin
            @next = @cron.next( Time.now )
            log "Monitor, #{@name}, next run time, #{@next}"
            self.sanitise
            self.process
            rescue MonitorTypeExceptionHandled => e
            m.alert( e.message )
        end
    end
end

#sanitiseObject

Overload this method if any parameters should be checked



25
26
# File 'lib/MonitorType.rb', line 25

def sanitise
end