From aaa36d3008d331ce611f18eaec7f16a194fcce82 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 4 Aug 2013 23:56:02 +0200 Subject: [PATCH] Added nagios/icinga checks. --- app/models/scheduler.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app/models/scheduler.rb b/app/models/scheduler.rb index 1eeb1e05b..71ccc9ba3 100644 --- a/app/models/scheduler.rb +++ b/app/models/scheduler.rb @@ -60,4 +60,29 @@ class Scheduler < ApplicationModel job.save eval job.method() end + + def self.check( name, time_warning = 10, time_critical = 20 ) + time_warning_time = Time.now - time_warning.minutes + time_critical_time = Time.now - time_critical.minutes + scheduler = Scheduler.where( :name => name ).first + if !scheduler + puts "CRITICAL - no such scheduler jobs '#{name}'" + return true + end +#puts "S " + scheduler.inspect + if !scheduler.last_run + puts "CRITICAL - scheduler jobs never started '#{name}'" + exit 2 + end + if scheduler.last_run < time_critical_time + puts "CRITICAL - scheduler jobs was not running in last '#{time_critical.to_s}' minutes - last run at '#{scheduler.last_run.to_s}' '#{name}'" + exit 2 + end + if scheduler.last_run < time_warning_time + puts "CRITICAL - scheduler jobs was not running in last '#{time_warning.to_s}' minutes - last run at '#{scheduler.last_run.to_s}' '#{name}'" + exit 2 + end + puts "ok - scheduler jobs was running at '#{scheduler.last_run.to_s}' '#{name}'" + exit 0 + end end