Пример #1
0
int process_arguments (int argc, char **argv) {
    int c;
    int option = 0;

    static struct option longopts[] = {
        MP_LONGOPTS_DEFAULT,
        MP_LONGOPTS_WC,
        MP_LONGOPTS_END,
    };

    /* Set default */
    setWarn(&usage_thresholds, "90", 0);
    setCrit(&usage_thresholds, "95", 0);

    while (1) {
        c = mp_getopt(&argc, &argv, MP_OPTSTR_DEFAULT"c:w:", longopts, &option);

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

        getopt_wc(c, optarg, &usage_thresholds);

    }

    /* Check requirements */

    return(OK);
}
Пример #2
0
int process_arguments (int argc, char **argv) {
    int c;
    int option = 0;

    static struct option longopts[] = {
        MP_LONGOPTS_DEFAULT,
        {"tcp", required_argument, NULL, (int)'T'},
        {"udp", required_argument, NULL, (int)'U'},
        {"raw", required_argument, NULL, (int)'R'},
        MP_LONGOPTS_WC,
        MP_LONGOPTS_END,
    };

    /* Set default */
    mp_threshold_set_warning_time(&socket_thresholds, "1000");
    mp_threshold_set_critical_time(&socket_thresholds, "1024");

    while (1) {
        c = mp_getopt(&argc, &argv, MP_OPTSTR_DEFAULT"T:U:R:c:w:46", longopts, &option);

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

        getopt_46(c, &ipv);
        getopt_wc(c, optarg, &socket_thresholds);

        switch (c) {
            case 'T':
                if (optarg)
                    tcpport = strtol(optarg,NULL,10);
                else
                    tcpport = 0;
                break;
            case 'U':
                if (optarg)
                    udpport = strtol(optarg,NULL,10);
                else
                    udpport = 0;
                break;
            case 'R':
                if (optarg)
                    rawport = strtol(optarg,NULL,10);
                else
                    rawport = 0;
                break;
        }
    }

    /* Check requirements */
    if (tcpport < 0 && udpport < 0 && rawport < 0)
        usage("--tcp, --udp or --raw mandatory.");

    return(OK);
}
int process_arguments (int argc, char **argv) {
    int c;
    int option = 0;

    static struct option longopts[] = {
        MP_LONGOPTS_DEFAULT,
        MP_LONGOPTS_HOST,
        MP_LONGOPTS_PORT,
        {"url", required_argument, 0, 'u'},
        MP_LONGOPTS_WC,
        MP_LONGOPTS_END
    };

    if (argc < 2) {
        print_help();
        exit(STATE_OK);
    }

    /* Set default */

    while (1) {
        c = mp_getopt(&argc, &argv, MP_OPTSTR_DEFAULT"H:P:u:w:c:", longopts, &option);

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

        getopt_wc(c, optarg, &open_thresholds);

        switch (c) {
            case 'u':
                getopt_url(optarg, &url);
                break;
            /* Hostname opt */
            case 'H':
                getopt_host(optarg, &hostname);
                break;
            case 'P':
                getopt_port(optarg, &port);
                break;
        }
    }

    /* Check requirements */
    if (!is_url_scheme(url, "http") && !is_url_scheme(url, "https"))
        usage("Only http and https url allowed.");
    if (!url && !hostname)
        usage("Url or Hostname is mandatory.");
    if (url && hostname)
        usage("Only Url or Hostname allowed.");

    if (!url) {
        size_t len = strlen(hostname) + 40;
        char *u;
        u = mp_malloc(len);
        mp_snprintf(u, len , "http://%s:%d/server-status?auto", hostname, port);
        url = u;
    } else {
        char *u;
        u = (char *)(url + strlen(url) - 5);
        if (strcmp(u, "?auto") != 0) {
            u = mp_malloc(strlen(url) + 6);
            strcpy(u, url);
            strcat(u, "?auto");
            url = u;
        }
    }

    return(OK);
}