Esempio n. 1
0
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
{
	int c;

	int option = 0;
	static struct option longopts[] = {
		{"filename", required_argument, 0, 'F'},
		{"expires", required_argument, 0, 'e'},
		{"command", required_argument, 0, 'C'},
		{"timeout", optional_argument, 0, 't'},
		{"version", no_argument, 0, 'V'},
		{"help", no_argument, 0, 'h'},
		{"verbose", no_argument, 0, 'v'},
		{0, 0, 0, 0}
	};

	if (argc < 2)
		return ERROR;

	if (!is_option (argv[1])) {
		status_log = argv[1];
		if (is_intnonneg (argv[2]))
			expire_minutes = atoi (argv[2]);
		else
			die (STATE_UNKNOWN,
								 _("Expiration time must be an integer (seconds)\n"));
		process_string = argv[3];
		return OK;
	}

	while (1) {
		c = getopt_long (argc, argv, "+hVvF:C:e:t:", longopts, &option);

		if (c == -1 || c == EOF || c == 1)
			break;

		switch (c) {
		case 'h':									/* help */
			print_help ();
			exit (STATE_OK);
		case 'V':									/* version */
			print_revision (progname, NP_VERSION);
			exit (STATE_OK);
		case 'F':									/* status log */
			status_log = optarg;
			break;
		case 'C':									/* command */
			process_string = optarg;
			break;
		case 'e':									/* expiry time */
			if (is_intnonneg (optarg))
				expire_minutes = atoi (optarg);
			else
				die (STATE_UNKNOWN,
				     _("Expiration time must be an integer (seconds)\n"));
			break;
		case 't':									/* timeout */
			timeout_interval = parse_timeout_string (optarg);
			break;
		case 'v':
			verbose++;
			break;
		default:									/* print short usage_va statement if args not parsable */
			usage5();
		}
	}


	if (status_log == NULL)
		die (STATE_UNKNOWN, _("You must provide the status_log\n"));

	if (process_string == NULL)
		die (STATE_UNKNOWN, _("You must provide a process string\n"));

	return OK;
}
Esempio n. 2
0
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
{
	int c;

	int option = 0;
	/* initialize the long option struct */
	static struct option longopts[] = {
		{"help", no_argument, 0, 'h'},
		{"version", no_argument, 0, 'V'},
		{"timeout", required_argument, 0, 't'},
		{"hostname", required_argument, 0, 'H'},
		{"uri", required_argument, 0, 'U'},
		{"base", required_argument, 0, 'b'},
		{"attr", required_argument, 0, 'a'},
		{"bind", required_argument, 0, 'D'},
		{"pass", required_argument, 0, 'P'},
#ifdef HAVE_LDAP_SET_OPTION
		{"ver2", no_argument, 0, '2'},
		{"ver3", no_argument, 0, '3'},
#endif
		{"starttls", no_argument, 0, 'T'},
		{"ssl", no_argument, 0, 'S'},
		{"use-ipv4", no_argument, 0, '4'},
		{"use-ipv6", no_argument, 0, '6'},
		{"port", required_argument, 0, 'p'},
		{"warn", required_argument, 0, 'w'},
		{"crit", required_argument, 0, 'c'},
		{"warn-entries", required_argument, 0, 'W'},
		{"crit-entries", required_argument, 0, 'C'},
		{"verbose", no_argument, 0, 'v'},
		{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, "hvV234TS6t:c:w:H:b:p:a:D:P:U:C:W:", longopts, &option);

		if (c == -1 || c == EOF)
			break;

		switch (c) {
		case 'h':									/* help */
			print_help ();
			exit (STATE_OK);
		case 'V':									/* version */
			print_revision (progname, NP_VERSION);
			exit (STATE_OK);
		case 't':									/* timeout period */
			timeout_interval = parse_timeout_string(optarg);
			break;
		case 'U':
			ld_uri = optarg;
			break;
		case 'H':
			ld_host = optarg;
			break;
		case 'b':
			ld_base = optarg;
			break;
		case 'p':
			ld_port = atoi (optarg);
			break;
		case 'a':
			ld_attr = optarg;
			break;
		case 'D':
			ld_binddn = optarg;
			break;
		case 'P':
			ld_passwd = optarg;
			break;
		case 'w':
			warn_time = strtod (optarg, NULL);
			break;
		case 'c':
			crit_time = strtod (optarg, NULL);
			break;
		case 'W':
			warn_entries = optarg;
			break;
		case 'C':
			crit_entries = optarg;
			break;
#ifdef HAVE_LDAP_SET_OPTION
		case '2':
			ld_protocol = 2;
			break;
		case '3':
			ld_protocol = 3;
			break;
#endif
		case '4':
			address_family = AF_INET;
			break;
		case 'v':
			verbose++;
			break;
		case 'T':
			if (! ssl_on_connect)
				starttls = TRUE;
			else
				usage_va(_("%s cannot be combined with %s"), "-T/--starttls", "-S/--ssl");
			break;
		case 'S':
			if (! starttls) {
				ssl_on_connect = TRUE;
				if (ld_port == -1)
					ld_port = LDAPS_PORT;
			} else
				usage_va(_("%s cannot be combined with %s"), "-S/--ssl", "-T/--starttls");
			break;
		case '6':
#ifdef USE_IPV6
			address_family = AF_INET6;
#else
			usage (_("IPv6 support not available\n"));
#endif
			break;
		default:
			usage5 ();
		}
	}

	c = optind;
	if (ld_host == NULL && is_host(argv[c]))
		ld_host = strdup (argv[c++]);

	if (ld_base == NULL && argv[c])
		ld_base = strdup (argv[c++]);

	if (ld_port == -1)
		ld_port = DEFAULT_PORT;

	return validate_arguments ();
}
Esempio n. 3
0
/* process command-line arguments */
int process_arguments(int argc, char **argv){
	int c;

	int option = 0;
	static struct option longopts[] =
	{
		{"port",     required_argument,0,'p'},
		{"timeout",  required_argument,0,'t'},
		{"critical", required_argument,0,'c'},
		{"warning",  required_argument,0,'w'},
		{"variable", required_argument,0,'v'},
		{"hostname", required_argument,0,'H'},
		{"params",   required_argument,0,'l'},
		{"secret",   required_argument,0,'s'},
		{"display",  required_argument,0,'d'},
		{"unknown-timeout", no_argument, 0, 'u'},
		{"version",  no_argument,      0,'V'},
		{"help",     no_argument,      0,'h'},
		{0,0,0,0}
	};

	/* no options were supplied */
	if(argc<2) return ERROR;

	/* backwards compatibility */
	if (! is_option(argv[1])) {
		server_address = strdup(argv[1]);
		argv[1]=argv[0];
		argv=&argv[1];
		argc--;
	}

	for (c=1;c<argc;c++) {
		if(strcmp("-to",argv[c])==0)
			strcpy(argv[c],"-t");
		else if (strcmp("-wv",argv[c])==0)
			strcpy(argv[c],"-w");
		else if (strcmp("-cv",argv[c])==0)
			strcpy(argv[c],"-c");
	}

	while (1) {
		c = getopt_long(argc,argv,"+hVH:t:c:w:p:v:l:s:d:u",longopts,&option);

		if (c==-1||c==EOF||c==1)
			break;

		switch (c) {
			case '?': /* print short usage statement if args not parsable */
			usage5 ();
			case 'h': /* help */
				print_help();
				exit(STATE_OK);
			case 'V': /* version */
				print_revision(progname, NP_VERSION);
				exit(STATE_OK);
			case 'H': /* hostname */
				server_address = optarg;
				break;
			case 's': /* password */
				req_password = optarg;
				break;
			case 'p': /* port */
				if (is_intnonneg(optarg))
					server_port=atoi(optarg);
				else
					die(STATE_UNKNOWN,_("Server port must be an integer\n"));
				break;
			case 'v':
				if(strlen(optarg)<4)
					return ERROR;
				if(!strcmp(optarg,"CLIENTVERSION"))
					vars_to_check=CHECK_CLIENTVERSION;
				else if(!strcmp(optarg,"CPULOAD"))
					vars_to_check=CHECK_CPULOAD;
				else if(!strcmp(optarg,"UPTIME"))
					vars_to_check=CHECK_UPTIME;
				else if(!strcmp(optarg,"USEDDISKSPACE"))
					vars_to_check=CHECK_USEDDISKSPACE;
				else if(!strcmp(optarg,"SERVICESTATE"))
					vars_to_check=CHECK_SERVICESTATE;
				else if(!strcmp(optarg,"PROCSTATE"))
					vars_to_check=CHECK_PROCSTATE;
				else if(!strcmp(optarg,"MEMUSE"))
					vars_to_check=CHECK_MEMUSE;
				else if(!strcmp(optarg,"COUNTER"))
					vars_to_check=CHECK_COUNTER;
				else if(!strcmp(optarg,"FILEAGE"))
					vars_to_check=CHECK_FILEAGE;
				else if(!strcmp(optarg,"INSTANCES"))
					vars_to_check=CHECK_INSTANCES;
				else
					return ERROR;
				break;
			case 'l': /* value list */
				value_list = optarg;
				break;
			case 'w': /* warning threshold */
				warning_value=strtoul(optarg,NULL,10);
				check_warning_value=TRUE;
				break;
			case 'c': /* critical threshold */
				critical_value=strtoul(optarg,NULL,10);
				check_critical_value=TRUE;
				break;
			case 'd': /* Display select for services */
				if (!strcmp(optarg,"SHOWALL"))
					show_all = TRUE;
				break;
			case 'u':
				timeout_state=STATE_UNKNOWN;
				break;
			case 't': /* timeout */
				timeout_interval = parse_timeout_string(optarg);
				break;
			}

	}
	if (server_address == NULL)
		usage4 (_("You must provide a server address or host name"));

	if (vars_to_check==CHECK_NONE)
		return ERROR;

	if (req_password == NULL)
		req_password = strdup (_("None"));

	return OK;
}
Esempio n. 4
0
int process_arguments(int argc, char **argv){
	int c;
	int option=0;
	static struct option longopts[] = {
		{"version", no_argument, 0, 'V'},
		{"help", no_argument, 0, 'h'},
		{"verbose", no_argument, 0, 'v'},
		{"use-ipv4", no_argument, 0, '4'},
		{"use-ipv6", no_argument, 0, '6'},
		{"quiet", no_argument, 0, 'q'},
		{"time-offset", optional_argument, 0, 'o'},
		{"warning", required_argument, 0, 'w'},
		{"critical", required_argument, 0, 'c'},
		{"timeout", required_argument, 0, 't'},
		{"hostname", required_argument, 0, 'H'},
		{"port", required_argument, 0, 'p'},
		{0, 0, 0, 0}
	};


	if (argc < 2)
		usage ("\n");

	while (1) {
		c = getopt_long (argc, argv, "Vhv46qw:c:t:H:p:o:", longopts, &option);
		if (c == -1 || c == EOF || c == 1)
			break;

		switch (c) {
		case 'h':
			print_help();
			exit(STATE_OK);
			break;
		case 'V':
			print_revision(progname, NP_VERSION);
			exit(STATE_OK);
			break;
		case 'v':
			verbose++;
			break;
		case 'q':
			quiet = 1;
			break;
		case 'w':
			owarn = optarg;
			break;
		case 'c':
			ocrit = optarg;
			break;
		case 'H':
			if(is_host(optarg) == FALSE)
				usage2(_("Invalid hostname/address"), optarg);
			server_address = strdup(optarg);
			break;
		case 'p':
			port = strdup(optarg);
			break;
		case 't':
			timeout_interval = parse_timeout_string(optarg);
			break;
		case 'o':
			time_offset=atoi(optarg);
                        break;
		case '4':
			address_family = AF_INET;
			break;
		case '6':
#ifdef USE_IPV6
			address_family = AF_INET6;
#else
			usage4 (_("IPv6 support not available"));
#endif
			break;
		case '?':
			/* print short usage statement if args not parsable */
			usage5 ();
			break;
		}
	}

	if(server_address == NULL){
		usage4(_("Hostname was not supplied"));
	}

	return 0;
}
Esempio n. 5
0
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
{
	int c = 1;
	char *user;
	struct passwd *pw;
	int option = 0;
	int err;
	int cflags = REG_NOSUB | REG_EXTENDED;
	char errbuf[MAX_INPUT_BUFFER];
	char *temp_string;
	int i=0;
	static struct option longopts[] = {
		{"warning", required_argument, 0, 'w'},
		{"critical", required_argument, 0, 'c'},
		{"metric", required_argument, 0, 'm'},
		{"timeout", required_argument, 0, 't'},
		{"status", required_argument, 0, 's'},
		{"ppid", required_argument, 0, 'p'},
		{"user", required_argument, 0, 'u'},
		{"command", required_argument, 0, 'C'},
		{"vsz", required_argument, 0, 'z'},
		{"rss", required_argument, 0, 'r'},
		{"pcpu", required_argument, 0, 'P'},
		{"elapsed", required_argument, 0, 'e'},
		{"argument-array", required_argument, 0, 'a'},
		{"help", no_argument, 0, 'h'},
		{"version", no_argument, 0, 'V'},
		{"verbose", no_argument, 0, 'v'},
		{"ereg-argument-array", required_argument, 0, CHAR_MAX+1},
		{"input-file", required_argument, 0, CHAR_MAX+2},
		{"no-kthreads", required_argument, 0, 'k'},
		{"traditional-filter", no_argument, 0, 'T'},
		{"cgroup-hierarchy", required_argument, 0, 'g'},
		{0, 0, 0, 0}
	};

	for (c = 1; c < argc; c++)
		if (strcmp ("-to", argv[c]) == 0)
			strcpy (argv[c], "-t");

	while (1) {
		c = getopt_long (argc, argv, "Vvhkt:c:w:p:s:u:C:a:z:r:m:P:Tg:",
			longopts, &option);

		if (c == -1 || c == EOF)
			break;

		switch (c) {
		case '?':									/* help */
			usage5 ();
		case 'h':									/* help */
			print_help ();
			exit (STATE_OK);
		case 'V':									/* version */
			print_revision (progname, NP_VERSION);
			exit (STATE_OK);
		case 't':									/* timeout period */
			timeout_interval = parse_timeout_string (optarg);
			break;
		case 'c':									/* critical threshold */
			critical_range = optarg;
			break;							 
		case 'w':									/* warning threshold */
			warning_range = optarg;
			break;
		case 'p':									/* process id */
			if (sscanf (optarg, "%d%[^0-9]", &ppid, tmp) == 1) {
				xasprintf (&fmt, "%s%sPPID = %d", (fmt ? fmt : "") , (options ? ", " : ""), ppid);
				options |= PPID;
				break;
			}
			usage4 (_("Parent Process ID must be an integer!"));
		case 's':									/* status */
			if (statopts)
				break;
			else
				statopts = optarg;
			xasprintf (&fmt, _("%s%sSTATE = %s"), (fmt ? fmt : ""), (options ? ", " : ""), statopts);
			options |= STAT;
			break;
		case 'u':									/* user or user id */
			if (is_integer (optarg)) {
				uid = atoi (optarg);
				pw = getpwuid ((uid_t) uid);
				/*  check to be sure user exists */
				if (pw == NULL)
					usage2 (_("UID was not found"), optarg);
			}
			else {
				pw = getpwnam (optarg);
				/*  check to be sure user exists */
				if (pw == NULL)
					usage2 (_("User name was not found"), optarg);
				/*  then get uid */
				uid = pw->pw_uid;
			}
			user = pw->pw_name;
			xasprintf (&fmt, "%s%sUID = %d (%s)", (fmt ? fmt : ""), (options ? ", " : ""),
			          uid, user);
			options |= USER;
			break;
		case 'C':									/* command */
			/* TODO: allow this to be passed in with --metric */
			if (prog)
				break;
			else
				prog = optarg;
			xasprintf (&fmt, _("%s%scommand name '%s'"), (fmt ? fmt : ""), (options ? ", " : ""),
			          prog);
			options |= PROG;
			break;
		case 'g':									/* cgroup hierarchy */
			if (cgroup_hierarchy)
				break;
			else
				cgroup_hierarchy = optarg;
			xasprintf (&fmt, _("%s%scgroup hierarchy '%s'"), (fmt ? fmt : ""), (options ? ", " : ""),
			          cgroup_hierarchy);
			options |= CGROUP_HIERARCHY;
			break;
		case 'a':									/* args (full path name with args) */
			/* TODO: allow this to be passed in with --metric */
			if (args)
				break;
			else
				args = optarg;
			xasprintf (&fmt, "%s%sargs '%s'", (fmt ? fmt : ""), (options ? ", " : ""), args);
			options |= ARGS;
			break;
		case CHAR_MAX+1:
			err = regcomp(&re_args, optarg, cflags);
			if (err != 0) {
				regerror (err, &re_args, errbuf, MAX_INPUT_BUFFER);
				die (STATE_UNKNOWN, "PROCS %s: %s - %s\n", _("UNKNOWN"), _("Could not compile regular expression"), errbuf);
			}
			/* Strip off any | within the regex optarg */
			temp_string = strdup(optarg);
			while(temp_string[i]!='\0'){
				if(temp_string[i]=='|')
					temp_string[i]=',';
				i++;
			}
			xasprintf (&fmt, "%s%sregex args '%s'", (fmt ? fmt : ""), (options ? ", " : ""), temp_string);
			options |= EREG_ARGS;
			break;
		case 'r': 					/* RSS */
			if (sscanf (optarg, "%d%[^0-9]", &rss, tmp) == 1) {
				xasprintf (&fmt, "%s%sRSS >= %d", (fmt ? fmt : ""), (options ? ", " : ""), rss);
				options |= RSS;
				break;
			}
			usage4 (_("RSS must be an integer!"));
		case 'z':					/* VSZ */
			if (sscanf (optarg, "%d%[^0-9]", &vsz, tmp) == 1) {
				xasprintf (&fmt, "%s%sVSZ >= %d", (fmt ? fmt : ""), (options ? ", " : ""), vsz);
				options |= VSZ;
				break;
			}
			usage4 (_("VSZ must be an integer!"));
		case 'P':					/* PCPU */
			/* TODO: -P 1.5.5 is accepted */
			if (sscanf (optarg, "%f%[^0-9.]", &pcpu, tmp) == 1) {
				xasprintf (&fmt, "%s%sPCPU >= %.2f", (fmt ? fmt : ""), (options ? ", " : ""), pcpu);
				options |= PCPU;
				break;
			}
			usage4 (_("PCPU must be a float!"));
		case 'm':
			xasprintf (&metric_name, "%s", optarg);
			if ( strcmp(optarg, "PROCS") == 0) {
				metric = METRIC_PROCS;
				break;
			} 
			else if ( strcmp(optarg, "VSZ") == 0) {
				metric = METRIC_VSZ;
				break;
			} 
			else if ( strcmp(optarg, "RSS") == 0 ) {
				metric = METRIC_RSS;
				break;
			}
			else if ( strcmp(optarg, "CPU") == 0 ) {
				metric = METRIC_CPU;
				break;
			}
			else if ( strcmp(optarg, "ELAPSED") == 0) {
				metric = METRIC_ELAPSED;
				break;
			}

			usage4 (_("Metric must be one of PROCS, VSZ, RSS, CPU, ELAPSED!"));
		case 'k':	/* linux kernel thread filter */
			kthread_filter = 1;
			break;
		case 'v':									/* command */
			verbose++;
			break;
		case 'T':
			usepid = 1;
			break;
		case CHAR_MAX+2:
			input_filename = optarg;
			break;
		}
	}

	c = optind;
	if ((! warning_range) && argv[c])
		warning_range = argv[c++];
	if ((! critical_range) && argv[c])
		critical_range = argv[c++];
	if (statopts == NULL && argv[c]) {
		xasprintf (&statopts, "%s", argv[c++]);
		xasprintf (&fmt, _("%s%sSTATE = %s"), (fmt ? fmt : ""), (options ? ", " : ""), statopts);
		options |= STAT;
	}

	/* this will abort in case of invalid ranges */
	set_thresholds (&procs_thresholds, warning_range, critical_range);

	return validate_arguments ();
}
Esempio n. 6
0
/* process command-line arguments */
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'},
    {"retries", required_argument, 0, 'r'},
    {"dig-arguments", required_argument, 0, 'A'},
    {"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'},
    {"port", required_argument, 0, 'p'},
    {"use-ipv4", no_argument, 0, '4'},
    {"use-ipv6", no_argument, 0, '6'},
    {0, 0, 0, 0}
  };

  if (argc < 2)
    return ERROR;

  while (1) {
    c = getopt_long (argc, argv, "hVvt:l:H:w:c:T:p:a:A:46r:", longopts, &option);

    if (c == -1 || c == EOF)
      break;

    switch (c) {
    case 'h':                 /* help */
      print_help ();
      exit (STATE_OK);
    case 'V':                 /* version */
      print_revision (progname, NP_VERSION);
      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 */
      timeout_interval = parse_timeout_string (optarg);
      break;
    case 'r':                 /* retires */
      if (is_intnonneg (optarg)) {
        number_tries = atoi (optarg);
      }
      else {
        usage_va(_("Number of retries must be a positive integer - %s"), optarg);
      }
      break;
    case 'A':                 /* dig arguments */
      dig_args = strdup(optarg);
      break;
    case 'v':                 /* verbose */
      verbose = TRUE;
      break;
    case 'T':
      record_type = optarg;
      break;
    case 'a':
      expected_address = optarg;
      break;
    case '4':
      query_transport = "-4";
      break;
    case '6':
      query_transport = "-6";
      break;
    default:                  /* usage5 */
      usage5();
    }
  }

  c = optind;
  if (dns_server == NULL) {
    if (c < argc) {
      host_or_die(argv[c]);
      dns_server = argv[c];
    }
    else {
      if (strcmp(query_transport,"-6") == 0)
        dns_server = strdup("::1");
      else
        dns_server = strdup ("127.0.0.1");
    }
  }

  return validate_arguments ();
}
Esempio n. 7
0
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
{
    int c, err, i;
    struct parameter_list *se;
    struct parameter_list *temp_list = NULL, *previous = NULL;
    struct parameter_list *temp_path_select_list = NULL;
    struct mount_entry *me, *temp_me;
    int result = OK;
    regex_t re;
    int cflags = REG_NOSUB | REG_EXTENDED;
    int default_cflags = cflags;
    char errbuf[MAX_INPUT_BUFFER];
    int fnd = 0;

    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'},
        {"kilobytes", no_argument, 0, 'k'},
        {"megabytes", no_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'},
        {"include-type", required_argument, 0, 'N'},
        {"newlines", no_argument, 0, 'n'},
        {"group", required_argument, 0, 'g'},
        {"eregi-path", required_argument, 0, 'R'},
        {"eregi-partition", required_argument, 0, 'R'},
        {"ereg-path", required_argument, 0, 'r'},
        {"ereg-partition", required_argument, 0, 'r'},
        {"freespace-ignore-reserved", no_argument, 0, 'f'},
        {"ignore-ereg-path", required_argument, 0, 'i'},
        {"ignore-ereg-partition", required_argument, 0, 'i'},
        {"ignore-eregi-path", required_argument, 0, 'I'},
        {"ignore-eregi-partition", required_argument, 0, 'I'},
        {"local", no_argument, 0, 'l'},
        {"stat-remote-fs", no_argument, 0, 'L'},
        {"mountpoint", no_argument, 0, 'M'},
        {"errors-only", no_argument, 0, 'e'},
        {"exact-match", no_argument, 0, 'E'},
        {"all", no_argument, 0, 'A'},
        {"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;

    for (i = 0; always_exclude[i]; ++i)
        np_add_name(&fs_exclude_list, always_exclude[i]);

    for (c = 1; c < argc; c++)
        if (strcmp ("-to", argv[c]) == 0)
            strcpy (argv[c], "-t");

    while (1) {
        c = getopt_long (argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLg:R:r:i:I:MEAn", longopts, &option);

        if (c == -1 || c == EOF)
            break;

        switch (c) {
        case 't':                 /* timeout period */
            timeout_interval = parse_timeout_string(optarg);
            break;
        /* See comments for 'c' */
        case 'w':                 /* warning threshold */
            if (strstr(optarg, "%")) {
                if (*optarg == '@') {
                    warn_freespace_percent = optarg;
                } else {
                    xasprintf(&warn_freespace_percent, "@%s", optarg);
                }
            } else {
                if (*optarg == '@') {
                    warn_freespace_units = optarg;
                } else {
                    xasprintf(&warn_freespace_units, "@%s", optarg);
                }
            }
            break;

        /* Awful mistake where the range values do not make sense. Normally,
           you alert if the value is within the range, but since we are using
           freespace, we have to alert if outside the range. Thus we artifically
           force @ at the beginning of the range, so that it is backwards compatible
        */
        case 'c':                 /* critical threshold */
            if (strstr(optarg, "%")) {
                if (*optarg == '@') {
                    crit_freespace_percent = optarg;
                } else {
                    xasprintf(&crit_freespace_percent, "@%s", optarg);
                }
            } else {
                if (*optarg == '@') {
                    crit_freespace_units = optarg;
                } else {
                    xasprintf(&crit_freespace_units, "@%s", optarg);
                }
            }
            break;

        case 'W':			/* warning inode threshold */
            if (*optarg == '@') {
                warn_freeinodes_percent = optarg;
            } else {
                xasprintf(&warn_freeinodes_percent, "@%s", optarg);
            }
            break;
        case 'K':			/* critical inode threshold */
            if (*optarg == '@') {
                crit_freeinodes_percent = optarg;
            } else {
                xasprintf(&crit_freeinodes_percent, "@%s", optarg);
            }
            break;
        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':
            stat_remote_fs = 1;
        case 'l':
            show_local_fs = 1;
            break;
        case 'p':                 /* select path */
            if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent ||
                    crit_freespace_percent || warn_usedspace_units || crit_usedspace_units ||
                    warn_usedspace_percent || crit_usedspace_percent || warn_usedinodes_percent ||
                    crit_usedinodes_percent || warn_freeinodes_percent || crit_freeinodes_percent )) {
                die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -p\n"));
            }

            /* add parameter if not found. overwrite thresholds if path has already been added  */
            if (! (se = np_find_parameter(path_select_list, optarg))) {
                se = np_add_parameter(&path_select_list, optarg);
            }
            se->group = group;
            set_all_thresholds(se);

            /* With autofs, it is required to stat() the path before re-populating the mount_list */
            stat_path(se);
            /* NB: We can't free the old mount_list "just like that": both list pointers and struct
             * pointers are copied around. One of the reason it wasn't done yet is that other parts
             * of check_disk need the same kind of cleanup so it'd better be done as a whole */
            mount_list = read_file_system_list (0);
            np_set_best_match(se, mount_list, exact_match);

            path_selected = TRUE;
            break;
        case 'x':                 /* exclude path or partition */
            np_add_name(&dp_exclude_list, optarg);
            break;
        case 'X':                 /* exclude file system type */
            np_add_name(&fs_exclude_list, optarg);
            break;
        case 'N':                 /* include file system type */
            np_add_name(&fs_include_list, optarg);
            break;
        case 'n':                 /* show each disk on a new line */
            newlines = TRUE;
            break;
        case 'v':                 /* verbose */
            verbose++;
            break;
        case 'q':                 /* TODO: this function should eventually go away (removed 2007-09-20) */
            /* verbose--; **replaced by line below**. -q was only a broken way of implementing -e */
            erronly = TRUE;
            break;
        case 'e':
            erronly = TRUE;
            break;
        case 'E':
            if (path_selected)
                die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set -E before selecting paths\n"));
            exact_match = TRUE;
            break;
        case 'f':
            freespace_ignore_reserved = TRUE;
            break;
        case 'g':
            if (path_selected)
                die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set group value before selecting paths\n"));
            group = optarg;
            break;
        case 'I':
            cflags |= REG_ICASE;
        case 'i':
            if (!path_selected)
                die (STATE_UNKNOWN, "DISK %s: %s\n", _("UNKNOWN"), _("Paths need to be selected before using -i/-I. Use -A to select all paths explicitly"));
            err = regcomp(&re, optarg, cflags);
            if (err != 0) {
                regerror (err, &re, errbuf, MAX_INPUT_BUFFER);
                die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"), _("Could not compile regular expression"), errbuf);
            }

            temp_list = path_select_list;

            previous = NULL;
            while (temp_list) {
                if (temp_list->best_match) {
                    if (np_regex_match_mount_entry(temp_list->best_match, &re)) {

                        if (verbose >=3)
                            printf("ignoring %s matching regex\n", temp_list->name);

                        temp_list = np_del_parameter(temp_list, previous);
                        /* pointer to first element needs to be updated if first item gets deleted */
                        if (previous == NULL)
                            path_select_list = temp_list;
                    } else {
                        previous = temp_list;
                        temp_list = temp_list->name_next;
                    }
                } else {
                    previous = temp_list;
                    temp_list = temp_list->name_next;
                }
            }


            cflags = default_cflags;
            break;

        case 'A':
            optarg = strdup(".*");
        case 'R':
            cflags |= REG_ICASE;
        case 'r':
            if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent ||
                    crit_freespace_percent || warn_usedspace_units || crit_usedspace_units ||
                    warn_usedspace_percent || crit_usedspace_percent || warn_usedinodes_percent ||
                    crit_usedinodes_percent || warn_freeinodes_percent || crit_freeinodes_percent )) {
                die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -r/-R\n"));
            }

            err = regcomp(&re, optarg, cflags);
            if (err != 0) {
                regerror (err, &re, errbuf, MAX_INPUT_BUFFER);
                die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"), _("Could not compile regular expression"), errbuf);
            }

            for (me = mount_list; me; me = me->me_next) {
                if (np_regex_match_mount_entry(me, &re)) {
                    fnd = TRUE;
                    if (verbose >= 3)
                        printf("%s %s matching expression %s\n", me->me_devname, me->me_mountdir, optarg);

                    /* add parameter if not found. overwrite thresholds if path has already been added  */
                    if (! (se = np_find_parameter(path_select_list, me->me_mountdir))) {
                        se = np_add_parameter(&path_select_list, me->me_mountdir);
                    }
                    se->group = group;
                    set_all_thresholds(se);
                }
            }

            if (!fnd)
                die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"),
                     _("Regular expression did not match any path or disk"), optarg);

            fnd = FALSE;
            path_selected = TRUE;
            np_set_best_match(path_select_list, mount_list, exact_match);
            cflags = default_cflags;

            break;
        case 'M': /* display mountpoint */
            display_mntp = TRUE;
            break;
        case 'C':
            /* add all mount entries to path_select list if no partitions have been explicitly defined using -p */
            if (path_selected == FALSE) {
                struct parameter_list *path;
                for (me = mount_list; me; me = me->me_next) {
                    if (! (path = np_find_parameter(path_select_list, me->me_mountdir)))
                        path = np_add_parameter(&path_select_list, me->me_mountdir);
                    path->best_match = me;
                    path->group = group;
                    set_all_thresholds(path);
                }
            }
            warn_freespace_units = NULL;
            crit_freespace_units = NULL;
            warn_usedspace_units = NULL;
            crit_usedspace_units = NULL;
            warn_freespace_percent = NULL;
            crit_freespace_percent = NULL;
            warn_usedspace_percent = NULL;
            crit_usedspace_percent = NULL;
            warn_usedinodes_percent = NULL;
            crit_usedinodes_percent = NULL;
            warn_freeinodes_percent = NULL;
            crit_freeinodes_percent = NULL;

            path_selected = FALSE;
            group = NULL;
            break;
        case 'V':                 /* version */
            print_revision (progname, NP_VERSION);
            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 (warn_usedspace_percent == NULL && argc > c && is_intnonneg (argv[c]))
        warn_usedspace_percent = argv[c++];

    if (crit_usedspace_percent == NULL && argc > c && is_intnonneg (argv[c]))
        crit_usedspace_percent = argv[c++];

    if (argc > c && path == NULL) {
        se = np_add_parameter(&path_select_list, strdup(argv[c++]));
        path_selected = TRUE;
        set_all_thresholds(se);
    }

    if (units == NULL) {
        units = strdup ("MB");
        mult = (uintmax_t)1024 * 1024;
    }

    return TRUE;
}