Exemple #1
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,
            {"on", required_argument, NULL, (int)'o'},
            {"off", required_argument, NULL, (int)'O'},
            SNMP_LONGOPTS,
            MP_LONGOPTS_END
    };

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


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

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

        getopt_snmp(c);

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

    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,
            {"extended-status", no_argument, NULL, (int) 'e'},
            SNMP_LONGOPTS,
            MP_LONGOPTS_END
    };

    if (argc < 3) {
       print_help();
       exit(STATE_UNKNOWN);
    }

    mp_snmp_version = SNMP_VERSION_1;

    while (1) {
        c = mp_getopt(&argc, &argv, MP_OPTSTR_DEFAULT"H:P:ew:c:W:Z:"SNMP_OPTSTR,
                      longopts, &option);

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

        getopt_snmp(c);

        switch (c) {
            /* Hostname opt */
            case 'H':
                getopt_host(optarg, &hostname);
                break;
            /* Port opt */
            case 'P':
                getopt_port(optarg, &port);
                break;
            /* Plugin opt */
            case 'e':
                extended_status = 1;
                break;
            case 'w':
                getopt_wc_at(c, optarg, &threshold_charge);
                break;
            case 'c':
                getopt_wc_at(c, optarg, &threshold_charge);
                break;
            case 'W':
                getopt_wc_at('w', optarg, &threshold_runtime);
                break;
            case 'Z':
                getopt_wc_at('c', optarg, &threshold_runtime);
                break;
        }
    }

    if (mp_verbose > 0) {
        print_thresholds("charge", threshold_charge);
        print_thresholds("runtime", threshold_runtime);
    }

    /* sanity check: charge threshold */
    if ((threshold_charge->warning->end < 0) ||
        (threshold_charge->warning->end > 100)) {
        usage("Warning charge threshold must be between 0 and 100.");
    }
    if ((threshold_charge->critical->end < 0) ||
        (threshold_charge->critical->end > 100)) {
        usage("Critical charge threshold must be between 0 and 100.");
    }
    if (threshold_charge->critical->end > threshold_charge->warning->end) {
        usage("Warning charge threshold (%ld) must be larger than "
              "critical charge threshold (%ld).",
              (long) threshold_charge->warning->end,
              (long) threshold_charge->critical->end);
    }

    /* sanity check: runtime threshold */
    if (threshold_runtime->warning->end < 0) {
        usage("Warning runtime threshold must be larher or equal to 0.");
    }
    if (threshold_runtime->critical->end < 0) {
        usage("Critical runtime threshold must be larher or equal to 0.");
    }
    if (threshold_runtime->critical->end > threshold_runtime->warning->end) {
        usage("Warning runtime threshold (%ld) must be larger than "
              "runtime charge threshold (%ld).",
              (long) threshold_runtime->warning->end,
              (long) threshold_runtime->critical->end);
    }

    return(OK);
}