int process_arguments (int argc, char **argv) { int c; int option = 0; static struct option longopts[] = { MP_LONGOPTS_DEFAULT, MP_LONGOPTS_WC, {"bonding", required_argument, NULL, (int)'b'}, MP_LONGOPTS_END, }; while (1) { c = mp_getopt(&argc, &argv, MP_OPTSTR_DEFAULT"b:", longopts, &option); if (c == -1 || c == EOF) break; switch (c) { case 'b': mp_array_push(&bond, strdup(optarg), &bonds); break; } } return(OK); }
int process_arguments (int argc, char **argv) { int c; int option = 0; static struct option longopts[] = { MP_LONGOPTS_DEFAULT, {"socket", required_argument, NULL, (int)'s'}, {"query", required_argument, NULL, (int)'q'}, MP_LONGOPTS_END }; if (argc < 2) { print_help(); exit(STATE_OK); } while (1) { c = mp_getopt(&argc, &argv, MP_OPTSTR_DEFAULT"s:q:", longopts, &option); if (c == -1 || c == EOF) break; switch (c) { case 's': fcgisocket = optarg; break; case 'q': query = 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_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); }
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); }
int process_arguments (int argc, char **argv) { int c; int option = 0; static struct option long_opts[] = { MP_LONGOPTS_DEFAULT, MP_LONGOPTS_HOST, LDNS_LONGOPTS, {"domain", required_argument, 0, 'D'}, {"trace-from", required_argument, 0, 'T'}, {"trusted-keys", required_argument, 0, 'k'}, {"resolver", required_argument, 0, 'R'}, MP_LONGOPTS_END }; if (argc < 2) { print_help(); exit (STATE_OK); } while (1) { c = mp_getopt(&argc, &argv, MP_OPTSTR_DEFAULT"H:D:T:k:R:"LDNS_OPTSTR, long_opts, &option); if (c == -1 || c == EOF) break; getopt_ldns(c); switch (c) { /* Host opt */ case 'H': getopt_host_ip(optarg, &hostname); break; case 'D': if (!is_hostname(optarg)) usage("Illegal domain name."); domainname = optarg; break; case 'k': trusted_keys = loadKeyfile(optarg); if (trusted_keys == NULL) usage("Parsing keyfile failed."); break; case 'T': if (!is_hostname(optarg)) usage("Illegal trace domain name."); domaintrace = optarg; break; case 'R': getopt_host_ip(optarg, &resolver); break; } } /* Check requirements */ if(!domainname) usage("Domain is mandatory"); return OK; }
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, {"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); }
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_NOTIFY, {"userkey", required_argument, 0, 'U'}, {"password", required_argument, 0, 'P'}, {"to", required_argument, NULL, (int)'T'}, {"from", required_argument, NULL, (int)'f'}, MP_LONGOPTS_END }; while (1) { c = mp_getopt(&argc, &argv, MP_OPTSTR_NOTIFY, longopts, &option); if (c == -1 || c == EOF) break; getopt_notify(c); switch (c) { case 'U': userkey = optarg; break; case 'P': password = optarg; break; case 'T': mp_array_push(&number, optarg, &numbers); break; case 'f': from = optarg; break; }; } /* Checks */ if (!userkey || !password) usage("Userkey and password are mandatory."); if (numbers == 0) usage("--to is mandatory."); if (!mp_notify_file && !mp_notify_msg) usage("--file or --message is 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, {"variable", required_argument, NULL, (int)LONGOPT_VARIABLE}, MYSQL_LONGOPTS, MP_LONGOPTS_END }; while (1) { c = mp_getopt(&argc, &argv, MP_OPTSTR_DEFAULT"H:"MYSQL_OPTSTR, longopts, &option); if (c == -1 || c == EOF) break; getopt_mysql(c); switch (c) { case LONGOPT_VARIABLE: { char *u; u = optarg; optarg = strsep(&u, ":"); mp_array_push(&variable, optarg, &variables); variables--; if (u) mp_array_push(&unit, optarg, &variables); else mp_array_push(&unit, "", &variables); } break; } } /* Apply defaults */ if (variables == 0) { variable = default_variable; unit = default_unit; variables = 13; } return(OK); }
int process_arguments (int argc, char **argv) { int c; int option = 0; static struct option longopts[] = { MP_LONGOPTS_DEFAULT, MP_LONGOPTS_END }; while (1) { c = mp_getopt(&argc, &argv, MP_OPTSTR_DEFAULT"", longopts, &option); if (c == -1 || c == EOF) break; } return(OK); }
int process_arguments (int argc, char **argv) { int c; int option = 0; static struct option longopts[] = { MP_LONGOPTS_DEFAULT, // PLUGIN OPTS {"cert", required_argument, NULL, (int)'C'}, MP_LONGOPTS_WC, MP_LONGOPTS_END }; mp_threshold_set_warning_time(&expire_thresholds, "30d:"); mp_threshold_set_critical_time(&expire_thresholds, "10d:"); while (1) { c = mp_getopt(&argc, &argv, MP_OPTSTR_DEFAULT"w:c:C:", longopts, &option); if (c == -1 || c == EOF) break; getopt_wc_time_at(c, optarg, &expire_thresholds); switch (c) { /* Plugin opts */ case 'C': { glob_t globbuf; globbuf.gl_offs = 0; glob(optarg, GLOB_BRACE|GLOB_TILDE|GLOB_NOMAGIC, NULL, &globbuf); int i=0; for (i=0; i < globbuf.gl_pathc; i++) { mp_array_push(&cert_file, globbuf.gl_pathv[i], &cert_files); } break; } } } if (cert_files < 1) usage("At least one cert file is required."); return(OK); }
int process_arguments (int argc, char **argv) { int c; int option = 0; static struct option longopts[] = { MP_LONGOPTS_DEFAULT, MP_LONGOPTS_HOST, {"domainname", required_argument, 0, 'D'}, {"norecursion", no_argument, &recursion, 0}, {"notcp", no_argument, &tcp, 0}, {"noudp", no_argument, &udp, 0}, {"noaxfr", no_argument, &axfr, 0}, MP_LONGOPTS_END }; if (argc < 2) { print_help(); exit(STATE_OK); } while (1) { c = mp_getopt(&argc, &argv, MP_OPTSTR_DEFAULT"H:D:", longopts, &option); if (c == -1 || c == EOF) break; switch (c) { /* Host opt */ case 'H': getopt_host_ip(optarg, &hostname); break; case 'D': domainname = optarg; break; } } /* Check requirements */ if (!domainname) usage("A domainname is 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, {"packets", required_argument, 0, 'p'}, {"quick", no_argument, 0, 'q'}, {"interval", required_argument, 0, 'i'}, {"interface", required_argument, 0, 'I'}, {"ttl", required_argument, 0, 'T'}, MP_LONGOPTS_WC, MP_LONGOPTS_END }; if (argc < 2) { print_help(); exit(STATE_OK); } /* Set default */ setWarn(&rta_thresholds, "~:90", NOEXT); setWarn(&lost_thresholds, "80", NOEXT); setCrit(&rta_thresholds, "~:100", NOEXT); setCrit(&lost_thresholds, "90", NOEXT); while (1) { c = mp_getopt(&argc, &argv, MP_OPTSTR_DEFAULT"H:46p:qi:I:T:w:c:", longopts, &option); if (c == -1 || c == EOF) break; getopt_46(c, &ipv); switch (c) { /* Hostname opt */ case 'H': getopt_host(optarg, &hostname); break; /* Packets opt */ case 'p': if (!is_integer(optarg)) usage("Illegal packets value '%s'.", optarg); packets = (int)strtol(optarg, NULL, 10); break; /* Quick opt */ case 'q': quick = 1; break; /* Interface opt */ case 'I': interface = optarg; break; /* Interval opt */ case 'i': { double val; val = strtod(optarg, NULL); if (val <= 0) usage("Illegal interval value '%s'.", optarg); interval.tv_sec = (int)val; interval.tv_nsec = ((int)(val*1000000000))%1000000000; } break; /* TTL opt */ case 'T': if (!is_integer(optarg)) usage("Illegal ttl value '%s'.", optarg); ttl = (int)strtol(optarg, NULL, 10); if (ttl < 1 || ttl > 255) usage("Illegal ttl value '%s'.", optarg); break; /* Warn/Crit opt */ case 'w': case 'c': { char *rta, *pl; pl = optarg; rta = strsep(&pl, ","); if (rta == NULL || pl == NULL) { usage("Waring/Critical threshold is <rta>,<pl>%%."); } if (c == 'w') { if (setWarn(&rta_thresholds, rta, NOEXT) == ERROR) usage("Illegal -w tra threshold '%s'.", rta); if (setWarn(&lost_thresholds, pl, NOEXT) == ERROR) usage("Illegal -w pl threshold '%s'.", pl); } else { if (setCrit(&rta_thresholds, rta, NOEXT) == ERROR) usage("Illegal -c tra threshold '%s'.", rta); if (setCrit(&lost_thresholds, pl, NOEXT) == ERROR) usage("Illegal -c pl threshold '%s'.", pl); } } break; } } /* Check requirements */ if (!hostname) usage("Hostname is 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, {"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); }
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); }