summaryrefslogtreecommitdiffstats
path: root/plugins-scripts/check_ircd.pl
diff options
context:
space:
mode:
Diffstat (limited to 'plugins-scripts/check_ircd.pl')
-rwxr-xr-xplugins-scripts/check_ircd.pl63
1 files changed, 26 insertions, 37 deletions
diff --git a/plugins-scripts/check_ircd.pl b/plugins-scripts/check_ircd.pl
index 84f2022..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,35 +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 $sockaddr;
150 my $that;
151 my ($name, $aliases,$type,$len,$thataddr) = gethostbyname($in_remotehost);
152
153 if (!socket(ClientSocket,AF_INET, SOCK_STREAM, $proto)) {
154 print "IRCD UNKNOWN: Could not start socket ($!)\n";
155 exit $ERRORS{"UNKNOWN"};
156 }
157 $sockaddr = 'S n a4 x8';
158 $that = pack($sockaddr, AF_INET, $in_remoteport, $thataddr);
159 if (!connect(ClientSocket, $that)) {
160 print "IRCD UNKNOWN: Could not connect socket ($!)\n";
161 exit $ERRORS{"UNKNOWN"};
162 }
163 select(ClientSocket); $| = 1; select(STDOUT);
164 return \*ClientSocket;
165}
166
167# ===================================================================[ MAIN ]== 147# ===================================================================[ MAIN ]==
168 148
169MAIN: 149MAIN:
@@ -179,6 +159,8 @@ MAIN:
179 "w=i" => \$opt_w, "warning=i" => \$opt_w, 159 "w=i" => \$opt_w, "warning=i" => \$opt_w,
180 "c=i" => \$opt_c, "critical=i" => \$opt_c, 160 "c=i" => \$opt_c, "critical=i" => \$opt_c,
181 "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,
182 "H=s" => \$opt_H, "hostname=s" => \$opt_H); 164 "H=s" => \$opt_H, "hostname=s" => \$opt_H);
183 165
184 if ($opt_V) { 166 if ($opt_V) {
@@ -189,7 +171,7 @@ MAIN:
189 if ($opt_h) {print_help(); exit $ERRORS{'UNKNOWN'};} 171 if ($opt_h) {print_help(); exit $ERRORS{'UNKNOWN'};}
190 172
191 ($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");
192 my $remotehost = $1 if ($opt_H =~ /([-.A-Za-z0-9]+)/); 174 my $remotehost = $1 if ($opt_H =~ /([-.:%A-Za-z0-9]+)/);
193 ($remotehost) || usage("Invalid host: $opt_H\n"); 175 ($remotehost) || usage("Invalid host: $opt_H\n");
194 176
195 ($opt_w) || ($opt_w = shift @ARGV) || ($opt_w = 50); 177 ($opt_w) || ($opt_w = shift @ARGV) || ($opt_w = 50);
@@ -214,21 +196,28 @@ MAIN:
214 196
215 alarm($TIMEOUT); 197 alarm($TIMEOUT);
216 198
217 my ($name, $alias, $proto) = getprotobyname('tcp');
218
219 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;
220 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 }
221 210
222 print ClientSocket "NICK $NICK\nUSER $USER_INFO\n"; 211 print $ClientSocket "NICK $NICK\nUSER $USER_INFO\n";
223 212
224 while (<ClientSocket>) { 213 while (<$ClientSocket>) {
225 print "MAIN(debug): default var = $_\n" if $verbose; 214 print "MAIN(debug): default var = $_\n" if $verbose;
226 215
227 # DALnet,LagNet,UnderNet etc. Require this! 216 # DALnet,LagNet,UnderNet etc. Require this!
228 # Replies with a PONG when presented with a PING query. 217 # Replies with a PONG when presented with a PING query.
229 # If a server doesn't require it, it will be ignored. 218 # If a server doesn't require it, it will be ignored.
230 219
231 if (m/^PING (.*)/) {print ClientSocket "PONG $1\n";} 220 if (m/^PING (.*)/) {print $ClientSocket "PONG $1\n";}
232 221
233 alarm(0); 222 alarm(0);
234 223