steto 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +7 -0
- data/Gemfile +9 -0
- data/Guardfile +9 -0
- data/License.txt +22 -0
- data/README.textile +53 -0
- data/Rakefile +17 -0
- data/config-sample.rb +16 -0
- data/lib/steto/base_check.rb +28 -0
- data/lib/steto/beep_reporter.rb +15 -0
- data/lib/steto/cocaine_ext.rb +19 -0
- data/lib/steto/config.rb +39 -0
- data/lib/steto/engine.rb +37 -0
- data/lib/steto/logger_reporter.rb +28 -0
- data/lib/steto/nagios_check.rb +40 -0
- data/lib/steto/proc_check.rb +13 -0
- data/lib/steto/proc_reporter.rb +11 -0
- data/lib/steto/status.rb +19 -0
- data/lib/steto/version.rb +3 -0
- data/lib/steto.rb +26 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/steto/beep_reporter_spec.rb +20 -0
- data/spec/steto/config_spec.rb +62 -0
- data/spec/steto/engine_spec.rb +67 -0
- data/spec/steto/logger_reporter_spec.rb +40 -0
- data/spec/steto/nagios_check_spec.rb +48 -0
- data/steto.gemspec +29 -0
- metadata +181 -0
    
        data/.gitignore
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/Guardfile
    ADDED
    
    
    
        data/License.txt
    ADDED
    
    | @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            (The MIT License)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Copyright (c) 20012 Alban Peignier, Florent Peyraud, Tryphon
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining
         | 
| 6 | 
            +
            a copy of this software and associated documentation files (the
         | 
| 7 | 
            +
            "Software"), to deal in the Software without restriction, including
         | 
| 8 | 
            +
            without limitation the rights to use, copy, modify, merge, publish,
         | 
| 9 | 
            +
            distribute, sublicense, and/or sell copies of the Software, and to
         | 
| 10 | 
            +
            permit persons to whom the Software is furnished to do so, subject to
         | 
| 11 | 
            +
            the following conditions:
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            The above copyright notice and this permission notice shall be
         | 
| 14 | 
            +
            included in all copies or substantial portions of the Software.
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         | 
| 17 | 
            +
            EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         | 
| 18 | 
            +
            MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
         | 
| 19 | 
            +
            IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
         | 
| 20 | 
            +
            CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
         | 
| 21 | 
            +
            TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
         | 
| 22 | 
            +
            SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         | 
    
        data/README.textile
    ADDED
    
    | @@ -0,0 +1,53 @@ | |
| 1 | 
            +
            h1. Steto
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Steto is a simple to check system status.
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            This first release can :
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            * use Nagios plugin
         | 
| 8 | 
            +
            * define a check with a simple block
         | 
| 9 | 
            +
            * configure via an extensible DSL
         | 
| 10 | 
            +
            * run checks with several threads
         | 
| 11 | 
            +
            * report via several customizable Reporters
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            h2. Sample
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            <pre>
         | 
| 16 | 
            +
            require 'steto'
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            Steto.config do
         | 
| 19 | 
            +
              # complete syntax
         | 
| 20 | 
            +
              check :load, Steto::NagiosCheck, :command => "/usr/lib/nagios/plugins/check_load", :options => { :warning => "1,0.5,0.5", :critical => "1,1,1"} 
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              # shortcut for nagios
         | 
| 23 | 
            +
              nagios :disk_space, "check_disk", :warning => "10%"
         | 
| 24 | 
            +
             | 
| 25 | 
            +
              # make your helpers
         | 
| 26 | 
            +
              def ping(host)
         | 
| 27 | 
            +
                nagios "ping_#{host.split('.')[1]}", "check_ping", :hostname => host, :warning => "100,1%", :critical => "300,20%", :use_ipv4 => true
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              ping "www.google.com" 
         | 
| 31 | 
            +
              ping "stream.tryphon.eu"
         | 
| 32 | 
            +
             | 
| 33 | 
            +
              def process(name)
         | 
| 34 | 
            +
                nagios "process_#{name}", "check_procs", :critical => "1:", :command => name
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
              process "apache2"
         | 
| 38 | 
            +
              process "icecast2"
         | 
| 39 | 
            +
              
         | 
| 40 | 
            +
              # check in one line
         | 
| 41 | 
            +
              check :if_link do
         | 
| 42 | 
            +
                `sudo /sbin/ethtool eth2` =~ /Link detected: yes/ ? :ok : :critical
         | 
| 43 | 
            +
              end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
              # load external files
         | 
| 46 | 
            +
              Dir["/etc/steto/**/*.rb")].each { |f| load f }
         | 
| 47 | 
            +
             | 
| 48 | 
            +
              report Steto::LoggerReporter
         | 
| 49 | 
            +
              report Steto::BeepReporter
         | 
| 50 | 
            +
            end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
            Steto.default_engine.check.report
         | 
| 53 | 
            +
            </pre>
         | 
    
        data/Rakefile
    ADDED
    
    | @@ -0,0 +1,17 @@ | |
| 1 | 
            +
            require "bundler/gem_tasks"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'rspec/core/rake_task'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            RSpec::Core::RakeTask.new(:spec)
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            RSpec::Core::RakeTask.new(:rcov) do |t|
         | 
| 8 | 
            +
              t.rcov = true
         | 
| 9 | 
            +
              t.rcov_opts = %w{--exclude osx\/objc,gems\/,spec\/}
         | 
| 10 | 
            +
            end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            task :readme do
         | 
| 13 | 
            +
              require 'RedCloth'
         | 
| 14 | 
            +
              File.open("README.html","w") do |f|
         | 
| 15 | 
            +
                f.write RedCloth.new(IO.read("README.textile")).to_html
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
            end
         | 
    
        data/config-sample.rb
    ADDED
    
    | @@ -0,0 +1,16 @@ | |
| 1 | 
            +
            Steto::config do
         | 
| 2 | 
            +
              register :proc, NagiosCheck, :plugin => "/usr/lib/nagios/plugins/check_procs" do |attributes|
         | 
| 3 | 
            +
                { :warning => "1:1", :critical => "1:1" }.merge attributes
         | 
| 4 | 
            +
              end 
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              check :proc, :command => "caed"
         | 
| 7 | 
            +
              check :proc, :command => "rdcatchd"
         | 
| 8 | 
            +
              check :proc, :command => "ripcd"
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              notifier :beep, :if => Proc.new { |set| set.any? { |c| c.status.nok? } } do |checkers|
         | 
| 11 | 
            +
                system "beep -d 1000 -r 15" 
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
              notifier :email, EmailNotifier, :to => "root@...", :if => &:critical?
         | 
| 14 | 
            +
              notifier :syslog, SyslogNotifier
         | 
| 15 | 
            +
            end
         | 
| 16 | 
            +
             | 
| @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            module Steto
         | 
| 2 | 
            +
              class BaseCheck
         | 
| 3 | 
            +
                attr_accessor :name
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def attributes=(attributes = {})
         | 
| 6 | 
            +
                  attributes.each { |k,v| send "#{k}=", v }
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def check_if_needed
         | 
| 10 | 
            +
                  check unless @status
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def status
         | 
| 14 | 
            +
                  check_if_needed
         | 
| 15 | 
            +
                  @status
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                def status=(status)
         | 
| 19 | 
            +
                  @status = Status.new status
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                attr_accessor :text
         | 
| 23 | 
            +
                def text
         | 
| 24 | 
            +
                  check_if_needed
         | 
| 25 | 
            +
                  @text
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
            end
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            require 'cocaine/command_line'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Cocaine
         | 
| 4 | 
            +
              class CommandLine
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                attr_reader :exit_status
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                alias_method :run_without_exit_status, :run
         | 
| 9 | 
            +
                def run_with_exit_status
         | 
| 10 | 
            +
                  begin
         | 
| 11 | 
            +
                    run_without_exit_status
         | 
| 12 | 
            +
                  ensure
         | 
| 13 | 
            +
                    @exit_status = $?.exitstatus
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
                alias_method :run, :run_with_exit_status
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
    
        data/lib/steto/config.rb
    ADDED
    
    | @@ -0,0 +1,39 @@ | |
| 1 | 
            +
            module Steto
         | 
| 2 | 
            +
              class Config
         | 
| 3 | 
            +
                attr_accessor :engine
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def initialize(engine)
         | 
| 6 | 
            +
                  @engine = engine
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def configure(&block)
         | 
| 10 | 
            +
                  instance_eval &block
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def check(name, check_class = nil, attributes = {}, &block)
         | 
| 14 | 
            +
                  name = name.to_sym
         | 
| 15 | 
            +
                  check =
         | 
| 16 | 
            +
                    if check_class
         | 
| 17 | 
            +
                      check_class.new attributes.merge(:name => name)
         | 
| 18 | 
            +
                    else
         | 
| 19 | 
            +
                      ProcCheck.new :name => name, &block
         | 
| 20 | 
            +
                    end
         | 
| 21 | 
            +
                  engine.checks << check
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                def nagios(name, command, options = {})
         | 
| 25 | 
            +
                  check name, Steto::NagiosCheck, :command => "/usr/lib/nagios/plugins/#{command}", :options => options
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                def report(reporter_class = nil, &block)
         | 
| 29 | 
            +
                  reporter =
         | 
| 30 | 
            +
                    if reporter_class
         | 
| 31 | 
            +
                      reporter_class.new
         | 
| 32 | 
            +
                    else
         | 
| 33 | 
            +
                      ProcReporter.new &block
         | 
| 34 | 
            +
                    end
         | 
| 35 | 
            +
                  engine.reporters << reporter
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
                
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
            end
         | 
    
        data/lib/steto/engine.rb
    ADDED
    
    | @@ -0,0 +1,37 @@ | |
| 1 | 
            +
            require 'logger'
         | 
| 2 | 
            +
            require 'parallel'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module Steto
         | 
| 5 | 
            +
              class Engine
         | 
| 6 | 
            +
                attr_reader :checks, :reporters
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def initialize
         | 
| 9 | 
            +
                  @checks = []
         | 
| 10 | 
            +
                  @reporters = []
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def config(&block)
         | 
| 14 | 
            +
                  @config ||= Config.new(self)
         | 
| 15 | 
            +
                  @config.configure(&block) if block_given?
         | 
| 16 | 
            +
                  @config
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                def check
         | 
| 20 | 
            +
                  Parallel.each(checks, :in_threads => 4) do |check|
         | 
| 21 | 
            +
                    check.check
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
                  self
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                def report(reporter = nil)
         | 
| 27 | 
            +
                  if reporter
         | 
| 28 | 
            +
                    reporter.report(checks)
         | 
| 29 | 
            +
                  else
         | 
| 30 | 
            +
                    reporters.each do |reporter|
         | 
| 31 | 
            +
                      report reporter
         | 
| 32 | 
            +
                    end
         | 
| 33 | 
            +
                  end
         | 
| 34 | 
            +
                  self
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
              end
         | 
| 37 | 
            +
            end
         | 
| @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            module Steto
         | 
| 2 | 
            +
              class LoggerReporter
         | 
| 3 | 
            +
                attr_accessor :logger
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def logger
         | 
| 6 | 
            +
                  @logger ||= Logger.new($stderr)
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def report(checks)
         | 
| 10 | 
            +
                  checks.each do |check|
         | 
| 11 | 
            +
                    level = 
         | 
| 12 | 
            +
                      case check.status
         | 
| 13 | 
            +
                      when "warning"
         | 
| 14 | 
            +
                        :warn 
         | 
| 15 | 
            +
                      when /critical|unknown/
         | 
| 16 | 
            +
                        :error
         | 
| 17 | 
            +
                      else
         | 
| 18 | 
            +
                        :debug
         | 
| 19 | 
            +
                      end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                    message = "#{check.name} is #{check.status}"
         | 
| 22 | 
            +
                    message += ": #{check.text}" if check.text
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                    logger.send level, message
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
            end
         | 
| @@ -0,0 +1,40 @@ | |
| 1 | 
            +
            require 'cocaine'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Steto
         | 
| 4 | 
            +
              class NagiosCheck < BaseCheck
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                attr_accessor :command, :options
         | 
| 7 | 
            +
                
         | 
| 8 | 
            +
                def initialize(attributes = {})
         | 
| 9 | 
            +
                  self.options = {}
         | 
| 10 | 
            +
                  self.attributes = attributes
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def check
         | 
| 14 | 
            +
                  self.text = command_line.run.chomp
         | 
| 15 | 
            +
                  self.status = status_from_command_line
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                def command_line
         | 
| 19 | 
            +
                  # => "--critical=:critical --warning=:warning"
         | 
| 20 | 
            +
                  params = options.map do |option, value| 
         | 
| 21 | 
            +
                    option = option.to_s.gsub("_","-")
         | 
| 22 | 
            +
                    unless value == true
         | 
| 23 | 
            +
                      "--#{option}=:#{option}"
         | 
| 24 | 
            +
                    else
         | 
| 25 | 
            +
                      "--#{option}"
         | 
| 26 | 
            +
                    end
         | 
| 27 | 
            +
                  end.sort.join(' ')
         | 
| 28 | 
            +
                  @command_line ||= Cocaine::CommandLine.new(command, params, options.merge(:expected_outcodes => [0, 1, 2, 3]))
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                def status_from_command_line
         | 
| 32 | 
            +
                  { 0 => :ok,
         | 
| 33 | 
            +
                    1 => :warning,
         | 
| 34 | 
            +
                    2 => :critical,
         | 
| 35 | 
            +
                    3 => :unknown
         | 
| 36 | 
            +
                  }[command_line.exit_status]
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
              end
         | 
| 40 | 
            +
            end
         | 
    
        data/lib/steto/status.rb
    ADDED
    
    | @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            module Steto
         | 
| 2 | 
            +
              class Status < String
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                def initialize(value)
         | 
| 5 | 
            +
                  super value.to_s
         | 
| 6 | 
            +
                end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                %w{ok warning critical unknown}.each do |state|
         | 
| 9 | 
            +
                  define_method("#{state}?") do 
         | 
| 10 | 
            +
                    to_s == state
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def nok?
         | 
| 15 | 
            +
                  not ok?
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
    
        data/lib/steto.rb
    ADDED
    
    | @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            require "steto/version"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Steto
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              def self.default_engine
         | 
| 6 | 
            +
                @default_engine ||= Engine.new
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              def self.config(&block)
         | 
| 10 | 
            +
                default_engine.config(&block)
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
            end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            require 'steto/cocaine_ext'
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            require 'steto/status'
         | 
| 17 | 
            +
            require 'steto/base_check'
         | 
| 18 | 
            +
            require 'steto/nagios_check'
         | 
| 19 | 
            +
            require 'steto/proc_check'
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            require 'steto/proc_reporter'
         | 
| 22 | 
            +
            require 'steto/logger_reporter'
         | 
| 23 | 
            +
            require 'steto/beep_reporter'
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            require 'steto/engine'
         | 
| 26 | 
            +
            require 'steto/config'
         | 
    
        data/spec/spec_helper.rb
    ADDED
    
    
| @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Steto::BeepReporter do
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              it "should beep twice when one of checks is critical" do
         | 
| 6 | 
            +
                subject.should_receive(:beep).with(2)
         | 
| 7 | 
            +
                subject.report [ mock :status => Steto::Status.new(:critical) ]
         | 
| 8 | 
            +
              end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              it "should beep when one of checks is warning" do
         | 
| 11 | 
            +
                subject.should_receive(:beep)
         | 
| 12 | 
            +
                subject.report [ mock :status => Steto::Status.new(:warning) ]
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              it "should not beep when no check is warning or critical" do
         | 
| 16 | 
            +
                subject.should_not_receive(:beep)
         | 
| 17 | 
            +
                subject.report [ mock :status => Steto::Status.new(:info) ]
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            end
         | 
| @@ -0,0 +1,62 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Steto::Config do
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              let(:engine) { Steto::Engine.new }
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              subject { Steto::Config.new(engine) }
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              describe "#check" do
         | 
| 10 | 
            +
                
         | 
| 11 | 
            +
                it "should use the given name for check" do
         | 
| 12 | 
            +
                  subject.check "dummy", Steto::ProcCheck
         | 
| 13 | 
            +
                  engine.checks.first.name.should == :dummy
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                it "should create a Check of given class" do
         | 
| 17 | 
            +
                  Steto::ProcCheck.should_receive(:new).with(:name => :dummy, :key1 => "value1")
         | 
| 18 | 
            +
                  subject.check "dummy", Steto::ProcCheck, :key1 => "value1"
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                it "should accept a block and create a ProcCheck" do
         | 
| 22 | 
            +
                  subject.check("dummy") {}
         | 
| 23 | 
            +
                  engine.checks.first.should be_an_instance_of(Steto::ProcCheck)
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              describe "#nagios" do
         | 
| 29 | 
            +
                
         | 
| 30 | 
            +
                it "should create Steto::NagiosCheck with given command and options" do
         | 
| 31 | 
            +
                  subject.should_receive(:check).with "dummy", Steto::NagiosCheck, :command => "/usr/lib/nagios/plugins/check_dummy", :options => { :key1 => "value1" }
         | 
| 32 | 
            +
                  subject.nagios "dummy", "check_dummy", :key1 => "value1"
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
              describe "#report" do
         | 
| 38 | 
            +
                
         | 
| 39 | 
            +
                it "should create a Reporter of given class" do
         | 
| 40 | 
            +
                  subject.report Steto::ProcReporter
         | 
| 41 | 
            +
                  engine.reporters.first.should be_instance_of(Steto::ProcReporter)
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                it "should accept a block and create a ProcReporter" do
         | 
| 45 | 
            +
                  subject.report {}
         | 
| 46 | 
            +
                  engine.reporters.first.should be_instance_of(Steto::ProcReporter)
         | 
| 47 | 
            +
                end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
              end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
              describe "#configure" do
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                it "should eval the given block" do
         | 
| 54 | 
            +
                  subject.should_receive(:check)
         | 
| 55 | 
            +
                  subject.configure do
         | 
| 56 | 
            +
                    check
         | 
| 57 | 
            +
                  end
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
                
         | 
| 60 | 
            +
              end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
            end
         | 
| @@ -0,0 +1,67 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Steto::Engine do
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              describe "#check" do
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                it "should check every check" do
         | 
| 8 | 
            +
                  3.times do
         | 
| 9 | 
            +
                    subject.checks << check = mock
         | 
| 10 | 
            +
                    check.should_receive :check
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
                  subject.check
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              describe "#config" do
         | 
| 18 | 
            +
                
         | 
| 19 | 
            +
                context "without block" do
         | 
| 20 | 
            +
                  
         | 
| 21 | 
            +
                  it "should return the engine Config" do
         | 
| 22 | 
            +
                    subject.config.engine.should == subject
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                context "with block" do
         | 
| 28 | 
            +
                  
         | 
| 29 | 
            +
                  it "should configure with block" do
         | 
| 30 | 
            +
                    subject.config.should_receive(:configure).and_yield
         | 
| 31 | 
            +
                    subject.config { }
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
                
         | 
| 36 | 
            +
              end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
              describe "#report" do
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                before(:each) do
         | 
| 41 | 
            +
                  subject.stub :checks => "checks"
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                let(:reporter) { mock } 
         | 
| 45 | 
            +
                
         | 
| 46 | 
            +
                context "with a reporter is given" do
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                  it "should create report with it" do
         | 
| 49 | 
            +
                    reporter.should_receive(:report).with(subject.checks)
         | 
| 50 | 
            +
                    subject.report reporter
         | 
| 51 | 
            +
                  end
         | 
| 52 | 
            +
                                                     
         | 
| 53 | 
            +
                end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                context "without argument" do
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                  it "should use all predefined reporters" do
         | 
| 58 | 
            +
                    subject.reporters << reporter
         | 
| 59 | 
            +
                    reporter.should_receive(:report).with(subject.checks)
         | 
| 60 | 
            +
                    subject.report
         | 
| 61 | 
            +
                  end
         | 
| 62 | 
            +
                                             
         | 
| 63 | 
            +
                end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
              end
         | 
| 66 | 
            +
             | 
| 67 | 
            +
            end
         | 
| @@ -0,0 +1,40 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Steto::LoggerReporter do
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              def check(status, attributes = {})
         | 
| 6 | 
            +
                attributes = { 
         | 
| 7 | 
            +
                  :name => "dummy", 
         | 
| 8 | 
            +
                  :text => "Dummy check", 
         | 
| 9 | 
            +
                  :status => Steto::Status.new(status) 
         | 
| 10 | 
            +
                }.merge(attributes)
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                mock attributes
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              it "should log in warn the warning checks" do
         | 
| 16 | 
            +
                subject.logger.should_receive(:warn)
         | 
| 17 | 
            +
                subject.report [ check(:warning) ]
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              it "should log in error the critical checks" do
         | 
| 21 | 
            +
                subject.logger.should_receive(:error)
         | 
| 22 | 
            +
                subject.report [ check(:critical) ]
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
              it "should log in debug the ok/unknown checks" do
         | 
| 26 | 
            +
                subject.logger.should_receive(:debug)
         | 
| 27 | 
            +
                subject.report [ check(:ok) ]
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              it "should include name and status in message" do
         | 
| 31 | 
            +
                subject.logger.should_receive(:debug).with("dummy is ok")
         | 
| 32 | 
            +
                subject.report [ check(:ok, :name => "dummy", :text => nil) ]
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
              it "should include text when available in message" do
         | 
| 36 | 
            +
                subject.logger.should_receive(:debug).with("dummy is ok: text")
         | 
| 37 | 
            +
                subject.report [ check(:ok, :name => "dummy", :text => "text") ]
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
            end
         | 
| @@ -0,0 +1,48 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Steto::NagiosCheck do
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              describe "#status" do
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                it "should be ok when nagios check returns OK status" do
         | 
| 8 | 
            +
                  Steto::NagiosCheck.new(:command => "/usr/lib/nagios/plugins/check_dummy 0").status.should be_ok
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                it "should be warning when nagios check returns WARNING status" do
         | 
| 12 | 
            +
                  Steto::NagiosCheck.new(:command => "/usr/lib/nagios/plugins/check_dummy 1").status.should be_warning
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                it "should be critical when nagios check returns CRITICAL status" do
         | 
| 16 | 
            +
                  Steto::NagiosCheck.new(:command => "/usr/lib/nagios/plugins/check_dummy 2").status.should be_critical
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                it "should be unknown when nagios check returns UNKNOWN status" do
         | 
| 20 | 
            +
                  Steto::NagiosCheck.new(:command => "/usr/lib/nagios/plugins/check_dummy 3").status.should be_unknown
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
                
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
              describe "#text" do
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                it "should be text returned by nagios check" do
         | 
| 28 | 
            +
                  Steto::NagiosCheck.new(:command => "/usr/lib/nagios/plugins/check_dummy 0 'additionnal text'").text.should == "OK: additionnal text"
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
              describe "#command_line" do
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                it "should use command as binary" do
         | 
| 36 | 
            +
                  subject.stub :command => "dummy"
         | 
| 37 | 
            +
                  subject.command_line.command.should == "dummy"
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                it "should use options as parameters" do
         | 
| 41 | 
            +
                  subject.stub :command => "dummy"
         | 
| 42 | 
            +
                  subject.stub :options => { :warning => "1,0.5,0.5", :critical => "1,1,1" }
         | 
| 43 | 
            +
                  subject.command_line.command.should == "dummy --critical='1,1,1' --warning='1,0.5,0.5'"
         | 
| 44 | 
            +
                end
         | 
| 45 | 
            +
                
         | 
| 46 | 
            +
              end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
            end
         | 
    
        data/steto.gemspec
    ADDED
    
    | @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            +
            $:.push File.expand_path("../lib", __FILE__)
         | 
| 3 | 
            +
            require "steto/version"
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Gem::Specification.new do |s|
         | 
| 6 | 
            +
              s.name        = "steto"
         | 
| 7 | 
            +
              s.version     = Steto::VERSION
         | 
| 8 | 
            +
              s.authors     = ["Alban Peignier", "Florent Peyraud"]
         | 
| 9 | 
            +
              s.email       = ["alban@tryphon.eu", "florent@tryphon.eu"]
         | 
| 10 | 
            +
              s.homepage    = "https://github.com/tryphon/steto"
         | 
| 11 | 
            +
              s.summary     = %q{Check system status}
         | 
| 12 | 
            +
              s.description = %q{Ruby engine to check system status (with Nagios or custom checks)}
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              s.rubyforge_project = "steto"
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              s.files         = `git ls-files`.split("\n")
         | 
| 17 | 
            +
              s.test_files    = `git ls-files -- {test,spec,features}/*`.split("\n")
         | 
| 18 | 
            +
              s.executables   = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
         | 
| 19 | 
            +
              s.require_paths = ["lib"]
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              # specify any dependencies here; for example:
         | 
| 22 | 
            +
              s.add_development_dependency "rspec"
         | 
| 23 | 
            +
              s.add_development_dependency "rake"
         | 
| 24 | 
            +
              s.add_development_dependency "rcov"
         | 
| 25 | 
            +
              s.add_development_dependency "RedCloth"
         | 
| 26 | 
            +
             | 
| 27 | 
            +
              s.add_runtime_dependency "cocaine"
         | 
| 28 | 
            +
              s.add_runtime_dependency "parallel"
         | 
| 29 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,181 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification 
         | 
| 2 | 
            +
            name: steto
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            +
              hash: 29
         | 
| 5 | 
            +
              prerelease: 
         | 
| 6 | 
            +
              segments: 
         | 
| 7 | 
            +
              - 0
         | 
| 8 | 
            +
              - 0
         | 
| 9 | 
            +
              - 1
         | 
| 10 | 
            +
              version: 0.0.1
         | 
| 11 | 
            +
            platform: ruby
         | 
| 12 | 
            +
            authors: 
         | 
| 13 | 
            +
            - Alban Peignier
         | 
| 14 | 
            +
            - Florent Peyraud
         | 
| 15 | 
            +
            autorequire: 
         | 
| 16 | 
            +
            bindir: bin
         | 
| 17 | 
            +
            cert_chain: []
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            date: 2012-05-28 00:00:00 Z
         | 
| 20 | 
            +
            dependencies: 
         | 
| 21 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 22 | 
            +
              prerelease: false
         | 
| 23 | 
            +
              type: :development
         | 
| 24 | 
            +
              requirement: &id001 !ruby/object:Gem::Requirement 
         | 
| 25 | 
            +
                none: false
         | 
| 26 | 
            +
                requirements: 
         | 
| 27 | 
            +
                - - ">="
         | 
| 28 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 29 | 
            +
                    hash: 3
         | 
| 30 | 
            +
                    segments: 
         | 
| 31 | 
            +
                    - 0
         | 
| 32 | 
            +
                    version: "0"
         | 
| 33 | 
            +
              name: rspec
         | 
| 34 | 
            +
              version_requirements: *id001
         | 
| 35 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 36 | 
            +
              prerelease: false
         | 
| 37 | 
            +
              type: :development
         | 
| 38 | 
            +
              requirement: &id002 !ruby/object:Gem::Requirement 
         | 
| 39 | 
            +
                none: false
         | 
| 40 | 
            +
                requirements: 
         | 
| 41 | 
            +
                - - ">="
         | 
| 42 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 43 | 
            +
                    hash: 3
         | 
| 44 | 
            +
                    segments: 
         | 
| 45 | 
            +
                    - 0
         | 
| 46 | 
            +
                    version: "0"
         | 
| 47 | 
            +
              name: rake
         | 
| 48 | 
            +
              version_requirements: *id002
         | 
| 49 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 50 | 
            +
              prerelease: false
         | 
| 51 | 
            +
              type: :development
         | 
| 52 | 
            +
              requirement: &id003 !ruby/object:Gem::Requirement 
         | 
| 53 | 
            +
                none: false
         | 
| 54 | 
            +
                requirements: 
         | 
| 55 | 
            +
                - - ">="
         | 
| 56 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 57 | 
            +
                    hash: 3
         | 
| 58 | 
            +
                    segments: 
         | 
| 59 | 
            +
                    - 0
         | 
| 60 | 
            +
                    version: "0"
         | 
| 61 | 
            +
              name: rcov
         | 
| 62 | 
            +
              version_requirements: *id003
         | 
| 63 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 64 | 
            +
              prerelease: false
         | 
| 65 | 
            +
              type: :development
         | 
| 66 | 
            +
              requirement: &id004 !ruby/object:Gem::Requirement 
         | 
| 67 | 
            +
                none: false
         | 
| 68 | 
            +
                requirements: 
         | 
| 69 | 
            +
                - - ">="
         | 
| 70 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 71 | 
            +
                    hash: 3
         | 
| 72 | 
            +
                    segments: 
         | 
| 73 | 
            +
                    - 0
         | 
| 74 | 
            +
                    version: "0"
         | 
| 75 | 
            +
              name: RedCloth
         | 
| 76 | 
            +
              version_requirements: *id004
         | 
| 77 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 78 | 
            +
              prerelease: false
         | 
| 79 | 
            +
              type: :runtime
         | 
| 80 | 
            +
              requirement: &id005 !ruby/object:Gem::Requirement 
         | 
| 81 | 
            +
                none: false
         | 
| 82 | 
            +
                requirements: 
         | 
| 83 | 
            +
                - - ">="
         | 
| 84 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 85 | 
            +
                    hash: 3
         | 
| 86 | 
            +
                    segments: 
         | 
| 87 | 
            +
                    - 0
         | 
| 88 | 
            +
                    version: "0"
         | 
| 89 | 
            +
              name: cocaine
         | 
| 90 | 
            +
              version_requirements: *id005
         | 
| 91 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 92 | 
            +
              prerelease: false
         | 
| 93 | 
            +
              type: :runtime
         | 
| 94 | 
            +
              requirement: &id006 !ruby/object:Gem::Requirement 
         | 
| 95 | 
            +
                none: false
         | 
| 96 | 
            +
                requirements: 
         | 
| 97 | 
            +
                - - ">="
         | 
| 98 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 99 | 
            +
                    hash: 3
         | 
| 100 | 
            +
                    segments: 
         | 
| 101 | 
            +
                    - 0
         | 
| 102 | 
            +
                    version: "0"
         | 
| 103 | 
            +
              name: parallel
         | 
| 104 | 
            +
              version_requirements: *id006
         | 
| 105 | 
            +
            description: Ruby engine to check system status (with Nagios or custom checks)
         | 
| 106 | 
            +
            email: 
         | 
| 107 | 
            +
            - alban@tryphon.eu
         | 
| 108 | 
            +
            - florent@tryphon.eu
         | 
| 109 | 
            +
            executables: []
         | 
| 110 | 
            +
             | 
| 111 | 
            +
            extensions: []
         | 
| 112 | 
            +
             | 
| 113 | 
            +
            extra_rdoc_files: []
         | 
| 114 | 
            +
             | 
| 115 | 
            +
            files: 
         | 
| 116 | 
            +
            - .gitignore
         | 
| 117 | 
            +
            - Gemfile
         | 
| 118 | 
            +
            - Guardfile
         | 
| 119 | 
            +
            - License.txt
         | 
| 120 | 
            +
            - README.textile
         | 
| 121 | 
            +
            - Rakefile
         | 
| 122 | 
            +
            - config-sample.rb
         | 
| 123 | 
            +
            - lib/steto.rb
         | 
| 124 | 
            +
            - lib/steto/base_check.rb
         | 
| 125 | 
            +
            - lib/steto/beep_reporter.rb
         | 
| 126 | 
            +
            - lib/steto/cocaine_ext.rb
         | 
| 127 | 
            +
            - lib/steto/config.rb
         | 
| 128 | 
            +
            - lib/steto/engine.rb
         | 
| 129 | 
            +
            - lib/steto/logger_reporter.rb
         | 
| 130 | 
            +
            - lib/steto/nagios_check.rb
         | 
| 131 | 
            +
            - lib/steto/proc_check.rb
         | 
| 132 | 
            +
            - lib/steto/proc_reporter.rb
         | 
| 133 | 
            +
            - lib/steto/status.rb
         | 
| 134 | 
            +
            - lib/steto/version.rb
         | 
| 135 | 
            +
            - spec/spec_helper.rb
         | 
| 136 | 
            +
            - spec/steto/beep_reporter_spec.rb
         | 
| 137 | 
            +
            - spec/steto/config_spec.rb
         | 
| 138 | 
            +
            - spec/steto/engine_spec.rb
         | 
| 139 | 
            +
            - spec/steto/logger_reporter_spec.rb
         | 
| 140 | 
            +
            - spec/steto/nagios_check_spec.rb
         | 
| 141 | 
            +
            - steto.gemspec
         | 
| 142 | 
            +
            homepage: https://github.com/tryphon/steto
         | 
| 143 | 
            +
            licenses: []
         | 
| 144 | 
            +
             | 
| 145 | 
            +
            post_install_message: 
         | 
| 146 | 
            +
            rdoc_options: []
         | 
| 147 | 
            +
             | 
| 148 | 
            +
            require_paths: 
         | 
| 149 | 
            +
            - lib
         | 
| 150 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         | 
| 151 | 
            +
              none: false
         | 
| 152 | 
            +
              requirements: 
         | 
| 153 | 
            +
              - - ">="
         | 
| 154 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 155 | 
            +
                  hash: 3
         | 
| 156 | 
            +
                  segments: 
         | 
| 157 | 
            +
                  - 0
         | 
| 158 | 
            +
                  version: "0"
         | 
| 159 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         | 
| 160 | 
            +
              none: false
         | 
| 161 | 
            +
              requirements: 
         | 
| 162 | 
            +
              - - ">="
         | 
| 163 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 164 | 
            +
                  hash: 3
         | 
| 165 | 
            +
                  segments: 
         | 
| 166 | 
            +
                  - 0
         | 
| 167 | 
            +
                  version: "0"
         | 
| 168 | 
            +
            requirements: []
         | 
| 169 | 
            +
             | 
| 170 | 
            +
            rubyforge_project: steto
         | 
| 171 | 
            +
            rubygems_version: 1.8.15
         | 
| 172 | 
            +
            signing_key: 
         | 
| 173 | 
            +
            specification_version: 3
         | 
| 174 | 
            +
            summary: Check system status
         | 
| 175 | 
            +
            test_files: 
         | 
| 176 | 
            +
            - spec/spec_helper.rb
         | 
| 177 | 
            +
            - spec/steto/beep_reporter_spec.rb
         | 
| 178 | 
            +
            - spec/steto/config_spec.rb
         | 
| 179 | 
            +
            - spec/steto/engine_spec.rb
         | 
| 180 | 
            +
            - spec/steto/logger_reporter_spec.rb
         | 
| 181 | 
            +
            - spec/steto/nagios_check_spec.rb
         |