Class: MonitorType
- Inherits:
-
Object
- Object
- MonitorType
- Defined in:
- lib/MonitorType.rb
Direct Known Subclasses
Instance Method Summary collapse
- #alert(string) ⇒ Object
-
#initialize(params) ⇒ MonitorType
constructor
A new instance of MonitorType.
- #process ⇒ Object
- #run ⇒ Object
-
#sanitise ⇒ Object
Overload this method if any parameters should be checked.
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 |
#process ⇒ Object
28 29 30 |
# File 'lib/MonitorType.rb', line 28 def process raise "Method needs to be overridden" end |
#run ⇒ Object
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. ) end end end |
#sanitise ⇒ Object
Overload this method if any parameters should be checked
25 26 |
# File 'lib/MonitorType.rb', line 25 def sanitise end |