Sha256: e2af64b502343d10d4ef0c6a20da5153839739b2da02388b7dfea8b604f78148

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 KB

Contents

require 'pony'

require 'makesure/runner'
require 'makesure/cron'
require 'makesure/system'
require 'makesure/cmd'
require 'makesure/verify'
require 'makesure/summarize'
require 'makesure/version'

module Makesure
  
  @alert_options = {}
  @systems = []
  
  extend self
  
  # global options
  attr_accessor :uid,
                :alert_options,
                :log_level
  
  def load_system_defs
    file = File.join(Dir.pwd, "Makesurefile")
    Makesure.log("Loading #{file}")
    load(file)
    abort "No system specifications found" unless Makesure.systems.size > 0
    Makesure.log "Loaded #{Makesure.systems.size} system specifications"
    true
  rescue Exception => e
    if e.instance_of?(SystemExit)
      raise
    else
      Makesure.warn "There was an error loading #{file}"
      Makesure.warn "\t" + e.message
      Makesure.warn "\t" + e.backtrace.join("\n\t")
      false
    end
  end
  
  def system_with_name(name)
    systems.find { |s| s.name.to_s == name.to_s }
  end
  
  def send_alert(title, details = "")
    opts = { :from => "makesure@unknown" }.merge(Makesure.alert_options)
    Makesure.log "Sending alert to #{opts[:to]}: #{title}"
    msg = Pony.mail(opts.merge(:subject => title, :body => details))
  end
  
  # DSL stuff
  
  attr_reader :systems
  
  def system(name)
    Makesure.debug "Reading specification for system '#{name}'"
    s = Makesure::System.new(name)
    yield s
    @systems << s
  end
  
  # internal utils
  
  def log(msg, level = :info)
    puts "[#{Time.now.to_s}] #{level.to_s.upcase}: #{msg}"
  end
  
  def warn(msg)
    log(msg, :warn)
  end
  
  def debug(msg)
    log(msg, :debug) if log_level == :debug
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
makesure-0.0.1 lib/makesure.rb