summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/check_pgsql.c62
-rw-r--r--plugins/check_swap.c163
-rw-r--r--plugins/check_tcp.c44
3 files changed, 115 insertions, 154 deletions
diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c
index dea39cf..b532d68 100644
--- a/plugins/check_pgsql.c
+++ b/plugins/check_pgsql.c
@@ -23,13 +23,6 @@
23 * 23 *
24 *****************************************************************************/ 24 *****************************************************************************/
25 25
26const char *progname = "check_pgsql";
27#define REVISION "$Revision$"
28#define COPYRIGHT "1999-2001"
29#define AUTHOR "Karl DeBisschop"
30#define EMAIL "kdebisschop@users.sourceforge.net"
31#define SUMMARY "Tests to see if a PostgreSQL DBMS is accepting connections.\n"
32
33#define DEFAULT_DB "template1" 26#define DEFAULT_DB "template1"
34#define DEFAULT_HOST "127.0.0.1" 27#define DEFAULT_HOST "127.0.0.1"
35 28
@@ -65,6 +58,11 @@ int tcrit = DEFAULT_CRIT;
65 58
66PGconn *conn; 59PGconn *conn;
67/*PGresult *res;*/ 60/*PGresult *res;*/
61
62const char *progname = "check_pgsql";
63const char *revision = "$Revision$";
64const char *copyright = "1999-2003";
65const char *email = "nagiosplug-devel@lists.sourceforge.net";
68 66
69 67
70/****************************************************************************** 68/******************************************************************************
@@ -127,22 +125,18 @@ Please note that all tags must be lowercase to use the DocBook XML DTD.
127void 125void
128print_help (void) 126print_help (void)
129{ 127{
130 print_revision (progname, REVISION); 128 print_revision (progname, revision);
131 printf 129
132 ("Copyright (c) %s %s <%s>\n\n%s\n", 130 printf (_(COPYRIGHT), copyright, email);
133 COPYRIGHT, AUTHOR, EMAIL, SUMMARY); 131
132 printf (_("Test whether a PostgreSQL DBMS is accepting connections.\n\n"));
133
134 print_usage (); 134 print_usage ();
135 printf (_("\ 135
136\nOptions:\n\ 136 printf (_(HELP_VRSN));
137 -H, --hostname=ADDRESS\n\ 137
138 Host name argument for servers using host headers (use numeric\n\ 138 printf (_(HOST_PORT_46), 'P', "5432");
139 address if possible to bypass DNS lookup).\n\ 139
140 -P, --port=INTEGER\n\
141 Port number (default: %d)\n\
142 -4, --use-ipv4\n\
143 Use IPv4 connection\n\
144 -6, --use-ipv6\n\
145 Use IPv6 connection\n"), DEFAULT_PORT);
146 printf (S_("\ 140 printf (S_("\
147 -d, --database=STRING\n\ 141 -d, --database=STRING\n\
148 Database to check (default: %s)\n\ 142 Database to check (default: %s)\n\
@@ -150,22 +144,12 @@ print_help (void)
150 Login name of user\n\ 144 Login name of user\n\
151 -p, --password = STRING\n\ 145 -p, --password = STRING\n\
152 Password (BIG SECURITY ISSUE)\n\n"), DEFAULT_DB); 146 Password (BIG SECURITY ISSUE)\n\n"), DEFAULT_DB);
153 printf (S_("\nOptions:\n\ 147
154 -c, --critical=INTEGER\n\ 148 printf (_(WARN_CRIT_TO), DEFAULT_SOCKET_TIMEOUT);
155 Exit STATE_CRITICAL if connection time exceeds threshold (default: %d)\n\ 149
156 -w, --warning=INTEGER\n\ 150 printf (_(VRBS));
157 Exit STATE_WARNING if connection time exceeds threshold (default: %d)\n\ 151
158 -t, --timeout=INTEGER\n\ 152 printf (S_("\nAll parameters are optional.\n\
159 Terminate test if timeout limit is exceeded (default: %d)\n"),
160 DEFAULT_WARN, DEFAULT_CRIT, DEFAULT_TIMEOUT);
161 printf (_("\
162 -v, --verbose\n\
163 Show details for command-line debugging (Nagios may truncate output)\n\
164 -h, --help\n\
165 Print detailed help screen\n\
166 -V, --version\n\
167 Print version information\n\n"));
168 printf (S_("All parameters are optional.\n\
169\n\ 153\n\
170This plugin tests a PostgreSQL DBMS to determine whether it is active and\n\ 154This plugin tests a PostgreSQL DBMS to determine whether it is active and\n\
171accepting queries. In its current operation, it simply connects to the\n\ 155accepting queries. In its current operation, it simply connects to the\n\
@@ -290,7 +274,7 @@ process_arguments (int argc, char **argv)
290 print_help (); 274 print_help ();
291 exit (STATE_OK); 275 exit (STATE_OK);
292 case 'V': /* version */ 276 case 'V': /* version */
293 print_revision (progname, REVISION); 277 print_revision (progname, revision);
294 exit (STATE_OK); 278 exit (STATE_OK);
295 case 't': /* timeout period */ 279 case 't': /* timeout period */
296 if (!is_integer (optarg)) 280 if (!is_integer (optarg))
diff --git a/plugins/check_swap.c b/plugins/check_swap.c
index 96eacf3..5edb806 100644
--- a/plugins/check_swap.c
+++ b/plugins/check_swap.c
@@ -30,12 +30,11 @@
30#include "utils.h" 30#include "utils.h"
31 31
32const char *progname = "check_swap"; 32const char *progname = "check_swap";
33#define REVISION "$Revision$" 33const char *revision = "$Revision$";
34#define COPYRIGHT "2000-2002" 34const char *copyright = "2000-2003";
35#define AUTHOR "Karl DeBisschop" 35const char *email = "nagiosplug-devel@lists.sourceforge.net";
36#define EMAIL "kdebisschop@users.sourceforge.net"
37#define SUMMARY "Check swap space on local server.\n"
38 36
37int check_swap (int usp, int free_swap);
39int process_arguments (int argc, char **argv); 38int process_arguments (int argc, char **argv);
40int validate_arguments (void); 39int validate_arguments (void);
41void print_usage (void); 40void print_usage (void);
@@ -52,16 +51,68 @@ int allswaps;
52int sun = 0; /* defined by compiler if it is a sun solaris system */ 51int sun = 0; /* defined by compiler if it is a sun solaris system */
53#endif 52#endif
54 53
54void
55print_usage (void)
56{
57 printf (_("Usage:\n\
58 %s [-a] -w <used_percentage>%% -c <used_percentage>%%\n\
59 %s [-a] -w <bytes_free> -c <bytes_free>\n\
60 %s (-h | --help) for detailed help\n\
61 %s (-V | --version) for version information\n"),
62 progname, progname, progname, progname);
63}
64
65
66
67
68
69void
70print_help (void)
71{
72 print_revision (progname, revision);
73
74 printf (_(COPYRIGHT), copyright, email);
75
76 printf (_("Check swap space on local server.\n\n"));
77
78 print_usage ();
79
80 printf (_(HELP_VRSN));
81
82 printf (_("\n\
83 -w, --warning=INTEGER\n\
84 Exit with WARNING status if less than INTEGER bytes of swap space are free\n\
85 -w, --warning=PERCENT%%\n\
86 Exit with WARNING status if less than PERCENT of swap space has been used\n\
87 -c, --critical=INTEGER\n\
88 Exit with CRITICAL status if less than INTEGER bytes of swap space are free\n\
89 -c, --critical=PERCENT%%\n\
90 Exit with CRITCAL status if less than PERCENT of swap space has been used\n\
91 -a, --allswaps\n\
92 Conduct comparisons for all swap partitions, one by one\n"));
93
94#ifdef sun
95 printf (_("\n\
96On Solaris, if -a specified, uses swap -l, otherwise uses swap -s.\n\
97Will be discrepencies because swap -s counts allocated swap and includes\n\
98real memory\n"));
99#endif
100
101 support ();
102}
103
104
105
55int 106int
56main (int argc, char **argv) 107main (int argc, char **argv)
57{ 108{
58 int percent_used, percent; 109 int percent_used, percent;
59 long unsigned int total_swap = 0, used_swap = 0, free_swap = 0; 110 long unsigned int total_swap = 0, used_swap = 0, free_swap = 0;
60 long unsigned int total, used, free; 111 long unsigned int dsktotal, dskused, dskfree;
61 int conv_factor; /* Convert to MBs */
62 int result = STATE_OK; 112 int result = STATE_OK;
63 char input_buffer[MAX_INPUT_BUFFER]; 113 char input_buffer[MAX_INPUT_BUFFER];
64#ifdef HAVE_SWAP 114#ifdef HAVE_SWAP
115 int conv_factor; /* Convert to MBs */
65 char *temp_buffer; 116 char *temp_buffer;
66 char *swap_command; 117 char *swap_command;
67 char *swap_format; 118 char *swap_format;
@@ -78,11 +129,11 @@ main (int argc, char **argv)
78#ifdef HAVE_PROC_MEMINFO 129#ifdef HAVE_PROC_MEMINFO
79 fp = fopen (PROC_MEMINFO, "r"); 130 fp = fopen (PROC_MEMINFO, "r");
80 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) { 131 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) {
81 if (sscanf (input_buffer, " %s %lu %lu %lu", str, &total, &used, &free) == 4 && 132 if (sscanf (input_buffer, " %s %lu %lu %lu", str, &dsktotal, &dskused, &dskfree) == 4 &&
82 strstr (str, "Swap")) { 133 strstr (str, "Swap")) {
83 total = total / 1048576; 134 dsktotal = dsktotal / 1048576;
84 used = used / 1048576; 135 dskused = dskused / 1048576;
85 free = free / 1048576; 136 dskfree = dskfree / 1048576;
86#endif 137#endif
87#ifdef HAVE_SWAP 138#ifdef HAVE_SWAP
88 if (!allswaps && sun) { 139 if (!allswaps && sun) {
@@ -118,7 +169,7 @@ main (int argc, char **argv)
118 while (temp_buffer) { 169 while (temp_buffer) {
119 if (strstr (temp_buffer, "blocks")) 170 if (strstr (temp_buffer, "blocks"))
120 sprintf (str, "%s %s", str, "%f"); 171 sprintf (str, "%s %s", str, "%f");
121 else if (strstr (temp_buffer, "free")) 172 else if (strstr (temp_buffer, "dskfree"))
122 sprintf (str, "%s %s", str, "%f"); 173 sprintf (str, "%s %s", str, "%f");
123 else 174 else
124 sprintf (str, "%s %s", str, "%*s"); 175 sprintf (str, "%s %s", str, "%*s");
@@ -133,23 +184,23 @@ main (int argc, char **argv)
133 total_swap = used_swap + free_swap; 184 total_swap = used_swap + free_swap;
134 } else { 185 } else {
135 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { 186 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
136 sscanf (input_buffer, swap_format, &total, &free); 187 sscanf (input_buffer, swap_format, &dsktotal, &dskfree);
137 188
138 total = total / conv_factor; 189 dsktotal = dsktotal / conv_factor;
139 free = free / conv_factor; 190 dskfree = dskfree / conv_factor;
140 if (verbose >= 3) 191 if (verbose >= 3)
141 printf ("total=%d, free=%d\n", total, free); 192 printf ("total=%d, free=%d\n", dsktotal, dskfree);
142 193
143 used = total - free; 194 dskused = dsktotal - dskfree;
144#endif 195#endif
145 total_swap += total; 196 total_swap += dsktotal;
146 used_swap += used; 197 used_swap += dskused;
147 free_swap += free; 198 free_swap += dskfree;
148 if (allswaps) { 199 if (allswaps) {
149 percent = 100 * (((double) used) / ((double) total)); 200 percent = 100 * (((double) dskused) / ((double) dsktotal));
150 result = max_state (result, check_swap (percent, free)); 201 result = max_state (result, check_swap (percent, dskfree));
151 if (verbose) 202 if (verbose)
152 asprintf (&status, "%s [%lu (%d%%)]", status, free, 100 - percent); 203 asprintf (&status, "%s [%lu (%d%%)]", status, dskfree, 100 - percent);
153 } 204 }
154 } 205 }
155 } 206 }
@@ -175,6 +226,7 @@ main (int argc, char **argv)
175#endif 226#endif
176 227
177 terminate (result, "SWAP %s:%s\n", state_text (result), status); 228 terminate (result, "SWAP %s:%s\n", state_text (result), status);
229 return STATE_UNKNOWN;
178} 230}
179 231
180 232
@@ -186,11 +238,11 @@ check_swap (int usp, int free_swap)
186 int result = STATE_UNKNOWN; 238 int result = STATE_UNKNOWN;
187 if (usp >= 0 && usp >= (100.0 - crit_percent)) 239 if (usp >= 0 && usp >= (100.0 - crit_percent))
188 result = STATE_CRITICAL; 240 result = STATE_CRITICAL;
189 else if (crit_size >= 0 && free_swap <= crit_size) 241 else if (crit_size > 0 && (unsigned)free_swap <= crit_size)
190 result = STATE_CRITICAL; 242 result = STATE_CRITICAL;
191 else if (usp >= 0 && usp >= (100.0 - warn_percent)) 243 else if (usp >= 0 && usp >= (100.0 - warn_percent))
192 result = STATE_WARNING; 244 result = STATE_WARNING;
193 else if (warn_size >= 0 && free_swap <= warn_size) 245 else if (warn_size > 0 && (unsigned)free_swap <= warn_size)
194 result = STATE_WARNING; 246 result = STATE_WARNING;
195 else if (usp >= 0.0) 247 else if (usp >= 0.0)
196 result = STATE_OK; 248 result = STATE_OK;
@@ -270,7 +322,7 @@ process_arguments (int argc, char **argv)
270 verbose++; 322 verbose++;
271 break; 323 break;
272 case 'V': /* version */ 324 case 'V': /* version */
273 print_revision (progname, "$Revision$"); 325 print_revision (progname, revision);
274 exit (STATE_OK); 326 exit (STATE_OK);
275 case 'h': /* help */ 327 case 'h': /* help */
276 print_help (); 328 print_help ();
@@ -293,12 +345,12 @@ process_arguments (int argc, char **argv)
293 345
294 if (c == argc) 346 if (c == argc)
295 return validate_arguments (); 347 return validate_arguments ();
296 if (warn_size < 0 && is_intnonneg (argv[c])) 348 if (warn_size == 0 && is_intnonneg (argv[c]))
297 warn_size = atoi (argv[c++]); 349 warn_size = atoi (argv[c++]);
298 350
299 if (c == argc) 351 if (c == argc)
300 return validate_arguments (); 352 return validate_arguments ();
301 if (crit_size < 0 && is_intnonneg (argv[c])) 353 if (crit_size == 0 && is_intnonneg (argv[c]))
302 crit_size = atoi (argv[c++]); 354 crit_size = atoi (argv[c++]);
303 355
304 return validate_arguments (); 356 return validate_arguments ();
@@ -311,8 +363,8 @@ process_arguments (int argc, char **argv)
311int 363int
312validate_arguments (void) 364validate_arguments (void)
313{ 365{
314 if (warn_percent > 100 && crit_percent > 100 && warn_size < 0 366 if (warn_percent > 100 && crit_percent > 100 && warn_size == 0
315 && crit_size < 0) { 367 && crit_size == 0) {
316 return ERROR; 368 return ERROR;
317 } 369 }
318 else if (warn_percent < crit_percent) { 370 else if (warn_percent < crit_percent) {
@@ -325,54 +377,3 @@ validate_arguments (void)
325 } 377 }
326 return OK; 378 return OK;
327} 379}
328
329
330
331
332
333void
334print_usage (void)
335{
336 printf
337 ("Usage:\n"
338 " %s [-a] -w <used_percentage>%% -c <used_percentage>%%\n"
339 " %s [-a] -w <bytes_free> -c <bytes_free>\n"
340 " %s (-h | --help) for detailed help\n"
341 " %s (-V | --version) for version information\n",
342 progname, progname, progname, progname);
343}
344
345
346
347
348
349void
350print_help (void)
351{
352 print_revision (progname, REVISION);
353 printf
354 ("Copyright (c) %s %s <%s>\n\n%s\n", COPYRIGHT, AUTHOR, EMAIL, SUMMARY);
355 print_usage ();
356 printf
357 ("\nOptions:\n"
358 " -w, --warning=INTEGER\n"
359 " Exit with WARNING status if less than INTEGER bytes of swap space are free\n"
360 " -w, --warning=PERCENT%%\n"
361 " Exit with WARNING status if less than PERCENT of swap space has been used\n"
362 " -c, --critical=INTEGER\n"
363 " Exit with CRITICAL status if less than INTEGER bytes of swap space are free\n"
364 " -c, --critical=PERCENT%%\n"
365 " Exit with CRITCAL status if less than PERCENT of swap space has been used\n"
366 " -a, --allswaps\n"
367 " Conduct comparisons for all swap partitions, one by one\n"
368 " -h, --help\n"
369 " Print detailed help screen\n"
370 " -V, --version\n" " Print version information\n"
371#ifdef sun
372 "\nOn Solaris, if -a specified, uses swap -l, otherwise uses swap -s.\n"
373 "Will be discrepencies because swap -s counts allocated swap and includes real memory\n"
374#endif
375 "\n"
376 );
377 support ();
378}
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index 872a3cc..eb31774 100644
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
@@ -99,39 +99,26 @@ print_usage (void)
99 printf (_("\ 99 printf (_("\
100Usage: %s -H host -p port [-w <warning time>] [-c <critical time>]\n\ 100Usage: %s -H host -p port [-w <warning time>] [-c <critical time>]\n\
101 [-s <send string>] [-e <expect string>] [-q <quit string>]\n\ 101 [-s <send string>] [-e <expect string>] [-q <quit string>]\n\
102 [-m <maximum bytes>] [-d <delay>] [-t <timeout seconds>]\n\ 102 [-m <maximum bytes>] [-d <delay>] [-t <timeout seconds>]\n\
103 [-r <refuse state>] [-v] [-4|-6]\n"), progname); 103 [-r <refuse state>] [-v] [-4|-6]\n"), progname);
104 printf (" %s (-h|--help)\n", progname); 104 printf (" %s (-h|--help)\n", progname);
105 printf (" %s (-V|--version)\n", progname); 105 printf (" %s (-V|--version)\n", progname);
106} 106}
107
108void 107void
109print_help (void) 108print_help (void)
110{ 109{
111 print_revision (progname, revision); 110 print_revision (progname, revision);
112 111
113 printf (_("\ 112 printf (_(COPYRIGHT), copyright, email);
114Copyright (c) %s Nagios Plugin Development Team\n\
115\t<%s>\n\n"),
116 copyright, email);
117 113
118 printf (_("\ 114 printf (_("This plugin tests %s connections with the specified host.\n\n"),
119This plugin tests %s connections with the specified host.\n\n"),
120 SERVICE); 115 SERVICE);
121 116
122 print_usage (); 117 print_usage ();
123 118
124 printf (_("\ 119 printf (_(HELP_VRSN));
125\nOptions:\n\ 120
126 -H, --hostname=ADDRESS\n\ 121 printf (_(HOST_PORT_46), 'p', "none");
127 Host name argument for servers using host headers (use numeric\n\
128 address if possible to bypass DNS lookup).\n\
129 -p, --port=INTEGER\n\
130 Port number\n\
131 -4, --use-ipv4\n\
132 Use IPv4 connection\n\
133 -6, --use-ipv6\n\
134 Use IPv6 connection\n"));
135 122
136 printf (_("\ 123 printf (_("\
137 -s, --send=STRING\n\ 124 -s, --send=STRING\n\
@@ -147,22 +134,11 @@ This plugin tests %s connections with the specified host.\n\n"),
147 -m, --maxbytes=INTEGER\n\ 134 -m, --maxbytes=INTEGER\n\
148 Close connection once more than this number of bytes are received\n\ 135 Close connection once more than this number of bytes are received\n\
149 -d, --delay=INTEGER\n\ 136 -d, --delay=INTEGER\n\
150 Seconds to wait between sending string and polling for response\n\ 137 Seconds to wait between sending string and polling for response\n"));
151 -w, --warning=DOUBLE\n\
152 Response time to result in warning status (seconds)\n\
153 -c, --critical=DOUBLE\n\
154 Response time to result in critical status (seconds)\n"));
155 138
156 printf (_("\ 139 printf (_(WARN_CRIT_TO), DEFAULT_SOCKET_TIMEOUT);
157 -t, --timeout=INTEGER\n\ 140
158 Seconds before connection times out (default: %d)\n\ 141 printf (_(VRBS));
159 -v, --verbose\n\
160 Show details for command-line debugging (Nagios may truncate output)\n\
161 -h, --help\n\
162 Print detailed help screen\n\
163 -V, --version\n\
164 Print version information\n\n"),
165 DEFAULT_SOCKET_TIMEOUT);
166 142
167 support (); 143 support ();
168} 144}