@@ -126,6 +126,7 @@ main(int argc, char *argv[])
126
126
int crit_on_down_flag = 1 ;
127
127
int get_aliases_flag = 0 ;
128
128
int match_aliases_flag = 0 ;
129
+ int match_aliases_only_flag = 0 ;
129
130
int get_names_flag = 0 ;
130
131
int print_all_flag = 0 ;
131
132
int err_tolerance = 50 ;
@@ -227,6 +228,7 @@ main(int argc, char *argv[])
227
228
{"sleep" , required_argument , NULL , 3 },
228
229
{"retries" , required_argument , NULL , 4 },
229
230
{"max-repetitions" , required_argument , NULL , 5 },
231
+ {"aliases-only" , no_argument , NULL , 6 },
230
232
{NULL , 0 , NULL , 0 }
231
233
};
232
234
@@ -332,6 +334,10 @@ main(int argc, char *argv[])
332
334
case 5 :
333
335
pdu_max_repetitions = strtol (optarg , NULL , 10 );
334
336
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 ;
335
341
case '?' :
336
342
default :
337
343
exit (usage (progname ));
@@ -610,7 +616,7 @@ main(int argc, char *argv[])
610
616
611
617
/* now optionally fetch the interface aliases */
612
618
613
- if (match_aliases_flag ) {
619
+ if (match_aliases_flag || match_aliases_only_flag ) {
614
620
lastifflag = 0 ;
615
621
count = 0 ;
616
622
/* allocate the space for the alias OIDs */
@@ -888,18 +894,23 @@ main(int argc, char *argv[])
888
894
889
895
count = 0 ;
890
896
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 ));
891
900
/* 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 )
893
902
status = !regexec (& re , interfaces [i ].name , (size_t ) 0 , NULL , 0 ) ||
894
903
(get_aliases_flag && !(regexec (& re , interfaces [i ].alias , (size_t ) 0 , NULL , 0 )));
895
904
else
896
905
status = !regexec (& re , interfaces [i ].descr , (size_t ) 0 , NULL , 0 ) ||
897
906
(get_aliases_flag && !(regexec (& re , interfaces [i ].alias , (size_t ) 0 , NULL , 0 )));
898
907
status2 = 0 ;
899
908
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 )
901
912
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 )));
903
914
else
904
915
status2 = !regexec (& exclude_re , interfaces [i ].descr , (size_t ) 0 , NULL , 0 ) ||
905
916
(get_aliases_flag && !(regexec (& exclude_re , interfaces [i ].alias , (size_t ) 0 , NULL , 0 )));
@@ -1353,7 +1364,8 @@ int usage(char *progname)
1353
1364
printf (" --timeout\t\tsets the SNMP timeout (in ms)\n" );
1354
1365
printf (" --sleep\t\tsleep between every SNMP query (in ms)\n" );
1355
1366
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" );
1357
1369
printf ("\n" );
1358
1370
return 3 ;
1359
1371
}
0 commit comments