summaryrefslogtreecommitdiffstats
path: root/plugins-scripts/check_ircd.pl
diff options
context:
space:
mode:
authorEthan Galstad <egalstad@users.sourceforge.net>2002-02-28 06:42:51 +0000
committerEthan Galstad <egalstad@users.sourceforge.net>2002-02-28 06:42:51 +0000
commit44a321cb8a42d6c0ea2d96a1086a17f2134c89cc (patch)
treea1a4d9f7b92412a17ab08f34f04eec45433048b7 /plugins-scripts/check_ircd.pl
parent54fd5d7022ff2d6a59bc52b8869182f3fc77a058 (diff)
downloadmonitoring-plugins-44a321cb8a42d6c0ea2d96a1086a17f2134c89cc.tar.gz
Initial revision
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins-scripts/check_ircd.pl')
-rwxr-xr-xplugins-scripts/check_ircd.pl257
1 files changed, 257 insertions, 0 deletions
diff --git a/plugins-scripts/check_ircd.pl b/plugins-scripts/check_ircd.pl
new file mode 100755
index 00000000..e4c4bd02
--- /dev/null
+++ b/plugins-scripts/check_ircd.pl
@@ -0,0 +1,257 @@
1#!/usr/bin/perl -wT
2
3# -----------------------------------------------------------------------------
4# File Name: check_ircd.pl
5#
6# Author: Richard Mayhew - South Africa
7#
8# Date: 1999/09/20
9#
10# $Id$
11#
12# Description: This script will check to see if an IRCD is running
13# about how many users it has
14#
15# Email: netsaint@splash.co.za
16#
17# -----------------------------------------------------------------------------
18# Copyright 1999 (c) Richard Mayhew
19#
20# Credits go to Ethan Galstad for coding Nagios
21#
22# If any changes are made to this script, please mail me a copy of the
23# changes :)
24#
25# Some code taken from Charlie Cook (check_disk.pl)
26#
27# License GPL
28#
29# -----------------------------------------------------------------------------
30# Date Author Reason
31# ---- ------ ------
32#
33# 1999/09/20 RM Creation
34#
35# 1999/09/20 TP Changed script to use strict, more secure by
36# specifying $ENV variables. The bind command is
37# still insecure through. Did most of my work
38# with perl -wT and 'use strict'
39#
40# test using check_ircd.pl (irc-2.mit.edu|irc.erols.com|irc.core.com)
41#
42# ------------------------------------------------------------------[ Begin ]--
43
44BEGIN {
45 if ($0 =~ m/^(.*?)[\/\\]([^\/\\]+)$/) {
46 $runtimedir = $1;
47 $PROGNAME = $2;
48 }
49}
50
51# ----------------------------------------------------------------[ Require ]--
52
53require 5.004;
54
55# -------------------------------------------------------------------[ Uses ]--
56
57use Socket;
58use strict;
59use Getopt::Long;
60use vars qw($opt_V $opt_h $opt_t $opt_p $opt_H $opt_w $opt_c $verbose);
61use vars qw($PROGNAME);
62use lib $main::runtimedir;
63use utils qw($TIMEOUT %ERRORS &print_revision &support &usage);
64
65# ----------------------------------------------------[ Function Prototypes ]--
66
67sub print_help ();
68sub print_usage ();
69sub connection ($$$$);
70sub bindRemote ($$$);
71
72# -------------------------------------------------------------[ Enviroment ]--
73
74$ENV{PATH} = "";
75$ENV{ENV} = "";
76$ENV{BASH_ENV} = "";
77
78# -----------------------------------------------------------------[ Global ]--
79
80my $NICK="ircd$$";
81my $USER_INFO="monitor localhost localhost : ";
82
83# -------------------------------------------------------------[ connection ]--
84sub connection ($$$$)
85{
86 my ($in_remotehost,$in_users,$in_warn,$in_crit) = @_;
87 my $state;
88 my $answer;
89
90 print "connection(debug): users = $in_users\n" if $verbose;
91 $in_users =~ s/\ //g;
92
93 if ($in_users >= 0) {
94
95 if ($in_users > $in_crit) {
96 $state = "CRITICAL";
97 $answer = "Critical Number Of Clients Connected : $in_users (Limit = $in_crit)\n";
98
99 } elsif ($in_users > $in_warn) {
100 $state = "WARNING";
101 $answer = "Warning Number Of Clients Connected : $in_users (Limit = $in_warn)\n";
102
103 } else {
104 $state = "OK";
105 $answer = "IRCD ok - Current Local Users: $in_users\n";
106 }
107
108 } else {
109 $state = "UNKNOWN";
110 $answer = "Server $in_remotehost has less than 0 users! Something is Really WRONG!\n";
111 }
112
113 print ClientSocket "quit\n";
114 print $answer;
115 exit $ERRORS{$state};
116}
117
118# ------------------------------------------------------------[ print_usage ]--
119
120sub print_usage () {
121 print "Usage: $PROGNAME -H <host> [-w <warn>] [-c <crit>] [-p <port>]\n";
122}
123
124# -------------------------------------------------------------[ print_help ]--
125
126sub print_help ()
127{
128 print_revision($PROGNAME,'$Revision$ ');
129 print "Copyright (c) 2000 Richard Mayhew/Karl DeBisschop
130
131Perl Check IRCD plugin for Nagios
132
133";
134 print_usage();
135 print "
136-H, --hostname=HOST
137 Name or IP address of host to check
138-w, --warning=INTEGER
139 Number of connected users which generates a warning state (Default: 50)
140-c, --critical=INTEGER
141 Number of connected users which generates a critical state (Default: 100)
142-p, --port=INTEGER
143 Port that the ircd daemon is running on <host> (Default: 6667)
144-v, --verbose
145 Print extra debugging information
146";
147}
148
149# -------------------------------------------------------------[ bindRemote ]--
150
151sub bindRemote ($$$)
152{
153 my ($in_remotehost, $in_remoteport, $in_hostname) = @_;
154 my $proto = getprotobyname('tcp');
155 my $sockaddr;
156 my $this;
157 my $thisaddr = gethostbyname($in_hostname);
158 my $that;
159 my ($name, $aliases,$type,$len,$thataddr) = gethostbyname($in_remotehost);
160# ($name,$aliases,$type,$len,$thisaddr) = gethostbyname($in_hostname);
161
162 if (!socket(ClientSocket,AF_INET, SOCK_STREAM, $proto)) {
163 print "IRCD UNKNOWN: Could not start socket ($!)\n";
164 exit $ERRORS{"UNKNOWN"};
165 }
166 $sockaddr = 'S n a4 x8';
167 $this = pack($sockaddr, AF_INET, 0, $thisaddr);
168 $that = pack($sockaddr, AF_INET, $in_remoteport, $thataddr);
169 if (!bind(ClientSocket, $this)) {
170 print "IRCD UNKNOWN: Could not bind socket ($!)\n";
171 exit $ERRORS{"UNKNOWN"};
172 }
173 if (!connect(ClientSocket, $that)) {
174 print "IRCD UNKNOWN: Could not connect socket ($!)\n";
175 exit $ERRORS{"UNKNOWN"};
176 }
177 select(ClientSocket); $| = 1; select(STDOUT);
178 return \*ClientSocket;
179}
180
181# ===================================================================[ MAIN ]==
182
183MAIN:
184{
185 my $hostname;
186
187 Getopt::Long::Configure('bundling');
188 GetOptions
189 ("V" => \$opt_V, "version" => \$opt_V,
190 "h" => \$opt_h, "help" => \$opt_h,
191 "v" => \$verbose,"verbose" => \$verbose,
192 "t=i" => \$opt_t, "timeout=i" => \$opt_t,
193 "w=i" => \$opt_w, "warning=i" => \$opt_w,
194 "c=i" => \$opt_c, "critical=i" => \$opt_c,
195 "p=i" => \$opt_p, "port=i" => \$opt_p,
196 "H=s" => \$opt_H, "hostname=s" => \$opt_H);
197
198 if ($opt_V) {
199 print_revision($PROGNAME,'$Revision$ ');
200 exit $ERRORS{'OK'};
201 }
202
203 if ($opt_h) {print_help(); exit $ERRORS{'OK'};}
204
205 ($opt_H) || ($opt_H = shift) || usage("Host name/address not specified\n");
206 my $remotehost = $1 if ($opt_H =~ /([-.A-Za-z0-9]+)/);
207 ($remotehost) || usage("Invalid host: $opt_H\n");
208
209 ($opt_w) || ($opt_w = shift) || ($opt_w = 50);
210 my $warn = $1 if ($opt_w =~ /^([0-9]+)$/);
211 ($warn) || usage("Invalid warning threshold: $opt_w\n");
212
213 ($opt_c) || ($opt_c = shift) || ($opt_c = 100);
214 my $crit = $1 if ($opt_c =~ /^([0-9]+)$/);
215 ($crit) || usage("Invalid critical threshold: $opt_c\n");
216
217 ($opt_p) || ($opt_p = shift) || ($opt_p = 6667);
218 my $remoteport = $1 if ($opt_p =~ /^([0-9]+)$/);
219 ($remoteport) || usage("Invalid port: $opt_p\n");
220
221 if ($opt_t && $opt_t =~ /^([0-9]+)$/) { $TIMEOUT = $1; }
222
223 # Just in case of problems, let's not hang Nagios
224 $SIG{'ALRM'} = sub {
225 print "Somthing is Taking a Long Time, Increase Your TIMEOUT (Currently Set At $TIMEOUT Seconds)\n";
226 exit $ERRORS{"UNKNOWN"};
227 };
228
229 alarm($TIMEOUT);
230
231 chomp($hostname = `/bin/hostname`);
232 $hostname = $1 if ($hostname =~ /([-.a-zA-Z0-9]+)/);
233 my ($name, $alias, $proto) = getprotobyname('tcp');
234 print "MAIN(debug): hostname = $hostname\n" if $verbose;
235
236 print "MAIN(debug): binding to remote host: $remotehost -> $remoteport -> $hostname\n" if $verbose;
237 my $ClientSocket = &bindRemote($remotehost,$remoteport,$hostname);
238
239 print ClientSocket "NICK $NICK\nUSER $USER_INFO\n";
240
241 while (<ClientSocket>) {
242 print "MAIN(debug): default var = $_\n" if $verbose;
243
244 # DALnet,LagNet,UnderNet etc. Require this!
245 # Replies with a PONG when presented with a PING query.
246 # If a server doesn't require it, it will be ignored.
247
248 if (m/^PING (.*)/) {print ClientSocket "PONG $1\n";}
249
250 alarm(0);
251
252 # Look for pattern in IRCD Output to gather Client Connections total.
253 connection($remotehost,$1,$warn,$crit) if (m/:I have\s+(\d+)/);
254 }
255 print "IRCD UNKNOWN: Unknown error - maybe could not authenticate\n";
256 exit $ERRORS{"UNKNOWN"};
257}