diff options
| author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-11-13 11:50:54 +0000 |
|---|---|---|
| committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-11-13 11:50:54 +0000 |
| commit | 9e009c4b1128352c6039d25b39213fd480e9b055 (patch) | |
| tree | e1495ef4ada6f8e092e20bc474195719f1b2b4aa | |
| parent | 9728dcad931d1c442a6d8e3e6765e2d9870600d1 (diff) | |
| download | monitoring-plugins-9e009c4b1128352c6039d25b39213fd480e9b055.tar.gz | |
remove call_getopt and asprintf
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@190 f882894a-f735-0410-b71e-b25c423dba1c
| -rw-r--r-- | plugins/check_disk.c | 82 | ||||
| -rw-r--r-- | plugins/check_dns.c | 130 | ||||
| -rw-r--r-- | plugins/check_fping.c | 5 | ||||
| -rw-r--r-- | plugins/check_hpjd.c | 96 | ||||
| -rw-r--r-- | plugins/check_mrtg.c | 166 | ||||
| -rw-r--r-- | plugins/check_nwstat.c | 94 | ||||
| -rw-r--r-- | plugins/check_ping.c | 6 | ||||
| -rw-r--r-- | plugins/check_vsz.c | 33 | ||||
| -rw-r--r-- | plugins/urlize.c | 4 | ||||
| -rw-r--r-- | plugins/utils.c | 67 |
10 files changed, 243 insertions, 440 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 9ce4a324..bde95631 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
| @@ -37,9 +37,10 @@ | |||
| 37 | #include <stdarg.h> | 37 | #include <stdarg.h> |
| 38 | 38 | ||
| 39 | #define PROGNAME "check_disk" | 39 | #define PROGNAME "check_disk" |
| 40 | #define REVISION "$Revision$" | ||
| 41 | #define COPYRIGHT "2000-2002" | ||
| 40 | 42 | ||
| 41 | int process_arguments (int, char **); | 43 | int process_arguments (int, char **); |
| 42 | int call_getopt (int, char **); | ||
| 43 | int validate_arguments (void); | 44 | int validate_arguments (void); |
| 44 | int check_disk (int usp, int free_disk); | 45 | int check_disk (int usp, int free_disk); |
| 45 | void print_help (void); | 46 | void print_help (void); |
| @@ -49,7 +50,7 @@ int w_df = -1; | |||
| 49 | int c_df = -1; | 50 | int c_df = -1; |
| 50 | float w_dfp = -1.0; | 51 | float w_dfp = -1.0; |
| 51 | float c_dfp = -1.0; | 52 | float c_dfp = -1.0; |
| 52 | char *path = NULL; | 53 | char *path = ""; |
| 53 | int verbose = FALSE; | 54 | int verbose = FALSE; |
| 54 | int display_mntp = FALSE; | 55 | int display_mntp = FALSE; |
| 55 | 56 | ||
| @@ -73,7 +74,7 @@ main (int argc, char **argv) | |||
| 73 | if (process_arguments (argc, argv) != OK) | 74 | if (process_arguments (argc, argv) != OK) |
| 74 | usage ("Could not parse arguments\n"); | 75 | usage ("Could not parse arguments\n"); |
| 75 | 76 | ||
| 76 | command_line = ssprintf (command_line, "%s %s", DF_COMMAND, path); | 77 | asprintf (&command_line, "%s %s", DF_COMMAND, path); |
| 77 | 78 | ||
| 78 | if (verbose) | 79 | if (verbose) |
| 79 | printf ("%s ==> ", command_line); | 80 | printf ("%s ==> ", command_line); |
| @@ -175,41 +176,6 @@ process_arguments (int argc, char **argv) | |||
| 175 | { | 176 | { |
| 176 | int c; | 177 | int c; |
| 177 | 178 | ||
| 178 | if (argc < 2) | ||
| 179 | return ERROR; | ||
| 180 | |||
| 181 | for (c = 1; c < argc; c++) { | ||
| 182 | if (strcmp ("-to", argv[c]) == 0) { | ||
| 183 | strcpy (argv[c], "-t"); | ||
| 184 | } | ||
| 185 | } | ||
| 186 | |||
| 187 | c = 0; | ||
| 188 | while ((c += (call_getopt (argc - c, &argv[c]))) < argc) { | ||
| 189 | |||
| 190 | if (w_dfp == -1 && is_intnonneg (argv[c])) | ||
| 191 | w_dfp = (100.0 - atof (argv[c])); | ||
| 192 | else if (c_dfp == -1 && is_intnonneg (argv[c])) | ||
| 193 | c_dfp = (100.0 - atof (argv[c])); | ||
| 194 | else if (path == NULL || path[0] == 0) | ||
| 195 | path = strscpy (path, argv[c]); | ||
| 196 | } | ||
| 197 | |||
| 198 | if (path == NULL) { | ||
| 199 | path = malloc (1); | ||
| 200 | if (path == NULL) | ||
| 201 | terminate (STATE_UNKNOWN, "Could not malloc empty path\n"); | ||
| 202 | path[0] = 0; | ||
| 203 | } | ||
| 204 | |||
| 205 | return validate_arguments (); | ||
| 206 | } | ||
| 207 | |||
| 208 | int | ||
| 209 | call_getopt (int argc, char **argv) | ||
| 210 | { | ||
| 211 | int c, i = 0; | ||
| 212 | |||
| 213 | #ifdef HAVE_GETOPT_H | 179 | #ifdef HAVE_GETOPT_H |
| 214 | int option_index = 0; | 180 | int option_index = 0; |
| 215 | static struct option long_options[] = { | 181 | static struct option long_options[] = { |
| @@ -226,28 +192,25 @@ call_getopt (int argc, char **argv) | |||
| 226 | }; | 192 | }; |
| 227 | #endif | 193 | #endif |
| 228 | 194 | ||
| 195 | if (argc < 2) | ||
| 196 | return ERROR; | ||
| 197 | |||
| 198 | for (c = 1; c < argc; c++) | ||
| 199 | if (strcmp ("-to", argv[c]) == 0) | ||
| 200 | strcpy (argv[c], "-t"); | ||
| 201 | |||
| 229 | while (1) { | 202 | while (1) { |
| 230 | #ifdef HAVE_GETOPT_H | 203 | #ifdef HAVE_GETOPT_H |
| 231 | c = | 204 | c = |
| 232 | getopt_long (argc, argv, "+?Vhvt:c:w:p:m", long_options, &option_index); | 205 | getopt_long (argc, argv, "Vhvt:c:w:p:m", long_options, &option_index); |
| 233 | #else | 206 | #else |
| 234 | c = getopt (argc, argv, "+?Vhvt:c:w:p:m"); | 207 | c = getopt (argc, argv, "Vhvt:c:w:p:m"); |
| 235 | #endif | 208 | #endif |
| 236 | 209 | ||
| 237 | i++; | 210 | if (c == -1 || c == EOF) |
| 238 | |||
| 239 | if (c == -1 || c == EOF || c == 1) | ||
| 240 | break; | 211 | break; |
| 241 | 212 | ||
| 242 | switch (c) { | 213 | switch (c) { |
| 243 | case 't': | ||
| 244 | case 'c': | ||
| 245 | case 'w': | ||
| 246 | case 'p': | ||
| 247 | i++; | ||
| 248 | } | ||
| 249 | |||
| 250 | switch (c) { | ||
| 251 | case 'w': /* warning time threshold */ | 214 | case 'w': /* warning time threshold */ |
| 252 | if (is_intnonneg (optarg)) { | 215 | if (is_intnonneg (optarg)) { |
| 253 | w_df = atoi (optarg); | 216 | w_df = atoi (optarg); |
| @@ -298,7 +261,7 @@ call_getopt (int argc, char **argv) | |||
| 298 | display_mntp = TRUE; | 261 | display_mntp = TRUE; |
| 299 | break; | 262 | break; |
| 300 | case 'V': /* version */ | 263 | case 'V': /* version */ |
| 301 | print_revision (my_basename (argv[0]), "$Revision$"); | 264 | print_revision (PROGNAME, REVISION); |
| 302 | exit (STATE_OK); | 265 | exit (STATE_OK); |
| 303 | case 'h': /* help */ | 266 | case 'h': /* help */ |
| 304 | print_help (); | 267 | print_help (); |
| @@ -308,7 +271,18 @@ call_getopt (int argc, char **argv) | |||
| 308 | break; | 271 | break; |
| 309 | } | 272 | } |
| 310 | } | 273 | } |
| 311 | return i; | 274 | |
| 275 | c = optind; | ||
| 276 | if (w_dfp == -1 && argc > c && is_intnonneg (argv[c])) | ||
| 277 | w_dfp = (100.0 - atof (argv[c++])); | ||
| 278 | |||
| 279 | if (c_dfp == -1 && argc > c && is_intnonneg (argv[c])) | ||
| 280 | c_dfp = (100.0 - atof (argv[c++])); | ||
| 281 | |||
| 282 | if (argc > c && strlen (path) == 0) | ||
| 283 | path = argv[c++]; | ||
| 284 | |||
| 285 | return validate_arguments (); | ||
| 312 | } | 286 | } |
| 313 | 287 | ||
| 314 | int | 288 | int |
| @@ -358,7 +332,7 @@ check_disk (usp, free_disk) | |||
| 358 | void | 332 | void |
| 359 | print_help (void) | 333 | print_help (void) |
| 360 | { | 334 | { |
| 361 | print_revision (PROGNAME, "$Revision$"); | 335 | print_revision (PROGNAME, REVISION); |
| 362 | printf | 336 | printf |
| 363 | ("Copyright (c) 2000 Ethan Galstad/Karl DeBisschop\n\n" | 337 | ("Copyright (c) 2000 Ethan Galstad/Karl DeBisschop\n\n" |
| 364 | "This plugin will check the percent of used disk space on a mounted\n" | 338 | "This plugin will check the percent of used disk space on a mounted\n" |
diff --git a/plugins/check_dns.c b/plugins/check_dns.c index bc0400f8..f9cf2889 100644 --- a/plugins/check_dns.c +++ b/plugins/check_dns.c | |||
| @@ -48,11 +48,14 @@ | |||
| 48 | #include "popen.h" | 48 | #include "popen.h" |
| 49 | #include "utils.h" | 49 | #include "utils.h" |
| 50 | 50 | ||
| 51 | #define PROGNAME "check_dns" | ||
| 52 | #define REVISION "$Revision$" | ||
| 53 | #define COPYRIGHT "2000-2002" | ||
| 54 | |||
| 51 | int process_arguments (int, char **); | 55 | int process_arguments (int, char **); |
| 52 | int call_getopt (int, char **); | ||
| 53 | int validate_arguments (void); | 56 | int validate_arguments (void); |
| 54 | void print_usage (char *); | 57 | void print_usage (void); |
| 55 | void print_help (char *); | 58 | void print_help (void); |
| 56 | int error_scan (char *); | 59 | int error_scan (char *); |
| 57 | 60 | ||
| 58 | #define ADDRESS_LENGTH 256 | 61 | #define ADDRESS_LENGTH 256 |
| @@ -80,13 +83,12 @@ main (int argc, char **argv) | |||
| 80 | } | 83 | } |
| 81 | 84 | ||
| 82 | if (process_arguments (argc, argv) != OK) { | 85 | if (process_arguments (argc, argv) != OK) { |
| 83 | print_usage (my_basename (argv[0])); | 86 | print_usage (); |
| 84 | return STATE_UNKNOWN; | 87 | return STATE_UNKNOWN; |
| 85 | } | 88 | } |
| 86 | 89 | ||
| 87 | /* get the command to run */ | 90 | /* get the command to run */ |
| 88 | command_line = ssprintf (command_line, "%s %s %s", NSLOOKUP_COMMAND, | 91 | sprintf (&command_line, "%s %s %s", NSLOOKUP_COMMAND, query_address, dns_server); |
| 89 | query_address, dns_server); | ||
| 90 | 92 | ||
| 91 | alarm (timeout_interval); | 93 | alarm (timeout_interval); |
| 92 | time (&start_time); | 94 | time (&start_time); |
| @@ -171,7 +173,7 @@ main (int argc, char **argv) | |||
| 171 | /* compare to expected address */ | 173 | /* compare to expected address */ |
| 172 | if (result == STATE_OK && match_expected_address && strcmp(address, expected_address)) { | 174 | if (result == STATE_OK && match_expected_address && strcmp(address, expected_address)) { |
| 173 | result = STATE_CRITICAL; | 175 | result = STATE_CRITICAL; |
| 174 | output = ssprintf(output, "expected %s but got %s", expected_address, address); | 176 | asprintf(&output, "expected %s but got %s", expected_address, address); |
| 175 | } | 177 | } |
| 176 | 178 | ||
| 177 | (void) time (&end_time); | 179 | (void) time (&end_time); |
| @@ -256,46 +258,6 @@ process_arguments (int argc, char **argv) | |||
| 256 | { | 258 | { |
| 257 | int c; | 259 | int c; |
| 258 | 260 | ||
| 259 | if (argc < 2) | ||
| 260 | return ERROR; | ||
| 261 | |||
| 262 | for (c = 1; c < argc; c++) | ||
| 263 | if (strcmp ("-to", argv[c]) == 0) | ||
| 264 | strcpy (argv[c], "-t"); | ||
| 265 | |||
| 266 | c = 0; | ||
| 267 | while (c += (call_getopt (argc - c, &argv[c]))) { | ||
| 268 | if (argc <= c) | ||
| 269 | break; | ||
| 270 | if (query_address[0] == 0) { | ||
| 271 | if (is_host (argv[c]) == FALSE) { | ||
| 272 | printf ("Invalid name/address: %s\n\n", argv[c]); | ||
| 273 | return ERROR; | ||
| 274 | } | ||
| 275 | if (strlen (argv[c]) >= ADDRESS_LENGTH) | ||
| 276 | terminate (STATE_UNKNOWN, "Input buffer overflow\n"); | ||
| 277 | strcpy (query_address, argv[c]); | ||
| 278 | } | ||
| 279 | else if (dns_server[0] == 0) { | ||
| 280 | if (is_host (argv[c]) == FALSE) { | ||
| 281 | printf ("Invalid name/address: %s\n\n", argv[c]); | ||
| 282 | return ERROR; | ||
| 283 | } | ||
| 284 | if (strlen (argv[c]) >= ADDRESS_LENGTH) | ||
| 285 | terminate (STATE_UNKNOWN, "Input buffer overflow\n"); | ||
| 286 | strcpy (dns_server, argv[c]); | ||
| 287 | } | ||
| 288 | } | ||
| 289 | |||
| 290 | return validate_arguments (); | ||
| 291 | |||
| 292 | } | ||
| 293 | |||
| 294 | int | ||
| 295 | call_getopt (int argc, char **argv) | ||
| 296 | { | ||
| 297 | int c, i = 1; | ||
| 298 | |||
| 299 | #ifdef HAVE_GETOPT_H | 261 | #ifdef HAVE_GETOPT_H |
| 300 | int opt_index = 0; | 262 | int opt_index = 0; |
| 301 | static struct option long_opts[] = { | 263 | static struct option long_opts[] = { |
| @@ -311,37 +273,33 @@ call_getopt (int argc, char **argv) | |||
| 311 | }; | 273 | }; |
| 312 | #endif | 274 | #endif |
| 313 | 275 | ||
| 276 | if (argc < 2) | ||
| 277 | return ERROR; | ||
| 278 | |||
| 279 | for (c = 1; c < argc; c++) | ||
| 280 | if (strcmp ("-to", argv[c]) == 0) | ||
| 281 | strcpy (argv[c], "-t"); | ||
| 314 | 282 | ||
| 315 | while (1) { | 283 | while (1) { |
| 316 | #ifdef HAVE_GETOPT_H | 284 | #ifdef HAVE_GETOPT_H |
| 317 | c = getopt_long (argc, argv, "+?hVvt:H:s:r:a:", long_opts, &opt_index); | 285 | c = getopt_long (argc, argv, "hVvt:H:s:r:a:", long_opts, &opt_index); |
| 318 | #else | 286 | #else |
| 319 | c = getopt (argc, argv, "+?hVvt:H:s:r:a:"); | 287 | c = getopt (argc, argv, "hVvt:H:s:r:a:"); |
| 320 | #endif | 288 | #endif |
| 321 | 289 | ||
| 322 | if (c == -1 || c == EOF) | 290 | if (c == -1 || c == EOF) |
| 323 | break; | 291 | break; |
| 324 | 292 | ||
| 325 | i++; | ||
| 326 | switch (c) { | ||
| 327 | case 't': | ||
| 328 | case 'H': | ||
| 329 | case 's': | ||
| 330 | case 'r': | ||
| 331 | case 'a': | ||
| 332 | i++; | ||
| 333 | } | ||
| 334 | |||
| 335 | switch (c) { | 293 | switch (c) { |
| 336 | case '?': /* args not parsable */ | 294 | case '?': /* args not parsable */ |
| 337 | printf ("%s: Unknown argument: %s\n\n", my_basename (argv[0]), optarg); | 295 | printf ("%s: Unknown argument: %s\n\n", PROGNAME, optarg); |
| 338 | print_usage (my_basename (argv[0])); | 296 | print_usage (); |
| 339 | exit (STATE_UNKNOWN); | 297 | exit (STATE_UNKNOWN); |
| 340 | case 'h': /* help */ | 298 | case 'h': /* help */ |
| 341 | print_help (my_basename (argv[0])); | 299 | print_help (); |
| 342 | exit (STATE_OK); | 300 | exit (STATE_OK); |
| 343 | case 'V': /* version */ | 301 | case 'V': /* version */ |
| 344 | print_revision (my_basename (argv[0]), "$Revision$"); | 302 | print_revision (PROGNAME, REVISION); |
| 345 | exit (STATE_OK); | 303 | exit (STATE_OK); |
| 346 | case 'v': /* version */ | 304 | case 'v': /* version */ |
| 347 | verbose = TRUE; | 305 | verbose = TRUE; |
| @@ -352,7 +310,7 @@ call_getopt (int argc, char **argv) | |||
| 352 | case 'H': /* hostname */ | 310 | case 'H': /* hostname */ |
| 353 | if (is_host (optarg) == FALSE) { | 311 | if (is_host (optarg) == FALSE) { |
| 354 | printf ("Invalid host name/address\n\n"); | 312 | printf ("Invalid host name/address\n\n"); |
| 355 | print_usage (my_basename (argv[0])); | 313 | print_usage (); |
| 356 | exit (STATE_UNKNOWN); | 314 | exit (STATE_UNKNOWN); |
| 357 | } | 315 | } |
| 358 | if (strlen (optarg) >= ADDRESS_LENGTH) | 316 | if (strlen (optarg) >= ADDRESS_LENGTH) |
| @@ -362,7 +320,7 @@ call_getopt (int argc, char **argv) | |||
| 362 | case 's': /* server name */ | 320 | case 's': /* server name */ |
| 363 | if (is_host (optarg) == FALSE) { | 321 | if (is_host (optarg) == FALSE) { |
| 364 | printf ("Invalid server name/address\n\n"); | 322 | printf ("Invalid server name/address\n\n"); |
| 365 | print_usage (my_basename (argv[0])); | 323 | print_usage (); |
| 366 | exit (STATE_UNKNOWN); | 324 | exit (STATE_UNKNOWN); |
| 367 | } | 325 | } |
| 368 | if (strlen (optarg) >= ADDRESS_LENGTH) | 326 | if (strlen (optarg) >= ADDRESS_LENGTH) |
| @@ -372,7 +330,7 @@ call_getopt (int argc, char **argv) | |||
| 372 | case 'r': /* reverse server name */ | 330 | case 'r': /* reverse server name */ |
| 373 | if (is_host (optarg) == FALSE) { | 331 | if (is_host (optarg) == FALSE) { |
| 374 | printf ("Invalid host name/address\n\n"); | 332 | printf ("Invalid host name/address\n\n"); |
| 375 | print_usage (my_basename (argv[0])); | 333 | print_usage (); |
| 376 | exit (STATE_UNKNOWN); | 334 | exit (STATE_UNKNOWN); |
| 377 | } | 335 | } |
| 378 | if (strlen (optarg) >= ADDRESS_LENGTH) | 336 | if (strlen (optarg) >= ADDRESS_LENGTH) |
| @@ -382,7 +340,7 @@ call_getopt (int argc, char **argv) | |||
| 382 | case 'a': /* expected address */ | 340 | case 'a': /* expected address */ |
| 383 | if (is_dotted_quad (optarg) == FALSE) { | 341 | if (is_dotted_quad (optarg) == FALSE) { |
| 384 | printf ("Invalid expected address\n\n"); | 342 | printf ("Invalid expected address\n\n"); |
| 385 | print_usage (my_basename (argv[0])); | 343 | print_usage (); |
| 386 | exit (STATE_UNKNOWN); | 344 | exit (STATE_UNKNOWN); |
| 387 | } | 345 | } |
| 388 | if (strlen (optarg) >= ADDRESS_LENGTH) | 346 | if (strlen (optarg) >= ADDRESS_LENGTH) |
| @@ -392,7 +350,29 @@ call_getopt (int argc, char **argv) | |||
| 392 | break; | 350 | break; |
| 393 | } | 351 | } |
| 394 | } | 352 | } |
| 395 | return i; | 353 | |
| 354 | c = optind; | ||
| 355 | if (query_address[0] == 0) { | ||
| 356 | if (is_host (argv[c]) == FALSE) { | ||
| 357 | printf ("Invalid name/address: %s\n\n", argv[c]); | ||
| 358 | return ERROR; | ||
| 359 | } | ||
| 360 | if (strlen (argv[c]) >= ADDRESS_LENGTH) | ||
| 361 | terminate (STATE_UNKNOWN, "Input buffer overflow\n"); | ||
| 362 | strcpy (query_address, argv[c++]); | ||
| 363 | } | ||
| 364 | |||
| 365 | if (dns_server[0] == 0) { | ||
| 366 | if (is_host (argv[c]) == FALSE) { | ||
| 367 | printf ("Invalid name/address: %s\n\n", argv[c]); | ||
| 368 | return ERROR; | ||
| 369 | } | ||
| 370 | if (strlen (argv[c]) >= ADDRESS_LENGTH) | ||
| 371 | terminate (STATE_UNKNOWN, "Input buffer overflow\n"); | ||
| 372 | strcpy (dns_server, argv[c++]); | ||
| 373 | } | ||
| 374 | |||
| 375 | return validate_arguments (); | ||
| 396 | } | 376 | } |
| 397 | 377 | ||
| 398 | int | 378 | int |
| @@ -405,21 +385,21 @@ validate_arguments () | |||
| 405 | } | 385 | } |
| 406 | 386 | ||
| 407 | void | 387 | void |
| 408 | print_usage (char *cmd) | 388 | print_usage (void) |
| 409 | { | 389 | { |
| 410 | printf ("Usage: %s -H host [-s server] [-a expected-address] [-t timeout]\n" " %s --help\n" | 390 | printf ("Usage: %s -H host [-s server] [-a expected-address] [-t timeout]\n" " %s --help\n" |
| 411 | " %s --version\n", cmd, cmd, cmd); | 391 | " %s --version\n", PROGNAME, PROGNAME, PROGNAME); |
| 412 | } | 392 | } |
| 413 | 393 | ||
| 414 | void | 394 | void |
| 415 | print_help (char *cmd) | 395 | print_help (void) |
| 416 | { | 396 | { |
| 417 | print_revision (cmd, "$Revision$"); | 397 | print_revision (PROGNAME, REVISION); |
| 418 | printf ("Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)\n\n"); | 398 | printf ("Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)\n\n"); |
| 419 | print_usage (cmd); | 399 | print_usage (); |
| 420 | printf ("\n"); | ||
| 421 | printf | 400 | printf |
| 422 | ("-H, --hostname=HOST\n" | 401 | ("\nOptions:\n" |
| 402 | "-H, --hostname=HOST\n" | ||
| 423 | " The name or address you want to query\n" | 403 | " The name or address you want to query\n" |
| 424 | "-s, --server=HOST\n" | 404 | "-s, --server=HOST\n" |
| 425 | " Optional DNS server you want to use for the lookup\n" | 405 | " Optional DNS server you want to use for the lookup\n" |
diff --git a/plugins/check_fping.c b/plugins/check_fping.c index 9a2dd557..da11e678 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c | |||
| @@ -71,9 +71,8 @@ main (int argc, char **argv) | |||
| 71 | server = strscpy (server, server_name); | 71 | server = strscpy (server, server_name); |
| 72 | 72 | ||
| 73 | /* compose the command */ | 73 | /* compose the command */ |
| 74 | command_line = ssprintf | 74 | asprintf (&command_line, "%s -b %d -c %d %s", PATH_TO_FPING, |
| 75 | (command_line, "%s -b %d -c %d %s", | 75 | packet_size, packet_count, server); |
| 76 | PATH_TO_FPING, packet_size, packet_count, server); | ||
| 77 | 76 | ||
| 78 | if (verbose) | 77 | if (verbose) |
| 79 | printf ("%s\n", command_line); | 78 | printf ("%s\n", command_line); |
diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c index 6d42cd38..42b4bb54 100644 --- a/plugins/check_hpjd.c +++ b/plugins/check_hpjd.c | |||
| @@ -66,6 +66,8 @@ | |||
| 66 | #include "utils.h" | 66 | #include "utils.h" |
| 67 | 67 | ||
| 68 | #define PROGNAME "check_hpjd" | 68 | #define PROGNAME "check_hpjd" |
| 69 | #define REVISION "$Revision$" | ||
| 70 | #define COPYRIGHT "2000-2002" | ||
| 69 | 71 | ||
| 70 | #define HPJD_LINE_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.1" | 72 | #define HPJD_LINE_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.1" |
| 71 | #define HPJD_PAPER_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.2" | 73 | #define HPJD_PAPER_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.2" |
| @@ -84,13 +86,13 @@ | |||
| 84 | #define OFFLINE 1 | 86 | #define OFFLINE 1 |
| 85 | 87 | ||
| 86 | int process_arguments (int, char **); | 88 | int process_arguments (int, char **); |
| 87 | int call_getopt (int, char **); | ||
| 88 | int validate_arguments (void); | 89 | int validate_arguments (void); |
| 89 | void print_help (void); | 90 | void print_help (void); |
| 90 | void print_usage (void); | 91 | void print_usage (void); |
| 91 | 92 | ||
| 92 | char *community = NULL; | 93 | char *community = NULL; |
| 93 | char *address = NULL; | 94 | char *address = "127.0.0.1"; |
| 95 | |||
| 94 | 96 | ||
| 95 | int | 97 | int |
| 96 | main (int argc, char **argv) | 98 | main (int argc, char **argv) |
| @@ -386,55 +388,6 @@ process_arguments (int argc, char **argv) | |||
| 386 | { | 388 | { |
| 387 | int c; | 389 | int c; |
| 388 | 390 | ||
| 389 | if (argc < 2) | ||
| 390 | return ERROR; | ||
| 391 | |||
| 392 | for (c = 1; c < argc; c++) { | ||
| 393 | if (strcmp ("-to", argv[c]) == 0) | ||
| 394 | strcpy (argv[c], "-t"); | ||
| 395 | else if (strcmp ("-wt", argv[c]) == 0) | ||
| 396 | strcpy (argv[c], "-w"); | ||
| 397 | else if (strcmp ("-ct", argv[c]) == 0) | ||
| 398 | strcpy (argv[c], "-c"); | ||
| 399 | } | ||
| 400 | |||
| 401 | |||
| 402 | |||
| 403 | c = 0; | ||
| 404 | while ((c += (call_getopt (argc - c, &argv[c]))) < argc) { | ||
| 405 | |||
| 406 | if (is_option (argv[c])) | ||
| 407 | continue; | ||
| 408 | |||
| 409 | if (address == NULL) { | ||
| 410 | if (is_host (argv[c])) { | ||
| 411 | address = argv[c]; | ||
| 412 | } | ||
| 413 | else { | ||
| 414 | usage ("Invalid host name"); | ||
| 415 | } | ||
| 416 | } | ||
| 417 | else if (community == NULL) { | ||
| 418 | community = argv[c]; | ||
| 419 | } | ||
| 420 | } | ||
| 421 | |||
| 422 | if (address == NULL) | ||
| 423 | address = strscpy (NULL, "127.0.0.1"); | ||
| 424 | |||
| 425 | return validate_arguments (); | ||
| 426 | } | ||
| 427 | |||
| 428 | |||
| 429 | |||
| 430 | |||
| 431 | |||
| 432 | |||
| 433 | int | ||
| 434 | call_getopt (int argc, char **argv) | ||
| 435 | { | ||
| 436 | int c, i = 0; | ||
| 437 | |||
| 438 | #ifdef HAVE_GETOPT_H | 391 | #ifdef HAVE_GETOPT_H |
| 439 | int option_index = 0; | 392 | int option_index = 0; |
| 440 | static struct option long_options[] = { | 393 | static struct option long_options[] = { |
| @@ -450,6 +403,18 @@ call_getopt (int argc, char **argv) | |||
| 450 | }; | 403 | }; |
| 451 | #endif | 404 | #endif |
| 452 | 405 | ||
| 406 | if (argc < 2) | ||
| 407 | return ERROR; | ||
| 408 | |||
| 409 | for (c = 1; c < argc; c++) { | ||
| 410 | if (strcmp ("-to", argv[c]) == 0) | ||
| 411 | strcpy (argv[c], "-t"); | ||
| 412 | else if (strcmp ("-wt", argv[c]) == 0) | ||
| 413 | strcpy (argv[c], "-w"); | ||
| 414 | else if (strcmp ("-ct", argv[c]) == 0) | ||
| 415 | strcpy (argv[c], "-c"); | ||
| 416 | } | ||
| 417 | |||
| 453 | while (1) { | 418 | while (1) { |
| 454 | #ifdef HAVE_GETOPT_H | 419 | #ifdef HAVE_GETOPT_H |
| 455 | c = getopt_long (argc, argv, "+hVH:C:", long_options, &option_index); | 420 | c = getopt_long (argc, argv, "+hVH:C:", long_options, &option_index); |
| @@ -457,18 +422,10 @@ call_getopt (int argc, char **argv) | |||
| 457 | c = getopt (argc, argv, "+?hVH:C:"); | 422 | c = getopt (argc, argv, "+?hVH:C:"); |
| 458 | #endif | 423 | #endif |
| 459 | 424 | ||
| 460 | i++; | ||
| 461 | |||
| 462 | if (c == -1 || c == EOF || c == 1) | 425 | if (c == -1 || c == EOF || c == 1) |
| 463 | break; | 426 | break; |
| 464 | 427 | ||
| 465 | switch (c) { | 428 | switch (c) { |
| 466 | case 'H': | ||
| 467 | case 'C': | ||
| 468 | i++; | ||
| 469 | } | ||
| 470 | |||
| 471 | switch (c) { | ||
| 472 | case 'H': /* hostname */ | 429 | case 'H': /* hostname */ |
| 473 | if (is_host (optarg)) { | 430 | if (is_host (optarg)) { |
| 474 | address = optarg; | 431 | address = optarg; |
| @@ -481,7 +438,7 @@ call_getopt (int argc, char **argv) | |||
| 481 | community = optarg; | 438 | community = optarg; |
| 482 | break; | 439 | break; |
| 483 | case 'V': /* version */ | 440 | case 'V': /* version */ |
| 484 | print_revision (PROGNAME, "$Revision$"); | 441 | print_revision (PROGNAME, REVISION); |
| 485 | exit (STATE_OK); | 442 | exit (STATE_OK); |
| 486 | case 'h': /* help */ | 443 | case 'h': /* help */ |
| 487 | print_help (); | 444 | print_help (); |
| @@ -490,7 +447,22 @@ call_getopt (int argc, char **argv) | |||
| 490 | usage ("Invalid argument\n"); | 447 | usage ("Invalid argument\n"); |
| 491 | } | 448 | } |
| 492 | } | 449 | } |
| 493 | return i; | 450 | |
| 451 | c = optind; | ||
| 452 | if (address == NULL) { | ||
| 453 | if (is_host (argv[c])) { | ||
| 454 | address = argv[c++]; | ||
| 455 | } | ||
| 456 | else { | ||
| 457 | usage ("Invalid host name"); | ||
| 458 | } | ||
| 459 | } | ||
| 460 | |||
| 461 | if (community == NULL) { | ||
| 462 | community = argv[c++]; | ||
| 463 | } | ||
| 464 | |||
| 465 | return validate_arguments (); | ||
| 494 | } | 466 | } |
| 495 | 467 | ||
| 496 | 468 | ||
| @@ -510,7 +482,7 @@ validate_arguments (void) | |||
| 510 | void | 482 | void |
| 511 | print_help (void) | 483 | print_help (void) |
| 512 | { | 484 | { |
| 513 | print_revision (PROGNAME, "$Revision$"); | 485 | print_revision (PROGNAME, REVISION); |
| 514 | printf | 486 | printf |
| 515 | ("Copyright (c) 2000 Ethan Galstad/Karl DeBisschop\n\n" | 487 | ("Copyright (c) 2000 Ethan Galstad/Karl DeBisschop\n\n" |
| 516 | "This plugin tests the STATUS of an HP printer with a JetDirect card.\n" | 488 | "This plugin tests the STATUS of an HP printer with a JetDirect card.\n" |
diff --git a/plugins/check_mrtg.c b/plugins/check_mrtg.c index b86686d7..4d297aaa 100644 --- a/plugins/check_mrtg.c +++ b/plugins/check_mrtg.c | |||
| @@ -86,7 +86,6 @@ Notes:\n\ | |||
| 86 | #include "utils.h" | 86 | #include "utils.h" |
| 87 | 87 | ||
| 88 | int process_arguments (int, char **); | 88 | int process_arguments (int, char **); |
| 89 | int call_getopt (int, char **); | ||
| 90 | int validate_arguments (void); | 89 | int validate_arguments (void); |
| 91 | void print_help (void); | 90 | void print_help (void); |
| 92 | void print_usage (void); | 91 | void print_usage (void); |
| @@ -97,8 +96,8 @@ int use_average = TRUE; | |||
| 97 | int variable_number = -1; | 96 | int variable_number = -1; |
| 98 | unsigned long value_warning_threshold = 0L; | 97 | unsigned long value_warning_threshold = 0L; |
| 99 | unsigned long value_critical_threshold = 0L; | 98 | unsigned long value_critical_threshold = 0L; |
| 100 | char *value_label = NULL; | 99 | char *value_label = ""; |
| 101 | char *units_label = NULL; | 100 | char *units_label = ""; |
| 102 | 101 | ||
| 103 | int | 102 | int |
| 104 | main (int argc, char **argv) | 103 | main (int argc, char **argv) |
| @@ -215,83 +214,6 @@ process_arguments (int argc, char **argv) | |||
| 215 | { | 214 | { |
| 216 | int c; | 215 | int c; |
| 217 | 216 | ||
| 218 | if (argc < 2) | ||
| 219 | return ERROR; | ||
| 220 | |||
| 221 | for (c = 1; c < argc; c++) { | ||
| 222 | if (strcmp ("-to", argv[c]) == 0) | ||
| 223 | strcpy (argv[c], "-t"); | ||
| 224 | else if (strcmp ("-wt", argv[c]) == 0) | ||
| 225 | strcpy (argv[c], "-w"); | ||
| 226 | else if (strcmp ("-ct", argv[c]) == 0) | ||
| 227 | strcpy (argv[c], "-c"); | ||
| 228 | } | ||
| 229 | |||
| 230 | |||
| 231 | |||
| 232 | c = 0; | ||
| 233 | while ((c += (call_getopt (argc - c, &argv[c]))) < argc) { | ||
| 234 | |||
| 235 | if (is_option (argv[c])) | ||
| 236 | continue; | ||
| 237 | |||
| 238 | if (log_file == NULL) { | ||
| 239 | log_file = argv[c]; | ||
| 240 | } | ||
| 241 | else if (expire_minutes <= 0) { | ||
| 242 | if (is_intpos (argv[c])) | ||
| 243 | expire_minutes = atoi (argv[c]); | ||
| 244 | else | ||
| 245 | terminate (STATE_UNKNOWN, | ||
| 246 | "%s is not a valid expiration time\nUse '%s -h' for additional help\n", | ||
| 247 | argv[c], PROGNAME); | ||
| 248 | } | ||
| 249 | else if (strcmp (argv[c], "MAX") == 0) { | ||
| 250 | use_average = FALSE; | ||
| 251 | } | ||
| 252 | else if (strcmp (argv[c], "AVG") == 0) { | ||
| 253 | use_average = TRUE; | ||
| 254 | } | ||
| 255 | else if (variable_number == -1) { | ||
| 256 | variable_number = atoi (argv[c]); | ||
| 257 | if (variable_number < 1 || variable_number > 2) { | ||
| 258 | printf ("%s :", argv[c]); | ||
| 259 | usage ("Invalid variable number\n"); | ||
| 260 | } | ||
| 261 | } | ||
| 262 | else if (value_warning_threshold == 0) { | ||
| 263 | value_warning_threshold = strtoul (argv[c], NULL, 10); | ||
| 264 | } | ||
| 265 | else if (value_critical_threshold == 0) { | ||
| 266 | value_critical_threshold = strtoul (argv[c], NULL, 10); | ||
| 267 | } | ||
| 268 | else if (value_label == NULL) { | ||
| 269 | value_label = argv[c]; | ||
| 270 | } | ||
| 271 | else if (units_label == NULL) { | ||
| 272 | units_label = argv[c]; | ||
| 273 | } | ||
| 274 | } | ||
| 275 | |||
| 276 | if (value_label == NULL) | ||
| 277 | value_label = strscpy (NULL, ""); | ||
| 278 | |||
| 279 | if (units_label == NULL) | ||
| 280 | units_label = strscpy (NULL, ""); | ||
| 281 | |||
| 282 | return validate_arguments (); | ||
| 283 | } | ||
| 284 | |||
| 285 | |||
| 286 | |||
| 287 | |||
| 288 | |||
| 289 | |||
| 290 | int | ||
| 291 | call_getopt (int argc, char **argv) | ||
| 292 | { | ||
| 293 | int c, i = 0; | ||
| 294 | |||
| 295 | #ifdef HAVE_GETOPT_H | 217 | #ifdef HAVE_GETOPT_H |
| 296 | int option_index = 0; | 218 | int option_index = 0; |
| 297 | static struct option long_options[] = { | 219 | static struct option long_options[] = { |
| @@ -310,33 +232,31 @@ call_getopt (int argc, char **argv) | |||
| 310 | }; | 232 | }; |
| 311 | #endif | 233 | #endif |
| 312 | 234 | ||
| 235 | if (argc < 2) | ||
| 236 | return ERROR; | ||
| 237 | |||
| 238 | for (c = 1; c < argc; c++) { | ||
| 239 | if (strcmp ("-to", argv[c]) == 0) | ||
| 240 | strcpy (argv[c], "-t"); | ||
| 241 | else if (strcmp ("-wt", argv[c]) == 0) | ||
| 242 | strcpy (argv[c], "-w"); | ||
| 243 | else if (strcmp ("-ct", argv[c]) == 0) | ||
| 244 | strcpy (argv[c], "-c"); | ||
| 245 | } | ||
| 246 | |||
| 313 | while (1) { | 247 | while (1) { |
| 314 | #ifdef HAVE_GETOPT_H | 248 | #ifdef HAVE_GETOPT_H |
| 315 | c = | 249 | c = |
| 316 | getopt_long (argc, argv, "+hVF:e:a:v:c:w:l:u:", long_options, | 250 | getopt_long (argc, argv, "hVF:e:a:v:c:w:l:u:", long_options, |
| 317 | &option_index); | 251 | &option_index); |
| 318 | #else | 252 | #else |
| 319 | c = getopt (argc, argv, "+?hVF:e:a:v:c:w:l:u:"); | 253 | c = getopt (argc, argv, "hVF:e:a:v:c:w:l:u:"); |
| 320 | #endif | 254 | #endif |
| 321 | 255 | ||
| 322 | i++; | 256 | if (c == -1 || c == EOF) |
| 323 | |||
| 324 | if (c == -1 || c == EOF || c == 1) | ||
| 325 | break; | 257 | break; |
| 326 | 258 | ||
| 327 | switch (c) { | 259 | switch (c) { |
| 328 | case 'F': | ||
| 329 | case 'e': | ||
| 330 | case 'a': | ||
| 331 | case 'v': | ||
| 332 | case 'c': | ||
| 333 | case 'w': | ||
| 334 | case 'l': | ||
| 335 | case 'u': | ||
| 336 | i++; | ||
| 337 | } | ||
| 338 | |||
| 339 | switch (c) { | ||
| 340 | case 'F': /* input file */ | 260 | case 'F': /* input file */ |
| 341 | log_file = optarg; | 261 | log_file = optarg; |
| 342 | break; | 262 | break; |
| @@ -367,7 +287,7 @@ call_getopt (int argc, char **argv) | |||
| 367 | units_label = optarg; | 287 | units_label = optarg; |
| 368 | break; | 288 | break; |
| 369 | case 'V': /* version */ | 289 | case 'V': /* version */ |
| 370 | print_revision (PROGNAME, "$Revision$"); | 290 | print_revision (PROGNAME, REVISION); |
| 371 | exit (STATE_OK); | 291 | exit (STATE_OK); |
| 372 | case 'h': /* help */ | 292 | case 'h': /* help */ |
| 373 | print_help (); | 293 | print_help (); |
| @@ -376,7 +296,55 @@ call_getopt (int argc, char **argv) | |||
| 376 | usage ("Invalid argument\n"); | 296 | usage ("Invalid argument\n"); |
| 377 | } | 297 | } |
| 378 | } | 298 | } |
| 379 | return i; | 299 | |
| 300 | c = optind; | ||
| 301 | if (log_file == NULL && argc > c) { | ||
| 302 | log_file = argv[c++]; | ||
| 303 | } | ||
| 304 | |||
| 305 | if (expire_minutes <= 0 && argc > c) { | ||
| 306 | if (is_intpos (argv[c])) | ||
| 307 | expire_minutes = atoi (argv[c++]); | ||
| 308 | else | ||
| 309 | terminate (STATE_UNKNOWN, | ||
| 310 | "%s is not a valid expiration time\nUse '%s -h' for additional help\n", | ||
| 311 | argv[c], PROGNAME); | ||
| 312 | } | ||
| 313 | |||
| 314 | if (argc > c && strcmp (argv[c], "MAX") == 0) { | ||
| 315 | use_average = FALSE; | ||
| 316 | c++; | ||
| 317 | } | ||
| 318 | else if (argc > c && strcmp (argv[c], "AVG") == 0) { | ||
| 319 | use_average = TRUE; | ||
| 320 | c++; | ||
| 321 | } | ||
| 322 | |||
| 323 | if (argc > c && variable_number == -1) { | ||
| 324 | variable_number = atoi (argv[c++]); | ||
| 325 | if (variable_number < 1 || variable_number > 2) { | ||
| 326 | printf ("%s :", argv[c]); | ||
| 327 | usage ("Invalid variable number\n"); | ||
| 328 | } | ||
| 329 | } | ||
| 330 | |||
| 331 | if (argc > c && value_warning_threshold == 0) { | ||
| 332 | value_warning_threshold = strtoul (argv[c++], NULL, 10); | ||
| 333 | } | ||
| 334 | |||
| 335 | if (vargc > c && alue_critical_threshold == 0) { | ||
| 336 | value_critical_threshold = strtoul (argv[c++], NULL, 10); | ||
| 337 | } | ||
| 338 | |||
| 339 | if (argc > c && strlen (value_label) == 0) { | ||
| 340 | value_label = argv[c++]; | ||
| 341 | } | ||
| 342 | |||
| 343 | if (argc > c && strlen (units_label) == 0) { | ||
| 344 | units_label = argv[c++]; | ||
| 345 | } | ||
| 346 | |||
| 347 | return validate_arguments (); | ||
| 380 | } | 348 | } |
| 381 | 349 | ||
| 382 | int | 350 | int |
diff --git a/plugins/check_nwstat.c b/plugins/check_nwstat.c index e1426702..f8fca736 100644 --- a/plugins/check_nwstat.c +++ b/plugins/check_nwstat.c | |||
| @@ -180,13 +180,13 @@ int main(int argc, char **argv){ | |||
| 180 | if(result!=STATE_OK) | 180 | if(result!=STATE_OK) |
| 181 | return result; | 181 | return result; |
| 182 | if(!strcmp(recv_buffer,"-1\n")) | 182 | if(!strcmp(recv_buffer,"-1\n")) |
| 183 | netware_version = ssprintf(netware_version,""); | 183 | asprintf(&netware_version,""); |
| 184 | else { | 184 | else { |
| 185 | recv_buffer[strlen(recv_buffer)-1]=0; | 185 | recv_buffer[strlen(recv_buffer)-1]=0; |
| 186 | netware_version = ssprintf(netware_version,"NetWare %s: ",recv_buffer); | 186 | asprintf(&netware_version,"NetWare %s: ",recv_buffer); |
| 187 | } | 187 | } |
| 188 | } else | 188 | } else |
| 189 | netware_version = ssprintf(netware_version,""); | 189 | asprintf(&netware_version,""); |
| 190 | 190 | ||
| 191 | 191 | ||
| 192 | /* check CPU load */ | 192 | /* check CPU load */ |
| @@ -204,7 +204,7 @@ int main(int argc, char **argv){ | |||
| 204 | break; | 204 | break; |
| 205 | } | 205 | } |
| 206 | 206 | ||
| 207 | send_buffer = ssprintf(send_buffer,"UTIL%s\r\n",temp_buffer); | 207 | asprintf(&send_buffer,"UTIL%s\r\n",temp_buffer); |
| 208 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); | 208 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); |
| 209 | if(result!=STATE_OK) | 209 | if(result!=STATE_OK) |
| 210 | return result; | 210 | return result; |
| @@ -221,7 +221,7 @@ int main(int argc, char **argv){ | |||
| 221 | else if(check_warning_value==TRUE && utilization >= warning_value) | 221 | else if(check_warning_value==TRUE && utilization >= warning_value) |
| 222 | result=STATE_WARNING; | 222 | result=STATE_WARNING; |
| 223 | 223 | ||
| 224 | output_message = ssprintf(output_message,"Load %s - %s %s-min load average = %lu%%",(result==STATE_OK)?"ok":"problem",uptime,temp_buffer,utilization); | 224 | asprintf(&output_message,"Load %s - %s %s-min load average = %lu%%",(result==STATE_OK)?"ok":"problem",uptime,temp_buffer,utilization); |
| 225 | 225 | ||
| 226 | /* check number of user connections */ | 226 | /* check number of user connections */ |
| 227 | } else if (vars_to_check==CHECK_CONNS) { | 227 | } else if (vars_to_check==CHECK_CONNS) { |
| @@ -236,7 +236,7 @@ int main(int argc, char **argv){ | |||
| 236 | result=STATE_CRITICAL; | 236 | result=STATE_CRITICAL; |
| 237 | else if(check_warning_value==TRUE && current_connections >= warning_value) | 237 | else if(check_warning_value==TRUE && current_connections >= warning_value) |
| 238 | result=STATE_WARNING; | 238 | result=STATE_WARNING; |
| 239 | output_message = ssprintf(output_message,"Conns %s - %lu current connections",(result==STATE_OK)?"ok":"problem",current_connections); | 239 | asprintf(&output_message,"Conns %s - %lu current connections",(result==STATE_OK)?"ok":"problem",current_connections); |
| 240 | 240 | ||
| 241 | /* check % long term cache hits */ | 241 | /* check % long term cache hits */ |
| 242 | } else if (vars_to_check==CHECK_LTCH) { | 242 | } else if (vars_to_check==CHECK_LTCH) { |
| @@ -251,7 +251,7 @@ int main(int argc, char **argv){ | |||
| 251 | result=STATE_CRITICAL; | 251 | result=STATE_CRITICAL; |
| 252 | else if(check_warning_value==TRUE && cache_hits <= warning_value) | 252 | else if(check_warning_value==TRUE && cache_hits <= warning_value) |
| 253 | result=STATE_WARNING; | 253 | result=STATE_WARNING; |
| 254 | output_message = ssprintf(output_message,"Long term cache hits = %d%%",cache_hits); | 254 | asprintf(&output_message,"Long term cache hits = %d%%",cache_hits); |
| 255 | 255 | ||
| 256 | /* check cache buffers */ | 256 | /* check cache buffers */ |
| 257 | } else if (vars_to_check==CHECK_CBUFF) { | 257 | } else if (vars_to_check==CHECK_CBUFF) { |
| @@ -266,7 +266,7 @@ int main(int argc, char **argv){ | |||
| 266 | result=STATE_CRITICAL; | 266 | result=STATE_CRITICAL; |
| 267 | else if(check_warning_value==TRUE && cache_buffers <= warning_value) | 267 | else if(check_warning_value==TRUE && cache_buffers <= warning_value) |
| 268 | result=STATE_WARNING; | 268 | result=STATE_WARNING; |
| 269 | output_message = ssprintf(output_message,"Total cache buffers = %lu",cache_buffers); | 269 | asprintf(&output_message,"Total cache buffers = %lu",cache_buffers); |
| 270 | 270 | ||
| 271 | /* check dirty cache buffers */ | 271 | /* check dirty cache buffers */ |
| 272 | } else if (vars_to_check==CHECK_CDBUFF) { | 272 | } else if (vars_to_check==CHECK_CDBUFF) { |
| @@ -281,7 +281,7 @@ int main(int argc, char **argv){ | |||
| 281 | result=STATE_CRITICAL; | 281 | result=STATE_CRITICAL; |
| 282 | else if(check_warning_value==TRUE && cache_buffers >= warning_value) | 282 | else if(check_warning_value==TRUE && cache_buffers >= warning_value) |
| 283 | result=STATE_WARNING; | 283 | result=STATE_WARNING; |
| 284 | output_message = ssprintf(output_message,"Dirty cache buffers = %lu",cache_buffers); | 284 | asprintf(&output_message,"Dirty cache buffers = %lu",cache_buffers); |
| 285 | 285 | ||
| 286 | /* check LRU sitting time in minutes */ | 286 | /* check LRU sitting time in minutes */ |
| 287 | } else if (vars_to_check==CHECK_LRUM) { | 287 | } else if (vars_to_check==CHECK_LRUM) { |
| @@ -296,19 +296,19 @@ int main(int argc, char **argv){ | |||
| 296 | result=STATE_CRITICAL; | 296 | result=STATE_CRITICAL; |
| 297 | else if(check_warning_value==TRUE && lru_time <= warning_value) | 297 | else if(check_warning_value==TRUE && lru_time <= warning_value) |
| 298 | result=STATE_WARNING; | 298 | result=STATE_WARNING; |
| 299 | output_message = ssprintf(output_message,"LRU sitting time = %lu minutes",lru_time); | 299 | sprintf(&output_message,"LRU sitting time = %lu minutes",lru_time); |
| 300 | 300 | ||
| 301 | 301 | ||
| 302 | /* check KB free space on volume */ | 302 | /* check KB free space on volume */ |
| 303 | } else if (vars_to_check==CHECK_VKF) { | 303 | } else if (vars_to_check==CHECK_VKF) { |
| 304 | 304 | ||
| 305 | send_buffer = ssprintf(send_buffer,"VKF%s\r\n",volume_name); | 305 | asprintf(&send_buffer,"VKF%s\r\n",volume_name); |
| 306 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); | 306 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); |
| 307 | if(result!=STATE_OK) | 307 | if(result!=STATE_OK) |
| 308 | return result; | 308 | return result; |
| 309 | 309 | ||
| 310 | if (!strcmp(recv_buffer,"-1\n")) { | 310 | if (!strcmp(recv_buffer,"-1\n")) { |
| 311 | output_message = ssprintf(output_message,"Error: Volume '%s' does not exist!",volume_name); | 311 | asprintf(&output_message,"Error: Volume '%s' does not exist!",volume_name); |
| 312 | result=STATE_CRITICAL; | 312 | result=STATE_CRITICAL; |
| 313 | } else { | 313 | } else { |
| 314 | free_disk_space=strtoul(recv_buffer,NULL,10); | 314 | free_disk_space=strtoul(recv_buffer,NULL,10); |
| @@ -316,27 +316,27 @@ int main(int argc, char **argv){ | |||
| 316 | result=STATE_CRITICAL; | 316 | result=STATE_CRITICAL; |
| 317 | else if(check_warning_value==TRUE && free_disk_space <= warning_value) | 317 | else if(check_warning_value==TRUE && free_disk_space <= warning_value) |
| 318 | result=STATE_WARNING; | 318 | result=STATE_WARNING; |
| 319 | output_message = ssprintf(output_message,"%s%lu KB free on volume %s",(result==STATE_OK)?"":"Only ",free_disk_space,volume_name); | 319 | asprintf(&output_message,"%s%lu KB free on volume %s",(result==STATE_OK)?"":"Only ",free_disk_space,volume_name); |
| 320 | } | 320 | } |
| 321 | 321 | ||
| 322 | /* check % free space on volume */ | 322 | /* check % free space on volume */ |
| 323 | } else if (vars_to_check==CHECK_VPF) { | 323 | } else if (vars_to_check==CHECK_VPF) { |
| 324 | 324 | ||
| 325 | send_buffer = ssprintf(send_buffer,"VKF%s\r\n",volume_name); | 325 | asprintf(&send_buffer,"VKF%s\r\n",volume_name); |
| 326 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); | 326 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); |
| 327 | if(result!=STATE_OK) | 327 | if(result!=STATE_OK) |
| 328 | return result; | 328 | return result; |
| 329 | 329 | ||
| 330 | if(!strcmp(recv_buffer,"-1\n")){ | 330 | if(!strcmp(recv_buffer,"-1\n")){ |
| 331 | 331 | ||
| 332 | output_message = ssprintf(output_message,"Error: Volume '%s' does not exist!",volume_name); | 332 | asprintf(&output_message,"Error: Volume '%s' does not exist!",volume_name); |
| 333 | result=STATE_CRITICAL; | 333 | result=STATE_CRITICAL; |
| 334 | 334 | ||
| 335 | } else { | 335 | } else { |
| 336 | 336 | ||
| 337 | free_disk_space=strtoul(recv_buffer,NULL,10); | 337 | free_disk_space=strtoul(recv_buffer,NULL,10); |
| 338 | 338 | ||
| 339 | send_buffer = ssprintf(send_buffer,"VKS%s\r\n",volume_name); | 339 | asprintf(&send_buffer,"VKS%s\r\n",volume_name); |
| 340 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); | 340 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); |
| 341 | if(result!=STATE_OK) | 341 | if(result!=STATE_OK) |
| 342 | return result; | 342 | return result; |
| @@ -349,7 +349,7 @@ int main(int argc, char **argv){ | |||
| 349 | else if(check_warning_value==TRUE && percent_free_space <= warning_value) | 349 | else if(check_warning_value==TRUE && percent_free_space <= warning_value) |
| 350 | result=STATE_WARNING; | 350 | result=STATE_WARNING; |
| 351 | free_disk_space/=1024; | 351 | free_disk_space/=1024; |
| 352 | output_message = ssprintf(output_message,"%lu MB (%d%%) free on volume %s",free_disk_space,percent_free_space,volume_name); | 352 | asprintf(&output_message,"%lu MB (%d%%) free on volume %s",free_disk_space,percent_free_space,volume_name); |
| 353 | } | 353 | } |
| 354 | 354 | ||
| 355 | /* check to see if DS Database is open or closed */ | 355 | /* check to see if DS Database is open or closed */ |
| @@ -368,7 +368,7 @@ int main(int argc, char **argv){ | |||
| 368 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); | 368 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); |
| 369 | temp_buffer=strtok(recv_buffer,"\r\n"); | 369 | temp_buffer=strtok(recv_buffer,"\r\n"); |
| 370 | 370 | ||
| 371 | output_message = ssprintf(output_message,"Directory Services Database is %s (DS version %s)",(result==STATE_OK)?"open":"closed",temp_buffer); | 371 | asprintf(&output_message,"Directory Services Database is %s (DS version %s)",(result==STATE_OK)?"open":"closed",temp_buffer); |
| 372 | 372 | ||
| 373 | /* check to see if logins are enabled */ | 373 | /* check to see if logins are enabled */ |
| 374 | } else if (vars_to_check==CHECK_LOGINS) { | 374 | } else if (vars_to_check==CHECK_LOGINS) { |
| @@ -382,19 +382,19 @@ int main(int argc, char **argv){ | |||
| 382 | else | 382 | else |
| 383 | result=STATE_WARNING; | 383 | result=STATE_WARNING; |
| 384 | 384 | ||
| 385 | output_message = ssprintf(output_message,"Logins are %s",(result==STATE_OK)?"enabled":"disabled"); | 385 | asprintf(&output_message,"Logins are %s",(result==STATE_OK)?"enabled":"disabled"); |
| 386 | 386 | ||
| 387 | /* check packet receive buffers */ | 387 | /* check packet receive buffers */ |
| 388 | } else if (vars_to_check==CHECK_UPRB || vars_to_check==CHECK_PUPRB) { | 388 | } else if (vars_to_check==CHECK_UPRB || vars_to_check==CHECK_PUPRB) { |
| 389 | 389 | ||
| 390 | send_buffer = ssprintf(send_buffer,"S15\r\n",volume_name); | 390 | asprintf(&send_buffer,"S15\r\n",volume_name); |
| 391 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); | 391 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); |
| 392 | if(result!=STATE_OK) | 392 | if(result!=STATE_OK) |
| 393 | return result; | 393 | return result; |
| 394 | 394 | ||
| 395 | used_packet_receive_buffers=atoi(recv_buffer); | 395 | used_packet_receive_buffers=atoi(recv_buffer); |
| 396 | 396 | ||
| 397 | send_buffer = ssprintf(send_buffer,"S16\r\n",volume_name); | 397 | asprintf(&send_buffer,"S16\r\n",volume_name); |
| 398 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); | 398 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); |
| 399 | if(result!=STATE_OK) | 399 | if(result!=STATE_OK) |
| 400 | return result; | 400 | return result; |
| @@ -415,15 +415,15 @@ int main(int argc, char **argv){ | |||
| 415 | result=STATE_WARNING; | 415 | result=STATE_WARNING; |
| 416 | } | 416 | } |
| 417 | 417 | ||
| 418 | output_message = ssprintf(output_message,"%d of %d (%lu%%) packet receive buffers used",used_packet_receive_buffers,max_packet_receive_buffers,percent_used_packet_receive_buffers); | 418 | asprintf(&output_message,"%d of %d (%lu%%) packet receive buffers used",used_packet_receive_buffers,max_packet_receive_buffers,percent_used_packet_receive_buffers); |
| 419 | 419 | ||
| 420 | /* check SAP table entries */ | 420 | /* check SAP table entries */ |
| 421 | } else if (vars_to_check==CHECK_SAPENTRIES) { | 421 | } else if (vars_to_check==CHECK_SAPENTRIES) { |
| 422 | 422 | ||
| 423 | if(sap_number==-1) | 423 | if(sap_number==-1) |
| 424 | send_buffer = ssprintf(send_buffer,"S9\r\n"); | 424 | asprintf(&send_buffer,"S9\r\n"); |
| 425 | else | 425 | else |
| 426 | send_buffer = ssprintf(send_buffer,"S9.%d\r\n",sap_number); | 426 | asprintf(&send_buffer,"S9.%d\r\n",sap_number); |
| 427 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); | 427 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); |
| 428 | if(result!=STATE_OK) | 428 | if(result!=STATE_OK) |
| 429 | return result; | 429 | return result; |
| @@ -436,20 +436,20 @@ int main(int argc, char **argv){ | |||
| 436 | result=STATE_WARNING; | 436 | result=STATE_WARNING; |
| 437 | 437 | ||
| 438 | if(sap_number==-1) | 438 | if(sap_number==-1) |
| 439 | output_message = ssprintf(output_message,"%d entries in SAP table",sap_entries); | 439 | asprintf(&output_message,"%d entries in SAP table",sap_entries); |
| 440 | else | 440 | else |
| 441 | output_message = ssprintf(output_message,"%d entries in SAP table for SAP type %d",sap_entries,sap_number); | 441 | asprintf(&output_message,"%d entries in SAP table for SAP type %d",sap_entries,sap_number); |
| 442 | 442 | ||
| 443 | /* check KB purgeable space on volume */ | 443 | /* check KB purgeable space on volume */ |
| 444 | } else if (vars_to_check==CHECK_VKP) { | 444 | } else if (vars_to_check==CHECK_VKP) { |
| 445 | 445 | ||
| 446 | send_buffer = ssprintf(send_buffer,"VKP%s\r\n",volume_name); | 446 | asprintf(&send_buffer,"VKP%s\r\n",volume_name); |
| 447 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); | 447 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); |
| 448 | if(result!=STATE_OK) | 448 | if(result!=STATE_OK) |
| 449 | return result; | 449 | return result; |
| 450 | 450 | ||
| 451 | if (!strcmp(recv_buffer,"-1\n")) { | 451 | if (!strcmp(recv_buffer,"-1\n")) { |
| 452 | output_message = ssprintf(output_message,"Error: Volume '%s' does not exist!",volume_name); | 452 | asprintf(&output_message,"Error: Volume '%s' does not exist!",volume_name); |
| 453 | result=STATE_CRITICAL; | 453 | result=STATE_CRITICAL; |
| 454 | } else { | 454 | } else { |
| 455 | purgeable_disk_space=strtoul(recv_buffer,NULL,10); | 455 | purgeable_disk_space=strtoul(recv_buffer,NULL,10); |
| @@ -457,27 +457,27 @@ int main(int argc, char **argv){ | |||
| 457 | result=STATE_CRITICAL; | 457 | result=STATE_CRITICAL; |
| 458 | else if(check_warning_value==TRUE && purgeable_disk_space >= warning_value) | 458 | else if(check_warning_value==TRUE && purgeable_disk_space >= warning_value) |
| 459 | result=STATE_WARNING; | 459 | result=STATE_WARNING; |
| 460 | output_message = ssprintf(output_message,"%s%lu KB purgeable on volume %s",(result==STATE_OK)?"":"Only ",purgeable_disk_space,volume_name); | 460 | asprintf(&output_message,"%s%lu KB purgeable on volume %s",(result==STATE_OK)?"":"Only ",purgeable_disk_space,volume_name); |
| 461 | } | 461 | } |
| 462 | 462 | ||
| 463 | /* check % purgeable space on volume */ | 463 | /* check % purgeable space on volume */ |
| 464 | } else if (vars_to_check==CHECK_VPP) { | 464 | } else if (vars_to_check==CHECK_VPP) { |
| 465 | 465 | ||
| 466 | send_buffer = ssprintf(send_buffer,"VKP%s\r\n",volume_name); | 466 | asprintf(&send_buffer,"VKP%s\r\n",volume_name); |
| 467 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); | 467 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); |
| 468 | if(result!=STATE_OK) | 468 | if(result!=STATE_OK) |
| 469 | return result; | 469 | return result; |
| 470 | 470 | ||
| 471 | if(!strcmp(recv_buffer,"-1\n")){ | 471 | if(!strcmp(recv_buffer,"-1\n")){ |
| 472 | 472 | ||
| 473 | output_message = ssprintf(output_message,"Error: Volume '%s' does not exist!",volume_name); | 473 | asprintf(&output_message,"Error: Volume '%s' does not exist!",volume_name); |
| 474 | result=STATE_CRITICAL; | 474 | result=STATE_CRITICAL; |
| 475 | 475 | ||
| 476 | } else { | 476 | } else { |
| 477 | 477 | ||
| 478 | purgeable_disk_space=strtoul(recv_buffer,NULL,10); | 478 | purgeable_disk_space=strtoul(recv_buffer,NULL,10); |
| 479 | 479 | ||
| 480 | send_buffer = ssprintf(send_buffer,"VKS%s\r\n",volume_name); | 480 | asprintf(&send_buffer,"VKS%s\r\n",volume_name); |
| 481 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); | 481 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); |
| 482 | if(result!=STATE_OK) | 482 | if(result!=STATE_OK) |
| 483 | return result; | 483 | return result; |
| @@ -490,19 +490,19 @@ int main(int argc, char **argv){ | |||
| 490 | else if(check_warning_value==TRUE && percent_purgeable_space >= warning_value) | 490 | else if(check_warning_value==TRUE && percent_purgeable_space >= warning_value) |
| 491 | result=STATE_WARNING; | 491 | result=STATE_WARNING; |
| 492 | purgeable_disk_space/=1024; | 492 | purgeable_disk_space/=1024; |
| 493 | output_message = ssprintf(output_message,"%lu MB (%d%%) purgeable on volume %s",purgeable_disk_space,percent_purgeable_space,volume_name); | 493 | asprintf(&output_message,"%lu MB (%d%%) purgeable on volume %s",purgeable_disk_space,percent_purgeable_space,volume_name); |
| 494 | } | 494 | } |
| 495 | 495 | ||
| 496 | /* check KB not yet purgeable space on volume */ | 496 | /* check KB not yet purgeable space on volume */ |
| 497 | } else if (vars_to_check==CHECK_VKNP) { | 497 | } else if (vars_to_check==CHECK_VKNP) { |
| 498 | 498 | ||
| 499 | send_buffer = ssprintf(send_buffer,"VKNP%s\r\n",volume_name); | 499 | asprintf(&send_buffer,"VKNP%s\r\n",volume_name); |
| 500 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); | 500 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); |
| 501 | if(result!=STATE_OK) | 501 | if(result!=STATE_OK) |
| 502 | return result; | 502 | return result; |
| 503 | 503 | ||
| 504 | if (!strcmp(recv_buffer,"-1\n")) { | 504 | if (!strcmp(recv_buffer,"-1\n")) { |
| 505 | output_message = ssprintf(output_message,"Error: Volume '%s' does not exist!",volume_name); | 505 | asprintf(&output_message,"Error: Volume '%s' does not exist!",volume_name); |
| 506 | result=STATE_CRITICAL; | 506 | result=STATE_CRITICAL; |
| 507 | } else { | 507 | } else { |
| 508 | non_purgeable_disk_space=strtoul(recv_buffer,NULL,10); | 508 | non_purgeable_disk_space=strtoul(recv_buffer,NULL,10); |
| @@ -510,27 +510,27 @@ int main(int argc, char **argv){ | |||
| 510 | result=STATE_CRITICAL; | 510 | result=STATE_CRITICAL; |
| 511 | else if(check_warning_value==TRUE && non_purgeable_disk_space >= warning_value) | 511 | else if(check_warning_value==TRUE && non_purgeable_disk_space >= warning_value) |
| 512 | result=STATE_WARNING; | 512 | result=STATE_WARNING; |
| 513 | output_message = ssprintf(output_message,"%s%lu KB not yet purgeable on volume %s",(result==STATE_OK)?"":"Only ",non_purgeable_disk_space,volume_name); | 513 | asprintf(&output_message,"%s%lu KB not yet purgeable on volume %s",(result==STATE_OK)?"":"Only ",non_purgeable_disk_space,volume_name); |
| 514 | } | 514 | } |
| 515 | 515 | ||
| 516 | /* check % not yet purgeable space on volume */ | 516 | /* check % not yet purgeable space on volume */ |
| 517 | } else if (vars_to_check==CHECK_VPNP) { | 517 | } else if (vars_to_check==CHECK_VPNP) { |
| 518 | 518 | ||
| 519 | send_buffer = ssprintf(send_buffer,"VKNP%s\r\n",volume_name); | 519 | asprintf(&send_buffer,"VKNP%s\r\n",volume_name); |
| 520 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); | 520 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); |
| 521 | if(result!=STATE_OK) | 521 | if(result!=STATE_OK) |
| 522 | return result; | 522 | return result; |
| 523 | 523 | ||
| 524 | if(!strcmp(recv_buffer,"-1\n")){ | 524 | if(!strcmp(recv_buffer,"-1\n")){ |
| 525 | 525 | ||
| 526 | output_message = ssprintf(output_message,"Error: Volume '%s' does not exist!",volume_name); | 526 | asprintf(&output_message,"Error: Volume '%s' does not exist!",volume_name); |
| 527 | result=STATE_CRITICAL; | 527 | result=STATE_CRITICAL; |
| 528 | 528 | ||
| 529 | } else { | 529 | } else { |
| 530 | 530 | ||
| 531 | non_purgeable_disk_space=strtoul(recv_buffer,NULL,10); | 531 | non_purgeable_disk_space=strtoul(recv_buffer,NULL,10); |
| 532 | 532 | ||
| 533 | send_buffer = ssprintf(send_buffer,"VKS%s\r\n",volume_name); | 533 | asprintf(&send_buffer,"VKS%s\r\n",volume_name); |
| 534 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); | 534 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); |
| 535 | if(result!=STATE_OK) | 535 | if(result!=STATE_OK) |
| 536 | return result; | 536 | return result; |
| @@ -543,13 +543,13 @@ int main(int argc, char **argv){ | |||
| 543 | else if(check_warning_value==TRUE && percent_non_purgeable_space >= warning_value) | 543 | else if(check_warning_value==TRUE && percent_non_purgeable_space >= warning_value) |
| 544 | result=STATE_WARNING; | 544 | result=STATE_WARNING; |
| 545 | purgeable_disk_space/=1024; | 545 | purgeable_disk_space/=1024; |
| 546 | output_message = ssprintf(output_message,"%lu MB (%d%%) not yet purgeable on volume %s",non_purgeable_disk_space,percent_non_purgeable_space,volume_name); | 546 | asprintf(&output_message,"%lu MB (%d%%) not yet purgeable on volume %s",non_purgeable_disk_space,percent_non_purgeable_space,volume_name); |
| 547 | } | 547 | } |
| 548 | 548 | ||
| 549 | /* check # of open files */ | 549 | /* check # of open files */ |
| 550 | } else if (vars_to_check==CHECK_OFILES) { | 550 | } else if (vars_to_check==CHECK_OFILES) { |
| 551 | 551 | ||
| 552 | send_buffer = ssprintf(send_buffer,"S18\r\n"); | 552 | asprintf(&send_buffer,"S18\r\n"); |
| 553 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); | 553 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); |
| 554 | if(result!=STATE_OK) | 554 | if(result!=STATE_OK) |
| 555 | return result; | 555 | return result; |
| @@ -561,12 +561,12 @@ int main(int argc, char **argv){ | |||
| 561 | else if(check_warning_value==TRUE && open_files >= warning_value) | 561 | else if(check_warning_value==TRUE && open_files >= warning_value) |
| 562 | result=STATE_WARNING; | 562 | result=STATE_WARNING; |
| 563 | 563 | ||
| 564 | output_message = ssprintf(output_message,"%d open files",open_files); | 564 | asprintf(&output_message,"%d open files",open_files); |
| 565 | 565 | ||
| 566 | /* check # of abended threads (Netware 5.x only) */ | 566 | /* check # of abended threads (Netware 5.x only) */ |
| 567 | } else if (vars_to_check==CHECK_ABENDS) { | 567 | } else if (vars_to_check==CHECK_ABENDS) { |
| 568 | 568 | ||
| 569 | send_buffer = ssprintf(send_buffer,"S17\r\n"); | 569 | asprintf(&send_buffer,"S17\r\n"); |
| 570 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); | 570 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); |
| 571 | if(result!=STATE_OK) | 571 | if(result!=STATE_OK) |
| 572 | return result; | 572 | return result; |
| @@ -578,19 +578,19 @@ int main(int argc, char **argv){ | |||
| 578 | else if(check_warning_value==TRUE && abended_threads >= warning_value) | 578 | else if(check_warning_value==TRUE && abended_threads >= warning_value) |
| 579 | result=STATE_WARNING; | 579 | result=STATE_WARNING; |
| 580 | 580 | ||
| 581 | output_message = ssprintf(output_message,"%d abended threads",abended_threads); | 581 | asprintf(&output_message,"%d abended threads",abended_threads); |
| 582 | 582 | ||
| 583 | /* check # of current service processes (Netware 5.x only) */ | 583 | /* check # of current service processes (Netware 5.x only) */ |
| 584 | } else if (vars_to_check==CHECK_CSPROCS) { | 584 | } else if (vars_to_check==CHECK_CSPROCS) { |
| 585 | 585 | ||
| 586 | send_buffer = ssprintf(send_buffer,"S20\r\n"); | 586 | asprintf(&send_buffer,"S20\r\n"); |
| 587 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); | 587 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); |
| 588 | if(result!=STATE_OK) | 588 | if(result!=STATE_OK) |
| 589 | return result; | 589 | return result; |
| 590 | 590 | ||
| 591 | max_service_processes=atoi(recv_buffer); | 591 | max_service_processes=atoi(recv_buffer); |
| 592 | 592 | ||
| 593 | send_buffer = ssprintf(send_buffer,"S21\r\n"); | 593 | sprintf(&send_buffer,"S21\r\n"); |
| 594 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); | 594 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); |
| 595 | if(result!=STATE_OK) | 595 | if(result!=STATE_OK) |
| 596 | return result; | 596 | return result; |
| @@ -602,7 +602,7 @@ int main(int argc, char **argv){ | |||
| 602 | else if(check_warning_value==TRUE && current_service_processes >= warning_value) | 602 | else if(check_warning_value==TRUE && current_service_processes >= warning_value) |
| 603 | result=STATE_WARNING; | 603 | result=STATE_WARNING; |
| 604 | 604 | ||
| 605 | output_message = ssprintf(output_message,"%d current service processes (%d max)",current_service_processes,max_service_processes); | 605 | asprintf(&output_message,"%d current service processes (%d max)",current_service_processes,max_service_processes); |
| 606 | 606 | ||
| 607 | } else { | 607 | } else { |
| 608 | 608 | ||
diff --git a/plugins/check_ping.c b/plugins/check_ping.c index df1d9eb2..3602122c 100644 --- a/plugins/check_ping.c +++ b/plugins/check_ping.c | |||
| @@ -88,11 +88,9 @@ main (int argc, char **argv) | |||
| 88 | 88 | ||
| 89 | /* does the host address of number of packets argument come first? */ | 89 | /* does the host address of number of packets argument come first? */ |
| 90 | #ifdef PING_PACKETS_FIRST | 90 | #ifdef PING_PACKETS_FIRST |
| 91 | command_line = | 91 | asprintf (&command_line, PING_COMMAND, max_packets, server_address); |
| 92 | ssprintf (command_line, PING_COMMAND, max_packets, server_address); | ||
| 93 | #else | 92 | #else |
| 94 | command_line = | 93 | asprintf (&command_line, PING_COMMAND, server_address, max_packets); |
| 95 | ssprintf (command_line, PING_COMMAND, server_address, max_packets); | ||
| 96 | #endif | 94 | #endif |
| 97 | 95 | ||
| 98 | /* Set signal handling and alarm */ | 96 | /* Set signal handling and alarm */ |
diff --git a/plugins/check_vsz.c b/plugins/check_vsz.c index 2ec8775b..7eeab22c 100644 --- a/plugins/check_vsz.c +++ b/plugins/check_vsz.c | |||
| @@ -61,7 +61,7 @@ main (int argc, char **argv) | |||
| 61 | int proc_size = -1; | 61 | int proc_size = -1; |
| 62 | char input_buffer[MAX_INPUT_BUFFER]; | 62 | char input_buffer[MAX_INPUT_BUFFER]; |
| 63 | char proc_name[MAX_INPUT_BUFFER]; | 63 | char proc_name[MAX_INPUT_BUFFER]; |
| 64 | char *message = NULL; | 64 | char *message = ""; |
| 65 | 65 | ||
| 66 | if (!process_arguments (argc, argv)) { | 66 | if (!process_arguments (argc, argv)) { |
| 67 | printf ("%s: failure parsing arguments\n", my_basename (argv[0])); | 67 | printf ("%s: failure parsing arguments\n", my_basename (argv[0])); |
| @@ -80,8 +80,6 @@ main (int argc, char **argv) | |||
| 80 | if (child_stderr == NULL) | 80 | if (child_stderr == NULL) |
| 81 | printf ("Could not open stderr for %s\n", VSZ_COMMAND); | 81 | printf ("Could not open stderr for %s\n", VSZ_COMMAND); |
| 82 | 82 | ||
| 83 | message = malloc ((size_t) 1); | ||
| 84 | message[0] = 0; | ||
| 85 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { | 83 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { |
| 86 | 84 | ||
| 87 | line++; | 85 | line++; |
| @@ -93,12 +91,7 @@ main (int argc, char **argv) | |||
| 93 | if (sscanf (input_buffer, VSZ_FORMAT, &proc_size, proc_name) == 2) { | 91 | if (sscanf (input_buffer, VSZ_FORMAT, &proc_size, proc_name) == 2) { |
| 94 | if (proc == NULL) { | 92 | if (proc == NULL) { |
| 95 | if (proc_size > warn) { | 93 | if (proc_size > warn) { |
| 96 | len = strlen (message) + strlen (proc_name) + 23; | 94 | asprintf (&message, "%s %s(%d)", message, proc_name, proc_size); |
| 97 | message = realloc (message, len); | ||
| 98 | if (message == NULL) | ||
| 99 | terminate (STATE_UNKNOWN, | ||
| 100 | "check_vsz: could not malloc message (1)"); | ||
| 101 | sprintf (message, "%s %s(%d)", message, proc_name, proc_size); | ||
| 102 | result = max_state (result, STATE_WARNING); | 95 | result = max_state (result, STATE_WARNING); |
| 103 | } | 96 | } |
| 104 | if (proc_size > crit) { | 97 | if (proc_size > crit) { |
| @@ -106,12 +99,7 @@ main (int argc, char **argv) | |||
| 106 | } | 99 | } |
| 107 | } | 100 | } |
| 108 | else if (strstr (proc_name, proc)) { | 101 | else if (strstr (proc_name, proc)) { |
| 109 | len = strlen (message) + 21; | 102 | asprintf (&message, "%s %d", message, proc_size); |
| 110 | message = realloc (message, len); | ||
| 111 | if (message == NULL) | ||
| 112 | terminate (STATE_UNKNOWN, | ||
| 113 | "check_vsz: could not malloc message (2)"); | ||
| 114 | sprintf (message, "%s %d", message, proc_size); | ||
| 115 | if (proc_size > warn) { | 103 | if (proc_size > warn) { |
| 116 | result = max_state (result, STATE_WARNING); | 104 | result = max_state (result, STATE_WARNING); |
| 117 | } | 105 | } |
| @@ -206,11 +194,7 @@ process_arguments (int argc, char **argv) | |||
| 206 | warn = atoi (optarg); | 194 | warn = atoi (optarg); |
| 207 | break; | 195 | break; |
| 208 | case 'C': /* command name */ | 196 | case 'C': /* command name */ |
| 209 | proc = malloc (strlen (optarg) + 1); | 197 | proc = optarg; |
| 210 | if (proc == NULL) | ||
| 211 | terminate (STATE_UNKNOWN, | ||
| 212 | "check_vsz: failed malloc of proc in process_arguments"); | ||
| 213 | strcpy (proc, optarg); | ||
| 214 | break; | 198 | break; |
| 215 | } | 199 | } |
| 216 | } | 200 | } |
| @@ -236,13 +220,8 @@ process_arguments (int argc, char **argv) | |||
| 236 | crit = atoi (argv[c++]); | 220 | crit = atoi (argv[c++]); |
| 237 | } | 221 | } |
| 238 | 222 | ||
| 239 | if (proc == NULL) { | 223 | if (proc == NULL) |
| 240 | proc = malloc (strlen (argv[c]) + 1); | 224 | proc = argv[c]; |
| 241 | if (proc == NULL) | ||
| 242 | terminate (STATE_UNKNOWN, | ||
| 243 | "check_vsz: failed malloc of proc in process_arguments"); | ||
| 244 | strcpy (proc, argv[c]); | ||
| 245 | } | ||
| 246 | 225 | ||
| 247 | return c; | 226 | return c; |
| 248 | } | 227 | } |
diff --git a/plugins/urlize.c b/plugins/urlize.c index 9e02cb5d..9835c824 100644 --- a/plugins/urlize.c +++ b/plugins/urlize.c | |||
| @@ -71,9 +71,9 @@ main (int argc, char **argv) | |||
| 71 | exit (STATE_UNKNOWN); | 71 | exit (STATE_UNKNOWN); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | cmd = ssprintf (cmd, "%s", argv[2]); | 74 | asprintf (&cmd, "%s", argv[2]); |
| 75 | for (i = 3; i < argc; i++) { | 75 | for (i = 3; i < argc; i++) { |
| 76 | cmd = ssprintf (cmd, "%s %s", cmd, argv[i]); | 76 | asprintf (&cmd, "%s %s", cmd, argv[i]); |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | child_process = spopen (cmd); | 79 | child_process = spopen (cmd); |
diff --git a/plugins/utils.c b/plugins/utils.c index bf1d2047..5dc6cfdb 100644 --- a/plugins/utils.c +++ b/plugins/utils.c | |||
| @@ -50,7 +50,6 @@ void strip (char *); | |||
| 50 | char *strscpy (char *dest, const char *src); | 50 | char *strscpy (char *dest, const char *src); |
| 51 | char *strscat (char *dest, const char *src); | 51 | char *strscat (char *dest, const char *src); |
| 52 | char *strnl (char *str); | 52 | char *strnl (char *str); |
| 53 | char *ssprintf (char *str, const char *fmt, ...); | ||
| 54 | char *strpcpy (char *dest, const char *src, const char *str); | 53 | char *strpcpy (char *dest, const char *src, const char *str); |
| 55 | char *strpcat (char *dest, const char *src, const char *str); | 54 | char *strpcat (char *dest, const char *src, const char *str); |
| 56 | 55 | ||
| @@ -496,72 +495,6 @@ strnl (char *str) | |||
| 496 | 495 | ||
| 497 | /****************************************************************************** | 496 | /****************************************************************************** |
| 498 | * | 497 | * |
| 499 | * Does a formatted print to a string variable | ||
| 500 | * | ||
| 501 | * Given a pointer destination string, which may or may not already | ||
| 502 | * hold some text, and a source string with additional text (possibly | ||
| 503 | * NULL or empty), returns a pointer to a string that cntains the | ||
| 504 | * results of the specified formatted print | ||
| 505 | * | ||
| 506 | * Example: | ||
| 507 | * | ||
| 508 | * char *str=NULL; | ||
| 509 | * str = ssprintf(str,"%d %s",1,"string"); | ||
| 510 | * | ||
| 511 | *****************************************************************************/ | ||
| 512 | |||
| 513 | char * | ||
| 514 | ssprintf (char *ptr, const char *fmt, ...) | ||
| 515 | { | ||
| 516 | va_list ap; | ||
| 517 | int nchars; | ||
| 518 | size_t size; | ||
| 519 | char *str = NULL; | ||
| 520 | |||
| 521 | if (str == NULL) { | ||
| 522 | str = malloc (TXTBLK); | ||
| 523 | if (str == NULL) | ||
| 524 | terminate (STATE_UNKNOWN, "malloc failed in ssprintf"); | ||
| 525 | size = TXTBLK; | ||
| 526 | } | ||
| 527 | else | ||
| 528 | size = max (strlen (str), TXTBLK); | ||
| 529 | |||
| 530 | va_start (ap, fmt); | ||
| 531 | |||
| 532 | while (1) { | ||
| 533 | |||
| 534 | nchars = vsnprintf (str, size, fmt, ap); | ||
| 535 | |||
| 536 | if (nchars > -1) | ||
| 537 | if (nchars < (int) size) { | ||
| 538 | va_end (ap); | ||
| 539 | str[nchars] = '\0'; | ||
| 540 | if (ptr) | ||
| 541 | free (ptr); | ||
| 542 | return str; | ||
| 543 | } | ||
| 544 | else { | ||
| 545 | size = (size_t) (nchars + 1); | ||
| 546 | } | ||
| 547 | |||
| 548 | else | ||
| 549 | size *= 2; | ||
| 550 | |||
| 551 | str = realloc (str, size); | ||
| 552 | |||
| 553 | if (str == NULL) | ||
| 554 | terminate (STATE_UNKNOWN, "realloc failed in ssprintf"); | ||
| 555 | } | ||
| 556 | |||
| 557 | } | ||
| 558 | |||
| 559 | |||
| 560 | |||
| 561 | |||
| 562 | |||
| 563 | /****************************************************************************** | ||
| 564 | * | ||
| 565 | * Like strscpy, except only the portion of the source string up to | 498 | * Like strscpy, except only the portion of the source string up to |
| 566 | * the provided delimiter is copied. | 499 | * the provided delimiter is copied. |
| 567 | * | 500 | * |
