Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A Ruby Gem to easily create Nagios Plugins.
branch: master

Merge pull request #4 from smintz/documentation

Adding example documentation to README.md
latest commit bc5056fcc9
Joshua Harding authored

README.rdoc

nagios-plugin

DESCRIPTION:

This allows you to easily write Nagios plugins in Ruby.

Example

#!/usr/bin/env ruby
require 'rubygems'
require 'nagios-plugin'
require 'time'

class MyNagiosCheck < Nagios::Plugin
  # What should run when check is run
  def run

    # Get more options via arguments using the OptParse object.
    # -w and -c for warning and critical thresholds are already included
    @opts.on('-H', '--host HOST', 'Proxy server to check') do |h|
      @proxy_host = h
    end

    # Init the argument parser
    parse_argv

    # Begin the check
    begin

      # Record the second when the check started to run
      started_at=Time.now

      # Run the commands you actually need for your check

      some_ruby_code_to_run

      # Calculate the run time
      run_time = Time.now - started_at

      # Add Performance data
      add_perfdata(:field => "run time", :data => run_time, :critical => @critical, :warning => @warning, :uom => 'secs')

      # Check the values against the thresholds
      if run_time > @critical.to_f
        critical("Took more than #{@critical}")
      elsif run_time > @warning.to_f
        warning("Took more than #{@warning}")
      else
        ok("Yay!")
      end

    # When the code has failed
    rescue
      critical("Check Failed!")
    end
  end
end

# Initialize and run the check!
@my_nagios_check = MyNagiosCheck.new(:shortname => 'my_nagios_check')
@my_nagios_check.run

LICENSE:

(The MIT License)

Copyright © 2011 Joshua Harding

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Something went wrong with that request. Please try again.