Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dusty Doris
committed
Sep 29, 2009
0 parents
commit 8c54a72
Showing
30 changed files
with
2,723 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
libexec/* |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
command=/opt/nagios-custom-plugins/bin/snmp_check_procs.rb | ||
cmd=/tmp/nag.cmd | ||
out=/tmp/nag.out | ||
err=/tmp/nag.err | ||
|
||
echo "${command} $*" > $cmd | ||
eval "./${command} $*" > $out 2> $err |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#!/usr/bin/env ruby | ||
require 'optparse' | ||
require File.join(File.dirname(__FILE__), "..", 'lib', 'command_helper') | ||
require File.join(File.dirname(__FILE__), "..", 'lib', 'nagios_check') | ||
require File.join(File.dirname(__FILE__), "..", 'lib', 'nagios_result') | ||
require File.join(File.dirname(__FILE__), "..", 'lib', 'rsync_utils') | ||
|
||
include CommandHelper | ||
|
||
@details = <<EOD | ||
Description: | ||
Check the age of files in an rsync module path and return nagios | ||
check states if results are outside the specified ranges. Time | ||
ranges should be specified in seconds. | ||
Example: | ||
Check for files on somehost in the somedir module and anotherdir/ | ||
sub-directory. Return a warning state if files are outside the range | ||
of 0-10 seconds old. Return a critical state if files are outside the | ||
range of 10-20 seconds old. | ||
$ rsync_file_age.rb -H somehost -P somedir/anotherdir/ -w "0:10" -c "10:20" | ||
EOD | ||
|
||
@options = {} | ||
# Default | ||
@opts = OptionParser.new | ||
|
||
@opts.on( | ||
"-H", "--hostname HOSTNAME", "Hostname" | ||
) { |value| @options[:hostname] = value } | ||
|
||
@opts.on( | ||
"-P", "--path PATH", "Path to Query" | ||
) { |value| @options[:path] = value } | ||
|
||
@opts.on( | ||
"-w", "--warning WARNING", "Return warning if outside this range" | ||
) { |value| @options[:warning] = value } | ||
|
||
@opts.on( | ||
"-c", "--critical CRITICAL", "Return critical if outside this range" | ||
) { |value| @options[:critical]= value } | ||
|
||
@opts.on( | ||
'-r', "--recursive", "Search recursively" | ||
) { |value| @options[:recursive] = value } | ||
|
||
@opts.on( | ||
"-d", "--drift DRIFT", "Time drift in seconds" | ||
) { |value| @options[:drift] = value } | ||
|
||
@opts.on( | ||
"-v", "--verbose", "Print out all files in path" | ||
) { |value| @options[:verbose] = true } | ||
|
||
@opts.on( | ||
"-h", "--help", "Show Command Help" | ||
) { |v| print_details } | ||
|
||
@opts.on( | ||
"-R", "--ranges", "Show Ranges Help" | ||
) { |v| print_ranges } | ||
|
||
|
||
|
||
def get_files | ||
rsync = RsyncUtils.new | ||
rsync.show(@options[:hostname],@options[:path],@options[:recursive]) | ||
end | ||
|
||
def check_files | ||
nagios = nagios_check_age(get_files) | ||
nagios.message = "#{nagios.result} files #{nagios.threshold} seconds old" | ||
nagios | ||
end | ||
|
||
def nagios_check_age(list) | ||
check = NagiosCheck.new(@options[:warning], @options[:critical]) | ||
files = [] | ||
list.results.each do |file| | ||
if file.is_file? | ||
diff = ((::Time.now - file.time) - @options[:drift].to_i).to_i | ||
files << check.compare(diff) | ||
end | ||
end | ||
crit = files.select {|r| r.kind_of? NagiosResult::Critical }.length | ||
warn = files.select {|r| r.kind_of? NagiosResult::Warning }.length | ||
return NagiosResult::Critical.new(check.critical[:output],crit) if crit > 0 | ||
return NagiosResult::Warning.new(check.warning[:output],warn) if warn > 0 | ||
return NagiosResult::Ok.new(check.ok[:output],0) | ||
end | ||
|
||
begin | ||
@opts.parse! | ||
rescue StandardError => e | ||
print_help("Error: #{e.message}") unless e.message == "exit" | ||
end | ||
|
||
unless @options[:hostname] && @options[:path] | ||
print_help("Missing Arguments: hostname and path are required.") | ||
end | ||
|
||
begin | ||
if @options[:verbose] | ||
puts get_files.stdout | ||
else | ||
print_results(check_files) | ||
end | ||
rescue StandardError => e | ||
print_exception(e) | ||
end | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#!/usr/bin/env ruby | ||
require 'optparse' | ||
require File.join(File.dirname(__FILE__), "..", 'lib', 'command_helper') | ||
require File.join(File.dirname(__FILE__), "..", 'lib', 'nagios_check') | ||
require File.join(File.dirname(__FILE__), "..", 'lib', 'nagios_result') | ||
require File.join(File.dirname(__FILE__), "..", 'lib', 'rsync_utils') | ||
|
||
include CommandHelper | ||
|
||
@details = <<EOD | ||
Description: | ||
Check the size of files in an rsync module path and return nagios | ||
check states if any files are outside the specified ranges. | ||
Example: | ||
Check for files on somehost in the somedir module and anotherdir/ | ||
sub-directory. Return a warning state if any files are outside the size | ||
of 0-5 MB. | ||
$ rsync_file_size.rb -H somehost -P somedir/anotherdir/ -w "0:5" | ||
EOD | ||
|
||
@options = {} | ||
|
||
@opts = OptionParser.new | ||
|
||
@opts.on( | ||
"-H", "--hostname HOSTNAME", "Hostname" | ||
) { |value| @options[:hostname] = value } | ||
|
||
@opts.on( | ||
"-P", "--path PATH", "Path to Query" | ||
) { |value| @options[:path] = value} | ||
|
||
@opts.on( | ||
"-w", "--warning WARNING", "Return warning if outside this range" | ||
) { |value| @options[:warning] = value } | ||
|
||
@opts.on( | ||
"-c", "--critical CRITICAL", "Return critical if outside this range" | ||
) { |value| @options[:critical]= value } | ||
|
||
@opts.on( | ||
'-r', "--recursive", "Search recursively" | ||
) { |value| @options[:recursive] = true } | ||
|
||
@opts.on( | ||
"-v", "--verbose", "Print out all files in path" | ||
) { |value| @options[:verbose] = true } | ||
|
||
@opts.on( | ||
"-h", "--help", "Show Command Help" | ||
) { |v| print_details } | ||
|
||
@opts.on( | ||
"-R", "--ranges", "Show Ranges Help" | ||
) { |v| print_ranges } | ||
|
||
|
||
def get_files | ||
rsync = RsyncUtils.new | ||
rsync.show(@options[:hostname],@options[:path],@options[:recursive]) | ||
end | ||
|
||
def check_files | ||
begin | ||
nagios = nagios_check_size(get_files) | ||
nagios.message = "#{nagios.result} files #{nagios.threshold} MB in size" | ||
nagios | ||
rescue Exception => e | ||
puts "CRITICAL: #{e.message[0,68]}" | ||
exit(2) | ||
end | ||
end | ||
|
||
def nagios_check_size(list) | ||
check = NagiosCheck.new(@options[:warning], @options[:critical]) | ||
files = [] | ||
list.results.each do |file| | ||
if file.is_file? | ||
files << check.compare(file.size_mb) | ||
end | ||
end | ||
crit = files.select {|r| r.kind_of? NagiosResult::Critical }.length | ||
warn = files.select {|r| r.kind_of? NagiosResult::Warning }.length | ||
return NagiosResult::Critical.new(check.critical[:output],crit) if crit > 0 | ||
return NagiosResult::Warning.new(check.warning[:output],warn) if warn > 0 | ||
return NagiosResult::Ok.new(check.ok[:output],0) | ||
end | ||
|
||
begin | ||
@opts.parse! | ||
rescue StandardError => e | ||
print_help("Error: #{e.message}") unless e.message == "exit" | ||
end | ||
|
||
unless @options[:hostname] && @options[:path] | ||
print_help("Missing Arguments: hostname and path are required.") | ||
end | ||
|
||
begin | ||
if @options[:verbose] | ||
puts get_files.stdout | ||
else | ||
print_results(check_files) | ||
end | ||
rescue StandardError => e | ||
print_exception(e) | ||
end | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/usr/bin/env ruby | ||
require 'optparse' | ||
require File.join(File.dirname(__FILE__), "..", 'lib', 'command_helper') | ||
require File.join(File.dirname(__FILE__), "..", 'lib', 'nagios_check') | ||
require File.join(File.dirname(__FILE__), "..", 'lib', 'nagios_result') | ||
require File.join(File.dirname(__FILE__), "..", 'lib', 'system_cpu') | ||
|
||
include CommandHelper | ||
|
||
@details = <<EOD | ||
Description: | ||
Check the CPU utilization of a host and return nagios | ||
check states if results are outside the specified ranges. | ||
Example: | ||
Check for CPU utilization on somehost. Warn if more than | ||
50%, critical if more than 75%. | ||
$ snmp_cpu.rb -H somehost -w "~:50" -c "~:75" | ||
EOD | ||
|
||
@options = {} | ||
|
||
@opts = OptionParser.new | ||
|
||
@opts.on( | ||
"-H", "--hostname HOSTNAME", "Hostname" | ||
) { |value| @options[:hostname] = value } | ||
|
||
@opts.on( | ||
"-w", "--warning WARNING", "Return warning if outside this range" | ||
) { |value| @options[:warning] = value } | ||
|
||
@opts.on( | ||
"-c", "--critical CRITICAL", "Return critical if outside this range" | ||
) { |value| @options[:critical] = value } | ||
|
||
@opts.on( | ||
"-v", "--verbose", "Print out all cpu usage" | ||
) { |value| @options[:verbose] = true } | ||
|
||
@opts.on( | ||
"-h", "--help", "Show Command Help" | ||
) { |v| print_details } | ||
|
||
@opts.on( | ||
"-R", "--ranges", "Show Ranges Help" | ||
) { |v| print_ranges } | ||
|
||
def get_cpu | ||
SystemCpu.find_by_host(@options[:hostname]) | ||
end | ||
|
||
def check_cpu | ||
check = NagiosCheck.new(@options[:warning], @options[:critical]) | ||
cpus = get_cpu | ||
max = cpus.max {|a,b| a.used_percent <=> b.used_percent} | ||
nagios = check.compare(max.used_percent) | ||
nagios.message = "Max CPU Utilization at #{nagios.result} %" | ||
nagios | ||
end | ||
|
||
begin | ||
@opts.parse! | ||
rescue StandardError => e | ||
print_help("Error: #{e.message}") unless e.message == "exit" | ||
end | ||
|
||
unless @options[:hostname] | ||
print_help("Missing Arguments: hostname is required.") | ||
end | ||
|
||
begin | ||
if @options[:verbose] | ||
puts get_cpu | ||
else | ||
print_results(check_cpu) | ||
end | ||
rescue StandardError => e | ||
print_exception(e) | ||
end | ||
|
Oops, something went wrong.