commit d6ee13fb7e16bc27668924834138fa149efc8ba8e72fdbb79fed9f17c9fa5a26 Author: Lars Vogdt Date: Wed Jul 30 21:26:50 2014 +0000 - Renamed package to monitoring-plugins-qlogic_sanbox - update to 1.3 (thanks to Christian Fertig): + added configurable warning and critical options for sensor 4 (the CPU sensor) + added explanation for --filename option in help text - license update following SPDX format - increase the temperature warnings for sensor 4 to 70/75 - looks more useful (and shown in manual, too) - temp sensor 4 (only with firmware 8.x) seems to be cpu-temperature, use special warn and crit levels - specify timeout also for snmp-session - add maxmsgsize, more useful error output - initial version OBS-URL: https://build.opensuse.org/package/show/server:monitoring/monitoring-plugins-qlogic_sanbox?expand=0&rev=2 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9b03811 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,23 @@ +## Default LFS +*.7z filter=lfs diff=lfs merge=lfs -text +*.bsp filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.gem filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.jar filter=lfs diff=lfs merge=lfs -text +*.lz filter=lfs diff=lfs merge=lfs -text +*.lzma filter=lfs diff=lfs merge=lfs -text +*.obscpio filter=lfs diff=lfs merge=lfs -text +*.oxt filter=lfs diff=lfs merge=lfs -text +*.pdf filter=lfs diff=lfs merge=lfs -text +*.png filter=lfs diff=lfs merge=lfs -text +*.rpm filter=lfs diff=lfs merge=lfs -text +*.tbz filter=lfs diff=lfs merge=lfs -text +*.tbz2 filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.ttf filter=lfs diff=lfs merge=lfs -text +*.txz filter=lfs diff=lfs merge=lfs -text +*.whl filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57affb6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.osc diff --git a/check_qlogic_sanbox b/check_qlogic_sanbox new file mode 100644 index 0000000..fd197bd --- /dev/null +++ b/check_qlogic_sanbox @@ -0,0 +1,503 @@ +#!/usr/bin/perl -w +# nagios: -epn +# +# Copyright (c) 2012, SUSE Linux Products GmbH +# Author: Lars Vogdt +# +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the Novell nor the names of its contributors may be +# used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +use strict; +use Net::SNMP; +use Getopt::Long; +use Net::Ping; +use Pod::Usage; +use bignum qw/hex/; +Getopt::Long::Configure('bundling'); + +# cleanup the environment +$ENV{'PATH'} = '/bin:/usr/bin:/sbin:/usr/sbin:'; +$ENV{'BASH_ENV'} = ''; +$ENV{'ENV'} = ''; + +our $conf = { + 'VERSION' => '1.3', + 'PROGNAME' => 'check_qlogic_sanbox', + 'timeout' => '60', + 'critical' => '45', + 'warning' => '35', + 'sensor_4_warn' => '70', + 'sensor_4_crit' => '75', + 'debug' => 0, + 'hostname' => 'localhost', + 'community' => 'public', + 'snmp_version' => '2c', + 'snmp_port' => '161', + 'maxmsgsize' => '65535', +}; + +our $print_version = 0; +our $print_help = 0; +our $exitcode = 0; +our $output = ''; + +# The Name_Identifier of the Fabric Element +our $fcFeElementName = '.1.3.6.1.2.1.75.1.1.2.0'; +# The basic information about the Fabric Element +our $base_table_query = '.1.3.6.1.2.1.1'; + +our %ERRORS = ( + 'OK' => 0, + 'WARNING' => 1, + 'CRITICAL' => 2, + 'UNKNOWN' => 3, + 'DEPENDENT' => 4 +); + +our %BASE_OIDs = ( + 'sysDescr' => '.1.3.6.1.2.1.1.1.0', + 'sysUpTime' => '.1.3.6.1.2.1.1.3.0', + 'sysName' => '.1.3.6.1.2.1.1.5.0', + 'sysContact' => '.1.3.6.1.2.1.1.4.0', + 'sysLocation' => '.1.3.6.1.2.1.1.6.0', +); + +####################################################################### +# Functions +####################################################################### + +sub snmp_get_table($$$){ + my ($conf,$session,$query) = @_; + my ($answer,$response); + if ( ! defined ( $response = $session->get_table($query))){ + $answer=$session->error; + $session->close; + print "CRITICAL: no response with SNMP version $conf->{'snmp_version'} for get_table on $query (error $answer)\n"; + exit $ERRORS{'CRITICAL'}; + } + return $response; +} + +sub snmp_get_request($$$){ + my ($conf,$session,$query) = @_; + my ($answer,$response); + if ( ! defined ( $response = $session->get_request($query))){ + $answer=$session->error; + $session->close; + print "CRITICAL: no response with SNMP version $conf->{'snmp_version'} for get_request on $query (error $answer)\n"; + exit $ERRORS{'CRITICAL'}; + } + return($response->{$query}); +} + +sub DEBUG($) { + my ($output) = @_; + print "DEBUG: $output\n" if ( $conf->{'debug'} ); +} + +sub print_myrevision ($$) { + my ($commandName,$pluginRevision) = @_; + print "$commandName v$pluginRevision\n"; +} + +####################################################################### +# Main +####################################################################### + +Getopt::Long::Configure('bundling'); +GetOptions( + "H=s" => \$conf->{'hostname'}, + "hostname=s" => \$conf->{'hostname'}, + "f=s" => \$conf->{'filename'}, + "filename=s" => \$conf->{'filename'}, + "v" => \$print_version, + "version" => \$print_version, + "h" => \$print_help, + "help" => \$print_help, + "d" => \$conf->{'debug'}, + "debug" => \$conf->{'debug'}, + "w=f" => \$conf->{'warning'}, + "warning=f" => \$conf->{'warning'}, + "c=f" => \$conf->{'critical'}, + "critical=f" => \$conf->{'critical'}, + "sensor4_warn=f"=> \$conf->{'sensor_4_warn'}, + "sensor4_crit=f"=> \$conf->{'sensor_4_crit'}, + "t=i" => \$conf->{'timeout'}, + "timeout=i" => \$conf->{'timeout'}, + "C=s" => \$conf->{'community'}, + "community=s" => \$conf->{'community'}, + "p=i" => \$conf->{'snmp_port'}, + "port=i" => \$conf->{'snmp_port'}, + "V=s" => \$conf->{'snmp_version'}, + "snmp-version=s"=> \$conf->{'snmp_version'}, +) or pod2usage(2); + +pod2usage( + -exitstatus => 0, + -verbose => 2, # 2 to print full pod +) if $print_help; + +# Just in case of problems, let's not hang Nagios +$SIG{'ALRM'} = sub { + print "UNKNOWN: No snmp response from ".$conf->{'hostname'}." (alarm timeout)\n"; + exit $ERRORS{'UNKNOWN'}; +}; +alarm( $conf->{'timeout'} ); + +if ($print_version) { + print_myrevision( $conf->{'PROGNAME'}, $conf->{'VERSION'} ); + exit $ERRORS{'OK'}; +} + +# +# Check the given options... +# +if (defined($conf->{'filename'})){ + use Config::IniFiles; + my $ini = new Config::IniFiles( -file => "$conf->{'filename'}"); + if( ! $ini ){ + print "ERROR: Could not open $conf->{'filename'} : $!\n"; + exit $ERRORS{'UNKNOWN'}; + } + if (! $ini->SectionExists($conf->{'hostname'})){ + print "ERROR: Could not find section [$conf->{'hostname'}] in $conf->{'filename'}\n"; + exit $ERRORS{'UNKNOWN'}; + } + $conf->{'community'} = $ini->val($conf->{'hostname'}, 'community') if (defined($ini->val($conf->{'hostname'},'community'))); + $conf->{'snmp_version'} = $ini->val($conf->{'hostname'}, 'snmp_version') if (defined($ini->val($conf->{'hostname'},'snmp_version'))); + $conf->{'snmp_port'} = $ini->val($conf->{'hostname'}, 'snmp_port') if (defined($ini->val($conf->{'hostname'},'snmp_port'))); + $conf->{'warning'} = $ini->val($conf->{'hostname'}, 'warning') if (defined($ini->val($conf->{'hostname'},'warning'))); + $conf->{'critical'} = $ini->val($conf->{'hostname'}, 'critical') if (defined($ini->val($conf->{'hostname'},'critical'))); + $conf->{'sensor_4_warn'}= $ini->val($conf->{'hostname'}, 'sensor4_warn') if (defined($ini->val($conf->{'hostname'},'sensor4_warn'))); + $conf->{'sensor_4_crit'}= $ini->val($conf->{'hostname'}, 'sensor4_crit') if (defined($ini->val($conf->{'hostname'},'sensor4_crit'))); +} + +if ( !defined($conf->{'hostname'}) ) { + print "ERROR - no hostname given\n"; + pod2usage(2); + alarm(0); + exit $ERRORS{'UNKNOWN'}; +} +if ($conf->{'warning'} gt $conf->{'critical'}){ + print "ERROR: warning level ($conf->{'warning'}) should not be greater than critical level ($conf->{'critical'})\n"; + pod2usage(2); + alarm(0); + exit $ERRORS{'UNKNOWN'}; +} +if ($conf->{'sensor_4_warn'} gt $conf->{'sensor_4_crit'}){ + print "ERROR: sensor 4 warning level ($conf->{'sensor_4_warn'}) should not be greater than sensor 4 critical level ($conf->{'sensor_4_crit'})\n"; + pod2usage(2); + alarm(0); + exit $ERRORS{'UNKNOWN'}; +} + +if ($conf->{'debug'}){ + use Data::Dumper; + print STDERR "Internal configuration:\n".Data::Dumper->Dump([$conf]); +} + +# +# Basic defines / checks +# +my $ret_str='UNKNOWN'; +my $error='UNKNOWN'; +my $session; + +# First try to ping the Sanbox, this gives faster results +my $p = Net::Ping->new(); +if (! $p->ping($conf->{'hostname'}) ){ + print "CRITICAL: could not ping your Sanbox ($conf->{'hostname'})\n"; + exit $ERRORS{'CRITICAL'}; +} +$p->close(); + +# +# Prepare SNMP Session +# +($session, $error) = Net::SNMP->session( + -hostname => $conf->{'hostname'}, + -community => $conf->{'community'}, + -port => $conf->{'snmp_port'}, + -version => $conf->{'snmp_version'}, + -maxmsgsize => $conf->{'maxmsgsize'}, + -timeout => $conf->{'timeout'}, +); +if (!defined($session)){ + print "ERROR: $error"; + exit $ERRORS{'UNKNOWN'}; +} + +# +# Query SNMP informations from the single switch +# +# first get the WWPN of the SANBox and convert it into octal number +my $WWPN=snmp_get_request($conf,$session,$fcFeElementName); +my @array = unpack ("C*", pack ("H*", $WWPN)); +my $sanbox_id=join(".",splice(@array,-4,4)); +my $snmp_status_query=".1.3.6.1.3.94.1.8.1.6.16.0.0.192.$sanbox_id.0.0.0.0.0.0.0.0"; +# The installed Firmware of the Fabric Element +our $firmware_oid = ".1.3.6.1.3.94.1.7.1.3.16.0.0.192.$sanbox_id.0.0.0.0.0.0.0.0.1"; + +# Now get some basic parameters +my $baseinfo=snmp_get_table($conf,$session,$base_table_query); + +# and also the currently running Firmware +my $firmware=snmp_get_request($conf,$session,$firmware_oid); + +# Get the status output from the switch +my $status=snmp_get_table($conf,$session,$snmp_status_query); + +# Get the names for the status output +my $snmp_status_names='.1.3.6.1.3.94.1.8.1.3.16.0.0.192.'.$sanbox_id.'.0.0.0.0.0.0.0.0'; +my $status_names_ref=snmp_get_table($conf,$session,$snmp_status_names); +my %status_names=%$status_names_ref; + +# +# Close the session and reset the alarm +# +$session->close; +alarm(0); + +if ($conf->{'debug'}){ + print STDERR "\nSanbox ID: $sanbox_id ($WWPN)\n"; + print STDERR "Firmware : $firmware\n"; + print STDERR "Basic information:\n"; + print STDERR Data::Dumper->Dump([$baseinfo]); + print STDERR "\nQuerying : $snmp_status_query"; + print STDERR "\nStatus Names Table:\n"; + print STDERR Data::Dumper->Dump([$status_names_ref]); + print STDERR "\nStatus Table:\n"; + print STDERR Data::Dumper->Dump([$status]); +} + +# +# Analyze the tables... +# +my $perfdata=''; +foreach my $value (sort(keys(%status_names))){ + my ($is_temp, $is_temp_status, $is_status)=0; + my ($sensor_number,$sensor_name); + $output.="$status_names{$value}: "; + if ( $status_names{$value} =~ /.*Temperature Sensor (.*) Value/ ){ + $perfdata.="'Temp ".$1."'="; + $sensor_number=$1; + $is_temp=1; + } + elsif ( $status_names{$value} =~ /Temperature Status/ ){ + $is_temp_status=1; + $sensor_name=$status_names{$value}; + } + elsif ( $status_names{$value} =~ /Power supply (.*) Status/ ){ + $is_status=1; + $sensor_number=$1; + $sensor_name=$status_names{$value}; + } + elsif ( $status_names{$value} =~ /Fan (.*) Status/ ){ + $is_status=1; + $sensor_number=$1; + $sensor_name=$status_names{$value}; + } + # convert the OID for the name to match the OID for the value: + $value =~ s/.1.3.6.1.3.94.1.8.1.3.16.0.0.192/.1.3.6.1.3.94.1.8.1.6.16.0.0.192/; + $output.="$status->{$value}; "; + # now check the results depending on the sensors: + if ($is_temp){ + my $temp="$status->{$value}"; + $temp=~ s/\D//g; + my $conf_warn = $conf->{'warning'}; + my $conf_crit = $conf->{'critical'}; + if ($sensor_number == 4) { + $conf_warn = $conf->{'sensor_4_warn'}; + $conf_crit = $conf->{'sensor_4_crit'}; + } + $perfdata.="$temp;$conf_warn;$conf_crit;; "; + if ($temp gt $conf_crit){ + $exitcode=$ERRORS{'CRITICAL'}; + $output="CRITICAL: temperatur $status->{$value} on sensor $sensor_number exceeds critical level ($conf_crit); ".$output; + } + elsif ($temp gt $conf_warn){ + $exitcode=$ERRORS{'WARNING'}; + $output="WARNING: temperatur $status->{$value} on sensor $sensor_number exceeds warning level ($conf_warn); ".$output; + } + } + if ($is_temp_status){ + if ($status->{$value} !~ /Normal/){ + $exitcode=$ERRORS{'CRITICAL'}; + $output="CRITICAL: $sensor_name is $status->{$value}; ".$output; + } + } + if ($is_status){ + if ($status->{$value} !~ /Good/){ + $exitcode=$ERRORS{'CRITICAL'}; + $output="CRITICAL: $sensor_name is $status->{$value}; ".$output; + } + } +} + +foreach my $value (sort(keys(%BASE_OIDs))){ + $output.="$value: $baseinfo->{$BASE_OIDs{$value}}; "; +} +$output.="Firmware: $firmware; "; + +# +# Finished : output what we have so far... +# +print "$output | $perfdata\n"; +exit $exitcode; + +__END__ + +=head1 check_qlogic_sanbox + +check_qlogic_sanbox is a Nagios plugin, allowing to check QLogic FC Sanboxes. + +This plugin has been tested with the following QLogic switches: + +=over 4 + +=item SANbox 5200 FC Switch + +=item SANbox 5202 FC Switch + +=item SANbox 5600 FC Switch + +=item SANbox 5602 FC Switch + +=item SANbox 5800 FC Switch + +=back + +=head1 SYNOPSIS + +./check_qlogic_sanbox -H $HOSTNAME$ --community public + + Options: + -H | --hostname + -w | --warning + -c | --critical + + -t | --timeout + -C | --community + -V | --snmp-version + -p | --port + + -f | --filename + + --sensor4_warn + --sensor4_crit + + -h | --help + -d | --debug + +=head1 OPTIONS + +=over 8 + +=item B<--hostname> F + +The name of the Sanbox. Default: localhost (which makes no sense). + +=item B<--critical> F + +Critical temperature level. Default is 45 degrees Celsius. + +=item B<--warning> F + +Warning temperature level. Default is 35 degrees Celsius. + +=item B<--timeout> F + +Timeout until the plugin times out with result UNKNOWN. + +=item B<--community> F + +SNMP community string to use. Default: public. + +=item B<--port> F + +SNMP port to use. Default: 161. + +=item B<--snmp-version> F + +SNMP version to use. Default: 2c. + +=item B<--filename F + +You can put the configuration in a file with ini-file syntax (using the hostname as section separator) using the long format of the available options. + +Example: + + [192.168.0.1] + warning=37 + critical=39 + community=public + sensor4_warn=50 + sensor4_crit=55 + + [192.168.0.2] + warning=40 + critical=45 + community=secure + sensor4_warn=60 + sensor4_crit=65 + +The script should be called with the hostname/IP and the filename option like: + B<$USER1$/check_qlogic_sanbox -H 192.168.0.1 --filename /etc/nagios-plugins/sanboxes.ini> + +=item B<--sensor4_warn F + +Warning temperature level for the CPU sensor (Sensor 4). Default is 70 degrees Celsius. + +=item B<--sensor4_crit F + +Critical temperature level for the CPU sensor (Sensor 4). Default is 75 degrees Celsius. + +=item B<--help> + +Produces this output. + +=item B<--debug> + +Print debug output on STDERR. + +=back + +=head1 DESCRIPTION + +=head1 AUTHORS + +Written by Lars Vogdt + +=head1 SUPPORT + +Please use https://bugzilla.novell.com to submit patches or suggest improvements. + +Include version information with all correspondence (when possible use output from +the --version option of the plugin itself). + diff --git a/monitoring-plugins-qlogic_sanbox.changes b/monitoring-plugins-qlogic_sanbox.changes new file mode 100644 index 0000000..4861517 --- /dev/null +++ b/monitoring-plugins-qlogic_sanbox.changes @@ -0,0 +1,45 @@ +------------------------------------------------------------------- +Wed Jul 30 19:20:22 UTC 2014 - lars@linux-schulserver.de + +- Renamed package to monitoring-plugins-qlogic_sanbox + +------------------------------------------------------------------- +Fri Mar 8 10:08:53 UTC 2013 - lars@linux-schulserver.de + +- update to 1.3 (thanks to Christian Fertig): + + added configurable warning and critical options for sensor 4 + (the CPU sensor) + + added explanation for --filename option in help text + +------------------------------------------------------------------- +Wed Jan 23 10:28:10 UTC 2013 - lars@linux-schulserver.de + +- license update following SPDX format + +------------------------------------------------------------------- +Tue Jun 12 12:08:35 UTC 2012 - lars@linux-schulserver.de + +- increase the temperature warnings for sensor 4 to 70/75 - looks + more useful (and shown in manual, too) + +------------------------------------------------------------------- +Wed Jun 6 20:47:18 CEST 2012 - ro@suse.de + +- temp sensor 4 (only with firmware 8.x) seems to be + cpu-temperature, use special warn and crit levels + +------------------------------------------------------------------- +Tue Jun 5 01:52:56 CEST 2012 - ro@suse.de + +- specify timeout also for snmp-session + +------------------------------------------------------------------- +Tue Jun 5 01:33:11 CEST 2012 - ro@suse.de + +- add maxmsgsize, more useful error output + +------------------------------------------------------------------- +Sat May 5 17:11:23 UTC 2012 - lars@linux-schulserver.de + +- initial version + diff --git a/monitoring-plugins-qlogic_sanbox.spec b/monitoring-plugins-qlogic_sanbox.spec new file mode 100644 index 0000000..27a33e1 --- /dev/null +++ b/monitoring-plugins-qlogic_sanbox.spec @@ -0,0 +1,69 @@ +# +# spec file for package monitoring-plugins-qlogic_sanbox +# +# Copyright (c) 2013-2014 SUSE LINUX Products GmbH, Nuernberg, Germany. +# Author: Lars Vogdt +# +# All modifications and additions to the file contributed by third parties +# remain the property of their copyright owners, unless otherwise agreed +# upon. The license for this file, and modifications and additions to the +# file, is the same license as for the pristine package itself (unless the +# license for the pristine package is not an Open Source License, in which +# case the license is the MIT License). An "Open Source License" is a +# license that conforms to the Open Source Definition (Version 1.9) +# published by the Open Source Initiative. + +# Please submit bugfixes or comments via http://bugs.opensuse.org/ +# + + +Name: monitoring-plugins-qlogic_sanbox +Summary: Check QLogic FC Sanboxes +License: BSD-3-Clause +Group: System/Monitoring +Version: 1.3 +Release: 100 +Url: http://en.opensuse.org/Monitoring-plugins-qlogic_sanbox +Source0: check_qlogic_sanbox +Requires: perl(Getopt::Long) +Requires: perl(Net::Ping) +Requires: perl(Net::SNMP) +Requires: perl(Pod::Usage) +Recommends: perl(Config::IniFiles) +Recommends: perl(Data::Dumper) +BuildArch: noarch +BuildRequires: nagios-rpm-macros +Provides: nagios-plugins-qlogic_sanbox = %{version}-%{release} +Obsoletes: nagios-plugins-qlogic_sanbox < %{version}-%{release} +BuildRoot: %{_tmppath}/%{name}-%{version}-build + +%description +Nagios plugin, allowing to check QLogic FC Sanboxes. + +This plugin has been tested with the following QLogic switches: + +SANbox 5200 FC Switch +SANbox 5202 FC Switch +SANbox 5600 FC Switch +SANbox 5602 FC Switch +SANbox 5800 FC Switch + + +%prep + +%build + +%install +install -D -m755 %{SOURCE0} %buildroot/%{nagios_plugindir}/check_qlogic_sanbox + +%clean +rm -rf %buildroot + +%files +%defattr(-,root,root) +# avoid build dependecy of nagios - own the dirs +%dir %{nagios_libdir} +%dir %{nagios_plugindir} +%{nagios_plugindir}/check_qlogic_sanbox + +%changelog