|
@@ -3,7 +3,7 @@
#
# check_zypper - nagios plugin
#
-# Copyright (C) 2008, Novell, Inc.
+# Copyright (C) 2008-2009, Novell, Inc.
# Author: Lars Vogdt
#
# All rights reserved.
@@ -43,48 +43,48 @@
use vars qw($PROGNAME $VERSION $DEBUG);
# cleanup the environment
-$ENV{'PATH'}='/bin:/usr/bin:/sbin:/usr/sbin:';
-$ENV{'BASH_ENV'}='';
-$ENV{'ENV'}='';
+$ENV{'PATH'} = '/bin:/usr/bin:/sbin:/usr/sbin:';
+$ENV{'BASH_ENV'} = '';
+$ENV{'ENV'} = '';
# constants
-$PROGNAME="check_zypper";
-$VERSION="1.1";
-$DEBUG = 0;
+$PROGNAME = "check_zypper";
+$VERSION = "1.26";
+$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.1";
-our $dist="openSUSE";
-our $patchlevel=0;
-our ($opt_V, $opt_h, $opt_i, $opt_w, $opt_c, $opt_f, $opt_o, $opt_p, $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_w="recommended,optional";
-$opt_c="security";
-$opt_f="$releasefile";
-$opt_t="120";
-$opt_v=0;
-$opt_o=0;
-$opt_p=1;
-$opt_s=0;
+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.2";
+our $dist = "openSUSE";
+our $patchlevel = 0;
+our ( $opt_V, $opt_h, $opt_i, $opt_w, $opt_c, $opt_f, $opt_o, $opt_p, $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_w = "recommended,optional";
+$opt_c = "security";
+$opt_f = "$releasefile";
+$opt_t = "120";
+$opt_v = 0;
+$opt_o = 0;
+$opt_p = 1;
+$opt_s = 0;
#######################################################################
# Functions
#######################################################################
sub print_myrevision ($$) {
- my $commandName = shift;
+ my $commandName = shift;
my $pluginRevision = shift;
print "$commandName v$pluginRevision\n";
}
@@ -96,28 +96,27 @@
}
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);
- print STDERR "INFO: $dist,$release,$patchlevel\n" if ($DEBUG);
- return($dist,$release,$patchlevel);
+ 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);
+ return ( $dist, $release, $patchlevel );
}
sub print_usage () {
@@ -172,189 +171,254 @@
print " -v, --verbose_output\n";
print " Print more information (useful only with Nagios v3.x).\n";
print " -w, --warning\n";
- print " A patch with this category result in warning status.\n";
+ print " A patch with this category result in warning status.\n";
print " Default: $opt_w\n";
print "\n";
print " -V, --version\n";
print " Print version information\n";
- print "\n";
- print " -d, --debug\n";
- print " Print debug output to STDERR\n";
+ print "\n";
+ print " -d, --debug\n";
+ print " Print debug output to STDERR\n";
}
sub print_help {
- my $exit=shift || undef;
+ my $exit = shift || undef;
print "Copyright (c) 2009, Novell, Inc.\n\n";
print_usage();
print "\n";
mysupport();
- exit $exit if (defined($exit));
+ exit $exit if ( defined($exit) );
}
-sub check_zypper(){
- if ( -x "$zypper" ){
- print STDERR "INFO: Trying $use_sudo $zypper sl 2>/dev/null 1>&2\n" if ( $DEBUG );
- return (system("$use_sudo $zypper sl 2>/dev/null 1>&2"));
- } else {
+sub check_zypper() {
+ if ( -x "$zypper" ) {
+ print STDERR "INFO: Trying $use_sudo $zypper sl 2>/dev/null 1>&2\n" if ($DEBUG);
+ return ( system("$use_sudo $zypper sl 2>/dev/null 1>&2") );
+ }
+ else {
return 1;
}
}
-sub refresh_zypper(){
- if ( -x "$refresh_wrapper" ){
- print STDERR "Trying: $refresh_wrapper 2>/dev/null 1>&2\n" if ( $DEBUG );
- return (system("$refresh_wrapper 2>/dev/null 1>&2"));
- }
- if ( -x "$zypper" ){
- print STDERR "Trying: $sudo $zypper ref 2>/dev/null 1>&2\n" if ( $DEBUG );
- my $res=system("$sudo $zypper ref 2>/dev/null 1>&2");
- if (( "$release" eq "10.2" ) || ("$dist" eq "SLE")){
- return 0 if ( $res );
- } else {
- return $res
- }
- } else {
- return 1;
+sub refresh_zypper() {
|