@@ -3,7 +3,8 @@
#
# check_zypper - nagios plugin
#
-# Copyright (C) 2008-2009, Novell, Inc.
+# Copyright (C) 2008-2010, Novell, Inc.
+# Copyright (C) 2011-2012, SUSE Linux Products GmbH
# Author: Lars Vogdt
#
# All rights reserved.
@@ -49,31 +50,48 @@
# constants
$PROGNAME = "check_zypper";
-$VERSION = "1.26";
+$VERSION = '1.41';
$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.2";
-our $dist = "openSUSE";
+our ( $opt_V, $opt_h, $opt_i, $opt_w, $opt_c, $opt_f, $opt_o, $opt_p, $opt_r, $opt_s, $opt_t, $opt_u, $opt_v );
+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 $rpm = '/bin/rpm';
+our $awk = '/bin/awk';
+our $grep = '/bin/grep';
+our $TIMEOUT = 120;
+our @patchignore = ();
+our @packageignore = ();
+our @packagewhitelist= ();
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";
+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 %supported_release = (
+ 'openSUSE' => [ '11.4', '12.1', '12.2' ],
+ 'SLE' => [ '10.4', '11.1', '11.2' ],
+);
+$opt_w = 'recommended,optional,unsupported';
+$opt_c = 'security';
$opt_f = "$releasefile";
-$opt_t = "120";
+$opt_t = '120';
$opt_v = 0;
$opt_o = 0;
$opt_p = 1;
@@ -102,21 +120,31 @@
}
sub get_distribution($) {
- my $file = shift || "$releasefile";
+ my ($file) = @_;
+ my %dist = (
+ 'name' => '',
+ 'version' => '',
+ 'release' => '0',
+ );
open( RELEASE, "<$file" ) || warn("Could not open $file\n");
while (<RELEASE>) {
if (/^SUSE Linux Enterprise/) {
- $dist = "SLE";
+ $dist{'name'} = 'SLE';
}
+ elsif (/^openSUSE/){
+ $dist{'name'} = 'openSUSE';
+ }
if (/^VERSION/) {
- ($release) = $_ =~ m/VERSION = (.*)/;
+ my ($version) = $_ =~ m/VERSION = (.*)/;
+ $dist{'version'}=trim($version);
}
if (/^PATCHLEVEL/) {
- ($patchlevel) = $_ =~ m/PATCHLEVEL = (.*)/;
+ my ($release) = $_ =~ m/PATCHLEVEL = (.*)/;
+ $dist{'release'}=trim($release);
}
}
close(RELEASE);
- return ( $dist, $release, $patchlevel );
+ return ( \%dist );
}
sub print_usage () {
@@ -148,7 +176,9 @@
print " patch:libtiff-devel\n";
print " # comment\n";
print " package:libtiff3\n";
- print " package:libtiff-devel\n\n";
+ print " package:libtiff-devel\n";
+ print " # comment\n";
+ print " whitelist:aaa_base\n\n";
print " -o, --ignore_outdated\n";
print " Don't warn if a repository is outdated.\n";
print " -p, --no_perfdata\n";
@@ -200,7 +230,8 @@
}
}
-sub refresh_zypper() {
+sub refresh_zypper($) {
+ my ($dist) = @_;
if ( -x "$refresh_wrapper" ) {
print STDERR "Trying: $refresh_wrapper 2>/dev/null 1>&2\n" if ($DEBUG);
if ( open( WRAPPER, "$refresh_wrapper 2>&1 |" ) ) {
@@ -209,7 +240,6 @@
foreach my $line (@wrapper_out) {
chomp $line;
print STDERR "LINE: $line\n" if ($DEBUG);
-
# error handling
return ( "ERROR: " . xml_re_escape($line), $ERRORS{'ERROR'} ) if ( $line =~ /Could not refresh repository.*/ );
return ( "ERROR: " . xml_re_escape($line), $ERRORS{'ERROR'} ) if ( $line =~ /Digest verification failed.*/ );
@@ -220,7 +250,8 @@
}
elsif ( -x "$zypper" ) {
print STDERR "Trying: $sudo $zypper ref 2>/dev/null 1>&2\n" if ($DEBUG);
- if ( ( "$release" eq "10.2" ) || ( ( "$dist" eq "SLE" ) && ( "$release" eq "10" ) ) ) {
+ if ( ( ( "$dist->{'name'}" eq "openSUSE" ) && ( "$dist->{'version'}" eq "10.2" ) )
+ || ( ( "$dist->{'name'}" eq "SLE" ) && ( "$dist->{'version'}" eq "10" ) ) ) {
my $res = system("$sudo $zypper ref 2>/dev/null 1>&2");
return ( "ERROR: Unable to refresh the repositories", $ERRORS{'ERROR'} ) if !($res);
}
@@ -243,9 +274,9 @@
sub check_errorcode($) {
my $status = shift;
my $level = 0;
- my $returnvalue = "OK";
- $returnvalue = "WARNING" if ( "$opt_w" =~ /$status/ );
- $returnvalue = "CRITICAL" if ( "$opt_c" =~ /$status/ );
+ my $returnvalue = 'OK';
+ $returnvalue = 'WARNING' if ( "$opt_w" =~ /$status/ );
+ $returnvalue = 'CRITICAL' if ( "$opt_c" =~ /$status/ );
$level = $ERRORS{"$returnvalue"};
$exitcode = $level if ( $level gt $exitcode );
$returnvalue = $REVERSE{"$exitcode"};
@@ -269,44 +300,64 @@
return $text;
}
-sub check() {
+sub check($) {
+ my ($dist) = @_;
my ( $status, $ret_str, $error );
- my $secstr = "";
- my $recstr = "";
- my $optstr = "";
- my $pacstr = "";
- my $warnstr = "";
+ my $secstr = '';
+ my $recstr = '';
+ my $optstr = '';
+ my $pacstr = '';
+ my $warnstr = '';
+ my $unsupstr = '';
my $update_avail = 0;
my %packagelist;
+ my @unsup_packagelist = ();
+
+ if ($opt_u) {
+ @unsup_packagelist = `$rpm -qa --qf "%{NAME} %{VENDOR}\n" | $grep -v 'SUSE LINUX Products GmbH, Nuernberg, Germany' | $grep -v gpg-pubkey | $awk '" " { print \$1 }'`;
+ my $category = 'unsupported';
+ my $status = 'new';
+ foreach my $name ( sort(@unsup_packagelist) ) {
+ chomp($name);
+ if ( grep {/\Q$name\E/} @packagewhitelist ) {
+ print STDERR "WARINING: ignoring $name as it is in \@packagewhitelist\n" if ($DEBUG);
+ next;
|