diff options
| author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-11-12 11:26:01 +0000 |
|---|---|---|
| committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-11-12 11:26:01 +0000 |
| commit | 41367d9625c1d8a854bdeef4c09511ad4d93b192 (patch) | |
| tree | 89f874444ede056c67cc4b5283e7b095efa9a255 /plugins | |
| parent | fb38088231efc4fc87308f54713ab91f33378c90 (diff) | |
| download | monitoring-plugins-41367d9625c1d8a854bdeef4c09511ad4d93b192.tar.gz | |
remove call_getopt
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@188 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/check_mysql.c | 102 | ||||
| -rw-r--r-- | plugins/check_real.c | 105 | ||||
| -rw-r--r-- | plugins/check_ups.c | 15 |
3 files changed, 73 insertions, 149 deletions
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c index 50836f91..a4a2ed1d 100644 --- a/plugins/check_mysql.c +++ b/plugins/check_mysql.c | |||
| @@ -15,6 +15,8 @@ | |||
| 15 | ******************************************************************************/ | 15 | ******************************************************************************/ |
| 16 | 16 | ||
| 17 | #define PROGNAME "check_mysql" | 17 | #define PROGNAME "check_mysql" |
| 18 | #define REVISION "$Revision$" | ||
| 19 | #define COPYRIGHT "1999-2002" | ||
| 18 | 20 | ||
| 19 | #include "common.h" | 21 | #include "common.h" |
| 20 | #include "utils.h" | 22 | #include "utils.h" |
| @@ -22,14 +24,13 @@ | |||
| 22 | #include <mysql/mysql.h> | 24 | #include <mysql/mysql.h> |
| 23 | #include <mysql/errmsg.h> | 25 | #include <mysql/errmsg.h> |
| 24 | 26 | ||
| 25 | char *db_user = NULL; | 27 | char *db_user = ""; |
| 26 | char *db_host = NULL; | 28 | char *db_host = ""; |
| 27 | char *db_pass = NULL; | 29 | char *db_pass = ""; |
| 28 | char *db = NULL; | 30 | char *db = ""; |
| 29 | unsigned int db_port = MYSQL_PORT; | 31 | unsigned int db_port = MYSQL_PORT; |
| 30 | 32 | ||
| 31 | int process_arguments (int, char **); | 33 | int process_arguments (int, char **); |
| 32 | int call_getopt (int, char **); | ||
| 33 | int validate_arguments (void); | 34 | int validate_arguments (void); |
| 34 | int check_disk (int usp, int free_disk); | 35 | int check_disk (int usp, int free_disk); |
| 35 | void print_help (void); | 36 | void print_help (void); |
| @@ -126,48 +127,6 @@ process_arguments (int argc, char **argv) | |||
| 126 | { | 127 | { |
| 127 | int c; | 128 | int c; |
| 128 | 129 | ||
| 129 | if (argc < 1) | ||
| 130 | return ERROR; | ||
| 131 | |||
| 132 | c = 0; | ||
| 133 | while ((c += (call_getopt (argc - c, &argv[c]))) < argc) { | ||
| 134 | |||
| 135 | if (is_option (argv[c])) | ||
| 136 | continue; | ||
| 137 | |||
| 138 | if (db_host == NULL) | ||
| 139 | if (is_host (argv[c])) { | ||
| 140 | db_host = argv[c]; | ||
| 141 | } | ||
| 142 | else { | ||
| 143 | usage ("Invalid host name"); | ||
| 144 | } | ||
| 145 | else if (db_user == NULL) | ||
| 146 | db_user = argv[c]; | ||
| 147 | else if (db_pass == NULL) | ||
| 148 | db_pass = argv[c]; | ||
| 149 | else if (db == NULL) | ||
| 150 | db = argv[c]; | ||
| 151 | else if (is_intnonneg (argv[c])) | ||
| 152 | db_port = atoi (argv[c]); | ||
| 153 | } | ||
| 154 | |||
| 155 | if (db_host == NULL) | ||
| 156 | db_host = strscpy (db_host, "127.0.0.1"); | ||
| 157 | |||
| 158 | return validate_arguments (); | ||
| 159 | } | ||
| 160 | |||
| 161 | |||
| 162 | |||
| 163 | |||
| 164 | |||
| 165 | |||
| 166 | int | ||
| 167 | call_getopt (int argc, char **argv) | ||
| 168 | { | ||
| 169 | int c, i = 0; | ||
| 170 | |||
| 171 | #ifdef HAVE_GETOPT_H | 130 | #ifdef HAVE_GETOPT_H |
| 172 | int option_index = 0; | 131 | int option_index = 0; |
| 173 | static struct option long_options[] = { | 132 | static struct option long_options[] = { |
| @@ -183,29 +142,21 @@ call_getopt (int argc, char **argv) | |||
| 183 | }; | 142 | }; |
| 184 | #endif | 143 | #endif |
| 185 | 144 | ||
| 145 | if (argc < 1) | ||
| 146 | return ERROR; | ||
| 147 | |||
| 186 | while (1) { | 148 | while (1) { |
| 187 | #ifdef HAVE_GETOPT_H | 149 | #ifdef HAVE_GETOPT_H |
| 188 | c = | 150 | c = |
| 189 | getopt_long (argc, argv, "+hVP:p:u:d:H:", long_options, &option_index); | 151 | getopt_long (argc, argv, "hVP:p:u:d:H:", long_options, &option_index); |
| 190 | #else | 152 | #else |
| 191 | c = getopt (argc, argv, "+?hVP:p:u:d:H:"); | 153 | c = getopt (argc, argv, "hVP:p:u:d:H:"); |
| 192 | #endif | 154 | #endif |
| 193 | 155 | ||
| 194 | i++; | 156 | if (c == -1 || c == EOF) |
| 195 | |||
| 196 | if (c == -1 || c == EOF || c == 1) | ||
| 197 | break; | 157 | break; |
| 198 | 158 | ||
| 199 | switch (c) { | 159 | switch (c) { |
| 200 | case 'P': | ||
| 201 | case 'p': | ||
| 202 | case 'u': | ||
| 203 | case 'd': | ||
| 204 | case 'H': | ||
| 205 | i++; | ||
| 206 | } | ||
| 207 | |||
| 208 | switch (c) { | ||
| 209 | case 'H': /* hostname */ | 160 | case 'H': /* hostname */ |
| 210 | if (is_host (optarg)) { | 161 | if (is_host (optarg)) { |
| 211 | db_host = optarg; | 162 | db_host = optarg; |
| @@ -227,7 +178,7 @@ call_getopt (int argc, char **argv) | |||
| 227 | db_port = atoi (optarg); | 178 | db_port = atoi (optarg); |
| 228 | break; | 179 | break; |
| 229 | case 'V': /* version */ | 180 | case 'V': /* version */ |
| 230 | print_revision (my_basename (argv[0]), "$Revision$"); | 181 | print_revision (PROGNAME, REVISION); |
| 231 | exit (STATE_OK); | 182 | exit (STATE_OK); |
| 232 | case 'h': /* help */ | 183 | case 'h': /* help */ |
| 233 | print_help (); | 184 | print_help (); |
| @@ -236,7 +187,30 @@ call_getopt (int argc, char **argv) | |||
| 236 | usage ("Invalid argument\n"); | 187 | usage ("Invalid argument\n"); |
| 237 | } | 188 | } |
| 238 | } | 189 | } |
| 239 | return i; | 190 | |
| 191 | c = optind; | ||
| 192 | |||
| 193 | if (strlen(db_host) == 0 && argc > c) | ||
| 194 | if (is_host (argv[c])) { | ||
| 195 | db_host = argv[c++]; | ||
| 196 | } | ||
| 197 | else { | ||
| 198 | usage ("Invalid host name"); | ||
| 199 | } | ||
| 200 | |||
| 201 | if (strlen(db_user) == 0 && argc > c) | ||
| 202 | db_user = argv[c++]; | ||
| 203 | |||
| 204 | if (strlen(db_pass) == 0 && argc > c) | ||
| 205 | db_pass = argv[c++]; | ||
| 206 | |||
| 207 | if (strlen(db) == 0 && argc > c) | ||
| 208 | db = argv[c++]; | ||
| 209 | |||
| 210 | if (is_intnonneg (argv[c])) | ||
| 211 | db_port = atoi (argv[c++]); | ||
| 212 | |||
| 213 | return validate_arguments (); | ||
| 240 | } | 214 | } |
| 241 | 215 | ||
| 242 | 216 | ||
| @@ -256,7 +230,7 @@ validate_arguments (void) | |||
| 256 | void | 230 | void |
| 257 | print_help (void) | 231 | print_help (void) |
| 258 | { | 232 | { |
| 259 | print_revision (PROGNAME, "$Revision$"); | 233 | print_revision (PROGNAME, REVISION); |
| 260 | printf | 234 | printf |
| 261 | ("Copyright (c) 2000 Didi Rieder/Karl DeBisschop\n\n" | 235 | ("Copyright (c) 2000 Didi Rieder/Karl DeBisschop\n\n" |
| 262 | "This plugin is for testing a mysql server.\n"); | 236 | "This plugin is for testing a mysql server.\n"); |
diff --git a/plugins/check_real.c b/plugins/check_real.c index ba746b81..c553352c 100644 --- a/plugins/check_real.c +++ b/plugins/check_real.c | |||
| @@ -55,17 +55,16 @@ | |||
| 55 | #define URL "" | 55 | #define URL "" |
| 56 | 56 | ||
| 57 | int process_arguments (int, char **); | 57 | int process_arguments (int, char **); |
| 58 | int call_getopt (int, char **); | ||
| 59 | int validate_arguments (void); | 58 | int validate_arguments (void); |
| 60 | int check_disk (int usp, int free_disk); | 59 | int check_disk (int usp, int free_disk); |
| 61 | void print_help (void); | 60 | void print_help (void); |
| 62 | void print_usage (void); | 61 | void print_usage (void); |
| 63 | 62 | ||
| 64 | int server_port = PORT; | 63 | int server_port = PORT; |
| 65 | char *server_address = NULL; | 64 | char *server_address = ""; |
| 66 | char *host_name = NULL; | 65 | char *host_name = NULL; |
| 67 | char *server_url = NULL; | 66 | char *server_url = NULL; |
| 68 | char *server_expect = NULL; | 67 | char *server_expect = EXPECT; |
| 69 | int warning_time = 0; | 68 | int warning_time = 0; |
| 70 | int check_warning_time = FALSE; | 69 | int check_warning_time = FALSE; |
| 71 | int critical_time = 0; | 70 | int critical_time = 0; |
| @@ -117,7 +116,7 @@ main (int argc, char **argv) | |||
| 117 | terminate (STATE_CRITICAL, "No data received from %s\n", host_name); | 116 | terminate (STATE_CRITICAL, "No data received from %s\n", host_name); |
| 118 | 117 | ||
| 119 | /* make sure we find the response we are looking for */ | 118 | /* make sure we find the response we are looking for */ |
| 120 | if (!strstr (buffer, EXPECT)) { | 119 | if (!strstr (buffer, server_expect)) { |
| 121 | if (server_port == PORT) | 120 | if (server_port == PORT) |
| 122 | printf ("Invalid REAL response received from host\n"); | 121 | printf ("Invalid REAL response received from host\n"); |
| 123 | else | 122 | else |
| @@ -190,7 +189,7 @@ main (int argc, char **argv) | |||
| 190 | } | 189 | } |
| 191 | else { | 190 | else { |
| 192 | /* make sure we find the response we are looking for */ | 191 | /* make sure we find the response we are looking for */ |
| 193 | if (!strstr (buffer, EXPECT)) { | 192 | if (!strstr (buffer, server_expect)) { |
| 194 | if (server_port == PORT) | 193 | if (server_port == PORT) |
| 195 | printf ("Invalid REAL response received from host\n"); | 194 | printf ("Invalid REAL response received from host\n"); |
| 196 | else | 195 | else |
| @@ -275,52 +274,6 @@ process_arguments (int argc, char **argv) | |||
| 275 | { | 274 | { |
| 276 | int c; | 275 | int c; |
| 277 | 276 | ||
| 278 | if (argc < 2) | ||
| 279 | return ERROR; | ||
| 280 | |||
| 281 | for (c = 1; c < argc; c++) { | ||
| 282 | if (strcmp ("-to", argv[c]) == 0) | ||
| 283 | strcpy (argv[c], "-t"); | ||
| 284 | else if (strcmp ("-wt", argv[c]) == 0) | ||
| 285 | strcpy (argv[c], "-w"); | ||
| 286 | else if (strcmp ("-ct", argv[c]) == 0) | ||
| 287 | strcpy (argv[c], "-c"); | ||
| 288 | } | ||
| 289 | |||
| 290 | |||
| 291 | |||
| 292 | c = 0; | ||
| 293 | while ((c += (call_getopt (argc - c, &argv[c]))) < argc) { | ||
| 294 | |||
| 295 | if (is_option (argv[c])) | ||
| 296 | continue; | ||
| 297 | |||
| 298 | if (server_address == NULL) { | ||
| 299 | if (is_host (argv[c])) { | ||
| 300 | server_address = argv[c]; | ||
| 301 | } | ||
| 302 | else { | ||
| 303 | usage ("Invalid host name"); | ||
| 304 | } | ||
| 305 | } | ||
| 306 | } | ||
| 307 | |||
| 308 | if (server_expect == NULL) | ||
| 309 | server_expect = strscpy (NULL, EXPECT); | ||
| 310 | |||
| 311 | return validate_arguments (); | ||
| 312 | } | ||
| 313 | |||
| 314 | |||
| 315 | |||
| 316 | |||
| 317 | |||
| 318 | |||
| 319 | int | ||
| 320 | call_getopt (int argc, char **argv) | ||
| 321 | { | ||
| 322 | int c, i = 0; | ||
| 323 | |||
| 324 | #ifdef HAVE_GETOPT_H | 277 | #ifdef HAVE_GETOPT_H |
| 325 | int option_index = 0; | 278 | int option_index = 0; |
| 326 | static struct option long_options[] = { | 279 | static struct option long_options[] = { |
| @@ -339,6 +292,18 @@ call_getopt (int argc, char **argv) | |||
| 339 | }; | 292 | }; |
| 340 | #endif | 293 | #endif |
| 341 | 294 | ||
| 295 | if (argc < 2) | ||
| 296 | return ERROR; | ||
| 297 | |||
| 298 | for (c = 1; c < argc; c++) { | ||
| 299 | if (strcmp ("-to", argv[c]) == 0) | ||
| 300 | strcpy (argv[c], "-t"); | ||
| 301 | else if (strcmp ("-wt", argv[c]) == 0) | ||
| 302 | strcpy (argv[c], "-w"); | ||
| 303 | else if (strcmp ("-ct", argv[c]) == 0) | ||
| 304 | strcpy (argv[c], "-c"); | ||
| 305 | } | ||
| 306 | |||
| 342 | while (1) { | 307 | while (1) { |
| 343 | #ifdef HAVE_GETOPT_H | 308 | #ifdef HAVE_GETOPT_H |
| 344 | c = | 309 | c = |
| @@ -348,32 +313,11 @@ call_getopt (int argc, char **argv) | |||
| 348 | c = getopt (argc, argv, "+?hVI:H:e:u:p:w:c:t"); | 313 | c = getopt (argc, argv, "+?hVI:H:e:u:p:w:c:t"); |
| 349 | #endif | 314 | #endif |
| 350 | 315 | ||
| 351 | i++; | 316 | if (c == -1 || c == EOF) |
| 352 | |||
| 353 | if (c == -1 || c == EOF || c == 1) | ||
| 354 | break; | 317 | break; |
| 355 | 318 | ||
| 356 | switch (c) { | 319 | switch (c) { |
| 357 | case 'I': | ||
| 358 | case 'H': | ||
| 359 | case 'e': | ||
| 360 | case 'u': | ||
| 361 | case 'p': | ||
| 362 | case 'w': | ||
| 363 | case 'c': | ||
| 364 | case 't': | ||
| 365 | i++; | ||
| 366 | } | ||
| 367 | |||
| 368 | switch (c) { | ||
| 369 | case 'I': /* hostname */ | 320 | case 'I': /* hostname */ |
| 370 | if (is_host (optarg)) { | ||
| 371 | server_address = optarg; | ||
| 372 | } | ||
| 373 | else { | ||
| 374 | usage ("Invalid host name\n"); | ||
| 375 | } | ||
| 376 | break; | ||
| 377 | case 'H': /* hostname */ | 321 | case 'H': /* hostname */ |
| 378 | if (is_host (optarg)) { | 322 | if (is_host (optarg)) { |
| 379 | server_address = optarg; | 323 | server_address = optarg; |
| @@ -385,7 +329,7 @@ call_getopt (int argc, char **argv) | |||
| 385 | case 'e': /* string to expect in response header */ | 329 | case 'e': /* string to expect in response header */ |
| 386 | server_expect = optarg; | 330 | server_expect = optarg; |
| 387 | break; | 331 | break; |
| 388 | case 'u': /* string to expect in response header */ | 332 | case 'u': /* server URL */ |
| 389 | server_url = optarg; | 333 | server_url = optarg; |
| 390 | break; | 334 | break; |
| 391 | case 'p': /* port */ | 335 | case 'p': /* port */ |
| @@ -435,7 +379,18 @@ call_getopt (int argc, char **argv) | |||
| 435 | usage ("Invalid argument\n"); | 379 | usage ("Invalid argument\n"); |
| 436 | } | 380 | } |
| 437 | } | 381 | } |
| 438 | return i; | 382 | |
| 383 | c = optind; | ||
| 384 | if (strlen(server_address) == 0 && argc > c) { | ||
| 385 | if (is_host (argv[c])) { | ||
| 386 | server_address = argv[c++]; | ||
| 387 | } | ||
| 388 | else { | ||
| 389 | usage ("Invalid host name"); | ||
| 390 | } | ||
| 391 | } | ||
| 392 | |||
| 393 | return validate_arguments (); | ||
| 439 | } | 394 | } |
| 440 | 395 | ||
| 441 | 396 | ||
diff --git a/plugins/check_ups.c b/plugins/check_ups.c index c711de20..e250ef9d 100644 --- a/plugins/check_ups.c +++ b/plugins/check_ups.c | |||
| @@ -82,7 +82,7 @@ | |||
| 82 | #define UPSSTATUS_UNKOWN 32 | 82 | #define UPSSTATUS_UNKOWN 32 |
| 83 | 83 | ||
| 84 | int server_port = PORT; | 84 | int server_port = PORT; |
| 85 | char *server_address = NULL; | 85 | char *server_address = "127.0.0.1"; |
| 86 | char *ups_name = NULL; | 86 | char *ups_name = NULL; |
| 87 | double warning_value = 0.0L; | 87 | double warning_value = 0.0L; |
| 88 | double critical_value = 0.0L; | 88 | double critical_value = 0.0L; |
| @@ -103,7 +103,6 @@ int determine_supported_vars (void); | |||
| 103 | int get_ups_variable (const char *, char *, int); | 103 | int get_ups_variable (const char *, char *, int); |
| 104 | 104 | ||
| 105 | int process_arguments (int, char **); | 105 | int process_arguments (int, char **); |
| 106 | int call_getopt (int, char **); | ||
| 107 | int validate_arguments (void); | 106 | int validate_arguments (void); |
| 108 | void print_help (void); | 107 | void print_help (void); |
| 109 | void print_usage (void); | 108 | void print_usage (void); |
| @@ -547,17 +546,13 @@ process_arguments (int argc, char **argv) | |||
| 547 | } | 546 | } |
| 548 | 547 | ||
| 549 | 548 | ||
| 550 | if (server_address == NULL) { | 549 | if (server_address == NULL && argc > optind) { |
| 551 | if (optind >= argc) { | 550 | if (is_host (argv[optind])) |
| 552 | server_address = strscpy (NULL, "127.0.0.1"); | ||
| 553 | } | ||
| 554 | else if (is_host (argv[optind])) { | ||
| 555 | server_address = argv[optind++]; | 551 | server_address = argv[optind++]; |
| 556 | } | 552 | else |
| 557 | else { | ||
| 558 | usage ("Invalid host name"); | 553 | usage ("Invalid host name"); |
| 559 | } | ||
| 560 | } | 554 | } |
| 555 | |||
| 561 | return validate_arguments(); | 556 | return validate_arguments(); |
| 562 | } | 557 | } |
| 563 | 558 | ||
