Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add nagios and sudo cookbook

  • Loading branch information...
commit c371ceb40a9364c811bd29645134eddfa6e9b283 1 parent e663afc
Joshua Sierles authored
Showing with 14,429 additions and 0 deletions.
  1. +31 −0 nagios/attributes/client.rb
  2. +32 −0 nagios/attributes/server.rb
  3. +22 −0 nagios/definitions/nagios_conf.rb
  4. +3 −0  nagios/definitions/nagios_service_template.rb
  5. +65 −0 nagios/files/default/notifiers/bulksms
  6. +60 −0 nagios/files/default/notifiers/campfire
  7. +66 −0 nagios/files/default/notifiers/clickatell
  8. +40 −0 nagios/files/default/notifiers/jabber
  9. +84 −0 nagios/files/default/notifiers/jabber_bot
  10. +19 −0 nagios/files/default/notifiers/send_passive_check
  11. +81 −0 nagios/files/default/notifiers/twilio
  12. +158 −0 nagios/files/default/plugins/check-mysql-slave.pl
  13. +161 −0 nagios/files/default/plugins/check_bl_async.pl
  14. +237 −0 nagios/files/default/plugins/check_cisco.pl
  15. +230 −0 nagios/files/default/plugins/check_cisco_stack.pl
  16. +726 −0 nagios/files/default/plugins/check_cpu.pl
  17. +96 −0 nagios/files/default/plugins/check_exceptions_log_error_rate.rb
  18. +69 −0 nagios/files/default/plugins/check_file_age.rb
  19. +194 −0 nagios/files/default/plugins/check_fortigate_memory.pl
  20. +194 −0 nagios/files/default/plugins/check_fortigate_session.pl
  21. +90 −0 nagios/files/default/plugins/check_highrise.rb
  22. +117 −0 nagios/files/default/plugins/check_http_log_error_rate.rb
  23. +98 −0 nagios/files/default/plugins/check_mem.sh
  24. +86 −0 nagios/files/default/plugins/check_mogilefs_bored_workers.rb
  25. +49 −0 nagios/files/default/plugins/check_mysql_backup_size.sh
  26. +3,181 −0 nagios/files/default/plugins/check_mysql_health
  27. +59 −0 nagios/files/default/plugins/check_mysql_lzop_backup_integrity.sh
  28. +67 −0 nagios/files/default/plugins/check_mysql_readonly.rb
  29. +73 −0 nagios/files/default/plugins/check_mysql_slave_warmer.rb
  30. +4,877 −0 nagios/files/default/plugins/check_openmanage
  31. +23 −0 nagios/files/default/plugins/check_redis.rb
  32. +45 −0 nagios/files/default/plugins/check_resque_queue.rb
  33. +42 −0 nagios/files/default/plugins/check_ruby_version.rb
  34. +125 −0 nagios/files/default/plugins/check_solr.rb
  35. +102 −0 nagios/files/default/plugins/db_queues.rb
  36. +7 −0 nagios/files/default/plugins/dell_check_controller_battery_learn_state.sh
  37. +7 −0 nagios/files/default/plugins/dell_check_controller_battery_next_learn_time.sh
  38. +84 −0 nagios/files/default/plugins/file_queues.rb
  39. +118 −0 nagios/files/default/plugins/ganglia_metrics.rb
  40. +88 −0 nagios/files/default/plugins/haproxy_stats.rb
  41. +26 −0 nagios/files/default/plugins/nagios_helper.rb
  42. +219 −0 nagios/files/default/plugins/pagerduty_nagios.pl
  43. +17 −0 nagios/files/default/plugins/passenger_detect_hung_processes
  44. +26 −0 nagios/files/default/plugins/unicorn_detect_old_processes
  45. +19 −0 nagios/libraries/default.rb
  46. +8 −0 nagios/metadata.rb
  47. +31 −0 nagios/recipes/client.rb
  48. 0  nagios/recipes/default.rb
  49. +168 −0 nagios/recipes/secondary.rb
  50. +236 −0 nagios/recipes/server.rb
  51. +29 −0 nagios/templates/default/apache2.conf.erb
  52. +34 −0 nagios/templates/default/cgi.cfg.erb
  53. +563 −0 nagios/templates/default/commands.cfg.erb
  54. +39 −0 nagios/templates/default/contacts.cfg.erb
  55. +29 −0 nagios/templates/default/hostgroups.cfg.erb
  56. +84 −0 nagios/templates/default/hosts.cfg.erb
  57. +151 −0 nagios/templates/default/nagios.cfg.erb
  58. +54 −0 nagios/templates/default/nginx.conf.erb
  59. +20 −0 nagios/templates/default/nrpe.cfg.erb
  60. +22 −0 nagios/templates/default/pagerduty_nagios.cfg.erb
  61. +7 −0 nagios/templates/default/sec_hostgroups.cfg.erb
  62. +45 −0 nagios/templates/default/sec_hosts.cfg.erb
  63. +54 −0 nagios/templates/default/sec_nginx.conf.erb
  64. +95 −0 nagios/templates/default/sec_service_templates.cfg.erb
  65. +41 −0 nagios/templates/default/sec_services.cfg.erb
  66. +105 −0 nagios/templates/default/service_templates.cfg.erb
  67. +330 −0 nagios/templates/default/services.cfg.erb
  68. +2 −0  nagios/templates/default/sv-nagios-bot-log-run.erb
  69. +4 −0 nagios/templates/default/sv-nagios-bot-run.erb
  70. +2 −0  nagios/templates/default/sv-nagios3-log-run.erb
  71. +4 −0 nagios/templates/default/sv-nagios3-run.erb
  72. 0  nagios/templates/default/templates.cfg.erb
  73. +14 −0 nagios/templates/default/timeperiods.cfg.erb
  74. 0  sudo/attributes/sudoers.rb
  75. +5 −0 sudo/metadata.rb
  76. +14 −0 sudo/recipes/default.rb
  77. +26 −0 sudo/templates/default/sudoers.erb
31 nagios/attributes/client.rb
View
@@ -0,0 +1,31 @@
+default.nagios[:plugins_dir] = "/u/nagios/plugins"
+
+# load average check: 5, 10 and 15 minute averages
+default.nagios[:checks][:load][:enable] = true
+default.nagios[:checks][:load][:warning] = "15,10,7"
+default.nagios[:checks][:load][:critical] = "30,20,10"
+
+# free memory
+default.nagios[:checks][:free_memory][:enable] = true
+default.nagios[:checks][:free_memory][:warning] = 250
+default.nagios[:checks][:free_memory][:critical] = 150
+
+# free disk space percentage
+default.nagios[:checks][:free_disk][:enable] = true
+default.nagios[:checks][:free_disk][:warning] = "8"
+default.nagios[:checks][:free_disk][:critical] = "5"
+
+# HAProxy
+default.nagios[:checks][:haproxy_queue][:enable] = true
+default.nagios[:checks][:haproxy_queue][:critical] = "10"
+default.nagios[:checks][:haproxy_queue][:warning] = "1"
+
+# HTTP error rates
+default.nagios[:checks][:http_error_rate][:enable] = true
+default.nagios[:checks][:http_error_rate][:critical] = "20"
+default.nagios[:checks][:http_error_rate][:warning] = "15"
+
+# Exceptions error rates
+default.nagios[:checks][:exceptions_log_error_rate][:enable] = true
+default.nagios[:checks][:exceptions_log_error_rate][:critical] = "30"
+default.nagios[:checks][:exceptions_log_error_rate][:warning] = "10"
32 nagios/attributes/server.rb
View
@@ -0,0 +1,32 @@
+default.nagios[:root] = "/etc/nagios3"
+default.nagios[:webroot] = "/usr/share/nagios3/htdocs"
+default.nagios[:bin_path] = "/usr/sbin/nagios3"
+default.nagios[:config_path] = "/etc/nagios3/nagios.cfg"
+default.nagios[:config_subdir] = "conf.d"
+default.nagios[:notifications_enabled] = 1
+default.nagios[:check_external_commands] = true
+default.nagios[:default_contact_groups] = %w(sysadmin)
+
+# This setting is effectively sets the minimum interval (in seconds) nagios can handle.
+# Other interval settings provided in seconds will calculate their actual from this value, since nagios works in 'time units' rather than allowing definitions everywhere in seconds
+
+default.nagios[:templates][:service] = {}
+
+default.nagios[:interval_length] = 1
+
+default.nagios[:default_host][:check_interval] = 15
+default.nagios[:default_host][:retry_interval] = 15
+default.nagios[:default_host][:notification_interval] = 300
+default.nagios[:default_host][:max_check_attempts] = 1
+
+default.nagios[:default_service][:check_interval] = 60
+default.nagios[:default_service][:retry_interval] = 15
+default.nagios[:default_service][:notification_interval] = 600
+default.nagios[:default_service][:max_check_attempts] = 3
+
+default.nagios[:notifiers_dir] = "/var/lib/nagios3/notifiers"
+
+default.nagios[:bot_path] = "#{nagios[:notifiers_dir]}/jabber_bot"
+
+# http checks
+#default.nagios[:checks][:http][:enable]
22 nagios/definitions/nagios_conf.rb
View
@@ -0,0 +1,22 @@
+define :nagios_conf, :variables => {}, :config_subdir => true, :prefix => nil do
+
+ subdir = if params[:config_subdir]
+ "/#{node[:nagios][:config_subdir]}/"
+ else
+ "/"
+ end
+
+ template "#{node[:nagios][:root]}#{subdir}#{params[:name]}.cfg" do
+ owner "nagios"
+ group "nagios"
+ if params[:prefix]
+ source "#{params[:prefix]}_#{params[:name]}.cfg.erb"
+ else
+ source "#{params[:name]}.cfg.erb"
+ end
+ mode 0644
+ variables params[:variables]
+ notifies :restart, resources(:service => "nagios3")
+ backup 0
+ end
+end
3  nagios/definitions/nagios_service_template.rb
View
@@ -0,0 +1,3 @@
+define :nagios_template, :template_type => "service" do
+ node[:nagios][:templates][params[:template_type]][params[:name]] = params
+end
65 nagios/files/default/notifiers/bulksms
View
@@ -0,0 +1,65 @@
+#!/usr/local/bin/ruby
+
+require 'rubygems'
+require 'choice'
+require 'ruby-bulksms'
+
+Choice.options do
+ header ''
+ header 'Specific options:'
+
+ option :number do
+ short '-n'
+ long '--number=NUMBER'
+ desc 'The recipient phone number, e.g. 1312555555 (including country code, no spaces)'
+ end
+
+ option :username do
+ short '-u'
+ long '--username=USERNAME'
+ desc 'BulkSMS username'
+ end
+
+ option :password do
+ short '-p'
+ long '--password=PASSWORD'
+ desc 'BulkSMS password'
+ end
+
+ option :message do
+ short '-m'
+ long '--message=MESSAGE'
+ desc 'Message to be sent'
+ end
+
+ option :country do
+ short '-c'
+ long '--country=COUNTRY'
+ desc 'Which country API to use: spain, uk, usa, international, safrica'
+ end
+
+ separator ''
+ separator 'Common options: '
+
+ option :help do
+ long '--help'
+ desc 'Show this message'
+ end
+ end
+
+choices = Choice.choices
+
+service = Service.new(choices[:username], choices[:password], choices[:country])
+
+if choices
+
+ if choices[:message].length > 160
+ messages = choices[:message].scan(/.{1,160}/)
+ else
+ messages = [choices[:message]]
+ end
+
+ messages.each do |message|
+ service.send(message, choices[:number])
+ end
+end
60 nagios/files/default/notifiers/campfire
View
@@ -0,0 +1,60 @@
+#!/usr/bin/env ruby
+#
+# Uses tinder to say things in a campfire room
+#
+#
+
+require 'rubygems'
+require 'tinder'
+require 'choice'
+
+Choice.options do
+ header ''
+ header 'Specific options:'
+
+ option :subdomain do
+ short '-s'
+ long '--subdomain=SUBDOMAIN'
+ desc 'The Campfire subdomain'
+ end
+
+ option :room do
+ short '-r'
+ long '--room=ROOM'
+ desc 'The target Campfire room name'
+ end
+
+ option :message do
+ short '-m'
+ long '--message=MESSAGE'
+ desc 'The desired message'
+ end
+
+ option :ssl do
+ short '-S'
+ long '--ssl'
+ desc 'Use SSL connections'
+ end
+
+ option :token do
+ short '-t'
+ long '-token=TOKEN'
+ desc 'Campfire API token'
+ end
+
+ separator ''
+ separator 'Common options: '
+
+ option :help do
+ long '--help'
+ desc 'Show this message'
+ end
+ end
+
+choices = Choice.choices
+
+if choices[:subdomain] && choices[:room] && choices[:message]
+ campfire = Tinder::Campfire.new(choices[:subdomain], :ssl => choices[:ssl], :token => choices[:token])
+ room = campfire.find_room_by_name choices[:room]
+ room.speak choices[:message]
+end
66 nagios/files/default/notifiers/clickatell
View
@@ -0,0 +1,66 @@
+#!/usr/bin/env ruby
+#
+# Uses tinder to say things in a campfire room
+#
+#
+
+require 'rubygems'
+require 'clickatell'
+require 'choice'
+
+Choice.options do
+ header ''
+ header 'Specific options:'
+
+ option :number do
+ short '-n'
+ long '--number=NUMBER'
+ desc 'The recipient phone number, e.g. 1312555555 (including country code, no spaces)'
+ end
+
+ option :username do
+ short '-u'
+ long '--username=USERNAME'
+ desc 'Clickatell API username'
+ end
+
+ option :password do
+ short '-p'
+ long '--password=PASSWORD'
+ desc 'Clickatell API password'
+ end
+
+ option :message do
+ short '-m'
+ long '--message=MESSAGE'
+ desc 'Message to be sent'
+ end
+
+ option :api_id do
+ short '-a'
+ long '--api_id=API_ID'
+ desc 'Clickatell API identifier'
+ end
+
+ separator ''
+ separator 'Common options: '
+
+ option :help do
+ long '--help'
+ desc 'Show this message'
+ end
+ end
+
+choices = Choice.choices
+if choices
+ api = Clickatell::API.authenticate(choices[:api_id], choices[:username], choices[:password])
+ # split message up if it's longer than 153 characters
+ if choices[:message].length > 153
+ message_count = (choices[:message].length.to_f / 153).ceil
+ opts = {:concat => message_count}
+ else
+ opts = {}
+ end
+ puts "OPTIONS #{opts.inspect}"
+ api.send_message(choices[:number], choices[:message], opts)
+end
40 nagios/files/default/notifiers/jabber
View
@@ -0,0 +1,40 @@
+#!/usr/bin/env ruby
+#
+#
+
+require 'rubygems'
+require 'choice'
+require 'drb'
+
+Choice.options do
+ header ''
+ header 'Specific options:'
+
+ option :jid do
+ short '-j'
+ long '--jid=JID'
+ desc 'The user JID'
+ end
+
+ option :message do
+ short '-m'
+ long '--message=MESSAGE'
+ desc 'The desired message'
+ end
+
+ separator ''
+ separator 'Common options: '
+
+ option :help do
+ long '--help'
+ desc 'Show this message'
+ end
+ end
+
+choices = Choice.choices
+
+if choices[:jid] && choices[:message]
+ agent = DRbObject.new(nil, "druby://localhost:10370")
+ agent.deliver choices[:jid], choices[:message]
+end
+
84 nagios/files/default/notifiers/jabber_bot
View
@@ -0,0 +1,84 @@
+#!/usr/bin/env ruby
+#
+
+require 'rubygems'
+require 'xmpp4r-simple'
+require 'drb'
+include Jabber
+
+jabber = Simple.new(ARGV[0], ARGV[1])
+AUTHORIZED_JIDS = ARGV[2].split(",")
+
+DRb.start_service("druby://127.0.0.1:10370", jabber)
+STATES = {0 => 'OK', 1 => "WARN", 2 => "CRIT"}
+
+def parse_nagios_status
+ status = File.read("/var/cache/nagios3/status.dat")
+ objects = status.split("\n\n")
+ all_objects = objects.collect do |o|
+ values_hash = {}
+ results = o.scan /\t(.+?)=(.+)/
+ results.each {|value| values_hash[value[0]] = value[1] }
+ values_hash if values_hash['host_name']
+ end
+ all_objects.compact.sort_by {|ob| ob['host_name'] }
+end
+
+def show_state(obj)
+ "#{STATES[obj['current_state'].to_i]} #{obj['host_name']} #{obj['plugin_output']}"
+end
+
+def send_nagios_command(cmd)
+ File.open("/var/lib/nagios3/rw/nagios.cmd",'a') { |f| f.write("[#{Time.now.to_i}] #{cmd}\n") }
+end
+
+loop do
+ sleep 0.05
+ jabber.received_messages do |msg|
+ puts "RECEIVED: '#{msg.body}' from #{msg.from.strip}"
+ next unless AUTHORIZED_JIDS.include?(msg.from.strip.to_s)
+ case
+ when msg.body =~ /^help/
+ help_msg ="Available commands:\n
+ broken - see all hosts and services with alerts\n
+ stats - see basic stats on all hosts and services\n
+ fullstats - see full stats on all hosts and services\n
+ host_downtime - set downtime for a host\n
+ msg - send a custom notification to all contacts for a host\n
+ <command> help - get usage details for a command"
+ jabber.deliver(msg.from, help_msg)
+ when msg.body =~ /^msg/
+ if msg.body =~ /help/
+ jabber.deliver(msg.from, 'Send a custom notification to all contacts for a host: msg <hostname> <message>')
+ else
+ args = msg.body.split
+ hostname = args[1]
+ send_nagios_command("SEND_CUSTOM_HOST_NOTIFICATION;#{hostname};1;#{msg.from.strip};#{args[3..-1].join(" ")}")
+ jabber.deliver(msg.from, "Sent custom notification")
+ end
+ when msg.body =~ /^broken/
+ objs = parse_nagios_status
+ txt = objs.collect {|o| show_state(o) if o['current_state'].to_i != 0 }.compact.join("\n")
+ txt = "All good!" if txt == ""
+ jabber.deliver(msg.from, txt)
+ when msg.body =~ /^host_downtime/
+ if msg.body =~ /help/
+ jabber.deliver(msg.from, 'Specify downtime for a host: host_downtime <hostname> <duration_in_minutes> <reason>')
+ else
+ args = msg.body.split
+ hostname = args[1]
+
+ start_time = Time.now.to_i
+ end_time = (Time.now + (60 * 30)).to_i
+ duration = args[2].to_i * 60
+ # SCHEDULE_HOST_DOWNTIME;<host_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
+ send_nagios_command("SCHEDULE_HOST_DOWNTIME;#{hostname};#{start_time};#{end_time};;;#{duration};#{msg.from.strip};#{args[3..-1].join(" ")}")
+ jabber.deliver(msg.from, "Set downtime for #{hostname}")
+ end
+ when msg.body =~ /^all/
+ objs = parse_nagios_status
+ txt = objs.collect {|o| show_state(o) }.join("\n")
+ jabber.deliver(msg.from, txt)
+ end
+ end
+end
19 nagios/files/default/notifiers/send_passive_check
View
@@ -0,0 +1,19 @@
+#!/usr/bin/env ruby
+
+require 'erb'
+require 'optparse'
+
+
+options = {}
+
+OptionParser.new do |opts|
+ opts.on('-s', '--service_name NAME', 'Nagios service description') { |name| options[:service_name] = name }
+ opts.on('-c', '--command COMMAND', 'Plugin command line') { |command| options[:command] = command }
+end.parse!
+
+result = `#{options[:command]}`
+exit_status = $?
+time = Time.now.to_i
+hostname = `hostname -s`.chomp
+command = "[#{time}] PROCESS_SERVICE_CHECK_RESULT;#{hostname};#{options[:service_name]};#{exit_status};#{result}"
+`ssh nagios@noc "echo '#{command}' >> /usr/local/nagios/var/rw/nagios.cmd"`
81 nagios/files/default/notifiers/twilio
View
@@ -0,0 +1,81 @@
+#!/usr/local/bin/ruby
+
+require 'rubygems'
+require 'choice'
+require 'twiliolib'
+
+API_VERSION="2008-08-01"
+
+# Hide SSL certificate validation warnings.
+class Net::HTTP
+ alias_method :old_initialize, :initialize
+ def initialize(*args)
+ old_initialize(*args)
+ @ssl_context = OpenSSL::SSL::SSLContext.new
+ @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
+ end
+end
+
+Choice.options do
+ header ''
+ header 'Specific options:'
+
+ option :number do
+ short '-n'
+ long '--number=NUMBER'
+ desc 'The recipient phone number, e.g. 1312555555 (including country code, no spaces)'
+ end
+
+ option :from do
+ short '-f'
+ long '--from=NUMBER'
+ desc 'The source phone number, must be a Twilio registered number'
+ end
+
+ option :account_id do
+ short '-a'
+ long '--account_id=ACCOUNT_ID'
+ desc 'Twilio account ID'
+ end
+
+ option :token do
+ short '-t'
+ long '--token=TOKEN'
+ desc 'Twilio account token'
+ end
+
+ option :message do
+ short '-m'
+ long '--message=MESSAGE'
+ desc 'Message to be sent'
+ end
+
+ separator ''
+ separator 'Common options: '
+
+ option :help do
+ long '--help'
+ desc 'Show this message'
+ end
+ end
+
+choices = Choice.choices
+if choices
+
+ if choices[:message].length > 160
+ messages = choices[:message].scan(/.{1,160}/)
+ else
+ messages = [choices[:message]]
+ end
+
+ messages.each do |message|
+ args = {
+ 'To' => choices[:number],
+ 'From' => choices[:from],
+ 'Body' => message
+ }
+
+ account = Twilio::RestAccount.new(choices[:account_id], choices[:token])
+ STDERR.puts account.request("/#{API_VERSION}/Accounts/#{choices[:account_id]}/SMS/Messages", "POST", args).inspect
+ end
+end
158 nagios/files/default/plugins/check-mysql-slave.pl
View
@@ -0,0 +1,158 @@
+#!/usr/bin/env perl
+
+#
+# mysql-slave-check.pl
+#
+# Nagios script for checking the replication
+# status of a slave MySQL server.
+#
+# Michal Ludvig <michal@logix.cz> (c) 2006
+# http://www.logix.cz/michal
+#
+# Run with --help to get some hints about usage or
+# look at subroutine usage() near the end of this file.
+#
+
+use strict;
+use DBI;
+use Getopt::Long;
+
+my $db_host = "localhost";
+my $db_port = "3306";
+my $db_sock = "";
+my $db_user = "";
+my $db_pass = "";
+my $db_name = "";
+my $warn = 300;
+my $crit = 900;
+
+# Nagios codes
+my %ERRORS=('OK'=>0, 'WARNING'=>1, 'CRITICAL'=>2, 'UNKNOWN'=>3, 'DEPENDENT'=>4);
+
+GetOptions(
+ 'host=s' => \$db_host,
+ 'port=i' => \$db_port,
+ 'user=s' => \$db_user,
+ 'password=s' => \$db_pass,
+ 'socket=s' => \$db_sock,
+ 'warn=i' => \$warn,
+ 'crit=i' => \$crit,
+ 'name|dbname|database=s' => \$db_name,
+ 'help' => sub { &usage(); },
+);
+
+&nagios_return("UNKNOWN", "Either set --host/--port or --sock, not both!") if (($db_port || $db_host ne "localhost") && $db_sock);
+
+my $db_conn_string = "DBI:mysql:";
+$db_conn_string .= "database=$db_name;";
+$db_conn_string .= "host=$db_host;";
+$db_conn_string .= "port=$db_port;";
+$db_conn_string .= "mysql_socket=$db_sock;";
+
+## Connect to the database.
+my $dbh = DBI->connect($db_conn_string, $db_user, $db_pass,
+ {'RaiseError' => 0, 'PrintError' => 0});
+
+&nagios_return("UNKNOWN", "Connect failed: $DBI::errstr") if (!$dbh);
+
+## Now retrieve data from the table.
+my $sth = $dbh->prepare("SHOW SLAVE STATUS");
+&nagios_return("UNKNOWN", "[1] $DBI::errstr") if (!$sth);
+
+$sth->execute();
+
+&nagios_return("UNKNOWN", "[2] $DBI::errstr") if ($sth->err);
+&nagios_return("CRITICAL", "Query returned ".scalar($sth->rows)." rows") if (scalar($sth->rows) < 1);
+
+## Query should return one row only
+my $result = $sth->fetchrow_hashref();
+
+&nagios_return("UNKNOWN", "[3] $DBI::errstr") if (!$result);
+
+## Print all results? No thanks.
+# while (my ($key, $val) = each %$result) {
+# print "$key = $val\n";
+# }
+
+## Check the returned values
+&nagios_return("CRITICAL", "Slave_IO_Running=".$result->{'Slave_IO_Running'}."!") if ($result->{'Slave_IO_Running'} ne "Yes");
+&nagios_return("CRITICAL", "Slave_SQL_Running=".$result->{'Slave_SQL_Running'}."!") if ($result->{'Slave_SQL_Running'} ne "Yes");
+&nagios_return("CRITICAL", "Seconds_Behind_Master=".$result->{'Seconds_Behind_Master'}) if ($result->{'Seconds_Behind_Master'} > $crit);
+&nagios_return("WARNING", "Seconds_Behind_Master=".$result->{'Seconds_Behind_Master'}) if ($result->{'Seconds_Behind_Master'} > $warn);
+$sth->finish();
+
+# Disconnect from the database.
+$dbh->disconnect();
+
+&nagios_return("OK", "$result->{'Slave_IO_State'}, replicating host $result->{'Master_Host'}:$result->{'Master_Port'}");
+exit 0;
+
+###
+
+sub nagios_return($$) {
+ my ($ret, $message) = @_;
+ my ($retval, $retstr);
+ if (defined($ERRORS{$ret})) {
+ $retval = $ERRORS{$ret};
+ $retstr = $ret;
+ } else {
+ $retstr = 'UNKNOWN';
+ $retval = $ERRORS{$retstr};
+ $message = "WTF is return code '$ret'??? ($message)";
+ }
+ $message = "$retstr - $message\n";
+ print $message;
+ exit $retval;
+}
+
+sub usage() {
+ print("
+Nagios script for checking the replication status of a
+slave MySQL server.
+
+Michal Ludvig <michal\@logix.cz> (c) 2006
+ http://www.logix.cz/michal
+
+ --host=<host> Hostname or IP address to connect to.
+ --port=<port> TCP port where the server listens
+ --socket=</path/to/mysqld.sock>
+ Path and filename of the Unix socket
+
+ --user=<user>
+ --password=<password>
+ Username and password of a user with
+ REPLICATION CLIENT privileges. See
+ below for details.
+
+ --dbname=<dbname>
+ Name od database to open on connect.
+ Should normaly not be needed.
+
+ --warn=<seconds> Warning threshold in seconds for Seconds_behind_master variable
+
+ --crit=<seconds> Critical threshold in seconds for Seconds_behind_master variable
+
+ --help Guess what ;-)
+
+The script needs to connect as a MySQL user (say 'monitor')
+with privilege REPLICATION CLIENT. Use this GRANT
+command to create such a user:
+
+mysql> GRANT REPLICATION CLIENT ON *.* \\
+ TO monitor\@localhost IDENTIFIED BY 'SecretPassword';
+
+To access the script over SNMP put the following line
+into your /etc/snmpd.conf:
+
+extend mysql-slave /path/to/mysql-slave-check.pl \\
+ --user monitor --pass 'SecretPassword';
+
+To check retrieve the status over SNMP use check_snmp_extend.sh
+from http://www.logix.cz/michal/devel/nagios
+
+
+
+");
+ exit 0;
+
+}
161 nagios/files/default/plugins/check_bl_async.pl
View
@@ -0,0 +1,161 @@
+#!/usr/bin/perl -w
+#
+# check_bl plugin for nagios
+# $Revision: 1.1 $
+#
+# Nagios plugin designed to warn you if you mail servers appear in one of the
+# many anti-spam 'blacklists'
+#
+# By Sam Bashton, Bashton Ltd
+# bashton.com/content/nagios-plugins
+#
+# Updated by Mark Nagel, Willing Minds LLC
+# - converted to use asynchronous lookups and list failures
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+use strict;
+use lib "/usr/lib/nagios/plugins";
+use utils qw($TIMEOUT %ERRORS &print_revision &support);
+use Net::DNS;
+use vars qw($PROGNAME);
+my ($verbose,$host),;
+my ($opt_V,$opt_h,$opt_B,$opt_H,$opt_c);
+$opt_V = $opt_h = $opt_B = $opt_H = $opt_c = '';
+my $state = 'UNKNOWN';
+sub print_help();
+sub print_usage();
+
+$PROGNAME = "check_bl";
+
+$ENV{'BASH_ENV'}='';
+$ENV{'ENV'}='';
+$ENV{'PATH'}='';
+$ENV{'LC_ALL'}='C';
+
+use Getopt::Long;
+Getopt::Long::Configure('bundling');
+GetOptions(
+ "version|V" => \$opt_V,
+ "help|h" => \$opt_h,
+ "hostname|H=s" => \$opt_H,
+ "blacklists|B=s" => \$opt_B,
+ "critical|c=i" => \$opt_c,
+);
+
+# -h means display verbose help screen
+if ($opt_h) { print_help(); exit $ERRORS{'OK'}; }
+
+# -V means display version number
+if ($opt_V) {
+ print_revision($PROGNAME,'$Revision: 1.0 $ ');
+ exit $ERRORS{'OK'};
+}
+
+# First check the hostname is OK..
+unless ($opt_H) { print_usage(); exit $ERRORS{'UNKNOWN'}; }
+
+if (! utils::is_hostname($opt_H)) {
+ print "$opt_H is not a valid host name\n";
+ print_usage();
+ exit $ERRORS{"UNKNOWN"};
+} else {
+ # If the host contains letters we assume it's a hostname, not an IP
+ if ($opt_H =~ /[a-zA-Z]/ ) {
+ $host = lookup($opt_H);
+ }
+ else {
+ $host = $opt_H;
+ }
+}
+
+
+# $opt_c is a count of the blacklists a mail server is in,
+# after which state will be CRITICAL rather than WARNING
+# By default any listing is CRITICAL
+my $critcount = 0;
+if ($opt_c) { $critcount = $opt_c };
+
+# $opt_B is a comma seperated list of blacklists
+$opt_B = shift unless ($opt_B);
+unless ($opt_B) { print_usage(); exit -1 }
+my @bls = split(/,/, $opt_B);
+
+my %listed;
+my %socket;
+
+my $res = Net::DNS::Resolver->new;
+my $lookupip = $host;
+$lookupip =~
+ s/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/$4.$3.$2.$1/;
+for my $bl (@bls) {
+ $socket{$bl} = $res->bgsend("$lookupip.$bl", 'A');
+}
+
+# watch for results to come in up to $TIMEOUT-2 seconds
+my $start_time = time;
+while (keys(%socket) and time - $start_time < ($TIMEOUT-2)) {
+ for my $bl (keys(%socket)) {
+ if ($res->bgisready($socket{$bl})) {
+ my $packet = $res->bgread($socket{$bl});
+ delete $socket{$bl};
+ for my $rr ($packet->answer) {
+ if ($rr->address) {
+ $listed{$bl}++;
+ }
+ }
+ }
+ }
+}
+
+if (keys(%listed) == 0) {
+ $state = 'OK'
+}
+elsif (scalar(keys(%listed)) < $critcount) {
+ $state = 'WARNING'
+}
+else {
+ $state = 'CRITICAL'
+}
+
+my $unknown = "";
+if (keys(%socket)) {
+ $unknown = " (unknown: " . join(" ", sort(keys(%socket))) . ")";
+}
+if (%listed) {
+ print "Listed at " . join(" ", sort(keys(%listed))) . "$unknown\n";
+}
+else {
+ print "Not black-listed$unknown\n";
+}
+
+exit $ERRORS{$state};
+
+
+######## Subroutines ==========================
+
+
+sub print_help() {
+ print_revision($PROGNAME,'$Revision: 1.0 $ ');
+ print "\n";
+ support();
+}
+
+sub print_usage () {
+ print "Usage: \n";
+ print " $PROGNAME -H host -B [blacklist1],[blacklist2] [-c critnum]\n";
+ print " $PROGNAME [-h | --help]\n";
+ print " $PROGNAME [-V | --version]\n";
+}
237 nagios/files/default/plugins/check_cisco.pl
View
@@ -0,0 +1,237 @@
+#!/usr/bin/perl -w
+# $Header$
+# # ============================================================================
+# #
+# #
+# # This program is free software; you can redistribute it and/or modify it
+# # under the terms of the GNU General Public License as published by the
+# # Free Software Foundation; either version 2, or (at your option) any
+# # later version.
+# #
+# # This program is distributed in the hope that it will be useful,
+# # but WITHOUT ANY WARRANTY; without even the implied warranty of
+# # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# # GNU General Public License for more details.
+# #
+# # You should have received a copy of the GNU General Public License
+# # along with this program; if not, write to the Free Software
+# # Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+# #
+# # ============================================================================
+# #
+# # Description:
+
+=head1 DESCRIPTION
+
+check_cisco.pl : SNMP check for cisco devices (routers/switches) returning state of different interfaces.
+
+=cut
+
+=head1 USAGE
+
+ ./check_cisco.pl -h ip -c community -i interface -s state (optional)
+
+=cut
+
+#
+#
+# ============================================================================
+#
+# ==============================================================================
+# # How using it ?
+# ============================================================================
+# ============================================================================
+#
+
+=head2 Options
+
+C<-h or --host> : Set here the ip of your host
+
+C<-c or --community> : Set here your own community
+
+C<-i or --interface> : Set here the interface u want to check (Use the same syntax as for cisco devices, for exemple FastEthernet1/0/1, Fa2/0/3 or Fa0)
+
+C<-s or --state> : Set the state of your interface. Options are : up/down/dormant
+
+=head3 IMPORTANT:
+
+snmp must be installed to perform snmpget/snmpwalk AND snmp server must be activated on your cisco device (switch or router)
+
+=cut
+
+=cut
+
+=head2 Example
+
+Wanna check Fa2/0/1 is up on your switch ?
+
+./check_cisco.pl -h 192.168.0.1 -c public -i Fa2/0/1
+or
+./check_cisco.pl -h 192.168.0.1 -c public -i FastEthernet2/0/1
+
+To check your FastEthernet0 is down on your router :
+
+./check_cisco.pl -h 192.168.0.1 -c MyCommunity -i FastEthernet0 (or Fa0) -s down
+
+To check your Backup RNIS BRIO:1 is dormant on your router:
+
+./check_cisco.pl -h 192.168.0.1 -c MyCommunity -i BRI0:1 -s down
+
+State option are : up (-s up), down (-s down), dormant (-s dormant). State is set to up if not defined.
+
+Have FuN
+
+=cut
+#
+
+
+#
+## ============================================================================
+#
+###################Setting up some parameters#########################
+use strict;
+use Getopt::Long;
+
+my $UNKNOW = -1;
+my $OK = 0;
+my $WARNING = 1;
+my $CRITICAL = 2;
+my $state = "up";
+my $host = "127.0.0.1";
+my $community = "public";
+my $warning = "1000";
+my $critical = "2000";
+my $interface = "Vlan1";
+my $oid="0";
+my $MIBifDescr="IF-MIB::ifDescr";
+my $MIBifOper="IF-MIB::ifOperStatus";
+my $MIBifName="IF-MIB::ifName";
+my $MIBifLastChange="IF-MIB::ifLastChange";
+my $MIBTrafficIn="IF-MIB::ifInOctets";
+my $MIBTrafficOut="IF-MIB::ifOutOctets";
+my $MIBDescription="IF-MIB::ifAlias";
+###################Getting options##############################
+GetOptions(
+ "host|h=s" => \$host,
+ "community|c=s" => \$community,
+ "interface|i=s" => \$interface,
+ "state|s=s" =>\$state
+);
+chomp($host);
+chomp($community);
+chomp($interface);
+chomp($state);
+#################################################################
+
+my $walkDescr = snmpwalkgrep($host, $community, $MIBifDescr, $interface);
+my $walkName = snmpwalkgrep($host, $community, $MIBifName, $interface);
+
+if ($walkDescr =~ /$interface/ or $walkName =~ /$interface/){
+ if ($walkDescr =~ /ifDescr.([0-9]+)/ || $walkName =~ /ifName.([0-9]+)/){
+ my $oid =$1;
+ #print "$oid\n";
+ my $tree="IF-MIB::ifOperStatus.$oid";
+ my $return=snmpwalk($host, $community, $tree);
+ if ($return =~ /up/ && $state eq "up"){
+ my $LastChange= snmpwalk($host, $community, "$MIBifLastChange"."\.".$oid);
+ my $Alias= snmpwalk($host, $community, "$MIBDescription"."\.".$oid);
+ my $TrafficIn =snmpwalk($host, $community, "$MIBTrafficIn"."\.".$oid);
+ my $TrafficOut=snmpwalk($host, $community, "$MIBTrafficOut"."\.".$oid);
+ my $LastChangeCleaned=CleanMe($LastChange);
+ my $AliasCleaned=CleanMe($Alias);
+ my $TrafficInCleaned=CleanMe($TrafficIn);
+ my $TrafficOutCleaned=CleanMe($TrafficOut);
+ print "$interface up: $AliasCleaned, LastChanges: $LastChangeCleaned, Traffic in : $TrafficInCleaned octets, out: $TrafficOutCleaned octets\n";
+ exit $OK;
+
+ }elsif ($return =~ /down/ && $state eq "up"){
+ print "$interface is down\n";
+ exit $CRITICAL;
+ }elsif($return =~ /down/ && $state eq "down"){
+ print "$interface down : ok\n";
+ exit $OK;
+ }elsif($return =~ /up/ && $state eq "down"){
+ print "$interface should not be up\n";
+ exit $CRITICAL;
+ }elsif($return =~ /dormant/ && $state eq "down" || $return =~ /dormant/ && $state eq "up"){
+ print "Error : $interface is sleeping\n";
+ exit $CRITICAL;
+ }elsif($return =~ /dormant/ && $state eq "dormant"){
+ print "$interface is sleeping : ok\n";
+ exit $OK
+ }elsif($return =~ /up/ && $state eq "dormant"){
+ print "$interface is up and should be sleeping\n";
+ exit $CRITICAL;
+ }else{
+ print "Unknown state for $interface : check your -s state syntax\n";
+ exit $UNKNOW;
+ }
+
+ }else{
+ print "Not supported\n";
+ exit $UNKNOW;
+ }
+}else{
+ print "Interface not found : please check your syntax for this device\n";
+ exit $UNKNOW;
+}
+
+sub CleanMe
+{
+ my $input=$_[0];
+ if ($input =~ /: (.*)/){
+ my $return=$1;
+ chomp($return);
+ return $return;
+}
+
+
+}
+
+sub snmpwalk
+{
+ my ($host, $community, $tree)=@_;
+ my $walk = `snmpwalk -v 1 -c $community $host $tree`;
+ chomp($walk);
+ return $walk;
+}
+
+sub snmpwalkgrep
+{
+ my ($host, $community, $tree, $interface)=@_;
+ my $walk = `snmpwalk -v 1 -c $community $host $tree |grep $interface`;
+ chomp($walk);
+ return $walk;
+}
+
+sub snmpget
+{
+ my ($host, $community, $tree)=@_;
+ my $get = `snmpget -v 1 -c $community $host $tree`;
+ chomp($get);
+ return $get;
+}
+
+
+# ============================================================================
+ #
+=head1 AUTHORS
+
+by R3dl!GhT
+
+=cut
+
+
+=head1 COPYRIGHT
+
+ Copyright (C) R3dL!GhT 2007.
+
+This module is free software; you can redistribute it and/or
+modify it under the terms of the GNU Public License.
+
+=cut
+# ============================================================================
+#
+# __END__
+#
+
230 nagios/files/default/plugins/check_cisco_stack.pl
View
@@ -0,0 +1,230 @@
+#!/usr/bin/perl -w
+
+use strict;
+use Getopt::Long;
+use Net::SNMP;
+
+my $Version = "1.2.1 20071018";
+my $snmp_timeout = 3;
+
+my $cisco_stack_table = "1.3.6.1.4.1.9.9.500.1.2.1.1.1";
+my $cisco_stack_state = "1.3.6.1.4.1.9.9.500.1.2.1.1.6";
+my $cisco_stack_ring = "1.3.6.1.4.1.9.9.500.1.1.3.0";
+
+my $status = "UNKNOWN";
+my $session;
+my $error;
+my $result;
+my $stackring_state;
+
+my $o_debug = 0;
+my $o_alarm = 0;
+my $o_host;
+my $o_community;
+my $o_version;
+my $o_help;
+
+my %members;
+my %ERRORS = (
+ 'OK' => 0,
+ 'WARNING' => 1,
+ 'CRITICAL' => 2,
+ 'UNKNOWN' => 3,
+ 'DEPENDENT' => 4,
+);
+my %STACK_STATES = (
+ '1' => 'waiting',
+ '2' => 'progressing',
+ '3' => 'added',
+ '4' => 'ready',
+ '5' => 'sdmMismatch',
+ '6' => 'verMismatch',
+ '7' => 'featureMismatch',
+ '8' => 'newMasterInit',
+ '9' => 'provisioned',
+ '10' => 'invalid',
+);
+
+
+##########################
+#
+# MAIN
+#
+##########################
+
+check_options();
+
+($session, $error) = Net::SNMP->session(
+ -hostname => $o_host,
+ -community => $o_community,
+ -port => 161,
+ -timeout => $snmp_timeout
+ );
+
+if (!defined($session)) {
+ printf("ERROR: %s.\n", $error);
+ exit $ERRORS{"CRITICAL"};
+}
+
+#
+# Get Cisco stack table
+#
+$result = $session->get_table(
+ -baseoid => $cisco_stack_table
+ );
+
+if (!defined($result)) {
+ printf("ERROR: %s.\n", $session->error);
+ $session->close;
+ exit $ERRORS{"CRITICAL"};
+}
+
+foreach my $key ( keys %{$result}) {
+ my $id = ( $$result{$key} * 1000 ) + 1;
+ my $oid = "$cisco_stack_state.$id";
+
+ my $result2 = $session->get_request(
+ -varbindlist => [$oid]
+ );
+
+ if (!defined($result2)) {
+ printf("ERROR: %s.\n", $session->error);
+ $session->close;
+ exit $ERRORS{"CRITICAL"};
+ }
+
+ print "DEBUG: member = $$result{$key} -> oid = $oid -> state = " . $result2->{"$oid"} . "\n" if $o_debug;
+
+ $members{$$result{$key}} = $result2->{"$oid"};
+}
+
+if ($o_alarm) {
+ $members{"2"} = 6;
+ print "-- SIMULATING ALARM -- ";
+}
+
+#
+# Get Cisco stack ring speed if more than one stack member
+#
+if ( keys(%{$result}) > 1 ) {
+ $result = $session->get_request(
+ -varbindlist => [$cisco_stack_ring]
+ );
+
+ if (!defined($result)) {
+ printf("ERROR: %s.\n", $session->error);
+ $session->close;
+ exit $ERRORS{"CRITICAL"};
+ }
+
+ #
+ # Parse SNMP stack ring result
+ #
+ if ( $result->{$cisco_stack_ring} == 1 ) {
+ $stackring_state = "Full";
+ }
+ else {
+ $status = "WARNING";
+ $stackring_state = "Half";
+ }
+
+ print "DEBUG: snmp_ring_state = " . $result->{$cisco_stack_ring} . " -> ring_state = $stackring_state\n" if $o_debug;
+ print "Stack Ring: $stackring_state, ";
+}
+
+$session->close;
+
+my $nitems = keys (%members);
+my $n = 0;
+
+foreach my $member (keys (%members)) {
+ $n++;
+ if ( $members{$member} == 4 or 9 ) {
+ if (( $status ne "CRITICAL" ) && ( $status ne "WARNING" )) {
+ $status = "OK";
+ }
+ } else {
+ $status = "CRITICAL";
+ }
+ print "Member $member: $STACK_STATES{$members{$member}}";
+ if ($n < $nitems) {
+ print ", ";
+ } else {
+ print "\n";
+ }
+}
+
+print "DEBUG: $status: $ERRORS{$status}\n" if $o_debug;
+
+exit $ERRORS{$status};
+
+##########################
+#
+# FUNCTIONS
+#
+##########################
+
+sub version {
+ print "$0 version: $Version\n";
+}
+
+sub usage {
+ print <<DATA;
+
+Usage: $0 [-V] [-h] [-D] [-A] -H <host> -C <community>
+
+-h, --help
+ prints this help message
+-V, --version
+ prints version number
+-D, --debug
+ prints debug info. do not use in production.
+-A, --alarm
+ the plugin simulates an alarm without the need to break the stack!!!
+-H, --hostname=HOST
+ name or IP address of host to check
+-C, --community=STRING NAME
+ community name for the host's SNMP agent (implies v1/v2 protocol)
+
+DATA
+}
+
+sub help {
+ print <<DATA;
+
+SNMP Cisco stack for Nagios version: $Version
+Author: Andrea Gabellini - <andrea.gabellini\@telecomitalia.sm>
+Check for stack's status of Cisco 3750
+
+DATA
+
+ usage();
+}
+
+sub check_options {
+ Getopt::Long::Configure ("bundling");
+ GetOptions(
+ 'h' => \$o_help, 'help' => \$o_help,
+ 'V' => \$o_version, 'version' => \$o_version,
+ 'D' => \$o_debug, 'debug' => \$o_debug,
+ 'A' => \$o_alarm, 'alarm' => \$o_alarm,
+ 'H:s' => \$o_host, 'hostname:s' => \$o_host,
+ 'C:s' => \$o_community, 'community:s' => \$o_community,
+ );
+ if (defined ($o_help) ) {
+ help();
+ exit $ERRORS{"UNKNOWN"};
+ }
+ if (defined($o_version)) {
+ version();
+ exit $ERRORS{"UNKNOWN"};
+ }
+ if (!defined($o_host) ) {
+ usage();
+ exit $ERRORS{"UNKNOWN"};
+ }
+ if (!defined($o_community) ) {
+ usage();
+ exit $ERRORS{"UNKNOWN"};
+ }
+}
726 nagios/files/default/plugins/check_cpu.pl
View
@@ -0,0 +1,726 @@
+#!/usr/bin/perl -w
+############################## check_snmp_load #################
+# Version : 1.3.1
+# Date : 8 Sept 2006
+# Author : Patrick Proy ( patrick at proy.org)
+# Help : http://www.manubulon.com/nagios/
+# Licence : GPL - http://www.fsf.org/licenses/gpl.txt
+# Changelog : HP-UX load added.
+# Contributors : F. Lacroix and many others !!!
+#################################################################
+#
+# Help : ./check_snmp_load.pl -h
+#
+
+use strict;
+use Net::SNMP;
+use Getopt::Long;
+
+# Nagios specific
+
+use lib "/usr/local/groundwork/nagios/libexec";
+use lib "/usr/lib/nagios/plugins/";
+use utils qw(%ERRORS $TIMEOUT);
+#my $TIMEOUT = 15;
+#my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
+
+# SNMP Datas
+
+# Generic with host-ressource-mib
+my $base_proc = "1.3.6.1.2.1.25.3.3.1"; # oid for all proc info
+my $proc_id = "1.3.6.1.2.1.25.3.3.1.1"; # list of processors (product ID)
+my $proc_load = "1.3.6.1.2.1.25.3.3.1.2"; # %time the proc was not idle over last minute
+
+# Linux load
+
+my $linload_table= "1.3.6.1.4.1.2021.10.1"; # net-snmp load table
+my $linload_name = "1.3.6.1.4.1.2021.10.1.2"; # text 'Load-1','Load-5', 'Load-15'
+my $linload_load = "1.3.6.1.4.1.2021.10.1.3"; # effective load table
+
+# Cisco cpu/load
+
+my $cisco_cpu_5m = "1.3.6.1.4.1.9.2.1.58.0"; # Cisco CPU load (5min %)
+my $cisco_cpu_1m = "1.3.6.1.4.1.9.2.1.57.0"; # Cisco CPU load (1min %)
+my $cisco_cpu_5s = "1.3.6.1.4.1.9.2.1.56.0"; # Cisco CPU load (5sec %)
+
+# Cisco catalyst cpu/load
+
+my $ciscocata_cpu_5m = ".1.3.6.1.4.1.9.9.109.1.1.1.1.5.9"; # Cisco CPU load (5min %)
+my $ciscocata_cpu_1m = ".1.3.6.1.4.1.9.9.109.1.1.1.1.3.9"; # Cisco CPU load (1min %)
+my $ciscocata_cpu_5s = ".1.3.6.1.4.1.9.9.109.1.1.1.1.4.9"; # Cisco CPU load (5sec %)
+
+# Netscreen cpu/load
+
+my $nsc_cpu_5m = "1.3.6.1.4.1.3224.16.1.4.0"; # NS CPU load (5min %)
+my $nsc_cpu_1m = "1.3.6.1.4.1.3224.16.1.2.0"; # NS CPU load (1min %)
+my $nsc_cpu_5s = "1.3.6.1.4.1.3224.16.1.3.0"; # NS CPU load (5sec %)
+
+# AS/400 CPU
+
+my $as400_cpu = "1.3.6.1.4.1.2.6.4.5.1.0"; # AS400 CPU load (10000=100%);
+
+# Net-SNMP CPU
+
+my $ns_cpu_idle = "1.3.6.1.4.1.2021.11.11.0"; # Net-snmp cpu idle
+my $ns_cpu_user = "1.3.6.1.4.1.2021.11.9.0"; # Net-snmp user cpu usage
+my $ns_cpu_system = "1.3.6.1.4.1.2021.11.10.0"; # Net-snmp system cpu usage
+
+# Procurve CPU
+my $procurve_cpu = "1.3.6.1.4.1.11.2.14.11.5.1.9.6.1.0"; # Procurve CPU Counter
+
+# Nokia CPU
+my $nokia_cpu = "1.3.6.1.4.1.94.1.21.1.7.1.0"; # Nokia CPU % usage
+
+# Bluecoat Appliance
+my $bluecoat_cpu = "1.3.6.1.4.1.3417.2.4.1.1.1.4.1"; # Bluecoat %cpu usage.
+
+# Fortigate CPU
+my $fortigate_cpu = ".1.3.6.1.4.1.12356.1.8.0"; # Fortigate CPU % usage
+
+# Linkproof Appliance
+my $linkproof_cpu= "1.3.6.1.4.1.89.35.1.53.0"; # Ressource utilisation (%) Considers network utilization and internal CPU utilization
+# 1.3.6.1.4.1.89.35.1.54 : CPU only (%)
+# 1.3.6.1.4.1.89.35.1.55 : network only (%)
+
+# HP-UX cpu usage (thanks to krizb for the OIDs).
+my $hpux_load_1_min="1.3.6.1.4.1.11.2.3.1.1.3.0";
+my $hpux_load_5_min="1.3.6.1.4.1.11.2.3.1.1.4.0";
+my $hpux_load_15_min="1.3.6.1.4.1.11.2.3.1.1.5.0";
+
+# valid values
+my @valid_types = ("stand","netsc","netsl","as400","cisco","cata","nsc","fg","bc","nokia","hp","lp","hpux");
+# CPU OID array
+my %cpu_oid = ("netsc",$ns_cpu_idle,"as400",$as400_cpu,"bc",$bluecoat_cpu,"nokia",$nokia_cpu,"hp",$procurve_cpu,"lp",$linkproof_cpu,"fg",$fortigate_cpu);
+
+# Globals
+
+my $Version='1.3.1';
+
+my $o_host = undef; # hostname
+my $o_community = undef; # community
+my $o_port = 161; # port
+my $o_help= undef; # wan't some help ?
+my $o_verb= undef; # verbose mode
+my $o_version= undef; # print version
+# check type : stand | netsc | netsl | as400 | cisco | cata | nsc | fg | bc | nokia | hp | lp | hpux
+my $o_check_type= "stand";
+# End compatibility
+my $o_warn= undef; # warning level
+my @o_warnL= undef; # warning levels for Linux Load or Cisco CPU
+my $o_crit= undef; # critical level
+my @o_critL= undef; # critical level for Linux Load or Cisco CPU
+my $o_timeout= undef; # Timeout (Default 5)
+my $o_perf= undef; # Output performance data
+my $o_version2= undef; # use snmp v2c
+# SNMPv3 specific
+my $o_login= undef; # Login for snmpv3
+my $o_passwd= undef; # Pass for snmpv3
+my $v3protocols=undef; # V3 protocol list.
+my $o_authproto='md5'; # Auth protocol
+my $o_privproto='des'; # Priv protocol
+my $o_privpass= undef; # priv password
+
+# functions
+
+sub p_version { print "check_snmp_load version : $Version\n"; }
+
+sub print_usage {
+ print "Usage: $0 [-v] -H <host> -C <snmp_community> [-2] | (-l login -x passwd [-X pass -L <authp>,<privp>]) [-p <port>] -w <warn level> -c <crit level> -T=[stand|netsl|netsc|as400|cisco|cata|nsc|fg|bc|nokia|hp|lp|hpux] [-f] [-t <timeout>] [-V]\n";
+}
+
+sub isnnum { # Return true if arg is not a number
+ my $num = shift;
+ if ( $num =~ /^(\d+\.?\d*)|(^\.\d+)$/ ) { return 0 ;}
+ return 1;
+}
+
+sub help {
+ print "\nSNMP Load & CPU Monitor for Nagios version ",$Version,"\n";
+ print "GPL licence, (c)2004-2006 Patrick Proy\n\n";
+ print_usage();
+ print <<EOT;
+-v, --verbose
+ print extra debugging information
+-h, --help
+ print this help message
+-H, --hostname=HOST
+ name or IP address of host to check
+-C, --community=COMMUNITY NAME
+ community name for the host's SNMP agent (implies v1 protocol)
+-2, --v2c
+ Use snmp v2c
+-l, --login=LOGIN ; -x, --passwd=PASSWD
+ Login and auth password for snmpv3 authentication
+ If no priv password exists, implies AuthNoPriv
+-X, --privpass=PASSWD
+ Priv password for snmpv3 (AuthPriv protocol)
+-L, --protocols=<authproto>,<privproto>
+ <authproto> : Authentication protocol (md5|sha : default md5)
+ <privproto> : Priv protocole (des|aes : default des)
+-P, --port=PORT
+ SNMP port (Default 161)
+-w, --warn=INTEGER | INT,INT,INT
+ 1 value check : warning level for cpu in percent (on one minute)
+ 3 value check : comma separated level for load or cpu for 1min, 5min, 15min
+-c, --crit=INTEGER | INT,INT,INT
+ critical level for cpu in percent (on one minute)
+ 1 value check : critical level for cpu in percent (on one minute)
+ 3 value check : comma separated level for load or cpu for 1min, 5min, 15min
+-T, --type=stand|netsl|netsc|as400|cisco|bc|nokia|hp|lp
+ CPU check :
+ stand : standard MIBII (works with Windows),
+ can handle multiple CPU.
+ netsl : linux load provided by Net SNMP (1,5 & 15 minutes values)
+ netsc : cpu usage given by net-snmp (100-idle)
+ as400 : as400 CPU usage
+ cisco : Cisco CPU usage
+ cata : Cisco catalyst CPU usage
+ nsc : NetScreen CPU usage
+ fg : Fortigate CPU usage
+ bc : Bluecoat CPU usage
+ nokia : Nokia CPU usage
+ hp : HP procurve switch CPU usage
+ lp : Linkproof CPU usage
+ hpux : HP-UX load (1,5 & 15 minutes values)
+-f, --perfparse
+ Perfparse compatible output
+-t, --timeout=INTEGER
+ timeout for SNMP in seconds (Default: 5)
+-V, --version
+ prints version number
+EOT
+}
+
+# For verbose output
+sub verb { my $t=shift; print $t,"\n" if defined($o_verb) ; }
+
+sub check_options {
+ Getopt::Long::Configure ("bundling");
+ GetOptions(
+ 'v' => \$o_verb, 'verbose' => \$o_verb,
+ 'h' => \$o_help, 'help' => \$o_help,
+ 'H:s' => \$o_host, 'hostname:s' => \$o_host,
+ 'p:i' => \$o_port, 'port:i' => \$o_port,
+ 'C:s' => \$o_community, 'community:s' => \$o_community,
+ 'l:s' => \$o_login, 'login:s' => \$o_login,
+ 'x:s' => \$o_passwd, 'passwd:s' => \$o_passwd,
+ 'X:s' => \$o_privpass, 'privpass:s' => \$o_privpass,
+ 'L:s' => \$v3protocols, 'protocols:s' => \$v3protocols,
+ 't:i' => \$o_timeout, 'timeout:i' => \$o_timeout,
+ 'V' => \$o_version, 'version' => \$o_version,
+ '2' => \$o_version2, 'v2c' => \$o_version2,
+ 'c:s' => \$o_crit, 'critical:s' => \$o_crit,
+ 'w:s' => \$o_warn, 'warn:s' => \$o_warn,
+ 'f' => \$o_perf, 'perfparse' => \$o_perf,
+ 'T:s' => \$o_check_type, 'type:s' => \$o_check_type
+ );
+ # check the -T option
+ my $T_option_valid=0;
+ foreach (@valid_types) { if ($_ eq $o_check_type) {$T_option_valid=1} };
+ if ( $T_option_valid == 0 )
+ {print "Invalid check type (-T)!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
+ # Basic checks
+ if (defined($o_timeout) && (isnnum($o_timeout) || ($o_timeout < 2) || ($o_timeout > 60)))
+ { print "Timeout must be >1 and <60 !\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
+ if (!defined($o_timeout)) {$o_timeout=5;}
+ if (defined ($o_help) ) { help(); exit $ERRORS{"UNKNOWN"}};
+ if (defined($o_version)) { p_version(); exit $ERRORS{"UNKNOWN"}};
+ if ( ! defined($o_host) ) # check host and filter
+ { print_usage(); exit $ERRORS{"UNKNOWN"}}
+ # check snmp information
+ if ( !defined($o_community) && (!defined($o_login) || !defined($o_passwd)) )
+ { print "Put snmp login info!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
+ if ((defined($o_login) || defined($o_passwd)) && (defined($o_community) || defined($o_version2)) )
+ { print "Can't mix snmp v1,2c,3 protocols!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
+ if (defined ($v3protocols)) {
+ if (!defined($o_login)) { print "Put snmp V3 login info with protocols!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
+ my @v3proto=split(/,/,$v3protocols);
+ if ((defined ($v3proto[0])) && ($v3proto[0] ne "")) {$o_authproto=$v3proto[0]; } # Auth protocol
+ if (defined ($v3proto[1])) {$o_privproto=$v3proto[1]; } # Priv protocol
+ if ((defined ($v3proto[1])) && (!defined($o_privpass))) {
+ print "Put snmp V3 priv login info with priv protocols!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
+ }
+ # Check warnings and critical
+ if (!defined($o_warn) || !defined($o_crit))
+ { print "put warning and critical info!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
+ # Get rid of % sign
+ $o_warn =~ s/\%//g;
+ $o_crit =~ s/\%//g;
+ # Check for multiple warning and crit in case of -L
+ if (($o_check_type eq "netsl") || ($o_check_type eq "cisco") || ($o_check_type eq "cata") ||
+ ($o_check_type eq "nsc") || ($o_check_type eq "hpux")) {
+ @o_warnL=split(/,/ , $o_warn);
+ @o_critL=split(/,/ , $o_crit);
+ if (($#o_warnL != 2) || ($#o_critL != 2))
+ { print "3 warnings and critical !\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
+ for (my $i=0;$i<3;$i++) {
+ if ( isnnum($o_warnL[$i]) || isnnum($o_critL[$i]))
+ { print "Numeric value for warning or critical !\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
+ if ($o_warnL[$i] > $o_critL[$i])
+ { print "warning <= critical ! \n";print_usage(); exit $ERRORS{"UNKNOWN"}}
+ }
+ } else {
+ if (($o_warn =~ /,/) || ($o_crit =~ /,/)) {
+ { print "Multiple warning/critical levels not available for this check\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
+ }
+ if ( isnnum($o_warn) || isnnum($o_crit) )
+ { print "Numeric value for warning or critical !\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
+ if ($o_warn > $o_crit)
+ { print "warning <= critical ! \n";print_usage(); exit $ERRORS{"UNKNOWN"}}
+ }
+}
+
+########## MAIN #######
+
+check_options();
+
+# Check gobal timeout if snmp screws up
+if (defined($TIMEOUT)) {
+ verb("Alarm at $TIMEOUT + 5");
+ alarm($TIMEOUT+5);
+} else {
+ verb("no global timeout defined : $o_timeout + 10");
+ alarm ($o_timeout+10);
+}
+
+# Connect to host
+my ($session,$error);
+if ( defined($o_login) && defined($o_passwd)) {
+ # SNMPv3 login
+ verb("SNMPv3 login");
+ if (!defined ($o_privpass)) {
+ verb("SNMPv3 AuthNoPriv login : $o_login, $o_authproto");
+ ($session, $error) = Net::SNMP->session(
+ -hostname => $o_host,
+ -version => '3',
+ -username => $o_login,
+ -authpassword => $o_passwd,
+ -authprotocol => $o_authproto,
+ -timeout => $o_timeout
+ );
+ } else {
+ verb("SNMPv3 AuthPriv login : $o_login, $o_authproto, $o_privproto");
+ ($session, $error) = Net::SNMP->session(
+ -hostname => $o_host,
+ -version => '3',
+ -username => $o_login,
+ -authpassword => $o_passwd,
+ -authprotocol => $o_authproto,
+ -privpassword => $o_privpass,
+ -privprotocol => $o_privproto,
+ -timeout => $o_timeout
+ );
+ }
+} else {
+ if (defined ($o_version2)) {
+ # SNMPv2 Login
+ verb("SNMP v2c login");
+ ($session, $error) = Net::SNMP->session(
+ -hostname => $o_host,
+ -version => 2,
+ -community => $o_community,
+ -port => $o_port,
+ -timeout => $o_timeout
+ );
+ } else {
+ # SNMPV1 login
+ verb("SNMP v1 login");
+ ($session, $error) = Net::SNMP->session(
+ -hostname => $o_host,
+ -community => $o_community,
+ -port => $o_port,
+ -timeout => $o_timeout
+ );
+ }
+}
+if (!defined($session)) {
+ printf("ERROR opening session: %s.\n", $error);
+ exit $ERRORS{"UNKNOWN"};
+}
+
+my $exit_val=undef;
+########### Linux load check ##############
+
+if ($o_check_type eq "netsl") {
+
+verb("Checking linux load");
+# Get load table
+my $resultat = (Net::SNMP->VERSION < 4) ?
+ $session->get_table($linload_table)
+ : $session->get_table(Baseoid => $linload_table);
+
+if (!defined($resultat)) {
+ printf("ERROR: Description table : %s.\n", $session->error);
+ $session->close;
+ exit $ERRORS{"UNKNOWN"};
+}
+$session->close;
+
+my @load = undef;
+my @iload = undef;
+my @oid=undef;
+my $exist=0;
+foreach my $key ( keys %$resultat) {
+ verb("OID : $key, Desc : $$resultat{$key}");
+ if ( $key =~ /$linload_name/ ) {
+ @oid=split (/\./,$key);
+ $iload[0]= pop(@oid) if ($$resultat{$key} eq "Load-1");
+ $iload[1]= pop(@oid) if ($$resultat{$key} eq "Load-5");
+ $iload[2]= pop(@oid) if ($$resultat{$key} eq "Load-15");
+ $exist=1
+ }
+}
+
+if ($exist == 0) {
+ print "Can't find snmp information on load : UNKNOWN\n";
+ exit $ERRORS{"UNKNOWN"};
+}
+
+for (my $i=0;$i<3;$i++) { $load[$i] = $$resultat{$linload_load . "." . $iload[$i]}};
+
+print "Load : $load[0] $load[1] $load[2] :";
+
+$exit_val=$ERRORS{"OK"};
+for (my $i=0;$i<3;$i++) {
+ if ( $load[$i] > $o_critL[$i] ) {
+ print " $load[$i] > $o_critL[$i] : CRITICAL";
+ $exit_val=$ERRORS{"CRITICAL"};
+ }
+ if ( $load[$i] > $o_warnL[$i] ) {
+ # output warn error only if no critical was found
+ if ($exit_val eq $ERRORS{"OK"}) {
+ print " $load[$i] > $o_warnL[$i] : WARNING";
+ $exit_val=$ERRORS{"WARNING"};
+ }
+ }
+}
+print " OK" if ($exit_val eq $ERRORS{"OK"});
+if (defined($o_perf)) {
+ print " | load_1_min=$load[0];$o_warnL[0];$o_critL[0] ";
+ print "load_5_min=$load[1];$o_warnL[1];$o_critL[1] ";
+ print "load_15_min=$load[2];$o_warnL[2];$o_critL[2]\n";
+} else {
+ print "\n";
+}
+exit $exit_val;
+}
+
+############## Cisco CPU check ################
+
+if ($o_check_type eq "cisco") {
+my @oidlists = ($cisco_cpu_5m, $cisco_cpu_1m, $cisco_cpu_5s);
+my $resultat = (Net::SNMP->VERSION < 4) ?
+ $session->get_request(@oidlists)
+ : $session->get_request(-varbindlist => \@oidlists);
+
+if (!defined($resultat)) {
+ printf("ERROR: Description table : %s.\n", $session->error);
+ $session->close;
+ exit $ERRORS{"UNKNOWN"};
+}
+
+$session->close;
+
+if (!defined ($$resultat{$cisco_cpu_5s})) {
+ print "No CPU information : UNKNOWN\n";
+ exit $ERRORS{"UNKNOWN"};
+}
+
+my @load = undef;
+
+$load[0]=$$resultat{$cisco_cpu_5s};
+$load[1]=$$resultat{$cisco_cpu_1m};
+$load[2]=$$resultat{$cisco_cpu_5m};
+
+print "CPU : $load[0] $load[1] $load[2] :";
+
+$exit_val=$ERRORS{"OK"};
+for (my $i=0;$i<3;$i++) {
+ if ( $load[$i] > $o_critL[$i] ) {
+ print " $load[$i] > $o_critL[$i] : CRITICAL";
+ $exit_val=$ERRORS{"CRITICAL"};
+ }
+ if ( $load[$i] > $o_warnL[$i] ) {
+ # output warn error only if no critical was found
+ if ($exit_val eq $ERRORS{"OK"}) {
+ print " $load[$i] > $o_warnL[$i] : WARNING";
+ $exit_val=$ERRORS{"WARNING"};
+ }
+ }
+}
+print " OK" if ($exit_val eq $ERRORS{"OK"});
+if (defined($o_perf)) {
+ print " | load_5_sec=$load[0]%;$o_warnL[0];$o_critL[0],";
+ print "load_1_min=$load[1]%;$o_warnL[1];$o_critL[1],";
+ print "load_5_min=$load[2]%;$o_warnL[2];$o_critL[2]\n";
+} else {
+ print "\n";
+}
+
+exit $exit_val;
+}
+
+############## Cisco Catalyst CPU check ################
+
+if ($o_check_type eq "cata") {
+my @oidlists = ($ciscocata_cpu_5m, $ciscocata_cpu_1m, $ciscocata_cpu_5s);
+my $resultat = (Net::SNMP->VERSION < 4) ?
+ $session->get_request(@oidlists)
+ : $session->get_request(-varbindlist => \@oidlists);
+
+if (!defined($resultat)) {
+ printf("ERROR: Description table : %s.\n", $session->error);
+ $session->close;
+ exit $ERRORS{"UNKNOWN"};
+}
+
+$session->close;
+
+if (!defined ($$resultat{$ciscocata_cpu_5s})) {
+ print "No CPU information : UNKNOWN\n";
+ exit $ERRORS{"UNKNOWN"};
+}
+
+my @load = undef;
+
+$load[0]=$$resultat{$ciscocata_cpu_5s};
+$load[1]=$$resultat{$ciscocata_cpu_1m};
+$load[2]=$$resultat{$ciscocata_cpu_5m};
+
+print "CPU : $load[0] $load[1] $load[2] :";
+
+$exit_val=$ERRORS{"OK"};
+for (my $i=0;$i<3;$i++) {
+ if ( $load[$i] > $o_critL[$i] ) {
+ print " $load[$i] > $o_critL[$i] : CRITICAL";
+ $exit_val=$ERRORS{"CRITICAL"};
+ }
+ if ( $load[$i] > $o_warnL[$i] ) {
+ # output warn error only if no critical was found
+ if ($exit_val eq $ERRORS{"OK"}) {
+ print " $load[$i] > $o_warnL[$i] : WARNING";
+ $exit_val=$ERRORS{"WARNING"};
+ }
+ }
+}
+print " OK" if ($exit_val eq $ERRORS{"OK"});
+if (defined($o_perf)) {
+ print " | load_5_sec=$load[0]%;$o_warnL[0];$o_critL[0],";
+ print "load_1_min=$load[1]%;$o_warnL[1];$o_critL[1],";
+ print "load_5_min=$load[2]%;$o_warnL[2];$o_critL[2]\n";
+} else {
+ print "\n";
+}
+
+exit $exit_val;
+}
+
+############## Netscreen CPU check ################
+
+if ($o_check_type eq "nsc") {
+my @oidlists = ($nsc_cpu_5m, $nsc_cpu_1m, $nsc_cpu_5s);
+my $resultat = (Net::SNMP->VERSION < 4) ?
+ $session->get_request(@oidlists)
+ : $session->get_request(-varbindlist => \@oidlists);
+
+if (!defined($resultat)) {
+ printf("ERROR: Description table : %s.\n", $session->error);
+ $session->close;
+ exit $ERRORS{"UNKNOWN"};
+}
+
+$session->close;
+
+if (!defined ($$resultat{$nsc_cpu_5s})) {
+ print "No CPU information : UNKNOWN\n";
+ exit $ERRORS{"UNKNOWN"};
+}
+
+my @load = undef;
+
+$load[0]=$$resultat{$nsc_cpu_5s};
+$load[1]=$$resultat{$nsc_cpu_1m};
+$load[2]=$$resultat{$nsc_cpu_5m};
+
+print "CPU : $load[0] $load[1] $load[2] :";
+
+$exit_val=$ERRORS{"OK"};
+for (my $i=0;$i<3;$i++) {
+ if ( $load[$i] > $o_critL[$i] ) {
+ print " $load[$i] > $o_critL[$i] : CRITICAL";
+ $exit_val=$ERRORS{"CRITICAL"};
+ }
+ if ( $load[$i] > $o_warnL[$i] ) {
+ # output warn error only if no critical was found
+ if ($exit_val eq $ERRORS{"OK"}) {
+ print " $load[$i] > $o_warnL[$i] : WARNING";
+ $exit_val=$ERRORS{"WARNING"};
+ }
+ }
+}
+print " OK" if ($exit_val eq $ERRORS{"OK"});
+if (defined($o_perf)) {
+ print " | cpu_5_sec=$load[0]%;$o_warnL[0];$o_critL[0],";
+ print "cpu_1_min=$load[1]%;$o_warnL[1];$o_critL[1],";
+ print "cpu_5_min=$load[2]%;$o_warnL[2];$o_critL[2]\n";
+} else {
+ print "\n";
+}
+
+exit $exit_val;
+}
+
+################## CPU for : AS/400 , Netsnmp, HP, Bluecoat, linkproof, fortigate ###########
+if ( $o_check_type =~ /netsc|as400|bc|nokia|hp|lp|fg/ ) {
+
+# Get load table
+my @oidlist = $cpu_oid{$o_check_type};
+verb("Checking OID : @oidlist");
+my $resultat = (Net::SNMP->VERSION < 4) ?
+ $session->get_request(@oidlist)
+ : $session->get_request(-varbindlist => \@oidlist);
+if (!defined($resultat)) {
+ printf("ERROR: Description table : %s.\n", $session->error);
+ $session->close;
+ exit $ERRORS{"UNKNOWN"};
+}
+$session->close;
+
+if (!defined ($$resultat{$cpu_oid{$o_check_type}})) {
+ print "No CPU information : UNKNOWN\n";
+ exit $ERRORS{"UNKNOWN"};
+}
+
+my $load=$$resultat{$cpu_oid{$o_check_type}};
+verb("OID returned $load");
+# for AS400, divide by 100
+if ($o_check_type eq "as400") {$load /= 100; };
+# for Net-snmp : oid returned idle time so load = 100-idle.
+if ($o_check_type eq "netsc") {$load = 100 - $load; };
+
+printf("CPU used %.1f%% (",$load);
+
+$exit_val=$ERRORS{"OK"};
+if ($load > $o_crit) {
+ print ">$o_crit) : CRITICAL";
+ $exit_val=$ERRORS{"CRITICAL"};
+} else {
+ if ($load > $o_warn) {
+ print ">$o_warn) : WARNING";
+ $exit_val=$ERRORS{"WARNING"};
+ }
+}
+print "<$o_warn) : OK" if ($exit_val eq $ERRORS{"OK"});
+(defined($o_perf)) ?
+ print " | cpu_prct_used=$load%;$o_warn;$o_crit\n"
+ : print "\n";
+exit $exit_val;
+
+}
+
+##### Checking hpux load
+if ($o_check_type eq "hpux") {
+
+verb("Checking hpux load");
+
+my @oidlists = ($hpux_load_1_min, $hpux_load_5_min, $hpux_load_15_min);
+my $resultat = (Net::SNMP->VERSION < 4) ?
+ $session->get_request(@oidlists)
+ : $session->get_request(-varbindlist => \@oidlists);
+
+if (!defined($resultat)) {
+ printf("ERROR: Load table : %s.\n", $session->error);
+ $session->close;
+ exit $ERRORS{"UNKNOWN"};
+}
+
+$session->close;
+
+if (!defined ($$resultat{$hpux_load_1_min})) {
+ print "No Load information : UNKNOWN\n";
+ exit $ERRORS{"UNKNOWN"};
+}
+
+my @load = undef;
+
+$load[0]=$$resultat{$hpux_load_1_min}/100;
+$load[1]=$$resultat{$hpux_load_5_min}/100;
+$load[2]=$$resultat{$hpux_load_15_min}/100;
+
+print "Load : $load[0] $load[1] $load[2] :";
+
+$exit_val=$ERRORS{"OK"};
+for (my $i=0;$i<3;$i++) {
+ if ( $load[$i] > $o_critL[$i] ) {
+ print " $load[$i] > $o_critL[$i] : CRITICAL";
+ $exit_val=$ERRORS{"CRITICAL"};
+ }
+ if ( $load[$i] > $o_warnL[$i] ) {
+ # output warn error only if no critical was found
+ if ($exit_val eq $ERRORS{"OK"}) {
+ print " $load[$i] > $o_warnL[$i] : WARNING";
+ $exit_val=$ERRORS{"WARNING"};
+ }
+ }
+}
+print " OK" if ($exit_val eq $ERRORS{"OK"});
+if (defined($o_perf)) {
+ print " | load_1_min=$load[0]%;$o_warnL[0];$o_critL[0],";
+ print "load_5_min=$load[1]%;$o_warnL[1];$o_critL[1],";
+ print "load_15_min=$load[2]%;$o_warnL[2];$o_critL[2]\n";
+} else {
+ print "\n";
+}
+
+exit $exit_val;
+}
+
+########## Standard cpu usage check ############
+# Get desctiption table
+my $resultat = (Net::SNMP->VERSION < 4) ?
+ $session->get_table($base_proc)
+ : $session->get_table(Baseoid => $base_proc);
+
+if (!defined($resultat)) {
+ printf("ERROR: Description table : %s.\n", $session->error);
+ $session->close;
+ exit $ERRORS{"UNKNOWN"};
+}
+
+$session->close;
+
+my ($cpu_used,$ncpu)=(0,0);
+foreach my $key ( keys %$resultat) {
+ verb("OID : $key, Desc : $$resultat{$key}");
+ if ( $key =~ /$proc_load/) {
+ $cpu_used += $$resultat{$key};
+ $ncpu++;
+ }
+}
+
+if ($ncpu==0) {
+ print "Can't find CPU usage information : UNKNOWN\n";
+ exit $ERRORS{"UNKNOWN"};
+}
+
+$cpu_used /= $ncpu;
+
+print "$ncpu CPU, ", $ncpu==1 ? "load" : "average load";
+printf(" %.1f",$cpu_used);
+$exit_val=$ERRORS{"OK"};
+
+if ($cpu_used > $o_crit) {
+ print " > $o_crit : CRITICAL";
+ $exit_val=$ERRORS{"CRITICAL"};
+} else {
+ if ($cpu_used > $o_warn) {
+ print " > $o_warn : WARNING";
+ $exit_val=$ERRORS{"WARNING"};
+ }
+}
+print " < $o_warn : OK" if ($exit_val eq $ERRORS{"OK"});
+(defined($o_perf)) ?
+ print " | cpu_prct_used=$cpu_used%;$o_warn;$o_crit\n"
+ : print "\n";
+exit $exit_val;
+
96 nagios/files/default/plugins/check_exceptions_log_error_rate.rb
View
@@ -0,0 +1,96 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'optparse'
+require 'date'
+
+# Useful for testing
+# require 'timecop'
+# Timecop.travel(Time.local(2011, 1, 19, 13, 40, 0)) #Jan 19 13:40:26
+
+OPT = {}
+OptionParser.new do |opts|
+ opts.on("-l", "--logfile FILENAME", "Log filename") {|logfile| OPT[:logfile] = logfile }
+ opts.on("-w", "--critical WARNING", "Warning threshold") { |warning| OPT[:warning] = warning.to_i }
+ opts.on("-c", "--critical CRITICAL", "Critical threshold") { |critical| OPT[:critical] = critical.to_i }
+ opts.parse!(ARGV)
+end
+
+def debug(message)
+ DEBUG and puts message
+end
+
+def datetime_from_string(log)
+ date = log.match /Date: (\w{3}, \d+ \w{3} \d{4} \d{2}:\d{2}:\d{2} \+\d{4})\s+From:/
+ if date
+ return DateTime.strptime(date[1], "%a, %d %b %Y %H:%M:%S %z")
+ else
+ # Some log entries don't have a full date, use the shorter initial date that doesn't specify the year
+ return DateTime.strptime(log[0..14], "%b %e %H:%M:%S")
+ end
+end
+
+now = Time.now; past = Time.now - 300
+NOW = DateTime.civil(now.year, now.month, now.day, now.hour, now.min, now.sec)
+FIVE_MINUTES_AGO = DateTime.civil(past.year, past.month, past.day, past.hour, past.min, past.sec)
+
+DEBUG = false
+HOSTNAME = `hostname`.strip
+FILE_SIZE = File.size(OPT[:logfile])
+LOGFILE = File.open OPT[:logfile]
+MIN_OFFSET = 500 # How many bytes difference until we stop bothering to do a binary search
+
+def log_start_position(seek_pos, old_pos = 0)
+ # Don't try and seek past the beginning or end of the file
+ return FILE_SIZE if seek_pos >= FILE_SIZE
+ return 0 if seek_pos <= 0
+
+ debug "Seeking to #{seek_pos} (#{(seek_pos/FILE_SIZE.to_f) * 100}%), offset is #{seek_pos - old_pos}"
+
+ LOGFILE.seek(seek_pos)
+
+ # discard the first line, it could be incomplete
+ LOGFILE.readline
+ return LOGFILE.pos if LOGFILE.pos == FILE_SIZE
+ ln = LOGFILE.readline
+ date = datetime_from_string(ln)
+
+ if date < FIVE_MINUTES_AGO
+ # The position we are in in the file is too far back in time, jump forward
+ new_pos = LOGFILE.pos + ((FILE_SIZE - LOGFILE.pos) / 2)
+ debug "Date #{date} is too old compared to #{FIVE_MINUTES_AGO.to_s}, new position is #{new_pos}"
+ return LOGFILE.pos if new_pos - LOGFILE.pos <= MIN_OFFSET
+ return log_start_position(new_pos, seek_pos)
+ else
+ # The position we are in the file is too close to the present, jump back
+ new_pos = LOGFILE.pos - ((seek_pos - old_pos) / 2)
+ debug "Date #{date} is too new compared to #{FIVE_MINUTES_AGO.to_s}, new position is #{new_pos}"
+ return LOGFILE.pos if LOGFILE.pos - new_pos <= MIN_OFFSET
+ return log_start_position(new_pos, seek_pos)
+ end
+end
+
+# Seek to the beginning of the log entries we are interested in
+LOGFILE.seek log_start_position(FILE_SIZE/2)
+
+error_count = 0
+
+# Work out error rates
+LOGFILE.readlines.each do |ln|
+ date = datetime_from_string(ln)
+ if date >= FIVE_MINUTES_AGO
+ error_count += 1
+ end
+end
+
+# Let nagios know what the status is
+if error_count > OPT[:critical].to_i
+ puts "Exceptionsfor on #{HOSTNAME} for the last 5 minutes above #{OPT[:critical]} (#{error_count} exceptions)"
+ exit 2
+elsif error_count > OPT[:warning].to_i
+ puts "Exceptions for on #{HOSTNAME} for the last 5 minutes above #{OPT[:warning]} (#{error_count} exceptions)"
+ exit 1
+else
+ puts "Exceptions for on #{HOSTNAME} for the last 5 minutes (#{error_count} exceptions) is OK"
+ exit 0
+end
69 nagios/files/default/plugins/check_file_age.rb
View
@@ -0,0 +1,69 @@
+#!/usr/bin/env ruby
+#
+# Nagios check
+# Check the age of a file. Replaces the nagios default plugin
+#
+
+require 'rubygems'
+require 'choice'
+
+EXIT_OK = 0
+EXIT_WARNING = 1
+EXIT_CRITICAL = 2
+EXIT_UNKNOWN = 3
+
+Choice.options do
+ header ''
+ header 'Specific options:'
+
+ option :warn do
+ short '-w'
+ long '--warning=VALUE'
+ desc 'Warning threshold'
+ cast Integer
+ end
+
+ option :crit do
+ short '-c'
+ long '--critical=VALUE'
+ desc 'Critical threshold'
+ cast Integer
+ end
+
+ option :file do
+ short '-f'
+ long '--file=VALUE'
+ desc 'Path to file'
+ end
+
+ option :invert do
+ short '-i'
+ long '--invert'
+ desc 'File timestamp must be *newer* than the provided thresholds to alert'
+ end
+
+end
+
+c = Choice.choices
+
+age = (Time.now - File.stat(c[:file]).mtime).round
+
+operator = c[:invert] ? "<=" : ">="
+
+if c[:warn] && c[:crit]
+
+ if age.send(operator.to_sym, c[:crit])
+ puts "File age is CRITICAL: #{age} seconds"
+ exit(EXIT_CRITICAL)
+ end
+
+ if age.send(operator.to_sym, c[:warn])
+ puts "File age is WARNING: #{age} seconds"
+ exit(EXIT_WARNING)
+ end
+
+else
+ puts "Please provide a warning and critical threshold"
+end
+
+puts "File age OK"
194 nagios/files/default/plugins/check_fortigate_memory.pl
View
@@ -0,0 +1,194 @@
+#! /usr/bin/perl -w
+#
+# check_fortigate_memory - nagios plugin
+#
+# Description: plugin to query a Fortigate firewall and report the
+# % of memory in use
+#
+##
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+#
+# Report bugs to: msullivan101@gmail.com
+#
+# This plugin is based on existing work from warrious users.
+# No liability
+
+use POSIX;
+use strict;
+# Update the following value to reflect your install
+use lib "/usr/lib/groundwork/nagios/script_securalis" ;
+use lib "/usr/local/groundwork/nagios/libexec" ;
+use lib "/usr/lib/nagios/plugins/";
+use utils qw($TIMEOUT %ERRORS &print_revision &support);
+
+use Net::SNMP;
+use Getopt::Long;
+&Getopt::Long::config('bundling');
+
+my $PROGNAME = "check_fortigate_memory";
+my $status;
+
+my $state = "UNKNOWN";
+my $answer = "";
+my $snmpkey = 0;
+my $community = "public";
+my $port = 161;
+my @snmpoids;
+my $snmpnsResSessActive = '.1.3.6.1.4.1.12356.1.9.0';;
+my $hostname;
+my $session;
+my $error;
+my $response;
+my $snmp_version = 2 ;
+my $opt_h ;
+my $opt_w = 40 ;
+my $opt_c = 60;
+my $opt_V ;
+my $session_used=0;
+
+
+# Just in case of problems, let's not hang Nagios
+$SIG{'ALRM'} = sub {
+ print ("ERROR: No snmp response from $hostname (alarm)\n");
+ exit $ERRORS{"UNKNOWN"};
+};
+alarm($TIMEOUT);
+
+
+$status = GetOptions(
+ "V" => \$opt_V, "version" => \$opt_V,
+ "w=i" => \$opt_w, "warning=i" => \$opt_w,
+ "c=i" => \$opt_c, "critical=i" => \$opt_c,
+ "h" => \$opt_h, "help" => \$opt_h,
+ "v=i" => \$snmp_version, "snmp_version=i" => \$snmp_version,
+ "C=s" =>\$community, "community=s" => \$community,
+ "p=i" =>\$port, "port=i",\$port,
+ "H=s" => \$hostname, "hostname=s" => \$hostname);
+
+
+
+if ($status == 0)
+{
+ print_help();
+ exit $ERRORS{'OK'};
+}
+
+if ($opt_V) {
+ print_revision($PROGNAME,'$Revision: 1.1 $ ');
+ exit $ERRORS{'OK'};
+}
+
+if ($opt_h) {
+ print_help();
+ exit $ERRORS{'OK'};
+}
+
+if (! utils::is_hostname($hostname)){
+ usage();
+ exit $ERRORS{"UNKNOWN"};
+}
+
+
+if ( $snmp_version =~ /[12]/ ) {
+ ($session, $error) = Net::SNMP->session(
+ -hostname => $hostname,
+ -community => $community,
+ -port => $port,
+ -version => $snmp_version