Code

Fix Debian bug #545940: Failure when run via ePN
[nagiosplug.git] / plugins-scripts / check_ircd.pl
index e4c4bd02686f53ec34d3fb619af0c30a3eca7e73..42a9bca91601546d05ba7ee9fea85a83b56f44e3 100755 (executable)
@@ -7,7 +7,6 @@
 #
 # Date:                        1999/09/20
 #
-# $Id$
 #
 # Description:         This script will check to see if an IRCD is running
 #                      about how many users it has
 #                              with perl -wT and 'use strict'
 #
 # test using check_ircd.pl (irc-2.mit.edu|irc.erols.com|irc.core.com)
+# 2002/05/02    SG             Fixed for Embedded Perl
 #
-# ------------------------------------------------------------------[ Begin ]--
-
-BEGIN {
-       if ($0 =~ m/^(.*?)[\/\\]([^\/\\]+)$/) {
-               $runtimedir = $1;
-               $PROGNAME = $2;
-       }
-}
 
 # ----------------------------------------------------------------[ Require ]--
 
@@ -59,7 +51,7 @@ use strict;
 use Getopt::Long;
 use vars qw($opt_V $opt_h $opt_t $opt_p $opt_H $opt_w $opt_c $verbose);
 use vars qw($PROGNAME);
-use lib $main::runtimedir;
+use lib utils.pm;
 use utils qw($TIMEOUT %ERRORS &print_revision &support &usage);
 
 # ----------------------------------------------------[ Function Prototypes ]--
@@ -67,7 +59,7 @@ use utils qw($TIMEOUT %ERRORS &print_revision &support &usage);
 sub print_help ();
 sub print_usage ();
 sub connection ($$$$);
-sub bindRemote ($$$);
+sub bindRemote ($$);
 
 # -------------------------------------------------------------[ Enviroment ]--
 
@@ -77,6 +69,7 @@ $ENV{BASH_ENV} = "";
 
 # -----------------------------------------------------------------[ Global ]--
 
+$PROGNAME = "check_ircd";
 my $NICK="ircd$$";
 my $USER_INFO="monitor localhost localhost : ";
        
@@ -125,7 +118,7 @@ sub print_usage () {
 
 sub print_help ()
 {
-       print_revision($PROGNAME,'$Revision$ ');
+       print_revision($PROGNAME,'@NP_VERSION@');
        print "Copyright (c) 2000 Richard Mayhew/Karl DeBisschop
 
 Perl Check IRCD plugin for Nagios
@@ -148,28 +141,20 @@ Perl Check IRCD plugin for Nagios
 
 # -------------------------------------------------------------[ bindRemote ]--
 
-sub bindRemote ($$$)
+sub bindRemote ($$)
 {
-       my ($in_remotehost, $in_remoteport, $in_hostname) = @_;
+       my ($in_remotehost, $in_remoteport) = @_;
        my $proto = getprotobyname('tcp');
        my $sockaddr;
-       my $this;
-       my $thisaddr = gethostbyname($in_hostname);
        my $that;
        my ($name, $aliases,$type,$len,$thataddr) = gethostbyname($in_remotehost);
-#      ($name,$aliases,$type,$len,$thisaddr) = gethostbyname($in_hostname);
 
        if (!socket(ClientSocket,AF_INET, SOCK_STREAM, $proto)) {
            print "IRCD UNKNOWN: Could not start socket ($!)\n";
            exit $ERRORS{"UNKNOWN"};
        }
        $sockaddr = 'S n a4 x8';
-       $this = pack($sockaddr, AF_INET, 0, $thisaddr);
        $that = pack($sockaddr, AF_INET, $in_remoteport, $thataddr);
-       if (!bind(ClientSocket, $this)) {
-           print "IRCD UNKNOWN: Could not bind socket ($!)\n";
-           exit $ERRORS{"UNKNOWN"};
-       }
        if (!connect(ClientSocket, $that)) { 
            print "IRCD UNKNOWN: Could not connect socket ($!)\n";
            exit $ERRORS{"UNKNOWN"};
@@ -196,25 +181,25 @@ MAIN:
                "H=s" => \$opt_H,  "hostname=s" => \$opt_H);
 
        if ($opt_V) {
-               print_revision($PROGNAME,'$Revision$ ');
+               print_revision($PROGNAME,'@NP_VERSION@');
                exit $ERRORS{'OK'};
        }
 
        if ($opt_h) {print_help(); exit $ERRORS{'OK'};}
 
-       ($opt_H) || ($opt_H = shift) || usage("Host name/address not specified\n");
+       ($opt_H) || ($opt_H = shift @ARGV) || usage("Host name/address not specified\n");
        my $remotehost = $1 if ($opt_H =~ /([-.A-Za-z0-9]+)/);
        ($remotehost) || usage("Invalid host: $opt_H\n");
 
-       ($opt_w) || ($opt_w = shift) || ($opt_w = 50);
+       ($opt_w) || ($opt_w = shift @ARGV) || ($opt_w = 50);
        my $warn = $1 if ($opt_w =~ /^([0-9]+)$/);
        ($warn) || usage("Invalid warning threshold: $opt_w\n");
 
-       ($opt_c) || ($opt_c = shift) || ($opt_c = 100);
+       ($opt_c) || ($opt_c = shift @ARGV) || ($opt_c = 100);
        my $crit = $1 if ($opt_c =~ /^([0-9]+)$/);
        ($crit) || usage("Invalid critical threshold: $opt_c\n");
 
-       ($opt_p) || ($opt_p = shift) || ($opt_p = 6667);
+       ($opt_p) || ($opt_p = shift @ARGV) || ($opt_p = 6667);
        my $remoteport = $1 if ($opt_p =~ /^([0-9]+)$/);
        ($remoteport) || usage("Invalid port: $opt_p\n");
 
@@ -228,13 +213,10 @@ MAIN:
        
        alarm($TIMEOUT);
 
-       chomp($hostname = `/bin/hostname`);
-       $hostname = $1 if ($hostname =~ /([-.a-zA-Z0-9]+)/);
        my ($name, $alias, $proto) = getprotobyname('tcp');
-       print "MAIN(debug): hostname = $hostname\n" if $verbose;
 
-       print "MAIN(debug): binding to remote host: $remotehost -> $remoteport -> $hostname\n" if $verbose;
-       my $ClientSocket = &bindRemote($remotehost,$remoteport,$hostname);
+       print "MAIN(debug): binding to remote host: $remotehost -> $remoteport\n" if $verbose;
+       my $ClientSocket = &bindRemote($remotehost,$remoteport);
        
        print ClientSocket "NICK $NICK\nUSER $USER_INFO\n";