summaryrefslogtreecommitdiffstats
path: root/plugins/check_swap.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_swap.c')
-rw-r--r--plugins/check_swap.c126
1 files changed, 64 insertions, 62 deletions
diff --git a/plugins/check_swap.c b/plugins/check_swap.c
index b92694d..a4e7e81 100644
--- a/plugins/check_swap.c
+++ b/plugins/check_swap.c
@@ -34,7 +34,7 @@ const char *revision = "$Revision$";
34const char *copyright = "2000-2003"; 34const char *copyright = "2000-2003";
35const char *email = "nagiosplug-devel@lists.sourceforge.net"; 35const char *email = "nagiosplug-devel@lists.sourceforge.net";
36 36
37int check_swap (int usp, int free_swap); 37int check_swap (int usp, long unsigned int free_swap);
38int process_arguments (int argc, char **argv); 38int process_arguments (int argc, char **argv);
39int validate_arguments (void); 39int validate_arguments (void);
40void print_usage (void); 40void print_usage (void);
@@ -51,58 +51,6 @@ int allswaps;
51int 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 */
52#endif 52#endif
53 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 (_(UT_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
106int 54int
107main (int argc, char **argv) 55main (int argc, char **argv)
108{ 56{
@@ -121,7 +69,9 @@ main (int argc, char **argv)
121 FILE *fp; 69 FILE *fp;
122#endif 70#endif
123 char str[32]; 71 char str[32];
124 char *status = ""; 72 char *status;
73
74 status = strdup("");
125 75
126 if (process_arguments (argc, argv) != OK) 76 if (process_arguments (argc, argv) != OK)
127 usage (_("Invalid command arguments supplied\n")); 77 usage (_("Invalid command arguments supplied\n"));
@@ -233,16 +183,16 @@ main (int argc, char **argv)
233 183
234 184
235int 185int
236check_swap (int usp, int free_swap) 186check_swap (int usp, long unsigned int free_swap)
237{ 187{
238 int result = STATE_UNKNOWN; 188 int result = STATE_UNKNOWN;
239 if (usp >= 0 && usp >= (100.0 - crit_percent)) 189 if (usp >= 0 && usp >= (100.0 - crit_percent))
240 result = STATE_CRITICAL; 190 result = STATE_CRITICAL;
241 else if (crit_size > 0 && (unsigned)free_swap <= crit_size) 191 else if (crit_size > 0 && free_swap <= crit_size)
242 result = STATE_CRITICAL; 192 result = STATE_CRITICAL;
243 else if (usp >= 0 && usp >= (100.0 - warn_percent)) 193 else if (usp >= 0 && usp >= (100.0 - warn_percent))
244 result = STATE_WARNING; 194 result = STATE_WARNING;
245 else if (warn_size > 0 && (unsigned)free_swap <= warn_size) 195 else if (warn_size > 0 && free_swap <= warn_size)
246 result = STATE_WARNING; 196 result = STATE_WARNING;
247 else if (usp >= 0.0) 197 else if (usp >= 0.0)
248 result = STATE_OK; 198 result = STATE_OK;
@@ -258,8 +208,8 @@ process_arguments (int argc, char **argv)
258 int wc = 0; /* warning counter */ 208 int wc = 0; /* warning counter */
259 int cc = 0; /* critical counter */ 209 int cc = 0; /* critical counter */
260 210
261 int option_index = 0; 211 int option = 0;
262 static struct option long_options[] = { 212 static struct option longopts[] = {
263 {"warning", required_argument, 0, 'w'}, 213 {"warning", required_argument, 0, 'w'},
264 {"critical", required_argument, 0, 'c'}, 214 {"critical", required_argument, 0, 'c'},
265 {"allswaps", no_argument, 0, 'a'}, 215 {"allswaps", no_argument, 0, 'a'},
@@ -273,7 +223,7 @@ process_arguments (int argc, char **argv)
273 return ERROR; 223 return ERROR;
274 224
275 while (1) { 225 while (1) {
276 c = getopt_long (argc, argv, "+?Vvhac:w:", long_options, &option_index); 226 c = getopt_long (argc, argv, "+?Vvhac:w:", longopts, &option);
277 227
278 if (c == -1 || c == EOF) 228 if (c == -1 || c == EOF)
279 break; 229 break;
@@ -296,7 +246,6 @@ process_arguments (int argc, char **argv)
296 else { 246 else {
297 usage (_("Warning threshold must be integer or percentage!\n")); 247 usage (_("Warning threshold must be integer or percentage!\n"));
298 } 248 }
299 wc++;
300 case 'c': /* critical time threshold */ 249 case 'c': /* critical time threshold */
301 if (is_intnonneg (optarg)) { 250 if (is_intnonneg (optarg)) {
302 crit_size = atoi (optarg); 251 crit_size = atoi (optarg);
@@ -314,7 +263,6 @@ process_arguments (int argc, char **argv)
314 else { 263 else {
315 usage (_("Critical threshold must be integer or percentage!\n")); 264 usage (_("Critical threshold must be integer or percentage!\n"));
316 } 265 }
317 cc++;
318 case 'a': /* all swap */ 266 case 'a': /* all swap */
319 allswaps = TRUE; 267 allswaps = TRUE;
320 break; 268 break;
@@ -377,3 +325,57 @@ validate_arguments (void)
377 } 325 }
378 return OK; 326 return OK;
379} 327}
328
329
330
331
332
333
334void
335print_help (void)
336{
337 print_revision (progname, revision);
338
339 printf (_(COPYRIGHT), copyright, email);
340
341 printf (_("Check swap space on local server.\n\n"));
342
343 print_usage ();
344
345 printf (_(UT_HELP_VRSN));
346
347 printf (_("\n\
348 -w, --warning=INTEGER\n\
349 Exit with WARNING status if less than INTEGER bytes of swap space are free\n\
350 -w, --warning=PERCENT%%\n\
351 Exit with WARNING status if less than PERCENT of swap space has been used\n\
352 -c, --critical=INTEGER\n\
353 Exit with CRITICAL status if less than INTEGER bytes of swap space are free\n\
354 -c, --critical=PERCENT%%\n\
355 Exit with CRITCAL status if less than PERCENT of swap space has been used\n\
356 -a, --allswaps\n\
357 Conduct comparisons for all swap partitions, one by one\n"));
358
359#ifdef sun
360 printf (_("\n\
361On Solaris, if -a specified, uses swap -l, otherwise uses swap -s.\n\
362Will be discrepencies because swap -s counts allocated swap and includes\n\
363real memory\n"));
364#endif
365
366 printf (_(UT_SUPPORT));
367}
368
369
370
371
372void
373print_usage (void)
374{
375 printf (_("Usage:\n\
376 %s [-a] -w <used_percentage>%% -c <used_percentage>%%\n\
377 %s [-a] -w <bytes_free> -c <bytes_free>\n\
378 %s (-h | --help) for detailed help\n\
379 %s (-V | --version) for version information\n"),
380 progname, progname, progname, progname);
381}