summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGES1
-rw-r--r--plugins/Makefile.am2
-rw-r--r--plugins/check_udp.c276
-rw-r--r--plugins/t/check_udp.t12
4 files changed, 8 insertions, 283 deletions
diff --git a/CHANGES b/CHANGES
index f446565..2636e99 100644
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,7 @@ This file documents the major additions and syntax changes between releases.
7 Please check at http://www.nagiosexchange.org for contributed plugins 7 Please check at http://www.nagiosexchange.org for contributed plugins
8 Major bug fixes to check_disk where values were incorrectly calculated and alerted on. 8 Major bug fixes to check_disk where values were incorrectly calculated and alerted on.
9 Perf data for warn/crit/max/min have been removed, to be readded soon. 9 Perf data for warn/crit/max/min have been removed, to be readded soon.
10 check_udp2 removed. check_udp is now linked to check_tcp.c
10 11
111.4.3 121.4.3
12 Setuid plugins (check_dhcp, check_icmp) separated into plugins-root/. Run make install as root to install 13 Setuid plugins (check_dhcp, check_icmp) separated into plugins-root/. Run make install as root to install
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 9dd7184..b84d0d7 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -20,7 +20,7 @@ libexec_PROGRAMS = check_apt check_disk check_dummy check_http check_load \
20 urlize @EXTRAS@ 20 urlize @EXTRAS@
21 21
22check_tcp_programs = check_ftp check_imap check_nntp check_pop \ 22check_tcp_programs = check_ftp check_imap check_nntp check_pop \
23 check_udp2 check_clamd @check_tcp_ssl@ 23 check_udp check_clamd @check_tcp_ssl@
24 24
25EXTRA_PROGRAMS = check_mysql check_radius check_pgsql check_snmp check_hpjd \ 25EXTRA_PROGRAMS = check_mysql check_radius check_pgsql check_snmp check_hpjd \
26 check_swap check_fping check_ldap check_game check_dig \ 26 check_swap check_fping check_ldap check_game check_dig \
diff --git a/plugins/check_udp.c b/plugins/check_udp.c
deleted file mode 100644
index a712871..0000000
--- a/plugins/check_udp.c
+++ /dev/null
@@ -1,276 +0,0 @@
1/******************************************************************************
2*
3* Nagios check_udp plugin
4*
5* License: GPL
6* Copyright (c) 1999-2006 nagios-plugins team
7*
8* Last Modified: $Date$
9*
10* Description:
11*
12* This file contains the check_udp plugin
13*
14* License Information:
15*
16* This program is free software; you can redistribute it and/or modify
17* it under the terms of the GNU General Public License as published by
18* the Free Software Foundation; either version 2 of the License, or
19* (at your option) any later version.
20*
21* This program is distributed in the hope that it will be useful,
22* but WITHOUT ANY WARRANTY; without even the implied warranty of
23* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24* GNU General Public License for more details.
25*
26* You should have received a copy of the GNU General Public License
27* along with this program; if not, write to the Free Software
28* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29*
30* $Id$
31*
32*****************************************************************************/
33
34const char *progname = "check_udp";
35const char *revision = "$Revision$";
36const char *copyright = "1999-2006";
37const char *email = "nagiosplug-devel@lists.sourceforge.net";
38
39#include "common.h"
40#include "netutils.h"
41#include "utils.h"
42
43int process_arguments (int, char **);
44void print_help (void);
45void print_usage (void);
46
47int warning_time = 0;
48int check_warning_time = FALSE;
49int critical_time = 0;
50int check_critical_time = FALSE;
51int verbose = FALSE;
52int server_port = 0;
53char *server_address = NULL;
54char *server_expect = NULL;
55char *server_send;
56
57int
58main (int argc, char **argv)
59{
60 int result = STATE_UNKNOWN;
61 char recv_buffer[MAX_INPUT_BUFFER];
62
63 setlocale (LC_ALL, "");
64 bindtextdomain (PACKAGE, LOCALEDIR);
65 textdomain (PACKAGE);
66
67 if (process_arguments (argc, argv) == ERROR)
68 usage4 (_("Could not parse arguments"));
69
70 /* initialize alarm signal handling */
71 signal (SIGALRM, socket_timeout_alarm_handler);
72
73 /* set socket timeout */
74 alarm (socket_timeout);
75
76 time (&start_time);
77 result = process_udp_request (server_address, server_port, server_send,
78 recv_buffer, MAX_INPUT_BUFFER - 1);
79
80 time (&end_time);
81
82 if (result != STATE_OK) {
83 printf (_("No response from host on port %d\n"), server_port);
84 result = STATE_CRITICAL;
85 }
86
87 else {
88
89 /* check to see if we got the response we wanted */
90 if (server_expect) {
91 if (!strstr (recv_buffer, server_expect)) {
92 printf (_("Invalid response received from host on port %d\n"),
93 server_port);
94 result = STATE_CRITICAL;
95 }
96 }
97 }
98
99 /* we connected, so close connection before exiting */
100 if (result == STATE_OK) {
101
102 if (check_critical_time == TRUE
103 && (end_time - start_time) > critical_time) result = STATE_CRITICAL;
104 else if (check_warning_time == TRUE
105 && (end_time - start_time) > warning_time) result =
106 STATE_WARNING;
107
108 printf (_("Connection %s on port %d - %d second response time\n"),
109 (result == STATE_OK) ? _("accepted") : _("problem"), server_port,
110 (int) (end_time - start_time));
111 }
112
113 /* reset the alarm */
114 alarm (0);
115
116 return result;
117}
118
119
120
121/* process command-line arguments */
122int
123process_arguments (int argc, char **argv)
124{
125 int c;
126
127 int option = 0;
128 static struct option longopts[] = {
129 {"hostname", required_argument, 0, 'H'},
130 {"critical", required_argument, 0, 'c'},
131 {"warning", required_argument, 0, 'w'},
132 {"timeout", required_argument, 0, 't'},
133 {"port", required_argument, 0, 'p'},
134 {"expect", required_argument, 0, 'e'},
135 {"send", required_argument, 0, 's'},
136 {"verbose", no_argument, 0, 'v'},
137 {"version", no_argument, 0, 'V'},
138 {"help", no_argument, 0, 'h'},
139 {0, 0, 0, 0}
140 };
141
142 if (argc < 2)
143 usage ("\n");
144
145 for (c = 1; c < argc; c++) {
146 if (strcmp ("-to", argv[c]) == 0)
147 strcpy (argv[c], "-t");
148 else if (strcmp ("-wt", argv[c]) == 0)
149 strcpy (argv[c], "-w");
150 else if (strcmp ("-ct", argv[c]) == 0)
151 strcpy (argv[c], "-c");
152 }
153
154 while (1) {
155 c = getopt_long (argc, argv, "+hVvH:e:s:c:w:t:p:", longopts, &option);
156
157 if (c == -1 || c == EOF || c == 1)
158 break;
159
160 switch (c) {
161 case '?': /* print short usage statement if args not parsable */
162 usage2 (_("Unknown argument"), optarg);
163 case 'h': /* help */
164 print_help ();
165 exit (STATE_OK);
166 case 'V': /* version */
167 print_revision (progname, revision);
168 exit (STATE_OK);
169 case 'v': /* verbose mode */
170 verbose = TRUE;
171 break;
172 case 'H': /* hostname */
173 if (is_host (optarg) == FALSE)
174 usage2 (_("Invalid hostname/address"), optarg);
175 server_address = optarg;
176 break;
177 case 'c': /* critical */
178 if (!is_intnonneg (optarg))
179 usage4 (_("Critical threshold must be a positive integer"));
180 else
181 critical_time = atoi (optarg);
182 check_critical_time = TRUE;
183 break;
184 case 'w': /* warning */
185 if (!is_intnonneg (optarg))
186 usage4 (_("Warning threshold must be a positive integer"));
187 else
188 warning_time = atoi (optarg);
189 check_warning_time = TRUE;
190 break;
191 case 't': /* timeout */
192 if (!is_intnonneg (optarg))
193 usage2 (_("Timeout interval must be a positive integer"), optarg);
194 else
195 socket_timeout = atoi (optarg);
196 break;
197 case 'p': /* port */
198 if (!is_intnonneg (optarg))
199 usage4 (_("Port must be a positive integer"));
200 else
201 server_port = atoi (optarg);
202 break;
203 case 'e': /* expect */
204 server_expect = optarg;
205 break;
206 case 's': /* send */
207 server_send = optarg;
208 break;
209 }
210 }
211
212 c = optind;
213 if (server_address == NULL && c < argc && argv[c]) {
214 if (is_host (argv[c]) == FALSE)
215 usage2 (_("Invalid hostname/address"), optarg);
216 server_address = argv[c++];
217 }
218
219 if (server_address == NULL)
220 usage4 (_("Hostname was not supplied"));
221
222 if (server_send == NULL)
223 server_send = strdup("");
224
225 return c;
226}
227
228
229
230void
231print_help (void)
232{
233 print_revision (progname, revision);
234
235 printf ("Copyright (c) 1999 Ethan Galstad\n");
236 printf (COPYRIGHT, copyright, email);
237
238 printf ("%s\n", _("This plugin tests an UDP connection with the specified host."));
239
240 printf ("\n\n");
241
242 print_usage ();
243
244 printf (_(UT_HELP_VRSN));
245
246 printf (_(UT_HOST_PORT), 'p', "none");
247
248 printf (" %s\n", "-e, --expect=STRING <optional>");
249 printf (" %s\n", _("String to expect in first line of server response"));
250 printf (" %s\n", "-s, --send=STRING <optional>");
251 printf (" %s\n", _("String to send to the server when initiating the connection"));
252
253 printf (_(UT_WARN_CRIT));
254
255 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
256
257 printf (_(UT_VERBOSE));
258
259 printf ("%s\n", _("This plugin will attempt to connect to the specified port on the host."));
260 printf (" %s\n", _("Successful connects return STATE_OK, refusals and timeouts return"));
261 printf (" %s\n", _("STATE_CRITICAL, other errors return STATE_UNKNOWN."));
262
263 printf(_(UT_SUPPORT));
264}
265
266
267/* Original Command line:
268 check_udp <host_address> [-p port] [-s send] [-e expect] \
269 [-wt warn_time] [-ct crit_time] [-to to_sec] */
270void
271print_usage (void)
272{
273 printf (_("Usage:"));
274 printf ("%s -H <host_address> [-p port] [-w warn_time] [-c crit_time]\n", progname);
275 printf (" [-e expect] [-s send] [-t to_sec] [-v]\n");
276}
diff --git a/plugins/t/check_udp.t b/plugins/t/check_udp.t
index c22aeaf..e8a1e39 100644
--- a/plugins/t/check_udp.t
+++ b/plugins/t/check_udp.t
@@ -13,19 +13,19 @@ my $res;
13 13
14plan tests => 14; 14plan tests => 14;
15 15
16$res = NPTest->testCmd( "./check_udp2 -H localhost -p 3333" ); 16$res = NPTest->testCmd( "./check_udp -H localhost -p 3333" );
17cmp_ok( $res->return_code, '==', 3, "Need send/expect string"); 17cmp_ok( $res->return_code, '==', 3, "Need send/expect string");
18like ( $res->output, '/With UDP checks, a send/expect string must be specified./', "Output OK"); 18like ( $res->output, '/With UDP checks, a send/expect string must be specified./', "Output OK");
19 19
20$res = NPTest->testCmd( "./check_udp2 -H localhost -p 3333 -s send" ); 20$res = NPTest->testCmd( "./check_udp -H localhost -p 3333 -s send" );
21cmp_ok( $res->return_code, '==', 3, "Need expect string"); 21cmp_ok( $res->return_code, '==', 3, "Need expect string");
22like ( $res->output, '/With UDP checks, a send/expect string must be specified./', "Output OK"); 22like ( $res->output, '/With UDP checks, a send/expect string must be specified./', "Output OK");
23 23
24$res = NPTest->testCmd( "./check_udp2 -H localhost -p 3333 -e expect" ); 24$res = NPTest->testCmd( "./check_udp -H localhost -p 3333 -e expect" );
25cmp_ok( $res->return_code, '==', 3, "Need send string"); 25cmp_ok( $res->return_code, '==', 3, "Need send string");
26like ( $res->output, '/With UDP checks, a send/expect string must be specified./', "Output OK"); 26like ( $res->output, '/With UDP checks, a send/expect string must be specified./', "Output OK");
27 27
28$res = NPTest->testCmd( "./check_udp2 -H localhost -p 3333 -s foo -e bar" ); 28$res = NPTest->testCmd( "./check_udp -H localhost -p 3333 -s foo -e bar" );
29cmp_ok( $res->return_code, '==', 2, "Errors correctly because no udp service running" ); 29cmp_ok( $res->return_code, '==', 2, "Errors correctly because no udp service running" );
30like ( $res->output, '/No data received from host/', "Output OK"); 30like ( $res->output, '/No data received from host/', "Output OK");
31 31
@@ -33,7 +33,7 @@ SKIP: {
33 skip "No netcat available", 6 unless (system("which nc > /dev/null") == 0); 33 skip "No netcat available", 6 unless (system("which nc > /dev/null") == 0);
34 open (NC, "echo 'barbar' | nc -l -p 3333 -u |"); 34 open (NC, "echo 'barbar' | nc -l -p 3333 -u |");
35 sleep 1; 35 sleep 1;
36 $res = NPTest->testCmd( "./check_udp2 -H localhost -p 3333 -s '' -e barbar -4" ); 36 $res = NPTest->testCmd( "./check_udp -H localhost -p 3333 -s '' -e barbar -4" );
37 cmp_ok( $res->return_code, '==', 0, "Got barbar response back" ); 37 cmp_ok( $res->return_code, '==', 0, "Got barbar response back" );
38 like ( $res->output, '/\[barbar\]/', "Output OK"); 38 like ( $res->output, '/\[barbar\]/', "Output OK");
39 close NC; 39 close NC;
@@ -44,7 +44,7 @@ SKIP: {
44 sleep 1; # Allow nc to startup 44 sleep 1; # Allow nc to startup
45 45
46 my $start = time; 46 my $start = time;
47 $res = NPTest->testCmd( "./check_udp2 -H localhost -p 3333 -s foofoo -e barbar -t 5 -4" ); 47 $res = NPTest->testCmd( "./check_udp -H localhost -p 3333 -s foofoo -e barbar -t 5 -4" );
48 my $duration = time - $start; 48 my $duration = time - $start;
49 cmp_ok( $res->return_code, '==', '2', "Hung waiting for response"); 49 cmp_ok( $res->return_code, '==', '2', "Hung waiting for response");
50 like ( $res->output, '/Socket timeout after 5 seconds/', "Timeout message"); 50 like ( $res->output, '/Socket timeout after 5 seconds/', "Timeout message");