summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xplugins-scripts/check_ifstatus.pl73
1 files changed, 57 insertions, 16 deletions
diff --git a/plugins-scripts/check_ifstatus.pl b/plugins-scripts/check_ifstatus.pl
index 181fb7d7..cb8b5d00 100755
--- a/plugins-scripts/check_ifstatus.pl
+++ b/plugins-scripts/check_ifstatus.pl
@@ -70,11 +70,14 @@ my %ifStatus;
70my $ifup =0 ; 70my $ifup =0 ;
71my $ifdown =0; 71my $ifdown =0;
72my $ifdormant = 0; 72my $ifdormant = 0;
73my $ifexclude =0 ;
73my $ifmessage = ""; 74my $ifmessage = "";
74my $snmp_version = 1; 75my $snmp_version = 1;
75my $ifXTable; 76my $ifXTable;
76my $opt_h ; 77my $opt_h ;
77my $opt_V ; 78my $opt_V ;
79my $opt_x ;
80my %excluded ;
78 81
79 82
80 83
@@ -97,7 +100,8 @@ $status = GetOptions(
97 "C=s" =>\$community,"community=s" => \$community, 100 "C=s" =>\$community,"community=s" => \$community,
98 "p=i" =>\$port, "port=i" => \$port, 101 "p=i" =>\$port, "port=i" => \$port,
99 "H=s" => \$hostname, "hostname=s" => \$hostname, 102 "H=s" => \$hostname, "hostname=s" => \$hostname,
100 "I" => \$ifXTable, "ifmib" => \$ifXTable ); 103 "I" => \$ifXTable, "ifmib" => \$ifXTable,
104 "x:s" => \$opt_x, "exclude:s" => \$opt_x);
101 105
102if ($status == 0) 106if ($status == 0)
103{ 107{
@@ -116,6 +120,22 @@ if ($opt_h) {
116 exit $ERRORS{'OK'}; 120 exit $ERRORS{'OK'};
117} 121}
118 122
123
124if (defined $opt_x) {
125 my @x = split(",", $opt_x);
126 my $x;
127 if ( @x) {
128 foreach $x (@x){
129 $excluded{$x} = 1;
130 }
131 }else{
132 $excluded{23} = 1; # default PPP(23) if empty list - note (AIX seems to think PPP is 22 according to a post)
133 }
134 #debugging
135 #foreach $x (keys %excluded)
136 # { print "key = $x val = $excluded{$x}\n";}
137}
138
119if (! utils::is_hostname($hostname)){ 139if (! utils::is_hostname($hostname)){
120 usage(); 140 usage();
121 exit $ERRORS{"UNKNOWN"}; 141 exit $ERRORS{"UNKNOWN"};
@@ -159,6 +179,8 @@ push(@snmpoids,$snmpIfAdminStatus);
159push(@snmpoids,$snmpIfDescr); 179push(@snmpoids,$snmpIfDescr);
160push(@snmpoids,$snmpIfType); 180push(@snmpoids,$snmpIfType);
161push(@snmpoids,$snmpIfName) if ( defined $ifXTable); 181push(@snmpoids,$snmpIfName) if ( defined $ifXTable);
182push(@snmpoids,$snmpIfAlias) if ( defined $ifXTable);
183
162 184
163 185
164 186
@@ -168,7 +190,11 @@ foreach $snmpoid (@snmpoids) {
168 $answer=$session->error; 190 $answer=$session->error;
169 $session->close; 191 $session->close;
170 $state = 'CRITICAL'; 192 $state = 'CRITICAL';
171 print ("$state: $answer for $snmpoid with snmp version $snmp_version\n"); 193 if ( ( $snmpoid =~ $snmpIfName ) && defined $ifXTable ) {
194 print ("$state: Device does not support ifTable - try without -I option\n");
195 }else{
196 print ("$state: $answer for $snmpoid with snmp version $snmp_version\n");
197 }
172 exit $ERRORS{$state}; 198 exit $ERRORS{$state};
173 } 199 }
174 200
@@ -186,40 +212,52 @@ foreach $key (keys %ifStatus) {
186 212
187 # check only if interface is administratively up 213 # check only if interface is administratively up
188 if ($ifStatus{$key}{$snmpIfAdminStatus} == 1 ) { 214 if ($ifStatus{$key}{$snmpIfAdminStatus} == 1 ) {
189 # check only if interface is not of type 23 aka PPP interface 215
190 if ($ifStatus{$key}{$snmpIfType} != 23 ) { 216 # check only if interface type is not listed in %excluded
217
218 if (!defined $excluded{$ifStatus{$key}{$snmpIfType}} ) {
191 if ($ifStatus{$key}{$snmpIfOperStatus} == 1 ) { $ifup++ ;} 219 if ($ifStatus{$key}{$snmpIfOperStatus} == 1 ) { $ifup++ ;}
192 if ($ifStatus{$key}{$snmpIfOperStatus} == 2 ) { 220 if ($ifStatus{$key}{$snmpIfOperStatus} == 2 ) {
193 $ifdown++ ; 221 $ifdown++ ;
194 $ifmessage .= sprintf("%s: down -> %s<BR>", 222 if (defined $ifXTable) {
195 $ifStatus{$key}{$snmpIfDescr}, 223 $ifmessage .= sprintf("%s: down -> %s<BR>",
196 $ifStatus{$key}{$snmpIfName}); 224 $ifStatus{$key}{$snmpIfName},
225 $ifStatus{$key}{$snmpIfAlias});
226 }else{
227 $ifmessage .= sprintf("%s: down <BR>",
228 $ifStatus{$key}{$snmpIfDescr});
229 }
197 } 230 }
198 if ($ifStatus{$key}{$snmpIfOperStatus} == 5 ) { $ifdormant++ ;} 231 if ($ifStatus{$key}{$snmpIfOperStatus} == 5 ) { $ifdormant++ ;}
232 }else{
233 $ifexclude++;
199 } 234 }
235
200 } 236 }
201 237
202} 238}
203 239
204 if ($ifdown > 0) { 240 if ($ifdown > 0) {
205 $state = 'CRITICAL'; 241 $state = 'CRITICAL';
206 $answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d<BR>", 242 $answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d, excluded: %d<BR>",
207 $hostname, 243 $hostname,
208 $ifup, 244 $ifup,
209 $ifdown, 245 $ifdown,
210 $ifdormant); 246 $ifdormant,
247 $ifexclude);
211 $answer = $answer . $ifmessage . "\n"; 248 $answer = $answer . $ifmessage . "\n";
212 } 249 }
213 else { 250 else {
214 $state = 'OK'; 251 $state = 'OK';
215 $answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d\n", 252 $answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d, excluded: %d",
216 $hostname, 253 $hostname,
217 $ifup, 254 $ifup,
218 $ifdown, 255 $ifdown,
219 $ifdormant); 256 $ifdormant,
257 $ifexclude);
220 } 258 }
221 259my $perfdata = sprintf("up:%d,down:%d,dormant:%d,excluded:%d",$ifup,$ifdown,$ifdormant,$ifexclude);
222print ("$state: $answer"); 260print ("$state: $answer |$perfdata\n");
223exit $ERRORS{$state}; 261exit $ERRORS{$state};
224 262
225 263
@@ -236,7 +274,7 @@ sub usage {
236 274
237sub print_help { 275sub print_help {
238 printf "check_ifstatus plugin for Nagios monitors operational \n"; 276 printf "check_ifstatus plugin for Nagios monitors operational \n";
239 printf "status of each network interface (except PPP interfaces) on the target host\n"; 277 printf "status of each network interface on the target host\n";
240 printf "\nUsage:\n"; 278 printf "\nUsage:\n";
241 printf " -H (--hostname) Hostname to query - (required)\n"; 279 printf " -H (--hostname) Hostname to query - (required)\n";
242 printf " -C (--community) SNMP read community (defaults to public,\n"; 280 printf " -C (--community) SNMP read community (defaults to public,\n";
@@ -245,8 +283,11 @@ sub print_help {
245 printf " 2 for SNMP v2c\n"; 283 printf " 2 for SNMP v2c\n";
246 printf " SNMP v2c will use get_bulk for less overhead\n"; 284 printf " SNMP v2c will use get_bulk for less overhead\n";
247 printf " -p (--port) SNMP port (default 161)\n"; 285 printf " -p (--port) SNMP port (default 161)\n";
248 printf " -I (--ifmib) Agent supports IFMIB ifXTable. Do not use if\n"; 286 printf " -I (--ifmib) Agent supports IFMIB ifXTable. For Cisco - this will provide\n";
249 printf " you don't know what this is.\n"; 287 printf " the descriptive name. Do not use if you don't know what this is. \n";
288 printf " -x (--exclude) A comma separated list of ifType values that should be excluded \n";
289 printf " from the report (default for an empty list is PPP(23).\n";
290 printf " See the IANAifType-MIB for a list of interface types.\n";
250 printf " -V (--version) Plugin version\n"; 291 printf " -V (--version) Plugin version\n";
251 printf " -h (--help) usage help \n\n"; 292 printf " -h (--help) usage help \n\n";
252 print_revision($PROGNAME, '$Revision$'); 293 print_revision($PROGNAME, '$Revision$');