From 206f55f3f1c50a46994970d03984a4a77df9e6d0 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 15 Oct 2019 16:38:51 +0200 Subject: [PATCH] Add XOS SNMP v3 plugin Added modified Extreme OS plugins for SNMP v3 usage --- check_extreme_fans_v3.pl | 152 ++++++++++++++++++++++++++ check_extreme_mem_v3.pl | 186 ++++++++++++++++++++++++++++++++ check_extreme_powersupply_v3.pl | 155 ++++++++++++++++++++++++++ check_extreme_temp_v3.pl | 140 ++++++++++++++++++++++++ 4 files changed, 633 insertions(+) create mode 100644 check_extreme_fans_v3.pl create mode 100644 check_extreme_mem_v3.pl create mode 100644 check_extreme_powersupply_v3.pl create mode 100644 check_extreme_temp_v3.pl diff --git a/check_extreme_fans_v3.pl b/check_extreme_fans_v3.pl new file mode 100644 index 0000000..4c4b143 --- /dev/null +++ b/check_extreme_fans_v3.pl @@ -0,0 +1,152 @@ +#!/usr/bin/perl -w +################################################# +# +# Monitor FANS of an extreme networks device +# written by Martin Scharm +# see http://binfalse.de +# modified for SNMPv3 by Benjamin Gauß +# +################################################# + +use strict; +use Net::SNMP; +use Getopt::Long; + +use lib "/usr/lib64/nagios/plugins/"; +use utils qw($TIMEOUT %ERRORS); + +my $FANTABLE = '1.3.6.1.4.1.1916.1.1.1.9.1'; +my $FAN_DEV = '1'; +my $FAN_STATE = '2'; +my $FAN_SPEED = '4'; + + +my $returnvalue = $ERRORS{"OK"}; +my $returnstring = ""; +my $returnsupp = ""; + +my $switch = undef; +my $username = undef; +my $authpassword = undef; +my $authprotocol = undef; +my $privpassword = undef; +my $privprotocol = undef; +my $help = undef; + +Getopt::Long::Configure ("bundling"); +GetOptions( + 'h' => \$help, + 'help' => \$help, + 's:s' => \$switch, + 'switch:s' => \$switch, + 'U:s' => \$username, + 'user:s' => \$username, + 'A:s' => \$authpassword, + 'authpassword:s' => \$authpassword, + 'a:s' => \$authprotocol, + 'authprotocol:s' => \$authprotocol, + 'P:s' => \$privpassword, + 'privpassword:s' => \$privpassword, + 'p:s' => \$privprotocol, + 'privprotocol:s' => \$privprotocol, + 'T:s' => \$TIMEOUT, + 'timeout:s' => \$TIMEOUT +); + +sub print_usage +{ + print "Usage: $0 -s -U -A -a -P -p [-T ]\n\n"; + print " the switch's hostname or ip address\n"; + print " the SNMPv3 username\n"; + print " the password for SNMPv3 authentication\n"; + print " the protocol for SNMPv3 authentication\n"; + print " the privacy password for SNMPv3 data transport\n"; + print " the privacy protocol for SNMPv3data transport\n"; + print " max time to wait for an answer, defaults to ".$TIMEOUT."\n" +} + + +# CHECKS +if ( defined($help) ) +{ + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} +if ( !defined($switch) ) +{ + print "Need switch address!\n"; + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} +if ( !defined($username) ) +{ + print "Need SNMPv3 username!\n"; + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} +if ( !defined($authpassword) ) +{ + print "Need SNMPv3 authentication password!\n"; + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} +if ( !defined($authprotocol) ) +{ + print "Need SNMPv3 authentication protocol!\n"; + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} +if ( !defined($privpassword) ) +{ + print "Need SNMPv3 privacy password!\n"; + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} +if ( !defined($privprotocol) ) +{ + print "Need SNMPv3 privacy protocol!\n"; + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} + + +my ($session, $error) = Net::SNMP->session( -hostname => $switch, -version => 3, -username => $username, -authpassword => $authpassword, -authprotocol => $authprotocol, -privpassword => $privpassword, -privprotocol => $privprotocol, -timeout => $TIMEOUT); + +if (!defined($session)) { + printf("ERROR opening session: %s.\n", $error); + exit $ERRORS{"CRITICAL"}; +} +my $fan_table = $session->get_table(-baseoid => $FANTABLE); +if (!defined($fan_table)) +{ + printf("ERROR: Description table : %s.\n", $session->error); + $session->close; + exit $ERRORS{"CRITICAL"}; +} + +# building the hash with information on all the fans +my %fans = (); +foreach my $k (keys %$fan_table) +{ + my ($type,$id) = ((split(/\./, $k)) [-2,-1]); + $fans{$id}{$type} = $$fan_table{$k}; +} + +# evaluating the fans +my $ok = 0; +my $nonok = 0; +foreach my $k (sort keys %fans) +{ + $returnsupp .= $fans{$k}{$FAN_DEV} . ": " . (($fans{$k}{$FAN_STATE} == 1) ? "OK" : "FAILED") . ($fans{$k}{$FAN_SPEED} ? " (" . $fans{$k}{$FAN_SPEED} . "RPM)" : "") . "; "; + $ok++ if $fans{$k}{2} == 1; + $nonok++ if $fans{$k}{2} != 1; +} + +# generating the output +print "detected " . ($ok + $nonok) . " fans: " . $nonok . " are bad."; +print "|" . $returnsupp; +print "\n"; + +exit $ERRORS{"OK"} unless $nonok > 0; +exit $ERRORS{"CRITICAL"}; + diff --git a/check_extreme_mem_v3.pl b/check_extreme_mem_v3.pl new file mode 100644 index 0000000..25db82c --- /dev/null +++ b/check_extreme_mem_v3.pl @@ -0,0 +1,186 @@ +#!/usr/bin/perl -w +################################################# +# +# Monitor MEMORY of an extreme networks device +# written by Martin Scharm +# see http://binfalse.de +# modified for SNMPv3 by Benjamin Gauß +# +################################################# + +use strict; +use Net::SNMP; +use Getopt::Long; +use Number::Format qw(format_bytes); + +use lib "/usr/lib64/nagios/plugins/"; +use utils qw($TIMEOUT %ERRORS); + + +my $MEM_TOTAL = '1.3.6.1.4.1.1916.1.32.2.2.1.2.1'; +my $MEM_FREE = '1.3.6.1.4.1.1916.1.32.2.2.1.3.1'; +my $MEM_SYS = '1.3.6.1.4.1.1916.1.32.2.2.1.4.1'; +my $MEM_USER = '1.3.6.1.4.1.1916.1.32.2.2.1.5.1'; + +my $returnvalue = $ERRORS{"OK"}; +my $returnstring = ""; +my $returnsupp = ""; + +my $switch = undef; +my $username = undef; +my $authpassword = undef; +my $authprotocol = undef; +my $privpassword = undef; +my $privprotocol = undef; +my $help = undef; +my $warning = undef; +my $critical = undef; + +Getopt::Long::Configure ("bundling"); +GetOptions( + 'h' => \$help, + 'help' => \$help, + 's:s' => \$switch, + 'switch:s' => \$switch, + 'U:s' => \$username, + 'user:s' => \$username, + 'A:s' => \$authpassword, + 'authpassword:s' => \$authpassword, + 'a:s' => \$authprotocol, + 'authprotocol:s' => \$authprotocol, + 'P:s' => \$privpassword, + 'privpassword:s' => \$privpassword, + 'p:s' => \$privprotocol, + 'privprotocol:s' => \$privprotocol, + 'c:s' => \$critical, + 'critical:s' => \$critical, + 'w:s' => \$warning, + 'warn:s' => \$warning, + 'T:s' => \$TIMEOUT, + 'timeout:s' => \$TIMEOUT +); + +sub nonum +{ + my $num = shift; + if ( $num =~ /^(\d+\.?\d*)|(^\.\d+)$/ ) { return 0 ;} + return 1; +} +sub print_usage +{ + print "Usage: $0 -s -U -A -a -P -p -w -c [-T ]\n\n"; + print " the switch's hostname or ip address\n"; + print " the SNMPv3 username\n"; + print " the password for SNMPv3 authentication\n"; + print " the protocol for SNMPv3 authentication\n"; + print " the privacy password for SNMPv3 data transport\n"; + print " the privacy protocol for SNMPv3data transport\n"; + print " the % of free mem that triggers a warning\n"; + print " the % of free mem that triggers a critical message\n"; + print " max time to wait for an answer, defaults to ".$TIMEOUT."\n" +} + + +# CHECKS +if ( defined($help) ) +{ + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} +if ( !defined($switch) ) +{ + print "Need Switch-Address!\n"; + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} +if ( !defined($username) ) +{ + print "Need SNMPv3 username!\n"; + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} +if ( !defined($authpassword) ) +{ + print "Need SNMPv3 authentication password!\n"; + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} +if ( !defined($authprotocol) ) +{ + print "Need SNMPv3 authentication protocol!\n"; + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} +if ( !defined($privpassword) ) +{ + print "Need SNMPv3 privacy password!\n"; + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} +if ( !defined($privprotocol) ) +{ + print "Need SNMPv3 privacy protocol!\n"; + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} +if (!defined($warning) || !defined($critical)) +{ + print "Need Warning- and Critical-Info!\n"; + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} +$warning =~ s/\%//g; +$critical =~ s/\%//g; +if ( nonum($warning) || nonum($critical)) +{ + print "Only numerical Values for crit/warn allowed !\n"; + print_usage(); + exit $ERRORS{"UNKNOWN"} +} +if ($warning < $critical) +{ + print "warning >= critical ! \n"; + print_usage(); + exit $ERRORS{"UNKNOWN"} +} + + +my ($session, $error) = Net::SNMP->session( -hostname => $switch, -version => 3, -username => $username, -authpassword => $authpassword, -authprotocol => $authprotocol, -privpassword => $privpassword, -privprotocol => $privprotocol, -timeout => $TIMEOUT); + +if (!defined($session)) { + printf("ERROR opening session: %s.\n", $error); + exit $ERRORS{"CRITICAL"}; +} + + +# retrieving values + +my $result = $session->get_request(-varbindlist => [$MEM_TOTAL,$MEM_FREE,$MEM_SYS,$MEM_USER] ); +if (!defined($result)) +{ + printf("ERROR: couldn't retrieve memory values : %s.\n", $session->error); + $session->close; + exit $ERRORS{"CRITICAL"}; +} +my $mem_total = $result->{$MEM_TOTAL}; +my $mem_free = $result->{$MEM_FREE}; +my $mem_sys = $result->{$MEM_SYS}; +my $mem_user = $result->{$MEM_USER}; + + +# generating the output +$returnvalue = $ERRORS{"WARNING"} if ($mem_free / $mem_total < $warning / 100); +$returnvalue = $ERRORS{"CRITICAL"} if ($mem_free / $mem_total < $critical / 100); + +printf "free memory: %.2f%%", 100 * $mem_free / $mem_total; +printf "|total: %s; free: %s (%.2f%%); system: %s (%.2f%%); user: %s (%.2f%%)", + format_bytes ($mem_total), + format_bytes ($mem_free), + 100 * $mem_free / $mem_total, + format_bytes ($mem_sys), + 100 * $mem_sys / $mem_total, + format_bytes ($mem_user), + 100 * $mem_user / $mem_total; +printf "\n"; + +exit $returnvalue; diff --git a/check_extreme_powersupply_v3.pl b/check_extreme_powersupply_v3.pl new file mode 100644 index 0000000..e2f5209 --- /dev/null +++ b/check_extreme_powersupply_v3.pl @@ -0,0 +1,155 @@ +#!/usr/bin/perl -w +################################################# +# +# Monitor POWER SUPPLY of an extreme networks device +# written by Martin Scharm +# see http://binfalse.de +# modified for SNMPv3 by Benjamin Gauß +# +################################################# + +use strict; +use Net::SNMP; +use Getopt::Long; + +use lib "/usr/lib64/nagios/plugins/"; +use utils qw($TIMEOUT %ERRORS); + +my $POWER_OPERATIONAL = '1.3.6.1.4.1.1916.1.1.1.10.0'; +my $POWER_VOLTAGE = '1.3.6.1.4.1.1916.1.1.1.20.0'; +my $POWER_STATUS = '1.3.6.1.4.1.1916.1.1.1.21.0'; +my $POWER_ALARM = '1.3.6.1.4.1.1916.1.1.1.22.0'; +my $POWER_REDUNDANT_STATUS = '1.3.6.1.4.1.1916.1.1.1.11.0'; +my $POWER_REDUNDANT_ALARM = '1.3.6.1.4.1.1916.1.1.1.12.0'; + +my $returnvalue = $ERRORS{"OK"}; +my $returnstring = ""; +my $returnsupp = ""; + +my $switch = undef; +my $username = undef; +my $authpassword = undef; +my $authprotocol = undef; +my $privpassword = undef; +my $privprotocol = undef; +my $help = undef; + +Getopt::Long::Configure ("bundling"); +GetOptions( + 'h' => \$help, + 'help' => \$help, + 's:s' => \$switch, + 'switch:s' => \$switch, + 'U:s' => \$username, + 'user:s' => \$username, + 'A:s' => \$authpassword, + 'authpassword:s' => \$authpassword, + 'a:s' => \$authprotocol, + 'authprotocol:s' => \$authprotocol, + 'P:s' => \$privpassword, + 'privpassword:s' => \$privpassword, + 'p:s' => \$privprotocol, + 'privprotocol:s' => \$privprotocol, + 'T:s' => \$TIMEOUT, + 'timeout:s' => \$TIMEOUT +); + +sub print_usage +{ + print "Usage: $0 -s -U -A -a -P -p [-T ]\n\n"; + print " the switch's hostname or ip address\n"; + print " the SNMPv3 username\n"; + print " the password for SNMPv3 authentication\n"; + print " the protocol for SNMPv3 authentication\n"; + print " the privacy password for SNMPv3 data transport\n"; + print " the privacy protocol for SNMPv3data transport\n"; + print " max time to wait for an answer, defaults to ".$TIMEOUT."\n" +} + + +# CHECKS +if ( defined($help) ) +{ + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} +if ( !defined($switch) ) +{ + print "Need Switch-Address!\n"; + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} +if ( !defined($username) ) +{ + print "Need SNMPv3 username!\n"; + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} +if ( !defined($authpassword) ) +{ + print "Need SNMPv3 authentication password!\n"; + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} +if ( !defined($authprotocol) ) +{ + print "Need SNMPv3 authentication protocol!\n"; + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} +if ( !defined($privpassword) ) +{ + print "Need SNMPv3 privacy password!\n"; + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} +if ( !defined($privprotocol) ) +{ + print "Need SNMPv3 privacy protocol!\n"; + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} + + +my ($session, $error) = Net::SNMP->session( -hostname => $switch, -version => 3, -username => $username, -authpassword => $authpassword, -authprotocol => $authprotocol, -privpassword => $privpassword, -privprotocol => $privprotocol, -timeout => $TIMEOUT); + +if (!defined($session)) { + printf("ERROR opening session: %s.\n", $error); + exit $ERRORS{"CRITICAL"}; +} + + +# retrieving values + +my $result = $session->get_request(-varbindlist => [$POWER_OPERATIONAL, $POWER_REDUNDANT_STATUS, $POWER_REDUNDANT_ALARM, $POWER_VOLTAGE, $POWER_STATUS, $POWER_ALARM] ); +if (!defined($result)) +{ + printf("ERROR: couldn't retrieve power supply values : %s.\n", $session->error); + $session->close; + exit $ERRORS{"CRITICAL"}; +} +my $power_op = $result->{$POWER_OPERATIONAL}; +my $power_redundant_state = $result->{$POWER_REDUNDANT_STATUS}; +my $power_redundant_alarm = $result->{$POWER_REDUNDANT_ALARM}; +my $power_voltage = $result->{$POWER_VOLTAGE}; +my $power_status = $result->{$POWER_STATUS}; +my $power_alarm = $result->{$POWER_ALARM}; + + +# generating the output +$returnvalue = $ERRORS{"WARNING"} if ($power_redundant_state == 3 || $power_redundant_alarm != 2); +$returnvalue = $ERRORS{"CRITICAL"} if ($power_op != 1 || $power_alarm != 2 || $power_status != 2); + +print "power supply is " . ($returnvalue == $ERRORS{"OK"} ? "ok" : "ERR"); + +printf "|power is%s operational%s - status: %s; voltage input is %s; redundant power supply is %s; redundant power is %s", + ($power_op != 1 ? " NOT" : ""), # NOT operational + ($power_alarm != 2 ? " and ALARMING!!" : ""), #power alarming + ($power_status == 1 ? "NOT PRESENT" : ($power_status == 2 ? "present and ok" : "PRESENT AND NOT OK")), #primary power present? + ($power_voltage == 1 ? "v110" : ($power_voltage == 2 ? "v220" : ($power_voltage == 3 ? "v48DC" : "unknown"))), # what voltage? supplemental only + ($power_redundant_state != 2 ? ($power_redundant_state != 1 ? "ERR" : "not existant") : "OK"), #what about the redundant supply + ($power_redundant_alarm != 2 ? "ALARMING" : "OK"); # is redundant alarming? + +printf "\n"; + +exit $returnvalue; diff --git a/check_extreme_temp_v3.pl b/check_extreme_temp_v3.pl new file mode 100644 index 0000000..ad42fc6 --- /dev/null +++ b/check_extreme_temp_v3.pl @@ -0,0 +1,140 @@ +#!/usr/bin/perl -w +################################################# +# +# Monitor TEMPERATURE of an extreme networks device +# written by Martin Scharm +# see http://binfalse.de +# modified for SNMPv3 by Benjamin Gauß +# +################################################# + +use strict; +use Net::SNMP; +use Getopt::Long; +use Scalar::Util qw(looks_like_number); + +use lib "/usr/lib64/nagios/plugins/"; +use utils qw($TIMEOUT %ERRORS); + +my $TEMP_ALRM = '1.3.6.1.4.1.1916.1.1.1.7.0'; +my $TEMP_CURR = '1.3.6.1.4.1.1916.1.1.1.8.0'; + + +my $returnvalue = $ERRORS{"OK"}; +my $returnstring = ""; +my $returnsupp = ""; + +my $switch = undef; +my $username = undef; +my $authpassword = undef; +my $authprotocol = undef; +my $privpassword = undef; +my $privprotocol = undef; +my $help = undef; + +Getopt::Long::Configure ("bundling"); +GetOptions( + 'h' => \$help, + 'help' => \$help, + 's:s' => \$switch, + 'switch:s' => \$switch, + 'U:s' => \$username, + 'user:s' => \$username, + 'A:s' => \$authpassword, + 'authpassword:s' => \$authpassword, + 'a:s' => \$authprotocol, + 'authprotocol:s' => \$authprotocol, + 'P:s' => \$privpassword, + 'privpassword:s' => \$privpassword, + 'p:s' => \$privprotocol, + 'privprotocol:s' => \$privprotocol, + 'T:s' => \$TIMEOUT, + 'timeout:s' => \$TIMEOUT +); + +sub print_usage +{ + print "Usage: $0 -s -U -A -a -P -p [-T ]\n\n"; + print " the switch's hostname or ip address\n"; + print " the SNMPv3 username\n"; + print " the password for SNMPv3 authentication\n"; + print " the protocol for SNMPv3 authentication\n"; + print " the privacy password for SNMPv3 data transport\n"; + print " the privacy protocol for SNMPv3data transport\n"; + print " max time to wait for an answer, defaults to ".$TIMEOUT."\n" +} + + +# CHECKS +if ( defined($help) ) +{ + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} +if ( !defined($switch) ) +{ + print "Need Switch-Address!\n"; + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} +if ( !defined($username) ) +{ + print "Need SNMPv3 username!\n"; + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} +if ( !defined($authpassword) ) +{ + print "Need SNMPv3 authentication password!\n"; + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} +if ( !defined($authprotocol) ) +{ + print "Need SNMPv3 authentication protocol!\n"; + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} +if ( !defined($privpassword) ) +{ + print "Need SNMPv3 privacy password!\n"; + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} +if ( !defined($privprotocol) ) +{ + print "Need SNMPv3 privacy protocol!\n"; + print_usage(); + exit $ERRORS{"UNKNOWN"}; +} + + +my ($session, $error) = Net::SNMP->session( -hostname => $switch, -version => 3, -username => $username, -authpassword => $authpassword, -authprotocol => $authprotocol, -privpassword => $privpassword, -privprotocol => $privprotocol, -timeout => $TIMEOUT); + +if (!defined($session)) { + printf("ERROR opening session: %s.\n", $error); + exit $ERRORS{"CRITICAL"}; +} + + +# retrieving values + +my $result = $session->get_request(-varbindlist => [$TEMP_CURR, $TEMP_ALRM] ); +if (!defined($result)) +{ + printf("ERROR: couldn't retrieve temperature values : %s.\n", $session->error); + $session->close; + exit $ERRORS{"CRITICAL"}; +} +my $temp_alarm = $result->{$TEMP_ALRM}; +my $temp_current = $result->{$TEMP_CURR}; + + + +# generating the output +print "Temperature " . ($temp_alarm != 2 ? "ALARM" : "OK"); +print "|" . (looks_like_number $temp_current ? "current temperature: ${temp_current}°C; " : "") . "alarm status of overtemperature sensor: $temp_alarm (1=alarm,2=ok)"; +print "\n"; + +exit $ERRORS{"OK"} unless $temp_alarm != 2; +exit $ERRORS{"CRITICAL"};