Created
April 10, 2011 16:48
-
-
Save obi-a/912513 to your computer and use it in GitHub Desktop.
testing Design ideas for Ragios 0.5: Adding detached monitors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require "bundler/setup" | |
dir = Pathname(__FILE__).dirname.expand_path | |
require dir + 'lib/ragios' | |
module Ragios | |
module Monitors | |
class System | |
def test_command | |
puts 'original system monitor' | |
return TRUE | |
end | |
end | |
end | |
end | |
module Monitors | |
#plugin to monitor http | |
class Http | |
attr_accessor :describe_test_result | |
def initialize() | |
@describe_test_result = "testing HTTP" | |
end | |
def init(options) | |
end | |
def test_command | |
puts 'testing HTTP' | |
return TRUE | |
end | |
end | |
end | |
module Notifiers | |
def notify | |
if @notifier == 'email' | |
email_notify | |
elsif @notifier == 'gmail' | |
gmail_notify | |
elsif @notifier == 'twitter' | |
tweet_notify | |
else | |
raise 'Notifier: Not Found' | |
end | |
end | |
def fixed | |
if @notifier == 'email' | |
email_resolved | |
elsif @notifier == 'gmail' | |
gmail_resolved | |
elsif @notifier == 'twitter' | |
tweet_resolved | |
else | |
raise 'Notifier: Not Found' | |
end | |
end | |
end | |
module InitValues | |
def ragios_init_values(options) | |
#translate values of the DSL to a Ragios::Monitors::System object | |
@time_interval = options[:every] | |
@notification_interval = options[:notify_interval] | |
@contact = options[:contact] | |
@test_description = options[:test] | |
@notifier = options[:via] | |
end | |
end | |
module Ragios | |
class GenericMonitor < Ragios::Monitors::System | |
attr_reader :plugin | |
#TODO: help create the right type of monitor instance | |
def initialize(plugin,options) | |
@plugin = plugin | |
@plugin.ragios_init_values(options) | |
ragios_init_values(options) | |
@describe_test_result = '' | |
if defined?(@plugin.describe_test_result) | |
@describe_test_result = @plugin.describe_test_result | |
else | |
raise '@describe_test_result must be defined in ' + @plugin.to_s | |
end | |
super() | |
end | |
def test_command | |
if @plugin.respond_to?('test_command') | |
@plugin.test_command | |
end | |
end | |
def failed | |
if @plugin.respond_to?('failed') | |
@plugin.failed | |
end | |
end | |
include Notifiers | |
end | |
class Monitor | |
def self.start(monitoring) | |
monitor = [] | |
count = 0 | |
monitoring.each do|m| | |
#TODO: create the right type of monitor instance for each monitor and pass the values to the scheduler | |
options = m | |
module_name = "Monitors" | |
plugin_name = m[:monitor] | |
plugin_class = Module.const_get(module_name).const_get(plugin_name.capitalize) | |
#add method to plugin class that will translate options to real values | |
plugin_class.class_eval do |options| | |
include InitValues | |
end | |
plugin = plugin_class.new | |
plugin.init(options) | |
#add method to GenericMonitor class that will translate options to real values | |
GenericMonitor.class_eval do |options| | |
include InitValues | |
end | |
ragios_monitor = GenericMonitor.new(plugin,options) | |
monitor[count] = ragios_monitor | |
count = count + 1 | |
end #end of each...do loop | |
Ragios::System.start monitor | |
end | |
end | |
end | |
monitoring = [{:monitor =>'http', | |
:every => '5m', | |
:test => 'Http connection to my site', | |
:domain => 'www.mysite.com', | |
:contact => '[email protected]', | |
:via => 'gmail', | |
:notify_interval => '6h' | |
}] | |
Ragios::Monitor.start monitoring |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment