Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make -a/-A working as expected #14

Merged
merged 3 commits into from
Dec 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 25 additions & 23 deletions snmp_bulkget.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ main(int argc, char *argv[])

/* now optionally fetch the interface aliases */

if (match_aliases_flag) {
if (get_aliases_flag) {
lastifflag = 0;
count = 0;
/* allocate the space for the alias OIDs */
Expand Down Expand Up @@ -891,18 +891,18 @@ main(int argc, char *argv[])
/* When --if-name is set ignore descr in favor of name, else use old behaviour */
if (get_names_flag)
status = !regexec(&re, interfaces[i].name, (size_t) 0, NULL, 0) ||
(get_aliases_flag && !(regexec(&re, interfaces[i].alias, (size_t) 0, NULL, 0)));
(match_aliases_flag && !(regexec(&re, interfaces[i].alias, (size_t) 0, NULL, 0)));
else
status = !regexec(&re, interfaces[i].descr, (size_t) 0, NULL, 0) ||
(get_aliases_flag && !(regexec(&re, interfaces[i].alias, (size_t) 0, NULL, 0)));
(match_aliases_flag && !(regexec(&re, interfaces[i].alias, (size_t) 0, NULL, 0)));
status2 = 0;
if (status && exclude_list) {
if (get_names_flag)
status2 = !regexec(&exclude_re, interfaces[i].name, (size_t) 0, NULL, 0) ||
(get_aliases_flag && !(regexec(&re, interfaces[i].alias, (size_t) 0, NULL, 0)));
(match_aliases_flag && !(regexec(&re, interfaces[i].alias, (size_t) 0, NULL, 0)));
else
status2 = !regexec(&exclude_re, interfaces[i].descr, (size_t) 0, NULL, 0) ||
(get_aliases_flag && !(regexec(&exclude_re, interfaces[i].alias, (size_t) 0, NULL, 0)));
(match_aliases_flag && !(regexec(&exclude_re, interfaces[i].alias, (size_t) 0, NULL, 0)));
} if (status && !status2) {
count++;
#ifdef DEBUG
Expand Down Expand Up @@ -959,18 +959,19 @@ main(int argc, char *argv[])
if (interfaces[i].descr && !interfaces[i].ignore) {
int warn = 0;

char *nameOrDescr = get_names_flag && strlen(interfaces[i].name)
? interfaces[i].name : interfaces[i].descr;

if ((!interfaces[i].status || interfaces[i].err_disable) && !interfaces[i].ignore && !interfaces[i].admin_down) {
if (crit_on_down_flag) {
addstr(&perf, "[CRITICAL] ");
errorflag++;
/* show the alias if configured */
if (get_names_flag && strlen(interfaces[i].name)) {
addstr(&out, ", %s", interfaces[i].name);
addstr(&perf, "%s is down", interfaces[i].name);
} else {
addstr(&out, ", %s", interfaces[i].descr);
addstr(&perf, "%s is down", interfaces[i].descr);
}
addstr(&out, ", %s", nameOrDescr);
addstr(&perf, "%s", nameOrDescr);
if (get_aliases_flag && strlen(interfaces[i].alias))
addstr(&perf, " (%s)", interfaces[i].alias);
addstr(&perf, " is down");
if (interfaces[i].err_disable)
addstr(&perf, " (errdisable)");
if (!interfaces[i].admin_down) {
Expand All @@ -982,15 +983,16 @@ main(int argc, char *argv[])
addstr(&out, " (errdisable)");
}
} else {
addstr(&perf, "[OK] ");
if (get_names_flag && strlen(interfaces[i].name))
addstr(&perf, "%s is up", interfaces[i].name);
else
addstr(&perf, "%s is up", interfaces[i].descr);
addstr(&perf, "[OK] %s", nameOrDescr);
if (get_aliases_flag && strlen(interfaces[i].alias))
addstr(&perf, " (%s)", interfaces[i].alias);
addstr(&perf, " is up");
}
} else if (interfaces[i].admin_down && print_all_flag) {
addstr(&perf, "[OK] %s is down (administrative down)",
(get_names_flag && strlen(interfaces[i].name)) ? interfaces[i].name : interfaces[i].descr);
addstr(&perf, "[OK] %s", nameOrDescr);
if (get_aliases_flag && strlen(interfaces[i].alias))
addstr(&perf, " (%s)", interfaces[i].alias);
addstr(&perf, " is down (administrative down)");
}

/* check if errors on the interface are increasing faster than our defined value */
Expand Down Expand Up @@ -1053,10 +1055,10 @@ main(int argc, char *argv[])
else
addstr(&perf, "[WARNING]");

if (get_names_flag && strlen(interfaces[i].name))
addstr(&perf, " %s is up", interfaces[i].name);
else
addstr(&perf, " %s is up", interfaces[i].descr);
addstr(&perf, " %s", nameOrDescr);
if (get_aliases_flag && strlen(interfaces[i].alias))
addstr(&perf, " (%s)", interfaces[i].alias);
addstr(&perf, " is up");
}
if (lastcheck && (interfaces[i].speed || speed) && (inbitps > 0ULL || outbitps > 0ULL)) {
gauge_to_si(inbitps, &ins);
Expand Down