Kaynağa Gözat

added support snmpv3 for nagios subsystem

root 1 yıl önce
ebeveyn
işleme
f7d70e4
44 değiştirilmiş dosya ile 7203 ekleme ve 38 silme
  1. 235 0
      docs/nagios/scripts/Nag/mysql.pm
  2. 44 0
      docs/nagios/scripts/plugins/check_cert_starttls
  3. 139 0
      docs/nagios/scripts/plugins/check_cpu_snmp.sh
  4. 244 0
      docs/nagios/scripts/plugins/check_cpu_usage
  5. 255 0
      docs/nagios/scripts/plugins/check_cpu_usage_v3
  6. 42 0
      docs/nagios/scripts/plugins/check_domain
  7. 52 0
      docs/nagios/scripts/plugins/check_host_mping
  8. 410 0
      docs/nagios/scripts/plugins/check_hwg-ste.pl
  9. 478 0
      docs/nagios/scripts/plugins/check_ifoperstatus
  10. 449 0
      docs/nagios/scripts/plugins/check_ifstatus
  11. 580 0
      docs/nagios/scripts/plugins/check_linux_bonding
  12. 130 0
      docs/nagios/scripts/plugins/check_linux_raid
  13. 58 0
      docs/nagios/scripts/plugins/check_netping_io.pl
  14. BIN
      docs/nagios/scripts/plugins/check_nrpe
  15. 93 0
      docs/nagios/scripts/plugins/check_nt_memory_process.sh
  16. 88 0
      docs/nagios/scripts/plugins/check_oki_status
  17. 149 0
      docs/nagios/scripts/plugins/check_snmp_bandwidth.pl
  18. 111 0
      docs/nagios/scripts/plugins/check_snmp_crc.pl
  19. 100 0
      docs/nagios/scripts/plugins/check_snmp_crc_simple.pl
  20. 189 0
      docs/nagios/scripts/plugins/check_snmp_db_bandwidth.pl
  21. 119 0
      docs/nagios/scripts/plugins/check_snmp_db_crc.pl
  22. 59 0
      docs/nagios/scripts/plugins/check_snmp_hikvision
  23. 72 0
      docs/nagios/scripts/plugins/check_snmp_lastbatt
  24. 910 0
      docs/nagios/scripts/plugins/check_snmp_printer
  25. 899 0
      docs/nagios/scripts/plugins/check_snmp_temperature
  26. 65 0
      docs/nagios/scripts/plugins/check_snmp_uptime
  27. 90 0
      docs/nagios/scripts/plugins/check_ups_battery_replace
  28. 93 0
      docs/nagios/scripts/plugins/check_ups_battery_temp
  29. 93 0
      docs/nagios/scripts/plugins/check_ups_charge_battery
  30. 52 0
      docs/nagios/scripts/plugins/check_ups_exttemp
  31. 56 0
      docs/nagios/scripts/plugins/check_ups_input1
  32. 52 0
      docs/nagios/scripts/plugins/check_ups_input2
  33. 53 0
      docs/nagios/scripts/plugins/check_ups_input3
  34. 97 0
      docs/nagios/scripts/plugins/check_ups_input_ac
  35. 106 0
      docs/nagios/scripts/plugins/check_ups_leave_time
  36. 93 0
      docs/nagios/scripts/plugins/check_ups_load
  37. 78 0
      docs/nagios/scripts/plugins/check_ups_model
  38. 146 0
      docs/nagios/scripts/plugins/check_ups_status
  39. BIN
      docs/nagios/scripts/plugins/libcrypto.so.10
  40. BIN
      docs/nagios/scripts/plugins/libssl.so.10
  41. 112 0
      docs/nagios/scripts/plugins/snmp.pm
  42. 64 0
      docs/nagios/snmp.cfg
  43. 42 18
      scripts/eyelib/nagios.pm
  44. 6 20
      scripts/gen_nagios_config.pl

+ 235 - 0
docs/nagios/scripts/Nag/mysql.pm

@@ -0,0 +1,235 @@
+package Nag::mysql;
+
+#
+# Copyright (C) Roman Dmitiriev, rnd@rajven.ru
+#
+
+use utf8;
+use strict;
+use English;
+use FindBin '$Bin';
+use lib "$Bin";
+use base 'Exporter';
+use vars qw(@EXPORT @ISA);
+use Net::Patricia;
+use Data::Dumper;
+use POSIX;
+use DBI;
+
+our @ISA = qw(Exporter);
+
+our @EXPORT = qw(
+StrToIp
+IpToStr
+do_sql
+init_db
+get_records_sql
+get_record_sql
+update_record
+insert_record
+delete_record
+GetNowTime
+GetUnixTimeByStr
+GetTimeStrByUnixTime
+);
+
+BEGIN
+{
+
+#mysql
+our $DBNAME = 'nagios';
+our $DBHOST = '127.0.0.1';
+our $DBUSER = 'nagios';
+our $DBPASS = 'nagios';
+
+#---------------------------------------------------------------------------------------------------------------
+
+#id
+#device_id
+#ip
+#changed - lsat changed unix timestamp
+#data_id - port number
+#data_type - 0 => bandwidth; 1 => crc
+#data_value1
+#data_value2
+#data_value3
+#data_value4
+
+#---------------------------------------------------------------------------------------------------------------
+
+sub StrToIp{
+return unpack('N',pack('C4',split(/\./,$_[0])));
+}
+
+#---------------------------------------------------------------------------------------------------------------
+
+sub IpToStr{
+my $nIP = shift;
+my $res = (($nIP>>24) & 255) .".". (($nIP>>16) & 255) .".". (($nIP>>8) & 255) .".". ($nIP & 255);
+return $res;
+}
+
+#---------------------------------------------------------------------------------------------------------------
+
+sub do_sql {
+my $db=shift;
+my $sql=shift;
+return if (!$db);
+return if (!$sql);
+my $sql_prep = $db->prepare($sql) or die "Unable to prepare $sql: " . $db->errstr;
+my $sql_ref;
+$sql_prep->execute() or die "Unable to execute $sql: " . $db->errstr;
+if ($sql=~/^insert/i) { $sql_ref = $sql_prep->{mysql_insertid}; }
+if ($sql=~/^select /i) { $sql_ref = $sql_prep->fetchall_arrayref() or die "Unable to select $sql: " . $db->errstr; };
+$sql_prep->finish();
+return $sql_ref;
+}
+
+#---------------------------------------------------------------------------------------------------------------
+
+sub init_db {
+# Create new database handle. If we can't connect, die()
+my $db = DBI->connect("dbi:mysql:database=$DBNAME;host=$DBHOST","$DBUSER","$DBPASS", { RaiseError => 0, AutoCommit => 1 });
+if ( !defined $db ) { die "Cannot connect to mySQL server: $DBI::errstr\n"; }
+$db->do('SET NAMES utf8mb4');
+$db->{'mysql_enable_utf8'} = 1;
+$db->{'mysql_auto_reconnect'} = 1;
+return $db;
+}
+
+#---------------------------------------------------------------------------------------------------------------
+
+sub get_records_sql {
+my $db = shift;
+my $table = shift;
+my @result;
+return @result if (!$db);
+return @result if (!$table);
+my $list = $db->prepare( $table ) or die "Unable to prepare $table:" . $db->errstr;
+$list->execute() or die "Unable to execute $table: " . $db->errstr;
+while(my $row_ref = $list->fetchrow_hashref()) { push(@result,$row_ref); }
+$list->finish();
+return @result;
+}
+
+#---------------------------------------------------------------------------------------------------------------
+
+sub get_record_sql {
+my $db = shift;
+my $tsql = shift;
+my @result;
+return @result if (!$db);
+return @result if (!$tsql);
+$tsql.=' LIMIT 1';
+my $list = $db->prepare($tsql) or die "Unable to prepare $tsql: " . $db->errstr;
+$list->execute() or die "Unable to execute $tsql: " . $db->errstr;
+my $row_ref = $list->fetchrow_hashref();
+$list->finish();
+return $row_ref;
+}
+
+#---------------------------------------------------------------------------------------------------------------
+
+sub update_record {
+my $db = shift;
+my $table = shift;
+my $record = shift;
+my $filter = shift;
+return if (!$db);
+return if (!$table);
+return if (!$filter);
+my $change_str='';
+foreach my $field (keys %$record) {
+    if (!defined $record->{$field}) { $record->{$field}=''; }
+    my $new_value = $record->{$field};
+    $new_value=~s/\'//g;
+    $new_value=~s/\"//g;
+    $change_str = $change_str." `$field`=".$db->quote($record->{$field}).",";
+    }
+
+$change_str=~s/\,$//;
+my $sSQL = "UPDATE $table SET $change_str WHERE $filter";
+do_sql($db,$sSQL);
+}
+
+#---------------------------------------------------------------------------------------------------------------
+
+sub insert_record {
+my $db = shift;
+my $table = shift;
+my $record = shift;
+return if (!$db);
+return if (!$table);
+my $fields='';
+my $values='';
+foreach my $field (keys %$record) {
+    if (!defined $record->{$field}) { $record->{$field}=''; }
+    my $new_value = $record->{$field};
+    $new_value=~s/\'//g;
+    $new_value=~s/\"//g;
+    $fields = $fields."`$field`,";
+    $values = $values." ".$db->quote($new_value).",";
+    }
+$fields=~s/,$//;
+$values=~s/,$//;
+my $sSQL = "INSERT INTO $table($fields) VALUES($values)";
+my $result = do_sql($db,$sSQL);
+return $result;
+}
+
+#---------------------------------------------------------------------------------------------------------------
+
+sub delete_record {
+my $db = shift;
+my $table = shift;
+my $filter = shift;
+return if (!$db);
+return if (!$table);
+return if (!$filter);
+my $sSQL = "DELETE FROM ".$table." WHERE ".$filter;
+do_sql($db,$sSQL);
+}
+
+#---------------------------------------------------------------------------------------------------------------
+
+sub GetNowTime {
+my ($sec,$min,$hour,$day,$month,$year,$zone) = localtime(time());
+$month += 1;
+$year += 1900;
+my $now_str=sprintf "%04d-%02d-%02d %02d:%02d:%02d",$year,$month,$day,$hour,$min,$sec;
+return $now_str;
+}
+
+#---------------------------------------------------------------------------------------------------------------
+
+sub GetUnixTimeByStr {
+my $time_str = shift;
+$time_str =~s/\//-/g;
+$time_str =~s/^\s+//g;
+$time_str =~s/\s+$//g;
+my ($sec,$min,$hour,$day,$mon,$year) = (localtime())[0,1,2,3,4,5];
+$year+=1900;
+$mon++;
+if ($time_str =~/^([0-9]{2,4})\-([0-9]{1,2})-([0-9]{1,2})\s+/) {
+    $year = $1; $mon = $2; $day = $3;
+    }
+if ($time_str =~/([0-9]{1,2})\:([0-9]{1,2})\:([0-9]{1,2})$/) {
+    $hour = $1; $min = $2; $sec = $3;
+    }
+my $result = mktime($sec,$min,$hour,$day,$mon-1,$year-1900);
+return $result;
+}
+
+#---------------------------------------------------------------------------------------------------------------
+
+sub GetTimeStrByUnixTime {
+my $time = shift || time();
+my ($sec, $min, $hour, $mday, $mon, $year) = (localtime($time))[0,1,2,3,4,5];
+my $result = strftime("%Y-%m-%d %H:%M:%S",$sec, $min, $hour, $mday, $mon, $year);
+return $result;
+}
+
+#---------------------------------------------------------------------------------------------------------------
+
+1;
+}

+ 44 - 0
docs/nagios/scripts/plugins/check_cert_starttls

@@ -0,0 +1,44 @@
+#!/bin/bash
+
+hostip=$1
+port=$2
+warn_days=$3
+crit_days=$4
+
+[ -z "${crit_days}" ] && crit_days=3
+[ -z "${warn_days}" ] && warn_days=10
+
+now=`date +%s`
+
+CERT_TXT=$(echo "QUIT" | LANG=C openssl s_client -min_protocol SSLv3 -starttls smtp -connect ${hostip}:${port} 2>/dev/null | sed -n '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/p' | openssl x509 -text -noout)
+
+NAME=$(echo "$CERT_TXT" | grep "Subject: OU=Domain Control Validated" | awk '{ print $NF }' | sed 's/CN=//')
+
+TIMESTAMP=$(echo "$CERT_TXT" | grep "Not After" | sed -r 's/\s+Not After\s+\://')
+
+expire_time=$(date +%s -d "${TIMESTAMP}")
+
+[ -z "${expire_time}" ] && expire_time=22394880000
+
+SEC_DIFF=$(( $expire_time - $now ))
+
+DAYS_DIFF=$(( $SEC_DIFF / 86400 ))
+
+if [ $expire_time -le $now ]; then
+    echo "CRIT! Expired cert ${NAME}"
+    exit 2
+    fi
+
+if [ $DAYS_DIFF -le $crit_days ]; then
+    echo "CRIT! Soon we will lose the certificate ${NAME} - only $DAYS_DIFF days left"
+    exit 2
+    fi
+
+if [ $DAYS_DIFF -le $warn_days ]; then
+    echo "WARN! we need to update the certificate ${NAME} - only $DAYS_DIFF days left"
+    exit 1
+    fi
+
+echo "OK! $DAYS_DIFF days left for ${NAME}"
+
+exit 0

+ 139 - 0
docs/nagios/scripts/plugins/check_cpu_snmp.sh

@@ -0,0 +1,139 @@
+#!/bin/bash
+
+#############################################################
+# Nagios Linux/Windows CPU usage monitoring (using SNMP)
+#############################################################
+# Author  : Sunchai Rungruengchoosakul
+# Date    : Feb 7, 2011
+# Version : 1.0
+# License : GPL
+#############################################################
+# Require:
+#    - snmpwalk command
+# 
+# Check total cpu
+# # snmpwalk -v 2c -c COMMUNITY x.x.x.x -On .1.3.6.1.2.1.25.3.3.1.1
+#
+# Check cpu usage
+# # snmpwalk -v 2c -c COMMUNITY x.x.x.x -On .1.3.6.1.2.1.25.3.3.1.2
+#
+#############################################################
+# Change Log :-
+#    Make plugin with performance output :-)
+#
+# Performance specification : 'label'=value[UOM];[warn];[crit];[min];[max]
+# Sample :DISK OK - free space: / 3326 MB (56%);| /=2643MB;5948;5958;0;5968
+#
+# From URL http://nagiosplug.sourceforge.net/developer-guidelines.html#AEN201
+#############################################################
+
+help () {
+
+  echo "===================================="
+  echo "check_cpu_snmp.bash"
+  echo "===================================="
+  echo "Author  : Sunchai Rungruengchoosakul "
+  echo "Version : 1.0"
+  echo "Date    : Feb 7, 2011"
+  echo "===================================="
+  echo "Option:-" 
+  echo " -w  : CPU Usage warning (default 60%)"
+  echo " -c  : CPU Usage critical (default 90%)"
+  echo " -H* : Hostname / IP address"
+  echo " -C* : SNMP Community string"
+  echo " -d  : Debug option"
+  echo " * is require parameter"
+  exit 0
+}
+
+WARNING="60"
+CRITICAL="90"
+COMMUNITY=""
+DESTINATION=""
+DEBUG="n"
+
+while getopts ":H:C:c:w:hd" Option
+do
+  case $Option in
+    w )
+      WARNING=$OPTARG
+      ;;
+    c )
+      CRITICAL=$OPTARG
+      ;;
+    H )
+      DESTINATION=$OPTARG
+      ;;
+    C ) 
+      COMMUNITY=$OPTARG
+      ;;
+    h ) 
+      help
+      ;;
+    d )
+      DEBUG=y
+      ;;
+  esac
+done
+shift $(($OPTIND - 1))
+
+
+# Check parameter
+[ -z $COMMUNITY ] && help
+[ -z $DESTINATION ] && help
+
+# Show debug
+[ $DEBUG == "y" ] && echo Community = $COMMUNITY
+[ $DEBUG == "y" ] && echo Destination = $DESTINATION
+
+#################
+# Engine from report monitoring tools
+
+# Make temp file
+TMP_FILE=/tmp/CPU_RRD_$RANDOM
+
+# Snmpwalk to HOSTMIB
+snmpwalk -v 1 -c $COMMUNITY $DESTINATION -On .1.3.6.1.2.1.25.3.3.1.2 > $TMP_FILE
+
+# Show debug
+[ $DEBUG == "y" ] && echo "RAW snmp ==" && cat $TMP_FILE
+
+# Summary all CPU Usage
+AAA=`awk '{ sum += $4 }; END { print sum }' $TMP_FILE`
+
+# Define total cpu
+BBB=`wc -l $TMP_FILE | awk '{print $1}'`
+
+# Fix problem with single cpu
+[ -z ${BBB} ] && BBB="1"
+[ "${BBB}" == "0" ] && BBB="1"
+
+# Show debug
+[ $DEBUG == "y" ] && echo "CPU USAGE TOTAL: "$AAA
+[ $DEBUG == "y" ] && echo "CPU NUM: "$BBB
+
+# Calculate total cpu usage
+let "CCC = ${AAA}/${BBB}"
+
+#echo "CPU USAGE AVG: "${CCC}
+
+# Remove temp file
+rm -f $TMP_FILE > /dev/null 2>&1
+
+#################
+
+# Unknow status
+[ -z $CCC ] && echo "Cannot retrive information" && exit 3
+
+# Sample from plugin ## time=0.627618s;;;0.000000 size=2016B;;;0
+#                       'label'=value[UOM];[warn];[crit];[min];[max]
+echo "CPU Usage : $CCC % |cpu=$CCC%;$WARNING;$CRITICAL;0;100"
+
+# Normal status
+[ $CCC -lt $WARNING ] && exit 0
+
+# Warning status
+[ $CCC -lt $CRITICAL ] && exit 1
+
+# Critical status
+[ $CCC -gt $CRITICAL ] && exit 2

+ 244 - 0
docs/nagios/scripts/plugins/check_cpu_usage

@@ -0,0 +1,244 @@
+#!/usr/bin/perl
+
+# Author: Martin Fuerstenau, Oce Printing Systems
+#         martin.fuerstenau_at_oce.com or Martin.fuerstenau_at_nagiossw.org
+#
+# Date:   14 Apr 2011
+# 
+#
+# Purpose and features of the program:
+#
+# - Get the CPU Usage for Windows, Solaris and Linux servers.
+#
+
+use strict;
+use Getopt::Long;
+use File::Basename;
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+#--- Start presets and declarations ----------------------------------------------
+
+my $version = '1.0';             # The program version
+my $get_version;                 # Switch to display the program version
+my $progname = basename($0);     # The name of the program
+my $warning;                     # The warning threshold
+my $warning_def=80;              # The default warning threshold
+my $critical;                    # The critical threshold
+my $critical_def=90;             # The default critical threshold
+my $result;                      # The result from the snmpwalk
+my @result;                      # The splitted result from the snmpwalk
+my $host;                        # Host to check
+my $help;                        # Switch to display the help function
+my $community;                   # Contains the SNMP community string
+my $community_def="public";      # Contains the SNMP default community string
+my $NoA;                         # Number of Arguments handled over to the program
+                                 # -1 means no arguments which will cause an error
+my $cpu_usage="";                # The usage per CPU
+my $avg_usage;                   # The usage for all CPUs
+my $perf_usage;                  # The usage for all 
+my $noperfdata;                  # If set no performance data will be delivered
+my $NoC;                         # Number of CPUs
+my $snmpversion;                 # SNMP version
+my $snmpversion_def=1;           # SNMP version default
+my $timeout;                     # SNMP timeout
+my $timeout_def=60;              # SNMP timeout default
+
+sub usage();
+sub help ();
+
+#--- End presets -----------------------------------------------------------------
+
+# First we have to fix  the number of arguments
+
+$NoA=$#ARGV;
+
+Getopt::Long::Configure('bundling');
+GetOptions
+	("H=s" => \$host,         "hostname=s"    => \$host,
+         "C=s" => \$community,    "community=s"   => \$community,
+	 "w=s" => \$warning,      "warning=s"     => \$warning,
+	 "c=s" => \$critical,     "critical=s"    => \$critical,
+	 "t=s" => \$timeout,      "timeout=s"     => \$timeout,
+	 "V"   => \$get_version,  "version"       => \$get_version,
+	 "v=s" => \$snmpversion,  "snmpversion=s" => \$snmpversion,
+	 "n"   => \$noperfdata,   "noperfdata"    => \$noperfdata,
+         "h"   => \$help,         "help"          => \$help);
+
+
+if ($get_version)
+   {
+   print "$progname version: $version\n";
+   exit 0;
+   }
+
+if ($help)
+   {
+   help();
+   exit 0;
+   }
+
+# Right number of arguments (therefore noa :-)) )
+
+if ( $NoA == -1 )
+   {
+   usage();
+   exit 1;
+   }
+
+if (!$warning)
+   {
+   $warning=$warning_def;
+   }
+
+if (!$critical)
+   {
+   $critical=$critical_def;
+   }
+
+if (!$timeout)
+   {
+   $timeout=$timeout_def;
+   }
+
+if (!$host)
+   {
+   print "Host name/address not specified\n\n";
+   usage();
+   exit 1;
+   }
+
+if (!$snmpversion)
+   {
+   $snmpversion=$snmpversion_def;
+   }
+else   
+   {
+   if ( $snmpversion ne "1" )
+      {
+      if ( $snmpversion ne "2c" )
+         {
+         print "\nWrong SNMP version submitted. Only version 1 of 2c is allowed.\n\n";
+         exit 1;
+         }
+      }
+   }
+
+if (!$community)
+   {
+   $community = $community_def;
+   print "No community string supplied - using default $community_def\n";
+   }
+
+$result =`snmpwalk -v $snmpversion -t $timeout -c $community $host 1.3.6.1.2.1.25.3.3.1.2`;
+
+if ( $result )
+   {
+   @result = split (/\n/,$result);
+   $NoC=0;
+  
+   foreach ( @result )
+           {
+           s/HOST-RESOURCES-MIB::hrProcessorLoad.\d+ = INTEGER://g;	
+           $avg_usage+=$_;
+           $cpu_usage=$cpu_usage.", CPU-$NoC:$_%".";".$warning.";".$critical;
+           $NoC++;
+           }
+   $avg_usage = $avg_usage / $NoC;
+   $avg_usage = sprintf("%.0f",$avg_usage);
+   $perf_usage = $cpu_usage;
+   $cpu_usage =~ s/;$warning;$critical//g;
+   $perf_usage =~ s/, / /g;
+   $perf_usage =~ s/: /=/g;
+   $perf_usage = "CPU-AVG=".$avg_usage."%".";".$warning.";".$critical.$perf_usage;
+
+   if ( $avg_usage < $warning )
+      {
+      if (!$noperfdata)
+         {
+         print "OK: Average CPU usage: $avg_usage%$cpu_usage|$perf_usage";
+         exit 0;
+         }
+      else
+         {
+         print "OK: Average CPU usage: $avg_usage%$cpu_usage";
+         exit 0;
+         }
+      }
+   else
+      {
+      if ( $avg_usage >= $warning )
+         {
+         if ( $avg_usage < $critical )
+            {
+            if (!$noperfdata)
+               {
+               print "WARNING: Average CPU usage: $avg_usage%$cpu_usage|$perf_usage";
+               exit 1;
+               }
+            else
+               {
+               print "WARNING: Average CPU usage: $avg_usage%$cpu_usage";
+               exit 1;
+               }
+            }
+         else
+            {
+            if (!$noperfdata)
+               {
+               print "CRITICAL: Average CPU usage: $avg_usage%$cpu_usage|$perf_usage";
+               exit 2;
+               }
+            else
+               {
+               print "CRITICAL: Average CPU usage: $avg_usage%$cpu_usage";
+               exit 2;
+               }
+            }
+         }
+      }
+   }
+else
+   {
+   print "Unknown: No response\n";
+   exit 3;
+   }
+
+
+# ---- Subroutines -------------------------------------------------------
+
+sub usage()
+    {
+    print "Usage:\n";
+    print "$progname -H <host>|--hostname=<host> [-C <community>|--community=<community>] ";
+    print "[-v <1|2c>|--snmpversion=<1|2c>] [-t <timeout>|--timeout=<timeout>] [-n|--noperfdata] ";
+    print "[-w <threshold>|--warning=<threshold>] [-c <threshold>|--critical=<threshold>]\n\n";
+    print "or \n\n";
+    print "$progname -h|--help\n\n";
+    print "or \n\n";
+    print "$progname -V|--version\n";
+    }
+
+sub help ()
+    {
+    usage();
+
+    print "This plugin check the CPU usage of solaris, linux and windows servers\n\n";
+
+    print "-h|--help                               Print detailed help screen\n";
+    print "-V|--version                            Print version information\n";
+    print "-H <host>|--hostname=<host>             Hostname/IP-Adress to use for the check.\n";
+    print "-C <community>|--community=<community>  SNMP community that should be used to access the switch.\n";
+    print "                                        Default: $community_def\n";
+    print "-n|--noperfdata                         Don't print performance data.\n";
+    print "-t <timeout>|--timeout=<timeout>        Seconds before plugin times out.\n";
+    print "                                        Default: $timeout_def\n";
+    print "-v <1|2c>|--snmpversion=<1|2c>          SNMP version details for command-line debugging (can repeat up to 3 times)\n\n";
+    print "                                        Default: $snmpversion_def\n";
+    print "-w <threshold>|--warning=<threshold>    Warning threshold in percent.\n\n";
+    print "                                        Default: $warning_def\n";
+    print "-c <threshold>|--critical=<threshold>   Critical threshold in percent.\n\n";
+    print "                                        Default: $critical_def\n";
+    }

+ 255 - 0
docs/nagios/scripts/plugins/check_cpu_usage_v3

@@ -0,0 +1,255 @@
+#!/usr/bin/perl
+
+# Author: Martin Fuerstenau, Oce Printing Systems
+#         martin.fuerstenau_at_oce.com or Martin.fuerstenau_at_nagiossw.org
+#
+# Date:   14 Apr 2011
+# 
+#
+# Purpose and features of the program:
+#
+# - Get the CPU Usage for Windows, Solaris and Linux servers.
+#
+
+use strict;
+use Getopt::Long;
+use File::Basename;
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+#--- Start presets and declarations ----------------------------------------------
+
+my $version = '1.0';             # The program version
+my $get_version;                 # Switch to display the program version
+my $progname = basename($0);     # The name of the program
+my $warning;                     # The warning threshold
+my $warning_def=80;              # The default warning threshold
+my $critical;                    # The critical threshold
+my $critical_def=90;             # The default critical threshold
+my $result;                      # The result from the snmpwalk
+my @result;                      # The splitted result from the snmpwalk
+my $host;                        # Host to check
+my $help;                        # Switch to display the help function
+my $community;                   # Contains the SNMP community string
+my $community_def="public";      # Contains the SNMP default community string
+my $NoA;                         # Number of Arguments handled over to the program
+                                 # -1 means no arguments which will cause an error
+my $cpu_usage="";                # The usage per CPU
+my $avg_usage;                   # The usage for all CPUs
+my $perf_usage;                  # The usage for all 
+my $noperfdata;                  # If set no performance data will be delivered
+my $NoC;                         # Number of CPUs
+my $snmpversion;                 # SNMP version
+my $snmpversion_def=1;           # SNMP version default
+my $snmp_user;
+my $snmp_password;
+my $timeout;                     # SNMP timeout
+my $timeout_def=60;              # SNMP timeout default
+
+sub usage();
+sub help ();
+
+#--- End presets -----------------------------------------------------------------
+
+# First we have to fix  the number of arguments
+
+$NoA=$#ARGV;
+
+Getopt::Long::Configure('bundling');
+GetOptions
+	("H=s" => \$host,         "hostname=s"    => \$host,
+         "C=s" => \$community,    "community=s"   => \$community,
+         "u=s" => \$snmp_user,    "snmp_user=s"   => \$snmp_user,
+         "p=s" => \$snmp_password,"snmp_password=s" => \$snmp_password,
+	 "w=s" => \$warning,      "warning=s"     => \$warning,
+	 "c=s" => \$critical,     "critical=s"    => \$critical,
+	 "t=s" => \$timeout,      "timeout=s"     => \$timeout,
+	 "V"   => \$get_version,  "version"       => \$get_version,
+	 "v=s" => \$snmpversion,  "snmpversion=s" => \$snmpversion,
+	 "n"   => \$noperfdata,   "noperfdata"    => \$noperfdata,
+         "h"   => \$help,         "help"          => \$help);
+
+
+if ($get_version)
+   {
+   print "$progname version: $version\n";
+   exit 0;
+   }
+
+if ($help)
+   {
+   help();
+   exit 0;
+   }
+
+# Right number of arguments (therefore noa :-)) )
+
+if ( $NoA == -1 )
+   {
+   usage();
+   exit 1;
+   }
+
+if (!$warning)
+   {
+   $warning=$warning_def;
+   }
+
+if (!$critical)
+   {
+   $critical=$critical_def;
+   }
+
+if (!$timeout)
+   {
+   $timeout=$timeout_def;
+   }
+
+if (!$host)
+   {
+   print "Host name/address not specified\n\n";
+   usage();
+   exit 1;
+   }
+
+if (!$snmpversion) { $snmpversion=$snmpversion_def; }
+
+if ( $snmpversion !~ "(1|2|2c|3)" ) {
+     print "\nWrong SNMP version submitted. Only version 1, 2, 2c, 3 is allowed.\n\n";
+     exit 1;
+   }
+
+if (!$community and $snmpversion ne "3")
+   {
+   $community = $community_def;
+   print "No community string supplied - using default $community_def\n";
+   }
+
+if ($snmpversion eq "3" and (!$snmp_user or !$snmp_password)) {
+     print "\nWrong SNMP parameters!\n\n";
+     exit 1;
+   }
+
+if ($snmpversion ne "3") { 
+    $result =`snmpwalk -v $snmpversion -t $timeout -c $community -O v $host 1.3.6.1.2.1.25.3.3.1.2`;
+    } else {
+#-a PROTOCOL           set authentication protocol (MD5|SHA)
+#-A PASSPHRASE               set authentication protocol pass phrase
+#-l LEVEL              set security level (noAuthNoPriv|authNoPriv|authPriv)
+#-u USER-NAME              set security name (e.g. bert)
+#-x PROTOCOL             set privacy protocol (DES|AES)
+#-X PASSPHRASE         set privacy protocol pass phrase
+    $result =`snmpwalk -v 3 -a SHA -x AES -l authNoPriv -u $snmp_user -A $snmp_password -X $snmp_password -t $timeout -O v $host 1.3.6.1.2.1.25.3.3.1.2`;
+    }
+
+if ( $result )
+   {
+   @result = split (/\n/,$result);
+   $NoC=0;
+  
+   foreach ( @result )
+           {
+           s/HOST-RESOURCES-MIB::hrProcessorLoad.\d+ = INTEGER://g;	
+           s/INTEGER: //g;
+           $avg_usage+=$_;
+           $cpu_usage=$cpu_usage.", CPU-$NoC:$_%".";".$warning.";".$critical;
+           $NoC++;
+           }
+   $avg_usage = $avg_usage / $NoC;
+   $avg_usage = sprintf("%.0f",$avg_usage);
+   $perf_usage = $cpu_usage;
+   $cpu_usage =~ s/;$warning;$critical//g;
+   $perf_usage =~ s/, / /g;
+   $perf_usage =~ s/: /=/g;
+   $perf_usage = "CPU-AVG=".$avg_usage."%".";".$warning.";".$critical.$perf_usage;
+
+   if ( $avg_usage < $warning )
+      {
+      if (!$noperfdata)
+         {
+         print "OK: Average CPU usage: $avg_usage%$cpu_usage|$perf_usage";
+         exit 0;
+         }
+      else
+         {
+         print "OK: Average CPU usage: $avg_usage%$cpu_usage";
+         exit 0;
+         }
+      }
+   else
+      {
+      if ( $avg_usage >= $warning )
+         {
+         if ( $avg_usage < $critical )
+            {
+            if (!$noperfdata)
+               {
+               print "WARNING: Average CPU usage: $avg_usage%$cpu_usage|$perf_usage";
+               exit 1;
+               }
+            else
+               {
+               print "WARNING: Average CPU usage: $avg_usage%$cpu_usage";
+               exit 1;
+               }
+            }
+         else
+            {
+            if (!$noperfdata)
+               {
+               print "CRITICAL: Average CPU usage: $avg_usage%$cpu_usage|$perf_usage";
+               exit 2;
+               }
+            else
+               {
+               print "CRITICAL: Average CPU usage: $avg_usage%$cpu_usage";
+               exit 2;
+               }
+            }
+         }
+      }
+   }
+else
+   {
+   print "Unknown: No response\n";
+   exit 3;
+   }
+
+
+# ---- Subroutines -------------------------------------------------------
+
+sub usage()
+    {
+    print "Usage:\n";
+    print "$progname -H <host>|--hostname=<host> [-C <community>|--community=<community>] ";
+    print "[-v <1|2c>|--snmpversion=<1|2c>] [-t <timeout>|--timeout=<timeout>] [-n|--noperfdata] ";
+    print "[-w <threshold>|--warning=<threshold>] [-c <threshold>|--critical=<threshold>]\n\n";
+    print "or \n\n";
+    print "$progname -h|--help\n\n";
+    print "or \n\n";
+    print "$progname -V|--version\n";
+    }
+
+sub help ()
+    {
+    usage();
+
+    print "This plugin check the CPU usage of solaris, linux and windows servers\n\n";
+
+    print "-h|--help                               Print detailed help screen\n";
+    print "-V|--version                            Print version information\n";
+    print "-H <host>|--hostname=<host>             Hostname/IP-Adress to use for the check.\n";
+    print "-C <community>|--community=<community>  SNMP community that should be used to access the switch.\n";
+    print "                                        Default: $community_def\n";
+    print "-n|--noperfdata                         Don't print performance data.\n";
+    print "-t <timeout>|--timeout=<timeout>        Seconds before plugin times out.\n";
+    print "                                        Default: $timeout_def\n";
+    print "-v <1|2c>|--snmpversion=<1|2c>          SNMP version details for command-line debugging (can repeat up to 3 times)\n\n";
+    print "                                        Default: $snmpversion_def\n";
+    print "-w <threshold>|--warning=<threshold>    Warning threshold in percent.\n\n";
+    print "                                        Default: $warning_def\n";
+    print "-c <threshold>|--critical=<threshold>   Critical threshold in percent.\n\n";
+    print "                                        Default: $critical_def\n";
+    }

+ 42 - 0
docs/nagios/scripts/plugins/check_domain

@@ -0,0 +1,42 @@
+#!/bin/bash
+
+. /usr/lib/nagios/plugins/utils.sh
+
+WHOIS=/usr/bin/whois
+
+DOMAIN_NAME=$1
+DAYS=$2
+
+if [ -z "${DOMAIN_NAME}" ]; then
+    echo "Domain not defined!"
+    exit $STATE_WARNING
+    fi
+
+[ -z "${DAYS}" ] && DAYS=30
+
+time_shift=$((86400 * ${DAYS}))
+
+if [ `echo "${DOMAIN_NAME}" | egrep -i "RU$"` ]; then
+    paid_data=`${WHOIS} "${DOMAIN_NAME}" | grep paid-till`
+    [ -z "${paid_data}" ] && exit $STATE_UNKNOWN
+    paid=`${WHOIS} "${DOMAIN_NAME}" | grep paid-till | awk '{ print $NF }' | awk -F"T" '{ print $1 }' | sed 's/\./\//g'`
+    else
+    paid=`${WHOIS} "${DOMAIN_NAME}" | grep -E "(Expiration|Expiry Date)" | head -1 | awk '{ print $NF }' | awk -F"T" '{ print $1 }' | sed 's/-/\//g'`
+    [ -z "${paid}" ] && exit $STATE_UNKNOWN
+    paid_data="paid-till: ${paid}"
+    fi
+
+now=`date +"%s"`
+paid_date=`date --date="${paid}" +"%s"`
+remaining=`expr ${paid_date} - ${now}`
+
+if [ ${remaining} -lt 0 ]; then
+    echo "${DOMAIN_NAME} domain prosrali..."
+    exit $STATE_CRITICAL
+    fi
+
+remaining_days=`expr ${remaining} / 86400`
+echo "${DOMAIN_NAME} ${paid_data} remaining ${remaining_days} days"
+
+[ ${remaining} -gt ${time_shift} ] && exit $STATE_OK
+exit $STATE_WARNING

+ 52 - 0
docs/nagios/scripts/plugins/check_host_mping

@@ -0,0 +1,52 @@
+#!/bin/sh
+#/usr/lib/nagios/plugins/check_icmp -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 1
+# usage of nagios: check_host_mping $ARGV1 $HOSTADDRESSES
+#        -- $ARGV1 - Quantity of addresses of a host
+#        -- $HOSTADDRESSES - ip the addresses of a host divided by a blank (it is no more 4)
+STAT=$1
+KIP=$1
+STRMES=""
+IP1=$2
+IP2=$3
+IP3=$4
+IP4=$5
+
+rez1=`/usr/lib/nagios/plugins/check_icmp -H $IP1 -w 1000.0,80% -c 2000.0,100% -p 1 |grep OK`
+perf1=`echo "${rez1}" | awk -F="|" '{ print $2}' | awk '{print $1 }'`
+if [ ! "$rez1" ]; then
+    STAT=`expr $STAT - 1`
+else
+    STRMES=${STRMES}$IP1" "
+fi
+
+if [ $KIP -gt 1 ]; then
+    rez2=`/usr/lib/nagios/plugins/check_icmp -H $IP2 -w 1000.0,80% -c 2000.0,100% -p 1 |grep OK`
+    if [ ! "$rez2" ]; then
+        STAT=`expr $STAT - 1`
+    else
+        STRMES=${STRMES}$IP2" "
+    fi
+    if [ $KIP -gt 2 ]; then
+        rez3=`/usr/lib/nagios/plugins/check_icmp -H $IP3 -w 1000.0,80% -c 2000.0,100% -p 1 |grep OK`
+        if [ ! "$rez3" ]; then
+            STAT=`expr $STAT - 1`
+        else
+            STRMES=${STRMES}$IP3" "
+        fi
+        if [ $KIP -gt 3 ]; then
+            rez4=`/usr/lib/nagios/plugins/check_icmp -H $IP4 -w 1000.0,80% -c 2000.0,100% -p 1 |grep OK`
+            if [ ! "$rez3" ]; then
+                STAT=`expr $STAT - 1`
+            else
+                STRMES=${STRMES}$IP4
+            fi
+        fi
+    fi
+fi
+
+if [ $STAT -eq 0 ]; then
+    echo "CRITICAL! Host Down!"
+    exit 2
+else
+    echo "OK! $STRMES  ip - $STAT of $KIP | ${perf1}"
+fi

+ 410 - 0
docs/nagios/scripts/plugins/check_hwg-ste.pl

@@ -0,0 +1,410 @@
+#!/usr/bin/perl
+
+# ------------------------------------------------------------------------------
+# check_hwgroup.pl - checks the HW group Hwg-STE devices.
+# Copyright (C) 2010  NETWAYS GmbH, www.netways.de
+# Author: Michael Streb <michael.streb@netways.de>
+# Author: Bernd Löhlein <bernd.loehlein@netways.de>
+# Version: $Id: check_hwg-ste.pl 1558 2010-02-17 13:07:57Z mstreb $
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the tepdu 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.
+# $Id: check_hwg-ste.pl 1558 2010-02-17 13:07:57Z mstreb $
+# ------------------------------------------------------------------------------
+
+# basic requirements
+use strict;
+use Getopt::Long;
+use File::Basename;
+use Pod::Usage;
+use Net::SNMP;
+use Data::Dumper;
+
+# predeclared subs
+use subs qw/print_help/;
+
+# predeclared vars
+use vars qw (
+  $PROGNAME
+  $VERSION
+
+  %states
+  %state_names
+
+  $opt_host
+  $opt_community
+  $opt_sensor
+  $opt_contact
+  $opt_warning
+  $opt_critical
+
+  $opt_help
+  $opt_man
+  $opt_version
+
+  $module
+
+  $device
+  $response
+  $output
+  @oids
+);
+
+# Main values
+$PROGNAME = basename($0);
+$VERSION  = '1.1';
+
+# Nagios exit states
+%states = (
+	OK       => 0,
+	WARNING  => 1,
+	CRITICAL => 2,
+	UNKNOWN  => 3
+);
+
+# Nagios state names
+%state_names = (
+	0 => 'OK',
+	1 => 'WARNING',
+	2 => 'CRITICAL',
+	3 => 'UNKNOWN'
+);
+
+$opt_warning = "null";
+$opt_critical = "null";
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+# SNMP
+
+my $opt_community = "public";
+my $snmp_version  = "1";
+
+#my $response;
+
+# Get the options from cl
+Getopt::Long::Configure('bundling');
+GetOptions(
+	'h'       => \$opt_help,
+	'help'       => \$opt_help,
+	'H=s'     => \$opt_host,
+	'C=s',    => \$opt_community,
+	'S=n',    => \$opt_sensor,
+	'I=n',    => \$opt_contact,
+	'w=s'     => \$opt_warning,
+	'c=s'     => \$opt_critical,
+	'man'     => \$opt_man,
+	'V'		  => \$opt_version
+  )
+  || print_help( 1, 'Please check your options!' );
+
+# If somebody wants to the help ...
+if ($opt_help) {
+	print_help(1);
+}
+elsif ($opt_man) {
+	print_help(2);
+}
+elsif ($opt_version) {
+	print_help(-1);
+}
+
+# oids
+my $deviceid = '.1.3.6.1.2.1.1.1.0';
+my $enterprise = '.1.3.6.1.4.1.21796';
+
+# Check if all needed options present.
+unless ( $opt_host && ( $opt_sensor || $opt_contact ) ) {
+
+	print_help( 1, 'Not enough options specified!' );
+}
+else {
+
+	# Open SNMP Session
+	my ( $session, $error ) = Net::SNMP->session(
+		-hostname  => $opt_host,
+		-community => $opt_community,
+		-port      => 161,
+		-timeout   => 5,
+		-version   => $snmp_version
+	);
+
+	# SNMP Session failed
+	if ( !defined($session) ) {
+		print $state_names{ ( $states{UNKNOWN} ) } . ": $error";
+		exit $states{UNKNOWN};
+	}
+
+	# request for sensor
+	if (defined $opt_sensor) {
+
+		my ($sensor_tree_id, $sensor_id);
+
+		# Sensor states
+		my %sensor_states = ();
+
+		# Sensor OID setting
+
+		# check for device type Poseidon/STE
+		$response = $session->get_request($deviceid);
+		$device = $response->{$deviceid};
+
+		if ($device =~ m/Poseidon/i) {
+			# Sensor states
+			%sensor_states = (
+				0 => 'invalid',
+				1 => 'normal',
+				2 => 'alarmstate',
+				3 => 'alarm',
+			);
+			$sensor_tree_id = $enterprise.".3.3.3.1.8";
+		} elsif ($device =~ m/STE/i) {
+			# Sensor states
+			%sensor_states = (
+				0 => 'invalid',
+				1 => 'normal',
+				2 => 'outofrangelo',
+				3 => 'outofrangehi',
+				4 => 'alarmlo',
+				5 => 'alarmhi',
+			);
+			$sensor_tree_id = $enterprise.".4.1.3.1.8";
+		} else {
+			print "ERROR: Device not supported\n";
+			$session->close();
+			exit $states{UNKNOWN};
+		}
+		
+		# correct sensor ID 1 and 2
+		if ($opt_sensor == 1 || $opt_sensor == 2) {
+			$opt_sensor += 214;
+		}
+
+		# get the sensor ID
+		$response = $session->get_table($sensor_tree_id);
+		foreach my $sensor (keys %$response) {
+			if($response->{$sensor} eq $opt_sensor) {
+				$sensor =~ m/.?[\d\.]+(\d)$/;
+				$sensor_id = $1;
+			};
+		}
+
+		# check for numeric sensor id
+		if (!defined $sensor_id || $sensor_id !~ m/\d/ ) {
+			print "ERROR: Sensor ID not found\n";
+			$session->close();
+			exit $states{UNKNOWN};
+		}
+
+		# setting per device OIDs for sensor values
+		if ($device =~ m/Poseidon/i) {
+			push(@oids, $enterprise.'.3.3.3.1.2.'.$sensor_id);			# POSEIDON-MIB::sensName
+			push(@oids, $enterprise.'.3.3.3.1.4.'.$sensor_id);			# POSEIDON-MIB::sensState
+			push(@oids, $enterprise.'.3.3.3.1.5.'.$sensor_id);			# POSEIDON-MIB::sensString
+			push(@oids, $enterprise.'.3.3.3.1.6.'.$sensor_id);			# POSEIDON-MIB::sensValue
+			push(@oids, $enterprise.'.3.3.3.1.9.'.$sensor_id);			# POSEIDON-MIB::sensUnit
+			push(@oids, $enterprise.'.3.3.99.1.2.1.6.'.$sensor_id);		# POSEIDON-MIB::sensLimitMin
+			push(@oids, $enterprise.'.3.3.99.1.2.1.7.'.$sensor_id);		# POSEIDON-MIB::sensLimitMax
+		} elsif ($device =~ m/STE/i) {
+			push(@oids, $enterprise.'.4.1.3.1.2.'.$sensor_id);			# POSEIDON-MIB::sensName
+			push(@oids, $enterprise.'.4.1.3.1.3.'.$sensor_id);			# POSEIDON-MIB::sensState
+			push(@oids, $enterprise.'.4.1.3.1.4.'.$sensor_id);			# POSEIDON-MIB::sensString
+			push(@oids, $enterprise.'.4.1.3.1.5.'.$sensor_id);			# POSEIDON-MIB::sensValue
+		} else {
+			print "ERROR: device not supported";
+			$session->close();
+			exit $states{UNKNOWN};
+		}
+
+		# getting the sensor values from the device
+		$response = $session->get_request(-varbindlist => \@oids) 
+			or die "ERROR while getting Sensor values";
+		
+		$response->{$oids[0]} = 'temp';
+		# setting the output string
+		$output .= "Sensor: ".$response->{$oids[0]}.", ";
+		$output .= "State: ".$sensor_states{$response->{$oids[1]}}.", ";
+		$output .= "Value: ".$response->{$oids[2]};
+		$output .= "| $response->{$oids[0]}=".int(eval($response->{$oids[3]}/10)).";";
+
+		# append thresholds to perfdata if device is Poseidon
+		if ($device =~ m/Poseidon/i) {
+				$output .= eval($response->{$oids[5]}/10).";";
+				$output .= eval($response->{$oids[6]}/10).";";
+		}
+	}
+
+	# request for dry contact
+	if (defined $opt_contact) {
+
+		# Input states
+		my %alarm_states = (
+			0 => 'normal',
+			1 => 'alarm',
+		);
+		my %input_values = (
+			0 => 'off',
+			1 => 'on',
+		);
+		my %alarm_setup = (
+			0 => 'inactive',
+			1 => 'activeOff',
+			2 => 'activeOn',
+		);
+
+		# get the contact values
+		push(@oids, $enterprise.'.3.3.1.1.3.'.$opt_contact);			# POSEIDON-MIB::inpName
+		push(@oids, $enterprise.'.3.3.1.1.2.'.$opt_contact);			# POSEIDON-MIB::inpValue
+		push(@oids, $enterprise.'.3.3.1.1.4.'.$opt_contact);			# POSEIDON-MIB::inpAlarmSetup
+		push(@oids, $enterprise.'.3.3.1.1.5.'.$opt_contact);			# POSEIDON-MIB::inpAlarmState
+
+		# getting the values from the device
+		$response = $session->get_request(-varbindlist => \@oids) 
+                        or print "ERROR: Sensor ID not found\n";
+		exit $states{UNKNOWN} if !defined $response;
+
+		# setting the output string
+		$output .= "Input: ".$response->{$oids[0]}.", ";
+		$output .= "AlarmState: ".$alarm_states{$response->{$oids[3]}}.", ";
+		$output .= "AlarmSetup: ".$alarm_setup{$response->{$oids[2]}}.", ";
+		$output .= "Value: ".$input_values{$response->{$oids[1]}};
+	}
+
+	# finally close SNMP session
+	$session->close();
+
+	# print the gathered data
+	print $output."25;30;;;\n";
+
+	# setting exit states
+	if (defined $opt_sensor) {
+		if ( $device =~ m/Poseidon/i ) {
+			if ($response->{$oids[1]} == 3) {
+				exit $states{CRITICAL};
+			} elsif ($response->{$oids[1]} == 2) {
+				exit $states{WARNING};
+				} elsif ($response->{$oids[1]} == 0) {
+				exit $states{UNKNOWN};
+			} else {
+				exit $states{OK};
+			}
+		} elsif ($device =~ m/STE/i ) {
+			if ($response->{$oids[1]} > 1) {
+				exit $states{CRITICAL};
+			} elsif ($response->{$oids[1]} == 0) {
+				exit $states{UNKNOWN};
+			} else {
+				exit $states{OK};
+			}
+		}
+	}
+
+	# check for dry contacts
+	if (defined $opt_contact) {
+		if ($response->{$oids[3]} == 1) {
+			exit $states{CRITICAL};
+		} else {
+			exit $states{OK};
+		}
+	}
+}	
+
+# -------------------------
+# THE SUBS:
+# -------------------------
+
+
+# print_help($level, $msg);
+# prints some message and the POD DOC
+sub print_help {
+	my ( $level, $msg ) = @_;
+	$level = 0 unless ($level);
+	if($level == -1) {
+		print "$PROGNAME - Version: $VERSION\n";
+		exit ( $states{UNKNOWN});
+	}
+	pod2usage(
+		{
+			-noperldoc => 1,
+			-message => $msg,
+			-verbose => $level
+		}
+	);
+
+	exit( $states{UNKNOWN} );
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+check_hwg-ste.pl - Checks a hwgroup hwg-ste device for nagios
+
+=head1 SYNOPSIS
+
+check_hwg-ste.pl -h 
+
+check_hwg-ste.pl -H <host> -S <sensor id>
+
+=head1 DESCRIPTION
+
+Bcheck_hwg-ste.pl recieves the data from the hwgroup devices.
+
+=head1 OPTIONS
+
+=over 8
+
+=item B<-h>
+
+Display this helpmessage.
+
+=item B<-H>
+
+The hostname or ipaddress of the hwgroup device.
+
+=item B<-C>
+
+The snmp community of the hwgroup device.
+
+=item B<-S>
+
+The sensor to check (e.g. 1 or 2)
+
+=back
+
+=cut
+
+=head1 THRESHOLD FORMATS
+
+B<1.> start <= end
+
+Thresholds have to be specified from the lower level end on e.g. -w 20 is meaning that a
+warning error is occuring when the collected value is over 20.
+
+=head1 VERSION
+
+$Id: check_hwg-ste.pl 1558 2010-02-17 13:07:57Z mstreb $
+
+=head1 AUTHOR
+
+NETWAYS GmbH, 2010, http://www.netways.de.
+
+Written by Michael Streb <michael.streb@netways.de>, Bernd Löhlein <bernd.loehlein@netways.de>
+
+Please report bugs through the contact of monitoringexchange, http://www.monitoringexchange.org. 
+

+ 478 - 0
docs/nagios/scripts/plugins/check_ifoperstatus

@@ -0,0 +1,478 @@
+#!/usr/bin/perl
+#
+# check_ifoperstatus.pl - nagios plugin 
+#
+# Copyright (C) 2000 Christoph Kron,
+# Modified 5/2002 to conform to updated Nagios Plugin Guidelines
+# Added support for named interfaces per Valdimir Ivaschenko (S. Ghosh)
+# Added SNMPv3 support (10/2003)
+#
+# 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., 51 Franklin Street, Fifth Floor, Boston, 
+# MA 02110-1301, USA
+#
+# Report bugs to:  help@nagios-plugins.org
+#
+# 11.01.2000 Version 1.0
+#
+# Patches from Guy Van Den Bergh to warn on ifadminstatus down interfaces
+# instead of critical.
+#
+# Primary MIB reference - RFC 2863
+
+
+use POSIX;
+use strict;
+use FindBin;
+use lib "$FindBin::Bin";
+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_ifoperstatus";
+sub print_help ();
+sub usage ($);
+sub print_usage ();
+sub process_arguments ();
+
+$ENV{'PATH'}='/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin';
+$ENV{'BASH_ENV'}=''; 
+$ENV{'ENV'}='';
+
+my $timeout;
+my $status;
+my %ifOperStatus = 	('1','up',
+                     '2','down',
+                     '3','testing',
+                     '4','unknown',
+                     '5','dormant',
+                     '6','notPresent',
+                     '7','lowerLayerDown');  # down due to the state of lower layer interface(s)
+
+my $state = "UNKNOWN";
+my $answer = "";
+my $snmpkey = 0;
+my $community = "public";
+my $maxmsgsize = 1472 ; # Net::SNMP default is 1472
+my ($seclevel, $authproto, $secname, $authpass, $privpass, $privproto, $auth, $priv, $context);
+my $port = 161;
+my @snmpoids;
+my $sysUptime        = '1.3.6.1.2.1.1.3.0';
+my $snmpIfDescr      = '1.3.6.1.2.1.2.2.1.2';
+my $snmpIfType       = '1.3.6.1.2.1.2.2.1.3';
+my $snmpIfAdminStatus = '1.3.6.1.2.1.2.2.1.7';
+my $snmpIfOperStatus = '1.3.6.1.2.1.2.2.1.8';
+my $snmpIfName       = '1.3.6.1.2.1.31.1.1.1.1';
+my $snmpIfLastChange = '1.3.6.1.2.1.2.2.1.9';
+my $snmpIfAlias      = '1.3.6.1.2.1.31.1.1.1.18';
+my $snmpLocIfDescr   = '1.3.6.1.4.1.9.2.2.1.1.28';
+my $hostname;
+my $ifName;
+my $session;
+my $error;
+my $response;
+my $snmp_version = 1 ;
+my $ifXTable;
+my $opt_h ;
+my $opt_V ;
+my $ifdescr;
+my $iftype;
+my $key;
+my $lastc;
+my $dormantWarn;
+my $adminWarn;
+my $name;
+my %session_opts;
+
+### Validate Arguments
+
+$status = process_arguments();
+
+
+# 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);
+
+($session, $error) = Net::SNMP->session(%session_opts);
+
+		
+if (!defined($session)) {
+			$state='UNKNOWN';
+			$answer=$error;
+			print ("$state: $answer\n");
+			exit $ERRORS{$state};
+}
+
+## map ifdescr to ifindex - should look at being able to cache this value
+
+if (defined $ifdescr || defined $iftype) {
+	# escape "/" in ifdescr - very common in the Cisco world
+	if (defined $iftype) {
+		$status=fetch_ifindex($snmpIfType, $iftype);
+	} else {
+		$ifdescr =~ s/\//\\\//g;
+		$status=fetch_ifindex($snmpIfDescr, $ifdescr);  # if using on device with large number of interfaces
+		                                                # recommend use of SNMP v2 (get-bulk)
+	}
+	if ($status==0) {
+		$state = "UNKNOWN";
+		printf "$state: could not retrive ifdescr/iftype snmpkey - $status-$snmpkey\n";
+		$session->close;
+		exit $ERRORS{$state};
+	}
+}
+
+
+## Main function
+
+$snmpIfAdminStatus = $snmpIfAdminStatus . "." . $snmpkey;
+$snmpIfOperStatus = $snmpIfOperStatus . "." . $snmpkey;
+$snmpIfDescr = $snmpIfDescr . "." . $snmpkey;
+$snmpIfName	= $snmpIfName . "." . $snmpkey ;
+$snmpIfAlias = $snmpIfAlias . "." . $snmpkey ; 
+
+push(@snmpoids,$snmpIfAdminStatus);
+push(@snmpoids,$snmpIfOperStatus);
+push(@snmpoids,$snmpIfDescr);
+push(@snmpoids,$snmpIfName) if (defined $ifXTable) ;
+push(@snmpoids,$snmpIfAlias) if (defined $ifXTable) ;
+
+if (!defined($response = $session->get_request(@snmpoids))) {
+	$answer=$session->error;
+	$session->close;
+	$state = 'WARNING';
+	print ("$state: SNMP error: $answer\n");
+	exit $ERRORS{$state};
+}
+
+$answer = sprintf("host '%s', %s(%s) is %s\n", 
+	$hostname, 
+	$response->{$snmpIfDescr},
+	$snmpkey, 
+	$ifOperStatus{$response->{$snmpIfOperStatus}}
+);
+
+
+## Check to see if ifName match is requested and it matches - exit if no match
+## not the interface we want to monitor
+if ( defined $ifName && not ($response->{$snmpIfName} eq $ifName) ) {
+	$state = 'UNKNOWN';
+	$answer = "Interface name ($ifName) doesn't match snmp value ($response->{$snmpIfName}) (index $snmpkey)";
+	print ("$state: $answer\n");
+	exit $ERRORS{$state};
+} 
+
+## define the interface name
+if (defined $ifXTable) {
+	 $name = $response->{$snmpIfName} ." - " .$response->{$snmpIfAlias} ; 
+}else{
+	 $name = $response->{$snmpIfDescr} ;
+}
+
+## if AdminStatus is down - some one made a consious effort to change config
+##
+if ( not ($response->{$snmpIfAdminStatus} == 1) ) {
+	$answer = "Interface $name (index $snmpkey) is administratively down.";
+	if ( not defined $adminWarn or $adminWarn eq "w" ) {
+		$state = 'WARNING';
+	} elsif ( $adminWarn eq "i" ) {
+		$state = 'OK';
+	} elsif ( $adminWarn eq "c" ) {
+		$state = 'CRITICAL';
+	} else { # If wrong value for -a, say warning
+		$state = 'WARNING';
+	}
+} 
+## Check operational status
+elsif ( $response->{$snmpIfOperStatus} == 2 ) {
+	$state = 'CRITICAL';
+	$answer = "Interface $name (index $snmpkey) is down.";
+} elsif ( $response->{$snmpIfOperStatus} == 5 ) {
+	if (defined $dormantWarn ) {
+		if ($dormantWarn eq "w") {
+			$state = 'WARNING';
+			$answer = "Interface $name (index $snmpkey) is dormant.";
+		}elsif($dormantWarn eq "c") {
+			$state = 'CRITICAL';
+			$answer = "Interface $name (index $snmpkey) is dormant.";
+		}elsif($dormantWarn eq "i") {
+			$state = 'OK';
+			$answer = "Interface $name (index $snmpkey) is dormant.";
+		}
+	}else{
+		# dormant interface - but warning/critical/ignore not requested
+		$state = 'CRITICAL';
+		$answer = "Interface $name (index $snmpkey) is dormant.";
+	}
+} elsif ( $response->{$snmpIfOperStatus} == 6 ) {
+	$state = 'CRITICAL';
+	$answer = "Interface $name (index $snmpkey) notPresent - possible hotswap in progress.";
+} elsif ( $response->{$snmpIfOperStatus} == 7 ) {
+	$state = 'CRITICAL';
+	$answer = "Interface $name (index $snmpkey) down due to lower layer being down.";
+} elsif ( $response->{$snmpIfOperStatus} == 3 || $response->{$snmpIfOperStatus} == 4  ) {
+	$state = 'CRITICAL';
+	$answer = "Interface $name (index $snmpkey) down (testing/unknown).";
+} else {
+	$state = 'OK';
+	$answer = "Interface $name (index $snmpkey) is up.";
+}
+
+
+
+print ("$state: $answer\n");
+exit $ERRORS{$state};
+
+
+### subroutines
+
+sub fetch_ifindex {
+	my $oid = shift;
+	my $lookup = shift;
+
+	if (!defined ($response = $session->get_table($oid))) {
+		$answer=$session->error;
+		$session->close;
+		$state = 'CRITICAL';
+		printf ("$state: SNMP error with snmp version $snmp_version ($answer)\n");
+		$session->close;
+		exit $ERRORS{$state};
+	}
+	
+	foreach $key ( keys %{$response}) {
+		if ($response->{$key} =~ /^$lookup$/) {
+			$key =~ /.*\.(\d+)$/;
+			$snmpkey = $1;
+			#print "$lookup = $key / $snmpkey \n";  #debug
+		}
+	}
+	unless (defined $snmpkey) {
+		$session->close;
+		$state = 'CRITICAL';
+		printf "$state: Could not match $ifdescr on $hostname\n";
+		exit $ERRORS{$state};
+	}
+	
+	return $snmpkey;
+}
+
+sub usage($) {
+	print "$_[0]\n";
+	print_usage();
+	exit $ERRORS{"UNKNOWN"};
+}
+
+sub print_usage() {
+	printf "\n";
+	printf "usage: \n";
+	printf "check_ifoperstatus -k <IF_KEY> -H <HOSTNAME> [-C <community>]\n";
+	printf "Copyright (C) 2000 Christoph Kron\n";
+	printf "check_ifoperstatus.pl comes with ABSOLUTELY NO WARRANTY\n";
+	printf "This programm is licensed under the terms of the ";
+	printf "GNU General Public License\n(check source code for details)\n";
+	printf "\n\n";
+}
+
+sub print_help() {
+	print_revision($PROGNAME, '2.2.1');
+	print_usage();
+	printf "check_ifoperstatus plugin for Nagios monitors operational \n";
+	printf "status of a particular network interface on the target host\n";
+	printf "\nUsage:\n";
+	printf "   -H (--hostname)   Hostname to query - (required)\n";
+	printf "   -C (--community)  SNMP read community (defaults to public,\n";
+	printf "                     used with SNMP v1 and v2c\n";
+	printf "   -v (--snmp_version)  1 for SNMP v1 (default)\n";
+	printf "                        2 for SNMP v2c\n";
+	printf "                        SNMP v2c will use get_bulk for less overhead\n";
+	printf "                        if monitoring with -d\n";
+	printf "   -L (--seclevel)   choice of \"noAuthNoPriv\", \"authNoPriv\", or	\"authPriv\"\n";
+	printf "   -U (--secname)    username for SNMPv3 context\n";
+	printf "   -c (--context)    SNMPv3 context name (default is empty string)\n";
+	printf "   -A (--authpass)   authentication password (cleartext ascii or localized key\n";
+	printf "                     in hex with 0x prefix generated by using \"snmpkey\" utility\n"; 
+	printf "                     auth password and authEngineID\n";
+	printf "   -a (--authproto)  Authentication protocol (MD5 or SHA1)\n";
+	printf "   -X (--privpass)   privacy password (cleartext ascii or localized key\n";
+	printf "                     in hex with 0x prefix generated by using \"snmpkey\" utility\n"; 
+	printf "                     privacy password and authEngineID\n";
+	printf "   -P (--privproto)  privacy protocol (DES or AES; default: DES)\n";
+	printf "   -k (--key)        SNMP IfIndex value\n";
+	printf "   -d (--descr)      SNMP ifDescr value\n";
+	printf "   -T (--type)       SNMP ifType integer value (see http://www.iana.org/assignments/ianaiftype-mib)\n";
+	printf "   -p (--port)       SNMP port (default 161)\n";
+	printf "   -I (--ifmib)      Agent supports IFMIB ifXTable. Do not use if\n";
+	printf "                     you don't know what this is. \n";
+	printf "   -n (--name)       the value should match the returned ifName\n";
+	printf "                     (Implies the use of -I)\n";
+	printf "   -w (--warn =i|w|c) ignore|warn|crit if the interface is dormant (default critical)\n";
+	printf "   -D (--admin-down =i|w|c) same for administratively down interfaces (default warning)\n";
+	printf "   -M (--maxmsgsize) Max message size - usefull only for v1 or v2c\n";
+	printf "   -t (--timeout)    seconds before the plugin times out (default=$TIMEOUT)\n";
+	printf "   -V (--version)    Plugin version\n";
+	printf "   -h (--help)       usage help \n\n";
+	printf " -k or -d or -T must be specified\n\n";
+	printf "Note: either -k or -d or -T must be specified and -d and -T are much more network \n";
+	printf "intensive.  Use it sparingly or not at all.  -n is used to match against\n";
+	printf "a much more descriptive ifName value in the IfXTable to verify that the\n";
+	printf "snmpkey has not changed to some other network interface after a reboot.\n\n";
+	
+}
+
+sub process_arguments() {
+	$status = GetOptions(
+			"V"   => \$opt_V, "version"    => \$opt_V,
+			"h"   => \$opt_h, "help"       => \$opt_h,
+			"v=i" => \$snmp_version, "snmp_version=i"  => \$snmp_version,
+			"C=s" => \$community, "community=s" => \$community,
+			"L=s" => \$seclevel, "seclevel=s" => \$seclevel,
+			"a=s" => \$authproto, "authproto=s" => \$authproto,
+			"U=s" => \$secname,   "secname=s"   => \$secname,
+			"A=s" => \$authpass,  "authpass=s"  => \$authpass,
+			"X=s" => \$privpass,  "privpass=s"  => \$privpass,
+			"P=s" => \$privproto,  "privproto=s"  => \$privproto,
+			"c=s" => \$context,   "context=s"   => \$context,
+			"k=i" => \$snmpkey, "key=i",\$snmpkey,
+			"d=s" => \$ifdescr, "descr=s" => \$ifdescr,
+			"l=s" => \$lastc,  "lastchange=s" => \$lastc,
+			"p=i" => \$port,  "port=i" =>\$port,
+			"H=s" => \$hostname, "hostname=s" => \$hostname,
+			"I"   => \$ifXTable, "ifmib" => \$ifXTable,
+			"n=s" => \$ifName, "name=s" => \$ifName,
+			"w=s" => \$dormantWarn, "warn=s" => \$dormantWarn,
+			"D=s" => \$adminWarn, "admin-down=s" => \$adminWarn,
+			"M=i" => \$maxmsgsize, "maxmsgsize=i" => \$maxmsgsize,
+			"t=i" => \$timeout,    "timeout=i" => \$timeout,
+			"T=i" => \$iftype,    "type=i" => \$iftype,
+			);
+
+
+	if ($status == 0){
+		print_help();
+		exit $ERRORS{'OK'};
+	}
+
+	if ($opt_V) {
+		print_revision($PROGNAME,'2.2.1');
+		exit $ERRORS{'OK'};
+	}
+
+	if ($opt_h) {
+		print_help();
+		exit $ERRORS{'OK'};
+	}
+
+	if (! utils::is_hostname($hostname)){
+		usage("Hostname invalid or not given");
+	}
+
+	unless ($snmpkey > 0 || defined $ifdescr || defined $iftype){
+		usage("Either a valid snmp key (-k) or a ifDescr (-d) must be provided");
+	}
+
+	if (defined $ifName) {
+		$ifXTable=1;
+	}	
+
+	if (defined $dormantWarn) {
+		unless ($dormantWarn =~ /^(w|c|i)$/ ) {
+			printf "Dormant alerts must be one of w|c|i \n";
+			exit $ERRORS{'UNKNOWN'};
+		}
+	}
+	
+	unless (defined $timeout) {
+		$timeout = $TIMEOUT;
+	}
+
+	if ($snmp_version !~ /[123]/){
+		$state='UNKNOWN';
+		print ("$state: No support for SNMP v$snmp_version yet\n");
+		exit $ERRORS{$state};
+	}
+
+	%session_opts = (
+		-hostname   => $hostname,
+		-port       => $port,
+		-version    => $snmp_version,
+		-maxmsgsize => $maxmsgsize
+	);
+
+	$session_opts{'-community'} = $community if (defined $community && $snmp_version =~ /[12]/);
+
+	if ($snmp_version =~ /3/ ) {
+		# Must define a security level even though default is noAuthNoPriv
+		# v3 requires a security username
+		if (defined $seclevel && defined $secname) {
+			$session_opts{'-username'} = $secname;
+		
+			# Must define a security level even though defualt is noAuthNoPriv
+			unless ( grep /^$seclevel$/, qw(noAuthNoPriv authNoPriv authPriv) ) {
+				usage("Must define a valid security level even though default is noAuthNoPriv");
+			}
+			
+			# Authentication wanted
+			if ( $seclevel eq 'authNoPriv' || $seclevel eq 'authPriv' ) {
+				if (defined $authproto && $authproto ne 'MD5' && $authproto !~ /sha/i) {
+					usage("Auth protocol can be either MD5 or SHA1");
+				}
+				$session_opts{'-authprotocol'} = $authproto if(defined $authproto);
+
+				if ( !defined $authpass) {
+					usage("Auth password/key is not defined");
+				}else{
+					if ($authpass =~ /^0x/ ) {
+						$session_opts{'-authkey'} = $authpass ;
+					}else{
+						$session_opts{'-authpassword'} = $authpass ;
+					}
+				}
+			}
+			
+			# Privacy (DES encryption) wanted
+			if ($seclevel eq 'authPriv' ) {
+				if (! defined $privpass) {
+					usage("Privacy passphrase/key is not defined");
+				}else{
+					if ($privpass =~ /^0x/){
+						$session_opts{'-privkey'} = $privpass;
+					}else{
+						$session_opts{'-privpassword'} = $privpass;
+					}
+				}
+
+				$session_opts{'-privprotocol'} = $privproto if(defined $privproto);
+			}
+
+			# Context name defined or default
+			unless ( defined $context) {
+				$context = "";
+			}
+		
+		}else {
+			usage("Security level or name is not defined");
+		}
+	} # end snmpv3
+
+
+}
+## End validation
+

+ 449 - 0
docs/nagios/scripts/plugins/check_ifstatus

@@ -0,0 +1,449 @@
+#!/usr/bin/perl
+#
+# check_ifstatus.pl - nagios plugin 
+# 
+#
+# Copyright (C) 2000 Christoph Kron
+# Modified 5/2002 to conform to updated Nagios Plugin Guidelines (S. Ghosh)
+#  Added -x option (4/2003)
+#  Added -u option (4/2003)
+#  Added -M option (10/2003)
+#  Added SNMPv3 support (10/2003)
+#  Added -n option (07/2014)
+#
+# 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., 51 Franklin Street, Fifth Floor, Boston, 
+# MA 02110-1301, USA
+#
+# Report bugs to: ck@zet.net, nagiosplug-help@lists.sf.net
+# 
+# 11.01.2000 Version 1.0
+#
+
+use POSIX;
+use strict;
+use FindBin;
+use lib "$FindBin::Bin";
+use lib '/usr/lib/nagios/plugins';
+use utils qw($TIMEOUT %ERRORS &print_revision &support);
+
+use Net::SNMP;
+use Getopt::Long;
+Getopt::Long::Configure('bundling');
+
+my $PROGNAME = "check_ifstatus";
+
+sub print_help ();
+sub usage ($);
+sub print_usage ();
+sub process_arguments ();
+
+$ENV{'PATH'}='/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin';
+$ENV{'BASH_ENV'}=''; 
+$ENV{'ENV'}='';
+
+my $status;
+my %ifOperStatus =	('1','up',
+			 '2','down',
+			 '3','testing',
+			 '4','unknown',
+			 '5','dormant',
+			 '6','notPresent',
+			 '7','lowerLayerDown');  # down due to the state of lower layer interface(s));
+
+my $timeout ;
+my $state = "UNKNOWN";
+my $answer = "";
+my $snmpkey=0;
+my $snmpoid=0;
+my $key=0;
+my $community = "public";
+my $maxmsgsize = 1472 ; # Net::SNMP default is 1472
+my ($seclevel, $authproto, $secname, $authpass, $privpass, $privproto, $auth, $priv, $context);
+my $port = 161;
+my @snmpoids;
+my $snmpIfAdminStatus = '1.3.6.1.2.1.2.2.1.7';
+my $snmpIfDescr = '1.3.6.1.2.1.2.2.1.2';
+my $snmpIfOperStatus = '1.3.6.1.2.1.2.2.1.8';
+my $snmpIfName = '1.3.6.1.2.1.31.1.1.1.1';
+my $snmpIfAlias = '1.3.6.1.2.1.31.1.1.1.18';
+my $snmpLocIfDescr = '1.3.6.1.4.1.9.2.2.1.1.28';
+my $snmpIfType = '1.3.6.1.2.1.2.2.1.3';
+my $hostname;
+my $session;
+my $error;
+my $response;
+my %ifStatus;
+my $ifup =0 ;
+my $ifdown =0;
+my $ifdormant = 0;
+my $ifexclude = 0 ;
+my $ifunused = 0;
+my $ifmessage = "";
+my $snmp_version = 1;
+my $ifXTable;
+my $opt_h ;
+my $opt_V ;
+my $opt_u;
+my $opt_n;
+my $opt_x ;
+my %excluded ;
+my %unused_names ;
+my @unused_ports ;
+my %session_opts;
+
+
+
+
+
+# Just in case of problems, let's not hang Nagios
+$SIG{'ALRM'} = sub {
+     print ("ERROR: No snmp response from $hostname (alarm timeout)\n");
+     exit $ERRORS{"UNKNOWN"};
+};
+
+
+#Option checking
+$status = process_arguments();
+
+if ($status != 0)
+{
+	print_help() ;
+	exit $ERRORS{'OK'};
+}
+
+
+alarm($timeout);
+($session, $error) = Net::SNMP->session(%session_opts);
+		
+if (!defined($session)) {
+			$state='UNKNOWN';
+			$answer=$error;
+			print ("$state: $answer\n");
+			exit $ERRORS{$state};
+}
+
+
+push(@snmpoids,$snmpIfOperStatus);
+push(@snmpoids,$snmpIfAdminStatus);
+push(@snmpoids,$snmpIfDescr);
+push(@snmpoids,$snmpIfType);
+push(@snmpoids,$snmpIfName) if ( defined $ifXTable);
+push(@snmpoids,$snmpIfAlias) if ( defined $ifXTable);
+
+
+
+
+foreach $snmpoid (@snmpoids) {
+
+   if (!defined($response = $session->get_table($snmpoid))) {
+      $answer=$session->error;
+      $session->close;
+      $state = 'CRITICAL';
+			if ( ( $snmpoid =~ $snmpIfName ) && defined $ifXTable ) {
+				print ("$state: Device does not support ifTable - try without -I option\n");
+			}else{
+				print ("$state: $answer for $snmpoid  with snmp version $snmp_version\n");
+			}
+      exit $ERRORS{$state};
+   }
+
+   foreach $snmpkey (keys %{$response}) {
+      $snmpkey =~ /.*\.(\d+)$/;
+      $key = $1;
+      $ifStatus{$key}{$snmpoid} = $response->{$snmpkey};
+   }
+}
+
+
+$session->close;
+
+alarm(0);
+
+foreach $key (keys %ifStatus) {
+
+	# skip unused interfaces
+	my $ifName = $ifStatus{$key}{$snmpIfDescr};
+
+	if (!defined($ifStatus{$key}{'notInUse'}) && !grep(/^${ifName}/, @unused_ports )) {
+		# check only if interface is administratively up
+		if ($ifStatus{$key}{$snmpIfAdminStatus} == 1 ) {
+			#check only if interface is not excluded
+			if (!defined $unused_names{$ifStatus{$key}{$snmpIfDescr}} ) {
+				# check only if interface type is not listed in %excluded
+				if (!defined $excluded{$ifStatus{$key}{$snmpIfType}} ) {
+					if ($ifStatus{$key}{$snmpIfOperStatus} == 1 ) { $ifup++ ; }
+					if ($ifStatus{$key}{$snmpIfOperStatus} == 2 ) {
+									$ifdown++ ;
+									if (defined $ifXTable) {
+										$ifmessage .= sprintf("%s: down -> %s<BR>\n", $ifStatus{$key}{$snmpIfName}, $ifStatus{$key}{$snmpIfAlias});
+									}else{
+										$ifmessage .= sprintf("%s: down <BR>\n",$ifStatus{$key}{$snmpIfDescr});
+									}
+					}
+					if ($ifStatus{$key}{$snmpIfOperStatus} == 5 ) { $ifdormant++ ;}
+				} else {
+					$ifexclude++;
+				}
+			} else {
+				$ifunused++;
+			}
+		
+		}
+	}else{
+		$ifunused++;
+	}
+}
+
+   if ($ifdown > 0) {
+      $state = 'CRITICAL';
+      $answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d, excluded: %d, unused: %d<BR>",
+                        $hostname,
+			$ifup,
+			$ifdown,
+			$ifdormant,
+			$ifexclude,
+			$ifunused);
+      $answer = $answer . $ifmessage . "\n";
+   }
+   else {
+      $state = 'OK';
+      $answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d, excluded: %d, unused: %d",
+                        $hostname,
+			$ifup,
+			$ifdown,
+			$ifdormant,
+			$ifexclude,
+			$ifunused);
+   }
+my $perfdata = sprintf("up=%d down=%d dormant=%d excluded=%d unused=%d",$ifup,$ifdown,$ifdormant,$ifexclude,$ifunused);
+print ("$state: $answer |$perfdata\n");
+exit $ERRORS{$state};
+
+sub usage($) {
+	print "$_[0]\n";
+	print_usage();
+	exit $ERRORS{"UNKNOWN"};
+}
+
+sub print_usage() {
+	printf "\n";
+	printf "usage: \n";
+	printf "check_ifstatus -C <READCOMMUNITY> -p <PORT> -H <HOSTNAME>\n";
+	printf "Copyright (C) 2000 Christoph Kron\n";
+	printf "Updates 5/2002 Subhendu Ghosh\n";
+	support();
+	printf "\n\n";
+}
+
+sub print_help() {
+	print_revision($PROGNAME, '2.2.1');
+	print_usage();
+	printf "check_ifstatus plugin for Nagios monitors operational \n";
+	printf "status of each network interface on the target host\n";
+	printf "\nUsage:\n";
+	printf "   -H (--hostname)   Hostname to query - (required)\n";
+	printf "   -C (--community)  SNMP read community (defaults to public,\n";
+	printf "                     used with SNMP v1 and v2c\n";
+	printf "   -v (--snmp_version)  1 for SNMP v1 (default)\n";
+	printf "                        2 for SNMP v2c\n";
+	printf "                          SNMP v2c will use get_bulk for less overhead\n";
+	printf "                        3 for SNMPv3 (requires -U option)";
+	printf "   -p (--port)       SNMP port (default 161)\n";
+	printf "   -I (--ifmib)      Agent supports IFMIB ifXTable.  For Cisco - this will provide\n";
+	printf "                     the descriptive name.  Do not use if you don't know what this is. \n";
+	printf "   -x (--exclude)    A comma separated list of ifType values that should be excluded \n";
+	printf "                     from the report (default for an empty list is PPP(23).\n";
+	printf "   -n (--unused_ports_by_name) A comma separated list of ifDescr values that should be excluded \n";
+	printf "                     from the report (default is an empty exclusion list).\n";
+	printf "   -u (--unused_ports) A comma separated list of ifIndex values that should be excluded \n";
+	printf "                     from the report (default is an empty exclusion list).\n";
+	printf "                     See the IANAifType-MIB for a list of interface types.\n";
+	printf "   -L (--seclevel)   choice of \"noAuthNoPriv\", \"authNoPriv\", or	\"authPriv\"\n";
+	printf "   -U (--secname)    username for SNMPv3 context\n";
+	printf "   -c (--context)    SNMPv3 context name (default is empty string)\n";
+	printf "   -A (--authpass)   authentication password (cleartext ascii or localized key\n";
+	printf "                     in hex with 0x prefix generated by using \"snmpkey\" utility\n"; 
+	printf "                     auth password and authEngineID\n";
+	printf "   -a (--authproto)  Authentication protocol (MD5 or SHA1)\n";
+	printf "   -X (--privpass)   privacy password (cleartext ascii or localized key\n";
+	printf "                     in hex with 0x prefix generated by using \"snmpkey\" utility\n"; 
+	printf "                     privacy password and authEngineID\n";
+	printf "   -P (--privproto)  privacy protocol (DES or AES; default: DES)\n";
+	printf "   -M (--maxmsgsize) Max message size - usefull only for v1 or v2c\n";
+	printf "   -t (--timeout)    seconds before the plugin times out (default=$TIMEOUT)\n";
+	printf "   -V (--version)    Plugin version\n";
+	printf "   -h (--help)       usage help \n\n";
+	print_revision($PROGNAME, '2.2.1');
+	
+}
+
+sub process_arguments() {
+	$status = GetOptions(
+		"V"   => \$opt_V, "version"    => \$opt_V,
+		"h"   => \$opt_h, "help"       => \$opt_h,
+		"v=s" => \$snmp_version, "snmp_version=s"  => \$snmp_version,
+		"C=s" => \$community,"community=s" => \$community,
+		"L=s" => \$seclevel, "seclevel=s" => \$seclevel,
+		"a=s" => \$authproto, "authproto=s" => \$authproto,
+		"U=s" => \$secname,   "secname=s"   => \$secname,
+		"A=s" => \$authpass,  "authpass=s"  => \$authpass,
+		"X=s" => \$privpass,  "privpass=s"  => \$privpass,
+		"P=s" => \$privproto,  "privproto=s"  => \$privproto,
+		"c=s" => \$context,   "context=s"   => \$context,
+		"p=i" =>\$port, "port=i" => \$port,
+		"H=s" => \$hostname, "hostname=s" => \$hostname,
+		"I"		=> \$ifXTable, "ifmib" => \$ifXTable,
+		"x:s"		=>	\$opt_x,   "exclude:s" => \$opt_x,
+		"u=s" => \$opt_u,  "unused_ports=s" => \$opt_u,
+		"n=s" => \$opt_n, "unused_ports_by_name=s" => \$opt_n,
+		"M=i" => \$maxmsgsize, "maxmsgsize=i" => \$maxmsgsize,
+		"t=i" => \$timeout,    "timeout=i" => \$timeout,
+		);
+		
+	if ($status == 0){
+		print_help();
+		exit $ERRORS{'OK'};
+	}
+
+	if ($opt_V) {
+		print_revision($PROGNAME,'2.2.1');
+		exit $ERRORS{'OK'};
+	}
+
+	if ($opt_h) {
+		print_help();
+		exit $ERRORS{'OK'};
+	}
+
+	unless (defined $timeout) {
+		$timeout = $TIMEOUT;
+	}
+
+	# Net::SNMP wants an integer
+	$snmp_version = 2 if $snmp_version eq "2c";
+
+	if ($snmp_version !~ /^[123]$/){
+		$state='UNKNOWN';
+		print ("$state: No support for SNMP v$snmp_version yet\n");
+		exit $ERRORS{$state};
+	}
+
+	%session_opts = (
+		-hostname   => $hostname,
+		-port       => $port,
+		-version    => $snmp_version,
+		-maxmsgsize => $maxmsgsize
+	);
+
+	$session_opts{'-community'} = $community if (defined $community && $snmp_version =~ /[12]/);
+
+	if ($snmp_version =~ /3/ ) {
+		# Must define a security level even though default is noAuthNoPriv
+		# v3 requires a security username
+		if (defined $seclevel && defined $secname) {
+			$session_opts{'-username'} = $secname;
+		
+			# Must define a security level even though defualt is noAuthNoPriv
+			unless ( grep /^$seclevel$/, qw(noAuthNoPriv authNoPriv authPriv) ) {
+				usage("Must define a valid security level even though default is noAuthNoPriv");
+			}
+			
+			# Authentication wanted
+			if ( $seclevel eq 'authNoPriv' || $seclevel eq 'authPriv' ) {
+				if (defined $authproto && $authproto ne 'MD5' && $authproto ne 'SHA1') {
+					usage("Auth protocol can be either MD5 or SHA1");
+				}
+				$session_opts{'-authprotocol'} = $authproto if(defined $authproto);
+
+				if ( !defined $authpass) {
+					usage("Auth password/key is not defined");
+				}else{
+					if ($authpass =~ /^0x/ ) {
+						$session_opts{'-authkey'} = $authpass ;
+					}else{
+						$session_opts{'-authpassword'} = $authpass ;
+					}
+				}
+			}
+			
+			# Privacy (DES encryption) wanted
+			if ($seclevel eq 'authPriv' ) {
+				if (! defined $privpass) {
+					usage("Privacy passphrase/key is not defined");
+				}else{
+					if ($privpass =~ /^0x/){
+						$session_opts{'-privkey'} = $privpass;
+					}else{
+						$session_opts{'-privpassword'} = $privpass;
+					}
+				}
+
+				$session_opts{'-privprotocol'} = $privproto if(defined $privproto);
+			}
+
+			# Context name defined or default
+			unless ( defined $context) {
+				$context = "";
+			}
+		
+		}else {
+			usage("Security level or name is not defined");
+		}
+	} # end snmpv3
+
+	# Excluded interfaces types (ifType) (backup interfaces, dial-on demand interfaces, PPP interfaces
+	if (defined $opt_x) {
+		my @x = split(/,/, $opt_x);
+		if ( @x) {
+			foreach $key (@x){
+				$excluded{$key} = 1;
+			}
+		}else{
+			$excluded{23} = 1; # default PPP(23) if empty list - note (AIX seems to think PPP is 22 according to a post)
+		}
+	}
+	
+	# Excluded interface descriptors
+	if (defined $opt_n) {
+		my @unused = split(/,/,$opt_n);
+		if ( @unused ) {
+			foreach $key (@unused) {
+				$unused_names{$key} = 1;
+			}
+		}
+	}
+
+	# Excluded interface ports (ifIndex) - management reasons
+	if ($opt_u) {
+		@unused_ports = split(/,/,$opt_u);
+		foreach $key (@unused_ports) { 
+			$ifStatus{$key}{'notInUse'}++ ;
+		}
+	}
+
+	if (! utils::is_hostname($hostname)){
+		usage("Hostname invalid or not given");
+		exit $ERRORS{"UNKNOWN"};
+	}
+
+		
+	if ($snmp_version !~ /[123]/) {
+		$state='UNKNOWN';
+		print ("$state: No support for SNMP v$snmp_version yet\n");
+		exit $ERRORS{$state};
+	}
+
+return $ERRORS{"OK"};
+}

+ 580 - 0
docs/nagios/scripts/plugins/check_linux_bonding

@@ -0,0 +1,580 @@
+#!/usr/bin/perl
+#
+# DESCRIPTION: Nagios plugin for checking the status of bonded network
+#              interfaces (masters and slaves) on Linux servers.
+#
+# AUTHOR: Trond H. Amundsen <t.h.amundsen@usit.uio.no>
+#
+# Copyright (C) 2009-2014 Trond H. Amundsen
+#
+# 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 3 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, see <http://www.gnu.org/licenses/>.
+#
+
+use strict;
+use warnings;
+use POSIX qw(isatty);
+use Getopt::Long qw(:config no_ignore_case);
+
+# Global (package) variables used throughout the code
+use vars qw( $NAME $VERSION $AUTHOR $CONTACT $E_OK $E_WARNING $E_CRITICAL
+	     $E_UNKNOWN $USAGE $HELP $LICENSE $linebreak $counter $exit_code
+	     %opt %reverse_exitcode %text2exit %bonding %nagios_level_count
+	     @perl_warnings @reports @blacklist @ok_reports
+	  );
+#---------------------------------------------------------------------
+# Initialization and global variables
+#---------------------------------------------------------------------
+
+# Collect perl warnings in an array
+$SIG{__WARN__} = sub { push @perl_warnings, [@_]; };
+
+# Version and similar info
+$NAME    = 'check_linux_bonding';
+$VERSION = '1.4';
+$AUTHOR  = 'Trond H. Amundsen';
+$CONTACT = 't.h.amundsen@usit.uio.no';
+
+# Exit codes
+$E_OK       = 0;
+$E_WARNING  = 1;
+$E_CRITICAL = 2;
+$E_UNKNOWN  = 3;
+
+# Nagios error levels reversed
+%reverse_exitcode
+  = (
+     0 => 'OK',
+     1 => 'WARNING',
+     2 => 'CRITICAL',
+     3 => 'UNKNOWN',
+    );
+
+# Usage text
+$USAGE = <<"END_USAGE";
+Usage: $NAME [OPTION]...
+END_USAGE
+
+# Help text
+$HELP = <<'END_HELP';
+
+OPTIONS:
+
+   -t, --timeout       Plugin timeout in seconds [5]
+   -s, --state         Prefix alerts with alert state
+   -S, --short-state   Prefix alerts with alert state abbreviated
+   -n, --no-bonding    Alert level if no bonding interfaces found [ok]
+   --slave-down        Alert level if a slave is down [warning]
+   --disable-sysfs     Don't use sysfs (default), use procfs
+   --ignore-num-ad     (IEEE 802.3ad) Don't warn if num_ad_ports != num_slaves
+   -b, --blacklist     Blacklist failed interfaces
+   -v, --verbose       Debug/Verbose output, reports everything
+   -h, --help          Display this help text
+   -V, --version       Display version info
+
+For more information and advanced options, see the manual page or URL:
+  http://folk.uio.no/trondham/software/check_linux_bonding.html
+END_HELP
+
+# Version and license text
+$LICENSE = <<"END_LICENSE";
+$NAME $VERSION
+Copyright (C) 2009-2014 $AUTHOR
+License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
+This is free software: you are free to change and redistribute it.
+There is NO WARRANTY, to the extent permitted by law.
+
+Written by $AUTHOR <$CONTACT>
+END_LICENSE
+
+# Options with default values
+%opt
+  = ( 'timeout'       => 5,  # default timeout is 5 seconds
+      'help'          => 0,
+      'version'       => 0,
+      'blacklist'     => [],
+      'no_bonding'    => 'ok',
+      'state'         => 0,
+      'shortstate'    => 0,
+      'linebreak'     => undef,
+      'verbose'       => 0,
+      'disable_sysfs' => 0,
+      'slave_down'    => 'warning',
+      'ignore_num_ad' => 0,
+    );
+
+# Get options
+GetOptions('t|timeout=i'    => \$opt{timeout},
+	   'h|help'         => \$opt{help},
+	   'V|version'      => \$opt{version},
+	   'b|blacklist=s'  => \@{ $opt{blacklist} },
+	   'n|no-bonding=s' => \$opt{no_bonding},
+	   's|state'        => \$opt{state},
+	   'S|short-state'  => \$opt{shortstate},
+	   'linebreak=s'    => \$opt{linebreak},
+	   'v|verbose'      => \$opt{verbose},
+           'disable-sysfs'  => \$opt{disable_sysfs},
+           'slave-down=s'   => \$opt{slave_down},
+	   'ignore-num-ad'  => \$opt{ignore_num_ad},
+	  ) or do { print $USAGE; exit $E_UNKNOWN };
+
+# If user requested help
+if ($opt{'help'}) {
+    print $USAGE, $HELP;
+    exit $E_OK;
+}
+
+# If user requested version info
+if ($opt{'version'}) {
+    print $LICENSE;
+    exit $E_OK;
+}
+
+# Reports (messages) are gathered in this array
+@reports = ();
+
+# Setting timeout
+$SIG{ALRM} = sub {
+    print "PLUGIN TIMEOUT: $NAME timed out after $opt{timeout} seconds\n";
+    exit $E_UNKNOWN;
+};
+alarm $opt{timeout};
+
+# Default line break
+$linebreak = isatty(*STDOUT) ? "\n" : '<br/>';
+
+# Line break from option
+if (defined $opt{linebreak}) {
+    if ($opt{linebreak} eq 'REG') {
+	$linebreak = "\n";
+    }
+    elsif ($opt{linebreak} eq 'HTML') {
+	$linebreak = '<br/>';
+    }
+    else {
+	$linebreak = $opt{linebreak};
+    }
+}
+
+# Blacklisted interfaces
+@blacklist = defined $opt{blacklist} ? @{ get_blacklist() } : ();
+
+# Translate text exit codes to values
+%text2exit
+  = ( 'ok'       => $E_OK,
+      'warning'  => $E_WARNING,
+      'critical' => $E_CRITICAL,
+      'unknown'  => $E_UNKNOWN,
+    );
+
+# Check syntax of '--no-bonding' option
+if (!exists $text2exit{$opt{no_bonding}}) {
+    unknown_error("Wrong usage of '--no-bonding' option: '"
+		  . $opt{no_bonding}
+		  . "' is not a recognized keyword");
+}
+
+# Check syntax of '--slave-down' option
+if (!exists $text2exit{$opt{slave_down}}) {
+    unknown_error("Wrong usage of '--slave-down' option: '"
+		  . $opt{slave_down}
+		  . "' is not a recognized keyword");
+}
+
+#---------------------------------------------------------------------
+# Functions
+#---------------------------------------------------------------------
+
+#
+# Store a message in the message array
+#
+sub report {
+    my ($msg, $exval) = @_;
+    return push @reports, [ $msg, $exval ];
+}
+
+#
+# Give an error and exit with unknown state
+#
+sub unknown_error {
+    my $msg = shift;
+    print "ERROR: $msg\n";
+    exit $E_UNKNOWN;
+}
+
+#
+# Read the blacklist option and return a hash containing the
+# blacklisted components
+#
+sub get_blacklist {
+    my @bl = ();
+    my @blacklist = ();
+
+    if (scalar @{ $opt{blacklist} } >= 0) {
+	foreach my $black (@{ $opt{blacklist} }) {
+	    my $tmp = q{};
+	    if (-f $black) {
+		open my $BL, '<', $black
+		  or do { report('other', "Couldn't open blacklist file $black: $!", $E_UNKNOWN)
+			    and return {} };
+		chomp($tmp = <$BL>);
+		close $BL;
+	    }
+	    else {
+		$tmp = $black;
+	    }
+	    push @bl, $tmp;
+	}
+    }
+
+    return [] if $#bl < 0;
+
+    # Parse blacklist string, put in hash
+    foreach my $black (@bl) {
+	push @blacklist, split m{,}xms, $black;
+    }
+
+    return \@blacklist;
+}
+
+#
+# Find bonding interfaces using sysfs
+#
+sub find_bonding_sysfs {
+    my $sysdir       = '/sys/class/net';
+    my $masters_file = "$sysdir/bonding_masters";
+    my @bonds        = ();
+    my %bonding      = ();
+
+    if (! -f $masters_file) {
+	return {};
+    }
+
+    # get bonding masters
+    open my $MASTER, '<', $masters_file
+      or unknown_error("Couldn't open $masters_file: $!");
+    @bonds = split m{\s+}xms, <$MASTER>;
+    close $MASTER;
+
+    foreach my $bond (@bonds) {
+
+	# get bonding mode
+	open my $MODE, '<', "$sysdir/$bond/bonding/mode"
+	  or unknown_error("ERROR: Couldn't open $sysdir/$bond/bonding/mode: $!");
+	my ($mode, $nr) = split m/\s+/xms, <$MODE>;
+	close $MODE;
+	$bonding{$bond}{mode} = "mode=$nr ($mode)";
+
+	# get 802.3ad number of ports
+	if ($bonding{$bond}{mode} eq 'mode=4 (802.3ad)') {
+	    open my $AD_NUM, '<', "$sysdir/$bond/bonding/ad_num_ports"
+	      or unknown_error("ERROR: Couldn't open $sysdir/$bond/bonding/ad_num_ports: $!");
+	    my $ad_num = <$AD_NUM>;
+	    close $AD_NUM;
+	    $bonding{$bond}{ad_num} = $ad_num;
+	}
+
+	# get slaves
+	my @slaves = ();
+	open my $SLAVES, '<', "$sysdir/$bond/bonding/slaves"
+	  or unknown_error("Couldn't open $sysdir/$bond/bonding/slaves: $!");
+	@slaves = split m/\s+/xms, <$SLAVES>;
+	close $SLAVES;
+
+	# get active slave
+	open my $ACTIVE, '<', "$sysdir/$bond/bonding/active_slave"
+	  or unknown_error("Couldn't open $sysdir/$bond/bonding/active_slave: $!");
+	$bonding{$bond}{active} = <$ACTIVE>;
+	close $ACTIVE;
+	if (defined $bonding{$bond}{active}) {
+	    chop $bonding{$bond}{active};
+	}
+
+	# get primary slave
+	open my $PRIMARY, '<', "$sysdir/$bond/bonding/primary"
+	  or unknown_error("Couldn't open $sysdir/$bond/bonding/primary: $!");
+	$bonding{$bond}{primary} = <$PRIMARY>;
+	close $PRIMARY;
+	if (defined $bonding{$bond}{primary}) {
+	    chop $bonding{$bond}{primary};
+	}
+
+	# get slave status
+	foreach my $slave (@slaves) {
+	    my $statefile = -e "$sysdir/$bond/slave_$slave/operstate"
+	      ? "$sysdir/$bond/slave_$slave/operstate"
+		: "$sysdir/$bond/lower_$slave/operstate";
+	    open my $STATE, '<', "$statefile"
+	      or unknown_error("Couldn't open $statefile: $!");
+	    chop($bonding{$bond}{slave}{$slave} = <$STATE>);
+	    close $STATE;
+	}
+
+	# get bond state
+	open my $BSTATE, '<', "$sysdir/$bond/operstate"
+	  or unknown_error("Couldn't open $sysdir/$bond/operstate: $!");
+	chop($bonding{$bond}{status} = <$BSTATE>);
+	close $BSTATE;
+    }
+
+    return \%bonding;
+}
+
+
+#
+# Find bonding interfaces using procfs (fallback, deprecated)
+#
+sub find_bonding_procfs {
+    my $procdir = '/proc/net/bonding';
+    my @bonds   = ();
+    my %bonding = ();
+
+    opendir(my $DIR, $procdir);
+    @bonds = grep { m{\A bond\d+ \z}xms && -f "$procdir/$_" } readdir $DIR;
+    closedir $DIR;
+
+    if ($#bonds == -1) {
+	return {};
+    }
+
+    foreach my $b (@bonds) {
+	my $slave = undef;
+	open my $BOND, '<', "$procdir/$b"
+	  or unknown_error("Couldn't open $procdir/$b: $!");
+	while (<$BOND>) {
+	    # get bonding mode
+	    if (m{\A Bonding \s Mode: \s (.+) \z}xms) {
+		chop($bonding{$b}{mode} = $1);
+	    }
+	    # get 802.3ad number of ports
+	    elsif (defined $bonding{$b}{mode} and $bonding{$b}{mode} =~ m{802\.3ad}xms
+		   and m{\A\s+ Number \s of \s ports: \s (\d+) .*\z}xms) {
+		chomp($bonding{$b}{ad_num} = $1);
+	    }
+	    # get slave
+	    elsif (m{\A Slave \s Interface: \s (.+) \z}xms) {
+		chop($slave = $1);
+	    }
+	    # get slave and bonding status
+	    elsif (m{\A MII \s Status: \s (.+) \z}xms) {
+		if (defined $slave) {
+		    chop($bonding{$b}{slave}{$slave} = $1);
+		}
+		else {
+		    chop($bonding{$b}{status} = $1);
+		}
+	    }
+	    # get primary slave
+	    elsif (m{\A Primary \s Slave: \s (\S+) .* \z}xms) {
+		chomp($bonding{$b}{primary} = $1);
+	    }
+	    # get active slave
+	    elsif (m{\A Currently \s Active \s Slave: \s (.+) \z}xms) {
+		chop($bonding{$b}{active} = $1);
+	    }
+	}
+    }
+
+    return \%bonding;
+}
+
+#
+# Find bonding interfaces
+#
+sub find_bonding {
+    my $bonding = undef;
+
+    if ($opt{disable_sysfs}) {
+        $bonding = find_bonding_procfs();
+    }
+    else {
+        # first try sysfs
+        $bonding = find_bonding_sysfs();
+
+        # second try procfs
+        if (scalar keys %{ $bonding } == 0) {
+            $bonding = find_bonding_procfs();
+        }
+    }
+
+    # if no bonding interfaces found, exit
+    if (scalar keys %{ $bonding } == 0) {
+	print $reverse_exitcode{$text2exit{$opt{no_bonding}}}
+	  . ": No bonding interfaces found\n";
+	exit $text2exit{$opt{no_bonding}};
+    }
+
+    return $bonding;
+}
+
+#
+# Returns true if an interface is blacklisted
+#
+sub blacklisted {
+    return 0 if !defined $opt{blacklist};
+    my $if = shift;
+    foreach $b (@blacklist) {
+	if ($if eq $b) {
+	    return 1;
+	}
+    }
+    return 0;
+}
+
+#=====================================================================
+# Main program
+#=====================================================================
+
+%bonding = %{ find_bonding() };
+MASTER:
+foreach my $b (sort keys %bonding) {
+
+    # If the master interface is blacklisted
+    if (blacklisted($b)) {
+	my $msg = sprintf 'Bonding interface %s [%s] is %s, but IGNORED',
+	  $b, $bonding{$b}{mode}, $bonding{$b}{status};
+	report($msg, $E_OK);
+	next MASTER;
+    }
+
+    if ($bonding{$b}{status} ne 'up') {
+	my $msg = sprintf 'Bonding interface %s [%s] is %s',
+	  $b, $bonding{$b}{mode}, $bonding{$b}{status};
+	report($msg, $E_CRITICAL);
+    }
+    else {
+	my $slaves_are_up = 1; # flag
+
+      SLAVE:
+	foreach my $i (sort keys %{ $bonding{$b}{slave} }) {
+
+	    # If the slave interface is blacklisted
+	    if (blacklisted($i)) {
+		my $msg = sprintf 'Slave interface %s [member of %s] is %s, but IGNORED',
+		  $i, $b, $bonding{$b}{slave}{$i};
+		report($msg, $E_OK);
+		next SLAVE;
+	    }
+
+	    if ($bonding{$b}{slave}{$i} ne 'up') {
+		$slaves_are_up = 0;  # not all slaves are up
+		my $msg = sprintf 'Bonding interface %s [%s]: Slave %s is %s',
+		  $b, $bonding{$b}{mode}, $i, $bonding{$b}{slave}{$i};
+		report($msg, $text2exit{$opt{slave_down}});
+	    }
+	}
+	if ($slaves_are_up) {
+	    my %slave = map { $_ => q{} } keys %{ $bonding{$b}{slave} };
+	    foreach my $s (keys %slave) {
+		if (defined $bonding{$b}{primary} and $bonding{$b}{primary} eq $s) {
+		    $slave{$s} .= '*';
+		}
+		if (defined $bonding{$b}{active} and $bonding{$b}{active} eq $s) {
+		    $slave{$s} .= '!';
+		}
+	    }
+	    if (scalar keys %slave == 1) {
+		my @slaves = keys %slave;
+		my $msg = sprintf 'Bonding interface %s [%s] has only one slave (%s)',
+		  $b, $bonding{$b}{mode}, $slaves[0];
+		report($msg, $E_WARNING);
+	    }
+	    elsif (scalar keys %slave == 0) {  # FIXME: does this ever happen?
+		my $msg = sprintf 'Bonding interface %s [%s] has zero slaves!',
+		  $b, $bonding{$b}{mode};
+		report($msg, $E_CRITICAL);
+	    }
+	    elsif (defined $bonding{$b}{ad_num} and $bonding{$b}{ad_num} != scalar keys %slave
+		   and $opt{ignore_num_ad} == 0) {
+		my $msg = sprintf 'Bonding interface %s [%s]: Number of AD ports (%d) does not equal the number of slaves (%d)',
+		  $b, $bonding{$b}{mode}, $bonding{$b}{ad_num}, scalar keys %slave;
+		report($msg, $E_WARNING);
+	    }
+	    else {
+		my @slaves = map { $_ . $slave{$_} } sort keys %slave;
+		my $msg = sprintf 'Interface %s is %s: %s, %d slaves: %s',
+		  $b, $bonding{$b}{status}, $bonding{$b}{mode},
+		    scalar @slaves, join q{, }, @slaves;
+		report($msg, $E_OK);
+	    }
+	}
+    }
+}
+
+# Counter variable
+%nagios_level_count
+  = (
+     'OK'       => 0,
+     'WARNING'  => 0,
+     'CRITICAL' => 0,
+     'UNKNOWN'  => 0,
+    );
+
+# holds only ok messages
+@ok_reports = ();
+
+# Reset the WARN signal
+$SIG{__WARN__} = 'DEFAULT';
+
+# Print any perl warnings that have occured
+if (@perl_warnings) {
+    foreach (@perl_warnings) {
+	chop @$_;
+        report("INTERNAL ERROR: @$_", $E_UNKNOWN);
+    }
+}
+
+$counter = 0;
+ALERT:
+foreach (sort {$a->[1] < $b->[1]} @reports) {
+    my ($msg, $level) = @{ $_ };
+    $nagios_level_count{$reverse_exitcode{$level}}++;
+
+    if ($level == $E_OK && !$opt{verbose}) {
+	push @ok_reports, $msg;
+	next ALERT;
+    }
+
+    # Prefix with nagios level if specified with option '--state'
+    $msg = $reverse_exitcode{$level} . ": $msg" if $opt{state};
+
+    # Prefix with one-letter nagios level if specified with option '--short-state'
+    $msg = (substr $reverse_exitcode{$level}, 0, 1) . ": $msg" if $opt{shortstate};
+
+    ($counter++ == 0) ? print $msg : print $linebreak, $msg;
+}
+
+# Determine our exit code
+$exit_code = $E_OK;
+if ($nagios_level_count{UNKNOWN} > 0)  { $exit_code = $E_UNKNOWN;  }
+if ($nagios_level_count{WARNING} > 0)  { $exit_code = $E_WARNING;  }
+if ($nagios_level_count{CRITICAL} > 0) { $exit_code = $E_CRITICAL; }
+
+# Print OK messages
+$counter = 0;
+if ($exit_code == $E_OK && !$opt{verbose}) {
+    foreach my $msg (@ok_reports) {
+	# Prefix with nagios level if specified with option '--state'
+	$msg = "OK: $msg" if $opt{state};
+
+	# Prefix with one-letter nagios level if specified with option '--short-state'
+	$msg = "O: $msg" if $opt{shortstate};
+
+	($counter++ == 0) ? print $msg : print $linebreak, $msg;
+    }
+}
+
+print "\n";
+
+# Exit with proper exit code
+exit $exit_code;

+ 130 - 0
docs/nagios/scripts/plugins/check_linux_raid

@@ -0,0 +1,130 @@
+#!/usr/bin/perl
+
+# Copyright (c) 2002 ISOMEDIA, Inc.
+# originally written by Steve Milton
+# later updates by sean finney <seanius@seanius.net>
+#
+# 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
+#
+# Usage:   check_raid [raid-name]
+# Example: check_raid md0
+#	  WARNING md0 status=[UUU_U], recovery=46.4%, finish=123.0min
+
+use strict;
+use lib "/usr/lib/nagios/plugins";
+use utils qw(%ERRORS);
+
+# die with an error if we're not on Linux
+if ($^O ne 'linux') {
+    print "This plugin only applicable on Linux.\n";
+    exit $ERRORS{'UNKNOWN'};
+}
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+sub max_state($$){
+	my ($a, $b) = @_;
+	if ($a eq "CRITICAL" || $b eq "CRITICAL") { return "CRITICAL"; } 
+	elsif ($a eq "WARNING" || $b eq "WARNING") { return "WARNING"; }
+	elsif ($a eq "OK" || $b eq "OK") { return "OK"; }
+	elsif ($a eq "UNKNOWN" || $b eq "UNKNOWN") { return "UNKNOWN"; }
+	elsif ($a eq "DEPENDENT" || $b eq "DEPENDENT") { return "DEPENDENT"; }
+	return "UNKNOWN";
+}
+
+my $nextdev;
+if(defined $ARGV[0]) { $nextdev = shift; }
+else { $nextdev = "md[0-9]+"; }
+
+my $code = "UNKNOWN";
+my $msg = "";
+my %status;
+my %recovery;
+my %resyncing;
+my %finish;
+my %active;
+my %devices;
+
+while(defined $nextdev){
+	open (MDSTAT, "< /proc/mdstat") or die "Failed to open /proc/mdstat";
+	my $device = undef;
+	while(<MDSTAT>) {
+		if (defined $device) {
+			if (/(\[[_U]+\])/) {
+				$status{$device} = $1;
+			} elsif (/recovery =\s+(.*?)\s/) {
+				$recovery{$device} = $1;
+				($finish{$device}) = /finish=(.*?min)/;
+				$device=undef;
+            } elsif (/resync =\s+(.*?)\s/) {
+                $resyncing{$device} = $1;
+                ($finish{$device}) = /finish=(.*?min)/;
+                $device=undef;
+			} elsif (/^\s*$/) {
+				$device=undef;
+			}
+		} elsif (/^($nextdev)\s*:/) {
+			$device=$1;
+			$devices{$device}=$device;
+			if (/\sactive/) {
+				$status{$device} = ''; # Shall be filled later if available
+				$active{$device} = 1;
+			}
+		}
+	}
+	$nextdev = shift;
+}
+
+foreach my $k (sort keys %devices){
+	if (!exists($status{$k})) {
+		$msg .= sprintf " %s inactive with no status information.",
+			$devices{$k};
+		$code = max_state($code, "CRITICAL");
+	} elsif ($status{$k} =~ /_/) {
+		if (defined $recovery{$k}) {
+			$msg .= sprintf " %s status=%s, recovery=%s, finish=%s.",
+				$devices{$k}, $status{$k}, $recovery{$k}, $finish{$k};
+			$code = max_state($code, "WARNING");
+		} else {
+			$msg .= sprintf " %s status=%s.", $devices{$k}, $status{$k};
+			$code = max_state($code, "CRITICAL");
+		}
+	} elsif ($status{$k} =~ /U+/) {
+        if (defined $resyncing{$k}) {
+            $msg .= sprintf " %s status=%s, resync=%s, finish=%s.",
+                $devices{$k}, $status{$k}, $resyncing{$k}, $finish{$k};
+            $code = max_state($code, "WARNING");
+        } else {
+            $msg .= sprintf " %s status=%s.", $devices{$k}, $status{$k};
+            $code = max_state($code, "OK");
+        }
+	} else {
+		if ($active{$k}) {
+			$msg .= sprintf " %s active with no status information.",
+				$devices{$k};
+			$code = max_state($code, "OK");
+		} else {
+			# This should't run anymore, but is left as a catch-all
+			$msg .= sprintf " %s does not exist.\n", $devices{$k};
+			$code = max_state($code, "CRITICAL");
+		}
+	}
+}
+
+print $code, $msg, "\n";
+exit ($ERRORS{$code});
+

+ 58 - 0
docs/nagios/scripts/plugins/check_netping_io.pl

@@ -0,0 +1,58 @@
+#!/usr/bin/perl
+
+use strict;
+use Net::SNMP;
+
+my $netping_oids = {
+'netpingIOlevel'=>'.1.3.6.1.4.1.25728.8900.1.1.2',
+'netpingIOLineName'=>'.1.3.6.1.4.1.25728.8900.1.1.6',
+'netpingIOCount'=>'.1.3.6.1.4.1.25728.8900.1.1.9'
+};
+
+exit if (!$ARGV[0]);
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+my $hostip=$ARGV[0];
+
+my $line =$ARGV[1] || '1';
+
+my $community = $ARGV[2] || 'public';
+
+my $location_oid = '.1.3.6.1.2.1.1.6.0';
+
+my ($session, $error) = Net::SNMP->session(
+   -hostname  => shift || $hostip,
+   -version   => shift || 2,
+   -community => shift || $community,
+   -timeout   => 5,
+   -port      => shift || 161 
+);
+
+if (!defined($session)) {
+   printf("ERROR: %s.\n", $error);
+   exit 1;
+}
+
+my $line_oid = $netping_oids->{netpingIOlevel}.'.'.$line;
+my $desc_oid = $netping_oids->{netpingIOLineName}.'.'.$line;
+
+my $result = $session->get_request( -varbindlist => [$line_oid] );
+my $status = $result->{$line_oid};
+
+$result = $session->get_request( -varbindlist => [$desc_oid] );
+my $desc = $result->{$desc_oid};
+
+$result = $session->get_request( -varbindlist => [$location_oid] );
+my $location = $result->{$location_oid};
+$session->close;
+
+if ($status) {
+   print("CRIT: $location $desc detected!\n");
+   exit 2;
+}
+
+print("OK: $location $desc\n");
+exit 0;

BIN
docs/nagios/scripts/plugins/check_nrpe


+ 93 - 0
docs/nagios/scripts/plugins/check_nt_memory_process.sh

@@ -0,0 +1,93 @@
+#!/bin/bash
+#Date: 11.04.08
+#Author: Christian Mies (cmies@itnovum.de)
+#Version 0.0.1
+#About: Take Working Set Perfmon Value of specified Process and calculate it to MB
+#       ./check_nt -H <HOSTNAME> -p 1248 -v COUNTER -l "\\Process(NSClient++)\Working Set","Belegter Arbeitsspeicher NSClient++,Byte"
+
+#typeset -i mb crit warn
+
+pluginpath="/usr/lib/nagios/plugins"
+pluginname=`basename $0`
+. $pluginpath/utils.sh
+
+while getopts "H:p:s:P:L:w:c:" options; do
+  case $options in
+        H)hostname=$OPTARG;;
+        p)port=$OPTARG;;
+        P)process=$OPTARG;;
+	L)language=$OPTARG;;
+	s)secret=$OPTARG;;
+        w)warn=$OPTARG;;
+        c)crit=$OPTARG;;
+        *)
+          echo "$pluginname Help:"
+          echo "-----------------"
+          echo "-H <Hostname> : Hostname/IP of Citrix Enterprise Server 4"
+          echo "-p <portnumber>: NSClient++ Port Default: 1248"
+          echo "-s <secret>: NSClient++ secret"
+          echo "-P Process: Which Process to check?"
+          echo "-L Language: Language for Perfmon. Values: german/english Default: english"
+          echo "-----------------"
+          echo "Usage: $pluginname -H <HOSTADDRESS> -p <port> -s <secret> -P <processname> -L <language> -w <warn> -c <crit>"
+          exit 3
+        ;;
+  esac
+done
+
+if [ -z $port ]; then
+        port=1248;
+fi;
+if [ -z $language ]; then
+        language="english";
+fi;
+if [ -z $process ]; then
+        echo "UNKNOWN: Missing Process Name";
+	exit $STATE_UNKNOWN;
+fi;
+if [ -z $crit ] || [ -z $warn ]; then
+        echo "UNKNOWN: Critical / Warning Value must be set";
+	exit $STATE_UNKNOWN;
+fi;
+
+if [ -z $secret ]; then
+        echo "UNKNOWN: Secret not defined!";
+	exit $STATE_UNKNOWN;
+fi;
+
+if [ $language = "english" ]; then
+	perfcount_name="Process"
+	perfcount_value="Working Set"
+	output="Used Memory of"
+	perfout="UsedMemory"
+	fi;
+
+if [ $language = "german" ]; then
+	perfcount_name="Prozess"
+	perfcount_value="Arbeitsseiten"
+	output="Belegter Speicher von"
+	perfout="Speicer"
+	fi;
+
+if [ $language = "russian" ]; then
+	perfcount_name="Процесс"
+	perfcount_value="Рабочий набор"
+	output="Использовано памяти"
+	perfout="UsedMemory"
+	fi;
+
+command="\\$perfcount_name($process)\\$perfcount_value"
+memory=`$pluginpath/check_nt -H $hostname -p $port -s $secret -v COUNTER -l "$command" | tr -d '\n'`
+mb=`echo "scale=0; $memory/1048576"|bc -l`
+
+if [ $mb -ge $crit ]; then
+	echo "CRITICAL: $output $process: $mb MB|$perfout=${mb}MB;$warn;$crit;;;"
+        exit $STATE_CRITICAL;
+fi;
+if [ $mb -ge $warn ] && [ $mb -lt $crit ]; then
+        echo "WARNING: $output $process: $mb MB|$perfout=${mb}MB;$warn;$crit;;;"
+        exit $STATE_WARNING;
+fi;
+
+echo "OK: $output $process: $mb MB|$perfout=${mb}MB;$warn;$crit;;;"
+exit $STATE_OK;

+ 88 - 0
docs/nagios/scripts/plugins/check_oki_status

@@ -0,0 +1,88 @@
+#!/usr/bin/perl
+
+use strict;
+use Net::SNMP;
+
+my $RET_OK=0;
+my $RET_WARNING=1;
+my $RET_UNKNOWN=3;
+my $RET_CRITICAL=2;
+
+my $MSG_OK="OK";
+my $MSG_WARNING="WARN";
+my $MSG_CRITICAL="CRIT";
+
+my $hostip=$ARGV[0];
+
+exit if (!$hostip);
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+sub ping {
+use Net::Ping;
+use Time::HiRes;
+my ($host,$time) = @_;
+my $p = Net::Ping->new();
+$p->hires();
+$time=1 if (!$time);
+my ($ret, $duration, $ip) = $p->ping($host, $time);
+$p->close();
+$ret ? return 1: return 0;
+}
+
+exit $RET_UNKNOWN if (!ping($hostip));
+
+eval {
+
+#set timout for script work.
+$SIG{ALRM} = sub { die "Timeout 55 sec reached.\n" };
+alarm 55;
+
+my ($session, $error) = Net::SNMP->session(
+   -hostname  => shift || $hostip,
+   -version   => 1,
+   -timeout   => 15,
+   -community => shift || 'public',
+   -port      => shift || 161 
+);
+
+if (!defined($session)) {
+   printf("ERROR: %s.\n", $error);
+   exit 1;
+}
+
+my $oki_status = '1.3.6.1.4.1.2001.1.3.1.1.10.4.0';
+
+my $oki_status2 = '1.3.6.1.4.1.2001.1.3.1.1.7.1.2.1.1';
+
+my $result = $session->get_request(
+   -varbindlist => [$oki_status]
+);
+
+if (!defined($result)) { $oki_status = $oki_status2; $result = $session->get_request(-varbindlist => [$oki_status]); }
+
+if (!defined($result)) {
+   printf("ERROR: %s.\n", $session->error);
+   $session->close;
+   exit $RET_CRITICAL;
+}
+
+my $ret_str = $result->{$oki_status};
+$session->close;
+
+if ($ret_str =~/error/i) {
+    print("ERROR: ".$ret_str."\n\n");
+    exit $RET_CRITICAL;
+    }
+if ($ret_str =~/warning/i) {
+    print("WARNING ".$ret_str."\n\n");
+    exit $RET_WARNING;
+    }
+
+print("OK ".$ret_str."\n\n");
+$SIG{ALRM} = 'DEFAULT';
+};
+
+exit $RET_OK;

+ 149 - 0
docs/nagios/scripts/plugins/check_snmp_bandwidth.pl

@@ -0,0 +1,149 @@
+#!/usr/bin/perl
+
+use lib "/etc/nagios4/scripts/plugins";
+use Net::SNMP;
+use Config::Tiny;
+use File::Path qw( mkpath );
+use POSIX;
+use strict;
+use snmp;
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+my $ifSpeed       = '.1.3.6.1.2.1.2.2.1.5';
+my $ifInOctets    = '.1.3.6.1.2.1.2.2.1.10';
+my $ifOutOctets   = '.1.3.6.1.2.1.2.2.1.16';
+
+my $ifHighSpeed   = '.1.3.6.1.2.1.31.1.1.1.15';
+my $ifHCInOctets  = '.1.3.6.1.2.1.31.1.1.1.6';
+my $ifHCOutOctets = '.1.3.6.1.2.1.31.1.1.1.10';
+
+### return codes
+my $RET_OK=0;
+my $RET_WARNING=1;
+my $RET_UNKNOWN=3;
+my $RET_CRITICAL=2;
+
+if (scalar @ARGV <= 2) {
+    print "Usage: $0 <host> <snmp_string> <port> <32|64> [warning] [critical]\n";
+    print "<snmp_string> => community;version;user;auth;priv\n";
+    print "for version 3: community = password\n";
+    exit $RET_OK;
+    }
+
+my $host = shift @ARGV;
+my $snmp_str = shift @ARGV;
+my ($community,$version,$user,$auth,$priv) = split(/;/,$snmp_str);
+
+my $snmp;
+$snmp->{version} = $version || '2';
+$snmp->{timeout} = 30;
+$snmp->{community} = $community || 'public';
+$snmp->{user} = $user || 'public';
+$snmp->{auth} = $auth || 'sha1';
+$snmp->{priv} = $priv || 'aes';
+
+my $port = shift @ARGV;
+
+my $counter = shift @ARGV || 64;
+my $warning = shift (@ARGV) || 80;
+my $critical = shift (@ARGV) || 90;
+
+sub get_snmp_band {
+my $port = shift;
+my $counter = shift;
+
+my $IN_OID = $ifHCInOctets.".".$port;
+my $OUT_OID = $ifHCOutOctets.".".$port;
+my $SPEED_OID = $ifHighSpeed.".".$port;
+
+if ($counter eq 32) {
+    $IN_OID = $ifInOctets.".".$port;
+    $OUT_OID = $ifOutOctets.".".$port;
+    $SPEED_OID = $ifSpeed.".".$port;
+    }
+
+my $session = init_snmp($host,$snmp);
+
+my $result_in = $session->get_request( -varbindlist => [$IN_OID]);
+my $result_out = $session->get_request( -varbindlist => [$OUT_OID]);
+my $result_speed = $session->get_request( -varbindlist => [$SPEED_OID]);
+$session->close;
+
+my $port_speed;
+$port_speed->{timestamp}=time();
+$port_speed->{counter}=$counter;
+$port_speed->{in} = $result_in->{$IN_OID};
+$port_speed->{out} = $result_out->{$OUT_OID};
+$port_speed->{speed} = $result_speed->{$SPEED_OID};
+
+return $port_speed;
+}
+
+my $start_time = time();
+my $host_spool_dir = "/var/spool/nagios4/plugins/bandwidth/";
+if (!-e "$host_spool_dir") { mkpath( $host_spool_dir, 0, 0770 ); }
+my $host_data = $host_spool_dir.'/'.$host;
+
+my $old_info;
+my $cur_info;
+
+my $clean_start = 0;
+
+my $host_spool = Config::Tiny->new;
+if (-e "$host_data") {
+    $host_spool = Config::Tiny->read($host_data, 'utf8' );
+    $old_info=$host_spool->{$port};
+    } else { $clean_start=1; }
+
+$cur_info=get_snmp_band($port,$counter);
+#speed patch for x64 counter
+if ($counter eq 64) { $cur_info->{speed}=$cur_info->{speed}*1000; }
+#extreme patch
+if ($cur_info->{speed} eq 4294967295) { $cur_info->{speed}=10000000; }
+
+$host_spool->{$port} = $cur_info;
+$host_spool->write($host_data);
+
+my $perf="IN=%s%%;$warning;$critical OUT=%s%%;$warning;$critical";
+
+if ($clean_start or $cur_info->{speed} eq 0) {
+    printf("OK: Bandwidth in=%s%% out=%s%% |".$perf."\n",0,0,0,0);
+    exit $RET_OK;
+    }
+
+my $deltaIn = $cur_info->{in} - $old_info->{in};
+my $deltaOut = $cur_info->{out} - $old_info->{out};
+my $deltaTime = $cur_info->{timestamp} - $old_info->{timestamp};
+
+my $counter_div = 10;
+
+if ($counter eq 32) { $counter_div = 1; }
+
+my $band_in = ceil((($deltaIn * 8) / $deltaTime) / $cur_info->{speed} / $counter_div);
+my $band_out = ceil((($deltaOut * 8) / $deltaTime) / $cur_info->{speed} / $counter_div);
+
+if ($band_in <$warning and $band_out<$warning) {
+    printf("OK: Bandwidth in=%s%% out=%s%%|".$perf."\n",$band_in,$band_out,$band_in,$band_out);
+    exit $RET_OK;
+    }
+
+if ($band_in >=$critical or $band_out>=$critical) {
+    printf("CRIT: Bandwidth in=%s%% out=%s%%|".$perf."\n",$band_in,$band_out,$band_in,$band_out);
+    exit $RET_CRITICAL;
+    }
+
+if ($band_in >=$warning and $band_in<$critical) {
+    printf("WARN: Bandwidth in=%s%% out=%s%%|".$perf."\n",$band_in,$band_out,$band_in,$band_out);
+    exit $RET_WARNING;
+    }
+
+if ($band_out >=$warning and $band_out<$critical) {
+    printf("WARN: Bandwidth in=%s%% out=%s%%|".$perf."\n",$band_in,$band_out,$band_in,$band_out);
+    exit $RET_WARNING;
+    }
+
+printf("OK: You don't see this! in=%s%% out=%s%% |".$perf."\n",$band_in,$band_out);
+exit $RET_OK;

+ 111 - 0
docs/nagios/scripts/plugins/check_snmp_crc.pl

@@ -0,0 +1,111 @@
+#!/usr/bin/perl
+
+use lib "/etc/nagios4/scripts/plugins";
+use snmp;
+use Net::SNMP;
+use Config::Tiny;
+use File::Path qw( mkpath );
+use strict;
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+### return codes
+my $RET_OK=0;
+my $RET_WARNING=1;
+my $RET_UNKNOWN=3;
+my $RET_CRITICAL=2;
+
+my $time_cache = 1800;
+
+my $err_step = 100;
+
+
+if (scalar @ARGV <= 2) {
+    print "Usage: $0 <host> <snmp_string> <port> <32|64> [warning] [critical]\n";
+    print "<snmp_string> => community;version;user;auth;priv\n";
+    print "for version 3: community = password\n";
+    exit $RET_OK;
+    }
+
+my $host = shift @ARGV;
+my $snmp_str = shift @ARGV;
+my ($community,$version,$user,$auth,$priv) = split(/;/,$snmp_str);
+
+my $snmp;
+$snmp->{version} = $version || '2';
+$snmp->{timeout} = 30;
+$snmp->{community} = $community || 'public';
+$snmp->{user} = $user || 'public';
+$snmp->{auth} = $auth || 'sha1';
+$snmp->{priv} = $priv || 'aes';
+
+my $port = shift @ARGV;
+
+sub get_snmp_crc {
+
+my $CRC_OID = ".1.3.6.1.2.1.2.2.1.14";
+
+my $session = init_snmp($host,$snmp);
+
+my $result = $session->get_table($CRC_OID);
+$session->close;
+
+my %port_crc;
+foreach my $row (keys (%$result)) {
+next if ($row !~ /$CRC_OID/);
+my $crc_value = $result->{$row};
+$row =~ s/$CRC_OID//;
+$row =~ s/^(\.*)//;
+$port_crc{$row}=$crc_value;
+}
+
+return \%port_crc;
+}
+
+my $time_cache_min = int($time_cache/60);
+
+my $start_time = time();
+my $host_spool_dir = "/var/spool/nagios4/plugins/crc/";
+
+if (!-e "$host_spool_dir") { mkpath( $host_spool_dir, 0, 0770 ); }
+
+my $host_data = $host_spool_dir.$host;
+
+my $old_crc_info;
+my $cur_crc_info;
+
+my $need_rescan = 0;
+
+if (-e "$host_data") {
+    my $host_spool = Config::Tiny->new;
+    $host_spool = Config::Tiny->read($host_data, 'utf8' );
+    my $old_time=$host_spool->{_}->{timestamp};
+    foreach my $port (keys %{$host_spool->{crc_data}}) { $old_crc_info->{$port} = $host_spool->{crc_data}->{$port}; }
+    if (($start_time - $old_time) >=$time_cache) { $need_rescan = 1; } else { $need_rescan = 0; }
+    } else { $need_rescan = 1; }
+
+if (!$old_crc_info->{$port}) { $old_crc_info->{$port}=0; }
+
+if ($need_rescan) {
+    $cur_crc_info=get_snmp_crc;
+    my $host_spool = Config::Tiny->new;
+    $host_spool->{_}->{timestamp}=$start_time;
+    $host_spool->{crc_data} = $cur_crc_info;
+    $host_spool->write($host_data);
+    } else { $cur_crc_info = $old_crc_info; }
+
+my $diff_crc = $cur_crc_info->{$port} - $old_crc_info->{$port};
+
+my $perf="ErrSpeed=%s;0;0;0;10000000;";
+
+if ($diff_crc >0 and $diff_crc >= $err_step) {
+    my $speed_crc = int($diff_crc/$time_cache_min);
+    printf("CRIT: CRC error found! Speedup $speed_crc by minute!|".$perf."\n",$speed_crc);
+    exit $RET_CRITICAL;
+    }
+
+printf("OK: Errors not found. |".$perf."\n",0);
+
+exit $RET_OK;

+ 100 - 0
docs/nagios/scripts/plugins/check_snmp_crc_simple.pl

@@ -0,0 +1,100 @@
+#!/usr/bin/perl
+
+use lib "/etc/nagios4/scripts/plugins";
+use snmp;
+use Net::SNMP;
+use Config::Tiny;
+use File::Path qw( mkpath );
+use strict;
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+### return codes
+my $RET_OK=0;
+my $RET_WARNING=1;
+my $RET_UNKNOWN=3;
+my $RET_CRITICAL=2;
+
+my $time_cache = 1800;
+
+my $err_step = 100;
+
+if (scalar @ARGV <= 2) {
+    print "Usage: $0 <host> <snmp_string> <port> [warning] [critical]\n";
+    print "<snmp_string> => community;version;user;auth;priv\n";
+    print "for version 3: community = password\n";
+    exit $RET_OK;
+    }
+
+my $host = shift @ARGV;
+my $snmp_str = shift @ARGV;
+my ($community,$version,$user,$auth,$priv) = split(/;/,$snmp_str);
+
+my $snmp;
+$snmp->{version} = $version || '2';
+$snmp->{timeout} = 30;
+$snmp->{community} = $community || 'public';
+$snmp->{user} = $user || 'public';
+$snmp->{auth} = $auth || 'sha1';
+$snmp->{priv} = $priv || 'aes';
+
+my $port = shift @ARGV;
+
+sub get_snmp_crc {
+my $port = shift;
+my $CRC_OID = ".1.3.6.1.2.1.2.2.1.14.".$port;
+my $session = init_snmp($host,$snmp);
+my $result = $session->get_request( -varbindlist => [$CRC_OID]);
+$session->close;
+my %port_crc;
+$port_crc{$port} = $result->{$CRC_OID};
+return \%port_crc;
+}
+
+my $time_cache_min = int($time_cache/60);
+
+my $start_time = time();
+my $host_spool_dir = "/var/spool/nagios4/plugins/crc/".$host;
+
+if (!-e "$host_spool_dir") { mkpath( $host_spool_dir, 0, 0770 ); }
+
+my $host_data = $host_spool_dir.'/'.$host."-port-".$port;
+
+my $old_crc_info;
+my $cur_crc_info;
+
+my $need_rescan = 0;
+
+if (-e "$host_data") {
+    my $host_spool = Config::Tiny->new;
+    $host_spool = Config::Tiny->read($host_data, 'utf8' );
+    my $old_time=$host_spool->{_}->{timestamp};
+    foreach my $port (keys %{$host_spool->{crc_data}}) { $old_crc_info->{$port} = $host_spool->{crc_data}->{$port}; }
+    if (($start_time - $old_time) >=$time_cache) { $need_rescan = 1; } else { $need_rescan = 0; }
+    } else { $need_rescan = 1; }
+
+if (!$old_crc_info->{$port}) { $old_crc_info->{$port}=0; }
+
+if ($need_rescan) {
+    $cur_crc_info=get_snmp_crc($port);
+    my $host_spool = Config::Tiny->new;
+    $host_spool->{_}->{timestamp}=$start_time;
+    $host_spool->{crc_data} = $cur_crc_info;
+    $host_spool->write($host_data);
+    } else { $cur_crc_info = $old_crc_info; }
+
+my $diff_crc = $cur_crc_info->{$port} - $old_crc_info->{$port};
+
+my $perf="ErrSpeed=%s;0;0;0;10000000;";
+
+if ($diff_crc >0 and $diff_crc >= $err_step) {
+    my $speed_crc = int($diff_crc/$time_cache_min);
+    printf("CRIT: CRC error found! Speedup $speed_crc by minute!|".$perf."\n",$speed_crc);
+    exit $RET_CRITICAL;
+    }
+
+printf("OK: Errors not found. |".$perf."\n",0);
+
+exit $RET_OK;

+ 189 - 0
docs/nagios/scripts/plugins/check_snmp_db_bandwidth.pl

@@ -0,0 +1,189 @@
+#!/usr/bin/perl
+
+use FindBin;
+use Net::SNMP;
+use POSIX;
+use strict;
+use lib "$FindBin::/etc/nagios4/scripts/";
+use lib "/etc/nagios4/scripts/plugins";
+use Nag::mysql;
+use Data::Dumper;
+use DateTime;
+use snmp;
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+my $ifSpeed       = '.1.3.6.1.2.1.2.2.1.5';
+my $ifInOctets    = '.1.3.6.1.2.1.2.2.1.10';
+my $ifOutOctets   = '.1.3.6.1.2.1.2.2.1.16';
+
+my $ifHighSpeed   = '.1.3.6.1.2.1.31.1.1.1.15';
+my $ifHCInOctets  = '.1.3.6.1.2.1.31.1.1.1.6';
+my $ifHCOutOctets = '.1.3.6.1.2.1.31.1.1.1.10';
+
+### return codes
+my $RET_OK=0;
+my $RET_WARNING=1;
+my $RET_UNKNOWN=3;
+my $RET_CRITICAL=2;
+
+if (scalar @ARGV <= 2) {
+    print "Usage: $0 <host> <snmp_string> <port> <32|64> [warning] [critical]\n";
+    print "<snmp_string> => community;version;user;auth;priv\n";
+    print "for version 3: community = password\n";
+    exit $RET_OK;
+    }
+
+my $host = shift @ARGV;
+my $snmp_str = shift @ARGV;
+my ($community,$version,$user,$auth,$priv) = split(/;/,$snmp_str);
+
+my $snmp;
+$snmp->{version} = $version || '2';
+$snmp->{timeout} = 30;
+$snmp->{community} = $community || 'public';
+$snmp->{user} = $user || 'public';
+$snmp->{auth} = $auth || 'sha1';
+$snmp->{priv} = $priv || 'aes';
+
+my $port = shift @ARGV;
+
+my $counter = shift @ARGV || 64;
+my $warning = shift (@ARGV) || 80;
+my $critical = shift (@ARGV) || 90;
+
+###################################################
+
+sub get_snmp_band {
+my $port = shift;
+my $counter = shift;
+
+my $IN_OID = $ifHCInOctets.".".$port;
+my $OUT_OID = $ifHCOutOctets.".".$port;
+my $SPEED_OID = $ifHighSpeed.".".$port;
+
+if ($counter eq 32) {
+    $IN_OID = $ifInOctets.".".$port;
+    $OUT_OID = $ifOutOctets.".".$port;
+    $SPEED_OID = $ifSpeed.".".$port;
+    }
+
+my $session = init_snmp($host,$snmp);
+
+my $result_in = $session->get_request( -varbindlist => [$IN_OID]);
+my $result_out = $session->get_request( -varbindlist => [$OUT_OID]);
+my $result_speed = $session->get_request( -varbindlist => [$SPEED_OID]);
+$session->close;
+
+my $port_speed;
+$port_speed->{data_value4} = $counter;
+$port_speed->{data_value1} = $result_in->{$IN_OID} || 0;
+$port_speed->{data_value2} = $result_out->{$OUT_OID} || 0;
+$port_speed->{data_value3} = $result_speed->{$SPEED_OID} || 10000000;
+
+return $port_speed;
+}
+
+###################################################
+
+my $start = DateTime->now(time_zone => 'local');
+
+my $start_time = $start->epoch;
+
+my $old_info;
+my $cur_info;
+
+my $clean_start = 0;
+
+my $dbh = init_db();
+
+if (!$dbh) {
+    print("ERROR connect to database\n");
+    exit $RET_UNKNOWN;
+    }
+
+my $ip_aton = StrToIp($host);
+
+my $old_info = get_record_sql($dbh,"SELECT * FROM netdevices WHERE ip=".$ip_aton." AND data_type=0 AND data_id=".$port);
+
+#data_value1 - in
+#data_value2 - out
+#data_value3 - speed
+
+if (!$old_info) { $clean_start=1; }
+
+if (!$old_info or !defined $old_info->{data_value1}) { $old_info->{data_value1}=0; }
+if (!$old_info or !defined $old_info->{data_value2}) { $old_info->{data_value2}=0; }
+if (!$old_info or !defined $old_info->{data_value3}) { $old_info->{data_value3} = 10000000; }
+if (!$old_info or !defined $old_info->{data_value4}) { $old_info->{data_value4} = 64; }
+if (!$old_info or !defined $old_info->{data_id}) { $old_info->{data_id}=$port; }
+if (!$old_info or !defined $old_info->{data_type}) { $old_info->{data_type}=0; }
+if (!$old_info or !$old_info->{changed}) { $old_info->{changed} = $start_time - 600; }
+if (!$old_info or !$old_info->{ip}) { $old_info->{ip}=$ip_aton; }
+
+if ($clean_start) { insert_record($dbh,"netdevices",$old_info); }
+
+$cur_info=get_snmp_band($port,$counter);
+
+#add record info
+$cur_info->{data_id} = $port;
+$cur_info->{ip} = $ip_aton;
+$cur_info->{data_type} = 0;
+$cur_info->{changed} = $start_time;
+
+#speed patch for x64 counter
+if ($counter eq 64) { $cur_info->{data_value3}=$cur_info->{data_value3}*1000; }
+#extreme patch
+if ($cur_info->{data_value3} eq 4294967295) { $cur_info->{data_value3}=10000000; }
+
+update_record($dbh,"netdevices",$cur_info,"ip=".$ip_aton." AND data_type=0 AND data_id=".$port);
+
+$dbh->disconnect;
+
+my $perf="IN=%s%%;$warning;$critical OUT=%s%%;$warning;$critical";
+
+if ($clean_start or $cur_info->{data_value3} <= 1) {
+    printf("OK: Bandwidth in=%s%% out=%s%% |".$perf."\n",0,0,0,0);
+    exit $RET_OK;
+    }
+
+my $deltaIn = $cur_info->{data_value1} - $old_info->{data_value1};
+my $deltaOut = $cur_info->{data_value2} - $old_info->{data_value2};
+my $deltaTime = $cur_info->{changed} - $old_info->{changed};
+
+if (!$deltaTime) { $deltaTime = 600; }
+
+my $counter_div = 10;
+
+if ($counter eq 32) { $counter_div = 1; }
+
+my $band_in = ceil((($deltaIn * 8) / $deltaTime) / $cur_info->{data_value3} / $counter_div);
+my $band_out = ceil((($deltaOut * 8) / $deltaTime) / $cur_info->{data_value3} / $counter_div);
+
+if ($band_in >100) { $band_in = 1; }
+if ($band_out >100) { $band_out = 1; }
+
+if ($band_in <$warning and $band_out<$warning) {
+    printf("OK: Bandwidth in=%s%% out=%s%%|".$perf."\n",$band_in,$band_out,$band_in,$band_out);
+    exit $RET_OK;
+    }
+
+if ($band_in >=$critical or $band_out>=$critical) {
+    printf("CRIT: Bandwidth in=%s%% out=%s%%|".$perf."\n",$band_in,$band_out,$band_in,$band_out);
+    exit $RET_CRITICAL;
+    }
+
+if ($band_in >=$warning and $band_in<$critical) {
+    printf("WARN: Bandwidth in=%s%% out=%s%%|".$perf."\n",$band_in,$band_out,$band_in,$band_out);
+    exit $RET_WARNING;
+    }
+
+if ($band_out >=$warning and $band_out<$critical) {
+    printf("WARN: Bandwidth in=%s%% out=%s%%|".$perf."\n",$band_in,$band_out,$band_in,$band_out);
+    exit $RET_WARNING;
+    }
+
+printf("OK: You don't see this! in=%s%% out=%s%% |".$perf."\n",$band_in,$band_out);
+exit $RET_OK;

+ 119 - 0
docs/nagios/scripts/plugins/check_snmp_db_crc.pl

@@ -0,0 +1,119 @@
+#!/usr/bin/perl
+
+use FindBin;
+use Net::SNMP;
+use POSIX;
+use strict;
+use lib "$FindBin::/etc/nagios4/scripts/";
+use lib "/etc/nagios4/scripts/plugins";
+use snmp;
+use Nag::mysql;
+use Data::Dumper;
+use DateTime;
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+### return codes
+my $RET_OK=0;
+my $RET_WARNING=1;
+my $RET_UNKNOWN=3;
+my $RET_CRITICAL=2;
+
+if (scalar @ARGV <= 2) {
+    print "Usage: $0 <host> <snmp_string> <port> [warning] [critical]\n";
+    print "<snmp_string> => community;version;user;auth;priv\n";
+    print "for version 3: community = password\n";
+    exit $RET_OK;
+    }
+
+my $host = shift @ARGV;
+my $snmp_str = shift @ARGV;
+my ($community,$version,$user,$auth,$priv) = split(/;/,$snmp_str);
+
+my $snmp;
+$snmp->{version} = $version || '2';
+$snmp->{timeout} = 30;
+$snmp->{community} = $community || 'public';
+$snmp->{user} = $user || 'public';
+$snmp->{auth} = $auth || 'sha1';
+$snmp->{priv} = $priv || 'aes';
+
+my $port = shift @ARGV;
+
+#minimal sporadic value
+my $err_step = 100;
+
+##########################################################################
+
+sub get_snmp_crc {
+my $port = shift;
+
+my $CRC_OID = ".1.3.6.1.2.1.2.2.1.14.".$port;
+my $session = init_snmp($host,$snmp);
+
+my $result_crc = $session->get_request( -varbindlist => [$CRC_OID]);
+$session->close;
+my $result = $result_crc->{$CRC_OID} || 0;
+return $result;
+}
+
+###########################################################################
+
+my $start = DateTime->now(time_zone => 'local');
+my $start_time = $start->epoch;
+
+my $clean_start = 0;
+
+my $dbh = init_db();
+
+if (!$dbh) {
+    print("ERROR connect to database\n");
+    exit $RET_UNKNOWN;
+    }
+
+my $ip_aton = StrToIp($host);
+
+#data_type = 1 for crc
+my $old_crc_info = get_record_sql($dbh,"SELECT * FROM netdevices WHERE ip=".$ip_aton." AND data_type=1 AND data_id=".$port);
+
+if (!$old_crc_info) { $clean_start=1; }
+
+my $cur_crc_info;
+
+if (!$old_crc_info or !defined $old_crc_info->{data_value1}) { $old_crc_info->{data_value1}=0; }
+if (!$old_crc_info or !defined $old_crc_info->{data_id}) { $old_crc_info->{data_id}=$port; }
+if (!$old_crc_info or !defined $old_crc_info->{data_type}) { $old_crc_info->{data_type}=1; }
+if (!$old_crc_info or !$old_crc_info->{changed}) { $old_crc_info->{changed} = $start_time - 600; }
+if (!$old_crc_info or !$old_crc_info->{ip}) { $old_crc_info->{ip}=$ip_aton; }
+
+if ($clean_start) { insert_record($dbh,"netdevices",$old_crc_info); }
+
+$cur_crc_info->{data_id} = $port;
+$cur_crc_info->{ip} = $ip_aton;
+$cur_crc_info->{data_type} = 1;
+$cur_crc_info->{changed} = $start_time;
+
+$cur_crc_info->{data_value1} =get_snmp_crc($port);
+
+update_record($dbh,"netdevices",$cur_crc_info,"ip=".$ip_aton." AND data_type=1 AND data_id=".$port);
+$dbh->disconnect;
+
+my $diff_crc = $cur_crc_info->{data_value1} - $old_crc_info->{data_value1};
+
+my $time_diff = $cur_crc_info->{changed} - $old_crc_info->{changed};
+if (!$time_diff) { $time_diff = 600; }
+
+my $perf="ErrSpeed=%s;0;0;0;10000000;";
+
+my $speed_crc = int($diff_crc/$time_diff/60);
+
+if ($speed_crc>0 and $diff_crc >0 and $diff_crc >= $err_step) {
+    printf("CRIT: CRC error found! Speedup $speed_crc by minute!|".$perf."\n",$speed_crc);
+    exit $RET_CRITICAL;
+    }
+
+printf("OK: Errors not found. |".$perf."\n",0);
+
+exit $RET_OK;

+ 59 - 0
docs/nagios/scripts/plugins/check_snmp_hikvision

@@ -0,0 +1,59 @@
+#!/usr/bin/perl
+
+use strict;
+
+use Net::SNMP qw(ticks_to_time TRANSLATE_NONE);
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+my $ip  = shift;
+my $community = shift || 'public';
+my $port = shift || '161';
+my $version = shift || '2';
+
+my ($session, $error) = Net::SNMP->session(
+   -hostname  => $ip,
+   -community => $community,
+   -port      => $port,
+   -version   => $version
+);
+
+if (!defined($session)) {
+   printf("ERROR: %s.\n", $error);
+   exit 1;
+}
+
+my %hik_snmp_oids=(
+'.1.3.6.1.4.1.39165.1.5.0'=>'Number',
+'.1.3.6.1.4.1.39165.1.6.0'=>'Vendor',
+'.1.3.6.1.4.1.39165.1.1.0'=>'Model',
+'.1.3.6.1.4.1.39165.1.3.0'=>'Firmware',
+);
+
+my @hik_oids=();
+foreach my $oid (keys %hik_snmp_oids) {
+push (@hik_oids,$oid);
+}
+
+$session->translate(TRANSLATE_NONE);
+
+my $ret = $session->get_request( -varbindlist => [@hik_oids] );
+if (!defined($ret)) {
+   printf("ERROR: %s.\n", $session->error);
+   $session->close;
+   exit 2;
+}
+$session->close;
+
+my $result = '';
+foreach my $oid (keys %hik_snmp_oids) {
+    $result = $result." ".$hik_snmp_oids{$oid}.": ".$ret->{$oid};
+    }
+$result =~s/^\s+//g;
+$result =~s/\s+$//g;
+
+printf("OK : $result\n");
+
+exit 0;

+ 72 - 0
docs/nagios/scripts/plugins/check_snmp_lastbatt

@@ -0,0 +1,72 @@
+#!/usr/bin/perl
+
+use strict;
+
+use Net::SNMP qw(ticks_to_time TRANSLATE_NONE);
+use DateTime;
+use DateTime::Format::Strptime;
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+my $warn_time = 365 * 5;
+
+my $hostip=$ARGV[0];
+my $community = $ARGV[1] || 'public';
+
+my ($session, $error) = Net::SNMP->session(
+   -hostname  => shift || $hostip,
+   -community => shift || $community,
+   -port      => shift || 161,
+   -timeout   => 5,
+);
+
+
+if (!defined($session)) {
+   printf("ERROR: %s.\n", $error);
+   exit 1;
+}
+
+my $inputline = '1.3.6.1.4.1.318.1.1.1.2.1.3.0';
+
+$session->translate(TRANSLATE_NONE);
+
+my $result = $session->get_request(
+   -varbindlist => [$inputline]
+);
+
+if (!defined($result)) {
+   printf("ERROR: %s.\n", $session->error);
+   $session->close;
+   exit 2;
+}
+
+$session->close;
+
+if (!defined($result->{$inputline})) {
+    printf("ERROR: %s.\n", $session->error);
+    $session->close;
+    exit 2;
+    }
+
+my $value = $result->{$inputline};
+
+my ($mm,$dd,$yy) = split(/\//,$value);
+
+if ($yy <2000 ) { $yy+=2000; }
+
+my $date = DateTime->new( year => $yy, month => $mm, day => $dd, time_zone => 'local');
+my $today = DateTime->today(time_zone=>'local');
+my $dur = $date->delta_days($today);
+
+my $timeshift = $dur->in_units('days');
+if ($timeshift > $warn_time) {
+    printf("WARN: The batteries are too old. It's time to change: %s\n", $value);
+    $session->close;
+    exit 1;
+    }
+
+printf("Last Battery Replacement : %s\n",$value);
+
+exit 0;

+ 910 - 0
docs/nagios/scripts/plugins/check_snmp_printer

@@ -0,0 +1,910 @@
+#!/bin/bash
+#########################################################
+#							#
+#		SNMP Printer Check			#
+#							#
+# check_snmp_printer					#
+# 	Version 3.141592 (December 12, 2011)		#
+#							#
+# Authored by Jason Leonard				#
+# 	E-mail: jason_leonard@yahoo.com			#
+#							#
+# Overview						#
+# ----------------------------------------------------- #
+#	This plugin is a rewrite of the SNMP printer	#
+# check provided by Monitoring Solutions. In operating	#
+# the plugin at our environment, I noticed the output	#
+# was combined as one long paragraph when using	the 	#
+# CONSUM ALL option (definitely a favorite of mine).	#
+# While this is in accordance with Nagios plugin dev.	#
+# guidelines, for devices with numerous consumables 	#
+# (like copiers), this makes it difficult to quickly	#
+# find the empty consumable when an alert came in. So I #
+# set out to spruce up the output of the plugin - using #
+# one consumable per line.				#
+#							#
+#	In the process, I also realized the original 	#
+# plugin was more if/then statements than I had seen 	#
+# since my programming class in college. So I made the 	#
+# code a bit cleaner for faster execution. I also had	#
+# add SNMP pre-flight checks, as the original would 	#
+# return OK status to Nagios even if SNMP was broken. 	#
+#							#
+#	Lastly, I decided to rewrite the options and	#
+# add other pre-flight checks that are present in my 	#
+# other plugins. I like to be thorough in making sure 	#
+# the program won't return output if the input is just	#
+# garbage!						#
+#							#
+# NOTE:							#
+#	Because CONSUM ALL uses a multi-line output, 	#
+# you will need to use the $LONGSERVICEOUTPUT$ macro 	#
+# in your service notification commands!		#
+#							#
+# This plugin is distributed under the GNU GPL license.	#
+# You may re-destribute only according to the terms of 	#
+# the GNU GPL v2.					#
+#							#
+#########################################################
+
+#########################################################
+##		     GLOBAL VARIABLES 		       ##
+#########################################################
+APPNAME=$(basename $0)
+VERSION="3.14159"
+COMMUNITY="public"
+EXIT_CODE=0
+EXIT_STRING=""
+
+STRING_TYPE=""
+PERFDAT=""
+CHECK=""
+PARAMETER=""
+
+# Set a warning at 20% of consumable, if not passed
+WARNING=20
+
+# Set a critical at 5% of consumable, if not passed. The standard of 10 
+# seems to be high for most consumables, which move very slowly.
+CRITICAL=5
+
+# Change this to modify the script's handling of how it separates
+# each consumable/tray when multiple checks are output.
+# SEPARATOR="\n"
+SEPARATOR=" "
+
+# This is the character that tokenizes multiple arguments
+# to the TRAY and CONSUM checks. I have this here
+# so it's easy to change if I find the current character
+# I have is buggy or a bad choice
+ARG_TOKEN=","
+
+
+#########################################################
+##		    print_help Function		       ##
+#########################################################
+# Prints out user help and gives examples of proper	#
+# plugin usage						#
+#########################################################
+
+function print_help {
+	echo 'SNMP Printer Check for Nagios'
+	echo ''
+	echo 'This plugin is not developped by the Nagios Plugin group.'
+	echo 'Please do not e-mail them for support on this plugin.'
+	echo ''
+	echo 'For contact info, please read the plugin script file.'
+	echo ''
+	echo "Usage of $APPNAME"
+	echo " $APPNAME -H <host/IP> -C <community> -x <check> [-w] [-c] [-S] | -h | -V "
+	echo '---------------------------------------------------------------------'
+	echo 'Usable Options:'
+	echo '' 
+	echo '	 -C <community>'
+	echo '	     The SNMP Community variable - use the name of your SNMP community with read privileges'
+	echo '	     By default, the community is assumed to be public'
+	echo '	 -H <hostname>'
+	echo '	 (required option)'
+	echo '	     The IP address or hostname of the system to check'
+	echo '	 -S <text string>'
+	echo '	     assign a particular string as the separator for consumables.'
+	echo '	     Default is " " to conform to Nagios plugin development guidelines'
+	echo '	 -w <warn>'
+	echo '       warning threshold (% of consumable remaining)'
+	echo '	 -c <crit>'
+	echo '	     critical threshold (% of consumable remaining)'
+	echo '	 -h'
+	echo '	     show this help screen'
+	echo '	 -V'
+	echo '	     show the current version of the plugin'
+	echo '	 -x <check>'     
+	echo '	 (required option)'
+	echo '	     The check you want to perform for the printer. Choose from the following:'
+	echo ''
+	echo '	         CONSUM {<string> | TEST | ALL}'
+	echo '	 	         <string> will give you all consumables matching the string '
+	echo "	             	For example, 'CONSUM Toner' will only show toner levels"
+	echo '	             TEST will give you the exact names of available consumables'
+	echo '	                 For example,'
+	echo '	                     Black Toner Cartridge HP C4191A'
+	echo '	                 To monitor a consumable, call the function as follows:'
+	echo "	 				    $APPNAME -H <hostname> -C <community> -x \"CONSUM Black\" "
+	echo '	             ALL gives you all consumable output at once.'
+	echo ''
+	echo '	         CONSUMX <string>'
+	echo '	                this gives you results only for the ***EXACT*** consumable specified by <string>'
+	echo '	                     For example, '
+	echo '	                          CONSUMX "Black Toner Cartridge" '
+	echo '	                     will only give you the usage for a consumable named "Black Toner Cartridge". '
+	echo '	                     It will not give you results for "Black Toner Cartridge 1" or "Black Toner". '
+	echo '	         DISPLAY'
+	echo '	                Report contents of printer display'
+	echo ''
+	echo '	         DEVICES'
+	echo '	                Status of hardware modules'
+	echo ''
+	echo '	         MESSAGES'
+	echo '	                Event logs reported by the printer'
+	echo ''
+	echo '	         MODEL'
+	echo '	                ALL will give you all tray output at once.'
+	echo ''
+	echo '	         PAGECOUNT'
+	echo '	                How many pages this printer has processed (culmulative)'
+	echo ''
+	echo '	         STATUS'
+	echo '	                Overall status of the printer'
+	echo ''
+	echo '	         TRAY {<number> | TEST | ALL}'
+	echo '	                <number> will give you output for the specified tray. A comma-separated list of values is possible as well.'
+	echo "	                TEST will give you the #'s of all trays available "
+	echo '	                ALL will give you all tray output at once.'
+	echo ''
+	echo 'Examples:'
+	echo "    $APPNAME -H 10.0.1.10 -C public -x \"CONSUM ALL\" -w 25 -c 10 "
+	echo "    $APPNAME -H 10.0.1.10 -C public -x \"CONSUMX Punch Dust Box\" "
+	echo "    $APPNAME -H 10.0.1.10 -C public -x MODEL "
+	echo "    $APPNAME -H 10.0.1.10 -C public -x \"TRAY 2,3\" "
+	echo "    $APPNAME -V"
+	echo ''
+	echo '---------------------------------------------------------------------'
+
+	return 3
+}
+
+#########################################################
+##		   check_model function		       ##
+#########################################################
+# Returns printer model and serial. Always returns OK 	#
+#########################################################
+
+function check_model(){
+#	Vendor specific items to code here!
+#		possibly serial #
+	MODEL=$(snmpget -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.25.3.2.1.3.1 2>/dev/null)
+	SERIAL=$(snmpwalk -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.5.1.1.17 2>/dev/null | tr -d "\"")
+	
+	EXIT_STRING="$MODEL, Serial # $SERIAL"
+	return 0
+}
+
+#########################################################
+##		  check_messages function	       ##
+#########################################################
+# Shows messages on the printer display. The OID is not #
+# commonly used in all printers				#
+#########################################################
+
+function check_messages(){
+	MESSAGES=$(snmpwalk -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.18.1.1.8 2>/dev/null | tr -d "\"" | tr "\n" "\!")
+	if [ -z "$MESSAGES" ]; then
+		EXIT_STRING="UNKNOWN: Can't determine messages. Device does not support this OID.\n"
+		EXIT_CODE=3
+	else
+		EXIT_STRING="$MESSAGES"
+	fi
+	
+	return $EXIT_CODE
+
+}
+
+#########################################################
+##		 check_page_count function	       ##
+#########################################################
+# Returns pretty-formatted page count for the printer.	#
+# Awesome for tracking historical page usage.		#
+#########################################################
+
+function check_page_count(){
+	PAGE_COUNT=$(snmpget -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.10.2.1.4.1.1 2>/dev/null | sed -e :x -e 's/\([0-9][0-9]*\)\([0-9][0-9][0-9]\)/\1,\2/' -e 'tx')
+	
+	EXIT_STRING="Pagecount is $PAGE_COUNT"
+	PERFDAT="Pages=$PAGE_COUNT;"
+	return 0
+}
+
+
+
+#########################################################
+## 		  check_display function 	       ##
+#########################################################
+#							#
+#########################################################
+
+function check_display(){
+
+	DISPLAY=$(snmpwalk -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.16.5.1.2.1 2>/dev/null | tr -d "\"" )
+
+	# if display is null, we need to let the user know
+	if [ $? -eq 0 ]; then
+		# Let's make sure we eliminate any extra new lines, or at least replace them with our
+		#	specified SEPARATOR (which could be a new line)
+		EXIT_STRING=$(echo "$DISPLAY" | tr "\n" "$SEPARATOR")
+		return 0
+	else
+		# Something happened or this OID isn't available
+		EXIT_STRING="UNKNOWN - printer does not appear to support using this OID."
+		return 3
+	fi
+
+}
+
+#########################################################
+##	        check_printer_status function 	       ##
+#########################################################
+#							#
+#########################################################
+
+function check_printer_status(){
+
+	STATUS_EXIT_CODE=0
+	PRINTER_STATUS=$(snmpget -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.25.3.5.1.1.1 2>/dev/null)
+	
+	case "$PRINTER_STATUS" in
+		"other(1)"|"other"|"1")
+			EXIT_STRING="OK: Printer status is $PRINTER_STATUS"
+			STATUS_EXIT_CODE=0
+		;;
+		"idle(3)"|"idle"|"3")
+			EXIT_STRING="OK: Printer status is $PRINTER_STATUS"
+		;;
+		"printing(4)"|"printing"|"4")
+			EXIT_STRING="OK: Printer status is $PRINTER_STATUS"
+		;;
+		"warmup(5)"|"warmup"|"5")
+			EXIT_STRING="OK: Printer status is $PRINTER_STATUS"
+		;;
+		*)
+			EXIT_STRING="WARNING: Printer status is $PRINTER_STATUS"
+			STATUS_EXIT_CODE=1
+		;;
+	esac
+	
+	return $STATUS_EXIT_CODE
+}
+
+#########################################################
+## 		check_device_status function 	       ##
+#########################################################
+#							#
+#########################################################
+
+function check_device_status(){
+
+	CURRENT_EXIT_CODE=0
+	CURRENT_STATUS=0
+	DEVICE_STATUS=""
+	DEVICE_NAME=""
+	DEVICE_IDS=$(snmpwalk -v1 -On -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.25.3.2.1.1 2>/dev/null)
+
+	# create this around a for loop on id's, which come from .1.3.6.1.2.1.25.3.2.1.1.x
+	for ID in $(echo $DEVICE_IDS | egrep -oe '[[:digit:]]+\ =' | cut -d " " -f1)
+	do
+		DEVICE_NAME=$(snmpget -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.25.3.2.1.3.$ID 2>/dev/null)
+		EXIT_STRING="$EXIT_STRING$DEVICE_NAME status is "
+		
+		DEVICE_STATUS=$(snmpget -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.25.3.2.1.5.$ID 2>/dev/null)
+
+		case "$DEVICE_STATUS" in
+			"unknown(1)")
+				EXIT_STRING="$EXIT_STRING$DEVICE_STATUS - WARNING!$SEPARATOR"
+				CURRENT_STATUS=1
+			;;
+			"running(2)")
+				EXIT_STRING="$EXIT_STRING$DEVICE_STATUS - OK!$SEPARATOR"
+			;;
+			"warning(3)")
+				EXIT_STRING="$EXIT_STRING$DEVICE_STATUS - WARNING!$SEPARATOR"
+				CURRENT_STATUS=1
+			;;
+			"testing(4)")
+				EXIT_STRING="$EXIT_STRING$DEVICE_STATUS - OK!$SEPARATOR"
+			;;
+			"down(5)")
+				EXIT_STRING="$EXIT_STRING$DEVICE_STATUS - CRITICAL!$SEPARATOR"
+				CURRENT_STATUS=2
+			;;
+			*)
+				EXIT_STRING="$EXIT_STRING$DEVICE_STATUS - WARNING!$SEPARATOR"
+				CURRENT_STATUS=1
+			;;
+		esac
+		
+		if [ "$CURRENT_STATUS" -gt "$CURRENT_EXIT_CODE" ]; then
+			CURRENT_EXIT_CODE="$CURRENT_STATUS"
+		fi
+
+	done
+	
+	return $CURRENT_EXIT_CODE
+
+} 
+
+#########################################################
+##	      check_one_consumable function	       ##
+#########################################################
+# Given the marker's ID (1, 2, 3, etc.), this function	#
+# grabs the consmable string for that ID, converts it 	#
+# to a name and determines capacity and status code for	#
+# it.							#
+#							#
+# Only status code is returned. Global string variables #
+# are used for printing and other functionality.	#
+#########################################################
+
+function check_one_consumable () {
+
+	local CONSUM_EXIT_CODE=0
+	CURRENT_CAPACITY=0
+	MAX_CAPACITY=0
+	MARKER_NAME=""
+	MARKER_COLOR=""
+	MARKER_STRING=$(snmpget -v1 -On -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.11.1.1.6.1.$1 2>/dev/null)
+
+	# We'll be parsing our name differently depending on whether we have Hex-String or not
+	if [ "$STRING_TYPE" == "Hex-STRING:" ]; then
+		MARKER_NAME=$(echo "$MARKER_STRING" | cut -d ":" -f2- | tr -d "\n" | xxd -r -p)
+	else
+		MARKER_NAME=$(echo "$MARKER_STRING" | cut -d " " -f4- | tr -d "\"")
+	fi
+
+	# Some manufacturers don't put the actual cartridge color in the above OID text for 
+	#	MARKER_STRING. Instead, each entry just says "toner". The OID used here is 
+	#	a place where an associated color string must be stored. We are going to get this 
+	#	info. and use it if not already available in the MARKER_NAME we've parsed.
+	# --- Thanks to Martin Љoltis for letting me know about this problem on some copiers.
+	GETCOLOR=$(snmpget -v1 -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.12.1.1.4.1.$1 2>/dev/null)
+	MARKER_COLOR=$(echo $GETCOLOR | cut -d " " -f4- | tr -d "\"")
+	
+	# We're just checking here to see if the consumable already has this color in its text description
+	if [ $(echo "$MARKER_NAME" | grep -vqi "$MARKER_COLOR") ]; then
+		# It doesn't, so we're going to add it
+		MARKER_NAME="$MARKER_COLOR $MARKER_NAME"
+	fi
+
+	# As usual, if the results are an empty set, something went wrong or didn't match up
+	if [ -z "$MARKER_NAME" ]; then 
+		EXIT_STRING="UNKNOWN - OID not found! Your printer may not support checking this consumable."
+		EXIT_STRING="$EXIT_STRING Use the CONSUM TEST option to determine which consumables may be monitored."
+		PERFDAT=""
+		CONSUM_EXIT_CODE=3
+	else
+		# Determine capacities for the current marker
+		CURRENT_CAPACITY=$(snmpget -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.11.1.1.9.1.$1 2>/dev/null)
+		MAX_CAPACITY=$(snmpget -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.11.1.1.8.1.$1 2>/dev/null)
+		if [ "$MAX_CAPACITY" -lt 0 ]; then
+			MAX_CAPACITY=0
+		fi
+		
+		# the component does not have a measurable status indication
+		case "$CURRENT_CAPACITY" in
+			"-3") # A value of (-3) means that the printer knows that there is some supply/remaining space
+				EXIT_STRING="$EXIT_STRING$MARKER_NAME is OK!$SEPARATOR"
+			;;
+			"-2") # The value (-2) means unknown
+				EXIT_STRING="$EXIT_STRING$MARKER_NAME is at WARNING level!$SEPARATOR"
+				if [ "$CONSUM_EXIT_CODE" -lt 1 ]; then
+					CONSUM_EXIT_CODE=1
+				fi
+			;;
+			"0") # Something is empty!
+				EXIT_STRING="$EXIT_STRING$MARKER_NAME is at CRITICAL level!$SEPARATOR"
+				CONSUM_EXIT_CODE=2
+			;;
+			*) # A positive value means this is a measurable component - let's report it's status code and let user know the % usage
+				let "CURRENT_CAPACITY=$CURRENT_CAPACITY * 100 / $MAX_CAPACITY"
+				if [ "$CURRENT_CAPACITY" -gt "$WARNING" ]; then 
+					EXIT_STRING="$EXIT_STRING$MARKER_NAME is at $CURRENT_CAPACITY%% - OK!$SEPARATOR"
+				else 
+					if [ "$CURRENT_CAPACITY" -le "$WARNING" ] && [ "$CURRENT_CAPACITY" -gt "$CRITICAL" ]; then
+						EXIT_STRING="$EXIT_STRING$MARKER_NAME is at $CURRENT_CAPACITY%% - WARNING!$SEPARATOR"
+						if [ "$CONSUM_EXIT_CODE" -lt 1 ]; then
+							CONSUM_EXIT_CODE=1
+						fi
+					else 
+						if [ "$CURRENT_CAPACITY" -le "$CRITICAL" ]; then
+							EXIT_STRING="$EXIT_STRING$MARKER_NAME is at $CURRENT_CAPACITY%% - CRITICAL!$SEPARATOR"
+							CONSUM_EXIT_CODE=2
+						fi
+					fi
+				fi						
+			;;
+		esac	
+		
+		PERFDAT="$PERFDAT $MARKER_NAME=$CURRENT_CAPACITY;$WARNING;$CRITICAL;"
+		
+	fi
+	
+	return $CONSUM_EXIT_CODE
+				
+}
+
+#########################################################
+##	      check_exact_consumable function	       ##
+#########################################################
+# Loops through all consumables and compares the string #
+# passed to the consumable string. If a match is found, #
+# we calculate and output capacity and status. If a	#
+# match is not found, let the user know.		#
+#							#
+# Global string variables are used for printing status 	#
+# and perf data.					#
+#########################################################
+
+function check_exact_consumable(){
+
+	local CONSUMX_EXIT_CODE=0
+	FOUND=false
+	FOUND_MARKER=0
+	
+	# Now we can loop through everything that matched
+	for MARKER_ID in $(echo "$ALL_MARKERS" | egrep -oe '[[:digit:]]+\ =' | cut -d " " -f1)
+	do
+		MARKER_STRING=$(snmpget -v1 -On -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.11.1.1.6.1.$MARKER_ID 2>/dev/null)
+
+		# We'll be parsing our name differently depending on whether we have Hex-String or not
+		if [ "$STRING_TYPE" == "Hex-STRING:" ]; then
+			MARKER_NAME=$(echo "$MARKER_STRING" | cut -d ":" -f2- | tr -d "\n" | xxd -r -p)
+		else
+			MARKER_NAME=$(echo "$MARKER_STRING" | cut -d " " -f4- | tr -d "\"")
+		fi
+
+		# Update our boolean if we find a match!
+		if [ "$1" == "$MARKER_NAME" ]; then
+			FOUND=true
+			FOUND_MARKER="$MARKER_ID"
+		fi
+
+	done
+
+	if $FOUND; then
+		# Determine capacities for the marker of the matching consumable
+		X_CURRENT_CAPACITY=$(snmpget -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.11.1.1.9.1.$FOUND_MARKER 2>/dev/null)
+		MAX_CAPACITY=$(snmpget -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.11.1.1.8.1.$FOUND_MARKER 2>/dev/null)
+		if [ "$MAX_CAPACITY" -lt 0 ]; then
+			MAX_CAPACITY=0
+		fi
+		
+		# the component does not have a measurable status indication
+		case "$X_CURRENT_CAPACITY" in
+			"-3") # A value of (-3) means that the printer knows that there is some supply/remaining space
+				EXIT_STRING="$EXIT_STRING$1 is OK!\n"
+			;;
+			"-2") # The value (-2) means unknown
+				EXIT_STRING="$EXIT_STRING$1 is at WARNING level!$SEPARATOR"
+				if [ "$CONSUMX_EXIT_CODE" -lt 1 ]; then
+					CONSUMX_EXIT_CODE=1
+				fi
+			;;
+			"0") # Something is empty!
+				EXIT_STRING="$EXIT_STRING$1 is at CRITICAL level!$SEPARATOR"
+				CONSUMX_EXIT_CODE=2
+			;;
+			*) # A positive value means this is a measurable component - let's report it's status code and let user know the % usage
+				let "X_CURRENT_CAPACITY=$X_CURRENT_CAPACITY * 100 / $MAX_CAPACITY"
+				if [ "$X_CURRENT_CAPACITY" -gt "$WARNING" ]; then 
+					EXIT_STRING="$EXIT_STRING$1 is at $X_CURRENT_CAPACITY%% - OK!$SEPARATOR"
+				else 
+					if [ "$X_CURRENT_CAPACITY" -le "$WARNING" ] && [ "$X_CURRENT_CAPACITY" -gt "$CRITICAL" ]; then
+						EXIT_STRING="$EXIT_STRING$1 is at $X_CURRENT_CAPACITY%% - WARNING!$SEPARATOR"
+						if [ "$CONSUMX_EXIT_CODE" -lt 1 ]; then
+							CONSUMX_EXIT_CODE=1
+						fi
+					else 
+						if [ "$X_CURRENT_CAPACITY" -le "$CRITICAL" ]; then
+							EXIT_STRING="$EXIT_STRING$1 is at $X_CURRENT_CAPACITY%% - CRITICAL!$SEPARATOR"
+							CONSUMX_EXIT_CODE=2
+						fi
+					fi
+				fi						
+			;;
+		esac
+		PERFDAT="$PERFDAT $1=$X_CURRENT_CAPACITY;$WARNING;$CRITICAL;"
+	else
+		# Let the user know we didn't find anything, and report back the string they sent. Also prompt them to run the TEST option to double-check their string
+		EXIT_STRING="UNKNOWN - No match found for '$1'! Use the CONSUM TEST option to determine which consumables may be monitored.\n"
+		CONSUMX_EXIT_CODE=3
+	fi
+		
+	return $CONSUMX_EXIT_CODE
+
+}
+
+#########################################################
+##		check_consumables function	       ##
+#########################################################
+# Determines which consumables to check and then pass 	#
+# them all off to check_one_consumable			#
+#							#
+# Global string variables are used for printing status 	#
+# and perf data.					#
+#########################################################
+
+function check_consumables(){
+
+	local CONSUMS_EXIT_CODE=0
+	HEX_ID=0
+	CURRENT_STATUS=0
+	HEX_MARKER=""
+	ASCII_MARKER=""
+	MARKERS_MATCHED=""
+
+	case "$1" in
+		"TEST")	# User passed "TEST" parameter - output what consumables are available
+			printf "Consumables you may monitor:\n"
+			
+			if [ "$STRING_TYPE" == "Hex-STRING:" ]; then
+				for HEX_ID in $(echo "$ALL_MARKERS" | egrep -oe '[[:digit:]]+\ =' | cut -d " " -f1)
+				do
+					HEX_MARKER=$(snmpget -v1 -On -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.11.1.1.6.1.$HEX_ID 2>/dev/null)
+					ASCII_MARKER=$(echo "$HEX_MARKER" | cut -d ":" -f2 | tr -d "\n" | xxd -r -p)
+					EXIT_STRING="$EXIT_STRING$ASCII_MARKER\n"
+				done
+			else
+				EXIT_STRING=$(snmpwalk -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.11.1.1.6.1 2>/dev/null)
+			fi
+			
+			CONSUMS_EXIT_CODE=3
+		;;
+		"ALL") # User passed ALL parameter - check everything!
+			# Let's loop through all consumables available
+			for MARKER_ID in $(echo "$ALL_MARKERS" | egrep -oe '[[:digit:]]+\ =' | cut -d " " -f1)
+			do
+				check_one_consumable "$MARKER_ID"
+				CURRENT_STATUS=$?
+				
+				if [ "$CURRENT_STATUS" -gt "$CONSUMS_EXIT_CODE" ]; then
+					CONSUMS_EXIT_CODE="$CURRENT_STATUS"
+				fi
+			done
+		;;
+		*) # A string was passed, on which we will match to available consumable strings
+			if [ "$STRING_TYPE" == "Hex-STRING:" ]; then
+				# If our printer uses Hex-STRING fields, we need to convert our user's string to hex first
+				HEX_STRING=$(echo "$1" | tr -d "\n" | xxd -p -u)
+				
+				# Now that we have a hex string for the user string, we need look for it in output that is formatted similarly 
+				#	XXD -p doesn't output spaces, but the Hex-STRING fields do use spaces between each byte
+				MARKERS_MATCHED=$(echo "$ALL_MARKERS" | tr -d " " | egrep -i "$HEX_STRING")
+			else
+				MARKERS_MATCHED=$(echo "$ALL_MARKERS" | egrep -i "$1")
+			fi
+
+			if [ -z "$MARKERS_MATCHED" ]; then
+				EXIT_STRING="UNKNOWN - OID not found! Your printer may not support checking this consumable."
+				EXIT_STRING="$EXIT_STRING Use the CONSUM TEST option to determine which consumables may be monitored."
+				PERFDAT=""
+				EXIT_CODE=3
+			else
+				# Now we can loop through everything that matched
+				for MARKER_ID in $(echo "$MARKERS_MATCHED" | cut -d "=" -f1 | cut -d "." -f14)
+				do
+					check_one_consumable "$MARKER_ID"
+
+					CURRENT_STATUS=$?
+					
+					if [ "$CURRENT_STATUS" -gt "$CONSUMS_EXIT_CODE" ]; then
+						CONSUMS_EXIT_CODE="$CURRENT_STATUS"
+					fi
+				done
+			fi
+		;;
+	esac
+	
+	return $CONSUMS_EXIT_CODE
+
+}
+
+#########################################################
+##		  check_one_tray Function	       ##
+#########################################################
+# Checks the tray #, as passed by parameter. If found,	#
+# it returns the status and capacity. 			#
+#							#
+# Only status code is returned. Global string variables #
+# are used for printing and other functionality.	#
+#########################################################
+
+function check_one_tray (){
+
+	TRAY_EXIT_CODE=0
+	TRAY_CAPACITY=0
+	TRAY_MAX_CAPACITY=0
+	TRAY_FEED_DIMENSION=0
+	TRAY_XFEED_DIMENSION=0
+	TRAY_DIMENSION_UNITS=0
+	
+	TRAY_CAPACITY=$(snmpwalk -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.8.2.1.10.1.$1 2>/dev/null)
+	if [ -z "$TRAY_CAPACITY" ]; then
+		EXIT_STRING="$EXIT_STRING UNKNOWN - Tray $1 not found. Use the TRAY TEST option to determine which trays may be monitored.\n"
+		TRAY_EXIT_CODE=3
+	else
+		# Determine information about the tray
+		TRAY_NAME=$(snmpwalk -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.8.2.1.13.1.$1 2>/dev/null)
+		
+		# Some manufacturers do not set the tray name OID, so we'll assume a generic name depending on the # passed to the function
+		if [ "$TRAY_NAME"=="" ]; then
+			TRAY_NAME="Tray $1"
+		fi
+		
+		case "$TRAY_CAPACITY" in
+			"-3") # The value (-3) means that the printer knows that at least one unit remains.
+				EXIT_STRING="$EXIT_STRING$TRAY_NAME is OK!$SEPARATOR"
+			;;
+			"-2") # The value (-2) means unknown
+				EXIT_STRING="$EXIT_STRING$TRAY_NAME status is UNKNOWN!$SEPARATOR"
+				TRAY_EXIT_CODE=3
+			;;
+			"0") # 0 means there is no paper left! This is our only critical value.
+				# Determine paper size of current tray
+				TRAY_FEED_DIMENSION=$(snmpwalk -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.8.2.1.4.1.$1 2>/dev/null)
+				TRAY_XFEED_DIMENSION=$(snmpwalk -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.8.2.1.5.1.$1 2>/dev/null)
+				TRAY_DIMENSION_UNITS=$(snmpwalk -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.8.2.1.3.1.$1 2>/dev/null)
+
+				if [ "$TRAY_FEED_DIMENSION" -lt 0 ] && [ "$TRAY_XFEED_DIMENSION" -lt 0 ]; then
+					# If either dimension was negative, then we really don't know much about the dimension
+					TRAY_DIMENSION_STRING="paper."
+				else
+			
+					case "$TRAY_DIMENSION_UNITS" in
+						"3") # convert ten thousandths of an inch to inches
+						TRAY_FEED_DIMENSION=$(echo "scale=1;$TRAY_FEED_DIMENSION/10000" | bc)
+						TRAY_XFEED_DIMENSION=$(echo "scale=1;$TRAY_XFEED_DIMENSION/10000" | bc)
+						;;
+						"4") # convert micrometers to inches, and get the int portion
+						TRAY_FEED_DIMENSION=$(echo "scale=1;$TRAY_FEED_DIMENSION*0.0000393700787" | bc)
+						TRAY_FEED_DIMENSION=$(echo "scale=1;$TRAY_FEED_DIMENSION+0.5" | bc)
+						TRAY_FEED_DIMENSION=$(echo "scale=1;$TRAY_FEED_DIMENSION/1" | bc)
+
+						TRAY_XFEED_DIMENSION=$(echo "scale=1;$TRAY_XFEED_DIMENSION*0.0000393700787" | bc)
+						TRAY_XFEED_DIMENSION=$(echo "scale=1;$TRAY_XFEED_DIMENSION+0.5" | bc)
+						TRAY_XFEED_DIMENSION=$(echo "scale=1;$TRAY_XFEED_DIMENSION/1" | bc)
+						;;
+					esac
+
+					TRAY_DIMENSION_STRING="$TRAY_XFEED_DIMENSION x $TRAY_FEED_DIMENSION paper."
+				fi
+
+				EXIT_STRING="$EXIT_STRING$TRAY_NAME is at CRITICAL level - please refill with more $TRAY_DIMENSION_STRING$SEPARATOR"
+				TRAY_EXIT_CODE=2
+			;;
+			*) # A positive number indicates how many pages are left. We'll calculate what % of capacity this is and determine status
+				TRAY_MAX_CAPACITY=$(snmpwalk -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.8.2.1.9.1.$1 2>/dev/null )
+				let "TRAY_CAPACITY = $TRAY_CAPACITY * 100 / $TRAY_MAX_CAPACITY"
+					
+				if [ "$TRAY_CAPACITY" -gt "$CRITICAL" ]; then
+					EXIT_STRING="$EXIT_STRING$TRAY_NAME is at $TRAY_CAPACITY%% - OK!$SEPARATOR"
+				else
+					if [ "$TRAY_CAPACITY" -le "$WARNING" ]; then
+						# Determine paper size of current tray
+						TRAY_FEED_DIMENSION=$(snmpwalk -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.8.2.1.4.1.$1 2>/dev/null )
+						TRAY_XFEED_DIMENSION=$(snmpwalk -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.8.2.1.5.1.$1 2>/dev/null )
+						TRAY_DIMENSION_UNITS=$(snmpwalk -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.8.2.1.3.1.$1 2>/dev/null )
+						if [ "$TRAY_FEED_DIMENSION" -lt 0 ] && [ "$TRAY_XFEED_DIMENSION" -lt 0 ]; then
+							# If either dimension was negative, then we really don't know much about the dimension
+							TRAY_DIMENSION_STRING="paper."
+						else
+							case "$TRAY_DIMENSION_UNITS" in
+								"3") # convert ten thousandths of an inch to inches
+								TRAY_FEED_DIMENSION=$(echo "scale=1;$TRAY_FEED_DIMENSION/10000" | bc)
+								TRAY_XFEED_DIMENSION=$(echo "scale=1;$TRAY_XFEED_DIMENSION/10000" | bc)
+								;;
+								"4") # convert micrometers to inches, and get the int portion
+								TRAY_FEED_DIMENSION=$(echo "scale=1;$TRAY_FEED_DIMENSION*0.0000393700787" | bc)
+								TRAY_FEED_DIMENSION=$(echo "scale=1;$TRAY_FEED_DIMENSION+0.5" | bc)
+								TRAY_FEED_DIMENSION=$(echo "scale=1;$TRAY_FEED_DIMENSION/1" | bc)
+
+								TRAY_XFEED_DIMENSION=$(echo "scale=1;$TRAY_XFEED_DIMENSION*0.0000393700787" | bc)
+								TRAY_XFEED_DIMENSION=$(echo "scale=1;$TRAY_XFEED_DIMENSION+0.5" | bc)
+								TRAY_XFEED_DIMENSION=$(echo "scale=1;$TRAY_XFEED_DIMENSION/1" | bc)
+								;;
+							esac
+									
+							TRAY_DIMENSION_STRING="$TRAY_XFEED_DIMENSION x $TRAY_FEED_DIMENSION paper."
+						fi
+						
+						if [ "$TRAY_CAPACITY" -le "$CRITICAL" ]; then
+							# we have a critical: we already know the value is less than warning
+							EXIT_STRING="$EXIT_STRING$TRAY_NAME is at $TRAY_CAPACITY%% - CRITICAL! Please refill with more $TRAY_DIMENSION_STRING$SEPARATOR"
+							TRAY_EXIT_CODE=2
+						else
+							# we are only below warning, but not yet below critical
+							EXIT_STRING="$EXIT_STRING$TRAY_NAME is at $TRAY_CAPACITY%% - WARNING! Please refill with more $TRAY_DIMENSION_STRING$SEPARATOR"
+							if [ "$TRAY_EXIT_CODE" -lt 1 ]; then
+								TRAY_EXIT_CODE=1
+							fi
+						fi
+					fi
+				fi
+				
+				PERFDAT="$PERFDAT $TRAY_NAME=$TRAY_CAPACITY;$WARNING;$CRITICAL;"
+			;;
+		esac
+		
+	fi
+
+	return $TRAY_EXIT_CODE
+
+}
+
+#########################################################
+##		check_paper_trays Function	       ##
+#########################################################
+# Determines which trays to check and passes each check	#
+# off to check_one_tray.				#
+#							#
+# Global string variables are used for printing status 	#
+# and perf data.					#
+#########################################################
+
+function check_paper_trays (){
+
+	TRAYS_EXIT_CODE=0
+	ALL_TRAYS=$(snmpwalk -v1 -On -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.8.2.1.10.1 2>/dev/null)
+	CURRENT_TRAY_STATUS=0
+	
+	case "$1" in
+		"TEST")
+			echo "Trays you may monitor:"
+			echo "$(echo "$ALL_TRAYS" | egrep -oe '[[:digit:]]+\ =' | cut -d " " -f1)"
+			TRAYS_EXIT_CODE=3
+		;;
+		"ALL") # let's check all trays!
+			for TRAY_ID in $(echo "$ALL_TRAYS" | egrep -oe '[[:digit:]]+\ =' | cut -d " " -f1)
+			do
+				check_one_tray "$TRAY_ID"
+				CURRENT_TRAY_STATUS=$?
+				
+				if [ "$CURRENT_TRAY_STATUS" -gt "$TRAYS_EXIT_CODE" ]; then
+					TRAYS_EXIT_CODE="$CURRENT_TRAY_STATUS"
+				fi
+			done
+		;;
+		*) 
+			for TRAY_ID in $(echo "$1" | tr "$ARG_TOKEN" "\n")
+			do
+				check_one_tray "$TRAY_ID"
+				CURRENT_TRAY_STATUS=$?
+				
+				if [ "$CURRENT_TRAY_STATUS" -gt "$TRAYS_EXIT_CODE" ]; then
+					TRAYS_EXIT_CODE="$CURRENT_TRAY_STATUS"
+				fi
+			done
+		;;
+	esac
+	
+	return $TRAYS_EXIT_CODE
+	
+}
+
+#########################################################
+##			MAIN CODE		       ##
+#########################################################
+
+# Check that all required binaries for the script are available
+# 	EXIT with an UNKNOWN status if not
+binaries="snmpwalk snmpget bc egrep xxd"
+
+for required_binary in $binaries; 
+do
+	which $required_binary > /dev/null
+	if [ "$?" != '0' ];then
+		printf "UNKNOWN: $APPNAME: No usable '$required_binary' binary in '$PATH'\n"
+		exit 3
+	fi
+done
+
+# Parse our options as passed, and make sure things are peachy
+while getopts "C:H:c:w:x:S:hV" OPTION;
+do
+	case $OPTION in
+		"C") # Assign community
+			COMMUNITY="$OPTARG"
+		;;
+		"H") # Assign hostname
+			HOST_NAME="$OPTARG"
+		;;
+		"c") # Assign CRITICAL threshold
+			CRITICAL="$OPTARG"
+		;;
+		"w") # Assign WARNING threshold
+			WARNING="$OPTARG"
+		;;
+		"x") # Assign check to perform
+			CHECK=$(echo "$OPTARG" | cut -d " " -f1)
+			PARAMETER=$(echo "$OPTARG" | cut -d " " -f2-)
+		;;
+		"S") # Assign separator
+			SEPARATOR="$OPTARG"
+		;;
+		"h") # Print application help
+			print_help
+			exit $?
+		;;
+		"V") # Print application version
+			printf "$APPNAME - version $VERSION\n"
+			exit $EXIT_CODE
+		;;
+	esac
+done
+
+# Make sure all necessary arguments were given; EXIT with an UNKNOWN status if not
+if [ -z "$COMMUNITY" ] || [ -z "$HOST_NAME" ];then
+	# we need these parameters to continue
+	EXIT_STRING="UNKNOWN: Hostname and/or Community variables have not been set!\n"
+	EXIT_CODE=3
+else
+	ALL_MARKERS=$(snmpwalk -v1 -On -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.11.1.1.6.1 2>/dev/null)
+	if [ $? -ne 0 ]; then
+		#Check for server response - is SNMP even setup okay?
+		EXIT_STRING="WARNING: No SNMP response from $HOST_NAME! Make sure host is up and SNMP is configured properly.\n"
+		EXIT_CODE=1
+	else
+		STRING_TYPE=$(echo "$ALL_MARKERS" | tr -d "\n" | cut -d " " -f3)
+		case "$CHECK" in
+			"MESSAGES") 
+				check_messages
+				;;
+			"MODEL") 
+				check_model
+				;;
+			"CONSUM") 
+				check_consumables "$PARAMETER"
+				;;
+			"CONSUMX") 
+				check_exact_consumable "$PARAMETER"
+				;;
+			"TRAY") 
+				check_paper_trays "$PARAMETER"
+				;;
+			"PAGECOUNT") 
+				check_page_count
+				;;
+			"DEVICES") 
+				check_device_status
+				;;
+			"STATUS") 
+				check_printer_status
+				;;
+			"DISPLAY") 
+				check_display
+				;;
+			*) # no parameters were passed, or a parameter was incorrect (wrong spelling, etc.)
+				echo 'Invalid check specified by -x parameter.'
+				echo ''
+				print_help
+				;;
+		esac	
+
+		EXIT_CODE=$?
+	fi
+fi
+
+# If the program hasn't exited already, then a check was run okay and we can quit.
+if [ "$PERFDAT" == "" ]; then
+	printf "$EXIT_STRING\n"
+else
+	printf "$EXIT_STRING|$PERFDAT\n"
+fi
+
+exit $EXIT_CODE

+ 899 - 0
docs/nagios/scripts/plugins/check_snmp_temperature

@@ -0,0 +1,899 @@
+#!/usr/bin/perl
+#
+# ============================== SUMMARY =====================================
+#
+# Program : check_snmp_temperature.pl
+# Version : 0.41
+# Date    : Mar 23, 2012
+# Author  : William Leibzon - william@leibzon.org
+# Summary : This is a nagios plugin that checks temperature sensors
+#           using SNMP. Dell, HP, Cisco and other types are supported
+#	    and for other systems OIDs can be easily specified too
+# Licence : GPL - summary below, text at http://www.fsf.org/licenses/gpl.txt
+#
+# =========================== PROGRAM LICENSE =================================
+#
+# 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+# ===================== INFORMATION ABOUT THIS PLUGIN =========================
+#
+# This Temperature check plugin that retreives temperature sensor values from
+# SNMP and can issue alerts if selected parameters are above given number
+# It also returns performance data for further nagios 2.0 post-processing
+#
+# This program is written and maintained by:
+#   William Leibzon - william(at)leibzon.org
+# It is partially based on check_snmp_* plugins by:
+#   Patrick Proy (patrick at proy.org)
+#
+# ============================= SETUP NOTES ====================================
+#
+# Make sure to check and if necessary adjust the the path to utils.pm
+# Make sure you have Net::SNMP perl module installed
+#
+# If you want to check Dell servers, HP server, Juniper routers or
+# Cisco Switches/Routers (cisco 7500, 5500, 2948) then you may skip
+# much of the configuration hassles and use pre-programmed settings
+# by using "--type" (or -T) parameter, you do still need to specify
+# though if you want output as C or F with '-o' option (see examples). 
+# The plugin currently does not support finding critical & warning
+# thresholds which most systems also report in SNMP, so actual thresholds
+# you will need to specify as well.
+#
+# NOTE: If you've previously used 0.2x version of this plugin to
+# 	check HP equipment, beware that 0.3 version has "incompatible"
+#	change in that it returns human-readable sensor names rather
+#       then using HP locale ids to enumerate sensors. If you need
+#	old behavior then instead of using '-T hp' as parameter
+#	use '-N 1.3.6.1.4.1.232.6.2.6.8.1.3 -D 1.3.6.1.4.1.232.6.2.6.8.1.4'
+#
+# If you're using some other device then you need to check documentation to
+# figure out correct parameters for this plugin, then specify base temperature
+# sensor names table OID with '-N' and values table OID with '-D. You also need
+# to specify what base sensor temperature data type is with "-i" (see below).
+#
+# The way plugin works is to walk the snmp tree from base names OID and find
+# all the sensor names. Then it compares names given with '-a' (names are 
+# seperated by ',') to those found in the snmp tree (in '-a' you're expected
+# to specify one word which would be found in the full sensor name and
+# is unique for thaqt `sensor) and uses OID ending (i.e. part of OID after 
+# the base) and adds it to base value table OID to create OID to be retrieved
+# (similar to how you find ethernet statistics OIDs based on name of the
+# interface and in fact many of SNMP parameters are like that).
+#
+# Note: If you don't know temperature sensor names on your system do:
+#         check_snmp_temperature -v -A '*' ...
+#       (using '-v' option forces debugging output that should further help)
+#
+# If your system does not have table with sensor names you can still use
+# this plugin if you know exact temperature data OIDs. Then you specify list
+# of names sensors should be known by with '-n' option and list of data OIDs
+# with '-d' option (this can also be useful if you want to avoid having plugin
+# do snmp table walk each time as retrieving specific list of OIDs is faster).
+# You will still need to specify what is likely the same sensor names you
+# you put in '-n' with '-a' or '-A' option.
+#
+# Request: If you have an new type of device and as per above you figured
+#          out SNMP parameters that work, please send me email with this
+#          information so that I can add it as a new system type.
+#
+# The values retrieved are compared to specified warning and critical values, 
+# but first the temperature has to be converted from base measurement units to
+# measurement units you want. These units are Celsius (C) or Fahrenheit (F)
+# or Kelvin (K) with input measurement unit specified with '-i' and output
+# specified with '-o'. For input you sometimes have situation where sensor
+# reports 10xRealValue, i.e. 33.5C is reported as 335 - this is supported
+# too and then input type is specified as '-i 10C'.
+#
+# Warning and critical values are specified with '-w' and '-c' and each
+# one must have exact same number of values (separated by ',') as number
+# of sensor names specified with '-a'. Any values you dont want to compare
+# you specify as 0 or just not specify (i.e. -w ',50,'). In some cases you
+# might not get data for specific sensor and want to substitute default
+# value - this is supported with '-u' option (note that default values
+# is in fact compared against -w and -c).
+#
+# Additionally if you want performance output then use '-f' option to get all
+# the sensors specified in '-a' or specify particular list of sensors for
+# performance data with '-A' (this list can include names not found in '-a').
+# A special option of -A '*' will allow to get data from all sensors found
+# and is this very useful to find what sensors you have with manual run.
+#
+# ========================= SETUP EXAMPLES ==================================
+#
+# define command {
+#        command_name check_cisco_temperature
+#        command_line $USER1$/check_snmp_temperature.pl -f -H $HOSTADDRESS$ --type=cisco1 -o F -C $ARG1$ -a $ARG2$ -w $ARG3$ -c $ARG4$
+# }
+#
+# define service{
+#       use                             std-service
+#       hostgroup_name                  cs2948
+#       service_description             Temperature
+#       check_command                   check_cisco_temperature!foo!Chassis!160!190
+# }
+#
+# define command{
+# 	command_name check_dell_temperature
+#  	command_line $USER1$/check_snmp_temperature.pl -H $HOSTADDRESS$ -C public \
+#    		-N .1.3.6.1.4.1.674.10892.1.700.20.1.8 \
+#    		-D .1.3.6.1.4.1.674.10892.1.700.20.1.6 -i 10C -o F -u 0 \
+#    		-a ARG1$ -w $ARG2$ -c $ARG3$ -f
+# }
+#
+# define service {
+#  	use                     std-service
+#  	hostgroup_name          dell_1750
+#  	service_description     Temperature
+#	check_command		check_dell_temperature!CPU,Ambient,Bottom!110,90,0!135,110,0
+# }
+#
+# For some dell systems with all sensors enabled you can replace the above with:
+#       check_command           check_temperature!'CPU,PROC_1,PROC_2,Ambient,Bottom,BMC Planar,BMC Riser'!110,120,120,90,90,105,105!135,140,140,110,110,125,125
+#
+# ==================== CHANGES/RELEASE, TODO  ==================================
+#
+# 0.1  - ??? 2006 : Simple plugin where temperature table OIDs were to be
+#		    specified directly as parameter. Was used for checking Dell
+# 0.2  - Aug 2006 : Support multiple types of equipment by using config
+#		    hash/array and --type parameter
+# 0.21 - Dec 2006 : Added support for Juniper and HP 
+# 0.22 - Dec 2006 : Added quick hack to interpret 0 value as "dont' check" threshold
+# 0.23 - Dec 2007 : Bug Fixes (especially one involving F as input format)
+# 0.3  - Jan 2008 : Added '-n' and '-d' options to specify exact list of
+#                   sensor names and oids.
+#		    Also when you specify 'hp' type, the plugin will now
+#		    provide human-readable sensor names rather then purely
+#                   an id of their sensor locale (this is basicly special
+#                   hack just for HP since I don't know anyone else who
+#                   hard-coded sensor names by ids into SNMP MIB).
+# 0.31 - Feb 2008 : Bug fix due to report by Michael Timmers. The issue
+#                   was with sensor list that contains a name which matches
+#                   by regex with some other later sensor name. In this
+#                   case it was Juniper with "Routing Engine" which was
+#                   followed by "Routing Engine PCMCIA Card 0" sensor.
+# 0.32 - May 2008 : Minor bug fixes. Added baytech pdu SNMP OIDs
+# 0.33 - Aug 2008 : Full SNMPv3 support (contrib patch by Nicolas Deffayet)
+# 0.34 - Dec 2011 : Bug and small documentation fixes
+# 0.35 - Jan 2012 : Added reporting warning and critical threshold to
+#		    performance output (as 'name=temperature;warn;crit'
+#		    based on what become nagios standard for this info)
+# 		    Documentation history and todo updates (added 0.1 & 0.2
+#		    versions from below info to above), updated on todo
+# 0.36 - Jan 2012 : If data is missing return "UNKNOWN"
+#		    Added linux 'lmsensors' as type of device
+#		    In order to suppot this you need lmsensors package
+#		    and snmpd compiled as:
+#			--with-mib-modules="ucd-snmp/lmSensors ucd-snmp/diskio"
+# 0.40 (beta) - Mar 2012 :
+#                   Imported newest code from check_mysqld 0.93 to support full nagios
+#                   threshold specification (including ranges) as well as reporting
+#		    of warn/crit threshold in performance data. This changes internal
+#                   processing significantly and it needs to be tested more.
+# 0.41 - Mar 23, 2013: Fixed bug in parse_threshold function, reported by Charlie Langrall
+#		        official release of 0.4 code branch
+#
+# TODO and older revision history:
+#  -- TODO ON TODO --> since most of below is done, it should be cleaned up sometime later
+# 
+# 1. [DONE - Aug 2006] To support multiple types of equipment add config
+#    array/hash and --type parameter
+# 2. More plugin types for various other equipment need to be added ... 
+#    [DONE - Dec 2006] - added Juniper & HP
+# 3. [DONE - Mar 2012] Need to update warn & crit parameters parsing code so
+#    it would support both low and high values with '<' and '>' prefixed and
+#    using '~' for don't check rather then 0
+#    [DONE - Dec 2006] - added quick hack to interpret empty values
+#    (i.e. -w ",90,") as dont check instead of specifying '0' directly
+#      Note: Low temperature value checks are rarely needed for network
+#            equipment so this is not high priority right now and will
+#            be done together with #4 most likely as part of some general
+#            library that would be shared with check_snmp_table and quite
+#            likely other plugins where multiple "attributes" are specified
+# 4. [DONE - Mar 2012] Add threshold specification in nagios plugin spec compatible way
+#    as was done with check_mysqld 0.9 which uses code similar to this check 
+#    Add specifying of WARN & CRIT after actual value ';' in the perf output
+#    [DONE - Dec 2011] - added WARN & CRIT to perf, threshold spec still on todo
+# 5. Support specifying table OIDs for temperature threshold values.
+#    I'll do it only after adding optional file caching so these values
+#    can be retrieved about once every day rather then for each check.
+# 6. Support directly querying lmsensors on linux system without SNMP
+#    plugin would then be renamed to check_temperature similar to check_netint
+#
+# ========================== START OF PROGRAM CODE ============================
+
+use strict;
+use Getopt::Long;
+use Data::Dumper;
+
+# Nagios specific
+our $TIMEOUT = 30;
+our %ERRORS;
+eval 'use utils qw(%ERRORS $TIMEOUT)';
+if ($@) {
+ $TIMEOUT = 30;
+ %ERRORS = ('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
+}
+
+our $no_snmp=0;
+eval 'use Net::SNMP';
+if ($@) {
+  $no_snmp=1;
+}
+
+# Below is hash array for several types of equipment, format here is that
+# key is name you can specify in "--type" and data for that key is 3-value
+# array with 1st value sensor names table OID (-N option), 2nd is sensor
+# data table OID (-D option) and 3rd is type of temperature reading (-i)
+# Additionally instead of specifying sensor names table OID and sensor data
+# root table OID, the first two arguments to array can be "" and then 4th and
+# 5th argument should be arrays first with list of sensor names and 2nd with
+# list of OIDs for data to be retrieved (see below for how its done for Alteon)
+my %system_types = ( "dell" => [ "1.3.6.1.4.1.674.10892.1.700.20.1.8", "1.3.6.1.4.1.674.10892.1.700.20.1.6", "10C" ],
+		     "cisco1" => [ "1.3.6.1.4.1.9.9.13.1.3.1.2", "1.3.6.1.4.1.9.9.13.1.3.1.3", "C" ],
+		     "cisco" =>  [ "1.3.6.1.4.1.9.9.13.1.3.1.2", "1.3.6.1.4.1.9.9.13.1.3.1.3", "C" ], # same as cisco 1 for now, this may change
+		     "juniper" => [ "1.3.6.1.4.1.2636.3.1.13.1.5", "1.3.6.1.4.1.2636.3.1.13.1.7", "C" ], # somebody verify it, dont have juniper right now
+		     "hp" => [ "1.3.6.1.4.1.232.6.2.6.8.1.3", "1.3.6.1.4.1.232.6.2.6.8.1.4", "C" ], 
+		     "alteon" => [ "", "", "C", ['RearLeftSensor', 'RearMiddleSensor', 'FrontMiddleSensor', 'FrontRightSensor'], ['1.3.6.1.4.1.1872.2.1.1.6.0','1.3.6.1.4.1.1872.2.1.1.7.0','1.3.6.1.4.1.1872.2.1.1.8.0','1.3.6.1.4.1.1872.2.1.1.9.0'] ], # why do they need to make these alteons so proprietory and hard to deal with?
+		     "baytech" => [ "1.3.6.1.4.1.4779.1.3.5.2.1.2", "1.3.6.1.4.1.4779.1.3.5.2.1.8", "10C" ],  # baytech pdu
+		     "lmsensors" => [ "1.3.6.1.4.1.2021.13.16.2.1.2", "1.3.6.1.4.1.2021.13.16.2.1.3", "1000C" ], #linux with lmsensors
+		     "linux" => [ "1.3.6.1.4.1.2021.13.16.2.1.2", "1.3.6.1.4.1.2021.13.16.2.1.3", "1000C" ],
+		   );
+# APC OID for the temperature is .1.3.6.1.4.1.318.1.1.2.1.1.0
+# APC OID for the humidity is .1.3.6.1.4.1.318.1.1.2.1.2.0
+# Cisco fans: .1.3.6.1.4.1.9.9.13.1.4.1.3
+# HP switch temperature : .1.3.6.1.4.1.11.2.14.11.1.2.6.1.4.4
+# HP switch fan: .1.3.6.1.4.1.11.2.14.11.1.2.6.1.4.1
+
+my $Version='0.40';
+
+my $o_host=     undef;          # hostname
+my $o_community= undef;         # community
+my $o_port=     161;            # SNMP port
+my $o_help=     undef;          # help option
+my $o_verb=     undef;          # verbose mode
+my $o_version=  undef;          # version info option
+my $o_octets=	5000;
+my $o_warn=     undef;          # warning level option
+my @o_warnL=    ();             # array for above list
+my $o_crit=     undef;          # Critical level option
+my @o_critL=    ();             # array for above list
+my $o_perf=     undef;          # Performance data option
+my $o_timeout=  15;              # Default 15s Timeout
+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
+
+my $o_attr=	undef;  	# What attribute(s) to check (specify more then one separated by '.')
+my @o_attrL=    ();             # array for above list
+my $o_perfattr= undef;		# List of attributes to only provide values in performance data but no checking
+my @o_perfattrL=();		# array for above list
+my $o_ounit= 	'C';		# Output Temperature Measurement Units - can be 'C', 'F' or 'K'
+my $o_iunit=	'C';		# Incoming Temperature Measurement Units - can prefix with number if its n*temp 
+my $oid_names=	undef;		# OID for base of sensor attribute names
+my $oid_data=	undef;		# OID for base of actual data for those attributes found when walking name base
+my $o_names=	undef;		# List of sensor names (as opposed to specifying names table)
+my $o_unkdef=	undef;		# Default value to report for unknown attributes
+my $o_type=	undef;		# Type of system to check (predefined values for $oid_names, $oid_data, $oid_iunit)
+my $o_sensornames=undef;	# Option specifying list of sensor names that then go into @ar_sensornames array
+my $o_sensoroids=undef;		# Option specifying list of sensor oids that then go into @ar_sensoroids array
+my @ar_sensornames=();		# List of sensor names if specified in the sensor_types array
+my @ar_sensoroids=();		# List of sensor data oids if specified in sensor_types array
+
+# This is hack for HP based on cpqHeTemperatureLocale OID from cpqhlth.mib to map reported locale id to real name
+my %hp_locale =  ( 1=> ['OTHER',1], 2=> ['UNKNOWN',1],  3=> ['System', 1], 4=> ['SystemBoard',1], 5=> ['ioBoard',1], 
+		   6=> ['CPU',1], 7=> ['Memory',1], 8=> ['Storage',1], 9=> ['RemovableMedia',1],
+		   10=> ['PowerSupply',1], 11=> ['Ambient',1], 12=> ['Chassis',1], 13=> ['BridgeCard',1] );
+
+sub print_version { print "$0: $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>] [-t <timeout>] -T dell|hp|cisco1|juniper|alteon|lmsensors | [-N <oid_attribnames> -D <oid_attribdata>] | [-n <list of sensor names> -d <list of sensor oids>] [-a <attributes to check> -w <warn levels> -c <crit levels> [-f]] [-A <attributes for perfdata>] [-o <out_temp_unit: C|F|K>] [-i <in_temp_unit>] [-u <unknown_default>] [-V]\n";
+}
+
+# Return true if arg is a number
+sub isnum {
+	my $num = shift;
+	if ( $num =~ /^(\d+\.?\d*)|(^\.\d+)$/ ) { return 1 ;}
+	return 0;
+}
+
+# function used when checking data against critical and warn values
+sub check_threshold {
+    my ($attrib, $data, $th_array, $o_ounit) = @_;
+    my $mod = $th_array->[0];
+    my $lv1 = $th_array->[1];
+    my $lv2 = $th_array->[2];
+
+    # verb("debug check_threshold: $mod : ".(defined($lv1)?$lv1:'')." : ".(defined($lv2)?$lv2:''));
+    return "" if !defined($lv1) || ($mod eq '' && $lv1 eq ''); 
+    return " " . $attrib . " Temperature is " . $data . $o_ounit . " = " . $lv1.$o_ounit if $mod eq '=' && $data eq $lv1;
+    return " " . $attrib . " Temperature is " . $data . $o_ounit . " != " . $lv1.$o_ounit if $mod eq '!' && $data ne $lv1;
+    return " " . $attrib . " Temperature is " . $data . $o_ounit . " > " . $lv1.$o_ounit if $mod eq '>' && $data>$lv1;
+    return " " . $attrib . " Temperature is " . $data . $o_ounit . " > " . $lv2.$o_ounit if $mod eq ':' && $data>$lv2;
+    return " " . $attrib . " Temperature is " . $data . $o_ounit . " >= ". $lv1.$o_ounit if $mod eq '>=' && $data>=$lv1;
+    return " " . $attrib . " Temperature is " . $data . $o_ounit . " < "  . $lv1.$o_ounit if ($mod eq '<' || $mod eq ':') && $data<$lv1;
+    return " " . $attrib . " Temperature is " . $data . $o_ounit . " <= " . $lv1.$o_ounit if $mod eq '<=' && $data<=$lv1;
+    return " " . $attrib . " Temperature is " . $data . $o_ounit ." in range ". $lv1.$o_ounit."..".$lv2.$o_ounit if $mod eq '@' && $data>=$lv1 && $data<=$lv2;
+    return "";
+}
+
+# function called when parsing threshold options data
+sub parse_threshold {
+    my $thin = shift;
+
+    # link to an array that holds processed threshold data
+    # array: 1st is type of check, 2nd is value2, 3rd is value2, 4th is option, 5th is nagios spec string representation for perf out
+    my $th_array = [ '', undef, undef, '', '' ]; 
+    my $th = $thin;
+    my $at = '';
+
+    # take 3 ways to specify that there is no threshold
+    return $th_array if ($th eq '0' || $th eq '~' || $th eq '');
+
+    $at = $1 if $th =~ s/^(\^?[@|>|<|=|!]?~?)//; # check mostly for my own threshold format
+    $th_array->[3]='^' if $at =~ s/\^//; # deal with ^ option
+    $at =~ s/~//; # ignore ~ if it was entered
+    if ($th =~ /^\:([-|+]?\d+\.?\d*)/) { # :number format per nagios spec
+	$th_array->[1]=$1;
+	$th_array->[0]=($at !~ /@/)?'>':'<=';
+	$th_array->[5]=($at !~ /@/)?('~:'.$th_array->[1]):($th_array->[1].':');
+    }
+    elsif ($th =~ /([-|+]?\d+\.?\d*)\:$/) { # number: format per nagios spec
+        $th_array->[1]=$1;
+	$th_array->[0]=($at !~ /@/)?'<':'>=';
+	$th_array->[5]=($at !~ /@/)?'':'@';
+	$th_array->[5].=$th_array->[1].':';
+    }
+    elsif ($th =~ /([-|+]?\d+\.?\d*)\:([-|+]?\d+\.?\d*)/) { # nagios range format
+	$th_array->[1]=$1;
+	$th_array->[2]=$2;
+	if ($th_array->[1] > $th_array->[2]) {
+                print "Incorrect format in '$thin' - in range specification first number must be smaller then 2nd\n";
+                print_usage();
+                exit $ERRORS{"UNKNOWN"};
+	}
+	$th_array->[0]=($at !~ /@/)?':':'@';
+	$th_array->[5]=($at !~ /@/)?'':'@';
+	$th_array->[5].=$th_array->[1].':'.$th_array->[2];
+    }
+    if (!defined($th_array->[1])) {
+	$th_array->[0] = ($at eq '@')?'<=':$at;
+	$th_array->[1] = $th;
+	$th_array->[5] = '~:'.$th_array->[1] if ($th_array->[0] eq '>' || $th_array->[0] eq '>=');
+	$th_array->[5] = $th_array->[1].':' if ($th_array->[0] eq '<' || $th_array->[0] eq '<=');
+	$th_array->[5] = '@'.$th_array->[1].':'.$th_array->[1] if $th_array->[0] eq '=';
+	$th_array->[5] = $th_array->[1].':'.$th_array->[1] if $th_array->[0] eq '!';
+    }
+    if ($th_array->[0] =~ /[>|<]/ && !isnum($th_array->[1])) {
+	print "Numeric value required when '>' or '<' are used !\n";
+        print_usage();
+        exit $ERRORS{"UNKNOWN"};
+    }
+    # verb("debug parse_threshold: $th_array->[0] and $th_array->[1]");
+    $th_array->[0] = '=' if !$th_array->[0] && !isnum($th_array->[1]) && $th_array->[1] ne '';
+    if (!$th_array->[0] && isnum($th_array->[1])) { # this is just the number by itself, becomes 0:number check per nagios guidelines
+	$th_array->[2]=$th_array->[1];
+	$th_array->[1]=0;
+	$th_array->[0]=':';
+        $th_array->[5]=$th_array->[2];
+    }
+    return $th_array;
+}
+
+# this function checks that for numeric data warn threshold is within range of critical threshold
+# where within range depends on actual threshold spec and normally just means less
+sub threshold_specok {
+    my ($warn_thar,$crit_thar) = @_;
+    return 0 if (defined($warn_thar->[1]) && !isnum($warn_thar->[1])) || (defined($crit_thar->[1]) && !isnum($crit_thar->[1]));
+    return 1 if defined($warn_thar) && defined($warn_thar->[1]) &&
+                defined($crit_thar) && defined($crit_thar->[1]) &&
+                isnum($warn_thar->[1]) && isnum($crit_thar->[1]) &&
+                $warn_thar->[0] eq $crit_thar->[0] &&
+                (!defined($warn_thar->[3]) || $warn_thar->[3] !~ /\^/) &&
+                (!defined($crit_thar->[3]) || $crit_thar->[3] !~ /\^/) &&
+              (($warn_thar->[1]>$crit_thar->[1] && ($warn_thar->[0] =~ />/ || $warn_thar->[0] eq '@')) ||
+               ($warn_thar->[1]<$crit_thar->[1] && ($warn_thar->[0] =~ /</ || $warn_thar->[0] eq ':')) ||
+               ($warn_thar->[0] eq ':' && $warn_thar->[2]>=$crit_thar->[2]) ||
+               ($warn_thar->[0] eq '@' && $warn_thar->[2]<=$crit_thar->[2]));
+    return 0;  # return with 0 means specs check out and are ok
+}
+
+sub help {
+	print "\nSNMP Temperature Monitor for Nagios version ",$Version,"\n";
+	print " by William Leibzon - william(at)leibzon.org\n\n";
+	print_usage();
+	print <<EOD;
+-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 v 1 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=INT[,INT[,INT[..]]]
+	Warning temperature level(s). The number of values listed here must exactly match number
+        of sensors listed with '-a'. The values specifify threshold for when Nagios should send
+        WARNING alert. All values are numbers and can have the following prefix modifiers:
+           > - warn if data is above this value (default for numeric values)
+           < - warn if data is below this value (must be followed by number)
+           = - warn if data is equal to this value (default for non-numeric values)
+           ! - warn if data is not equal to this value
+           ~ - do not check this data (must not be followed by number or ':')
+           ^ - this disables check that warning < critical
+        Threshold values can also be specified as range in two forms:
+           num1:num2  - warn if data is outside range i.e. if data<num1 or data>num2
+           \@num1:num2 - warn if data is in range i.e. data>=num1 && data<=num2
+-c, --crit=INT[,INT[,INT[..]]]
+	Critical temperature level(s) (if more then one attribute is checked, must have multiple values)
+        The format is the same as with warning threshold levels.
+-f, --perfdata
+	Perfparse compatible output
+-t, --timeout=INTEGER
+	timeout for SNMP in seconds (Default: 5)
+-V, --version
+	prints version number
+-N, --oidtable_attribnames=OID_STRING
+	Base table OID to walk through to find names of those attributes supported and from that corresponding data OIDs
+-D, --oidtable_attribdata=OID_STRING
+	Base table OID for sensor attribute data, one number is added to that to make up full attribute OID
+-n, --sensor_names=STRING[,STRING[..]]
+        List of sensor names when -N is not used and sensors are specified with exeact oids
+-d, --sensor_oids=OID_STRING[,OID_STRING[..]]
+	List of exact data OIDs for sensors specified with -n (specify this when -N and -D are not used)
+-a, --attributes=STRING[,STRING[..]]
+	Which attribute(s) to check. This is used as regex to check if attribute is found in sensor names.
+	As an example for Dell the attribute names to use are: PROC_1, PROC_2, Ambient, Planar, Riser
+-A, --perf_attributes=STRING[,STRING[..]]
+	Which attribute(s) to add to as part of performance data output. These names can be different then the
+	ones listed in '-a' to only output attributes in perf data but not check. Special value of '*' gets them all.
+-f, --perfparse
+        Used only with '-a'. Causes to output data not only in main status line but also as perfparse output
+-o  --out_temp_unit=C|F|K
+	What temperature measurement units are used for output and warning/critical - 'C', 'F' or 'K' - default is 'C'
+-i  --in_temp_unit=[num]C|F|K
+	What temperature measurement reported by data OID - format is <num>C|F|K (default is 'C')
+ 	where num is used if data is num*realdata, i.e. if reported data of 330 means 33C, then it is: -i 10C
+-u, --unknown_default=INT
+        If attribute is not found then report the output as this number (i.e. -u 0)
+-T, --type=dell|hp|cisco1|juniper|alteon|lmsensors
+	This allows to use pre-defined system type to set Base, Data OIDs and incoming temperature measurement type
+	Currently support systems types are: dell, hp, cisco1 (7500, 5500, 2948, etc), juniper, alteon, lmsensors (linux using lmsensors package if snmp is compiled to support it)
+EOD
+}
+
+# For verbose output - don't use it right now
+sub verb { my $t=shift; print $t,"\n" if defined($o_verb) ; }
+
+# Get the alarm signal (just in case snmp timout screws up)
+$SIG{'ALRM'} = sub {
+     print ("ERROR: Alarm signal (Nagios time-out)\n");
+     exit $ERRORS{"UNKNOWN"};
+};
+
+# converts temperature from input format unit into output format units
+sub convert_temp {
+    my ($temp, $in_unit, $out_unit) = @_;
+
+    my $in_mult = 1;
+    my $ctemp = undef;
+    $in_mult = $1 if $in_unit =~ /(\d+)\w/;
+    $in_unit =~ s/\d+//;
+
+    # exit quickly avoiding conversion to and from C if both units are the same
+    return $temp / $in_mult if ($in_unit eq $out_unit);
+    # if units are not the same, we convert to/from C
+    $ctemp = $temp / $in_mult if $in_unit eq 'C';
+    $ctemp = ($temp / $in_mult - 32) / 1.8 if $in_unit eq 'F';
+    $ctemp = $temp / $in_mult - 273.15 if $in_unit eq 'K';
+    $ctemp = $temp / $in_mult if !defined($ctemp);
+    return $ctemp if $out_unit eq "C";
+    return $ctemp * 1.8 + 32 if $out_unit eq "F";
+    return $ctemp + 273.15 if $out_unit eq "K";
+    return $ctemp; # should not get here
+}
+
+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,
+        'a:s'   => \$o_attr,         	'attributes:s' 	=> \$o_attr,
+	'A:s'	=> \$o_perfattr,	'perf_attributes:s' => \$o_perfattr,
+	'o:s'	=> \$o_ounit,		'out_temp_unit:s' => \$o_ounit,
+	'i:s'	=> \$o_iunit,		'in_temp_unit:s' => \$o_iunit,
+	'u:i'	=> \$o_unkdef,		'unknown_default:i' => \$o_unkdef,
+	'N:s'	=> \$oid_names,		'oid_attribnames:s' => \$oid_names,  'oidtable_attribnames:s' => \$oid_names,
+	'D:s'	=> \$oid_data,		'oid_attribdata:s'  => \$oid_data,   'oidtable_attribdata:s'  => \$oid_data,
+	'n:s'   => \$o_sensornames,	'sensor_names:s' => \$o_sensornames,
+	'd:s'   => \$o_sensoroids,	'sensor_oids:s'  => \$o_sensoroids,
+	'T:s'   => \$o_type,		'type:s'	=> \$o_type
+    );
+    if (defined($o_help) ) { help(); exit $ERRORS{"UNKNOWN"}; }
+    if (defined($o_version)) { print_version(); exit $ERRORS{"UNKNOWN"}; }
+    if ($no_snmp) {
+        print "Can't locate Net/SNMP.pm\n"; print_usage(); exit $ERRORS{"UNKNOWN"};
+    }
+    if (! defined($o_host)) { # check host and filter
+        print "No host defined!\n";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"}}
+	}
+    $o_ounit =~ tr/[a-z]/[A-Z]/;
+    if ($o_ounit ne 'C' && $o_ounit ne 'F' && $o_ounit ne 'K') 
+	{ print "Invalid output measurement unit specified!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}; }
+    $o_iunit =~ tr/[a-z]/[A-Z]/;
+    if ($o_iunit !~ /\d*[C|K|F]/)
+	{ print "Invalid input measurement unit specified!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}; }
+    if (defined ($o_type)) {
+	if (defined($oid_names) || defined($oid_data) || defined($o_sensornames) || defined($o_sensoroids))
+	   { print "Please either specify specify system type (-T) OR base SNMP OIDs for name (-N) and data (-D) tables OR exact list of sensor names (-n) and data OIDs (-d) !\n"; print_usage(); exit $ERRORS{"UNKNOWN"}; }
+	if (defined($system_types{$o_type})) {
+	   $oid_names = $system_types{$o_type}[0];
+	   $oid_data = $system_types{$o_type}[1];
+	   $o_iunit = $system_types{$o_type}[2];
+	   @ar_sensornames= @{$system_types{$o_type}[3]} if defined($system_types{$o_type}[3]) && !$oid_names;
+	   @ar_sensoroids= @{$system_types{$o_type}[4]} if defined($system_types{$o_type}[4]) && !$oid_data;
+	}
+	else { print "Unknown system type $o_type !\n"; print_usage(); exit $ERRORS{"UNKNOWN"}; }
+    }
+    if (defined($o_sensornames) && defined($o_sensoroids)) {
+	if (defined($oid_names) || defined($oid_data)) {
+	   print "You can not combine -n / -d options with -N / -D\n"; print_usage(); exit $ERRORS{"UNKNOWN"};
+	}
+	else {
+	   @ar_sensornames = split(/,/, $o_sensornames);
+	   @ar_sensoroids = split(/,/, $o_sensoroids);
+	   if (scalar(@ar_sensornames) != scalar(@ar_sensoroids)) {
+		printf "Number of sensor names specified at -n (%d) must be equal to number of data OIDs specified with -d (%d)\n",
+		   scalar(@ar_sensornames), scalar(@ar_sensoroids);
+		print_usage();
+		exit $ERRORS{"UNKNOWN"};
+	   }
+	}
+    }
+    if (scalar(@ar_sensornames)==0 && scalar(@ar_sensoroids)==0 && !(defined($oid_names) && defined($oid_data)))
+	{ print "Specify system type (-T) OR base SNMP OIDs for names (-N) and data (-D) tables OR exact list of sensor names (-n) and data OIDs (-d) !\n"; print_usage(); exit $ERRORS{"UNKNOWN"}; }
+
+    # below code is common for number of my plugins, including check_snmp_?, netstat, etc
+    # it is mostly compliant with nagios threshold specification (except use of '~')
+    # and adds number of additional format options using '>','<','!','=' prefixes
+    my (@ar_warnLv,@ar_critLv);
+    if (defined($o_perfattr)) {
+        @o_perfattrL=split(/,/ ,$o_perfattr);
+    }
+    if (defined($o_warn) || defined($o_crit) || defined($o_attr)) {
+        if (defined($o_attr)) {
+          @o_attrL=split(/,/, $o_attr);
+	  if (defined($o_warn)) {
+	     $o_warn.="~" if $o_warn =~ /,$/;
+	     @ar_warnLv=split( /,/ , lc $o_warn );
+	  }
+	  if (defined($o_crit)) {
+	     $o_crit.="~" if $o_crit =~ /,$/;
+    	     @ar_critLv=split( /,/ , lc $o_crit );
+	  }
+	}
+	else {
+	  print "Specifying warning and critical levels requires '-a' parameter with list of STATUS variables\n";
+	  print_usage();
+	  exit $ERRORS{"UNKNOWN"};
+        }
+	if (scalar(@ar_warnLv)!=scalar(@o_attrL) || scalar(@ar_critLv)!=scalar(@o_attrL)) {
+	  printf "Number of specified warning levels (%d) and critical levels (%d) must be equal to the number of attributes specified at '-a' (%d). If you need to ignore some attribute do it as ',,'\n", scalar(@ar_warnLv), scalar(@ar_critLv), scalar(@o_attrL); 
+	  verb("Warning Levels: ".join(",",@ar_warnLv));
+	  verb("Critical Levels: ".join(",",@ar_critLv));
+	  print_usage();
+	  exit $ERRORS{"UNKNOWN"};
+	}
+	for (my $i=0; $i<scalar(@o_attrL); $i++) {
+          $o_warnL[$i] = parse_threshold($ar_warnLv[$i]);
+          $o_critL[$i] = parse_threshold($ar_critLv[$i]);
+	  if (threshold_specok($o_warnL[$i],$o_critL[$i])) {
+                 print "Numeric value required for warning and critical thresholds!\n";
+		 print "And warning must be less then critical (or greater then when '<' is used)\n";
+                 print "(to override warning<critical check prefix warning value with ^)\n";
+                 print_usage();
+                 exit $ERRORS{"UNKNOWN"};
+           }
+	}
+    }
+   if (scalar(@o_attrL)==0 && scalar(@o_perfattrL)==0) {
+        print "You must specify list of attributes with either '-a' or '-A'\n";
+        print_usage();
+        exit $ERRORS{"UNKNOWN"};
+    }
+}
+
+########## MAIN #######
+
+check_options();
+
+# Check global timeout if something goes wrong
+if (defined($TIMEOUT)) {
+  verb("Alarm at $TIMEOUT");
+  alarm($TIMEOUT);
+} 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,
+      -maxmsgsize => $o_octets || 10000,
+      -port      => $o_port || 161,
+      -timeout   => $o_timeout
+    );
+  } else {
+    # SNMPV1 login
+    verb("SNMP v1 login");
+    ($session, $error) = Net::SNMP->session(
+      -version   => '1',
+      -hostname  => $o_host,
+      -community => $o_community,
+      -port      => $o_port || 161,
+      -timeout   => $o_timeout
+    );
+  }
+}
+if (!defined($session)) {
+   printf("ERROR opening session: %s.\n", $error);
+   exit $ERRORS{"UNKNOWN"};
+}
+
+# next part of the code builds list of attributes to be retrieved
+my $i;
+my $oid;
+my $line;
+my $attr;
+my @varlist = ();
+my %dataresults;
+my $result;
+
+for ($i=0;$i<scalar(@o_attrL);$i++) {
+  $dataresults{$o_attrL[$i]} = ["check", undef, undef, 0, 0];
+}
+if (defined($o_perfattr) && $o_perfattr ne '*') {
+  for ($i=0;$i<scalar(@o_perfattrL);$i++) {
+    $dataresults{$o_perfattrL[$i]} = ["perf", undef, undef, 0, 0];
+  }
+}
+
+if (scalar(@ar_sensornames)==0) {
+    verb("Retrieving SNMP table $oid_names to find sensor attribute names");
+    $result = $session->get_table( -baseoid => $oid_names );
+#    $result = $session->get_request( -varbindlist => [$oid_names] );
+
+    if (!defined($result)) {
+        printf("ERROR: Problem retrieving OID %s table: %s.\n", $oid_names, $session->error);
+        $session->close();
+        exit $ERRORS{"UNKNOWN"};
+    }
+    L1: foreach $oid (Net::SNMP::oid_lex_sort(keys %{$result})) {
+        $line=$result->{$oid};
+        verb("got $oid : $line");
+	# special hack for HP
+	if (defined($o_type) && $o_type eq 'hp' && exists($hp_locale{$line})) {
+		$line = $hp_locale{$result->{$oid}}[0] ."_". $hp_locale{$result->{$oid}}[1];
+		$hp_locale{$result->{$oid}}[1]++;
+		verb("HP hack: interpreting ".$result->{$oid}." as $line");
+	}	
+        if (defined($o_perfattr) && $o_perfattr eq '*') {
+                $oid =~ s/$oid_names/$oid_data/;
+                $dataresults{$line} = ["perf", $oid, undef, 0, 0];
+                unshift(@varlist,$oid);
+                verb("match found based on -A '*', now set to retrieve $oid");
+        }
+	foreach $attr (keys %dataresults) {
+	   if ($line =~ /$attr/ && !defined($dataresults{$attr}[1])) {
+		$oid =~ s/$oid_names/$oid_data/;
+		$dataresults{$attr}[1] = $oid;
+		unshift(@varlist,$oid) if !defined($varlist[0]) || $varlist[0] ne $oid;
+		verb("match found for $attr, now set to retrieve $oid");
+		next L1;
+	   }
+	}
+    }
+}
+else {
+    my $i;
+    for ($i=0;$i<scalar(@ar_sensornames);$i++) {
+	$line=$ar_sensornames[$i];
+	$oid=$ar_sensoroids[$i];
+        if (defined($o_perfattr) && $o_perfattr eq '*') {
+                $dataresults{$line} = ["perf", $oid, undef, 0, 0];
+                unshift(@varlist,$oid);
+                verb("match found based on -A '*', now set to retrieve $oid");
+        }
+        L2: foreach $attr (keys %dataresults) {
+           if ($line =~ /$attr/ && !defined($dataresults{$attr}[1])) {
+                $dataresults{$attr}[1] = $oid;
+                unshift(@varlist,$oid) if !defined($varlist[0]) || $varlist[0] ne $oid;
+                verb("match found for $attr, now set to retrieve $oid");
+                next L2;
+           }
+        }
+    }
+}
+
+# now we actually retrieve the attributes
+my $statuscode = "OK";
+my $statusinfo = "";
+my $statusdata = "";
+my $perfdata = "";
+my $chk = "";
+
+verb("Getting SNMP data for oids" . join(" ",@varlist));
+$result = $session->get_request(
+	-Varbindlist => \@varlist
+);
+if (!defined($result)) {
+        printf("ERROR: Can not retrieve OID(s) %s: %s.\n", join(" ",@varlist), $session->error);
+        $session->close();
+        exit $ERRORS{"UNKNOWN"};
+}
+else {
+	foreach $attr (keys %dataresults) {
+	    if (defined($dataresults{$attr}[1]) && defined($$result{$dataresults{$attr}[1]})) {
+		$dataresults{$attr}[2]=convert_temp($$result{$dataresults{$attr}[1]},$o_iunit,$o_ounit);
+		verb("got $dataresults{$attr}[1] : $attr = $dataresults{$attr}[2]");
+	    }
+	    else { 
+		if (defined($o_unkdef)) {
+		   $dataresults{$attr}[2]=$o_unkdef;
+		   verb("could not find snmp data for $attr, setting to to default value $o_unkdef");
+		}
+		else {
+		   verb("could not find snmp data for $attr");
+		}
+	    }
+	}
+} 
+
+# loop to check if warning & critical attributes are ok
+for ($i=0;$i<scalar(@o_attrL);$i++) {
+  if (defined($dataresults{$o_attrL[$i]}[2])) {
+    if ($chk = check_threshold($o_attrL[$i],$dataresults{$o_attrL[$i]}[2],$o_critL[$i],$o_ounit)) {
+	$dataresults{$o_attrL[$i]}[3]++;
+	$statuscode = "CRITICAL";
+        $statusinfo .= $chk;
+    }
+    elsif ($chk = check_threshold($o_attrL[$i],$dataresults{$o_attrL[$i]}[2],$o_warnL[$i],$o_ounit)) {
+	$dataresults{$o_attrL[$i]}[3]++;
+	$statuscode="WARNING" if $statuscode eq "OK";
+	$statusinfo .= $chk;
+    }
+    if ($dataresults{$o_attrL[$i]}[3]==0) {
+	  $dataresults{$o_attrL[$i]}[3]++;
+	  $statusdata .= "," if ($statusdata);
+	  $statusdata .= " " . $o_attrL[$i] . " Temperature is " . $dataresults{$o_attrL[$i]}[2] . $o_ounit;
+    }
+    if (defined($o_perf) && $dataresults{$o_attrL[$i]}[4]==0 && 
+        defined($o_warnL[$i][5]) && defined($o_critL[$i][5])) {
+	  $dataresults{$o_attrL[$i]}[4]++;
+          $perfdata .= " " . $o_attrL[$i] . "=" . $dataresults{$o_attrL[$i]}[2];
+	  $perfdata .= ';' if $o_warnL[$i][5] ne '' || $o_critL[$i][5] ne '';
+	  $perfdata .= $o_warnL[$i][5] if $o_warnL[$i][5] ne '';
+	  $perfdata .= ';'.$o_critL[$i][5] if $o_critL[$i][5] ne '';
+    }
+  }
+  else {
+	$statusdata .= "," if ($statusdata);
+        $statusdata .= " $o_attrL[$i] data is missing";
+	$statuscode = "UNKNOWN" if $statuscode eq "OK";
+  }
+}
+
+# add data for performance-only attributes
+if (defined($o_perfattr) && $o_perfattr eq '*') {
+  foreach $attr (keys %dataresults) {
+     if ($dataresults{$attr}[0] eq "perf" && defined($dataresults{$attr}[2]) && $dataresults{$attr}[4]==0) {
+        $dataresults{$attr}[4]++;
+	$perfdata .= " " . $attr . "=" . $dataresults{$attr}[2];
+     }
+  }
+}
+else {
+  for ($i=0;$i<scalar(@o_perfattrL);$i++) {
+     if (defined($dataresults{$o_perfattrL[$i]}[2]) && $dataresults{$o_perfattrL[$i]}[4]==0) {
+	$dataresults{$o_perfattrL[$i]}[4]++;
+	$perfdata .= " " . $o_perfattrL[$i] . "=" . $dataresults{$o_perfattrL[$i]}[2];
+     }
+  }
+}
+
+$session->close;
+print $statuscode . $statusinfo;
+print " -".$statusdata if $statusdata;
+print " |".$perfdata if $perfdata;
+print "\n";
+
+exit $ERRORS{$statuscode};

+ 65 - 0
docs/nagios/scripts/plugins/check_snmp_uptime

@@ -0,0 +1,65 @@
+#!/usr/bin/perl
+
+use strict;
+use lib "/etc/nagios4/scripts/plugins";
+use snmp;
+
+use Net::SNMP qw(ticks_to_time TRANSLATE_NONE);
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+my $host = shift @ARGV;
+my $snmp_str = shift @ARGV;
+my ($community,$version,$user,$auth,$priv) = split(/;/,$snmp_str);
+
+my $snmp;
+$snmp->{version} = $version || '2';
+$snmp->{timeout} = 30;
+$snmp->{community} = $community || 'public';
+$snmp->{user} = $user || 'public';
+$snmp->{auth} = $auth || 'sha1';
+$snmp->{priv} = $priv || 'aes';
+
+my $session = init_snmp($host,$snmp);
+
+#sysUpTimeInstance .1.3.6.1.2.1.1.3.0
+
+my $inputline = '.1.3.6.1.2.1.1.3.0';
+
+$session->translate(TRANSLATE_NONE);
+
+my $result = $session->get_request(
+   -varbindlist => [$inputline]
+);
+
+if (!defined($result)) {
+   printf("ERROR: %s.\n", $session->error);
+   $session->close;
+   exit 2;
+}
+
+$session->close;
+
+my $value = $result->{$inputline};
+
+my $uptime = ticks_to_time($value);
+
+my $perf_data = "input=0;0;0;0;0;";
+if (!defined($result->{$inputline})) {
+    printf("ERROR: %s. |".$perf_data."\n", $session->error);
+    $session->close;
+    exit 2;
+    }
+
+$perf_data = "uptime=%s;0;0;0;0;";
+if ($value <=480) {
+    printf("ERROR: Restarted device! Uptime: %s |".$perf_data."\n", $uptime, $value);
+    $session->close;
+    exit 2;
+    }
+
+printf("OK Uptime: %s |".$perf_data."\n", $uptime,$value);
+
+exit 0;

+ 90 - 0
docs/nagios/scripts/plugins/check_ups_battery_replace

@@ -0,0 +1,90 @@
+#!/usr/bin/perl
+
+use strict;
+use Net::SNMP;
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+my $debug = 0;
+
+#eaton
+#upsBatteryAbmStatus (Charging(1),Discharging(2),Floating(3),Resting(4),unknown(5),Disconnected(6),Under Test(7),Check Battery(8)) 1.3.6.1.4.1.534.1.2.5.0
+#upsTestBatteryStatus (unknown (1),passed (2),failed (3),inProgress (4),notSupported (5),inhibited (6),scheduled (7)) 1.3.6.1.4.1.534.1.8.2.0
+
+my %ups_oids = (
+#apc ?
+'apc'=>'.1.3.6.1.4.1.318.1.1.1.2.2.4.0',
+#upsTestBatteryStatus
+'eaton'=>'.1.3.6.1.4.1.534.1.8.2.0',
+);
+
+exit if (!$ARGV[0]);
+
+my $hostip=$ARGV[0];
+
+my ($session, $error) = Net::SNMP->session(
+   -hostname  => shift || $hostip,
+   -community => shift || 'public',
+   -port      => shift || '161',
+   -timeout   => 5,
+   -version   => shift || '1',
+);
+
+if (!defined($session)) { printf("ERROR: %s.\n", $error); exit 1; }
+
+my %result;
+foreach my $key (sort keys %ups_oids) {
+my $key_oid = $ups_oids{$key};
+my $ret = $session->get_request( -varbindlist => [$key_oid] );
+my $value;
+if (!$ret) {
+    #search in subtree
+    $ret = $session->get_next_request( -varbindlist => [$key_oid] );
+    my @keys_next = keys %$ret;
+    if (scalar @keys_next and $keys_next[0]) {
+        my $get_key = $keys_next[0];
+	if ($get_key=~/^$key_oid/) {
+	    $value = $ret->{$get_key};
+            print STDERR "Get-Next for key $key_oid: $get_key => $value\n" if ($debug);
+	    }
+	}
+    } else {
+    $value = $ret->{$key_oid};
+    print STDERR "Get: $key_oid => $value\n" if ($debug);
+    }
+next if (!defined($value));
+$result{$key_oid}{value}=$value;
+$result{$key_oid}{vendor}=$key;
+last;
+}
+
+$session->close;
+
+if (!%result) { printf("OK: Unknown model. \n"); exit 0; }
+
+my $result_ok = 0;
+foreach my $key (keys %result) {
+next if (!$key);
+my $return_value = $result{$key}{value};
+next if (!defined($return_value));
+$result_ok = 1;
+if ($result{$key}{value} eq 'apc' and $return_value > 1) {
+    print("ERROR!!! Battery requires replacement!\n");
+    exit 2;
+    }
+#eaton
+if ($result{$key}{value} eq 'eaton' and ($return_value == 1 or $return_value ==3)) {
+    print("ERROR!!! Battery requires replacement!\n");
+    exit 2;
+    }
+}
+
+if ($result_ok) {
+    printf("OK. No Battery requires replacement.\n");
+    exit 0;
+    }
+
+printf("WARNING! You shouldn't have seen this. If you still see it, something clearly went wrong.\n");
+exit 3;

+ 93 - 0
docs/nagios/scripts/plugins/check_ups_battery_temp

@@ -0,0 +1,93 @@
+#!/usr/bin/perl
+
+use strict;
+use Net::SNMP;
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+my $debug = 0;
+
+my %ups_oids = (
+#default
+#apc
+'apc'=>'.1.3.6.1.4.1.318.1.1.1.2.2.2.0',
+#eaton
+'eaton'=>'.1.3.6.1.4.1.534.1.6.1.0',
+);
+
+exit if (!$ARGV[0]);
+
+my $hostip=$ARGV[0];
+
+my ($session, $error) = Net::SNMP->session(
+   -hostname  => shift || $hostip,
+   -community => shift || 'public',
+   -port      => shift || '161',
+   -timeout   => 5,
+   -version   => shift || '1',
+);
+
+if (!defined($session)) { printf("ERROR: %s.\n", $error); exit 1; }
+
+my %result;
+foreach my $key (sort keys %ups_oids) {
+my $key_oid = $ups_oids{$key};
+my $ret = $session->get_request( -varbindlist => [$key_oid] );
+my $value;
+if (!$ret) {
+    #search in subtree
+    $ret = $session->get_next_request( -varbindlist => [$key_oid] );
+    my @keys_next = keys %$ret;
+    if (scalar @keys_next and $keys_next[0]) {
+        my $get_key = $keys_next[0];
+        if ($get_key=~/^$key_oid/) {
+            $value = $ret->{$get_key};
+            print STDERR "Get-Next for key $key_oid: $get_key => $value\n" if ($debug);
+            }
+        }
+    } else {
+    $value = $ret->{$key_oid};
+    print STDERR "Get: $key_oid => $value\n" if ($debug);
+    }
+next if (!defined($value));
+$result{$key_oid}{value}=$value;
+$result{$key_oid}{vendor}=$key;
+last;
+}
+
+$session->close;
+
+if (!%result) { printf("OK: Unknown model. \n"); exit 0; }
+
+my $result_ok = 0;
+
+my $perf_data = "input=%s;210;170;0;280;";
+my $return_value;
+
+foreach my $key (keys %result) {
+next if (!$key);
+$return_value = $result{$key}{value};
+next if (!defined($return_value));
+$result_ok = 1;
+
+########### check space
+if ($return_value >=55) {
+    printf("ERROR! Temperature of batteries %s Degrees. There will be flames soon |".$perf_data."\n", $return_value,$return_value);
+    exit 2;
+    }
+if ($return_value >=38) {
+    printf("ERROR! Burns. Temperature of batteries %s Degrees |".$perf_data."\n", $return_value,$return_value);
+    exit 2;
+    }
+}
+
+if ($result_ok) {
+    #print OK
+    printf("OK Temperature of batteries %s Degrees |".$perf_data."\n", $return_value,$return_value);
+    exit 0;
+    }
+
+printf("WARNING! You shouldn't have seen this. If you still see it, something clearly went wrong.\n");
+exit 3;

+ 93 - 0
docs/nagios/scripts/plugins/check_ups_charge_battery

@@ -0,0 +1,93 @@
+#!/usr/bin/perl
+
+use strict;
+use Net::SNMP;
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+my $debug = 0;
+
+my %ups_oids = (
+#default ups mib
+'_default'=>'.1.3.6.1.2.1.33.1.2.4',
+#eaton
+'powerware'=>'.1.3.6.1.4.1.318.1.1.1.2.2.1.0',
+#eaton 9PX3000i RT 2U
+'eaton'=>'.1.3.6.1.4.1.534.1.2.4.0',
+);
+
+exit if (!$ARGV[0]);
+
+my $hostip=$ARGV[0];
+
+my ($session, $error) = Net::SNMP->session(
+   -hostname  => shift || $hostip,
+   -community => shift || 'public',
+   -port      => shift || '161',
+   -timeout   => 5,
+   -version   => shift || '1',
+);
+
+if (!defined($session)) { printf("ERROR: %s.\n", $error); exit 1; }
+
+my %result;
+foreach my $key (sort keys %ups_oids) {
+my $key_oid = $ups_oids{$key};
+my $ret = $session->get_request( -varbindlist => [$key_oid] );
+my $value;
+if (!$ret) {
+    #search in subtree
+    $ret = $session->get_next_request( -varbindlist => [$key_oid] );
+    my @keys_next = keys %$ret;
+    if (scalar @keys_next and $keys_next[0]) {
+        my $get_key = $keys_next[0];
+        if ($get_key=~/^$key_oid/) {
+            $value = $ret->{$get_key};
+            print STDERR "Get-Next for key $key_oid: $get_key => $value\n" if ($debug);
+            }
+        }
+    } else {
+    $value = $ret->{$key_oid};
+    print STDERR "Get: $key_oid => $value\n" if ($debug);
+    }
+next if (!defined($value));
+$result{$key_oid}{value}=$value;
+$result{$key_oid}{vendor}=$key;
+last;
+}
+
+$session->close;
+
+if (!%result) { printf("OK: Unknown model. \n"); exit 0; }
+
+my $result_ok = 0;
+my $perf_data = "charge=%s%%;50;30;;;";
+my $return_value;
+foreach my $key (keys %result) {
+next if (!$key);
+$return_value = $result{$key}{value};
+next if (!defined($return_value));
+$result_ok = 1;
+
+########### check temp
+
+if ($return_value < 60 and $return_value > 30) {
+    printf("WARNING! Charge of batteries: %s percents |".$perf_data."\n",$return_value,$return_value);
+    exit 1;
+    }
+if ($return_value <= 30) {
+    printf("ERROR! Charge of batteries: %s percents |".$perf_data."\n",$return_value,$return_value);
+    exit 2;
+    }
+}
+
+if ($result_ok) {
+    #print OK
+    printf("OK. Charge of batteries %s percents |".$perf_data."\n", $return_value,$return_value);
+    exit 0;
+    }
+
+printf("WARNING! You shouldn't have seen this. If you still see it, something clearly went wrong.\n");
+exit 3;

+ 52 - 0
docs/nagios/scripts/plugins/check_ups_exttemp

@@ -0,0 +1,52 @@
+#!/usr/bin/perl
+
+use strict;
+
+use Net::SNMP;
+
+exit if (!$ARGV[0]);
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+my $hostip=$ARGV[0];
+
+my ($session, $error) = Net::SNMP->session(
+   -hostname  => shift || $hostip,
+   -community => shift || 'public',
+   -timeout   => 5,
+   -port      => shift || 161 
+);
+
+if (!defined($session)) {
+   printf("ERROR: %s.\n", $error);
+   exit 1;
+}
+
+my $exttemp = '1.3.6.1.4.1.318.1.1.10.2.3.2.1.4.1';
+
+my $result = $session->get_request(
+   -varbindlist => [$exttemp]
+);
+
+if (!defined($result)) {
+    ($session, $error) = Net::SNMP->session( -hostname  => $hostip, -community => 'public' );
+    $result = $session->get_request( -varbindlist => [$exttemp] );
+    }
+
+if (!defined($result)) {
+   printf("ERROR: %s.\n", $session->error);
+   $session->close;
+   exit 2;
+}
+
+if ($result->{$exttemp} > 28) {
+   printf("ERROR Temperature of server-room: %s Degrees\n",$result->{$exttemp});
+   $session->close;
+   exit 2;
+}
+
+printf("OK Temperature of server-room %s Degrees\n", $result->{$exttemp});
+$session->close;
+exit 0;

+ 56 - 0
docs/nagios/scripts/plugins/check_ups_input1

@@ -0,0 +1,56 @@
+#!/usr/bin/perl
+
+use strict;
+
+use Net::SNMP;
+
+exit if (!$ARGV[0]);
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+my $hostip=$ARGV[0];
+
+my ($session, $error) = Net::SNMP->session(
+   -hostname  => shift || $hostip,
+   -community => shift || 'public',
+   -timeout   => 5,
+   -port      => shift || 161 
+);
+
+if (!defined($session)) {
+   printf("ERROR: %s.\n", $error);
+   exit 1;
+}
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+my $inputac = '1.3.6.1.4.1.318.1.1.1.3.2.3.0';
+
+my $result = $session->get_request(
+   -varbindlist => [$inputac]
+);
+
+my $perf_data = "input=0;210;200;0;280;";
+if (!defined($result)) {
+   printf("ERROR: %s. |".$perf_data."\n", $session->error);
+   $session->close;
+   exit 2;
+   }
+
+$perf_data = "input=%s;210;200;0;280;";
+
+if (($result->{$inputac} < 201) or $result->{$inputac} > 255) {
+   printf("ERROR Input AC: %sV |".$perf_data."\n",$result->{$inputac},$result->{$inputac});
+   $session->close;
+   exit 2;
+   }
+
+printf("OK Input AC %sV |".$perf_data."\n", $result->{$inputac},$result->{$inputac});
+$session->close;
+
+exit 0;
+

+ 52 - 0
docs/nagios/scripts/plugins/check_ups_input2

@@ -0,0 +1,52 @@
+#!/usr/bin/perl
+
+use strict;
+
+use Net::SNMP;
+
+exit if (!$ARGV[0]);
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+my $hostip=$ARGV[0];
+
+my ($session, $error) = Net::SNMP->session(
+   -hostname  => shift || $hostip,
+   -community => shift || 'public',
+   -timeout   => 5,
+   -port      => shift || 161 
+);
+
+if (!defined($session)) {
+   printf("ERROR: %s.\n", $error);
+   exit 1;
+}
+
+my $inputac = '1.3.6.1.4.1.318.1.1.1.3.2.2.0';
+
+my $result = $session->get_request(
+   -varbindlist => [$inputac]
+);
+
+my $perf_data = "input=0;210;200;0;280;";
+if (!defined($result)) {
+   printf("ERROR: %s. |".$perf_data."\n", $session->error);
+   $session->close;
+   exit 2;
+   }
+
+$perf_data = "input=%s;210;200;0;280;";
+
+if (($result->{$inputac} < 201) or $result->{$inputac} > 255) {
+   printf("ERROR Input AC: %sV |".$perf_data."\n",$result->{$inputac},$result->{$inputac});
+   $session->close;
+   exit 2;
+   }
+
+printf("OK Input AC %sV |".$perf_data."\n", $result->{$inputac},$result->{$inputac});
+$session->close;
+
+exit 0;
+

+ 53 - 0
docs/nagios/scripts/plugins/check_ups_input3

@@ -0,0 +1,53 @@
+#!/usr/bin/perl
+
+use strict;
+
+use Net::SNMP;
+
+exit if (!$ARGV[0]);
+
+
+my $hostip=$ARGV[0];
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+my ($session, $error) = Net::SNMP->session(
+   -hostname  => shift || $hostip,
+   -community => shift || 'public',
+   -timeout   => 5,
+   -port      => shift || 161 
+);
+
+if (!defined($session)) {
+   printf("ERROR: %s.\n", $error);
+   exit 1;
+}
+
+my $inputac = '1.3.6.1.4.1.318.1.1.1.3.2.1.0';
+
+my $result = $session->get_request(
+   -varbindlist => [$inputac]
+);
+
+my $perf_data = "input=0;210;200;0;280;";
+if (!defined($result)) {
+   printf("ERROR: %s. |".$perf_data."\n", $session->error);
+   $session->close;
+   exit 2;
+   }
+
+$perf_data = "input=%s;210;200;0;280;";
+
+if (($result->{$inputac} < 201) or $result->{$inputac} > 255) {
+   printf("ERROR Input AC: %sV |".$perf_data."\n",$result->{$inputac},$result->{$inputac});
+   $session->close;
+   exit 2;
+   }
+
+printf("OK Input AC %sV |".$perf_data."\n", $result->{$inputac},$result->{$inputac});
+$session->close;
+
+exit 0;
+

+ 97 - 0
docs/nagios/scripts/plugins/check_ups_input_ac

@@ -0,0 +1,97 @@
+#!/usr/bin/perl
+
+use strict;
+use Net::SNMP;
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+my $debug = 0;
+
+my %ups_oids = (
+#default
+'_default'=>'.1.3.6.1.2.1.33.1.3.3.1.3.1',
+#apc
+'apc'=>'.1.3.6.1.4.1.318.1.1.1.3.2.1',
+);
+
+exit if (!$ARGV[0]);
+
+my $hostip=$ARGV[0];
+
+my ($session, $error) = Net::SNMP->session(
+   -hostname  => shift || $hostip,
+   -community => shift || 'public',
+   -port      => shift || '161',
+   -timeout   => 5,
+   -version   => shift || '1',
+);
+
+if (!defined($session)) { printf("ERROR: %s.\n", $error); exit 1; }
+
+my %result;
+foreach my $key (sort keys %ups_oids) {
+my $key_oid = $ups_oids{$key};
+my $ret = $session->get_request( -varbindlist => [$key_oid] );
+my $value;
+if (!$ret) {
+    #search in subtree
+    $ret = $session->get_next_request( -varbindlist => [$key_oid] );
+    my @keys_next = keys %$ret;
+    if (scalar @keys_next and $keys_next[0]) {
+        my $get_key = $keys_next[0];
+        if ($get_key=~/^$key_oid/) {
+            $value = $ret->{$get_key};
+            print STDERR "Get-Next for key $key_oid: $get_key => $value\n" if ($debug);
+            }
+        }
+    } else {
+    $value = $ret->{$key_oid};
+    print STDERR "Get: $key_oid => $value\n" if ($debug);
+    }
+next if (!defined($value));
+$result{$key_oid}{value}=$value;
+$result{$key_oid}{vendor}=$key;
+last;
+}
+
+$session->close;
+
+if (!%result) { printf("OK: Unknown model. \n"); exit 0; }
+
+my $result_ok = 0;
+
+my $perf_data = "input=%s;200;170;0;280;";
+my $return_value;
+
+foreach my $key (keys %result) {
+next if (!$key);
+$return_value = $result{$key}{value};
+
+next if (!defined($return_value));
+$result_ok = 1;
+
+########### check space
+if ($return_value > 240) {
+   printf("ERROR! Input AC: %sV |".$perf_data."\n",$return_value,$return_value);
+   exit 2;
+   }
+if ($return_value > 170 and $return_value<=200) {
+   printf("WARNING! Input AC: %sV |".$perf_data."\n",$return_value,$return_value);
+   exit 1;
+   }
+if ($return_value <=170) {
+   printf("ERROR! Input AC: %sV |".$perf_data."\n",$return_value,$return_value);
+   exit 2;
+   }
+}
+
+if ($result_ok) {
+    #print OK
+    printf("OK. Input AC %sV |".$perf_data."\n", $return_value,$return_value);
+    exit 0;
+    }
+
+printf("WARNING! You shouldn't have seen this. If you still see it, something clearly went wrong.\n");
+exit 3;

+ 106 - 0
docs/nagios/scripts/plugins/check_ups_leave_time

@@ -0,0 +1,106 @@
+#!/usr/bin/perl
+
+use strict;
+use Net::SNMP qw(ticks_to_time TRANSLATE_NONE);
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+my $debug = 0;
+
+my %ups_oids = (
+#default
+'_default'=>'.1.3.6.1.2.1.33.1.2.3.0',
+#apc
+'apc'=>'.1.3.6.1.4.1.318.1.1.1.2.2.3',
+#powerware
+'powerware'=>'.1.3.6.1.4.1.534.1.2.1.0',
+);
+
+exit if (!$ARGV[0]);
+
+my $hostip=$ARGV[0];
+
+my ($session, $error) = Net::SNMP->session(
+   -hostname  => shift || $hostip,
+   -community => shift || 'public',
+   -port      => shift || '161',
+   -timeout   => 5,
+   -version   => shift || '1',
+);
+
+if (!defined($session)) { printf("ERROR: %s.\n", $error); exit 1; }
+
+my %result;
+foreach my $key (sort keys %ups_oids) {
+my $key_oid = $ups_oids{$key};
+my $ret = $session->get_request( -varbindlist => [$key_oid] );
+my $value;
+if (!$ret) {
+    #search in subtree
+    $ret = $session->get_next_request( -varbindlist => [$key_oid] );
+    my @keys_next = keys %$ret;
+    if (scalar @keys_next and $keys_next[0]) {
+        my $get_key = $keys_next[0];
+        if ($get_key=~/^$key_oid/) {
+            $value = $ret->{$get_key};
+            print STDERR "Get-Next for key $key_oid: $get_key => $value\n" if ($debug);
+            }
+        }
+    } else {
+    $value = $ret->{$key_oid};
+    print STDERR "Get: $key_oid => $value\n" if ($debug);
+    }
+next if (!defined($value));
+$result{$key_oid}{value}=$value;
+$result{$key_oid}{vendor}=$key;
+last;
+}
+
+$session->close;
+
+if (!%result) { printf("OK: Unknown model. \n"); exit 0; }
+
+my $result_ok = 0;
+
+my $perf_data = "remain=%sm;10;8;;;";
+my $return_value;
+my $online_min;
+foreach my $key (keys %result) {
+next if (!$key);
+$return_value = $result{$key}{value};
+
+next if (!defined($return_value));
+$result_ok = 1;
+
+########### check space
+#apc
+if ($result{$key}{vendor} eq 'apc') { $online_min = int($return_value/6000); }
+#eaton
+if ($result{$key}{vendor} eq 'powerware') { $online_min = int($return_value/60); }
+#default
+if ($result{$key}{vendor} eq '_default') { $online_min = $return_value; }
+
+print STDERR "$key => $online_min\n" if ($debug);
+
+#compare
+if ($online_min <= 8) {
+    printf("ERROR! Before switching-off ups remains %s minutes |".$perf_data."\n", $online_min,$online_min);
+    exit 2;
+    }
+
+if ($online_min > 8 and $online_min<=10) {
+    printf("WARNING! Before switching-off ups remains %s minutes |".$perf_data."\n", $online_min,$online_min);
+    exit 1;
+    }
+}
+
+if ($result_ok) {
+    #print OK
+    printf("OK Before switching-off ups remains %s minutes |".$perf_data."\n", $online_min,$online_min);
+    exit 0;
+    }
+
+printf("WARNING! You shouldn't have seen this. If you still see it, something clearly went wrong.\n");
+exit 3;

+ 93 - 0
docs/nagios/scripts/plugins/check_ups_load

@@ -0,0 +1,93 @@
+#!/usr/bin/perl
+
+use strict;
+use Net::SNMP;
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+my $debug = 0;
+
+my %ups_oids = (
+#default ups mib
+'_default'=>'.1.3.6.1.2.1.33.1.4.4.1.5.1',
+#apc
+'apc'=>'.1.3.6.1.4.1.318.1.1.1.4.2.3.0',
+#eaton
+'powerware'=>'.1.3.6.1.4.1.534.1.4.1',
+);
+
+exit if (!$ARGV[0]);
+
+my $hostip=$ARGV[0];
+
+my ($session, $error) = Net::SNMP->session(
+   -hostname  => shift || $hostip,
+   -community => shift || 'public',
+   -port      => shift || '161',
+   -timeout   => 5,
+   -version   => shift || '1',
+);
+
+if (!defined($session)) { printf("ERROR: %s.\n", $error); exit 1; }
+
+my %result;
+foreach my $key (sort keys %ups_oids) {
+my $key_oid = $ups_oids{$key};
+my $ret = $session->get_request( -varbindlist => [$key_oid] );
+my $value;
+if (!$ret) {
+    #search in subtree
+    $ret = $session->get_next_request( -varbindlist => [$key_oid] );
+    my @keys_next = keys %$ret;
+    if (scalar @keys_next and $keys_next[0]) {
+        my $get_key = $keys_next[0];
+        if ($get_key=~/^$key_oid/) {
+            $value = $ret->{$get_key};
+            print STDERR "Get-Next for key $key_oid: $get_key => $value\n" if ($debug);
+            }
+        }
+    } else {
+    $value = $ret->{$key_oid};
+    print STDERR "Get: $key_oid => $value\n" if ($debug);
+    }
+next if (!defined($value));
+$result{$key_oid}{value}=$value;
+$result{$key_oid}{vendor}=$key;
+last;
+}
+
+$session->close;
+
+if (!%result) { printf("OK: Unknown model. \n"); exit 0; }
+
+my $result_ok = 0;
+my $perf_data = "load=%s%%;80;50;;;";
+my $return_value;
+foreach my $key (keys %result) {
+next if (!$key);
+$return_value = $result{$key}{value};
+next if (!defined($return_value));
+$result_ok = 1;
+########### check space
+
+if ($return_value >= 80) {
+    printf("ERROR! Loading on UPS: %s percents. Don't interfere! We drink tea, work as a grinder... |".$perf_data."\n",$return_value,$return_value);
+    exit 2;
+    }
+
+if ($return_value < 80) {
+    printf("OK! Loading on UPS: %s percents |".$perf_data."\n",$return_value,$return_value);
+    exit 0;
+    }
+}
+
+if ($result_ok) {
+    #print OK
+    printf("OK. Loading on UPS: %s percents |".$perf_data."\n", $return_value,$return_value);
+    exit 0;
+    }
+
+printf("WARNING! You shouldn't have seen this. If you still see it, something clearly went wrong.\n");
+exit 3;

+ 78 - 0
docs/nagios/scripts/plugins/check_ups_model

@@ -0,0 +1,78 @@
+#!/usr/bin/perl
+
+use strict;
+use Net::SNMP;
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+my $debug = 0;
+
+my %ups_oids = (
+#default ups mib
+'_default'=>'.1.3.6.1.2.1.33.1.1.2',
+#apc
+'apc'=>'.1.3.6.1.4.1.318.1.1.1.1.1.1.0',
+#eaton
+'powerware'=>'.1.3.6.1.4.1.534.1.1.2.0',
+);
+
+exit if (!$ARGV[0]);
+
+my $hostip=$ARGV[0];
+
+my ($session, $error) = Net::SNMP->session(
+   -hostname  => shift || $hostip,
+   -community => shift || 'public',
+   -port      => shift || '161',
+   -timeout   => 5,
+   -version   => shift || '1',
+);
+
+if (!defined($session)) { printf("ERROR: %s.\n", $error); exit 1; }
+
+my %result;
+foreach my $key (sort keys %ups_oids) {
+my $key_oid = $ups_oids{$key};
+my $ret = $session->get_request( -varbindlist => [$key_oid] );
+my $value;
+if (!$ret) {
+    #search in subtree
+    $ret = $session->get_next_request( -varbindlist => [$key_oid] );
+    my @keys_next = keys %$ret;
+    if (scalar @keys_next and $keys_next[0]) {
+        my $get_key = $keys_next[0];
+        if ($get_key=~/^$key_oid/) {
+            $value = $ret->{$get_key};
+            print STDERR "Get-Next for key $key_oid: $get_key => $value\n" if ($debug);
+            }
+        }
+    } else {
+    $value = $ret->{$key_oid};
+    print STDERR "Get: $key_oid => $value\n" if ($debug);
+    }
+next if (!defined($value));
+$result{$key_oid}{value}=$value;
+$result{$key_oid}{vendor}=$key;
+last;
+}
+
+$session->close;
+
+if (!%result) { printf("OK: Unknown model. \n"); exit 0; }
+
+my $result_ok = 0;
+my $return_value;
+foreach my $key (keys %result) {
+next if (!$key);
+$return_value = $result{$key}{value};
+next if (!defined($return_value));
+$result_ok = 1;
+########### check space
+printf("OK! Model: %s \n",$return_value);
+exit 0;
+}
+
+printf("WARNING! You shouldn't have seen this. If you still see it, something clearly went wrong.\n");
+exit 3;

+ 146 - 0
docs/nagios/scripts/plugins/check_ups_status

@@ -0,0 +1,146 @@
+#!/usr/bin/perl
+
+use strict;
+use Net::SNMP;
+
+my $TIMEOUT = 30;
+$SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
+alarm($TIMEOUT);
+
+my $debug = 0;
+
+my %ups_oids = (
+#default
+'_default'=>'.1.3.6.1.2.1.33.1.6.3.2',
+#apc ?
+'apc'=>'.1.3.6.1.4.1.318.1.1.1.4.1.1',
+#eaton
+'eaton'=>'.1.3.6.1.4.1.534.1.4.5.0',
+);
+
+my $res_state = {
+'apc' =>{
+    '1' =>'ERROR Current APC status is  unknown(1)',
+    '2' =>'OK Current APC status is  onLine(2)',
+    '3' =>'WARNING Current APC status is  onBattery(3)',
+    '4' =>'OK Current APC status is  onSmartBoost(4)',
+    '5' =>'WARNING Current APC status is  timedSleeping(5)',
+    '6' =>'WARNING Current APC status is  softwareBypass(6)',
+    '7' =>'ERROR Current APC status is  off(7)',
+    '8' =>'WARNING Current APC status is  rebooting(8)',
+    '9' =>'WARNING Current APC status is  switchedBypass(9)',
+    '10' =>'ERROR Current APC status is  hardwareFailureBypass(10)',
+    '11' =>'WARNING Current APC status is  sleepingUntilPowerReturn(11)'
+    },
+'eaton' => {
+    '1' => 'UNKNOWN State: other',
+    '2' => 'OK Offline mode: Load not powered',
+    '3' => 'OK State normal',
+    '4' => 'WARNING On bypass',
+    '5' => 'WARNING On battery',
+    '6' => 'OK Battery booster',
+    '7' => 'OK Battery reducer',
+    '8' => 'WARNING parallelCapacity',
+    '9' => 'WARNING parallelRedundant',
+    '10'=> 'OK highEfficiencyMode',
+    }
+};
+
+my $res_retcode = {
+'apc'=>{
+    '1' =>'2',
+    '2' =>'0',
+    '3' =>'1',
+    '4' =>'0',
+    '5' =>'1',
+    '6' =>'1',
+    '7' =>'2',
+    '8' =>'1',
+    '9' =>'1',
+    '10' =>'2',
+    '11' =>'1'
+    },
+'eaton'=>{
+    '1' =>'3',
+    '2' =>'0',
+    '3' =>'0',
+    '4' =>'1',
+    '5' =>'1',
+    '6' =>'0',
+    '7' =>'0',
+    '8' =>'1',
+    '9' =>'1',
+    '10' =>'0',
+    }
+};
+
+exit if (!$ARGV[0]);
+
+my $hostip=$ARGV[0];
+
+my ($session, $error) = Net::SNMP->session(
+   -hostname  => shift || $hostip,
+   -community => shift || 'public',
+   -port      => shift || '161',
+   -timeout   => 5,
+   -version   => shift || '1',
+);
+
+if (!defined($session)) { printf("ERROR: %s.\n", $error); exit 1; }
+
+my %result;
+foreach my $key (sort keys %ups_oids) {
+my $key_oid = $ups_oids{$key};
+my $ret = $session->get_request( -varbindlist => [$key_oid] );
+
+my $value;
+if (!$ret) {
+    #search in subtree
+    $ret = $session->get_next_request( -varbindlist => [$key_oid] );
+    my @keys_next = keys %$ret;
+    if (scalar @keys_next and $keys_next[0]) {
+        my $get_key = $keys_next[0];
+        if ($get_key=~/^$key_oid/) {
+            $value = $ret->{$get_key};
+            print STDERR "Get-Next for key $key_oid: $get_key => $value\n" if ($debug);
+            }
+        }
+    } else {
+    $value = $ret->{$key_oid};
+    print STDERR "Get: $key_oid => $value\n" if ($debug);
+    }
+next if (!defined($value));
+$result{$key_oid}{value}=$value;
+$result{$key_oid}{vendor}=$key;
+last;
+}
+
+$session->close;
+
+if (!%result) { printf("OK: Unknown model. \n"); exit 0; }
+
+my $result_ok = 0;
+foreach my $key (keys %result) {
+next if (!$key);
+my $return_value = $result{$key}{value};
+next if (!defined($return_value));
+$result_ok = 1;
+#apc
+if ($result{$key}{vendor} eq 'apc') {
+    print($res_state->{apc}->{$return_value}."\n");
+    exit $res_retcode->{apc}->{$return_value};
+    }
+#default
+if ($result{$key}{vendor} eq '_default') {
+    printf("ERROR: Alarm OnBattery detected! %s\n", $return_value);
+    exit 2;
+    }
+#eaton
+if ($result{$key}{vendor} eq 'eaton') {
+    print($res_state->{eaton}->{$return_value}."\n");
+    exit $res_retcode->{eaton}->{$return_value};
+    }
+}
+
+printf("OK Alarm OnBattery not found.\n\n");
+exit 0;

BIN
docs/nagios/scripts/plugins/libcrypto.so.10


BIN
docs/nagios/scripts/plugins/libssl.so.10


+ 112 - 0
docs/nagios/scripts/plugins/snmp.pm

@@ -0,0 +1,112 @@
+package snmp;
+
+#
+# Copyright (C) Roman Dmitiriev, rnd@rajven.ru
+#
+
+use utf8;
+use open ":encoding(utf8)";
+use strict;
+use English;
+use base 'Exporter';
+use vars qw(@EXPORT @ISA);
+use Net::SNMP;
+
+@ISA = qw(Exporter);
+@EXPORT = qw(
+snmp_set_int
+snmp_get_request
+snmp_get_oid
+init_snmp
+);
+
+
+BEGIN
+{
+
+#---------------------------------------------------------------------------------
+
+sub snmp_get_request {
+my $ip = shift;
+my $oid = shift;
+my $snmp = shift;
+my $session = init_snmp ($ip,$snmp);
+return if (!defined($session) or !$session);
+my $result = $session->get_request( -varbindlist => [$oid]);
+$session->close;
+return if (!$result->{$oid});
+return $result->{$oid};
+}
+
+#---------------------------------------------------------------------------------
+
+sub snmp_set_int {
+my $ip = shift;
+my $oid = shift;
+my $value = shift;
+my $snmp = shift;
+my $session = init_snmp ($ip,$snmp,1);
+return if (!defined($session) or !$session);
+my $result = $session->set_request( -varbindlist => [$oid,INTEGER,$value]);
+$session->close;
+return $result->{$oid};
+}
+
+#-------------------------------------------------------------------------------------
+
+sub snmp_get_oid {
+my ($host,$snmp,$oid) = @_;
+my $port = 161;
+my $session = init_snmp ($host,$snmp,0);
+return if (!defined($session) or !$session);
+$session->translate([-timeticks]);
+my $table = $session->get_table($oid);
+$session->close();
+return $table;
+}
+
+#-------------------------------------------------------------------------------------
+
+sub init_snmp {
+
+    my ($host,$snmp) = @_;
+
+    return if (!$host);
+
+    ### open SNMP session
+    my ($session, $error);
+
+    if ($snmp->{version} <=2) {
+        ($session, $error) = Net::SNMP->session(
+		-hostname  => $host,
+		-community => $snmp->{'community'} ,
+		-version   => $snmp->{'version'},
+		-port      => 161,
+		-timeout   => $snmp->{timeout},
+		);
+	} else {
+	($session, $error) = Net::SNMP->session(
+		-hostname     => $host,
+		-version      => 'snmpv3',
+		-username     => $snmp->{'user'},
+		-authprotocol => $snmp->{'auth'},
+		-privprotocol => $snmp->{'priv'},
+		-authpassword => $snmp->{'community'},
+		-privpassword => $snmp->{'community'},
+		-port         => 161,
+		-timeout      => $snmp->{timeout},
+		);
+	}
+
+    if (!defined($session)) {
+        printf("ERROR: %s.\n", $error);
+	exit 0;
+	}
+
+    return $session;
+}
+
+#-------------------------------------------------------------------------------------
+
+1;
+}

+ 64 - 0
docs/nagios/snmp.cfg

@@ -0,0 +1,64 @@
+#ARG1 : host type (stand,netsc,netsl,as400,cisco,cata,nsc,fg,bc,nokia,hp,lp,hpux)
+#ARG2 : warning level 
+#ARG3 : critical level
+#ARG4 : community
+define command{
+   command_name check_snmp_load
+   command_line  $USER1$/check_snmp_load.pl -H $HOSTADDRESS$ -C $ARG4$ -2 -T $ARG1$ -w $ARG2$ -c $ARG3$
+}
+
+#ARG1 : regexp of storage name
+#ARG2 : warning level
+#ARG3 : critical level
+define command{
+  command_name check_snmp_storage
+  command_line  $USER1$/check_snmp_storage.pl -H $HOSTADDRESS$ -C $ARG4$ -2 -m $ARG1$ -w $ARG2$ -c $ARG3$
+}
+
+#ARG1 : regexp of process name
+#ARG2 : warning level(s)
+#ARG3 : critical level(s) 
+#ARG4 : additional arguments if needed.
+define command{
+  command_name check_snmp_process
+  command_line  $USER1$/check_snmp_process.pl -H $HOSTADDRESS$ -C $ARG4$ -2 -n $ARG1$ -w $ARG2$ -c $ARG3$
+}
+
+#walk table oid
+define  command {
+    command_name        check_snmp_switch_crc
+    #host community port
+    command_line        $USER6$/check_snmp_db_crc.pl $HOSTADDRESS$ $ARG1$ $ARG2$
+}
+
+#get one oid by port
+define  command {
+    command_name        check_snmp_switch_crc_simple
+    #host community port
+    command_line        $USER6$/check_snmp_crc_simple.pl $HOSTADDRESS$ $ARG1$ $ARG2$
+}
+
+#check bandwidth usage at port
+define  command {
+    command_name        check_snmp_bandwidth
+    #host community port
+    command_line        $USER6$/check_snmp_db_bandwidth.pl $HOSTADDRESS$ $ARG1$ $ARG2$
+}
+
+# 'check_snmp' command definition
+define command{
+        command_name    check_snmp
+        command_line    $USER1$/check_snmp -H $HOSTADDRESS$ $ARG1$ -t 60
+        }
+
+# 'check_ifoperstatus' command definition
+define command{
+        command_name    check_ifoperstatus
+        command_line    $USER6$/check_ifoperstatus -H $HOSTADDRESS$ -k $ARG1$ -C $ARG2$ -v 2
+        }
+
+# 'check_ifoperstatus' command definition
+define command{
+        command_name    check_ifoperstatus_v3
+        command_line    $USER6$/check_ifoperstatus -H $HOSTADDRESS$ -k $ARG1$ -v 3 -L "authPriv" -U $ARG2$ -a $ARG3$ -P $ARG4$ -A $ARG5$ -X $ARG5$
+        }

+ 42 - 18
scripts/eyelib/nagios.pm

@@ -6,7 +6,7 @@ use open ":encoding(utf8)";
 use strict;
 use English;
 use FindBin '$Bin';
-use lib "/opt/Eye/scripts";
+use lib "$Bin";
 use base 'Exporter';
 use vars qw(@EXPORT @ISA);
 use eyelib::config;
@@ -14,6 +14,7 @@ use eyelib::main;
 use eyelib::database;
 use Time::Local;
 use Data::Dumper;
+use eyelib::mfi;
 
 @ISA = qw(Exporter);
 @EXPORT = qw(
@@ -88,9 +89,13 @@ if (@custom_cfg and scalar(@custom_cfg)) {
         $row=~s/\%HOST\%/$device->{name}/;
 	$row=~s/\%HOSTIP\%/$device->{ip}/;
 	$row=~s/\%HOST_IP\%/$device->{ip}/;
-	$row=~s/\%COMMUNITY\%/$device->{community}/ if ($device->{community});
-	$row=~s/\%RW_COMMUNITY\%/$device->{rw_community}/ if ($device->{rw_community});
-	$row=~s/\%SNMP_VERSION\%/$device->{snmp_version}/ if ($device->{snmp_version});
+	$row=~s/\%COMMUNITY\%/$device->{snmp}->{'ro-community'}/ if ($device->{snmp}->{'ro-community'});
+	$row=~s/\%RW_COMMUNITY\%/$device->{snmp}->{'rw-community'}/ if ($device->{snmp}->{'rw-community'});
+	$row=~s/\%SNMP_VERSION\%/$device->{snmp}->{'version'}/ if ($device->{snmp}->{'version'});
+	$row=~s/\%SNMP_V3_AUTH\%/$device->{snmp}->{'auth-proto'}/ if ($device->{snmp}->{'auth-proto'});
+	$row=~s/\%SNMP_V3_PRIV\%/$device->{snmp}->{'priv-proto'}/ if ($device->{snmp}->{'priv-proto'});
+	$row=~s/\%SNMP_V3_RO_PASSWORD\%/$device->{snmp}->{'ro-password'}/ if ($device->{snmp}->{'ro-password'});
+	$row=~s/\%SNMP_V3_RW_PASSWORD\%/$device->{snmp}->{'rw-password'}/ if ($device->{snmp}->{'rw-password'});
 	$row=~s/\%MODEL\%/$device->{device_model}->{model_name}/ if ($device->{device_model}->{model_name});
         push(@{$result->{template}},$row);
 	if ($row=~/\s+service_description\s+(.*)$/i) { $result->{services}->{$1}=1; }
@@ -104,6 +109,11 @@ my $device = shift;
 my $host_template = 'generic-host';
 my $default_service="local-service";
 
+my $snmp_string = $device->{snmp}->{'ro-community'};
+if ($device->{snmp}->{version} > 2) {
+    $snmp_string = join(";",$device->{snmp}->{'ro-password'},$device->{snmp}->{version},$device->{snmp}->{'ro-user'},$device->{snmp}->{'auth-proto'},$device->{snmp}->{'priv-proto'});
+    }
+
 my $ping_enable = $device->{ou}->{nagios_ping};
 if ($device->{ou}->{nagios_host_use}) { $host_template=$device->{ou}->{nagios_host_use}; }
 if ($device->{ou}->{nagios_default_service}) { $default_service=$device->{ou}->{nagios_default_service}; }
@@ -131,17 +141,21 @@ if ($ping_enable) {
 	print(FH "       use                    ping-service\n");
 	print(FH "       host_name              $device->{name}\n");
 	print(FH "       service_description    ping $device->{name}\n");
-	print(FH "       check_command          check_ping_icmp!100.0,20%!500.0,60%\n");
+	print(FH "       check_command          check_ping!100.0,20%!500.0,60%\n");
 	print(FH "       }\n");
 	print(FH "\n");
     }
-if ($device->{parent_name} and $device->{link_check} and $device->{parent_snmp_version}) {
+if ($device->{parent_name} and $device->{link_check} and $device->{parent_snmp}->{version}) {
 	#port status
         print(FH "define service{\n");
         print(FH "       use                        $default_service\n");
         print(FH "       host_name                  $device->{parent_name}\n");
         print(FH "       service_description port $device->{parent_port} - $device->{name}\n");
-        print(FH "       check_command              check_ifoperstatus!$device->{parent_port_snmp_index}!$device->{parent_community}\n");
+	if ($device->{parent_snmp}->{version}<3) {
+            print(FH "       check_command              check_ifoperstatus!$device->{parent_port_snmp_index}!$device->{snmp}->{'ro-community'}\n");
+	    } else {
+            print(FH "       check_command              check_ifoperstatus_v3!$device->{parent_port_snmp_index}!$device->{parent_snmp}->{'ro-user'}!$device->{parent_snmp}->{'auth-proto'}!$device->{parent_snmp}->{'priv-proto'}!$device->{parent_snmp}->{'ro-password'}\n");
+	    }
         print(FH "       }\n");
         print(FH "\n");
         #crc
@@ -149,7 +163,7 @@ if ($device->{parent_name} and $device->{link_check} and $device->{parent_snmp_v
         print(FH "       use                        service-snmp-crc\n");
         print(FH "       host_name                  $device->{parent_name}\n");
         print(FH "       service_description port $device->{parent_port} - $device->{name} CRC Errors\n");
-        print(FH "       check_command              check_snmp_switch_crc!$device->{parent_community}!$device->{parent_port_snmp_index}\n");
+        print(FH "       check_command              check_snmp_switch_crc!$snmp_string!$device->{parent_port_snmp_index}\n");
         print(FH "       }\n\n");
     }
 close(FH);
@@ -171,6 +185,11 @@ my $default_service="local-service";
 
 if (!$device->{ou}->{nagios_dir}) { print Dumper($device); }
 
+my $snmp_string = $device->{snmp}->{'ro-community'};
+if ($device->{snmp}->{version} > 2) {
+    $snmp_string = join(";",$device->{snmp}->{'ro-password'},$device->{snmp}->{version},$device->{snmp}->{'ro-user'},$device->{snmp}->{'auth-proto'},$device->{snmp}->{'priv-proto'});
+    }
+
 my $cfg_file = $device->{ou}->{nagios_dir}."/".$device->{name}.".cfg";
 
 if ($custom_cfg->{template}) {
@@ -186,11 +205,11 @@ if ($custom_cfg->{template}) {
     return;
     }
 
-#switch | router
+#router | switch | gateway
 if (in_array([0,1,2],$device->{type})) {
     open(FH, "> $cfg_file");
     my $device_template = 'switches';
-    if ($device->{type} eq 2) {  $device_template='routers'; }
+    if (in_array([0,2],$device->{type})) {  $device_template='routers'; }
     print(FH "define  host {\n");
     print(FH "       use                     $device_template\n");
     print(FH "       host_name               $device->{name}\n");
@@ -199,7 +218,7 @@ if (in_array([0,1,2],$device->{type})) {
     print(FH "       _ID                     $device->{device_id}\n");
     print(FH "       _TYPE                   device\n");
     if ($device->{device_model}) {
-	print(FH "       notes		$device->{device_model}->{model_name}\n");
+	print(FH "       notes                      $device->{device_model}->{model_name}\n");
 	}
     if ($device->{parent_name}) {
         print(FH "       parents                    $device->{parent_name}\n");
@@ -211,15 +230,15 @@ if (in_array([0,1,2],$device->{type})) {
     print(FH "        use                             ping-service         ; Name of service template to use\n");
     print(FH "        host_name                       $device->{name}\n");
     print(FH "        service_description             ping $device->{name}\n");
-    print(FH "        check_command                   check_ping_icmp!100.0,20%!500.0,60%\n");
+    print(FH "        check_command                   check_ping!100.0,20%!500.0,60%\n");
     print(FH "        }\n");
     #uptime
-    if ($device->{snmp_version}) {
+    if ($device->{snmp}->{version}) {
         print(FH "define service{\n");
 	print(FH "        use                             $default_service\n");
         print(FH "        host_name                       $device->{name}\n");
 	print(FH "        service_description             Uptime\n");
-        print(FH "        check_command                   check_snmp_uptime!$device->{community}!161!$device->{snmp_version}\n");
+        print(FH "        check_command                   check_snmp_uptime!$snmp_string\n");
 	print(FH "        }\n");
         print(FH "\n");
         #uplink
@@ -230,7 +249,7 @@ if (in_array([0,1,2],$device->{type})) {
             my $port_description = $device->{parent_name};
             my $conn = $device->{uplink};
             print(FH "       service_description port $conn->{port} - $port_description CRC Errors\n");
-            print(FH "       check_command              check_snmp_switch_crc!$device->{community}!$conn->{snmp_index}\n");
+            print(FH "       check_command              check_snmp_switch_crc!$snmp_string!$conn->{snmp_index}\n");
             print(FH "       }\n\n");
     	    }
 	foreach my $conn (@{$device->{downlinks}}) {
@@ -241,7 +260,11 @@ if (in_array([0,1,2],$device->{type})) {
             my $port_description=translit($conn->{comment});
             if ($conn->{target_port_id}) { $port_description = $conn->{downlink_name}; }
             print(FH "       service_description port $conn->{port} - $port_description \n");
-            print(FH "       check_command              check_ifoperstatus!$conn->{snmp_index}!$device->{community}\n");
+	    if ($device->{snmp}->{version}<3) {
+        	print(FH "       check_command              check_ifoperstatus!$conn->{snmp_index}!$device->{snmp}->{'ro-community'}\n");
+		} else {
+        	print(FH "       check_command              check_ifoperstatus_v3!$conn->{snmp_index}!$device->{snmp}->{'ro-user'}!$device->{snmp}->{'auth-proto'}!$device->{snmp}->{'priv-proto'}!$device->{snmp}->{'ro-password'}\n");
+		}
             print(FH "       }\n\n");
             #src
 	    print(FH "define service{\n");
@@ -250,7 +273,7 @@ if (in_array([0,1,2],$device->{type})) {
             my $port_description=translit($conn->{comment});
             if ($conn->{target_port_id}) { $port_description = $conn->{downlink_name}; }
             print(FH "       service_description port $conn->{port} - $port_description CRC Errors\n");
-            print(FH "       check_command              check_snmp_switch_crc!$device->{community}!$conn->{snmp_index}\n");
+            print(FH "       check_command              check_snmp_switch_crc!$snmp_string!$conn->{snmp_index}\n");
             print(FH "       }\n\n");
             #band
 	    print(FH "define service{\n");
@@ -259,7 +282,7 @@ if (in_array([0,1,2],$device->{type})) {
             my $port_description=translit($conn->{comment});
             if ($conn->{target_port_id}) { $port_description = $conn->{downlink_name}; }
             print(FH "       service_description port $conn->{port} - $port_description bandwidth usage\n");
-            print(FH "       check_command              check_snmp_bandwidth!$device->{community}!$conn->{snmp_index}\n");
+            print(FH "       check_command              check_snmp_bandwidth!$snmp_string!$conn->{snmp_index}\n");
             print(FH "       }\n\n");
 	    }
 	}
@@ -281,6 +304,7 @@ if ($device->{type} eq 3) {
 		    }
 		}
         }
+
     close FH;
     }
 }

+ 6 - 20
scripts/gen_nagios_config.pl

@@ -19,6 +19,7 @@ use Net::Ping;
 use eyelib::config;
 use eyelib::main;
 use eyelib::nagios;
+use eyelib::snmp;
 use eyelib::database;
 use Fcntl qw(:flock);
 
@@ -62,14 +63,14 @@ if (scalar(@netdev_list)>0) {
         $ip =~s/\/\d+$//g;
         my $device_id = 'netdev_'.$router->{'id'};
         $devices{$device_id}{ip}=$ip;
-        $devices{$device_id}{community}=$router->{'community'} || $config_ref{snmp_default_community};
+	setCommunity($router);
+	$devices{$device_id}{snmp} = $router->{snmp};
+
         $devices{$device_id}{description}=translit($router->{'comment'});
         $devices{$device_id}{name} = $router->{'device_name'};
         $devices{$device_id}{device_model_id} = $router->{'device_model_id'};
         if ($router->{'device_model_id'}) { $devices{$device_id}{device_model} = $models{$router->{'device_model_id'}};  }
         $devices{$device_id}{device_id} = $router->{'id'};
-        $devices{$device_id}{snmp_version} = $router->{'snmp_version'} || $config_ref{snmp_default_version};
-        if ($devices{$device_id}{snmp_version} eq '2') { $devices{$device_id}{snmp_version}='2c'; }
         $devices{$device_id}{vendor_id} = $router->{'vendor_id'};
         $devices{$device_id}{ou_id} = 0;
         #1 - switch; 2 - router; 3 - auth
@@ -91,11 +92,6 @@ if (scalar(@netdev_list)>0) {
     	    if ($devices{$device_id}{type} eq '1') { $devices{$device_id}{ou}->{nagios_dir}='switches'; }
     	    if ($devices{$device_id}{type} eq '2') { $devices{$device_id}{ou}->{nagios_dir}='routers'; }
     	    }
-
-	$devices{$device_id}{snmp_version}=$router->{'snmp_version'} || $config_ref{snmp_default_version};
-	$devices{$device_id}{community}=$router->{'community'} || $config_ref{snmp_default_community};
-        $devices{$device_id}{rw_community}=$router->{'rw_community'} || $config_ref{snmp_default_community};
-        $devices{$device_id}{fdb_snmp_index}=$router->{'fdb_snmp_index'};
         $devices{$device_id}{user_id}=$router->{'user_id'};
         #get uplinks
         my $uplink_port = get_record_sql($dbh,"SELECT * FROM device_ports WHERE uplink=1 AND device_id=".$devices{$device_id}{device_id}." AND target_port_id>0 ORDER BY port DESC");
@@ -155,16 +151,7 @@ if (scalar(@auth_list)>0) {
 	next if ($auth_device and $auth_device->{device_type}<=2);
 
 	#snmp parameters
-	if ($auth_device) {
-		$devices{$device_id}{snmp_version}=$auth_device->{snmp_version};
-		$devices{$device_id}{community}=$auth_device->{community};
-		$devices{$device_id}{rw_community}=$auth_device->{rw_community};
-		$devices{$device_id}{name}=$auth_device->{device_name};
-		} else {
-		$devices{$device_id}{snmp_version}=$config_ref{snmp_default_version};
-		$devices{$device_id}{community}=$config_ref{snmp_default_community};
-		$devices{$device_id}{rw_community}=$config_ref{snmp_default_community};
-		}
+	setCommunity($auth_device);
 
         $devices{$device_id}{ip}=$ip;
 
@@ -207,8 +194,7 @@ if (scalar(@auth_list)>0) {
                 $devices{$device_id}{parent_port} = $uplink->{port};
 	        $devices{$device_id}{parent_port_snmp_index} = $uplink->{snmp_index};
         	$devices{$device_id}{parent_name}=$devices{$devices{$device_id}{parent}}->{'name'};
-        	$devices{$device_id}{parent_snmp_version}=$devices{$devices{$device_id}{parent}}->{'snmp_version'};
-        	$devices{$device_id}{parent_community}=$devices{$devices{$device_id}{parent}}->{'community'};
+        	$devices{$device_id}{parent_snmp}=$devices{$devices{$device_id}{parent}}->{'snmp'};
         	}
             }
         }