Created
July 5, 2013 18:43
-
-
Save silfreed/5936442 to your computer and use it in GitHub Desktop.
Nagios Facter Check script using ruby-nagios-plugin -- untested
This file contains 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
#!/usr/bin/ruby | |
require 'facter' | |
require 'nagios-plugin' | |
Facter.search "/var/lib/puppet/lib/facter/" | |
class FacterPlugin < Nagios::Plugin | |
def run | |
result = nil | |
fact_name = nil | |
@opts.on("-f", "--fact_name FACT_NAME", "fact name") do |f| | |
fact_name = f | |
@shortname = f | |
end | |
@opts.on("-n", "--shortname SHORT_NAME", "Short name for result") do |s| | |
@shortname = s | |
end | |
parse_argv() | |
raise OptionParser::MissingArgument if @critical.nil? | |
raise OptionParser::MissingArgument if @warning.nil? | |
raise OptionParser::MissingArgument if fact_name.nil? | |
begin | |
result = Facter.value(fact_name) | |
rescue | |
Facter.loadfacts() | |
result = Facter.value(fact_name) | |
end | |
if result.nil? | |
unknown("Result unknown #{result}") | |
elsif range_match(result, @critical) | |
critical("Result out of bounds #{result} #{@critical}") | |
elsif range_match(result, @warning) | |
warning("Result out of bounds #{result} #{@warning}") | |
end | |
ok("#{result}") | |
end | |
end | |
@plugin = FacterPlugin.new | |
@plugin.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment