|
@@ -1,163 +1,228 @@
#!/usr/bin/perl -w
+# nagios: -epn
#
-# check_zypper.pl - nagios plugin
+# check_zypper - nagios plugin
#
-# Copyright (C) 2008 Lars Vogdt,
+# Copyright (C) 2008, Novell, Inc.
+# Author: Lars Vogdt
#
-# 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; version 2
-# of the License.
+# All rights reserved.
#
-# 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.
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
#
-# 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.
+# * 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.
#
-# Report bugs to: nagiosplug-help@lists.sourceforge.net
+# * 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.
#
-# 14.04.2008 Version 0.1
-# 15.04.2008 Version 0.2
-# TOOD: "online_update --dry-run --no-sig-check --check" for SLES9
+# 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.
+#
+# $Id$
#
-
use strict;
+use warnings;
use Getopt::Long;
-use vars qw($PROGNAME);
-use lib "/usr/lib/nagios/plugins"; # Pfad to util.pm
-use utils qw ($TIMEOUT %ERRORS &print_revision &support &usage);
-
-sub print_help ();
-sub print_usage ();
-sub check();
+use vars qw($PROGNAME $VERSION $DEBUG);
+# cleanup the environment
$ENV{'PATH'}='/bin:/usr/bin:/sbin:/usr/sbin:';
$ENV{'BASH_ENV'}='';
$ENV{'ENV'}='';
-my ($opt_V, $opt_h, $opt_H, $opt_w, $opt_c, $opt_t);
-my $DEBUG = 0;
-
+# constants
$PROGNAME="check_zypper";
+$VERSION="0.98ß";
+$DEBUG = 0;
+
+# variables
+our $zypper="/usr/bin/zypper";
+our $zypperopt="--non-interactive --no-gpg-checks xml-updates";
+our $sudo="/usr/bin/sudo";
+our $refresh_wrapper="/usr/sbin/zypp-refresh-wrapper";
+our $use_sudo="unset LANG; ";
+our $releasefile="/etc/SuSE-release";
+our $release="11.0";
+our $dist="openSUSE";
+our $patchlevel=0;
+our ($opt_V, $opt_h, $opt_i, $opt_H, $opt_w, $opt_c, $opt_f, $opt_o, $opt_r, $opt_s, $opt_t, $opt_v);
+our $exitcode=0;
+our %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
+our %REVERSE=(4=>'DEPENDENT',3=>'UNKNOWN',2=>'CRITICAL',1=>'WARNING',0=>'OK');
+our $TIMEOUT=120;
+our @patchignore=();
+our @packageignore=();
$opt_H="";
$opt_w="recommended,optional";
$opt_c="security";
+$opt_f="$releasefile";
$opt_t="120";
-
-my $zypper="/usr/bin/zypper";
-my $zypperopt="--non-interactive --no-gpg-checks xml-updates";
-my $release="10.3";
-my $dist="openSUSE";
-my $patchlevel=0;
-
-open(RELEASE,"</etc/SuSE-release");
-while (<RELEASE>){
- if (/^SUSE Linux Enterprise/){
- $dist="SLE";
- }
- if (/^VERSION/){
- ( $release ) = $_ =~ m/VERSION = (.*)/;
- }
- if (/^PATCHLEVEL/){
- ( $patchlevel ) = $_ =~ m/PATCHLEVEL = (.*)/;
+$opt_v=0;
+$opt_o=0;
+$opt_s=0;
+
+#######################################################################
+# Functions
+#######################################################################
+
+sub print_myrevision ($$) {
+ my $commandName = shift;
+ my $pluginRevision = shift;
+ print "$commandName v$pluginRevision\n";
+}
+
+sub mysupport () {
+ print "Please use https://bugzilla.novell.com to submit patches or suggest improvements.\n";
+ print "Please include version information with all correspondence (when possible,\n";
+ print "use output from the --version option of the plugin itself).\n";
+}
+
+sub usage ($) {
+ my $format=shift;
+ printf($format,@_);
+ exit $ERRORS{'UNKNOWN'};
+}
+
+sub get_distribution($){
+ my $file=shift || "$releasefile";
+ open(RELEASE,"<$file") || warn ("Could not open $file\n");
+ while (<RELEASE>){
+ if (/^SUSE Linux Enterprise/){
+ $dist="SLE";
+ }
+ if (/^VERSION/){
+ ( $release ) = $_ =~ m/VERSION = (.*)/;
+ }
+ if (/^PATCHLEVEL/){
+ ( $patchlevel ) = $_ =~ m/PATCHLEVEL = (.*)/;
+ }
}
-}
-close(RELEASE);
-
-if ("$release" eq "10.2"){
- $zypperopt="--non-interactive --no-gpg-checks list-updates";
-}
-
-if ("$dist" eq "SLE"){
- if (("$release" eq "10") && ($patchlevel gt 0)){
- $zypperopt="--non-interactive list-updates";
- } else {
- print "UNKNOWN - SLE $release is currently not supported\n";
- exit $ERRORS{"UNKNOWN"};
- }
-}
-
-Getopt::Long::Configure('bundling');
-GetOptions(
- "V" => \$opt_V, "version" => \$opt_V,
- "h" => \$opt_h, "help" => \$opt_h,
- "H=s" => \$opt_H, "hostname" => \$opt_H,
- "w=s" => \$opt_w, "warning=s" => \$opt_w,
- "c=s" => \$opt_c, "critical=s" => \$opt_c,
- "t=i" => \$opt_t, "timeout=i" => \$opt_t);
-
-if ($opt_t) {
- $TIMEOUT=$opt_t;
-}
-
-# Just in case of problems, let's not hang Nagios
-$SIG{'ALRM'} = sub {
- print "UNKNOWN - Plugin timed out\n";
- exit $ERRORS{"UNKNOWN"};
-};
-alarm($TIMEOUT);
-
-if ($opt_V) {
|