@@ -49,7 +49,7 @@
# constants
$PROGNAME="check_zypper";
-$VERSION="0.98ß";
+$VERSION="1.1";
$DEBUG = 0;
# variables
@@ -59,10 +59,10 @@
our $refresh_wrapper="/usr/sbin/zypp-refresh-wrapper";
our $use_sudo="unset LANG; ";
our $releasefile="/etc/SuSE-release";
-our $release="11.0";
+our $release="11.1";
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 ($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');
@@ -70,13 +70,13 @@
our @patchignore=();
our @packageignore=();
-$opt_H="";
$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;
#######################################################################
@@ -152,6 +152,8 @@
print " package:libtiff-devel\n\n";
print " -o, --ignore_outdated\n";
print " Don't warn if a repository is outdated.\n";
+ print " -p, --no_perfdata\n";
+ print " Print no perfdata\n";
print " -r, --refresh_repos\n";
print " Tries to refresh the repositories before checking for updates.\n";
print " Note: this maybe needs an entry in /etc/sudoers like:\n";
@@ -175,6 +177,9 @@
print "\n";
print " -V, --version\n";
print " Print version information\n";
+ print "\n";
+ print " -d, --debug\n";
+ print " Print debug output to STDERR\n";
}
sub print_help {
@@ -196,7 +201,7 @@
}
sub refresh_zypper(){
- if ( -x $refresh_wrapper ){
+ 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"));
}
@@ -231,10 +236,6 @@
my $recstr="";
my $optstr="";
my $pacstr="";
- my $seccount=0;
- my $reccount=0;
- my $optcount=0;
- my $paccount=0;
my $update_avail=0;
my %packagelist;
print STDERR "INFO: Trying $use_sudo $zypper $zypperopt\n" if ($DEBUG);
@@ -258,23 +259,14 @@
if (( "$release" eq "10.2" ) || ("$dist" eq "SLE") ){
my ($url,$name,$version,$category,$status)=split('\s*\|\s*',$_,5); # just for reference - perhaps we need the variables later
if (defined($name)){
- if (grep {/$name/} @patchignore){
+ if (grep {/\Q$name\E/} @patchignore){
print STDERR "WARNING: ignoring $name as it is in \@patchignore\n" if ($DEBUG);
next;
}
}
- if (/\|\s*optional\s*\|\s*Needed/) {
- $category="optional";
- $optcount++;
- }
- if (/\|\s*recommended\s*\|\s*Needed/){
- $category="recommended";
- $reccount++;
- }
- if (/\|\s*security\s*\|\s*Needed/){
- $category="security";
- $seccount++;
- }
+ $category="optional" if (/\|\s*optional\s*\|\s*Needed/);
+ $category="recommended" if (/\|\s*recommended\s*\|\s*Needed/);
+ $category="security" if (/\|\s*security\s*\|\s*Needed/);
$packagelist{"$category"}{"$name"}{'category'}="$category" if defined($category);
$packagelist{"$category"}{"$name"}{'status'}="$status" if defined($status);
$packagelist{"$category"}{"$name"}{'name'}="$name" if defined($name);
@@ -282,28 +274,18 @@
if (/<update /){
my ($name)=$_=~/name="(.*?)"/;
if (/kind="patch"/){ # line contains patch
- if (grep {/$name/} @patchignore){
+ if (grep {/\Q$name\E/} @patchignore){
print STDERR "WARNING: ignoring $name as it is in \@patchignore\n" if ($DEBUG);
next;
}
- if (/category="security"/){
- $seccount++;
- $category="security";
- }
- if (/category="recommended"/){
- $reccount++;
- $category="recommended";
- }
- if (/category="optional"/){
- $optcount++;
- $category="optional";
- }
+ $category="optional" if (/category="optional"/);
+ $category="recommended" if (/category="recommended"/);
+ $category="security" if (/category="security"/);
} elsif (/kind="package"/) {
- if (grep {/$name/} @packageignore){
+ if (grep {/\Q$name\E/} @packageignore){
print STDERR "WARNING: ignoring $name as it is in \@packageignore\n" if ($DEBUG);
next;
}
- $paccount++;
$category="package";
}
$packagelist{"$category"}{"$name"}{'category'}="$category";
@@ -313,32 +295,32 @@
}
}
if ($DEBUG){
- print STDERR "INFO: Packages (paccount): $paccount\n";
- print STDERR "INFO: Optional (optcount): $optcount\n";
- print STDERR "INFO: Recommended (reccount): $reccount\n";
- print STDERR "INFO: Security (seccount): $seccount\n";
+ print STDERR "INFO: Packages (paccount): ".scalar(keys %{($packagelist{'package'})})."\n";
+ print STDERR "INFO: Optional (optcount): ".scalar(keys %{($packagelist{'optional'})})."\n";
+ print STDERR "INFO: Recommended (reccount): ".scalar(keys %{($packagelist{'recommended'})})."\n";
+ print STDERR "INFO: Security (seccount): ".scalar(keys %{($packagelist{'security'})})."\n";
use Data::Dumper;
print STDERR Data::Dumper->Dump([\%packagelist]);
}
- if ("$paccount" ne "0"){
+ if (defined($packagelist{'package'})){
$update_avail=1;
$error=check_errorcode("packages");
- $pacstr="$paccount package update(s);";
+ $pacstr=scalar(keys %{($packagelist{'package'})})." package update(s);";
}
- if ("$optcount" ne "0"){
+ if (defined($packagelist{'optional'})){
$update_avail=1;
$error=check_errorcode("optional");
- $optstr="$optcount optinal update(s);";
+ $optstr=scalar(keys %{($packagelist{'optional'})})." optinal update(s);";
}
- if ("$reccount" ne "0"){
+ if (defined($packagelist{'recommended'})){
$update_avail=1;
$error=check_errorcode("recommended");
- $recstr="$reccount recommended update(s);";
+ $recstr=scalar(keys %{($packagelist{'recommended'})})." recommended update(s);";
}
- if ("$seccount" ne "0"){
+ if (defined($packagelist{'security'})){
$update_avail=1;
$error=check_errorcode("security");
- $secstr="$seccount security update(s);";
+ $secstr=scalar(keys %{($packagelist{'security'})})." security update(s);";
}
if ( $update_avail ){
$ret_str.="$error : $secstr $recstr $optstr $pacstr ";
@@ -369,7 +351,7 @@
$ret_str.="\nIgnored Packages: ".join(' ',@packageignore)." " if @packageignore;
}
}
- $ret_str.="| security=".$seccount.";recommended=".$reccount.";optional=".$optcount.";packages=".$paccount.";\n";
+ $ret_str.="| security=".scalar(keys %{($packagelist{'security'})}).";;;; recommended=".scalar(keys %{($packagelist{'recommended'})}).";;;; optional=".scalar(keys %{($packagelist{'optional'})}).";;;; packages=".scalar(keys %{($packagelist{'package'})}).";;;;\n" if ($opt_p);
}
close(FH);
return("$ret_str","$error");
@@ -383,12 +365,13 @@
GetOptions(
"V" => \$opt_V, "version" => \$opt_V,
"h" => \$opt_h, "help" => \$opt_h,
+ "d" => \$DEBUG, "debug" => \$DEBUG,
"i=s" => \$opt_i, "ignore=s" => \$opt_i,
- "H=s" => \$opt_H, "hostname" => \$opt_H,
"w=s" => \$opt_w, "warning=s" => \$opt_w,
|