Hello community, here is the log from the commit of package nagios-plugins-zypper checked in at Sat Sep 13 05:55:28 CEST 2008. -------- --- nagios-plugins-zypper/nagios-plugins-zypper.changes 2008-09-03 17:44:38.000000000 +0200 +++ nagios-plugins-zypper/nagios-plugins-zypper.changes 2008-09-10 11:52:04.000000000 +0200 @@ -1,0 +2,9 @@ +Wed Sep 10 11:50:53 CEST 2008 - lrupp@suse.de + +- update to 0.5: + + code cleanup + + return UNKNOWN state if system doesn't support check without + sudo rights + + allow user to specify the release file with '-r' + +------------------------------------------------------------------- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ nagios-plugins-zypper.spec ++++++ --- /var/tmp/diff_new_pack.D28135/_old 2008-09-13 05:55:07.000000000 +0200 +++ /var/tmp/diff_new_pack.D28135/_new 2008-09-13 05:55:07.000000000 +0200 @@ -1,5 +1,5 @@ # -# spec file for package nagios-plugins-zypper (Version 0.4) +# spec file for package nagios-plugins-zypper (Version 0.5) # # Copyright (c) 2008 SUSE LINUX Products GmbH, Nuernberg, Germany. # @@ -20,8 +20,8 @@ Name: nagios-plugins-zypper Summary: Nagios plugin for checking software updates -Version: 0.4 -Release: 2 +Version: 0.5 +Release: 1 Url: http://en.opensuse.org/nagios-plugins-zypper License: GPL v2 only Group: System/Monitoring @@ -74,6 +74,12 @@ %libexecdir/check_zypper %changelog +* Wed Sep 10 2008 lrupp@suse.de +- update to 0.5: + + code cleanup + + return UNKNOWN state if system doesn't support check without + sudo rights + + allow user to specify the release file with '-r' * Wed Sep 03 2008 lrupp@suse.de - update to 0.4: + added sudo option to call zypper via sudo ++++++ check_zypper.pl ++++++ --- nagios-plugins-zypper/check_zypper.pl 2008-09-03 18:28:12.000000000 +0200 +++ nagios-plugins-zypper/check_zypper.pl 2008-09-10 11:49:38.000000000 +0200 @@ -24,6 +24,8 @@ # 14.04.2008 Version 0.1 # 15.04.2008 Version 0.2 # 02.09.2008 Version 0.3 +# 04.09.2008 Version 0.4 +# 10.09.2008 Version 0.5 # # TOOD: "online_update --dry-run --no-sig-check --check" for SLES9 # @@ -36,94 +38,56 @@ sub print_help (); sub print_usage (); -sub check(); $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_s, $opt_t, $opt_v); -my $DEBUG = 0; - $PROGNAME="check_zypper"; - -$opt_H=""; -$opt_w="recommended,optional"; -$opt_c="security"; -$opt_t="120"; -$opt_v=0; -$opt_s=0; +my $VERSION=0.5; +my $DEBUG = 0; my $zypper="/usr/bin/zypper"; my $zypperopt="--non-interactive --no-gpg-checks xml-updates"; my $sudo="/usr/bin/sudo"; my $use_sudo=""; +my $releasefile="/etc/SuSE-release"; my $release="11.0"; my $dist="openSUSE"; -my $releasefile="/etc/SuSE-release"; my $patchlevel=0; +my ($opt_V, $opt_h, $opt_H, $opt_w, $opt_c, $opt_r, $opt_s, $opt_t, $opt_v); -open(RELEASE,"<$releasefile") || warn ("Could not open $releasefile\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, - "v" => \$opt_v, "verbose_output" => \$opt_v, - "s" => \$opt_s, "use_sudo" => \$opt_s); - -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) { - print_revision($PROGNAME,'$Revision: 0.3 $'); - exit $ERRORS{'OK'}; -} - -if ($opt_h) { - print_help(); - exit $ERRORS{'OK'}; -} +$opt_H=""; +$opt_w="recommended,optional"; +$opt_c="security"; +$opt_r="$releasefile"; +$opt_t="120"; +$opt_v=0; +$opt_s=0; -if (! $opt_H) { - $opt_H=$ENV{'HOSTNAME'}; +####################################################################### +# Functions +####################################################################### + +sub get_distribution($){ + my $file=shift || "$releasefile"; + my $release="11.0"; + my $dist="openSUSE"; + my $patchlevel=0; + 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 () { @@ -142,6 +106,9 @@ print " -c, --critical\n"; print " A patch with this category result in critical status.\n"; print " Default: $opt_c\n"; + print " -r, --releasefile\n"; + print " Use the given file to get informations about the distribution.\n"; + print " Default: $releasefile\n"; print " -s, --use_sudo\n"; print " Zypper needs root privileges on some distributions.\n"; print " You can enable the script to use $sudo to start zypper.\n"; @@ -169,7 +136,12 @@ support(); } -check(); +sub check_zypper(){ + if ( -x $zypper ){ + return (system("$use_sudo $zypper sl 2>/dev/null 1>&2")); + } + return 1; +} sub check_errorcode($){ my $status=shift || ""; @@ -178,7 +150,6 @@ return "OK"; } - sub check(){ my ($status,$ret_str,$error); my $secstr=""; @@ -234,8 +205,8 @@ print STDERR "Optional (optcount): $optcount\n"; print STDERR "Recommended (reccount): $reccount\n"; print STDERR "Security (seccount): $seccount\n"; - use Data::Dumper; - print STDERR Data::Dumper->Dump([\%packagelist]); + use Data::Dumper; + print STDERR Data::Dumper->Dump([\%packagelist]); } if ("$paccount" ne "0"){ $update_avail=1; @@ -274,15 +245,79 @@ } } else { $error="OK"; - $ret_str.="OK: no updates available\n"; + $ret_str="OK: no updates available\n"; } } close(FH); } else { - $ret_str="UNKNOWN - could not execute /usr/bin/zypper\n"; + $ret_str="UNKNOWN - could not execute $use_sudo $zypper $zypperopt\n"; $error="UNKNOWN"; } print "Updates $ret_str"; exit $ERRORS{"$error"}; } +####################################################################### +# Main +####################################################################### + +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, + "r=s" => \$opt_r, "releasefile=s" => \$opt_r, + "t=i" => \$opt_t, "timeout=i" => \$opt_t, + "v" => \$opt_v, "verbose_output" => \$opt_v, + "s" => \$opt_s, "use_sudo" => \$opt_s); + +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) { + print_revision($PROGNAME,"$VERSION"); + exit $ERRORS{'OK'}; +} + +if ($opt_h) { + print_help(); + exit $ERRORS{'OK'}; +} + +if (! $opt_H) { + $opt_H=$ENV{'HOSTNAME'}; +} + +($dist,$release,$patchlevel)=get_distribution("$opt_r"); + +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"}; + } +} + +if ( check_zypper() ){ + print "UNKNOWN - system doesn't allow to execute zypper\n"; + exit $ERRORS{"UNKNOWN"}; +} else { + check(); +} + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Remember to have fun... --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse-commit+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-commit+help@opensuse.org