[Openvas-commits] r6891 - trunk/tools/nagios

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Mar 3 19:45:10 CET 2010


Author: mime
Date: 2010-03-03 19:45:09 +0100 (Wed, 03 Mar 2010)
New Revision: 6891

Modified:
   trunk/tools/nagios/check_openvas
   trunk/tools/nagios/check_openvasmd
Log:
Fix for Nagios Embedded Perl

Modified: trunk/tools/nagios/check_openvas
===================================================================
--- trunk/tools/nagios/check_openvas	2010-03-03 17:16:01 UTC (rev 6890)
+++ trunk/tools/nagios/check_openvas	2010-03-03 18:45:09 UTC (rev 6891)
@@ -1,190 +1,183 @@
-#!/usr/bin/perl -w
-
-###############################################################################
-# Nagios Plugin for OpenVAS
-# $Id$
-#
-# Authors:
-# Michael Meyer <michael.meyer at greenbone.net>
-#
-# Copyright:
-# Copyright (c) 2010 Greenbone Networks GmbH <http://www.greenbone.net>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 2
-# (or any later version), as published by the Free Software Foundation.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# commands.cfg:
-#
-#  define command{
-#        command_name    check_openvas
-#        command_line    $USER1$/check_openvas -H $HOSTADDRESS$ -p $ARG1$ -u $ARG2$ -P $ARG3$ -c $ARG4$ -w $ARG5$
-#  } 
-#
-# <host>.cfg
-#
-#  define service{
-#        use                             local-service
-#        host_name                       <HOSTNAME>
-#        service_description             OpenVAS
-#        check_command                   check_openvas!<PORT>!<USERNAME>!<PASSWORD>!<CRITICAL Response Time>!<WARNING Response Time>
-#  }
-#        
-###############################################################################
-
-use strict;
-use IO::Socket::SSL;
-use File::Basename;
-use Getopt::Long;
-use Time::HiRes qw(gettimeofday tv_interval);
-
-my $dirname;
-
-BEGIN {
-  $dirname = dirname($0);
-}
-
-use lib $dirname;
-use utils qw($TIMEOUT %ERRORS &print_revision &support);
-use vars qw($PROGNAME);
-
-my ($opt_version,$opt_help,$opt_port,$opt_host,$opt_uname,$opt_pass,$opt_c,$opt_w);
-  
-$PROGNAME = "check_openvas";
-sub print_usage ();
-
-$ENV{'BASH_ENV'}='';
-$ENV{'ENV'}='';
-$ENV{'PATH'}='';
-$ENV{'LC_ALL'}='C';
-
-my $proto = "< OTP/1.0 >";
-
-Getopt::Long::Configure('bundling');
-
-GetOptions(
-        "V"   => \$opt_version,     "version"           => \$opt_version,
-        "h"   => \$opt_help,        "help"              => \$opt_help,
-        "p=i" => \$opt_port,        "port=i"            => \$opt_port,
-        "H=s" => \$opt_host,        "hostname=s"        => \$opt_host,
-        "u=s" => \$opt_uname,       "username=s"        => \$opt_uname,
-        "P=s" => \$opt_pass,        "password=s"        => \$opt_pass,
-        "c=i" => \$opt_c,           "critical=i"        => \$opt_c,
-        "w=i" => \$opt_w,           "warning=i"         => \$opt_w
-);
-
-if ($opt_help) { print_usage(); exit $ERRORS{'OK'}; }
-
-if ($opt_version) {
-        print_revision($PROGNAME,'0.1-$Revision$');
-        exit $ERRORS{'OK'};
-}
-
-if (!$opt_host || !$opt_port || !$opt_uname || !$opt_pass || !$opt_c || !$opt_w) { print_usage(); exit $ERRORS{'UNKNOWN'}; }
-
-if (!utils::is_hostname($opt_host)){
-        print "$opt_host is not a valid host name\n";
-        print_usage();
-        exit $ERRORS{"UNKNOWN"};
-}
-
-$SIG{'ALRM'} = sub {
-        print ("OpenVAS UNKNOWN: No response from server (alarm)\n");
-        exit $ERRORS{"UNKNOWN"};
-};
-
-alarm($TIMEOUT);
-
-checklogin();
-  
-sub checklogin {
-
-  my $t0 = [gettimeofday];
-
-  my $sock = IO::Socket::SSL->new(
-				  PeerAddr        => $opt_host,
-				  PeerPort        => $opt_port,
-				  SSL_version     => "TLSv1", 
-				  Timeout         => 30
-				  );
-  if(!$sock) {
-    print "OpenVAS CRITICAL: Could not connect to OpenVAS at $opt_host\n";
-    exit $ERRORS{'CRITICAL'};
-  }  
-  
-  $sock->autoflush();
-
-  $sock->print($proto . "\n");
-  my $r = $sock->getline;
-
-  if(!defined($r)) {
-    print "OpenVAS CRITICAL: No answer to OTP request from OpenVAS Server at $opt_host\n";
-    $sock->close();
-    exit $ERRORS{'CRITICAL'};
-  }
-
-  chomp($r);
-
-  if($r ne $proto) {
-    print "OoenVAS CRITICAL: OpenVAS Server at $opt_host does not understand OTP/1.0\n";
-    $sock->close();
-    exit $ERRORS{'CRITICAL'};
-  }
-
-  $sock->print($opt_uname ."\n");
-  $sock->print($opt_pass . "\n");
-
-  $r = $sock->getline;
-
-  if($r =~ /Bad login/gis) {
-    print "OpenVAS CRITICAL: Could not login to  at $opt_host: Bad login\n";
-    $sock->close();
-    exit $ERRORS{'CRITICAL'};
-  }
-
-  my $elapsed = sprintf("%.4f",tv_interval ($t0,[gettimeofday]));
-
-  if($elapsed > $opt_c) {
-    print "OpenVAS CRITICAL: Response time $elapsed seconds\n";
-    $sock->close();
-    exit $ERRORS{'CRITICAL'};
-  } 
-  elsif($elapsed > $opt_w) {
-    print "OpenVAS WARNING: Response time $elapsed seconds\n";
-    $sock->close();
-    exit $ERRORS{'WARNING'};
- }  
-
-  my $version = "unknown";
-
-  $sock->print("\n\n");
-
-  while($r = $sock->getline) {
- 
-    if($r =~ m/^server_info_openvas.*d_version <\|> ([0-9.]+)/) {
-      $version = $1;
-      last;
-    }  
-  }
-
-  print "OpenVAS OK: Server (v$version) ready. Response time $elapsed seconds \| restime=${elapsed}s;$opt_w;$opt_c\n";
-  $sock->close();
-  exit $ERRORS{'OK'};
-
-}
-
-sub print_usage () {
-        print "Usage: \n";
-        print " $PROGNAME -H <host> -p <port> -u <username> -P <password> -c <response time> -w <response time>\n";
-        print " $PROGNAME [-h | --help]\n";
-        print " $PROGNAME [-V | --version]\n";
-}
+#!/usr/bin/perl
+
+###############################################################################
+# Nagios Plugin for OpenVAS
+# $Id$
+#
+# Authors:
+# Michael Meyer <michael.meyer at greenbone.net>
+#
+# Copyright:
+# Copyright (c) 2010 Greenbone Networks GmbH <http://www.greenbone.net>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2
+# (or any later version), as published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# commands.cfg:
+#
+#  define command{
+#        command_name    check_openvas
+#        command_line    $USER1$/check_openvas -H $HOSTADDRESS$ -p $ARG1$ -u $ARG2$ -P $ARG3$ -c $ARG4$ -w $ARG5$
+#  } 
+#
+# <host>.cfg
+#
+#  define service{
+#        use                             local-service
+#        host_name                       <HOSTNAME>
+#        service_description             OpenVAS
+#        check_command                   check_openvas!<PORT>!<USERNAME>!<PASSWORD>!<CRITICAL Response Time>!<WARNING Response Time>
+#  }
+#        
+###############################################################################
+
+use strict;
+use IO::Socket::SSL;
+use File::Basename;
+use Getopt::Long;
+use Time::HiRes qw(gettimeofday tv_interval);
+
+use lib qw( /usr/lib/nagios/plugins /usr/local/nagios/libexec );
+use utils qw($TIMEOUT %ERRORS &print_revision &support);
+use vars qw($PROGNAME);
+
+my ($opt_version,$opt_help,$opt_port,$opt_host,$opt_uname,$opt_pass,$opt_c,$opt_w);
+  
+$PROGNAME = "check_openvas";
+sub print_usage ();
+
+$ENV{'BASH_ENV'}='';
+$ENV{'ENV'}='';
+$ENV{'PATH'}='';
+$ENV{'LC_ALL'}='C';
+
+my $proto = "< OTP/1.0 >";
+
+Getopt::Long::Configure('bundling');
+
+GetOptions(
+        "V"   => \$opt_version,     "version"           => \$opt_version,
+        "h"   => \$opt_help,        "help"              => \$opt_help,
+        "p=i" => \$opt_port,        "port=i"            => \$opt_port,
+        "H=s" => \$opt_host,        "hostname=s"        => \$opt_host,
+        "u=s" => \$opt_uname,       "username=s"        => \$opt_uname,
+        "P=s" => \$opt_pass,        "password=s"        => \$opt_pass,
+        "c=i" => \$opt_c,           "critical=i"        => \$opt_c,
+        "w=i" => \$opt_w,           "warning=i"         => \$opt_w
+);
+
+if ($opt_help) { print_usage(); exit $ERRORS{'OK'}; }
+
+if ($opt_version) {
+        print_revision($PROGNAME,'0.1-$Revision$');
+        exit $ERRORS{'OK'};
+}
+
+if (!$opt_host || !$opt_port || !$opt_uname || !$opt_pass || !$opt_c || !$opt_w) { print_usage(); exit $ERRORS{'UNKNOWN'}; }
+
+if (!utils::is_hostname($opt_host)){
+        print "$opt_host is not a valid host name\n";
+        print_usage();
+        exit $ERRORS{"UNKNOWN"};
+}
+
+$SIG{'ALRM'} = sub {
+        print ("OpenVAS CRITICAL: No response from server (alarm)\n");
+        exit $ERRORS{"CRITICAL"};
+};
+
+alarm($TIMEOUT);
+
+checklogin();
+  
+sub checklogin {
+
+  my $t0 = [gettimeofday];
+
+  my $sock = IO::Socket::SSL->new(
+				  PeerAddr        => $opt_host,
+				  PeerPort        => $opt_port,
+				  Timeout         => 30
+				  );
+  if(!$sock) {
+    print "OpenVAS CRITICAL: Could not connect to OpenVAS at $opt_host\n";
+    exit $ERRORS{'CRITICAL'};
+  }  
+  
+  $sock->autoflush();
+
+  $sock->print($proto . "\n");
+  my $r = $sock->getline;
+
+  if(!defined($r)) {
+    print "OpenVAS CRITICAL: No answer to OTP request from OpenVAS Server at $opt_host\n";
+    $sock->close(SSL_ctx_free => 1);
+    exit $ERRORS{'CRITICAL'};
+  }
+
+  chomp($r);
+
+  if($r ne $proto) {
+    print "OpenVAS CRITICAL: OpenVAS Server at $opt_host does not understand OTP/1.0\n";
+    $sock->close(SSL_ctx_free => 1);
+    exit $ERRORS{'CRITICAL'};
+  }
+
+  $sock->print($opt_uname ."\n");
+  $sock->print($opt_pass . "\n");
+
+  $r = $sock->getline;
+
+  if($r =~ /Bad login/gis) {
+    print "OpenVAS CRITICAL: Could not login to  at $opt_host: Bad login\n";
+    $sock->close(SSL_ctx_free => 1);
+    exit $ERRORS{'CRITICAL'};
+  }
+
+  my $elapsed = sprintf("%.4f",tv_interval ($t0,[gettimeofday]));
+
+  if($elapsed > $opt_c) {
+    print "OpenVAS CRITICAL: Response time $elapsed seconds\n";
+    $sock->close(SSL_ctx_free => 1);
+    exit $ERRORS{'CRITICAL'};
+  } 
+  elsif($elapsed > $opt_w) {
+    print "OpenVAS WARNING: Response time $elapsed seconds\n";
+    $sock->close(SSL_ctx_free => 1);
+    exit $ERRORS{'WARNING'};
+ }  
+
+  my $version = "unknown";
+
+  $sock->print("\n\n");
+
+  while($r = $sock->getline) {
+ 
+    if($r =~ m/^server_info_openvas.*d_version <\|> ([0-9.]+)/) {
+      $version = $1;
+      last;
+    }  
+  }
+
+  print "OpenVAS OK: Server (v$version) ready. Response time $elapsed seconds \| restime=${elapsed}s;$opt_w;$opt_c\n";
+  $sock->close(SSL_ctx_free => 1);
+  exit $ERRORS{'OK'};
+
+}
+
+sub print_usage () {
+        print "Usage: \n";
+        print " $PROGNAME -H <host> -p <port> -u <username> -P <password> -c <response time> -w <response time>\n";
+        print " $PROGNAME [-h | --help]\n";
+        print " $PROGNAME [-V | --version]\n";
+}

Modified: trunk/tools/nagios/check_openvasmd
===================================================================
--- trunk/tools/nagios/check_openvasmd	2010-03-03 17:16:01 UTC (rev 6890)
+++ trunk/tools/nagios/check_openvasmd	2010-03-03 18:45:09 UTC (rev 6891)
@@ -1,171 +1,164 @@
-#!/usr/bin/perl -w
-
-###############################################################################
-# Nagios Plugin for OpenVAS-Manager
-# $Id$
-#
-# Authors:
-# Michael Meyer <michael.meyer at greenbone.net>
-#
-# Copyright:
-# Copyright (c) 2010 Greenbone Networks GmbH <http://www.greenbone.net>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 2
-# (or any later version), as published by the Free Software Foundation.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# commands.cfg:
-#
-#  define command{
-#        command_name    check_openvasmd
-#        command_line    $USER1$/check_openvasmd -H $HOSTADDRESS$ -p $ARG1$ -u $ARG2$ -P $ARG3$ -c $ARG4$ -w $ARG5$
-#  } 
-#
-# <host>.cfg
-#
-#  define service{
-#        use                             local-service
-#        host_name                       <HOSTNAME>
-#        service_description             OpenVAS-Manager
-#        check_command                   check_openvasmd!<PORT>!<USERNAME>!<PASSWORD>!<CRITICAL Response Time>!<WARNING Response Time>
-#  }
-#        
-###############################################################################
-
-use strict;
-use IO::Socket::SSL;
-use File::Basename;
-use Getopt::Long;
-use Time::HiRes qw(gettimeofday tv_interval);
-
-my $dirname;
-
-BEGIN {
-  $dirname = dirname($0);
-}
-
-use lib $dirname;
-use utils qw($TIMEOUT %ERRORS &print_revision &support);
-use vars qw($PROGNAME);
-
-my ($opt_version,$opt_help,$opt_port,$opt_host,$opt_uname,$opt_pass,$opt_c,$opt_w);
-  
-$PROGNAME = "check_openvasmd";
-sub print_usage ();
-
-$ENV{'BASH_ENV'}='';
-$ENV{'ENV'}='';
-$ENV{'PATH'}='';
-$ENV{'LC_ALL'}='C';
-
-Getopt::Long::Configure('bundling');
-
-GetOptions(
-        "V"   => \$opt_version,     "version"           => \$opt_version,
-        "h"   => \$opt_help,        "help"              => \$opt_help,
-        "p=i" => \$opt_port,        "port=i"            => \$opt_port,
-        "H=s" => \$opt_host,        "hostname=s"        => \$opt_host,
-        "u=s" => \$opt_uname,       "username=s"        => \$opt_uname,
-        "P=s" => \$opt_pass,        "password=s"        => \$opt_pass,
-        "c=i" => \$opt_c,           "critical=i"        => \$opt_c,
-        "w=i" => \$opt_w,           "warning=i"         => \$opt_w
-);
-
-if ($opt_help) { print_usage(); exit $ERRORS{'OK'}; }
-
-if ($opt_version) {
-        print_revision($PROGNAME,'0.1-$Revision$');
-        exit $ERRORS{'OK'};
-}
-
-if (!$opt_host || !$opt_port || !$opt_uname || !$opt_pass || !$opt_c || !$opt_w) { print_usage(); exit $ERRORS{'UNKNOWN'}; }
-
-if (!utils::is_hostname($opt_host)){
-        print "OpenVAS-Manager UNKNOWN: $opt_host is not a valid host name\n";
-        print_usage();
-        exit $ERRORS{"UNKNOWN"};
-}
-
-$SIG{'ALRM'} = sub {
-        print ("OpenVAS-Manager UNKNOWN: No response from server (alarm)\n");
-        exit $ERRORS{"UNKNOWN"};
-};
-
-alarm($TIMEOUT);
-
-checklogin();
-  
-sub checklogin {
-
-  my $t0 = [gettimeofday];
-
-  my $sock = IO::Socket::SSL->new(
-				  PeerAddr        => $opt_host,
-				  PeerPort        => $opt_port,
-				  SSL_version     => "TLSv1", 
-				  Timeout         => 30
-				  );
-  if(!$sock) {
-    print "OpenVAS-Manager CRITICAL: Could not connect to OpenVAS-Manager at $opt_host\n";
-    exit $ERRORS{'CRITICAL'};
-  }  
-  
-  $sock->autoflush();
-
-  my $request = "<authenticate><credentials><username>$opt_uname</username><password>$opt_pass</password></credentials></authenticate>";
-
-  $sock->print($request."<HELP/>\n");
-  my $r = $sock->getline;
-
-  if(!defined($r)) {
-    print "OpenVAS-Manager CRITICAL: No answer to AUTH request from OpenVAS-Manager at $opt_host\n";
-    $sock->close();
-    exit $ERRORS{'CRITICAL'};
-  }  
-
-  if($r =~ /Authentication failed/gis) {
-    print "OpenVAS-Manager CRITICAL: Could not login to OpenVAS-Manager at $opt_host: Authentication failed\n";
-    $sock->close();
-    exit $ERRORS{'CRITICAL'};
-  } 
-
-  my $elapsed = sprintf("%.4f",tv_interval ($t0,[gettimeofday]));
-
-  if($elapsed > $opt_c) {
-    print "OpenVAS-Manager CRITICAL: Response time $elapsed seconds\n";
-    $sock->close();
-    exit $ERRORS{'CRITICAL'};
-  } 
-  elsif($elapsed > $opt_w) {
-    print "OpenVAS-Manager WARNING: Response time $elapsed seconds\n";
-    $sock->close();
-    exit $ERRORS{'WARNING'};
- }  
-
-  if($r =~ /<authenticate_response status="200"/gis) {
-    print "OpenVAS-Manager OK: Response time $elapsed seconds \| restime=${elapsed}s;$opt_w;$opt_c\n";
-    $sock->close();
-    exit $ERRORS{'OK'};
-  } else {
-    print "OpenVAS-Manager UNKNOWN: Unexpected answer from OpenVAS-Manager at $opt_host";
-    exit $ERRORS{'UNKNOWN'};
-    $sock->close();
-  }  
-
-}
-
-sub print_usage () {
-        print "Usage: \n";
-        print " $PROGNAME -H <host> -p <port> -u <username> -P <password> -c <response time> -w <response time>\n";
-        print " $PROGNAME [-h | --help]\n";
-        print " $PROGNAME [-V | --version]\n";
-}
+#!/usr/bin/perl
+
+###############################################################################
+# Nagios Plugin for OpenVAS-Manager
+# $Id$
+#
+# Authors:
+# Michael Meyer <michael.meyer at greenbone.net>
+#
+# Copyright:
+# Copyright (c) 2010 Greenbone Networks GmbH <http://www.greenbone.net>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2
+# (or any later version), as published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# commands.cfg:
+#
+#  define command{
+#        command_name    check_openvasmd
+#        command_line    $USER1$/check_openvasmd -H $HOSTADDRESS$ -p $ARG1$ -u $ARG2$ -P $ARG3$ -c $ARG4$ -w $ARG5$
+#  } 
+#
+# <host>.cfg
+#
+#  define service{
+#        use                             local-service
+#        host_name                       <HOSTNAME>
+#        service_description             OpenVAS-Manager
+#        check_command                   check_openvasmd!<PORT>!<USERNAME>!<PASSWORD>!<CRITICAL Response Time>!<WARNING Response Time>
+#  }
+#        
+###############################################################################
+
+use strict;
+use IO::Socket::SSL;
+use File::Basename;
+use Getopt::Long;
+use Time::HiRes qw(gettimeofday tv_interval);
+
+use lib qw( /usr/lib/nagios/plugins /usr/local/nagios/libexec );
+use utils qw($TIMEOUT %ERRORS &print_revision &support);
+use vars qw($PROGNAME);
+
+my ($opt_version,$opt_help,$opt_port,$opt_host,$opt_uname,$opt_pass,$opt_c,$opt_w);
+  
+$PROGNAME = "check_openvasmd";
+sub print_usage ();
+
+$ENV{'BASH_ENV'}='';
+$ENV{'ENV'}='';
+$ENV{'PATH'}='';
+$ENV{'LC_ALL'}='C';
+
+Getopt::Long::Configure('bundling');
+
+GetOptions(
+        "V"   => \$opt_version,     "version"           => \$opt_version,
+        "h"   => \$opt_help,        "help"              => \$opt_help,
+        "p=i" => \$opt_port,        "port=i"            => \$opt_port,
+        "H=s" => \$opt_host,        "hostname=s"        => \$opt_host,
+        "u=s" => \$opt_uname,       "username=s"        => \$opt_uname,
+        "P=s" => \$opt_pass,        "password=s"        => \$opt_pass,
+        "c=i" => \$opt_c,           "critical=i"        => \$opt_c,
+        "w=i" => \$opt_w,           "warning=i"         => \$opt_w
+);
+
+if ($opt_help) { print_usage(); exit $ERRORS{'OK'}; }
+
+if ($opt_version) {
+        print_revision($PROGNAME,'0.1-$Revision$');
+        exit $ERRORS{'OK'};
+}
+
+if (!$opt_host || !$opt_port || !$opt_uname || !$opt_pass || !$opt_c || !$opt_w) { print_usage(); exit $ERRORS{'UNKNOWN'}; }
+
+if (!utils::is_hostname($opt_host)){
+        print "OpenVAS-Manager UNKNOWN: $opt_host is not a valid host name\n";
+        print_usage();
+        exit $ERRORS{"UNKNOWN"};
+}
+
+$SIG{'ALRM'} = sub {
+        print ("OpenVAS-Manager CRITICAL: No response from server (alarm)\n");
+        exit $ERRORS{"CRITICAL"};
+};
+
+alarm($TIMEOUT);
+
+checklogin();
+  
+sub checklogin {
+
+  my $t0 = [gettimeofday];
+
+  my $sock = IO::Socket::SSL->new(
+				  PeerAddr        => $opt_host,
+				  PeerPort        => $opt_port,
+				  Timeout         => 30
+				  );
+  if(!$sock) {
+    print "OpenVAS-Manager CRITICAL: Could not connect to OpenVAS-Manager at $opt_host\n";
+    exit $ERRORS{'CRITICAL'};
+  }  
+  
+  $sock->autoflush();
+
+  my $request = "<authenticate><credentials><username>$opt_uname</username><password>$opt_pass</password></credentials></authenticate>";
+
+  $sock->print($request."<HELP/>\n");
+  my $r = $sock->getline;
+
+  if(!defined($r)) {
+    print "OpenVAS-Manager CRITICAL: No answer to AUTH request from OpenVAS-Manager at $opt_host\n";
+    $sock->close(SSL_ctx_free => 1);
+    exit $ERRORS{'CRITICAL'};
+  }  
+
+  if($r =~ /Authentication failed/gis) {
+    print "OpenVAS-Manager CRITICAL: Could not login to OpenVAS-Manager at $opt_host: Authentication failed\n";
+    $sock->close(SSL_ctx_free => 1);
+    exit $ERRORS{'CRITICAL'};
+  } 
+
+  my $elapsed = sprintf("%.4f",tv_interval ($t0,[gettimeofday]));
+
+  if($elapsed > $opt_c) {
+    print "OpenVAS-Manager CRITICAL: Response time $elapsed seconds\n";
+    $sock->close(SSL_ctx_free => 1);
+    exit $ERRORS{'CRITICAL'};
+  } 
+  elsif($elapsed > $opt_w) {
+    print "OpenVAS-Manager WARNING: Response time $elapsed seconds\n";
+    $sock->close(SSL_ctx_free => 1);
+    exit $ERRORS{'WARNING'};
+ }  
+
+  if($r =~ /<authenticate_response status="200"/gis) {
+    print "OpenVAS-Manager OK: Response time $elapsed seconds \| restime=${elapsed}s;$opt_w;$opt_c\n";
+    $sock->close(SSL_ctx_free => 1);
+    exit $ERRORS{'OK'};
+  } else {
+    print "OpenVAS-Manager UNKNOWN: Unexpected answer from OpenVAS-Manager at $opt_host";
+    exit $ERRORS{'UNKNOWN'};
+    $sock->close(SSL_ctx_free => 1);
+  }  
+
+}
+
+sub print_usage () {
+        print "Usage: \n";
+        print " $PROGNAME -H <host> -p <port> -u <username> -P <password> -c <response time> -w <response time>\n";
+        print " $PROGNAME [-h | --help]\n";
+        print " $PROGNAME [-V | --version]\n";
+}



More information about the Openvas-commits mailing list