From 10f94a0335b0ababda6423adef5990f8afc3dd5a Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 7 May 2021 14:24:16 +0200 Subject: [PATCH 1/3] Fetch the aliases on -a, not just on -A --- snmp_bulkget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmp_bulkget.c b/snmp_bulkget.c index fd58852..a828679 100644 --- a/snmp_bulkget.c +++ b/snmp_bulkget.c @@ -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 */ From 3e2c27298d7a9a833ce0c470254583622dedca25 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 7 May 2021 14:29:27 +0200 Subject: [PATCH 2/3] Match aliases only on -A, not on -a --- snmp_bulkget.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/snmp_bulkget.c b/snmp_bulkget.c index a828679..1b419ac 100644 --- a/snmp_bulkget.c +++ b/snmp_bulkget.c @@ -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 From 8d9bd2c5f745c03f2e65b9991eb23bed6984414e Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 7 May 2021 16:11:16 +0200 Subject: [PATCH 3/3] Show aliases also in the long output --- snmp_bulkget.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/snmp_bulkget.c b/snmp_bulkget.c index 1b419ac..fcb7daf 100644 --- a/snmp_bulkget.c +++ b/snmp_bulkget.c @@ -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) { @@ -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 */ @@ -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);