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

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

    /* Set default */
    setWarnTime(&delay_thresholds, "300s");
    setCritTime(&delay_thresholds, "3600s");

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

        getopt_wc_time(c, optarg, &delay_thresholds);

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

        getopt_pgsql(c);

    }

    return(OK);
}
Exemple #2
0
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,
        {"file", required_argument, 0, 'F'},
        MP_LONGOPTS_WC,
        MP_LONGOPTS_END
    };

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

    /* Set default */
    mp_threshold_set_warning_time(&fetch_thresholds, "5s");
    mp_threshold_set_critical_time(&fetch_thresholds, "9s");

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

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

        getopt_wc_time(c, optarg, &fetch_thresholds);

        switch (c) {
        /* Hostname opt */
        case 'H':
            getopt_host(optarg, &hostname);
            break;
        /* Port opt */
        case 'P':
            getopt_port(optarg, &port);
            break;
        case 'F':
            filename = optarg;
            break;
        }
    }

    /* Check requirements */
    if (!filename || !hostname)
        usage("Filename and hostname are mandatory.");

    return(OK);
}