Status NEGEMMLowpAArch64V8P4Kernel::validate(const ITensorInfo *input0, const ITensorInfo *input1, const ITensorInfo *output)
{
    ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input0, input1, output));
    ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input0->clone().get(), input1->clone().get(), output->clone().get()).first);

    return Status{};
}
Пример #2
0
/* process command-line arguments */
int process_arguments(int argc, char **argv){
	int arg_index;

	if(argc<1)
		return ERROR;

	arg_index = call_getopt(argc,argv);
	return validate_arguments(argc,arg_index);
        }
Пример #3
0
static int process_arguments (int argc, char **argv) {

	int c;
        int escape = 0;
        char *temp;
	
        int option = 0;
        static struct option longopts[] = {
                {"critical", required_argument, 0, 'c'},
                {"warning", required_argument, 0, 'w'},
                {"timeunit", required_argument, 0, 'u'},
                {"verbose", no_argument, 0, 'v'},
                {"version", no_argument, 0, 'V'},
                {"help", no_argument, 0, 'h'},
                {0, 0, 0, 0}
        };

	while ( 1 ) {

		c = getopt_long ( argc, argv, "+hvVu:c:w:", longopts, &option );

		if ( c == -1 || c == EOF || c == 1 ) break;
	
		switch ( c ) {
			case '?':
				usage5 ();
			case 'h':
				print_help ();
				exit ( STATE_OK );
			case 'v':
				verbose++;
				if (verbose >= 3) {
					printf("Verbose mode enabled\n");
				}
				break;
    			case 'V':
      				print_revision (progname, NP_VERSION);
      				exit (STATE_OK);
			case 'u':
				timeunit = optarg;
				break;
			case 'c':
				critical = optarg;
				break;
			case 'w':
				warning = optarg;
				break;
			} // end case
		} // end while

	c = optind;
	set_thresholds(&my_thresholds, warning, critical);
	return validate_arguments ();

} // end process_arguments
Пример #4
0
/* process command-line arguments */
int process_arguments(int argc, char **argv){
	int c;

	if(argc<1)
		return ERROR;

	c=0;
	while((c+=(call_getopt(argc-c,&argv[c])))<argc){

		/*
		if(is_option(argv[c]))
			continue;
		*/
		}

	return validate_arguments();
        }
Пример #5
0
void settings_controller::get_key(Mongoose::Request &request, boost::smatch &what, Mongoose::StreamResponse &response) {
	if (!session->is_loggedin("settings", request, response))
		return;

	if (!validate_arguments(2, what, response)) {
		return;
	}
	std::string path = what.str(1);
	std::string key = what.str(2);

	if (!session->can("settings.get", request, response))
		return;

	Plugin::SettingsRequestMessage rm;
	Plugin::SettingsRequestMessage::Request *payload = rm.add_payload();
	payload->mutable_query()->mutable_node()->set_path(path);
	payload->mutable_query()->mutable_node()->set_key(key);
	payload->mutable_query()->set_recursive(false);
	payload->set_plugin_id(plugin_id);

	std::string str_response;
	core->settings_query(rm.SerializeAsString(), str_response);
	Plugin::SettingsResponseMessage pb_response;
	pb_response.ParseFromString(str_response);
	json_spirit::Object node;

	BOOST_FOREACH(const Plugin::SettingsResponseMessage::Response r, pb_response.payload()) {
		if (!r.has_query()) {
			response.setCode(HTTP_NOT_FOUND);
			response.append("Key not found: " + path + "/" + key);
			return;
		}
		const Plugin::SettingsResponseMessage::Response::Query &i = r.query();
		node["path"] = i.node().path();
		node["key"] = i.node().key();
		if (i.value().has_string_data()) {
			node["value"] = i.value().string_data();
		} else if (i.value().has_int_data()) {
			node["value"] = i.value().int_data();
		} else if (i.value().has_bool_data()) {
			node["value"] = i.value().bool_data();
		}
	}
	response.append(json_spirit::write(node));
}
Пример #6
0
Файл: main.c Проект: thutt/lmsbw
int
main(int argc, char *argv[])
{
    directory_t *root;
    unsigned int seed = (unsigned int)time(NULL);

    process_arguments(argc, argv);
    validate_arguments();

    if (arg_seed_set) {
        seed = arg_seed;
    }
    srand(seed);

    root = create_structure(0, arg_root);
    create_source_tree(root);
    printf("Random Number Seed: %u\n", seed);
    return 0;
}
void NEGEMMLowpAArch64V8P4Kernel::internal_configure(const ITensor *input0, const ITensor *input1, ITensor *output, ITensor *workspace, float alpha, float beta, bool transform_0, bool transform_1)
{
    // Perform validate step
    ARM_COMPUTE_ERROR_ON_NULLPTR(input0, input1, output);
    ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input0->info(), input1->info(), output->info()));

    _input0      = input0;
    _input1      = input1;
    _output      = output;
    _workspace   = workspace;
    _alpha       = alpha;
    _beta        = beta;
    _transform_0 = transform_0;
    _transform_1 = transform_1;

    // Configure kernel window
    auto win_config = validate_and_configure_window(input0->info(), input1->info(), output->info());
    ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
    INEKernel::configure(win_config.second);
}
Пример #8
0
int main(int argc, const char** argv)
{
    if(parse_arguments(argc, argv) < 0) {
        print_usage(argv[0]);
        exit(1);
    }

    if(validate_arguments() < 0) {
        print_usage(argv[0]);
        exit(1);
    }


    printf("Waiting for S2E mode...\n");
    while(s2e_version() == 0) /* nothing */;
    printf("... S2E mode detected\n");

    copy_file(g_target_dir, g_file);

    return 0;
}
Пример #9
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'},
		{"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},
		{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, "Vvht:c:w:p:s:u:C:a:z:r:m:P:", 
			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 */
			if (!is_integer (optarg))
				usage2 (_("Timeout interval must be a positive integer"), optarg);
			else
				timeout_interval = atoi (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 '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 'v':									/* command */
			verbose++;
			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 ();
}
Пример #10
0
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
{
  int c;
  char *warning = NULL;
  char *critical = NULL;

  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'},
    {"warning", required_argument, 0, 'w'},
    {"critical", required_argument, 0, 'c'},
    {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:w:c:", 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, NP_VERSION);
      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"));
      expected_address = (char **)realloc(expected_address, (expected_address_cnt+1) * sizeof(char**));
      expected_address[expected_address_cnt] = strdup(optarg);
      expected_address_cnt++;
      break;
    case 'A': /* expect authority */
      expect_authority = TRUE;
      break;
    case 'w':
      warning = optarg;
      break;
    case 'c':
      critical = optarg;
      break;
    default: /* args not parsable */
      usage5();
    }
  }

  c = optind;
  if (strlen(query_address)==0 && c<argc) {
    if (strlen(argv[c])>=ADDRESS_LENGTH)
      die (STATE_UNKNOWN, _("Input buffer overflow\n"));
    strcpy (query_address, argv[c++]);
  }

  if (strlen(dns_server)==0 && c<argc) {
    /* TODO: See -s option */
    host_or_die(argv[c]);
    if (strlen(argv[c]) >= ADDRESS_LENGTH)
      die (STATE_UNKNOWN, _("Input buffer overflow\n"));
    strcpy (dns_server, argv[c++]);
  }

  set_thresholds(&time_thresholds, warning, critical);

  return validate_arguments ();
}
Пример #11
0
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
{
    int c = 1;
    char *ptr;

    int option = 0;
    static struct option longopts[] = {
        STD_LONG_OPTS,
        {"packets", required_argument, 0, 'p'},
        {"nohtml", no_argument, 0, 'n'},
        {"link", no_argument, 0, 'L'},
        {"use-ipv4", no_argument, 0, '4'},
        {"use-ipv6", no_argument, 0, '6'},
        {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");
        if (strcmp ("-nohtml", argv[c]) == 0)
            strcpy (argv[c], "-n");
    }

    while (1) {
        c = getopt_long (argc, argv, "VvhnL46t:c:w:H:p:", longopts, &option);

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

        switch (c) {
        case '?':	/* usage */
            usage5 ();
        case 'h':	/* help */
            print_help ();
            exit (STATE_UNKNOWN);
            break;
        case 'V':	/* version */
            print_revision (progname, NP_VERSION);
            exit (STATE_UNKNOWN);
            break;
        case 't':	/* timeout period */
            timeout_interval = atoi (optarg);
            break;
        case 'v':	/* verbose mode */
            verbose++;
            break;
        case '4':	/* IPv4 only */
            address_family = AF_INET;
            break;
        case '6':	/* IPv6 only */
#ifdef USE_IPV6
            address_family = AF_INET6;
#else
            usage (_("IPv6 support not available\n"));
#endif
            break;
        case 'H':	/* hostname */
            ptr=optarg;
            while (1) {
                n_addresses++;
                if (n_addresses > max_addr) {
                    max_addr *= 2;
                    addresses = realloc (addresses, sizeof(char*) * max_addr);
                    if (addresses == NULL)
                        die (STATE_UNKNOWN, _("Could not realloc() addresses\n"));
                }
                addresses[n_addresses-1] = ptr;
                if ((ptr = index (ptr, ','))) {
                    strcpy (ptr, "");
                    ptr += sizeof(char);
                } else {
                    break;
                }
            }
            break;
        case 'p':	/* number of packets to send */
            if (is_intnonneg (optarg))
                max_packets = atoi (optarg);
            else
                usage2 (_("<max_packets> (%s) must be a non-negative number\n"), optarg);
            break;
        case 'n':	/* no HTML */
            display_html = FALSE;
            break;
        case 'L':	/* show HTML */
            display_html = TRUE;
            break;
        case 'c':
            get_threshold (optarg, &crta, &cpl);
            break;
        case 'w':
            get_threshold (optarg, &wrta, &wpl);
            break;
        }
    }

    c = optind;
    if (c == argc)
        return validate_arguments ();

    if (addresses[0] == NULL) {
        if (is_host (argv[c]) == FALSE) {
            usage2 (_("Invalid hostname/address"), argv[c]);
        } else {
            addresses[0] = argv[c++];
            n_addresses++;
            if (c == argc)
                return validate_arguments ();
        }
    }

    if (wpl == UNKNOWN_PACKET_LOSS) {
        if (is_intpercent (argv[c]) == FALSE) {
            printf (_("<wpl> (%s) must be an integer percentage\n"), argv[c]);
            return ERROR;
        } else {
            wpl = atoi (argv[c++]);
            if (c == argc)
                return validate_arguments ();
        }
    }

    if (cpl == UNKNOWN_PACKET_LOSS) {
        if (is_intpercent (argv[c]) == FALSE) {
            printf (_("<cpl> (%s) must be an integer percentage\n"), argv[c]);
            return ERROR;
        } else {
            cpl = atoi (argv[c++]);
            if (c == argc)
                return validate_arguments ();
        }
    }

    if (wrta < 0.0) {
        if (is_negative (argv[c])) {
            printf (_("<wrta> (%s) must be a non-negative number\n"), argv[c]);
            return ERROR;
        } else {
            wrta = atof (argv[c++]);
            if (c == argc)
                return validate_arguments ();
        }
    }

    if (crta < 0.0) {
        if (is_negative (argv[c])) {
            printf (_("<crta> (%s) must be a non-negative number\n"), argv[c]);
            return ERROR;
        } else {
            crta = atof (argv[c++]);
            if (c == argc)
                return validate_arguments ();
        }
    }

    if (max_packets == -1) {
        if (is_intnonneg (argv[c])) {
            max_packets = atoi (argv[c++]);
        } else {
            printf (_("<max_packets> (%s) must be a non-negative number\n"), argv[c]);
            return ERROR;
        }
    }

    return validate_arguments ();
}
Пример #12
0
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
{
	int c;

	int option = 0;
	static struct option longopts[] = {
		{"help", no_argument, 0, 'h'},
		{"version", no_argument, 0, 'V'},
		{"timeout", required_argument, 0, 't'},
		{"critical", required_argument, 0, 'c'},
		{"warning", required_argument, 0, 'w'},
		{"hostname", required_argument, 0, 'H'},
		{"logname", required_argument, 0, 'l'},
		{"password", required_argument, 0, 'p'},
		{"authorization", required_argument, 0, 'a'},
		{"port", required_argument, 0, 'P'},
		{"database", required_argument, 0, 'd'},
		{"verbose", no_argument, 0, 'v'},
		{0, 0, 0, 0}
	};

	while (1) {
		c = getopt_long (argc, argv, "hVt:c:w:H:P:d:l:p:a:v",
		                 longopts, &option);

		if (c == EOF)
			break;

		switch (c) {
		case '?':     /* usage */
			usage5 ();
		case 'h':     /* help */
			print_help ();
			exit (STATE_OK);
		case 'V':     /* version */
			print_revision (progname, NP_VERSION);
			exit (STATE_OK);
		case 't':     /* timeout period */
			if (!is_integer (optarg))
				usage2 (_("Timeout interval must be a positive integer"), optarg);
			else
				timeout_interval = atoi (optarg);
			break;
		case 'c':     /* critical time threshold */
			if (!is_nonnegative (optarg))
				usage2 (_("Critical threshold must be a positive integer"), optarg);
			else
				tcrit = strtod (optarg, NULL);
			break;
		case 'w':     /* warning time threshold */
			if (!is_nonnegative (optarg))
				usage2 (_("Warning threshold must be a positive integer"), optarg);
			else
				twarn = strtod (optarg, NULL);
			break;
		case 'H':     /* host */
			if (!is_host (optarg))
				usage2 (_("Invalid hostname/address"), optarg);
			else
				pghost = optarg;
			break;
		case 'P':     /* port */
			if (!is_integer (optarg))
				usage2 (_("Port must be a positive integer"), optarg);
			else
				pgport = optarg;
			break;
		case 'd':     /* database name */
			if (!is_pg_dbname (optarg)) /* checks length and valid chars */
				usage2 (_("Database name is not valid"), optarg);
			else /* we know length, and know optarg is terminated, so us strcpy */
				strcpy (dbName, optarg);
			break;
		case 'l':     /* login name */
			if (!is_pg_logname (optarg))
				usage2 (_("User name is not valid"), optarg);
			else
				pguser = optarg;
			break;
		case 'p':     /* authentication password */
		case 'a':
			pgpasswd = optarg;
			break;
		case 'v':
			verbose++;
			break;
		}
	}

	return validate_arguments ();
}
Пример #13
0
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
{
	int c;
	char *warning = NULL;
	char *critical = NULL;

	int option = 0;
	static struct option longopts[] = {
		{"hostname", required_argument, 0, 'H'},
		{"socket", required_argument, 0, 's'},
		{"database", required_argument, 0, 'd'},
		{"username", required_argument, 0, 'u'},
		{"password", required_argument, 0, 'p'},
		{"file", required_argument, 0, 'f'},
		{"group", required_argument, 0, 'g'},
		{"port", required_argument, 0, 'P'},
		{"critical", required_argument, 0, 'c'},
		{"warning", required_argument, 0, 'w'},
		{"check-slave", no_argument, 0, 'S'},
		{"verbose", no_argument, 0, 'v'},
		{"version", no_argument, 0, 'V'},
		{"help", no_argument, 0, 'h'},
		{0, 0, 0, 0}
	};

	if (argc < 1)
		return ERROR;

	while (1) {
		c = getopt_long (argc, argv, "hvVSP:p:u:d:f:g:H:s:c:w:", longopts, &option);

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

		switch (c) {
		case 'H':									/* hostname */
			if (is_host (optarg)) {
				db_host = optarg;
			}
			else {
				usage2 (_("Invalid hostname/address"), optarg);
			}
			break;
		case 's':									/* socket */
			db_socket = optarg;
			break;
		case 'd':									/* database */
			db = optarg;
			break;
		case 'u':									/* username */
			db_user = optarg;
			break;
		case 'p':									/* authentication information: password */
			db_pass = strdup(optarg);

			/* Delete the password from process list */
			while (*optarg != '\0') {
				*optarg = 'X';
				optarg++;
			}
			break;
		case 'f':									/* username */
			opt_file = optarg;
			break;
		case 'g':									/* username */
			opt_group = optarg;
			break;
		case 'P':									/* critical time threshold */
			db_port = atoi (optarg);
			break;
		case 'S':
			check_slave = 1;							/* check-slave */
			break;
		case 'w':
			warning = optarg;
			break;
		case 'c':
			critical = optarg;
			break;
		case 'V':									/* version */
			print_revision (progname, NP_VERSION);
			exit (STATE_OK);
		case 'h':									/* help */
			print_help ();
			exit (STATE_OK);
		case 'v':
			verbose++;
			break;
		case '?':									/* help */
			usage5 ();
		}
	}

	c = optind;

	set_thresholds(&my_threshold, warning, critical);

	while ( argc > c ) {

		if (db_host == NULL)
			if (is_host (argv[c])) {
				db_host = argv[c++];
			}
			else {
				usage2 (_("Invalid hostname/address"), argv[c]);
			}
		else if (db_user == NULL)
			db_user = argv[c++];
		else if (opt_file == NULL)
			opt_file = argv[c++];
		else if (opt_group == NULL)
			opt_group = argv[c++];
		else if (db_pass == NULL)
			db_pass = argv[c++];
		else if (db == NULL)
			db = argv[c++];
		else if (is_intnonneg (argv[c]))
			db_port = atoi (argv[c++]);
		else
			break;
	}

	return validate_arguments ();
}
Пример #14
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'},
		{"community", required_argument, 0, 'C'},
/*  		{"critical",       required_argument,0,'c'}, */
/*  		{"warning",        required_argument,0,'w'}, */
  		{"port", required_argument,0,'p'}, 
		{"version", no_argument, 0, 'V'},
		{"help", no_argument, 0, 'h'},
		{0, 0, 0, 0}
	};

	if (argc < 2)
		return ERROR;


	while (1) {
		c = getopt_long (argc, argv, "+hVH:C:p:", longopts, &option);

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

		switch (c) {
		case 'H':									/* hostname */
			if (is_host (optarg)) {
				address = strscpy(address, optarg) ;
			}
			else {
				usage2 (_("Invalid hostname/address"), optarg);
			}
			break;
		case 'C':									/* community */
			community = strscpy (community, optarg);
			break;
		case 'p':
			if (!is_intpos(optarg))
				usage2 (_("Port must be a positive short integer"), optarg);
			else
				port = atoi(optarg);
			break;
		case 'V':									/* version */
			print_revision (progname, NP_VERSION);
			exit (STATE_UNKNOWN);
		case 'h':									/* help */
			print_help ();
			exit (STATE_UNKNOWN);
		case '?':									/* help */
			usage5 ();
		}
	}

	c = optind;
	if (address == NULL) {
		if (is_host (argv[c])) {
			address = argv[c++];
		}
		else {
			usage2 (_("Invalid hostname/address"), argv[c]);
		}
	}

	if (community == NULL) {
		if (argv[c] != NULL )
			community = argv[c];
		else
			community = strdup (DEFAULT_COMMUNITY);
	}

	if (port == NULL) {
		if (argv[c] != NULL )
			port = argv[c];
		else
			port = atoi (DEFAULT_PORT);
	}

	return validate_arguments ();
}
Пример #15
0
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
{
	int c;
	char* temp;

	int option = 0;
	static struct option longopts[] = {
		{"hostname", required_argument, 0, 'H'},
		{"expect", required_argument, 0, 'e'},
		{"critical", required_argument, 0, 'c'},
		{"warning", required_argument, 0, 'w'},
		{"timeout", required_argument, 0, 't'},
		{"port", required_argument, 0, 'p'},
		{"from", required_argument, 0, 'f'},
		{"fqdn", required_argument, 0, 'F'},
		{"authtype", required_argument, 0, 'A'},
		{"authuser", required_argument, 0, 'U'},
		{"authpass", required_argument, 0, 'P'},
		{"command", required_argument, 0, 'C'},
		{"response", required_argument, 0, 'R'},
		{"verbose", no_argument, 0, 'v'},
		{"version", no_argument, 0, 'V'},
		{"use-ipv4", no_argument, 0, '4'},
		{"use-ipv6", no_argument, 0, '6'},
		{"help", no_argument, 0, 'h'},
		{"starttls",no_argument,0,'S'},
		{"certificate",required_argument,0,'D'},
		{"ignore-quit-failure",no_argument,0,'q'},
		{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");
		else if (strcmp ("-wt", argv[c]) == 0)
			strcpy (argv[c], "-w");
		else if (strcmp ("-ct", argv[c]) == 0)
			strcpy (argv[c], "-c");
	}

	while (1) {
		c = getopt_long (argc, argv, "+hVv46t:p:f:e:c:w:H:C:R:SD:F:A:U:P:q",
		                 longopts, &option);

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

		switch (c) {
		case 'H':									/* hostname */
			if (is_host (optarg)) {
				server_address = optarg;
			}
			else {
				usage2 (_("Invalid hostname/address"), optarg);
			}
			break;
		case 'p':									/* port */
			if (is_intpos (optarg))
				server_port = atoi (optarg);
			else
				usage4 (_("Port must be a positive integer"));
			break;
		case 'F':
		/* localhostname */
			localhostname = strdup(optarg);
			break;
		case 'f':									/* from argument */
			from_arg = optarg + strspn(optarg, "<");
			from_arg = strndup(from_arg, strcspn(from_arg, ">"));
			send_mail_from = 1;
			break;
		case 'A':
			authtype = optarg;
			use_ehlo = TRUE;
			break;
		case 'U':
			authuser = optarg;
			break;
		case 'P':
			authpass = optarg;
			break;
		case 'e':									/* server expect string on 220  */
			server_expect = optarg;
			break;
		case 'C':									/* commands  */
			if (ncommands >= command_size) {
				command_size+=8;
				commands = realloc (commands, sizeof(char *) * command_size);
				if (commands == NULL)
					die (STATE_UNKNOWN,
					     _("Could not realloc() units [%d]\n"), ncommands);
			}
			commands[ncommands] = (char *) malloc (sizeof(char) * 255);
			strncpy (commands[ncommands], optarg, 255);
			ncommands++;
			break;
		case 'R':									/* server responses */
			if (nresponses >= response_size) {
				response_size += 8;
				responses = realloc (responses, sizeof(char *) * response_size);
				if (responses == NULL)
					die (STATE_UNKNOWN,
					     _("Could not realloc() units [%d]\n"), nresponses);
			}
			responses[nresponses] = (char *) malloc (sizeof(char) * 255);
			strncpy (responses[nresponses], optarg, 255);
			nresponses++;
			break;
		case 'c':									/* critical time threshold */
			if (!is_nonnegative (optarg))
				usage4 (_("Critical time must be a positive"));
			else {
				critical_time = strtod (optarg, NULL);
				check_critical_time = TRUE;
			}
			break;
		case 'w':									/* warning time threshold */
			if (!is_nonnegative (optarg))
				usage4 (_("Warning time must be a positive"));
			else {
				warning_time = strtod (optarg, NULL);
				check_warning_time = TRUE;
			}
			break;
		case 'v':									/* verbose */
			verbose++;
			break;
		case 'q':
			ignore_send_quit_failure++;             /* ignore problem sending QUIT */
			break;
		case 't':									/* timeout */
			if (is_intnonneg (optarg)) {
				socket_timeout = atoi (optarg);
			}
			else {
				usage4 (_("Timeout interval must be a positive integer"));
			}
			break;
		case 'S':
		/* starttls */
			use_ssl = TRUE;
			use_ehlo = TRUE;
			break;
		case 'D':
		/* Check SSL cert validity */
#ifdef USE_OPENSSL
                        if ((temp=strchr(optarg,','))!=NULL) {
                            *temp='\0';
                            if (!is_intnonneg (optarg))
                               usage2 ("Invalid certificate expiration period", optarg);
                            days_till_exp_warn = atoi(optarg);
                            *temp=',';
                            temp++;
                            if (!is_intnonneg (temp))
                                usage2 (_("Invalid certificate expiration period"), temp);
                            days_till_exp_crit = atoi (temp);
                        }
                        else {
                            days_till_exp_crit=0;
                            if (!is_intnonneg (optarg))
                                usage2 ("Invalid certificate expiration period", optarg);
                            days_till_exp_warn = atoi (optarg);
                        }
			check_cert = TRUE;
#else
			usage (_("SSL support not available - install OpenSSL and recompile"));
#endif
			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 'V':									/* version */
			print_revision (progname, NP_VERSION);
			exit (STATE_OK);
		case 'h':									/* help */
			print_help ();
			exit (STATE_OK);
		case '?':									/* help */
			usage5 ();
		}
	}

	c = optind;
	if (server_address == NULL) {
		if (argv[c]) {
			if (is_host (argv[c]))
				server_address = argv[c];
			else
				usage2 (_("Invalid hostname/address"), argv[c]);
		}
		else {
			xasprintf (&server_address, "127.0.0.1");
		}
	}

	if (server_expect == NULL)
		server_expect = strdup (SMTP_EXPECT);

	if (mail_command == NULL)
		mail_command = strdup("MAIL ");

	if (from_arg==NULL)
		from_arg = strdup(" ");

	return validate_arguments ();
}
Пример #16
0
void _seq_batch_r(void* exec)
{



    EtalisEvent* Event_b  = (EtalisEvent*)exec;
    if (Event_b == NULL) return;
    EtalisExecNode* rule_ = Event_b->RootModel->parentNode;

    EtalisEvent* Event_a=NULL;

    /* calculate EAT */

    float EAT = getHighResStamp(&Event_b->timestamps[1]) - rule_->window_size; /* TODO fix */

    if (rule_->leftChild->is_temp)
    {
        _seq_batch_r(StackPop(rule_->leftChild->childNode->rightChild->eventStack));
    }


    do
    {
        /*if (getHighResStamp(&Event_b->timestamps[0]) < EAT ) { free(Event_b); continue;} /* problem : all atomic right side events does not fulfill this condition */
        Event_a = StackPop(rule_->leftChild->eventStack);
        while( Event_a != NULL && getTimeDiff(&(Event_b->timestamps[0]),&(Event_a->timestamps[1])) >= 0 ) /* problem : recursion */
        {
            /*if (getHighResStamp(&Event_a->timestamps[0]) < EAT )*/ /* EAT is not compatible with timestamps */
            if (Event_b->timestamps[1].time - Event_a->timestamps[0].time  > rule_->window_size)
            {
                free (Event_a);
                Event_a = StackPop(rule_->leftChild->eventStack);
                continue; /* normally you don't have to continue here, because events are already choronogically ordered in the stack */ /* fix this */
            }
            if(validate_arguments(Event_b,Event_a) != ETALIS_OK)
            {
#ifdef DEBUG
                printf("Event arguments could not be validated ! \n");
#endif
                free(Event_a); /* check*/
                Event_a = StackPop(rule_->leftChild->eventStack);
                continue;
            }

            EtalisEventNode* cplxEvModel=NULL; /* Complex Event Root Model */

            /* the rest depends on the CEP policy */
            if (_conf.policy==recent) /* recent policy */
            {
                cplxEvModel = rule_->parentEvent;

                /* triggering the complex event */
                EtalisEvent* cplxEvent = (EtalisEvent*)malloc(sizeof(EtalisEvent));
                cplxEvent->RootModel = rule_->parentEvent;
                /* bind the arguments of the complex event */ /* todo validate */
                cplxEvent->args = (int*)malloc(sizeof(int)*cplxEvModel->event.arity);
                size_t arg_iterator=0;
                for(arg_iterator=0; arg_iterator<cplxEvModel->event.arity; arg_iterator++)
                {
                    switch (cplxEvModel->arg_links[arg_iterator].event_)
                    {
                    case 1 :
                        *((int*)cplxEvent->args+arg_iterator)=*((int*)Event_a->args+(cplxEvModel->arg_links[arg_iterator].argument_number));
                        break;

                    case 2 :
                        *((int*)cplxEvent->args+arg_iterator)=*((int*)Event_b->args+(cplxEvModel->arg_links[arg_iterator].argument_number));
                        break;
                    }
                }


                cplxEvent->timestamps[0] = Event_a->timestamps[0]; /* timestamp structure as suggested by the ETALIS paper */
                cplxEvent->timestamps[1] = Event_b->timestamps[1];
                triggerEvent_intern_no_hash(cplxEvent);            /* trigger the complex event (we already know the EventModel, so we don't need to search for it in the _event_hash) */

                /* garbage collect : we don't need these events anymore */
                free(Event_a);
                free(Event_b);
                return;
            }
            else if (_conf.policy==unrestricted)
            {
                /* TODO */
                return ;
            }

            Event_a = StackPop(rule_->leftChild->eventStack);
        }


    }
    while (Event_b = StackPop(Event_b->RootModel->eventStack));









}
Пример #17
0
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
{
	int c;
	char *warning = NULL;
	char *critical = NULL;

	int option = 0;
	static struct option longopts[] = {
		{"hostname", required_argument, 0, 'H'},
		{"socket", required_argument, 0, 's'},
		{"database", required_argument, 0, 'd'},
		{"username", required_argument, 0, 'u'},
		{"password", required_argument, 0, 'p'},
		{"port", required_argument, 0, 'P'},
		{"verbose", no_argument, 0, 'v'},
		{"version", no_argument, 0, 'V'},
		{"help", no_argument, 0, 'h'},
		{"query", required_argument, 0, 'q'},
		{"warning", required_argument, 0, 'w'},
		{"critical", required_argument, 0, 'c'},
		{0, 0, 0, 0}
	};

	if (argc < 1)
		return ERROR;

	while (1) {
		c = getopt_long (argc, argv, "hvVP:p:u:d:H:s:q:w:c:", longopts, &option);

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

		switch (c) {
		case 'H':									/* hostname */
			if (is_host (optarg)) {
				db_host = optarg;
			}
			else {
				usage2 (_("Invalid hostname/address"), optarg);
			}
			break;
		case 's':									/* socket */
			db_socket = optarg;
			break;
		case 'd':									/* database */
			db = optarg;
			break;
		case 'u':									/* username */
			db_user = optarg;
			break;
		case 'p':									/* authentication information: password */
			db_pass = strdup(optarg);

			/* Delete the password from process list */
			while (*optarg != '\0') {
				*optarg = 'X';
				optarg++;
			}
			break;
		case 'P':									/* critical time threshold */
			db_port = atoi (optarg);
			break;
		case 'v':
			verbose++;
			break;
		case 'V':									/* version */
			print_revision (progname, NP_VERSION);
			exit (STATE_OK);
		case 'h':									/* help */
			print_help ();
			exit (STATE_OK);
		case 'q':
			xasprintf(&sql_query, "%s", optarg);
			break;
		case 'w':
			warning = optarg;
			break;
		case 'c':
			critical = optarg;
			break;
		case '?':									/* help */
			usage5 ();
		}
	}

	c = optind;

	set_thresholds(&my_thresholds, warning, critical);

	return validate_arguments ();
}
Пример #18
0
int main(void) {
	int result = OK;

	/* get the arguments passed in the URL */
	process_cgivars();

	/* reset internal variables */
	reset_cgi_vars();

	document_header();

	/* validate arguments in URL */
	result = validate_arguments();
	if(result == ERROR) {
		document_footer();
		return ERROR;
		}

	/* read the CGI configuration file */
	result = read_cgi_config_file(get_cgi_config_location());
	if(result == ERROR) {
		printf("<P>Error: Could not open CGI configuration file '%s' for reading!</P>\n", get_cgi_config_location());
		document_footer();
		return ERROR;
		}

	/* read the main configuration file */
	result = read_main_config_file(main_config_file);
	if(result == ERROR) {
		printf("<P>Error: Could not open main configuration file '%s' for reading!</P>\n", main_config_file);
		document_footer();
		return ERROR;
		}

	/* read all object configuration data */
	result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
	if(result == ERROR) {
		printf("<P>Error: Could not read some or all object configuration data!</P>\n");
		document_footer();
		return ERROR;
		}

	/* read all status data */
	result = read_all_status_data(get_cgi_config_location(), READ_ALL_STATUS_DATA);
	if(result == ERROR) {
		printf("<P>Error: Could not read host and service status information!</P>\n");
		document_footer();
		free_memory();
		return ERROR;
		}

	/* get authentication information */
	get_authentication_information(&current_authdata);

	/* decide what to display to the user */
	if(display_type == DISPLAY_HOST && host_style == DISPLAY_HOST_SERVICES)
		display_host_services();
	else if(display_type == DISPLAY_HOST)
		display_host();
	else if(display_type == DISPLAY_SERVICE)
		display_service();
	else if(display_type == DISPLAY_HOSTGROUP && hostgroup_style == DISPLAY_HOSTGROUP_OVERVIEW)
		display_hostgroup_overview();
	else if(display_type == DISPLAY_HOSTGROUP && hostgroup_style == DISPLAY_HOSTGROUP_SUMMARY)
		display_hostgroup_summary();
	else if(display_type == DISPLAY_PING)
		display_ping();
	else if(display_type == DISPLAY_TRACEROUTE)
		display_traceroute();
	else if(display_type == DISPLAY_QUICKSTATS)
		display_quick_stats();
	else if(display_type == DISPLAY_PROCESS)
		display_process();
	else if(display_type == DISPLAY_ALL_PROBLEMS || display_type == DISPLAY_UNHANDLED_PROBLEMS)
		display_problems();
	else
		display_index();

	document_footer();

	/* free all allocated memory */
	free_memory();

	return OK;
	}
Пример #19
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'},
		{"aggregation", required_argument, 0, 'a'},
		{"critical", required_argument, 0, 'c'},
		{"warning", required_argument, 0, 'w'},
		{"version", no_argument, 0, 'V'},
		{"help", no_argument, 0, 'h'},
		{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");
		else if (strcmp ("-wt", argv[c]) == 0)
			strcpy (argv[c], "-w");
		else if (strcmp ("-ct", argv[c]) == 0)
			strcpy (argv[c], "-c");
	}

	while (1) {
		c = getopt_long (argc, argv, "hVF:e:a:c:w:", longopts, &option);

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

		switch (c) {
		case 'F':									/* input file */
			log_file = optarg;
			break;
		case 'e':									/* expiration time */
			expire_minutes = atoi (optarg);
			break;
		case 'a':									/* aggregation (AVE or MAX) */
			if (!strcmp (optarg, "MAX"))
				use_average = FALSE;
			else
				use_average = TRUE;
			break;
		case 'c':									/* warning threshold */
			sscanf (optarg, "%lu,%lu", &incoming_critical_threshold,
							&outgoing_critical_threshold);
			break;
		case 'w':									/* critical threshold */
			sscanf (optarg, "%lu,%lu", &incoming_warning_threshold,
							&outgoing_warning_threshold);
			break;
		case 'V':									/* version */
			print_revision (progname, NP_VERSION);
			exit (STATE_OK);
		case 'h':									/* help */
			print_help ();
			exit (STATE_OK);
		case '?':									/* help */
			usage5 ();
		}
	}

	c = optind;
	if (argc > c && log_file == NULL) {
		log_file = argv[c++];
	}

	if (argc > c && expire_minutes == -1) {
		expire_minutes = atoi (argv[c++]);
	}

	if (argc > c && strcmp (argv[c], "MAX") == 0) {
		use_average = FALSE;
		c++;
	}
	else if (argc > c && strcmp (argv[c], "AVG") == 0) {
		use_average = TRUE;
		c++;
	}

	if (argc > c && incoming_warning_threshold == 0) {
		incoming_warning_threshold = strtoul (argv[c++], NULL, 10);
	}

	if (argc > c && incoming_critical_threshold == 0) {
		incoming_critical_threshold = strtoul (argv[c++], NULL, 10);
	}

	if (argc > c && outgoing_warning_threshold == 0) {
		outgoing_warning_threshold = strtoul (argv[c++], NULL, 10);
	}
	
	if (argc > c && outgoing_critical_threshold == 0) {
		outgoing_critical_threshold = strtoul (argv[c++], NULL, 10);
	}

	return validate_arguments ();
}
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
{
  int c;
  char *warning = NULL;
  char *critical = NULL;

  int option = 0;
  static struct option longopts[] = {
    {"hostname" ,required_argument, 0, 'H'},
    {"port"     ,required_argument, 0, 'P'},
    {"expire"   ,required_argument, 0, 'E'},
    {"verbose"  ,no_argument,       0, 'v'},
    {"version"  ,no_argument,       0, 'V'},
    {"help"     ,no_argument,       0, 'h'},
    {"warning"  ,required_argument, 0, 'w'},
    {"critical" ,required_argument, 0, 'c'},
    {0, 0, 0, 0}
  };

  if (argc < 1)
    return ERROR;

  while (1) {
    c = getopt_long (argc, argv, "H:P:E:vVhw:c:", longopts, &option);

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

    switch (c) {
    case 'H':
      if (is_host(optarg)) {
        mc_host = optarg;
      }
      else {
        usage2(_("Invalid hostname/address"), optarg);
      }
      break;
    case 'P':
      mc_port = atoi(optarg);
      break;
    case 'E':
      mc_expire = atoi(optarg);
      break;
    case 'v':
      verbose++;
      break;
    case 'V':
      print_revision(progname, revision);
      exit(STATE_OK);
    case 'h':
      print_help();
      exit (STATE_OK);
    case 'w':
      warning  = optarg;
      break;
    case 'c':
      critical = optarg;
      break;
    case '?':
      usage5();
    }
  }

  c = optind;

  set_thresholds(&my_thresholds, warning, critical);

  return validate_arguments();
}
Пример #21
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'},
		{"IPaddress", required_argument, 0, 'I'},
		{"expect", required_argument, 0, 'e'},
		{"url", required_argument, 0, 'u'},
		{"port", required_argument, 0, 'p'},
		{"critical", required_argument, 0, 'c'},
		{"warning", required_argument, 0, 'w'},
		{"timeout", required_argument, 0, 't'},
		{"verbose", no_argument, 0, 'v'},
		{"version", no_argument, 0, 'V'},
		{"help", no_argument, 0, 'h'},
		{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");
		else if (strcmp ("-wt", argv[c]) == 0)
			strcpy (argv[c], "-w");
		else if (strcmp ("-ct", argv[c]) == 0)
			strcpy (argv[c], "-c");
	}

	while (1) {
		c = getopt_long (argc, argv, "+hvVI:H:e:u:p:w:c:t:", longopts,
									 &option);

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

		switch (c) {
		case 'I':									/* hostname */
		case 'H':									/* hostname */
			if (server_address)
				break;
			else if (is_host (optarg))
				server_address = optarg;
			else
				usage2 (_("Invalid hostname/address"), optarg);
			break;
		case 'e':									/* string to expect in response header */
			server_expect = optarg;
			break;
		case 'u':									/* server URL */
			server_url = optarg;
			break;
		case 'p':									/* port */
			if (is_intpos (optarg)) {
				server_port = atoi (optarg);
			}
			else {
				usage4 (_("Port must be a positive integer"));
			}
			break;
		case 'w':									/* warning time threshold */
			if (is_intnonneg (optarg)) {
				warning_time = atoi (optarg);
				check_warning_time = TRUE;
			}
			else {
				usage4 (_("Warning time must be a positive integer"));
			}
			break;
		case 'c':									/* critical time threshold */
			if (is_intnonneg (optarg)) {
				critical_time = atoi (optarg);
				check_critical_time = TRUE;
			}
			else {
				usage4 (_("Critical time must be a positive integer"));
			}
			break;
		case 'v':									/* verbose */
			verbose = TRUE;
			break;
		case 't':									/* timeout */
			if (is_intnonneg (optarg)) {
				socket_timeout = atoi (optarg);
			}
			else {
				usage4 (_("Timeout interval must be a positive integer"));
			}
			break;
		case 'V':									/* version */
			print_revision (progname, revision);
			exit (STATE_OK);
		case 'h':									/* help */
			print_help ();
			exit (STATE_OK);
		case '?':									/* usage */
			usage5 ();
		}
	}

	c = optind;
	if (server_address==NULL && argc>c) {
		if (is_host (argv[c])) {
			server_address = argv[c++];
		}
		else {
			usage2 (_("Invalid hostname/address"), argv[c]);
		}
	}

	if (server_address==NULL)
		usage4 (_("You must provide a server to check"));

	if (host_name==NULL)
		host_name = strdup (server_address);

	if (server_expect == NULL)
		server_expect = strdup(EXPECT);

	return validate_arguments ();
}
Пример #22
0
void settings_controller::get_section(Mongoose::Request &request, boost::smatch &what, Mongoose::StreamResponse &response) {
	if (!session->is_loggedin("settings.list", request, response))
		return;

	if (!validate_arguments(1, what, response)) {
		return;
	}

	std::string path = what.str(1);

	Plugin::SettingsRequestMessage rm;
	Plugin::SettingsRequestMessage::Request *payload = rm.add_payload();
	payload->mutable_query()->mutable_node()->set_path(path);
	payload->mutable_query()->set_recursive(false);
	payload->set_plugin_id(plugin_id);
	payload = rm.add_payload();
	payload->mutable_query()->mutable_node()->set_path(path);
	payload->mutable_query()->set_recursive(true);
	payload->set_plugin_id(plugin_id);

	std::string str_response;
	core->settings_query(rm.SerializeAsString(), str_response);
	Plugin::SettingsResponseMessage pb_response;
	pb_response.ParseFromString(str_response);
	json_spirit::Object node;
	node["path"] = path;

	if (pb_response.payload_size() != 2) {
		response.setCode(HTTP_SERVER_ERROR);
		response.append("Failed to fetch keys");
		return;
	}

	const Plugin::SettingsResponseMessage::Response rKeys = pb_response.payload(0);
	if (!rKeys.has_query()) {
		response.setCode(HTTP_NOT_FOUND);
		response.append("Key not found: " + path);
		return;
	}

	json_spirit::Array keys;
	BOOST_FOREACH(const std::string &s, rKeys.query().value().list_data()) {
		keys.push_back(s);
	}
	node["keys"] = keys;

	const Plugin::SettingsResponseMessage::Response rPath = pb_response.payload(1);
	if (!rPath.has_query()) {
		response.setCode(HTTP_NOT_FOUND);
		response.append("Key not found: " + path);
		return;
	}
	json_spirit::Array paths;
	BOOST_FOREACH(const std::string &s, rPath.query().value().list_data()) {
		paths.push_back(s);
	}
	node["paths"] = paths;


	response.append(json_spirit::write(node));
}
Пример #23
0
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
{
	int c;

	int option = 0;
	static struct option longopts[] = {
		{"help", no_argument, 0, 'h'},
		{"version", no_argument, 0, 'V'},
		{"host", required_argument, 0, 'H'},	/* backward compatibility */
		{"hostname", required_argument, 0, 'H'},
		{"port", required_argument, 0, 'p'},
		{"use-ipv4", no_argument, 0, '4'},
		{"use-ipv6", no_argument, 0, '6'},
		{"timeout", required_argument, 0, 't'},
		{"verbose", no_argument, 0, 'v'},
		{"remote-version", required_argument, 0, 'r'},
		{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, "+Vhv46t:r:H:p:", longopts, &option);

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

		switch (c) {
		case '?':									/* help */
			usage5 ();
		case 'V':									/* version */
			print_revision (progname, NP_VERSION);
			exit (STATE_OK);
		case 'h':									/* help */
			print_help ();
			exit (STATE_OK);
		case 'v':									/* verbose */
			verbose = TRUE;
			break;
		case 't':									/* timeout period */
			if (!is_integer (optarg))
				usage2 (_("Timeout interval must be a positive integer"), optarg);
			else
				socket_timeout = 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 'r':									/* remote version */
			remote_version = optarg;
			break;
		case 'H':									/* host */
			if (is_host (optarg) == FALSE)
				usage2 (_("Invalid hostname/address"), optarg);
			server_name = optarg;
			break;
		case 'p':									/* port */
			if (is_intpos (optarg)) {
				port = atoi (optarg);
			}
			else {
				usage2 (_("Port number must be a positive integer"), optarg);
			}
		}
	}

	c = optind;
	if (server_name == NULL && c < argc) {
		if (is_host (argv[c])) {
			server_name = argv[c++];
		}
	}

	if (port == -1 && c < argc) {
		if (is_intpos (argv[c])) {
			port = atoi (argv[c++]);
		}
		else {
			print_usage ();
			exit (STATE_UNKNOWN);
		}
	}

	return validate_arguments ();
}
Пример #24
0
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
{
	int c = 0;  /* option character */

	int option = 0;
	static struct option longopts[] = {
		{"warning", required_argument, 0, 'w'},
		{"critical", required_argument, 0, 'c'},
		{"allswaps", no_argument, 0, 'a'},
		{"verbose", no_argument, 0, 'v'},
		{"version", no_argument, 0, 'V'},
		{"help", no_argument, 0, 'h'},
		{0, 0, 0, 0}
	};

	if (argc < 2)
		return ERROR;

	while (1) {
		c = getopt_long (argc, argv, "+?Vvhac:w:", longopts, &option);

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

		switch (c) {
		case 'w':									/* warning size threshold */
			if (is_intnonneg (optarg)) {
				warn_size_bytes = (float) atoi (optarg);
				break;
			}
			else if (strstr (optarg, ",") &&
							 strstr (optarg, "%") &&
							 sscanf (optarg, "%f,%d%%", &warn_size_bytes, &warn_percent) == 2) {
				warn_size_bytes = floorf(warn_size_bytes);
				break;
			}
			else if (strstr (optarg, "%") &&
							 sscanf (optarg, "%d%%", &warn_percent) == 1) {
				break;
			}
			else {
				usage4 (_("Warning threshold must be integer or percentage!"));
			}
		case 'c':									/* critical size threshold */
			if (is_intnonneg (optarg)) {
				crit_size_bytes = (float) atoi (optarg);
				break;
			}
			else if (strstr (optarg, ",") &&
							 strstr (optarg, "%") &&
							 sscanf (optarg, "%f,%d%%", &crit_size_bytes, &crit_percent) == 2) {
				crit_size_bytes = floorf(crit_size_bytes);
				break;
			}
			else if (strstr (optarg, "%") &&
							 sscanf (optarg, "%d%%", &crit_percent) == 1) {
				break;
			}
			else {
				usage4 (_("Critical threshold must be integer or percentage!"));
			}
		case 'a':									/* all swap */
			allswaps = TRUE;
			break;
		case 'v':									/* verbose */
			verbose++;
			break;
		case 'V':									/* version */
			print_revision (progname, NP_VERSION);
			exit (STATE_OK);
		case 'h':									/* help */
			print_help ();
			exit (STATE_OK);
		case '?':									/* error */
			usage5 ();
		}
	}

	c = optind;
	if (c == argc)
		return validate_arguments ();
	if (warn_percent == 0 && is_intnonneg (argv[c]))
		warn_percent = atoi (argv[c++]);

	if (c == argc)
		return validate_arguments ();
	if (crit_percent == 0 && is_intnonneg (argv[c]))
		crit_percent = atoi (argv[c++]);

	if (c == argc)
		return validate_arguments ();
	if (warn_size_bytes == 0 && is_intnonneg (argv[c]))
		warn_size_bytes = (float) atoi (argv[c++]);

	if (c == argc)
		return validate_arguments ();
	if (crit_size_bytes == 0 && is_intnonneg (argv[c]))
		crit_size_bytes = (float) atoi (argv[c++]);

	return validate_arguments ();
}
Пример #25
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 ();
}
Пример #26
0
int main(int argc, char **argv) {
  open_log_files();
  assert_valid_setup(argv[0]);

  int operation;
  int ret = validate_arguments(argc, argv, &operation);

  if (ret != 0) {
    flush_and_close_log_files();
    return ret;
  }

  int exit_code = 0;

  switch (operation) {
  case CHECK_SETUP:
    //we already did this
    exit_code = 0;
    break;
  case MOUNT_CGROUPS:
    exit_code = 0;

    while (optind < argc && exit_code == 0) {
      exit_code = mount_cgroup(argv[optind++], cmd_input.cgroups_hierarchy);
    }

    break;
  case TRAFFIC_CONTROL_MODIFY_STATE:
    exit_code = traffic_control_modify_state(cmd_input.traffic_control_command_file);
    break;
  case TRAFFIC_CONTROL_READ_STATE:
    exit_code = traffic_control_read_state(cmd_input.traffic_control_command_file);
    break;
  case TRAFFIC_CONTROL_READ_STATS:
    exit_code = traffic_control_read_stats(cmd_input.traffic_control_command_file);
    break;
  case RUN_DOCKER:
    exit_code = run_docker(cmd_input.docker_command_file);
    break;
  case RUN_AS_USER_INITIALIZE_CONTAINER:
    exit_code = set_user(cmd_input.run_as_user_name);
    if (exit_code != 0) {
      break;
    }

    exit_code = initialize_app(cmd_input.yarn_user_name,
                            cmd_input.app_id,
                            cmd_input.cred_file,
                            extract_values(cmd_input.local_dirs),
                            extract_values(cmd_input.log_dirs),
                            argv + optind);
    break;
  case RUN_AS_USER_LAUNCH_DOCKER_CONTAINER:
     if (cmd_input.traffic_control_command_file != NULL) {
        //apply tc rules before switching users and launching the container
        exit_code = traffic_control_modify_state(cmd_input.traffic_control_command_file);
        if( exit_code != 0) {
          //failed to apply tc rules - break out before launching the container
          break;
        }
      }

      exit_code = set_user(cmd_input.run_as_user_name);
      if (exit_code != 0) {
        break;
      }

      exit_code = launch_docker_container_as_user(cmd_input.yarn_user_name,
                      cmd_input.app_id,
                      cmd_input.container_id,
                      cmd_input.current_dir,
                      cmd_input.script_file,
                      cmd_input.cred_file,
                      cmd_input.pid_file,
                      extract_values(cmd_input.local_dirs),
                      extract_values(cmd_input.log_dirs),
                      cmd_input.docker_command_file,
                      cmd_input.resources_key,
                      cmd_input.resources_values);
      break;
  case RUN_AS_USER_LAUNCH_CONTAINER:
    if (cmd_input.traffic_control_command_file != NULL) {
      //apply tc rules before switching users and launching the container
      exit_code = traffic_control_modify_state(cmd_input.traffic_control_command_file);
      if( exit_code != 0) {
        //failed to apply tc rules - break out before launching the container
        break;
      }
    }

    exit_code = set_user(cmd_input.run_as_user_name);
    if (exit_code != 0) {
      break;
    }

    exit_code = launch_container_as_user(cmd_input.yarn_user_name,
                    cmd_input.app_id,
                    cmd_input.container_id,
                    cmd_input.current_dir,
                    cmd_input.script_file,
                    cmd_input.cred_file,
                    cmd_input.pid_file,
                    extract_values(cmd_input.local_dirs),
                    extract_values(cmd_input.log_dirs),
                    cmd_input.resources_key,
                    cmd_input.resources_values);
    free(cmd_input.resources_key);
    free(cmd_input.resources_value);
    free(cmd_input.resources_values);
    break;
  case RUN_AS_USER_SIGNAL_CONTAINER:
    exit_code = set_user(cmd_input.run_as_user_name);
    if (exit_code != 0) {
      break;
    }

    exit_code = signal_container_as_user(cmd_input.yarn_user_name,
                                  cmd_input.container_pid,
                                  cmd_input.signal);
    break;
  case RUN_AS_USER_DELETE:
    exit_code = set_user(cmd_input.run_as_user_name);
    if (exit_code != 0) {
      break;
    }

    exit_code = delete_as_user(cmd_input.yarn_user_name,
                        cmd_input.dir_to_be_deleted,
                        argv + optind);
    break;
  }

  flush_and_close_log_files();
  return exit_code;
}
Пример #27
0
/*
* Zstream implementation for seq (right event)
*/
void _seq_win_cep_r(void* exec)
{
    EtalisEvent* Event_b  = (EtalisEvent*)exec;
    EtalisExecNode* rule_ = Event_b->RootModel->parentNode;
    assert(Event_b != NULL && rule_ != NULL);


    EtalisEvent* Event_a = StackPop(rule_->leftChild->eventStack);

    if(Event_a == NULL) /* stack is empty*/
    {
        free(Event_b);
        return;
    }
    /* Event a is in the stack */
    /* a complex event will be generated if the conditions are met */
    /* testing if the conditions could be proven correct */





    if(getTimeDiff(&(Event_b->timestamps[0]),&(Event_a->timestamps[0])) > rule_->window_size) /* out of the window*/
    {
        /* printf(" --- Time difference is %d > window size of %d\n",Event_b->timestamps[0]-Event_a->timestamps[0],rule_->window_size);
        */
        free(Event_a); /* check this */
        free(Event_b);
        return;
    }


    if (Event_b->RootModel->event.arity != 0 )
    {
        if(aprio_validation(Event_b) != ETALIS_OK) /* argument a priori conditions must be true*/
        {
#ifdef DEBUG
            log_err("Event could be validated !");
#endif
            free(Event_a); /* check*/
            free(Event_b);
            return;
        }

        /* event arguments must be valide - implicite condition */
        if(validate_arguments(Event_b,Event_a) != ETALIS_OK)
        {
#ifdef DEBUG
            printf("Event arguments could not be validated ! \n");
#endif
            free(Event_a); /* check*/
            free(Event_b);
            return;
        }
    }


    EtalisEventNode* cplxEvModel=NULL; /* Complex Event Root Model */

    /* the rest depends on the CEP policy */
    if (_conf.policy==recent) /* recent policy */
    {
        cplxEvModel = rule_->parentEvent;

        /* triggering the complex event */
        EtalisEvent* cplxEvent = (EtalisEvent*)malloc(sizeof(EtalisEvent));
        cplxEvent->RootModel = rule_->parentEvent;
        /* bind the arguments of the complex event */ /* todo validate */
        cplxEvent->args = (int*)malloc(sizeof(int)*cplxEvModel->event.arity);
        size_t arg_iterator=0;
        for(arg_iterator=0; arg_iterator<cplxEvModel->event.arity; arg_iterator++)
        {
            switch (cplxEvModel->arg_links[arg_iterator].event_)
            {
            case 1 :
                *((int*)cplxEvent->args+arg_iterator)=*((int*)Event_a->args+(cplxEvModel->arg_links[arg_iterator].argument_number));
                break;

            case 2 :
                *((int*)cplxEvent->args+arg_iterator)=*((int*)Event_b->args+(cplxEvModel->arg_links[arg_iterator].argument_number));
                break;
            }
        }


        cplxEvent->timestamps[0] = Event_a->timestamps[0]; /* timestamp structure as suggested by the ETALIS paper */
        cplxEvent->timestamps[1] = Event_b->timestamps[1];
        triggerEvent_intern_no_hash(cplxEvent);            /* trigger the complex event (we already know the EventModel, so we don't need to search for it in the _event_hash) */

        /* garbage collect : we don't need these events anymore */
        free(Event_a);
        free(Event_b);
        return;
    }
    else if (_conf.policy==unrestricted)
    {
        /* TODO */
        return ;
    }

}
Пример #28
0
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
{
	int c;
	char *p1, *p2;

	int option = 0;
	static struct option longopts[] = {
		{"version", no_argument, 0, 'V'},
		{"help", no_argument, 0, 'h'},
		{"verbose", no_argument, 0, 'v'},
		{"fork", no_argument, 0, 'f'},
		{"timeout", required_argument, 0, 't'},
		{"host", required_argument, 0, 'H'},
		{"port", required_argument,0,'p'},
		{"output", required_argument, 0, 'O'},
		{"name", required_argument, 0, 'n'},
		{"services", required_argument, 0, 's'},
		{"identity", required_argument, 0, 'i'},
		{"user", required_argument, 0, 'u'},
		{"logname", required_argument, 0, 'l'},
		{"command", required_argument, 0, 'C'},
		{"skip", optional_argument, 0, 'S'}, /* backwards compatibility */
		{"skip-stdout", optional_argument, 0, 'S'},
		{"skip-stderr", optional_argument, 0, 'E'},
		{"proto1", no_argument, 0, '1'},
		{"proto2", no_argument, 0, '2'},
		{"use-ipv4", no_argument, 0, '4'},
		{"use-ipv6", no_argument, 0, '6'},
		{"ssh-option", required_argument, 0, 'o'},
		{"quiet", no_argument, 0, 'q'},
		{"configfile", optional_argument, 0, 'F'},
		{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, "Vvh1246fqt:H:O:p:i:u:l:C:S::E::n:s:o:F:", longopts,
		                 &option);

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

		switch (c) {
		case 'V':									/* version */
			print_revision (progname, NP_VERSION);
			exit (STATE_OK);
		case 'h':									/* help */
			print_help ();
			exit (STATE_OK);
		case 'v':									/* help */
			verbose = TRUE;
			break;
		case 't':									/* timeout period */
			if (!is_integer (optarg))
				usage_va(_("Timeout interval must be a positive integer"));
			else
				timeout_interval = atoi (optarg);
			break;
		case 'H':									/* host */
			host_or_die(optarg);
			hostname = optarg;
			break;
		case 'p': /* port number */
			if (!is_integer (optarg))
				usage_va(_("Port must be a positive integer"));
			comm_append("-p");
			comm_append(optarg);
			break;
		case 'O':									/* output file */
			outputfile = optarg;
			passive = TRUE;
			break;
		case 's':									/* description of service to check */
			p1 = optarg;
			service = realloc (service, (++services) * sizeof(char *));
			while ((p2 = index (p1, ':'))) {
				*p2 = '\0';
				service[services - 1] = p1;
				service = realloc (service, (++services) * sizeof(char *));
				p1 = p2 + 1;
			}
			service[services - 1] = p1;
			break;
		case 'n':									/* short name of host in nagios configuration */
			host_shortname = optarg;
			break;

		case 'u':
			comm_append("-l");
			comm_append(optarg);
			break;
		case 'l':									/* login name */
			comm_append("-l");
			comm_append(optarg);
			break;
		case 'i':									/* identity */
			comm_append("-i");
			comm_append(optarg);
			break;

		case '1':									/* Pass these switches directly to ssh */
			comm_append("-1");
			break;
		case '2':									/* 1 to force version 1, 2 to force version 2 */
			comm_append("-2");
			break;
		case '4':									/* -4 for IPv4 */
			comm_append("-4");
			break;
		case '6': 								/* -6 for IPv6 */
			comm_append("-6");
			break;
		case 'f':									/* fork to background */
			comm_append("-f");
			break;
		case 'C':									/* Command for remote machine */
			commands++;
			if (commands > 1)
				xasprintf (&remotecmd, "%s;echo STATUS CODE: $?;", remotecmd);
			xasprintf (&remotecmd, "%s%s", remotecmd, optarg);
			break;
		case 'S':									/* skip n (or all) lines on stdout */
			if (optarg == NULL)
				skip_stdout = -1; /* skip all output on stdout */
			else if (!is_integer (optarg))
				usage_va(_("skip-stdout argument must be an integer"));
			else
				skip_stdout = atoi (optarg);
			break;
		case 'E':									/* skip n (or all) lines on stderr */
			if (optarg == NULL)
				skip_stderr = -1; /* skip all output on stderr */
			else if (!is_integer (optarg))
				usage_va(_("skip-stderr argument must be an integer"));
			else
				skip_stderr = atoi (optarg);
			break;
		case 'o':									/* Extra options for the ssh command */
			comm_append("-o");
			comm_append(optarg);
			break;
		case 'q':									/* Tell the ssh command to be quiet */
			comm_append("-q");
			break;
		case 'F': 									/* ssh configfile */
			comm_append("-F");
			comm_append(optarg);
			break;
		default:									/* help */
			usage5();
		}
	}

	c = optind;
	if (hostname == NULL) {
		if (c <= argc) {
			die (STATE_UNKNOWN, _("%s: You must provide a host name\n"), progname);
		}
		host_or_die(argv[c]);
		hostname = argv[c++];
	}

	if (strlen(remotecmd) == 0) {
		for (; c < argc; c++)
			if (strlen(remotecmd) > 0)
				xasprintf (&remotecmd, "%s %s", remotecmd, argv[c]);
			else
				xasprintf (&remotecmd, "%s", argv[c]);
	}

	if (commands > 1 || passive)
		xasprintf (&remotecmd, "%s;echo STATUS CODE: $?;", remotecmd);

	if (remotecmd == NULL || strlen (remotecmd) <= 1)
		usage_va(_("No remotecmd"));

	comm_append(hostname);
	comm_append(remotecmd);

	return validate_arguments ();
}
Пример #29
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'},
    {"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:46", longopts, &option);

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

    switch (c) {
    case 'h':                 /* help */
      print_help ();
      exit (STATE_UNKNOWN);
    case 'V':                 /* version */
      print_revision (progname, NP_VERSION);
      exit (STATE_UNKNOWN);
    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 '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 ();
}
Пример #30
0
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, NP_VERSION);
      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 */
      usage5();
    }
  }

  c = optind;
  /* first option is the game type */
  if (!game_type && c<argc)
    game_type = strdup (argv[c++]);

  /* Second option is the server name */
  if (!server_ip && c<argc)
    server_ip = strdup (argv[c++]);

  return validate_arguments ();
}