Skip to content

Commit 4adfa05

Browse files
committed
Added match alias only option
1 parent a78460c commit 4adfa05

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

snmp_bulkget.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ main(int argc, char *argv[])
126126
int crit_on_down_flag = 1;
127127
int get_aliases_flag = 0;
128128
int match_aliases_flag = 0;
129+
int match_aliases_only_flag = 0;
129130
int get_names_flag = 0;
130131
int print_all_flag = 0;
131132
int err_tolerance = 50;
@@ -227,6 +228,7 @@ main(int argc, char *argv[])
227228
{"sleep", required_argument, NULL, 3},
228229
{"retries", required_argument, NULL, 4},
229230
{"max-repetitions", required_argument, NULL, 5},
231+
{"aliases-only", no_argument, NULL, 6},
230232
{NULL, 0, NULL, 0}
231233
};
232234

@@ -332,6 +334,10 @@ main(int argc, char *argv[])
332334
case 5:
333335
pdu_max_repetitions = strtol(optarg, NULL, 10);
334336
break;
337+
case 6:
338+
get_aliases_flag = 1; /* we need to see what we have matched... */
339+
match_aliases_only_flag = 1;
340+
break;
335341
case '?':
336342
default:
337343
exit(usage(progname));
@@ -610,7 +616,7 @@ main(int argc, char *argv[])
610616

611617
/* now optionally fetch the interface aliases */
612618

613-
if (match_aliases_flag) {
619+
if (match_aliases_flag || match_aliases_only_flag) {
614620
lastifflag = 0;
615621
count = 0;
616622
/* allocate the space for the alias OIDs */
@@ -888,18 +894,23 @@ main(int argc, char *argv[])
888894

889895
count = 0;
890896
for (i=0; i < ifNumber; i++) {
897+
/* When --aliases-only is set check only alias */
898+
if (match_aliases_only_flag)
899+
status = !(regexec(&re, interfaces[i].alias, (size_t) 0, NULL, 0));
891900
/* When --if-name is set ignore descr in favor of name, else use old behaviour */
892-
if (get_names_flag)
901+
else if (get_names_flag)
893902
status = !regexec(&re, interfaces[i].name, (size_t) 0, NULL, 0) ||
894903
(get_aliases_flag && !(regexec(&re, interfaces[i].alias, (size_t) 0, NULL, 0)));
895904
else
896905
status = !regexec(&re, interfaces[i].descr, (size_t) 0, NULL, 0) ||
897906
(get_aliases_flag && !(regexec(&re, interfaces[i].alias, (size_t) 0, NULL, 0)));
898907
status2 = 0;
899908
if (status && exclude_list) {
900-
if (get_names_flag)
909+
if (match_aliases_only_flag)
910+
status2 = !(regexec(&exclude_re, interfaces[i].alias, (size_t) 0, NULL, 0));
911+
else if (get_names_flag)
901912
status2 = !regexec(&exclude_re, interfaces[i].name, (size_t) 0, NULL, 0) ||
902-
(get_aliases_flag && !(regexec(&re, interfaces[i].alias, (size_t) 0, NULL, 0)));
913+
(get_aliases_flag && !(regexec(&exclude_re, interfaces[i].alias, (size_t) 0, NULL, 0)));
903914
else
904915
status2 = !regexec(&exclude_re, interfaces[i].descr, (size_t) 0, NULL, 0) ||
905916
(get_aliases_flag && !(regexec(&exclude_re, interfaces[i].alias, (size_t) 0, NULL, 0)));
@@ -1353,7 +1364,8 @@ int usage(char *progname)
13531364
printf(" --timeout\t\tsets the SNMP timeout (in ms)\n");
13541365
printf(" --sleep\t\tsleep between every SNMP query (in ms)\n");
13551366
printf(" --retries\t\thow often to retry before giving up\n");
1356-
printf(" --max-repetitions\t\tsee <http://www.net-snmp.org/docs/man/snmpbulkwalk.html>\n");
1367+
printf(" --max-repetitions\tsee <http://www.net-snmp.org/docs/man/snmpbulkwalk.html>\n");
1368+
printf(" --aliases-only\tmatch only against aliases (Option -a automatically enabled)\n");
13571369
printf("\n");
13581370
return 3;
13591371
}

0 commit comments

Comments
 (0)