]> git.michaelhowe.org Git - packages/n/nagios-plugins-local.git/commitdiff
Fixed check_cert plugin to work with IPv6
authorMichael Howe <michael@michaelhowe.org>
Fri, 17 Jun 2011 18:18:18 +0000 (18:18 +0000)
committerMichael Howe <michael@michaelhowe.org>
Fri, 17 Jun 2011 18:18:18 +0000 (18:18 +0000)
debian/changelog
plugins/check_cert

index 92f42e773710fec48e8025e8695d3870617788f7..b279b73db0af4087fe342ea3236fd4756f233d25 100644 (file)
@@ -1,3 +1,9 @@
+nagios-plugins-local (0.3) unstable; urgency=low
+
+  * check_cert plugin now handles IPv6 
+
+ -- Michael Howe <michael@michaelhowe.org>  Fri, 17 Jun 2011 19:17:44 +0100
+
 nagios-plugins-local (0.2) unstable; urgency=low
 
   * Added check_ldaps_ip plugin
index d555581a61b1e509c787d51bf863bedf4e61e124..204cd0398ffa77fa2cc8cadd99018af5b3d8942b 100755 (executable)
@@ -95,7 +95,14 @@ my $certdata;
 my $host = $uri->opaque();
 $host =~ s/^\/+//;
 my $port = undef;
-if ($host =~ s/:(\d+)//) {
+if( $host =~ m/\[([0-9A-F:]+)\](?::(\d+))?/i ){
+    # It's an IPv6 host, with an optional port
+    $host = $1;
+    if( $2 ){
+        $port = $2;
+    }
+    # If we've only got one : assume it's a port
+} elsif ( $host !~ m{:.*:} and $host =~ s/:(\d+)$//) {
     $port = $1;
 }
 $host ||= 'localhost';
@@ -106,27 +113,27 @@ if ($scheme eq 'file') {
 } elsif ($scheme eq 'https') {
     $port ||= 443;
 
-    $certdata = s_client("", "-connect $host:$port");
+    $certdata = s_client("", "--port $port $host");
 
 } elsif ($scheme eq 'imaps') {
     $port ||= 993;
 
-    $certdata = s_client(". logout", "-connect $host:$port");
+    $certdata = s_client(". logout", "--port $port $host");
 
 } elsif ($scheme eq 'ldaps') {
     $port ||= 636;
 
-    $certdata = s_client("", "-connect $host:$port");
+    $certdata = s_client("", "--port $port $host");
 
 } elsif ($scheme eq 'smtp') {
     $port ||= 25;
 
-    $certdata = s_client("quit", "-starttls smtp -connect $host:$port");
+    $certdata = s_client("quit", "--starttls --port $port $host");
 
 } elsif ($scheme eq 'smtps') {
     $port ||= 465;
 
-    $certdata = s_client("quit", "-connect $host:$port");
+    $certdata = s_client("quit", "--port $port $host");
 
 } else {
     usage(message => "unsupported scheme ($scheme)");
@@ -194,7 +201,7 @@ exit($ERRORS{'OK'});
 sub s_client {
     my ($command, $arguments) = @_;
 
-    return(parse_certificate(scalar(`/bin/echo $command | /usr/bin/openssl s_client $arguments 2>/dev/null | /usr/bin/openssl x509 -text 2>/dev/null`)));
+    return(parse_certificate(scalar(`/bin/echo $command | /usr/bin/gnutls-cli --insecure --print-cert $arguments 2>/dev/null | /usr/bin/openssl x509 -text 2>/dev/null`)));
 }
 
 sub read_file {