summaryrefslogtreecommitdiffstats
path: root/plugins-scripts
diff options
context:
space:
mode:
Diffstat (limited to 'plugins-scripts')
-rwxr-xr-xplugins-scripts/check_ircd.pl61
1 files changed, 26 insertions, 35 deletions
diff --git a/plugins-scripts/check_ircd.pl b/plugins-scripts/check_ircd.pl
index 4822fe6..15a7080 100755
--- a/plugins-scripts/check_ircd.pl
+++ b/plugins-scripts/check_ircd.pl
@@ -40,15 +40,16 @@
40 40
41# ----------------------------------------------------------------[ Require ]-- 41# ----------------------------------------------------------------[ Require ]--
42 42
43require 5.004; 43require 5.14.0;
44 44
45# -------------------------------------------------------------------[ Uses ]-- 45# -------------------------------------------------------------------[ Uses ]--
46 46
47use Socket;
48use strict; 47use strict;
48use IO::Socket::IP;
49use Getopt::Long; 49use Getopt::Long;
50use vars qw($opt_V $opt_h $opt_t $opt_p $opt_H $opt_w $opt_c $verbose); 50use vars qw($opt_V $opt_h $opt_t $opt_p $opt_H $opt_w $opt_c $opt_4 $opt_6 $verbose);
51use vars qw($PROGNAME); 51use vars qw($PROGNAME);
52use vars qw($ClientSocket);
52use FindBin; 53use FindBin;
53use lib "$FindBin::Bin"; 54use lib "$FindBin::Bin";
54use utils qw($TIMEOUT %ERRORS &print_revision &support &usage); 55use utils qw($TIMEOUT %ERRORS &print_revision &support &usage);
@@ -58,7 +59,6 @@ use utils qw($TIMEOUT %ERRORS &print_revision &support &usage);
58sub print_help (); 59sub print_help ();
59sub print_usage (); 60sub print_usage ();
60sub connection ($$$$); 61sub connection ($$$$);
61sub bindRemote ($$);
62 62
63# -------------------------------------------------------------[ Environment ]-- 63# -------------------------------------------------------------[ Environment ]--
64 64
@@ -104,7 +104,7 @@ sub connection ($$$$)
104 $answer = "Server $in_remotehost has less than 0 users! Something is Really WRONG!\n"; 104 $answer = "Server $in_remotehost has less than 0 users! Something is Really WRONG!\n";
105 } 105 }
106 106
107 print ClientSocket "quit\n"; 107 print $ClientSocket "quit\n";
108 print $answer; 108 print $answer;
109 exit $ERRORS{$state}; 109 exit $ERRORS{$state};
110} 110}
@@ -112,7 +112,7 @@ sub connection ($$$$)
112# ------------------------------------------------------------[ print_usage ]-- 112# ------------------------------------------------------------[ print_usage ]--
113 113
114sub print_usage () { 114sub print_usage () {
115 print "Usage: $PROGNAME -H <host> [-w <warn>] [-c <crit>] [-p <port>]\n"; 115 print "Usage: $PROGNAME -H <host> [-w <warn>] [-c <crit>] [-p <port>] [ -4|-6 ]\n";
116} 116}
117 117
118# -------------------------------------------------------------[ print_help ]-- 118# -------------------------------------------------------------[ print_help ]--
@@ -135,33 +135,15 @@ Perl Check IRCD plugin for monitoring
135 Number of connected users which generates a critical state (Default: 100) 135 Number of connected users which generates a critical state (Default: 100)
136-p, --port=INTEGER 136-p, --port=INTEGER
137 Port that the ircd daemon is running on <host> (Default: 6667) 137 Port that the ircd daemon is running on <host> (Default: 6667)
138-4, --use-ipv4
139 Use IPv4 connection
140-6, --use-ipv6
141 Use IPv6 connection
138-v, --verbose 142-v, --verbose
139 Print extra debugging information 143 Print extra debugging information
140"; 144";
141} 145}
142 146
143# -------------------------------------------------------------[ bindRemote ]--
144
145sub bindRemote ($$)
146{
147 my ($in_remotehost, $in_remoteport) = @_;
148 my $proto = getprotobyname('tcp');
149 my $that;
150 my ($name, $aliases,$type,$len,$thataddr) = gethostbyname($in_remotehost);
151
152 if (!socket(ClientSocket,AF_INET, SOCK_STREAM, $proto)) {
153 print "IRCD UNKNOWN: Could not start socket ($!)\n";
154 exit $ERRORS{"UNKNOWN"};
155 }
156 $that = pack_sockaddr_in ($in_remoteport, $thataddr);
157 if (!connect(ClientSocket, $that)) {
158 print "IRCD UNKNOWN: Could not connect socket ($!)\n";
159 exit $ERRORS{"UNKNOWN"};
160 }
161 select(ClientSocket); $| = 1; select(STDOUT);
162 return \*ClientSocket;
163}
164
165# ===================================================================[ MAIN ]== 147# ===================================================================[ MAIN ]==
166 148
167MAIN: 149MAIN:
@@ -177,6 +159,8 @@ MAIN:
177 "w=i" => \$opt_w, "warning=i" => \$opt_w, 159 "w=i" => \$opt_w, "warning=i" => \$opt_w,
178 "c=i" => \$opt_c, "critical=i" => \$opt_c, 160 "c=i" => \$opt_c, "critical=i" => \$opt_c,
179 "p=i" => \$opt_p, "port=i" => \$opt_p, 161 "p=i" => \$opt_p, "port=i" => \$opt_p,
162 "4" => \$opt_4, "use-ipv4" => \$opt_4,
163 "6" => \$opt_6, "use-ipv6" => \$opt_6,
180 "H=s" => \$opt_H, "hostname=s" => \$opt_H); 164 "H=s" => \$opt_H, "hostname=s" => \$opt_H);
181 165
182 if ($opt_V) { 166 if ($opt_V) {
@@ -187,7 +171,7 @@ MAIN:
187 if ($opt_h) {print_help(); exit $ERRORS{'UNKNOWN'};} 171 if ($opt_h) {print_help(); exit $ERRORS{'UNKNOWN'};}
188 172
189 ($opt_H) || ($opt_H = shift @ARGV) || usage("Host name/address not specified\n"); 173 ($opt_H) || ($opt_H = shift @ARGV) || usage("Host name/address not specified\n");
190 my $remotehost = $1 if ($opt_H =~ /([-.A-Za-z0-9]+)/); 174 my $remotehost = $1 if ($opt_H =~ /([-.:%A-Za-z0-9]+)/);
191 ($remotehost) || usage("Invalid host: $opt_H\n"); 175 ($remotehost) || usage("Invalid host: $opt_H\n");
192 176
193 ($opt_w) || ($opt_w = shift @ARGV) || ($opt_w = 50); 177 ($opt_w) || ($opt_w = shift @ARGV) || ($opt_w = 50);
@@ -212,21 +196,28 @@ MAIN:
212 196
213 alarm($TIMEOUT); 197 alarm($TIMEOUT);
214 198
215 my ($name, $alias, $proto) = getprotobyname('tcp');
216
217 print "MAIN(debug): binding to remote host: $remotehost -> $remoteport\n" if $verbose; 199 print "MAIN(debug): binding to remote host: $remotehost -> $remoteport\n" if $verbose;
218 my $ClientSocket = &bindRemote($remotehost,$remoteport); 200 $ClientSocket = IO::Socket::IP->new(
201 PeerHost => $remotehost,
202 PeerService => $remoteport,
203 Family => $opt_4 ? AF_INET : $opt_6 ? AF_INET6 : undef,
204 Type => SOCK_STREAM,
205 );
206 if (!$ClientSocket) {
207 print "IRCD UNKNOWN: Could not start socket ($!)\n";
208 exit $ERRORS{"UNKNOWN"};
209 }
219 210
220 print ClientSocket "NICK $NICK\nUSER $USER_INFO\n"; 211 print $ClientSocket "NICK $NICK\nUSER $USER_INFO\n";
221 212
222 while (<ClientSocket>) { 213 while (<$ClientSocket>) {
223 print "MAIN(debug): default var = $_\n" if $verbose; 214 print "MAIN(debug): default var = $_\n" if $verbose;
224 215
225 # DALnet,LagNet,UnderNet etc. Require this! 216 # DALnet,LagNet,UnderNet etc. Require this!
226 # Replies with a PONG when presented with a PING query. 217 # Replies with a PONG when presented with a PING query.
227 # If a server doesn't require it, it will be ignored. 218 # If a server doesn't require it, it will be ignored.
228 219
229 if (m/^PING (.*)/) {print ClientSocket "PONG $1\n";} 220 if (m/^PING (.*)/) {print $ClientSocket "PONG $1\n";}
230 221
231 alarm(0); 222 alarm(0);
232 223