matteocorti / nagios_plugins

18 stars 7 forks source link

check_updates: openvz kernels and remove Sort::Versions dependncy #125

Closed matteocorti closed 8 years ago

matteocorti commented 8 years ago

Original reporter: liedekef@telenet.be

I changed this (unified diff) to support openvz kernels for check_updates, and to remove the dependancy for the perl plugin Sort::Versions (which is not installed by default):


--- check_updates   2013-08-22 13:53:23.000000000 +0200
+++ check_updates.new   2013-08-22 14:23:46.000000000 +0200
@@ -38,7 +38,6 @@
 use Nagios::Plugin::Threshold;
 use Nagios::Plugin;
 use POSIX qw(uname);
-use Sort::Versions;

 use Readonly;

@@ -83,6 +82,40 @@

 ##############################################################################
 # subroutines
+sub versioncmp( $$ ) {
+    my @A # ($_[0]~ /([-.]|\d+|[^-.\d]+)/g);
+    my @B # ($_[1]~ /([-.]|\d+|[^-.\d]+)/g);
+
+    my ($A, $B);
+    while (@A and @B) {
+        $A = shift @A;
+        $B = shift @B;
+        if ($A eq '-' and $B eq '-') {
+            next;
+        } elsif ( $A eq '-' ) {
+            return -1;
+        } elsif ( $B eq '-') {
+            return 1;
+        } elsif ($A eq '.' and $B eq '.') {
+            next;
+        } elsif ( $A eq '.' ) {
+            return -1;
+        } elsif ( $B eq '.' ) {
+            return 1;
+        } elsif ($A =~ /^\d+$/ and $B =~ /^\d+$/) {
+            if ($A =~ /^0/ || $B =~ /^0/) {
+                return $A cmp $B if $A cmp $B;
+            } else {
+                return $A <=> $B if $A <=> $B;
+            }
+        } else {
+            $A = uc $A;
+            $B = uc $B;
+            return $A cmp $B if $A cmp $B;
+        }
+    }
+    @A <=> @B;
+}

 ##############################################################################
 # Usage     : exit_with_error( $status, $message)
@@ -198,6 +231,9 @@
     # remove Xen
     $kernel =~ s/xen-//imxs;

+    # remove openvz
+    $kernel =~ s/o?vzkernel-//imxs;
+
     # remove architecture

     $kernel =~ s/[.](i[3-6]86|ppc|x86_64)$//mxs;
@@ -226,6 +262,11 @@
 # See also  : n/a
 sub check_running_kernel {

+    # return if running in openvz client: /proc/vz is always present but /proc/bc only exists on node, but not inside container.
+    if ( -d "/proc/vz" && !(-d "/proc/bc")) {
+        return;
+    }
+
     if ( !$bootcheck ) {
         return;
     }
@@ -247,7 +288,7 @@
     my @versions;

     for
-      my $rpm ( ( "$package", "$package-smp", "$package-PAE", "$package-xen" ) )
+      my $rpm ( ( "$package", "$package-smp", "$package-PAE", "$package-xen", "ovzkernel", "vzkernel" ) )
     {

         my $output;
matteocorti commented 8 years ago

Original reporter: matteo@corti.li

Hi

sorry for coming back to this ticket so late. I will include the openvz kernel change but I am a little curious on the reason to include the Sort::Version module. I should change the licensing of the module: are there any changes that I missed?

Matteo

matteocorti commented 8 years ago

Original reporter: liedekef@telenet.be

The reason to include the sort algoritm directly is because on redhat there's not a standard rpm for Sort::Version, so with this included we remove a dependancy and make it easy to use the plugin on redhat/centos as well.

matteocorti commented 8 years ago

Original reporter: matteo@corti.li

OK I'll see how it can be cleanly done. To be included in EPEL the plugin's RPM was reviewed and I remember a lot of points regarding the license :-)

matteocorti commented 8 years ago

Original reporter: matteo@corti.li

Dependency removed in r1372 (will be released with the new version)