From c68d99cee2d1b3de6a7e800440433a39a7436313 Mon Sep 17 00:00:00 2001 From: Benoit Mortier Date: Mon, 14 Nov 2005 00:51:44 +0000 Subject: start of the cleaning of the localization git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1282 f882894a-f735-0410-b71e-b25c423dba1c diff --git a/plugins/check_dig.c b/plugins/check_dig.c index bc4dcd5..c9fce61 100644 --- a/plugins/check_dig.c +++ b/plugins/check_dig.c @@ -26,7 +26,7 @@ const char *progname = "check_dig"; const char *revision = "$Revision$"; -const char *copyright = "2002-2004"; +const char *copyright = "2002-2005"; const char *email = "nagiosplug-devel@lists.sourceforge.net"; #include "common.h" @@ -55,113 +55,113 @@ struct timeval tv; int main (int argc, char **argv) { - char *command_line; - output chld_out, chld_err; - char *msg = NULL; - size_t i; - char *t; - long microsec; - double elapsed_time; - int result = STATE_UNKNOWN; - - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE, LOCALEDIR); - textdomain (PACKAGE); - - /* Set signal handling and alarm */ - if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) - usage_va(_("Cannot catch SIGALRM")); - - if (process_arguments (argc, argv) == ERROR) - usage_va(_("Could not parse arguments")); - - /* get the command to run */ - asprintf (&command_line, "%s @%s -p %d %s -t %s", - PATH_TO_DIG, dns_server, server_port, query_address, record_type); - - alarm (timeout_interval); - gettimeofday (&tv, NULL); - - if (verbose) { - printf ("%s\n", command_line); - if(expected_address != NULL) { - printf (_("Looking for: '%s'\n"), expected_address); - } else { - printf (_("Looking for: '%s'\n"), query_address); - } - } - - /* run the command */ - if(np_runcmd(command_line, &chld_out, &chld_err, 0) != 0) { - result = STATE_WARNING; - msg = (char *)_("dig returned an error status"); - } - - for(i = 0; i < chld_out.lines; i++) { - /* the server is responding, we just got the host name... */ - if (strstr (chld_out.line[i], ";; ANSWER SECTION:")) { - - /* loop through the whole 'ANSWER SECTION' */ - for(; i < chld_out.lines; i++) { - /* get the host address */ - if (verbose) - printf ("%s\n", chld_out.line[i]); - - if (strstr (chld_out.line[i], (expected_address == NULL ? query_address : expected_address)) != NULL) { - msg = chld_out.line[i]; - result = STATE_OK; - - /* Translate output TAB -> SPACE */ - t = msg; - while ((t = strchr(t, '\t')) != NULL) *t = ' '; - break; - } - } - - if (result == STATE_UNKNOWN) { - msg = (char *)_("Server not found in ANSWER SECTION"); - result = STATE_WARNING; - } - - /* we found the answer section, so break out of the loop */ - break; - } - } - - if (result == STATE_UNKNOWN) - msg = (char *)_("No ANSWER SECTION found"); - - /* If we get anything on STDERR, at least set warning */ - if(chld_err.buflen > 0) { - result = max_state(result, STATE_WARNING); - if(!msg) for(i = 0; i < chld_err.lines; i++) { - msg = strchr(chld_err.line[0], ':'); - if(msg) { - msg++; - break; - } - } - } - - microsec = deltime (tv); - elapsed_time = (double)microsec / 1.0e6; - - if (critical_interval > UNDEFINED && elapsed_time > critical_interval) - result = STATE_CRITICAL; - - else if (warning_interval > UNDEFINED && elapsed_time > warning_interval) - result = STATE_WARNING; - - printf ("DNS %s - %.3f seconds response time (%s)|%s\n", - state_text (result), elapsed_time, - msg ? msg : _("Probably a non-existent host/domain"), - fperfdata("time", elapsed_time, "s", - (warning_interval>UNDEFINED?TRUE:FALSE), - warning_interval, - (critical_interval>UNDEFINED?TRUE:FALSE), - critical_interval, - TRUE, 0, FALSE, 0)); - return result; + char *command_line; + output chld_out, chld_err; + char *msg = NULL; + size_t i; + char *t; + long microsec; + double elapsed_time; + int result = STATE_UNKNOWN; + + setlocale (LC_ALL, ""); + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); + + /* Set signal handling and alarm */ + if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) + usage_va(_("Cannot catch SIGALRM")); + + if (process_arguments (argc, argv) == ERROR) + usage_va(_("Could not parse arguments")); + + /* get the command to run */ + asprintf (&command_line, "%s @%s -p %d %s -t %s", + PATH_TO_DIG, dns_server, server_port, query_address, record_type); + + alarm (timeout_interval); + gettimeofday (&tv, NULL); + + if (verbose) { + printf ("%s\n", command_line); + if(expected_address != NULL) { + printf (_("Looking for: '%s'\n"), expected_address); + } else { + printf (_("Looking for: '%s'\n"), query_address); + } + } + + /* run the command */ + if(np_runcmd(command_line, &chld_out, &chld_err, 0) != 0) { + result = STATE_WARNING; + msg = (char *)_("dig returned an error status"); + } + + for(i = 0; i < chld_out.lines; i++) { + /* the server is responding, we just got the host name... */ + if (strstr (chld_out.line[i], ";; ANSWER SECTION:")) { + + /* loop through the whole 'ANSWER SECTION' */ + for(; i < chld_out.lines; i++) { + /* get the host address */ + if (verbose) + printf ("%s\n", chld_out.line[i]); + + if (strstr (chld_out.line[i], (expected_address == NULL ? query_address : expected_address)) != NULL) { + msg = chld_out.line[i]; + result = STATE_OK; + + /* Translate output TAB -> SPACE */ + t = msg; + while ((t = strchr(t, '\t')) != NULL) *t = ' '; + break; + } + } + + if (result == STATE_UNKNOWN) { + msg = (char *)_("Server not found in ANSWER SECTION"); + result = STATE_WARNING; + } + + /* we found the answer section, so break out of the loop */ + break; + } + } + + if (result == STATE_UNKNOWN) + msg = (char *)_("No ANSWER SECTION found"); + + /* If we get anything on STDERR, at least set warning */ + if(chld_err.buflen > 0) { + result = max_state(result, STATE_WARNING); + if(!msg) for(i = 0; i < chld_err.lines; i++) { + msg = strchr(chld_err.line[0], ':'); + if(msg) { + msg++; + break; + } + } + } + + microsec = deltime (tv); + elapsed_time = (double)microsec / 1.0e6; + + if (critical_interval > UNDEFINED && elapsed_time > critical_interval) + result = STATE_CRITICAL; + + else if (warning_interval > UNDEFINED && elapsed_time > warning_interval) + result = STATE_WARNING; + + printf ("DNS %s - %.3f seconds response time (%s)|%s\n", + state_text (result), elapsed_time, + msg ? msg : _("Probably a non-existent host/domain"), + fperfdata("time", elapsed_time, "s", + (warning_interval>UNDEFINED?TRUE:FALSE), + warning_interval, + (critical_interval>UNDEFINED?TRUE:FALSE), + critical_interval, + TRUE, 0, FALSE, 0)); + return result; } @@ -170,104 +170,104 @@ main (int argc, char **argv) int process_arguments (int argc, char **argv) { - int c; - - int option = 0; - static struct option longopts[] = { - {"hostname", required_argument, 0, 'H'}, - {"query_address", required_argument, 0, 'l'}, - {"warning", required_argument, 0, 'w'}, - {"critical", required_argument, 0, 'c'}, - {"timeout", required_argument, 0, 't'}, - {"verbose", no_argument, 0, 'v'}, - {"version", no_argument, 0, 'V'}, - {"help", no_argument, 0, 'h'}, - {"record_type", required_argument, 0, 'T'}, - {"expected_address", required_argument, 0, 'a'}, - {0, 0, 0, 0} - }; - - if (argc < 2) - return ERROR; - - while (1) { - c = getopt_long (argc, argv, "hVvt:l:H:w:c:T:a:", longopts, &option); - - if (c == -1 || c == EOF) - break; - - switch (c) { - case 'h': /* help */ - print_help (); - exit (STATE_OK); - case 'V': /* version */ - print_revision (progname, revision); - exit (STATE_OK); - case 'H': /* hostname */ - host_or_die(optarg); - dns_server = optarg; - break; - case 'p': /* server port */ - if (is_intpos (optarg)) { - server_port = atoi (optarg); - } - else { - usage_va(_("Port must be a positive integer - %s"), optarg); - } - break; - case 'l': /* address to lookup */ - query_address = optarg; - break; - case 'w': /* warning */ - if (is_nonnegative (optarg)) { - warning_interval = strtod (optarg, NULL); - } - else { - usage_va(_("Warning interval must be a positive integer - %s"), optarg); - } - break; - case 'c': /* critical */ - if (is_nonnegative (optarg)) { - critical_interval = strtod (optarg, NULL); - } - else { - usage_va(_("Critical interval must be a positive integer - %s"), optarg); - } - break; - case 't': /* timeout */ - if (is_intnonneg (optarg)) { - timeout_interval = atoi (optarg); - } - else { - usage_va(_("Timeout interval must be a positive integer - %s"), optarg); - } - break; - case 'v': /* verbose */ - verbose = TRUE; - break; - case 'T': - record_type = optarg; - break; - case 'a': - expected_address = optarg; - break; - default: /* usage_va */ - usage_va(_("Unknown argument - %s"), optarg); - } - } - - c = optind; - if (dns_server == NULL) { - if (c < argc) { - host_or_die(argv[c]); - dns_server = argv[c]; - } - else { - dns_server = strdup ("127.0.0.1"); - } - } - - return validate_arguments (); + int c; + + int option = 0; + static struct option longopts[] = { + {"hostname", required_argument, 0, 'H'}, + {"query_address", required_argument, 0, 'l'}, + {"warning", required_argument, 0, 'w'}, + {"critical", required_argument, 0, 'c'}, + {"timeout", required_argument, 0, 't'}, + {"verbose", no_argument, 0, 'v'}, + {"version", no_argument, 0, 'V'}, + {"help", no_argument, 0, 'h'}, + {"record_type", required_argument, 0, 'T'}, + {"expected_address", required_argument, 0, 'a'}, + {0, 0, 0, 0} + }; + + if (argc < 2) + return ERROR; + + while (1) { + c = getopt_long (argc, argv, "hVvt:l:H:w:c:T:a:", longopts, &option); + + if (c == -1 || c == EOF) + break; + + switch (c) { + case 'h': /* help */ + print_help (); + exit (STATE_OK); + case 'V': /* version */ + print_revision (progname, revision); + exit (STATE_OK); + case 'H': /* hostname */ + host_or_die(optarg); + dns_server = optarg; + break; + case 'p': /* server port */ + if (is_intpos (optarg)) { + server_port = atoi (optarg); + } + else { + usage_va(_("Port must be a positive integer - %s"), optarg); + } + break; + case 'l': /* address to lookup */ + query_address = optarg; + break; + case 'w': /* warning */ + if (is_nonnegative (optarg)) { + warning_interval = strtod (optarg, NULL); + } + else { + usage_va(_("Warning interval must be a positive integer - %s"), optarg); + } + break; + case 'c': /* critical */ + if (is_nonnegative (optarg)) { + critical_interval = strtod (optarg, NULL); + } + else { + usage_va(_("Critical interval must be a positive integer - %s"), optarg); + } + break; + case 't': /* timeout */ + if (is_intnonneg (optarg)) { + timeout_interval = atoi (optarg); + } + else { + usage_va(_("Timeout interval must be a positive integer - %s"), optarg); + } + break; + case 'v': /* verbose */ + verbose = TRUE; + break; + case 'T': + record_type = optarg; + break; + case 'a': + expected_address = optarg; + break; + default: /* usage_va */ + usage_va(_("Unknown argument - %s"), optarg); + } + } + + c = optind; + if (dns_server == NULL) { + if (c < argc) { + host_or_die(argv[c]); + dns_server = argv[c]; + } + else { + dns_server = strdup ("127.0.0.1"); + } + } + + return validate_arguments (); } @@ -275,7 +275,7 @@ process_arguments (int argc, char **argv) int validate_arguments (void) { - return OK; + return OK; } @@ -283,43 +283,56 @@ validate_arguments (void) void print_help (void) { - char *myport; + char *myport; - asprintf (&myport, "%d", DEFAULT_PORT); + asprintf (&myport, "%d", DEFAULT_PORT); - print_revision (progname, revision); + print_revision (progname, revision); - printf ("Copyright (c) 2000 Karl DeBisschop \n"); - printf (COPYRIGHT, copyright, email); + printf ("Copyright (c) 2000 Karl DeBisschop \n"); + printf (COPYRIGHT, copyright, email); - printf (_("Test the DNS service on the specified host using dig\n\n")); + printf (_("This plugin test the DNS service on the specified host using dig")); - print_usage (); + printf ("\n\n"); - printf (_(UT_HELP_VRSN)); + print_usage (); - printf (_(UT_HOST_PORT), 'P', myport); + printf (_(UT_HELP_VRSN)); - printf (_("\ - -l, --lookup=STRING\n\ - machine name to lookup\n")); + printf (_(UT_HOST_PORT), 'P', myport); - printf (_("\ - -T, --record_type=STRING\n\ - record type to lookup (default: A)\n")); + printf ("-l, --lookup=STRING"); + + printf ("\n"); - printf (_("\ - -a, --expected_address=STRING\n\ - an address expected to be in the answer section.\n\ - if not set, uses whatever was in -l\n")); + printf (_("machine name to lookup")); - printf (_(UT_WARN_CRIT)); + printf ("\n"); - printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); + printf ("-T, --record_type=STRING"); - printf (_(UT_VERBOSE)); + printf ("\n"); - printf (_(UT_SUPPORT)); + printf (_("record type to lookup (default: A)")); + + printf ("\n"); + + printf ("-a, --expected_address=STRING"); + + printf ("\n"); + + printf (_("an address expected to be in the answer section.if not set, uses whatever was in -l")); + + printf ("\n"); + + printf (_(UT_WARN_CRIT)); + + printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); + + printf (_(UT_VERBOSE)); + + printf (_(UT_SUPPORT)); } @@ -327,8 +340,8 @@ print_help (void) void print_usage (void) { - printf ("\ -Usage: %s -H host -l lookup [-p ] [-T ]\n\ - [-w ] [-c ] [-t ]\n\ - [-a ] [-v]\n", progname); + printf (_("Usage:")); + printf ("%s -H host -l lookup [-p ] [-T ]", progname); + printf (" [-w ] [-c ] [-t ]"); + printf (" [-a ] [-v]\n"); } diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 81dd6c7..3a5f476 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -19,9 +19,9 @@ *****************************************************************************/ const char *progname = "check_disk"; -const char *program_name = "check_disk"; /* Required for coreutils libs */ +const char *program_name = "check_disk"; /* Required for coreutils libs */ const char *revision = "$Revision$"; -const char *copyright = "1999-2004"; +const char *copyright = "1999-2005"; const char *email = "nagiosplug-devel@lists.sourceforge.net"; /* @@ -149,92 +149,92 @@ static struct mount_entry *mount_list; int main (int argc, char **argv) { - double usp = -1.0, uisp = -1.0; - int result = STATE_UNKNOWN; - int disk_result = STATE_UNKNOWN; - char file_system[MAX_INPUT_BUFFER]; - char *output; - char *details; - char *perf; - uintmax_t psize; - float free_space, free_space_pct, total_space, inode_space_pct; - - struct mount_entry *me; - struct fs_usage fsp; - struct name_list *temp_list; - - output = strdup (" - free space:"); - details = strdup (""); - perf = strdup (""); - - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE, LOCALEDIR); - textdomain (PACKAGE); - - mount_list = read_filesystem_list (0); - - if (process_arguments (argc, argv) == ERROR) - usage4 (_("Could not parse arguments")); - - /* if a list of paths has been selected, preseed the list with - * the longest matching filesystem name by iterating across - * the mountlist once ahead of time. this will allow a query on - * "/var/log" to return information about "/var" if no "/var/log" - * filesystem exists, etc. this is the default behavior already - * with df-based checks, but for systems with their own space - * checking routines, this should make them more consistent. - */ - if(path_select_list){ - for (me = mount_list; me; me = me->me_next) { - walk_name_list(path_select_list, me->me_mountdir); - walk_name_list(path_select_list, me->me_devname); - } - /* now pretend we never saw anything, but keep found_len. - * thus future searches will only match the best match */ - for (temp_list = path_select_list; temp_list; temp_list=temp_list->name_next){ - temp_list->found=0; - } - } - - /* for every mount entry */ - for (me = mount_list; me; me = me->me_next) { - /* if there's a list of paths to select, the current mount - * entry matches in path or device name, get fs usage */ - if (path_select_list && - (walk_name_list (path_select_list, me->me_mountdir) || - walk_name_list (path_select_list, me->me_devname) ) ) { - get_fs_usage (me->me_mountdir, me->me_devname, &fsp); - /* else if there's a list of paths/devices to select (but - * we didn't match above) skip to the next mount entry */ - } else if (dev_select_list || path_select_list) { - continue; - /* skip remote filesystems if we're not interested in them */ - } else if (me->me_remote && show_local_fs) { - continue; - /* skip pseudo fs's if we haven't asked for all fs's */ - } else if (me->me_dummy && !show_all_fs) { - continue; - /* skip excluded fstypes */ - } else if (fs_exclude_list && walk_name_list (fs_exclude_list, me->me_type)) { - continue; - /* skip excluded fs's */ - } else if (dp_exclude_list && - (walk_name_list (dp_exclude_list, me->me_devname) || - walk_name_list (dp_exclude_list, me->me_mountdir))) { - continue; - /* otherwise, get fs usage */ - } else { - get_fs_usage (me->me_mountdir, me->me_devname, &fsp); - } - - if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) { - usp = (double)(fsp.fsu_blocks - fsp.fsu_bavail) * 100 / fsp.fsu_blocks; + double usp = -1.0, uisp = -1.0; + int result = STATE_UNKNOWN; + int disk_result = STATE_UNKNOWN; + char file_system[MAX_INPUT_BUFFER]; + char *output; + char *details; + char *perf; + uintmax_t psize; + float free_space, free_space_pct, total_space, inode_space_pct; + + struct mount_entry *me; + struct fs_usage fsp; + struct name_list *temp_list; + + output = strdup (" - free space:"); + details = strdup (""); + perf = strdup (""); + + setlocale (LC_ALL, ""); + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); + + mount_list = read_filesystem_list (0); + + if (process_arguments (argc, argv) == ERROR) + usage4 (_("Could not parse arguments")); + + /* if a list of paths has been selected, preseed the list with + * the longest matching filesystem name by iterating across + * the mountlist once ahead of time. this will allow a query on + * "/var/log" to return information about "/var" if no "/var/log" + * filesystem exists, etc. this is the default behavior already + * with df-based checks, but for systems with their own space + * checking routines, this should make them more consistent. + */ + if(path_select_list){ + for (me = mount_list; me; me = me->me_next) { + walk_name_list(path_select_list, me->me_mountdir); + walk_name_list(path_select_list, me->me_devname); + } + /* now pretend we never saw anything, but keep found_len. + * thus future searches will only match the best match */ + for (temp_list = path_select_list; temp_list; temp_list=temp_list->name_next){ + temp_list->found=0; + } + } + + /* for every mount entry */ + for (me = mount_list; me; me = me->me_next) { + /* if there's a list of paths to select, the current mount + * entry matches in path or device name, get fs usage */ + if (path_select_list && + (walk_name_list (path_select_list, me->me_mountdir) || + walk_name_list (path_select_list, me->me_devname) ) ) { + get_fs_usage (me->me_mountdir, me->me_devname, &fsp); + /* else if there's a list of paths/devices to select (but + * we didn't match above) skip to the next mount entry */ + } else if (dev_select_list || path_select_list) { + continue; + /* skip remote filesystems if we're not interested in them */ + } else if (me->me_remote && show_local_fs) { + continue; + /* skip pseudo fs's if we haven't asked for all fs's */ + } else if (me->me_dummy && !show_all_fs) { + continue; + /* skip excluded fstypes */ + } else if (fs_exclude_list && walk_name_list (fs_exclude_list, me->me_type)) { + continue; + /* skip excluded fs's */ + } else if (dp_exclude_list && + (walk_name_list (dp_exclude_list, me->me_devname) || + walk_name_list (dp_exclude_list, me->me_mountdir))) { + continue; + /* otherwise, get fs usage */ + } else { + get_fs_usage (me->me_mountdir, me->me_devname, &fsp); + } + + if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) { + usp = (double)(fsp.fsu_blocks - fsp.fsu_bavail) * 100 / fsp.fsu_blocks; uisp = (double)(fsp.fsu_files - fsp.fsu_ffree) * 100 / fsp.fsu_files; - disk_result = check_disk (usp, fsp.fsu_bavail, uisp); + disk_result = check_disk (usp, fsp.fsu_bavail, uisp); - result = max_state (disk_result, result); - psize = fsp.fsu_blocks*fsp.fsu_blocksize/mult; + result = max_state (disk_result, result); + psize = fsp.fsu_blocks*fsp.fsu_blocksize/mult; /* Moved this computation up here so we can add it @@ -242,56 +242,56 @@ main (int argc, char **argv) inode_space_pct = (float)fsp.fsu_ffree*100/fsp.fsu_files; - asprintf (&perf, "%s %s", perf, - perfdata ((!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir, - psize-(fsp.fsu_bavail*fsp.fsu_blocksize/mult), units, - TRUE, min ((uintmax_t)psize-(uintmax_t)w_df, (uintmax_t)((1.0-w_dfp/100.0)*psize)), - TRUE, min ((uintmax_t)psize-(uintmax_t)c_df, (uintmax_t)((1.0-c_dfp/100.0)*psize)), + asprintf (&perf, "%s %s", perf, + perfdata ((!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir, + psize-(fsp.fsu_bavail*fsp.fsu_blocksize/mult), units, + TRUE, min ((uintmax_t)psize-(uintmax_t)w_df, (uintmax_t)((1.0-w_dfp/100.0)*psize)), + TRUE, min ((uintmax_t)psize-(uintmax_t)c_df, (uintmax_t)((1.0-c_dfp/100.0)*psize)), TRUE, inode_space_pct, - TRUE, psize)); - if (disk_result==STATE_OK && erronly && !verbose) - continue; - - free_space = (float)fsp.fsu_bavail*fsp.fsu_blocksize/mult; - free_space_pct = (float)fsp.fsu_bavail*100/fsp.fsu_blocks; - total_space = (float)fsp.fsu_blocks*fsp.fsu_blocksize/mult; - if (disk_result!=STATE_OK || verbose>=0) - asprintf (&output, ("%s %s %.0f %s (%.0f%% inode=%.0f%%);"), - output, - (!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir, - free_space, - units, - free_space_pct, - inode_space_pct); - - asprintf (&details, _("%s\n\ + TRUE, psize)); + if (disk_result==STATE_OK && erronly && !verbose) + continue; + + free_space = (float)fsp.fsu_bavail*fsp.fsu_blocksize/mult; + free_space_pct = (float)fsp.fsu_bavail*100/fsp.fsu_blocks; + total_space = (float)fsp.fsu_blocks*fsp.fsu_blocksize/mult; + if (disk_result!=STATE_OK || verbose>=0) + asprintf (&output, ("%s %s %.0f %s (%.0f%% inode=%.0f%%);"), + output, + (!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir, + free_space, + units, + free_space_pct, + inode_space_pct); + + asprintf (&details, _("%s\n\ %.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"), - details, free_space, total_space, units, free_space_pct, inode_space_pct, - me->me_devname, me->me_type, me->me_mountdir, - (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp); + details, free_space, total_space, units, free_space_pct, inode_space_pct, + me->me_devname, me->me_type, me->me_mountdir, + (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp); - } + } - } + } - asprintf (&output, "%s|%s", output, perf); + asprintf (&output, "%s|%s", output, perf); - if (verbose > 2) - asprintf (&output, "%s%s", output, details); + if (verbose > 2) + asprintf (&output, "%s%s", output, details); - /* Override result if paths specified and not found */ - temp_list = path_select_list; - while (temp_list) { - if (!temp_list->found) { - asprintf (&output, _("%s [%s not found]"), output, temp_list->name); - result = STATE_CRITICAL; - } - temp_list = temp_list->name_next; - } + /* Override result if paths specified and not found */ + temp_list = path_select_list; + while (temp_list) { + if (!temp_list->found) { + asprintf (&output, _("%s [%s not found]"), output, temp_list->name); + result = STATE_CRITICAL; + } + temp_list = temp_list->name_next; + } - printf ("DISK %s%s\n", state_text (result), output); - return result; + printf ("DISK %s%s\n", state_text (result), output); + return result; } @@ -300,106 +300,106 @@ main (int argc, char **argv) int process_arguments (int argc, char **argv) { - int c; - struct name_list *se; - struct name_list **pathtail = &path_select_list; - struct name_list **fstail = &fs_exclude_list; - struct name_list **dptail = &dp_exclude_list; - struct name_list *temp_list; - int result = OK; - - unsigned long l; - - int option = 0; - static struct option longopts[] = { - {"timeout", required_argument, 0, 't'}, - {"warning", required_argument, 0, 'w'}, - {"critical", required_argument, 0, 'c'}, - {"iwarning", required_argument, 0, 'W'}, - /* Dang, -C is taken. We might want to reshuffle this. */ - {"icritical", required_argument, 0, 'K'}, - {"local", required_argument, 0, 'l'}, - {"kilobytes", required_argument, 0, 'k'}, - {"megabytes", required_argument, 0, 'm'}, - {"units", required_argument, 0, 'u'}, - {"path", required_argument, 0, 'p'}, - {"partition", required_argument, 0, 'p'}, - {"exclude_device", required_argument, 0, 'x'}, - {"exclude-type", required_argument, 0, 'X'}, - {"mountpoint", no_argument, 0, 'M'}, - {"errors-only", no_argument, 0, 'e'}, - {"verbose", no_argument, 0, 'v'}, - {"quiet", no_argument, 0, 'q'}, - {"clear", no_argument, 0, 'C'}, - {"version", no_argument, 0, 'V'}, - {"help", no_argument, 0, 'h'}, - {0, 0, 0, 0} - }; - - if (argc < 2) - return ERROR; - - se = (struct name_list *) malloc (sizeof (struct name_list)); - se->name = strdup ("iso9660"); - se->name_next = NULL; - se->found = 0; - se->found_len = 0; - *fstail = se; - fstail = &se->name_next; - - for (c = 1; c < argc; c++) - if (strcmp ("-to", argv[c]) == 0) - strcpy (argv[c], "-t"); - - while (1) { - c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklM", longopts, &option); - - if (c == -1 || c == EOF) - break; - - switch (c) { - case 't': /* timeout period */ - if (is_integer (optarg)) { - timeout_interval = atoi (optarg); - break; - } - else { - usage2 (_("Timeout interval must be a positive integer"), optarg); - } - case 'w': /* warning threshold */ - if (is_intnonneg (optarg)) { - w_df = atoi (optarg); - break; - } - else if (strpbrk (optarg, ",:") && - strstr (optarg, "%") && - sscanf (optarg, "%lu%*[:,]%lf%%", &l, &w_dfp) == 2) { - w_df = (uintmax_t)l; - break; - } - else if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &w_dfp) == 1) { - break; - } - else { - usage4 (_("Warning threshold must be integer or percentage!")); - } - case 'c': /* critical threshold */ - if (is_intnonneg (optarg)) { - c_df = atoi (optarg); - break; - } - else if (strpbrk (optarg, ",:") && - strstr (optarg, "%") && - sscanf (optarg, "%lu%*[,:]%lf%%", &l, &c_dfp) == 2) { - c_df = (uintmax_t)l; - break; - } - else if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &c_dfp) == 1) { - break; - } - else { - usage4 (_("Critical threshold must be integer or percentage!")); - } + int c; + struct name_list *se; + struct name_list **pathtail = &path_select_list; + struct name_list **fstail = &fs_exclude_list; + struct name_list **dptail = &dp_exclude_list; + struct name_list *temp_list; + int result = OK; + + unsigned long l; + + int option = 0; + static struct option longopts[] = { + {"timeout", required_argument, 0, 't'}, + {"warning", required_argument, 0, 'w'}, + {"critical", required_argument, 0, 'c'}, + {"iwarning", required_argument, 0, 'W'}, + /* Dang, -C is taken. We might want to reshuffle this. */ + {"icritical", required_argument, 0, 'K'}, + {"local", required_argument, 0, 'l'}, + {"kilobytes", required_argument, 0, 'k'}, + {"megabytes", required_argument, 0, 'm'}, + {"units", required_argument, 0, 'u'}, + {"path", required_argument, 0, 'p'}, + {"partition", required_argument, 0, 'p'}, + {"exclude_device", required_argument, 0, 'x'}, + {"exclude-type", required_argument, 0, 'X'}, + {"mountpoint", no_argument, 0, 'M'}, + {"errors-only", no_argument, 0, 'e'}, + {"verbose", no_argument, 0, 'v'}, + {"quiet", no_argument, 0, 'q'}, + {"clear", no_argument, 0, 'C'}, + {"version", no_argument, 0, 'V'}, + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0} + }; + + if (argc < 2) + return ERROR; + + se = (struct name_list *) malloc (sizeof (struct name_list)); + se->name = strdup ("iso9660"); + se->name_next = NULL; + se->found = 0; + se->found_len = 0; + *fstail = se; + fstail = &se->name_next; + + for (c = 1; c < argc; c++) + if (strcmp ("-to", argv[c]) == 0) + strcpy (argv[c], "-t"); + + while (1) { + c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklM", longopts, &option); + + if (c == -1 || c == EOF) + break; + + switch (c) { + case 't': /* timeout period */ + if (is_integer (optarg)) { + timeout_interval = atoi (optarg); + break; + } + else { + usage2 (_("Timeout interval must be a positive integer"), optarg); + } + case 'w': /* warning threshold */ + if (is_intnonneg (optarg)) { + w_df = atoi (optarg); + break; + } + else if (strpbrk (optarg, ",:") && + strstr (optarg, "%") && + sscanf (optarg, "%lu%*[:,]%lf%%", &l, &w_dfp) == 2) { + w_df = (uintmax_t)l; + break; + } + else if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &w_dfp) == 1) { + break; + } + else { + usage4 (_("Warning threshold must be integer or percentage!")); + } + case 'c': /* critical threshold */ + if (is_intnonneg (optarg)) { + c_df = atoi (optarg); + break; + } + else if (strpbrk (optarg, ",:") && + strstr (optarg, "%") && + sscanf (optarg, "%lu%*[,:]%lf%%", &l, &c_dfp) == 2) { + c_df = (uintmax_t)l; + break; + } + else if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &c_dfp) == 1) { + break; + } + else { + usage4 (_("Critical threshold must be integer or percentage!")); + } case 'W': /* warning inode threshold */ @@ -407,71 +407,71 @@ process_arguments (int argc, char **argv) break; } else { - usage (_("Warning inode threshold must be percentage!\n")); - } + usage (_("Warning inode threshold must be percentage!\n")); + } case 'K': /* kritical inode threshold */ if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &c_idfp) == 1) { break; } else { - usage (_("Critical inode threshold must be percentage!\n")); + usage (_("Critical inode threshold must be percentage!\n")); } - case 'u': - if (units) - free(units); - if (! strcmp (optarg, "bytes")) { - mult = (uintmax_t)1; - units = strdup ("B"); - } else if (! strcmp (optarg, "kB")) { - mult = (uintmax_t)1024; - units = strdup ("kB"); - } else if (! strcmp (optarg, "MB")) { - mult = (uintmax_t)1024 * 1024; - units = strdup ("MB"); - } else if (! strcmp (optarg, "GB")) { - mult = (uintmax_t)1024 * 1024 * 1024; - units = strdup ("GB"); - } else if (! strcmp (optarg, "TB")) { - mult = (uintmax_t)1024 * 1024 * 1024 * 1024; - units = strdup ("TB"); - } else { - die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg); - } - if (units == NULL) - die (STATE_UNKNOWN, _("failed allocating storage for '%s'\n"), "units"); - break; - case 'k': /* display mountpoint */ - mult = 1024; - if (units) - free(units); - units = strdup ("kB"); - break; - case 'm': /* display mountpoint */ - mult = 1024 * 1024; - if (units) - free(units); - units = strdup ("MB"); - break; - case 'l': - show_local_fs = 1; - break; - case 'p': /* select path */ - se = (struct name_list *) malloc (sizeof (struct name_list)); - se->name = optarg; - se->name_next = NULL; - se->w_df = w_df; - se->c_df = c_df; - se->w_dfp = w_dfp; - se->c_dfp = c_dfp; - se->found = 0; - se->found_len = 0; - *pathtail = se; - pathtail = &se->name_next; - break; - case 'x': /* exclude path or partition */ - se = (struct name_list *) malloc (sizeof (struct name_list)); - se->name = optarg; - se->name_next = NULL; + case 'u': + if (units) + free(units); + if (! strcmp (optarg, "bytes")) { + mult = (uintmax_t)1; + units = strdup ("B"); + } else if (! strcmp (optarg, "kB")) { + mult = (uintmax_t)1024; + units = strdup ("kB"); + } else if (! strcmp (optarg, "MB")) { + mult = (uintmax_t)1024 * 1024; + units = strdup ("MB"); + } else if (! strcmp (optarg, "GB")) { + mult = (uintmax_t)1024 * 1024 * 1024; + units = strdup ("GB"); + } else if (! strcmp (optarg, "TB")) { + mult = (uintmax_t)1024 * 1024 * 1024 * 1024; + units = strdup ("TB"); + } else { + die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg); + } + if (units == NULL) + die (STATE_UNKNOWN, _("failed allocating storage for '%s'\n"), "units"); + break; + case 'k': /* display mountpoint */ + mult = 1024; + if (units) + free(units); + units = strdup ("kB"); + break; + case 'm': /* display mountpoint */ + mult = 1024 * 1024; + if (units) + free(units); + units = strdup ("MB"); + break; + case 'l': + show_local_fs = 1; + break; + case 'p': /* select path */ + se = (struct name_list *) malloc (sizeof (struct name_list)); + se->name = optarg; + se->name_next = NULL; + se->w_df = w_df; + se->c_df = c_df; + se->w_dfp = w_dfp; + se->c_dfp = c_dfp; + se->found = 0; + se->found_len = 0; + *pathtail = se; + pathtail = &se->name_next; + break; + case 'x': /* exclude path or partition */ + se = (struct name_list *) malloc (sizeof (struct name_list)); + se->name = optarg; + se->name_next = NULL; /* If you don't clear the w_fd etc values here, they * get processed when you walk the list and assigned @@ -481,15 +481,15 @@ process_arguments (int argc, char **argv) se->c_df = 0; se->w_dfp = 0; se->c_dfp = 0; - se->found = 0; - se->found_len = 0; - *dptail = se; - dptail = &se->name_next; - break; - case 'X': /* exclude file system type */ - se = (struct name_list *) malloc (sizeof (struct name_list)); - se->name = optarg; - se->name_next = NULL; + se->found = 0; + se->found_len = 0; + *dptail = se; + dptail = &se->name_next; + break; + case 'X': /* exclude file system type */ + se = (struct name_list *) malloc (sizeof (struct name_list)); + se->name = optarg; + se->name_next = NULL; /* If you don't clear the w_fd etc values here, they * get processed when you walk the list and assigned * to the global w_df! @@ -498,78 +498,78 @@ process_arguments (int argc, char **argv) se->c_df = 0; se->w_dfp = 0; se->c_dfp = 0; - se->found = 0; - se->found_len = 0; - *fstail = se; - fstail = &se->name_next; - break; - case 'v': /* verbose */ - verbose++; - break; - case 'q': /* verbose */ - verbose--; - break; - case 'e': - erronly = TRUE; - break; - case 'M': /* display mountpoint */ - display_mntp = TRUE; - break; - case 'C': - w_df = 0; - c_df = 0; - w_dfp = -1.0; - c_dfp = -1.0; - break; - case 'V': /* version */ - print_revision (progname, revision); - exit (STATE_OK); - case 'h': /* help */ - print_help (); - exit (STATE_OK); - case '?': /* help */ - usage2 (_("Unknown argument"), optarg); - } - } - - /* Support for "check_disk warn crit [fs]" with thresholds at used level */ - c = optind; - if (w_dfp < 0 && argc > c && is_intnonneg (argv[c])) - w_dfp = (100.0 - atof (argv[c++])); - - if (c_dfp < 0 && argc > c && is_intnonneg (argv[c])) - c_dfp = (100.0 - atof (argv[c++])); - - if (argc > c && path == NULL) { - se = (struct name_list *) malloc (sizeof (struct name_list)); - se->name = strdup (argv[c++]); - se->name_next = NULL; - se->w_df = w_df; - se->c_df = c_df; - se->w_dfp = w_dfp; - se->c_dfp = c_dfp; - se->found =0; - se->found_len = 0; - *pathtail = se; - } - - if (path_select_list) { - temp_list = path_select_list; - while (temp_list) { - if (validate_arguments (temp_list->w_df, - temp_list->c_df, - temp_list->w_dfp, - temp_list->c_dfp, - temp_list->w_idfp, - temp_list->c_idfp, - temp_list->name) == ERROR) - result = ERROR; - temp_list = temp_list->name_next; - } - return result; - } else { - return validate_arguments (w_df, c_df, w_dfp, c_dfp, w_idfp, c_idfp, NULL); - } + se->found = 0; + se->found_len = 0; + *fstail = se; + fstail = &se->name_next; + break; + case 'v': /* verbose */ + verbose++; + break; + case 'q': /* verbose */ + verbose--; + break; + case 'e': + erronly = TRUE; + break; + case 'M': /* display mountpoint */ + display_mntp = TRUE; + break; + case 'C': + w_df = 0; + c_df = 0; + w_dfp = -1.0; + c_dfp = -1.0; + break; + case 'V': /* version */ + print_revision (progname, revision); + exit (STATE_OK); + case 'h': /* help */ + print_help (); + exit (STATE_OK); + case '?': /* help */ + usage (_("Unknown argument")); + } + } + + /* Support for "check_disk warn crit [fs]" with thresholds at used level */ + c = optind; + if (w_dfp < 0 && argc > c && is_intnonneg (argv[c])) + w_dfp = (100.0 - atof (argv[c++])); + + if (c_dfp < 0 && argc > c && is_intnonneg (argv[c])) + c_dfp = (100.0 - atof (argv[c++])); + + if (argc > c && path == NULL) { + se = (struct name_list *) malloc (sizeof (struct name_list)); + se->name = strdup (argv[c++]); + se->name_next = NULL; + se->w_df = w_df; + se->c_df = c_df; + se->w_dfp = w_dfp; + se->c_dfp = c_dfp; + se->found =0; + se->found_len = 0; + *pathtail = se; + } + + if (path_select_list) { + temp_list = path_select_list; + while (temp_list) { + if (validate_arguments (temp_list->w_df, + temp_list->c_df, + temp_list->w_dfp, + temp_list->c_dfp, + temp_list->w_idfp, + temp_list->c_idfp, + temp_list->name) == ERROR) + result = ERROR; + temp_list = temp_list->name_next; + } + return result; + } else { + return validate_arguments (w_df, c_df, w_dfp, c_dfp, w_idfp, c_idfp, NULL); + } } @@ -577,12 +577,12 @@ process_arguments (int argc, char **argv) void print_path (const char *mypath) { - if (mypath == NULL) - printf ("\n"); - else - printf (_(" for %s\n"), mypath); + if (mypath == NULL) + printf ("\n"); + else + printf (_(" for %s\n"), mypath); - return; + return; } @@ -590,40 +590,40 @@ print_path (const char *mypath) int validate_arguments (uintmax_t w, uintmax_t c, double wp, double cp, double iwp, double icp, char *mypath) { - if (w < 0 && c < 0 && wp < 0.0 && cp < 0.0) { - printf (_("INPUT ERROR: No thresholds specified")); - print_path (mypath); - return ERROR; - } - else if ((wp >= 0.0 || cp >= 0.0) && - (wp < 0.0 || cp < 0.0 || wp > 100.0 || cp > 100.0 || cp > wp)) { - printf (_("\ + if (w < 0 && c < 0 && wp < 0.0 && cp < 0.0) { + printf (_("INPUT ERROR: No thresholds specified")); + print_path (mypath); + return ERROR; + } + else if ((wp >= 0.0 || cp >= 0.0) && + (wp < 0.0 || cp < 0.0 || wp > 100.0 || cp > 100.0 || cp > wp)) { + printf (_("\ INPUT ERROR: C_DFP (%f) should be less than W_DFP (%.1f) and both should be between zero and 100 percent, inclusive"), - cp, wp); - print_path (mypath); - return ERROR; - } - else if ((iwp >= 0.0 || icp >= 0.0) && - (iwp < 0.0 || icp < 0.0 || iwp > 100.0 || icp > 100.0 || icp > iwp)) { - printf (_("\ + cp, wp); + print_path (mypath); + return ERROR; + } + else if ((iwp >= 0.0 || icp >= 0.0) && + (iwp < 0.0 || icp < 0.0 || iwp > 100.0 || icp > 100.0 || icp > iwp)) { + printf (_("\ INPUT ERROR: C_IDFP (%f) should be less than W_IDFP (%.1f) and both should be between zero and 100 percent, inclusive"), - icp, iwp); - print_path (mypath); - return ERROR; - } - else if ((w > 0 || c > 0) && (w == 0 || c == 0 || c > w)) { - printf (_("\ + icp, iwp); + print_path (mypath); + return ERROR; + } + else if ((w > 0 || c > 0) && (w == 0 || c == 0 || c > w)) { + printf (_("\ INPUT ERROR: C_DF (%lu) should be less than W_DF (%lu) and both should be greater than zero"), - (unsigned long)c, (unsigned long)w); - print_path (mypath); - return ERROR; - } - - if (units == NULL) { - units = strdup ("MB"); - mult = (uintmax_t)1024 * 1024; - } - return OK; + (unsigned long)c, (unsigned long)w); + print_path (mypath); + return ERROR; + } + + if (units == NULL) { + units = strdup ("MB"); + mult = (uintmax_t)1024 * 1024; + } + return OK; } @@ -647,8 +647,8 @@ check_disk (double usp, uintmax_t free_disk, double uisp) else if (w_df > 0 && free_disk <= w_df) result = STATE_WARNING; else if (usp >= 0.0) - result = STATE_OK; - return result; + result = STATE_OK; + return result; } @@ -656,26 +656,26 @@ check_disk (double usp, uintmax_t free_disk, double uisp) int walk_name_list (struct name_list *list, const char *name) { - int name_len; - name_len = strlen(name); - while (list) { - /* if the paths match up to the length of the mount path, - * AND if the mount path name is longer than the longest - * found match, we have a new winner */ - if (name_len >= list->found_len && - ! strncmp(list->name, name, name_len)) { - list->found = 1; - list->found_len = name_len; - /* if required for name_lists that have not saved w_df, etc (eg exclude lists) */ - if (list->w_df) w_df = list->w_df; - if (list->c_df) c_df = list->c_df; - if (list->w_dfp>=0.0) w_dfp = list->w_dfp; - if (list->c_dfp>=0.0) c_dfp = list->c_dfp; - return TRUE; - } - list = list->name_next; - } - return FALSE; + int name_len; + name_len = strlen(name); + while (list) { + /* if the paths match up to the length of the mount path, + * AND if the mount path name is longer than the longest + * found match, we have a new winner */ + if (name_len >= list->found_len && + ! strncmp(list->name, name, name_len)) { + list->found = 1; + list->found_len = name_len; + /* if required for name_lists that have not saved w_df, etc (eg exclude lists) */ + if (list->w_df) w_df = list->w_df; + if (list->c_df) c_df = list->c_df; + if (list->w_dfp>=0.0) w_dfp = list->w_dfp; + if (list->c_dfp>=0.0) c_dfp = list->c_dfp; + return TRUE; + } + list = list->name_next; + } + return FALSE; } @@ -683,68 +683,163 @@ walk_name_list (struct name_list *list, const char *name) void print_help (void) { - print_revision (progname, revision); - - printf ("Copyright (c) 1999 Ethan Galstad \n"); - printf (COPYRIGHT, copyright, email); - - printf (_("\ -This plugin checks the amount of used disk space on a mounted file system\n\ -and generates an alert if free space is less than one of the threshold values.\n\n")); - - print_usage (); - - printf (_(UT_HELP_VRSN)); - - printf (_("\ - -w, --warning=INTEGER\n\ - Exit with WARNING status if less than INTEGER --units of disk are free\n\ - -w, --warning=PERCENT%%\n\ - Exit with WARNING status if less than PERCENT of disk space is free\n\ - -W, --iwarning=PERCENT%%\n\ - Exit with WARNING status if less than PERCENT of inode space is free\n\ - -K, --icritical=PERCENT%%\n\ - Exit with CRITICAL status if less than PERCENT of inode space is free\n\ - -c, --critical=INTEGER\n\ - Exit with CRITICAL status if less than INTEGER --units of disk are free\n\ - -c, --critical=PERCENT%%\n\ - Exit with CRITCAL status if less than PERCENT of disk space is free\n\ - -C, --clear\n\ - Clear thresholds\n")); - - printf (_("\ - -u, --units=STRING\n\ - Choose bytes, kB, MB, GB, TB (default: MB)\n\ - -k, --kilobytes\n\ - Same as '--units kB'\n\ - -m, --megabytes\n\ - Same as '--units MB'\n")); - - printf (_("\ - -l, --local\n\ - Only check local filesystems\n\ - -p, --path=PATH, --partition=PARTITION\n\ - Path or partition (may be repeated)\n\ - -x, --exclude_device=PATH \n\ - Ignore device (only works if -p unspecified)\n\ - -X, --exclude-type=TYPE \n\ - Ignore all filesystems of indicated type (may be repeated)\n\ - -M, --mountpoint\n\ - Display the mountpoint instead of the partition\n\ - -e, --errors-only\n\ - Display only devices/mountpoints with errors\n")); - - printf (_(UT_WARN_CRIT)); - - printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); - - printf (_(UT_VERBOSE)); - - printf ("%s", _("Examples:\n\ - check_disk -w 10% -c 5% -p /tmp -p /var -C -w 100000 -c 50000 -p /\n\ - Checks /tmp and /var at 10%,5% and / at 100MB, 50MB\n")); - - printf (_(UT_SUPPORT)); + print_revision (progname, revision); + + printf ("Copyright (c) 1999 Ethan Galstad \n"); + printf (COPYRIGHT, copyright, email); + + printf (_("This plugin checks the amount of used disk space on a mounted file system")); + printf (_("and generates an alert if free space is less than one of the threshold values")); + + printf ("\n\n"); + + print_usage (); + + printf (_(UT_HELP_VRSN)); + + printf (" -w, --warning=INTEGER"); + + printf ("\n"); + + printf (_("exit with WARNING status if less than INTEGER units of disk are free")); + + printf (" -w, --warning=PERCENT%%"); + + printf ("\n"); + + printf (_("exit with WARNING status if less than PERCENT of disk space is free")); + + printf ("\n"); + + printf (" -W, --iwarning=PERCENT%%"); + + printf ("\n"); + + printf (_("exit with WARNING status if less than PERCENT of inode space is free")); + + printf ("\n"); + + printf (" -K, --icritical=PERCENT%%"); + + printf ("\n"); + + printf (_("exit with CRITICAL status if less than PERCENT of inode space is free")); + + printf ("\n"); + + printf (" -c, --critical=INTEGER"); + + printf ("\n"); + + printf (_("exit with CRITICAL status if less than INTEGER --units of disk are free")); + + printf ("\n"); + + printf (" -c, --critical=PERCENT%%"); + + printf ("\n"); + + printf (_("exit with CRITCAL status if less than PERCENT of disk space is free")); + + printf ("\n"); + + printf (" -C, --clear"); + + printf ("\n"); + + printf (_("clear thresholds")); + + printf ("\n"); + + printf (" -u, --units=STRING"); + + printf ("\n"); + + printf (_("choose bytes, kB, MB, GB, TB (default: MB)")); + + printf ("\n"); + + printf (" -k, --kilobytes"); + + printf ("\n"); + + printf (_("same as '--units kB'")); + + printf ("\n"); + + printf (" -m, --megabytes"); + + printf ("\n"); + + printf (_("same as '--units MB'\n")); + + printf (" -l, --local"); + + printf ("\n"); + + printf (_("only check local filesystems")); + + printf ("\n"); + + printf (" -p, --path=PATH, --partition=PARTITION"); + + printf ("\n"); + + printf (_("path or partition (may be repeated)")); + + printf ("\n"); + + printf (" -x, --exclude_device=PATH "); + + printf ("\n"); + + printf (_("ignore device (only works if -p unspecified)")); + + printf ("\n"); + + printf (" -X, --exclude-type=TYPE "); + + printf ("\n"); + + printf (_("ignore all filesystems of indicated type (may be repeated)")); + + printf ("\n"); + + printf ("-m, --mountpoint"); + + printf ("\n"); + + printf (_("display the mountpoint instead of the partition")); + + printf ("\n"); + + printf ("-e, --errors-only"); + + printf ("\n"); + + printf (_("display only devices/mountpoints with errors")); + + printf ("\n"); + + printf (_(UT_WARN_CRIT)); + + printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); + + printf (_(UT_VERBOSE)); + + printf (_("examples:")); + + printf ("\n"); + + printf ("check_disk -w 10% -c 5% -p /tmp -p /var -C -w 100000 -c 50000 -p /"); + + printf ("\n"); + + printf (_("checks /tmp and /var at 10% and 5% and / at 100MB, 50MB")); + + printf ("\n"); + + printf (_(UT_SUPPORT)); } @@ -752,7 +847,7 @@ and generates an alert if free space is less than one of the threshold values.\n void print_usage (void) { - printf ("\ -Usage: %s -w limit -c limit [-p path | -x device] [-t timeout] [-m] [-e] [-W limit] [-K limit]\n\ - [-v] [-q]\n", progname); + printf (_("Usage:")); + printf (" %s -w limit -c limit [-p path | -x device] [-t timeout]", progname); + printf ("[-m] [-e] [-W limit] [-K limit] [-v] [-q]\n"); } diff --git a/plugins/check_dns.c b/plugins/check_dns.c index d6e8ca2..faa1e15 100644 --- a/plugins/check_dns.c +++ b/plugins/check_dns.c @@ -23,7 +23,7 @@ const char *progname = "check_dns"; const char *revision = "$Revision$"; -const char *copyright = "2000-2004"; +const char *copyright = "2000-2005"; const char *email = "nagiosplug-devel@lists.sourceforge.net"; #include "common.h" @@ -49,156 +49,156 @@ int expect_authority = FALSE; int main (int argc, char **argv) { - char *command_line = NULL; - char input_buffer[MAX_INPUT_BUFFER]; - char *address = NULL; - char *msg = NULL; - char *temp_buffer = NULL; - int non_authoritative = FALSE; - int result = STATE_UNKNOWN; - double elapsed_time; - long microsec; - struct timeval tv; - int multi_address; - int parse_address = FALSE; /* This flag scans for Address: but only after Name: */ - output chld_out, chld_err; - size_t i; - - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE, LOCALEDIR); - textdomain (PACKAGE); - - /* Set signal handling and alarm */ - if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) { - usage_va(_("Cannot catch SIGALRM")); - } - - if (process_arguments (argc, argv) == ERROR) { - usage_va(_("Could not parse arguments")); - } - - /* get the command to run */ - asprintf (&command_line, "%s %s %s", NSLOOKUP_COMMAND, query_address, dns_server); - - alarm (timeout_interval); - gettimeofday (&tv, NULL); - - if (verbose) - printf ("%s\n", command_line); - - /* run the command */ - if((np_runcmd(command_line, &chld_out, &chld_err, 0)) != 0) { - msg = (char *)_("nslookup returned error status"); - result = STATE_WARNING; - } - - /* scan stdout */ - for(i = 0; i < chld_out.lines; i++) { - if (verbose) - puts(chld_out.line[i]); - - if (strstr (chld_out.line[i], ".in-addr.arpa")) { - if ((temp_buffer = strstr (chld_out.line[i], "name = "))) - address = strdup (temp_buffer + 7); - else { - msg = (char *)_("Warning plugin error"); - result = STATE_WARNING; - } - } - - /* the server is responding, we just got the host name... */ - if (strstr (chld_out.line[i], "Name:")) - parse_address = TRUE; - else if (parse_address == TRUE && (strstr (chld_out.line[i], "Address:") || - strstr (chld_out.line[i], "Addresses:"))) { - temp_buffer = index (chld_out.line[i], ':'); - temp_buffer++; - - /* Strip leading spaces */ - for (; *temp_buffer != '\0' && *temp_buffer == ' '; temp_buffer++) - /* NOOP */; - - strip(temp_buffer); - if (temp_buffer==NULL || strlen(temp_buffer)==0) { - die (STATE_CRITICAL, - _("DNS CRITICAL - '%s' returned empty host name string\n"), - NSLOOKUP_COMMAND); - } - - if (address == NULL) - address = strdup (temp_buffer); - else - asprintf(&address, "%s,%s", address, temp_buffer); - } - - else if (strstr (chld_out.line[i], _("Non-authoritative answer:"))) { - non_authoritative = TRUE; - } - - result = error_scan (chld_out.line[i]); - if (result != STATE_OK) { - msg = strchr (chld_out.line[i], ':'); - if(msg) msg++; - break; - } - } - - /* scan stderr */ - for(i = 0; i < chld_err.lines; i++) { - if (verbose) - puts(chld_err.line[i]); - - if (error_scan (chld_err.line[i]) != STATE_OK) { - result = max_state (result, error_scan (chld_err.line[i])); - msg = strchr(input_buffer, ':'); - if(msg) msg++; - } - } - - /* If we got here, we should have an address string, - * and we can segfault if we do not */ - if (address==NULL || strlen(address)==0) - die (STATE_CRITICAL, - _("DNS CRITICAL - '%s' msg parsing exited with no address\n"), - NSLOOKUP_COMMAND); - - /* compare to expected address */ - if (result == STATE_OK && match_expected_address && strcmp(address, expected_address)) { - result = STATE_CRITICAL; - asprintf(&msg, _("expected %s but got %s"), expected_address, address); - } - - /* check if authoritative */ - if (result == STATE_OK && expect_authority && non_authoritative) { - result = STATE_CRITICAL; - asprintf(&msg, _("server %s is not authoritative for %s"), dns_server, query_address); - } - - microsec = deltime (tv); - elapsed_time = (double)microsec / 1.0e6; - - if (result == STATE_OK) { - if (strchr (address, ',') == NULL) - multi_address = FALSE; - else - multi_address = TRUE; - - printf ("DNS %s: ", _("OK")); - printf (ngettext("%.3f second response time", "%.3f seconds response time", elapsed_time), elapsed_time); - printf (_(". %s returns %s"), query_address, address); - printf ("|%s\n", fperfdata ("time", elapsed_time, "s", FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0)); - } - else if (result == STATE_WARNING) - printf (_("DNS WARNING - %s\n"), - !strcmp (msg, "") ? _(" Probably a non-existent host/domain") : msg); - else if (result == STATE_CRITICAL) - printf (_("DNS CRITICAL - %s\n"), - !strcmp (msg, "") ? _(" Probably a non-existent host/domain") : msg); - else - printf (_("DNS UNKNOW - %s\n"), - !strcmp (msg, "") ? _(" Probably a non-existent host/domain") : msg); - - return result; + char *command_line = NULL; + char input_buffer[MAX_INPUT_BUFFER]; + char *address = NULL; + char *msg = NULL; + char *temp_buffer = NULL; + int non_authoritative = FALSE; + int result = STATE_UNKNOWN; + double elapsed_time; + long microsec; + struct timeval tv; + int multi_address; + int parse_address = FALSE; /* This flag scans for Address: but only after Name: */ + output chld_out, chld_err; + size_t i; + + setlocale (LC_ALL, ""); + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); + + /* Set signal handling and alarm */ + if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) { + usage_va(_("Cannot catch SIGALRM")); + } + + if (process_arguments (argc, argv) == ERROR) { + usage_va(_("Could not parse arguments")); + } + + /* get the command to run */ + asprintf (&command_line, "%s %s %s", NSLOOKUP_COMMAND, query_address, dns_server); + + alarm (timeout_interval); + gettimeofday (&tv, NULL); + + if (verbose) + printf ("%s\n", command_line); + + /* run the command */ + if((np_runcmd(command_line, &chld_out, &chld_err, 0)) != 0) { + msg = (char *)_("nslookup returned an error status"); + result = STATE_WARNING; + } + + /* scan stdout */ + for(i = 0; i < chld_out.lines; i++) { + if (verbose) + puts(chld_out.line[i]); + + if (strstr (chld_out.line[i], ".in-addr.arpa")) { + if ((temp_buffer = strstr (chld_out.line[i], "name = "))) + address = strdup (temp_buffer + 7); + else { + msg = (char *)_("Warning plugin error"); + result = STATE_WARNING; + } + } + + /* the server is responding, we just got the host name... */ + if (strstr (chld_out.line[i], "Name:")) + parse_address = TRUE; + else if (parse_address == TRUE && (strstr (chld_out.line[i], "Address:") || + strstr (chld_out.line[i], "Addresses:"))) { + temp_buffer = index (chld_out.line[i], ':'); + temp_buffer++; + + /* Strip leading spaces */ + for (; *temp_buffer != '\0' && *temp_buffer == ' '; temp_buffer++) + /* NOOP */; + + strip(temp_buffer); + if (temp_buffer==NULL || strlen(temp_buffer)==0) { + die (STATE_CRITICAL, + _("DNS CRITICAL - '%s' returned empty host name string\n"), + NSLOOKUP_COMMAND); + } + + if (address == NULL) + address = strdup (temp_buffer); + else + asprintf(&address, "%s,%s", address, temp_buffer); + } + + else if (strstr (chld_out.line[i], _("Non-authoritative answer:"))) { + non_authoritative = TRUE; + } + + result = error_scan (chld_out.line[i]); + if (result != STATE_OK) { + msg = strchr (chld_out.line[i], ':'); + if(msg) msg++; + break; + } + } + + /* scan stderr */ + for(i = 0; i < chld_err.lines; i++) { + if (verbose) + puts(chld_err.line[i]); + + if (error_scan (chld_err.line[i]) != STATE_OK) { + result = max_state (result, error_scan (chld_err.line[i])); + msg = strchr(input_buffer, ':'); + if(msg) msg++; + } + } + + /* If we got here, we should have an address string, + * and we can segfault if we do not */ + if (address==NULL || strlen(address)==0) + die (STATE_CRITICAL, + _("DNS CRITICAL - '%s' msg parsing exited with no address\n"), + NSLOOKUP_COMMAND); + + /* compare to expected address */ + if (result == STATE_OK && match_expected_address && strcmp(address, expected_address)) { + result = STATE_CRITICAL; + asprintf(&msg, _("expected %s but got %s"), expected_address, address); + } + + /* check if authoritative */ + if (result == STATE_OK && expect_authority && non_authoritative) { + result = STATE_CRITICAL; + asprintf(&msg, _("server %s is not authoritative for %s"), dns_server, query_address); + } + + microsec = deltime (tv); + elapsed_time = (double)microsec / 1.0e6; + + if (result == STATE_OK) { + if (strchr (address, ',') == NULL) + multi_address = FALSE; + else + multi_address = TRUE; + + printf ("DNS %s: ", _("OK")); + printf (ngettext("%.3f second response time", "%.3f seconds response time", elapsed_time), elapsed_time); + printf (_(". %s returns %s"), query_address, address); + printf ("|%s\n", fperfdata ("time", elapsed_time, "s", FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0)); + } + else if (result == STATE_WARNING) + printf (_("DNS WARNING - %s\n"), + !strcmp (msg, "") ? _(" Probably a non-existent host/domain") : msg); + else if (result == STATE_CRITICAL) + printf (_("DNS CRITICAL - %s\n"), + !strcmp (msg, "") ? _(" Probably a non-existent host/domain") : msg); + else + printf (_("DNS UNKNOW - %s\n"), + !strcmp (msg, "") ? _(" Probably a non-existent host/domain") : msg); + + return result; } @@ -207,56 +207,56 @@ int error_scan (char *input_buffer) { - /* the DNS lookup timed out */ - if (strstr (input_buffer, _("Note: nslookup is deprecated and may be removed from future releases.")) || - strstr (input_buffer, _("Consider using the `dig' or `host' programs instead. Run nslookup with")) || - strstr (input_buffer, _("the `-sil[ent]' option to prevent this message from appearing."))) - return STATE_OK; - - /* DNS server is not running... */ - else if (strstr (input_buffer, "No response from server")) - die (STATE_CRITICAL, _("No response from DNS %s\n"), dns_server); - - /* Host name is valid, but server doesn't have records... */ - else if (strstr (input_buffer, "No records")) - die (STATE_CRITICAL, _("DNS %s has no records\n"), dns_server); - - /* Connection was refused */ - else if (strstr (input_buffer, "Connection refused") || - strstr (input_buffer, "Couldn't find server") || - strstr (input_buffer, "Refused") || - (strstr (input_buffer, "** server can't find") && - strstr (input_buffer, ": REFUSED"))) - die (STATE_CRITICAL, _("Connection to DNS %s was refused\n"), dns_server); - - /* Query refused (usually by an ACL in the namserver) */ - else if (strstr (input_buffer, "Query refused")) - die (STATE_CRITICAL, _("Query was refused by DNS server at %s\n"), dns_server); - - /* No information (e.g. nameserver IP has two PTR records) */ - else if (strstr (input_buffer, "No information")) - die (STATE_CRITICAL, _("No information returned by DNS server at %s\n"), dns_server); - - /* Host or domain name does not exist */ - else if (strstr (input_buffer, "Non-existent") || - strstr (input_buffer, "** server can't find") || - strstr (input_buffer,"NXDOMAIN")) - die (STATE_CRITICAL, _("Domain %s was not found by the server\n"), query_address); - - /* Network is unreachable */ - else if (strstr (input_buffer, "Network is unreachable")) - die (STATE_CRITICAL, _("Network is unreachable\n")); - - /* Internal server failure */ - else if (strstr (input_buffer, "Server failure")) - die (STATE_CRITICAL, _("DNS failure for %s\n"), dns_server); - - /* Request error or the DNS lookup timed out */ - else if (strstr (input_buffer, "Format error") || - strstr (input_buffer, "Timed out")) - return STATE_WARNING; - - return STATE_OK; + /* the DNS lookup timed out */ + if (strstr (input_buffer, _("Note: nslookup is deprecated and may be removed from future releases.")) || + strstr (input_buffer, _("Consider using the `dig' or `host' programs instead. Run nslookup with")) || + strstr (input_buffer, _("the `-sil[ent]' option to prevent this message from appearing."))) + return STATE_OK; + + /* DNS server is not running... */ + else if (strstr (input_buffer, "No response from server")) + die (STATE_CRITICAL, _("No response from DNS %s\n"), dns_server); + + /* Host name is valid, but server doesn't have records... */ + else if (strstr (input_buffer, "No records")) + die (STATE_CRITICAL, _("DNS %s has no records\n"), dns_server); + + /* Connection was refused */ + else if (strstr (input_buffer, "Connection refused") || + strstr (input_buffer, "Couldn't find server") || + strstr (input_buffer, "Refused") || + (strstr (input_buffer, "** server can't find") && + strstr (input_buffer, ": REFUSED"))) + die (STATE_CRITICAL, _("Connection to DNS %s was refused\n"), dns_server); + + /* Query refused (usually by an ACL in the namserver) */ + else if (strstr (input_buffer, "Query refused")) + die (STATE_CRITICAL, _("Query was refused by DNS server at %s\n"), dns_server); + + /* No information (e.g. nameserver IP has two PTR records) */ + else if (strstr (input_buffer, "No information")) + die (STATE_CRITICAL, _("No information returned by DNS server at %s\n"), dns_server); + + /* Host or domain name does not exist */ + else if (strstr (input_buffer, "Non-existent") || + strstr (input_buffer, "** server can't find") || + strstr (input_buffer,"NXDOMAIN")) + die (STATE_CRITICAL, _("Domain %s was not found by the server\n"), query_address); + + /* Network is unreachable */ + else if (strstr (input_buffer, "Network is unreachable")) + die (STATE_CRITICAL, _("Network is unreachable\n")); + + /* Internal server failure */ + else if (strstr (input_buffer, "Server failure")) + die (STATE_CRITICAL, _("DNS failure for %s\n"), dns_server); + + /* Request error or the DNS lookup timed out */ + else if (strstr (input_buffer, "Format error") || + strstr (input_buffer, "Timed out")) + return STATE_WARNING; + + return STATE_OK; } @@ -265,148 +265,177 @@ error_scan (char *input_buffer) int process_arguments (int argc, char **argv) { - int c; - - int opt_index = 0; - static struct option long_opts[] = { - {"help", no_argument, 0, 'h'}, - {"version", no_argument, 0, 'V'}, - {"verbose", no_argument, 0, 'v'}, - {"timeout", required_argument, 0, 't'}, - {"hostname", required_argument, 0, 'H'}, - {"server", required_argument, 0, 's'}, - {"reverse-server", required_argument, 0, 'r'}, - {"expected-address", required_argument, 0, 'a'}, - {"expect-authority", no_argument, 0, 'A'}, - {0, 0, 0, 0} - }; - - if (argc < 2) - return ERROR; - - for (c = 1; c < argc; c++) - if (strcmp ("-to", argv[c]) == 0) - strcpy (argv[c], "-t"); - - while (1) { - c = getopt_long (argc, argv, "hVvAt:H:s:r:a:", long_opts, &opt_index); - - if (c == -1 || c == EOF) - break; - - switch (c) { - case 'h': /* help */ - print_help (); - exit (STATE_OK); - case 'V': /* version */ - print_revision (progname, revision); - exit (STATE_OK); - case 'v': /* version */ - verbose = TRUE; - break; - case 't': /* timeout period */ - timeout_interval = atoi (optarg); - break; - case 'H': /* hostname */ - if (strlen (optarg) >= ADDRESS_LENGTH) - die (STATE_UNKNOWN, _("Input buffer overflow\n")); - strcpy (query_address, optarg); - break; - case 's': /* server name */ - /* TODO: this host_or_die check is probably unnecessary. - * Better to confirm nslookup response matches */ - host_or_die(optarg); - if (strlen (optarg) >= ADDRESS_LENGTH) - die (STATE_UNKNOWN, _("Input buffer overflow\n")); - strcpy (dns_server, optarg); - break; - case 'r': /* reverse server name */ - /* TODO: Is this host_or_die necessary? */ - host_or_die(optarg); - if (strlen (optarg) >= ADDRESS_LENGTH) - die (STATE_UNKNOWN, _("Input buffer overflow\n")); - strcpy (ptr_server, optarg); - break; - case 'a': /* expected address */ - if (strlen (optarg) >= ADDRESS_LENGTH) - die (STATE_UNKNOWN, _("Input buffer overflow\n")); - strcpy (expected_address, optarg); - match_expected_address = TRUE; - break; - case 'A': /* expect authority */ - expect_authority = TRUE; - break; - default: /* args not parsable */ - usage_va(_("Unknown argument - %s"), optarg); - } - } - - c = optind; - if (strlen(query_address)==0 && c=ADDRESS_LENGTH) - die (STATE_UNKNOWN, _("Input buffer overflow\n")); - strcpy (query_address, argv[c++]); - } - - if (strlen(dns_server)==0 && c= ADDRESS_LENGTH) - die (STATE_UNKNOWN, _("Input buffer overflow\n")); - strcpy (dns_server, argv[c++]); - } - - return validate_arguments (); + int c; + + int opt_index = 0; + static struct option long_opts[] = { + {"help", no_argument, 0, 'h'}, + {"version", no_argument, 0, 'V'}, + {"verbose", no_argument, 0, 'v'}, + {"timeout", required_argument, 0, 't'}, + {"hostname", required_argument, 0, 'H'}, + {"server", required_argument, 0, 's'}, + {"reverse-server", required_argument, 0, 'r'}, + {"expected-address", required_argument, 0, 'a'}, + {"expect-authority", no_argument, 0, 'A'}, + {0, 0, 0, 0} + }; + + if (argc < 2) + return ERROR; + + for (c = 1; c < argc; c++) + if (strcmp ("-to", argv[c]) == 0) + strcpy (argv[c], "-t"); + + while (1) { + c = getopt_long (argc, argv, "hVvAt:H:s:r:a:", long_opts, &opt_index); + + if (c == -1 || c == EOF) + break; + + switch (c) { + case 'h': /* help */ + print_help (); + exit (STATE_OK); + case 'V': /* version */ + print_revision (progname, revision); + exit (STATE_OK); + case 'v': /* version */ + verbose = TRUE; + break; + case 't': /* timeout period */ + timeout_interval = atoi (optarg); + break; + case 'H': /* hostname */ + if (strlen (optarg) >= ADDRESS_LENGTH) + die (STATE_UNKNOWN, _("Input buffer overflow\n")); + strcpy (query_address, optarg); + break; + case 's': /* server name */ + /* TODO: this host_or_die check is probably unnecessary. + * Better to confirm nslookup response matches */ + host_or_die(optarg); + if (strlen (optarg) >= ADDRESS_LENGTH) + die (STATE_UNKNOWN, _("Input buffer overflow\n")); + strcpy (dns_server, optarg); + break; + case 'r': /* reverse server name */ + /* TODO: Is this host_or_die necessary? */ + host_or_die(optarg); + if (strlen (optarg) >= ADDRESS_LENGTH) + die (STATE_UNKNOWN, _("Input buffer overflow\n")); + strcpy (ptr_server, optarg); + break; + case 'a': /* expected address */ + if (strlen (optarg) >= ADDRESS_LENGTH) + die (STATE_UNKNOWN, _("Input buffer overflow\n")); + strcpy (expected_address, optarg); + match_expected_address = TRUE; + break; + case 'A': /* expect authority */ + expect_authority = TRUE; + break; + default: /* args not parsable */ + usage_va(_("Unknown argument - %s"), optarg); + } + } + + c = optind; + if (strlen(query_address)==0 && c=ADDRESS_LENGTH) + die (STATE_UNKNOWN, _("Input buffer overflow\n")); + strcpy (query_address, argv[c++]); + } + + if (strlen(dns_server)==0 && c= ADDRESS_LENGTH) + die (STATE_UNKNOWN, _("Input buffer overflow\n")); + strcpy (dns_server, argv[c++]); + } + + return validate_arguments (); } int validate_arguments () { - if (query_address[0] == 0) - return ERROR; + if (query_address[0] == 0) + return ERROR; - return OK; + return OK; } void print_help (void) { - print_revision (progname, revision); + print_revision (progname, revision); - printf ("Copyright (c) 1999 Ethan Galstad \n"); - printf (COPYRIGHT, copyright, email); + printf ("Copyright (c) 1999 Ethan Galstad \n"); + printf (COPYRIGHT, copyright, email); - printf (_("\ -This plugin uses the nslookup program to obtain the IP address\n\ -for the given host/domain query. A optional DNS server to use may\n\ -be specified. If no DNS server is specified, the default server(s)\n\ -specified in /etc/resolv.conf will be used.\n\n")); + printf (_("This plugin uses the nslookup program to obtain the IP address for the given host/domain query.")); + + printf ("\n"); + + printf (_("An optional DNS server to use may be specified.")); + + printf ("\n"); - print_usage (); + printf (_("If no DNS server is specified, the default server(s)specified in /etc/resolv.conf will be used.")); - printf (_(UT_HELP_VRSN)); + printf ("\n\n"); - printf (_("\ --H, --hostname=HOST\n\ - The name or address you want to query\n\ --s, --server=HOST\n\ - Optional DNS server you want to use for the lookup\n\ --a, --expected-address=IP-ADDRESS\n\ - Optional IP address you expect the DNS server to return\n\ --A, --expect-authority\n\ - Optionally expect the DNS server to be authoritative for the lookup\n")); + print_usage (); - printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); + printf (_(UT_HELP_VRSN)); - printf (_(UT_SUPPORT)); + printf (" -H, --hostname=HOST"); + + printf ("\n"); + + printf (_("the name or address you want to query")); + + printf ("\n"); + + printf (" -s, --server=HOST"); + + printf ("\n"); + + printf (_("optional DNS server you want to use for the lookup")); + + printf ("\n"); + + printf (" -a, --expected-address=IP-ADDRESS"); + + printf ("\n"); + + printf (_("optional IP address you expect the DNS server to return")); + + printf ("\n"); + + printf (" -A, --expect-authority"); + + printf ("\n"); + + printf (_("optionally expect the DNS server to be authoritative for the lookup")); + + printf ("\n"); + + printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); + + printf (_(UT_SUPPORT)); } void print_usage (void) { - printf ("\ -Usage: %s -H host [-s server] [-a expected-address] [-A] [-t timeout]\n", progname); + printf (_("Usage:")); + + printf ("%s -H host [-s server] [-a expected-address] [-A] [-t timeout]\n", progname); } diff --git a/plugins/check_dummy.c b/plugins/check_dummy.c index 0892611..0a7f472 100644 --- a/plugins/check_dummy.c +++ b/plugins/check_dummy.c @@ -20,7 +20,7 @@ const char *progname = "check_dummy"; const char *revision = "$Revision$"; -const char *copyright = "1999-2004"; +const char *copyright = "1999-2005"; const char *email = "nagiosplug-devel@lists.sourceforge.net"; #include "common.h" @@ -33,51 +33,51 @@ void print_usage (void); int main (int argc, char **argv) { - int result = STATE_UNKNOWN; - - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE, LOCALEDIR); - textdomain (PACKAGE); - - if (argc < 2) - usage4 (_("Could not parse arguments")); - else if (strcmp (argv[1], "-V") == 0 || strcmp (argv[1], "--version") == 0) { - print_revision (progname, revision); - exit (STATE_OK); - } - else if (strcmp (argv[1], "-h") == 0 || strcmp (argv[1], "--help") == 0) { - print_help (); - exit (STATE_OK); - } - else if (!is_integer (argv[1])) - usage4 (_("Arguments to check_dummy must be an integer")); - else - result = atoi (argv[1]); - - switch (result) { - case STATE_OK: - printf (_("OK")); - break; - case STATE_WARNING: - printf (_("WARNING")); - break; - case STATE_CRITICAL: - printf (_("CRITICAL")); - break; - case STATE_UNKNOWN: - printf (_("UNKNOWN")); - break; - default: - printf (_("Status %d is not a supported error state\n"), result); - break; - } - - if (argc >= 3) - printf (": %s", argv[2]); - - printf("\n"); - - return result; + int result = STATE_UNKNOWN; + + setlocale (LC_ALL, ""); + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); + + if (argc < 2) + usage4 (_("Could not parse arguments")); + else if (strcmp (argv[1], "-V") == 0 || strcmp (argv[1], "--version") == 0) { + print_revision (progname, revision); + exit (STATE_OK); + } + else if (strcmp (argv[1], "-h") == 0 || strcmp (argv[1], "--help") == 0) { + print_help (); + exit (STATE_OK); + } + else if (!is_integer (argv[1])) + usage4 (_("Arguments to check_dummy must be an integer")); + else + result = atoi (argv[1]); + + switch (result) { + case STATE_OK: + printf (_("OK")); + break; + case STATE_WARNING: + printf (_("WARNING")); + break; + case STATE_CRITICAL: + printf (_("CRITICAL")); + break; + case STATE_UNKNOWN: + printf (_("UNKNOWN")); + break; + default: + printf (_("Status %d is not a supported error state\n"), result); + break; + } + + if (argc >= 3) + printf (": %s", argv[2]); + + printf("\n"); + + return result; } @@ -85,20 +85,24 @@ main (int argc, char **argv) void print_help (void) { - print_revision (progname, revision); + print_revision (progname, revision); - printf ("Copyright (c) 1999 Ethan Galstad \n"); - printf (COPYRIGHT, copyright, email); + printf ("Copyright (c) 1999 Ethan Galstad \n"); + printf (COPYRIGHT, copyright, email); - printf (_("\ -This plugin will simply return the state corresponding to the numeric value\n\ -of the argument with optional text.\n\n")); + printf (_("This plugin will simply return the state corresponding to the numeric value")); + + printf ("\n"); + + printf (_("of the argument with optional text")); - print_usage (); + printf ("\n\n"); + + print_usage (); - printf (_(UT_HELP_VRSN)); + printf (_(UT_HELP_VRSN)); - printf (_(UT_SUPPORT)); + printf (_(UT_SUPPORT)); } @@ -106,5 +110,6 @@ of the argument with optional text.\n\n")); void print_usage (void) { - printf ("Usage: %s [optional text]\n", progname); + printf (_("Usage:")); + printf (" %s [optional text]\n", progname); } diff --git a/plugins/check_fping.c b/plugins/check_fping.c index 5ffcd16..49615d1 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c @@ -29,10 +29,10 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; #include "utils.h" enum { - PACKET_COUNT = 1, - PACKET_SIZE = 56, - PL = 0, - RTA = 1 + PACKET_COUNT = 1, + PACKET_SIZE = 56, + PL = 0, + RTA = 1 }; int textscan (char *buf); @@ -57,65 +57,65 @@ int wrta_p = FALSE; int main (int argc, char **argv) { -/* normaly should be int result = STATE_UNKNOWN; */ - - int status = STATE_UNKNOWN; - char *server = NULL; - char *command_line = NULL; - char *input_buffer = NULL; - input_buffer = malloc (MAX_INPUT_BUFFER); - - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE, LOCALEDIR); - textdomain (PACKAGE); - - if (process_arguments (argc, argv) == ERROR) - usage4 (_("Could not parse arguments")); - - server = strscpy (server, server_name); - - /* compose the command */ - asprintf (&command_line, "%s -b %d -c %d %s", PATH_TO_FPING, - packet_size, packet_count, server); - - if (verbose) - printf ("%s\n", command_line); - - /* run the command */ - child_process = spopen (command_line); - if (child_process == NULL) { - printf (_("Could not open pipe: %s\n"), command_line); - return STATE_UNKNOWN; - } - - child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); - if (child_stderr == NULL) { - printf (_("Could not open stderr for %s\n"), command_line); - } - - while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { - if (verbose) - printf ("%s", input_buffer); - status = max_state (status, textscan (input_buffer)); - } - - /* If we get anything on STDERR, at least set warning */ - while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { - status = max_state (status, STATE_WARNING); - if (verbose) - printf ("%s", input_buffer); - status = max_state (status, textscan (input_buffer)); - } - (void) fclose (child_stderr); - - /* close the pipe */ - if (spclose (child_process)) - /* need to use max_state not max */ - status = max_state (status, STATE_WARNING); - - printf ("FPING %s - %s\n", state_text (status), server_name); - - return status; +/* normaly should be int result = STATE_UNKNOWN; */ + + int status = STATE_UNKNOWN; + char *server = NULL; + char *command_line = NULL; + char *input_buffer = NULL; + input_buffer = malloc (MAX_INPUT_BUFFER); + + setlocale (LC_ALL, ""); + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); + + if (process_arguments (argc, argv) == ERROR) + usage4 (_("Could not parse arguments")); + + server = strscpy (server, server_name); + + /* compose the command */ + asprintf (&command_line, "%s -b %d -c %d %s", PATH_TO_FPING, + packet_size, packet_count, server); + + if (verbose) + printf ("%s\n", command_line); + + /* run the command */ + child_process = spopen (command_line); + if (child_process == NULL) { + printf (_("Could not open pipe: %s\n"), command_line); + return STATE_UNKNOWN; + } + + child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); + if (child_stderr == NULL) { + printf (_("Could not open stderr for %s\n"), command_line); + } + + while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { + if (verbose) + printf ("%s", input_buffer); + status = max_state (status, textscan (input_buffer)); + } + + /* If we get anything on STDERR, at least set warning */ + while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { + status = max_state (status, STATE_WARNING); + if (verbose) + printf ("%s", input_buffer); + status = max_state (status, textscan (input_buffer)); + } + (void) fclose (child_stderr); + + /* close the pipe */ + if (spclose (child_process)) + /* need to use max_state not max */ + status = max_state (status, STATE_WARNING); + + printf ("FPING %s - %s\n", state_text (status), server_name); + + return status; } @@ -123,80 +123,80 @@ main (int argc, char **argv) int textscan (char *buf) { - char *rtastr = NULL; - char *losstr = NULL; - double loss; - double rta; - int status = STATE_UNKNOWN; - - if (strstr (buf, "not found")) { - die (STATE_CRITICAL, _("FPING UNKNOW - %s not found\n"), server_name); - - } - else if (strstr (buf, "is unreachable") || strstr (buf, "Unreachable")) { - die (STATE_CRITICAL, _("FPING CRITICAL - %s is unreachable\n"), - "host"); - - } - else if (strstr (buf, "is down")) { - die (STATE_CRITICAL, _("FPING CRITICAL - %s is down\n"), server_name); - - } - else if (strstr (buf, "is alive")) { - status = STATE_OK; - - } - else if (strstr (buf, "xmt/rcv/%loss") && strstr (buf, "min/avg/max")) { - losstr = strstr (buf, "="); - losstr = 1 + strstr (losstr, "/"); - losstr = 1 + strstr (losstr, "/"); - rtastr = strstr (buf, "min/avg/max"); - rtastr = strstr (rtastr, "="); - rtastr = 1 + index (rtastr, '/'); - loss = strtod (losstr, NULL); - rta = strtod (rtastr, NULL); - if (cpl_p == TRUE && loss > cpl) - status = STATE_CRITICAL; - else if (crta_p == TRUE && rta > crta) - status = STATE_CRITICAL; - else if (wpl_p == TRUE && loss > wpl) - status = STATE_WARNING; - else if (wrta_p == TRUE && rta > wrta) - status = STATE_WARNING; - else - status = STATE_OK; - die (status, - _("FPING %s - %s (loss=%.0f%%, rta=%f ms)|%s %s\n"), - state_text (status), server_name, loss, rta, - perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100), - fperfdata ("rta", rta/1.0e3, "s", wrta_p, wrta/1.0e3, crta_p, crta/1.0e3, TRUE, 0, FALSE, 0)); - - } - else if(strstr (buf, "xmt/rcv/%loss") ) { - /* no min/max/avg if host was unreachable in fping v2.2.b1 */ - losstr = strstr (buf, "="); - losstr = 1 + strstr (losstr, "/"); - losstr = 1 + strstr (losstr, "/"); - loss = strtod (losstr, NULL); - if (atoi(losstr) == 100) - status = STATE_CRITICAL; - else if (cpl_p == TRUE && loss > cpl) - status = STATE_CRITICAL; - else if (wpl_p == TRUE && loss > wpl) - status = STATE_WARNING; - else - status = STATE_OK; - /* loss=%.0f%%;%d;%d;0;100 */ - die (status, _("FPING %s - %s (loss=%.0f%% )|%s\n"), - state_text (status), server_name, loss , - perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100)); - - } - else { - status = max_state (status, STATE_WARNING); - } - - return status; + char *rtastr = NULL; + char *losstr = NULL; + double loss; + double rta; + int status = STATE_UNKNOWN; + + if (strstr (buf, "not found")) { + die (STATE_CRITICAL, _("FPING UNKNOW - %s not found\n"), server_name); + + } + else if (strstr (buf, "is unreachable") || strstr (buf, "Unreachable")) { + die (STATE_CRITICAL, _("FPING CRITICAL - %s is unreachable\n"), + "host"); + + } + else if (strstr (buf, "is down")) { + die (STATE_CRITICAL, _("FPING CRITICAL - %s is down\n"), server_name); + + } + else if (strstr (buf, "is alive")) { + status = STATE_OK; + + } + else if (strstr (buf, "xmt/rcv/%loss") && strstr (buf, "min/avg/max")) { + losstr = strstr (buf, "="); + losstr = 1 + strstr (losstr, "/"); + losstr = 1 + strstr (losstr, "/"); + rtastr = strstr (buf, "min/avg/max"); + rtastr = strstr (rtastr, "="); + rtastr = 1 + index (rtastr, '/'); + loss = strtod (losstr, NULL); + rta = strtod (rtastr, NULL); + if (cpl_p == TRUE && loss > cpl) + status = STATE_CRITICAL; + else if (crta_p == TRUE && rta > crta) + status = STATE_CRITICAL; + else if (wpl_p == TRUE && loss > wpl) + status = STATE_WARNING; + else if (wrta_p == TRUE && rta > wrta) + status = STATE_WARNING; + else + status = STATE_OK; + die (status, + _("FPING %s - %s (loss=%.0f%%, rta=%f ms)|%s %s\n"), + state_text (status), server_name, loss, rta, + perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100), + fperfdata ("rta", rta/1.0e3, "s", wrta_p, wrta/1.0e3, crta_p, crta/1.0e3, TRUE, 0, FALSE, 0)); + + } + else if(strstr (buf, "xmt/rcv/%loss") ) { + /* no min/max/avg if host was unreachable in fping v2.2.b1 */ + losstr = strstr (buf, "="); + losstr = 1 + strstr (losstr, "/"); + losstr = 1 + strstr (losstr, "/"); + loss = strtod (losstr, NULL); + if (atoi(losstr) == 100) + status = STATE_CRITICAL; + else if (cpl_p == TRUE && loss > cpl) + status = STATE_CRITICAL; + else if (wpl_p == TRUE && loss > wpl) + status = STATE_WARNING; + else + status = STATE_OK; + /* loss=%.0f%%;%d;%d;0;100 */ + die (status, _("FPING %s - %s (loss=%.0f%% )|%s\n"), + state_text (status), server_name, loss , + perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100)); + + } + else { + status = max_state (status, STATE_WARNING); + } + + return status; } @@ -205,145 +205,145 @@ textscan (char *buf) int process_arguments (int argc, char **argv) { - int c; - char *rv[2]; - - int option = 0; - static struct option longopts[] = { - {"hostname", required_argument, 0, 'H'}, - {"critical", required_argument, 0, 'c'}, - {"warning", required_argument, 0, 'w'}, - {"bytes", required_argument, 0, 'b'}, - {"number", required_argument, 0, 'n'}, - {"verbose", no_argument, 0, 'v'}, - {"version", no_argument, 0, 'V'}, - {"help", no_argument, 0, 'h'}, - {0, 0, 0, 0} - }; - - rv[PL] = NULL; - rv[RTA] = NULL; - - if (argc < 2) - return ERROR; - - if (!is_option (argv[1])) { - server_name = argv[1]; - argv[1] = argv[0]; - argv = &argv[1]; - argc--; - } - - while (1) { - c = getopt_long (argc, argv, "+hVvH:c:w:b:n:", longopts, &option); - - if (c == -1 || c == EOF || c == 1) - break; - - switch (c) { - case '?': /* print short usage statement if args not parsable */ - usage2 (_("Unknown argument"), optarg); - case 'h': /* help */ - print_help (); - exit (STATE_OK); - case 'V': /* version */ - print_revision (progname, revision); - exit (STATE_OK); - case 'v': /* verbose mode */ - verbose = TRUE; - break; - case 'H': /* hostname */ - if (is_host (optarg) == FALSE) { - usage2 (_("Invalid hostname/address"), optarg); - } - server_name = strscpy (server_name, optarg); - break; - case 'c': - get_threshold (optarg, rv); - if (rv[RTA]) { - crta = strtod (rv[RTA], NULL); - crta_p = TRUE; - rv[RTA] = NULL; - } - if (rv[PL]) { - cpl = atoi (rv[PL]); - cpl_p = TRUE; - rv[PL] = NULL; - } - break; - case 'w': - get_threshold (optarg, rv); - if (rv[RTA]) { - wrta = strtod (rv[RTA], NULL); - wrta_p = TRUE; - rv[RTA] = NULL; - } - if (rv[PL]) { - wpl = atoi (rv[PL]); - wpl_p = TRUE; - rv[PL] = NULL; - } - break; - case 'b': /* bytes per packet */ - if (is_intpos (optarg)) - packet_size = atoi (optarg); - else - usage (_("Packet size must be a positive integer")); - break; - case 'n': /* number of packets */ - if (is_intpos (optarg)) - packet_count = atoi (optarg); - else - usage (_("Packet count must be a positive integer")); - break; - } - } - - if (server_name == NULL) - usage4 (_("Hostname was not supplied")); - - return OK; + int c; + char *rv[2]; + + int option = 0; + static struct option longopts[] = { + {"hostname", required_argument, 0, 'H'}, + {"critical", required_argument, 0, 'c'}, + {"warning", required_argument, 0, 'w'}, + {"bytes", required_argument, 0, 'b'}, + {"number", required_argument, 0, 'n'}, + {"verbose", no_argument, 0, 'v'}, + {"version", no_argument, 0, 'V'}, + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0} + }; + + rv[PL] = NULL; + rv[RTA] = NULL; + + if (argc < 2) + return ERROR; + + if (!is_option (argv[1])) { + server_name = argv[1]; + argv[1] = argv[0]; + argv = &argv[1]; + argc--; + } + + while (1) { + c = getopt_long (argc, argv, "+hVvH:c:w:b:n:", longopts, &option); + + if (c == -1 || c == EOF || c == 1) + break; + + switch (c) { + case '?': /* print short usage statement if args not parsable */ + usage2 (_("Unknown argument"), optarg); + case 'h': /* help */ + print_help (); + exit (STATE_OK); + case 'V': /* version */ + print_revision (progname, revision); + exit (STATE_OK); + case 'v': /* verbose mode */ + verbose = TRUE; + break; + case 'H': /* hostname */ + if (is_host (optarg) == FALSE) { + usage2 (_("Invalid hostname/address"), optarg); + } + server_name = strscpy (server_name, optarg); + break; + case 'c': + get_threshold (optarg, rv); + if (rv[RTA]) { + crta = strtod (rv[RTA], NULL); + crta_p = TRUE; + rv[RTA] = NULL; + } + if (rv[PL]) { + cpl = atoi (rv[PL]); + cpl_p = TRUE; + rv[PL] = NULL; + } + break; + case 'w': + get_threshold (optarg, rv); + if (rv[RTA]) { + wrta = strtod (rv[RTA], NULL); + wrta_p = TRUE; + rv[RTA] = NULL; + } + if (rv[PL]) { + wpl = atoi (rv[PL]); + wpl_p = TRUE; + rv[PL] = NULL; + } + break; + case 'b': /* bytes per packet */ + if (is_intpos (optarg)) + packet_size = atoi (optarg); + else + usage (_("Packet size must be a positive integer")); + break; + case 'n': /* number of packets */ + if (is_intpos (optarg)) + packet_count = atoi (optarg); + else + usage (_("Packet count must be a positive integer")); + break; + } + } + + if (server_name == NULL) + usage4 (_("Hostname was not supplied")); + + return OK; } int get_threshold (char *arg, char *rv[2]) { - char *arg1 = NULL; - char *arg2 = NULL; - - arg1 = strscpy (arg1, arg); - if (strpbrk (arg1, ",:")) - arg2 = 1 + strpbrk (arg1, ",:"); - - if (arg2) { - arg1[strcspn (arg1, ",:")] = 0; - if (strstr (arg1, "%") && strstr (arg2, "%")) - die (STATE_UNKNOWN, - _("%s: Only one threshold may be packet loss (%s)\n"), progname, - arg); - if (!strstr (arg1, "%") && !strstr (arg2, "%")) - die (STATE_UNKNOWN, - _("%s: Only one threshold must be packet loss (%s)\n"), - progname, arg); - } - - if (arg2 && strstr (arg2, "%")) { - rv[PL] = arg2; - rv[RTA] = arg1; - } - else if (arg2) { - rv[PL] = arg1; - rv[RTA] = arg2; - } - else if (strstr (arg1, "%")) { - rv[PL] = arg1; - } - else { - rv[RTA] = arg1; - } - - return OK; + char *arg1 = NULL; + char *arg2 = NULL; + + arg1 = strscpy (arg1, arg); + if (strpbrk (arg1, ",:")) + arg2 = 1 + strpbrk (arg1, ",:"); + + if (arg2) { + arg1[strcspn (arg1, ",:")] = 0; + if (strstr (arg1, "%") && strstr (arg2, "%")) + die (STATE_UNKNOWN, + _("%s: Only one threshold may be packet loss (%s)\n"), progname, + arg); + if (!strstr (arg1, "%") && !strstr (arg2, "%")) + die (STATE_UNKNOWN, + _("%s: Only one threshold must be packet loss (%s)\n"), + progname, arg); + } + + if (arg2 && strstr (arg2, "%")) { + rv[PL] = arg2; + rv[RTA] = arg1; + } + else if (arg2) { + rv[PL] = arg1; + rv[RTA] = arg2; + } + else if (strstr (arg1, "%")) { + rv[PL] = arg1; + } + else { + rv[RTA] = arg1; + } + + return OK; } @@ -351,47 +351,82 @@ void print_help (void) { - print_revision (progname, revision); + print_revision (progname, revision); - printf ("Copyright (c) 1999 Didi Rieder \n"); - printf (COPYRIGHT, copyright, email); + printf ("Copyright (c) 1999 Didi Rieder \n"); + printf (COPYRIGHT, copyright, email); - printf (_("\ -This plugin will use the /bin/fping command to ping the specified host\n\ -for a fast check if the host is alive.\n\ -Note that it is necessary to set the suid flag on fping.\n\n")); + printf (_("This plugin will use the fping command to ping the specified host for a fast check")); + + printf ("\n"); + + printf (_("Note that it is necessary to set the suid flag on fping.")); - print_usage (); + printf ("\n\n"); + + print_usage (); - printf (_(UT_HELP_VRSN)); + printf (_(UT_HELP_VRSN)); - printf (_("\ - -H, --hostname=HOST\n\ - Name or IP Address of host to ping (IP Address bypasses name lookup,\n\ - reducing system load)\n\ - -w, --warning=THRESHOLD\n\ - warning threshold pair\n\ - -c, --critical=THRESHOLD\n\ - critical threshold pair\n\ - -b, --bytes=INTEGER\n\ - Size of ICMP packet (default: %d)\n\ - -n, --number=INTEGER\n\ - Number of ICMP packets to send (default: %d)\n"), - PACKET_SIZE, PACKET_COUNT); + printf (" -H, --hostname=HOST"); + + printf (_("name or IP Address of host to ping (IP Address bypasses name lookup, reducing system load)")); + + printf ("\n"); + + printf ("-w, --warning=THRESHOLD"); + + printf ("\n"); + + printf (_("warning threshold pair")); + + printf ("\n"); - printf (_(UT_VERBOSE)); + printf (" -c, --critical=THRESHOLD"); + + printf ("\n"); - printf (_("\n\ -THRESHOLD is ,%% where is the round trip average travel\n\ -time (ms) which triggers a WARNING or CRITICAL state, and is the\n\ -percentage of packet loss to trigger an alarm state.\n")); + printf (_("critical threshold pair")); + + printf ("\n"); - printf (_(UT_SUPPORT)); + printf (" -b, --bytes=INTEGER"); + + printf (_("size of ICMP packet (default: %d)"),PACKET_SIZE); + + printf ("\n"); + + printf (" -n, --number=INTEGER"); + + printf ("\n"); + + printf (_("number of ICMP packets to send (default: %d)"),PACKET_COUNT); + + printf ("\n"); + + printf (_(UT_VERBOSE)); + + printf ("\n"); + + printf (_("THRESHOLD is ,%% where is the round trip average travel time (ms)")); + + printf ("\n"); + + printf (_("which triggers a WARNING or CRITICAL state, and is the percentage of")); + + printf ("\n"); + + printf (_("packet loss to trigger an alarm state.")); + + printf ("\n"); + + printf (_(UT_SUPPORT)); } void print_usage (void) { - printf ("Usage: %s \n", progname); + printf (_("Usage:")); + printf (" %s \n", progname); } diff --git a/plugins/check_game.c b/plugins/check_game.c index 8548bbd..9f9ff7d 100644 --- a/plugins/check_game.c +++ b/plugins/check_game.c @@ -19,7 +19,7 @@ const char *progname = "check_game"; const char *revision = "$Revision$"; -const char *copyright = "2002-2004"; +const char *copyright = "2002-2005"; const char *email = "nagiosplug-devel@lists.sourceforge.net"; #include "common.h" @@ -31,12 +31,12 @@ int validate_arguments (void); void print_help (void); void print_usage (void); -#define QSTAT_DATA_DELIMITER "," +#define QSTAT_DATA_DELIMITER "," -#define QSTAT_HOST_ERROR "ERROR" -#define QSTAT_HOST_DOWN "DOWN" -#define QSTAT_HOST_TIMEOUT "TIMEOUT" -#define QSTAT_MAX_RETURN_ARGS 12 +#define QSTAT_HOST_ERROR "ERROR" +#define QSTAT_HOST_DOWN "DOWN" +#define QSTAT_HOST_TIMEOUT "TIMEOUT" +#define QSTAT_MAX_RETURN_ARGS 12 char *server_ip; char *game_type; @@ -54,239 +54,241 @@ int qstat_ping_field = -1; int main (int argc, char **argv) { - char *command_line; - int result = STATE_UNKNOWN; - char *p, *ret[QSTAT_MAX_RETURN_ARGS]; - size_t i = 0; - output chld_out; - - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE, LOCALEDIR); - textdomain (PACKAGE); - - if (process_arguments (argc, argv) == ERROR) - usage_va(_("Could not parse arguments")); - - result = STATE_OK; - - /* create the command line to execute */ - asprintf (&command_line, "%s -raw %s -%s %s", - PATH_TO_QSTAT, QSTAT_DATA_DELIMITER, game_type, server_ip); - - if (port) - asprintf (&command_line, "%s:%-d", command_line, port); - - if (verbose > 0) - printf ("%s\n", command_line); - - /* run the command. historically, this plugin ignores output on stderr, - * as well as return status of the qstat program */ - (void)np_runcmd(command_line, &chld_out, NULL, 0); - - /* sanity check */ - /* was thinking about running qstat without any options, capturing the - -default line, parsing it & making an array of all know server types - but thought this would be too much hassle considering this is a tool - for intelligent sysadmins (ha). Could put a static array of known - server types in a header file but then we'd be limiting ourselves - - In the end, I figured I'd simply let an error occur & then trap it - */ - - if (!strncmp (chld_out.line[0], "unknown option", 14)) { - printf (_("CRITICAL - Host type parameter incorrect!\n")); - result = STATE_CRITICAL; - return result; - } - - p = (char *) strtok (chld_out.line[0], QSTAT_DATA_DELIMITER); - while (p != NULL) { - ret[i] = p; - p = (char *) strtok (NULL, QSTAT_DATA_DELIMITER); - i++; - if (i >= QSTAT_MAX_RETURN_ARGS) - break; - } - - if (strstr (ret[2], QSTAT_HOST_ERROR)) { - printf (_("CRITICAL - Host not found\n")); - result = STATE_CRITICAL; - } - else if (strstr (ret[2], QSTAT_HOST_DOWN)) { - printf (_("CRITICAL - Game server down or unavailable\n")); - result = STATE_CRITICAL; - } - else if (strstr (ret[2], QSTAT_HOST_TIMEOUT)) { - printf (_("CRITICAL - Game server timeout\n")); - result = STATE_CRITICAL; - } - else { - printf ("OK: %s/%s %s (%s), Ping: %s ms|%s %s\n", - ret[qstat_game_players], - ret[qstat_game_players_max], - ret[qstat_game_field], - ret[qstat_map_field], - ret[qstat_ping_field], - perfdata ("players", atol(ret[qstat_game_players]), "", - FALSE, 0, FALSE, 0, - TRUE, 0, TRUE, atol(ret[qstat_game_players_max])), - fperfdata ("ping", strtod(ret[qstat_ping_field], NULL), "", - FALSE, 0, FALSE, 0, - TRUE, 0, FALSE, 0)); - } - - return result; + char *command_line; + int result = STATE_UNKNOWN; + char *p, *ret[QSTAT_MAX_RETURN_ARGS]; + size_t i = 0; + output chld_out; + + setlocale (LC_ALL, ""); + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); + + if (process_arguments (argc, argv) == ERROR) + usage_va(_("Could not parse arguments")); + + result = STATE_OK; + + /* create the command line to execute */ + asprintf (&command_line, "%s -raw %s -%s %s", + PATH_TO_QSTAT, QSTAT_DATA_DELIMITER, game_type, server_ip); + + if (port) + asprintf (&command_line, "%s:%-d", command_line, port); + + if (verbose > 0) + printf ("%s\n", command_line); + + /* run the command. historically, this plugin ignores output on stderr, + * as well as return status of the qstat program */ + (void)np_runcmd(command_line, &chld_out, NULL, 0); + + /* sanity check */ + /* was thinking about running qstat without any options, capturing the + -default line, parsing it & making an array of all know server types + but thought this would be too much hassle considering this is a tool + for intelligent sysadmins (ha). Could put a static array of known + server types in a header file but then we'd be limiting ourselves + + In the end, I figured I'd simply let an error occur & then trap it + */ + + if (!strncmp (chld_out.line[0], "unknown option", 14)) { + printf (_("CRITICAL - Host type parameter incorrect!\n")); + result = STATE_CRITICAL; + return result; + } + + p = (char *) strtok (chld_out.line[0], QSTAT_DATA_DELIMITER); + while (p != NULL) { + ret[i] = p; + p = (char *) strtok (NULL, QSTAT_DATA_DELIMITER); + i++; + if (i >= QSTAT_MAX_RETURN_ARGS) + break; + } + + if (strstr (ret[2], QSTAT_HOST_ERROR)) { + printf (_("CRITICAL - Host not found\n")); + result = STATE_CRITICAL; + } + else if (strstr (ret[2], QSTAT_HOST_DOWN)) { + printf (_("CRITICAL - Game server down or unavailable\n")); + result = STATE_CRITICAL; + } + else if (strstr (ret[2], QSTAT_HOST_TIMEOUT)) { + printf (_("CRITICAL - Game server timeout\n")); + result = STATE_CRITICAL; + } + else { + printf ("OK: %s/%s %s (%s), Ping: %s ms|%s %s\n", + ret[qstat_game_players], + ret[qstat_game_players_max], + ret[qstat_game_field], + ret[qstat_map_field], + ret[qstat_ping_field], + perfdata ("players", atol(ret[qstat_game_players]), "", + FALSE, 0, FALSE, 0, + TRUE, 0, TRUE, atol(ret[qstat_game_players_max])), + fperfdata ("ping", strtod(ret[qstat_ping_field], NULL), "", + FALSE, 0, FALSE, 0, + TRUE, 0, FALSE, 0)); + } + + return result; } int process_arguments (int argc, char **argv) { - int c; - - int opt_index = 0; - static struct option long_opts[] = { - {"help", no_argument, 0, 'h'}, - {"version", no_argument, 0, 'V'}, - {"verbose", no_argument, 0, 'v'}, - {"timeout", required_argument, 0, 't'}, - {"hostname", required_argument, 0, 'H'}, - {"port", required_argument, 0, 'P'}, - {"game-type", required_argument, 0, 'G'}, - {"map-field", required_argument, 0, 'm'}, - {"ping-field", required_argument, 0, 'p'}, - {"game-field", required_argument, 0, 'g'}, - {"players-field", required_argument, 0, 129}, - {"max-players-field", required_argument, 0, 130}, - {0, 0, 0, 0} - }; - - if (argc < 2) - return ERROR; - - for (c = 1; c < argc; c++) { - if (strcmp ("-mf", argv[c]) == 0) - strcpy (argv[c], "-m"); - else if (strcmp ("-pf", argv[c]) == 0) - strcpy (argv[c], "-p"); - else if (strcmp ("-gf", argv[c]) == 0) - strcpy (argv[c], "-g"); - } - - while (1) { - c = getopt_long (argc, argv, "hVvt:H:P:G:g:p:m:", long_opts, &opt_index); - - if (c == -1 || c == EOF) - break; - - switch (c) { - case 'h': /* help */ - print_help (); - exit (STATE_OK); - case 'V': /* version */ - print_revision (progname, revision); - exit (STATE_OK); - case 'v': /* version */ - verbose = TRUE; - break; - case 't': /* timeout period */ - timeout_interval = atoi (optarg); - break; - case 'H': /* hostname */ - if (strlen (optarg) >= MAX_HOST_ADDRESS_LENGTH) - die (STATE_UNKNOWN, _("Input buffer overflow\n")); - server_ip = optarg; - break; - case 'P': /* port */ - port = atoi (optarg); - break; - case 'G': /* hostname */ - if (strlen (optarg) >= MAX_INPUT_BUFFER) - die (STATE_UNKNOWN, _("Input buffer overflow\n")); - game_type = optarg; - break; - case 'p': /* index of ping field */ - qstat_ping_field = atoi (optarg); - if (qstat_ping_field < 0 || qstat_ping_field > QSTAT_MAX_RETURN_ARGS) - return ERROR; - break; - case 'm': /* index on map field */ - qstat_map_field = atoi (optarg); - if (qstat_map_field < 0 || qstat_map_field > QSTAT_MAX_RETURN_ARGS) - return ERROR; - break; - case 'g': /* index of game field */ - qstat_game_field = atoi (optarg); - if (qstat_game_field < 0 || qstat_game_field > QSTAT_MAX_RETURN_ARGS) - return ERROR; - break; - case 129: /* index of player count field */ - qstat_game_players = atoi (optarg); - if (qstat_game_players_max == 0) - qstat_game_players_max = qstat_game_players - 1; - if (qstat_game_players < 0 || qstat_game_players > QSTAT_MAX_RETURN_ARGS) - return ERROR; - break; - case 130: /* index of max players field */ - qstat_game_players_max = atoi (optarg); - if (qstat_game_players_max < 0 || qstat_game_players_max > QSTAT_MAX_RETURN_ARGS) - return ERROR; - break; - default: /* args not parsable */ - usage_va(_("Unknown argument - %s"), optarg); - } - } - - c = optind; - /* first option is the game type */ - if (!game_type && c= MAX_HOST_ADDRESS_LENGTH) + die (STATE_UNKNOWN, _("Input buffer overflow\n")); + server_ip = optarg; + break; + case 'P': /* port */ + port = atoi (optarg); + break; + case 'G': /* hostname */ + if (strlen (optarg) >= MAX_INPUT_BUFFER) + die (STATE_UNKNOWN, _("Input buffer overflow\n")); + game_type = optarg; + break; + case 'p': /* index of ping field */ + qstat_ping_field = atoi (optarg); + if (qstat_ping_field < 0 || qstat_ping_field > QSTAT_MAX_RETURN_ARGS) + return ERROR; + break; + case 'm': /* index on map field */ + qstat_map_field = atoi (optarg); + if (qstat_map_field < 0 || qstat_map_field > QSTAT_MAX_RETURN_ARGS) + return ERROR; + break; + case 'g': /* index of game field */ + qstat_game_field = atoi (optarg); + if (qstat_game_field < 0 || qstat_game_field > QSTAT_MAX_RETURN_ARGS) + return ERROR; + break; + case 129: /* index of player count field */ + qstat_game_players = atoi (optarg); + if (qstat_game_players_max == 0) + qstat_game_players_max = qstat_game_players - 1; + if (qstat_game_players < 0 || qstat_game_players > QSTAT_MAX_RETURN_ARGS) + return ERROR; + break; + case 130: /* index of max players field */ + qstat_game_players_max = atoi (optarg); + if (qstat_game_players_max < 0 || qstat_game_players_max > QSTAT_MAX_RETURN_ARGS) + return ERROR; + break; + default: /* args not parsable */ + usage_va(_("Unknown argument - %s"), optarg); + } + } + + c = optind; + /* first option is the game type */ + if (!game_type && c = Game type that is recognised by qstat (without the leading dash)\n\ = The IP address of the device you wish to query\n\ [port] = Optional port of which to connect\n\ @@ -294,15 +296,25 @@ print_help (void) [map_field] = Field number in raw qstat output that contains map name\n\ [ping_field] = Field number in raw qstat output that contains ping time\n")); - printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); + printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); - printf (_("\n\ -Notes:\n\ -- This plugin uses the 'qstat' command, the popular game server status query tool .\n\ - If you don't have the package installed, you will need to download it from\n\ - http://www.activesw.com/people/steve/qstat.html before you can use this plugin.\n")); + printf (_("Notes:")); + + printf ("\n"); - printf (_(UT_SUPPORT)); + printf (_("This plugin uses the 'qstat' command, the popular game server status query tool .")); + + printf ("\n"); + + printf (_("If you don't have the package installed, you will need to download it from")); + + printf ("\n"); + + printf (_("http://www.activesw.com/people/steve/qstat.html before you can use this plugin.")); + + printf ("\n"); + + printf (_(UT_SUPPORT)); } @@ -310,9 +322,8 @@ Notes:\n\ void print_usage (void) { - printf ("\ -Usage: %s [-p port] [-gf game_field] [-mf map_field]\n\ - [-pf ping_field]\n", progname); + printf (_("Usage:")); + printf (" %s [-p port] [-gf game_field] [-mf map_field] [-pf ping_field]\n", progname); } /****************************************************************************** -- cgit v0.10-9-g596f