diff options
Diffstat (limited to 'plugins-scripts/check_ifstatus.pl')
-rwxr-xr-x | plugins-scripts/check_ifstatus.pl | 73 |
1 files changed, 45 insertions, 28 deletions
diff --git a/plugins-scripts/check_ifstatus.pl b/plugins-scripts/check_ifstatus.pl index cb8b5d0..cc9cccf 100755 --- a/plugins-scripts/check_ifstatus.pl +++ b/plugins-scripts/check_ifstatus.pl | |||
@@ -5,6 +5,8 @@ | |||
5 | # | 5 | # |
6 | # Copyright (C) 2000 Christoph Kron | 6 | # Copyright (C) 2000 Christoph Kron |
7 | # Modified 5/2002 to conform to updated Nagios Plugin Guidelines (S. Ghosh) | 7 | # Modified 5/2002 to conform to updated Nagios Plugin Guidelines (S. Ghosh) |
8 | # Added -x option (4/2003) | ||
9 | # Added -u option (4/2003) | ||
8 | # | 10 | # |
9 | # This program is free software; you can redistribute it and/or | 11 | # This program is free software; you can redistribute it and/or |
10 | # modify it under the terms of the GNU General Public License | 12 | # modify it under the terms of the GNU General Public License |
@@ -70,14 +72,17 @@ my %ifStatus; | |||
70 | my $ifup =0 ; | 72 | my $ifup =0 ; |
71 | my $ifdown =0; | 73 | my $ifdown =0; |
72 | my $ifdormant = 0; | 74 | my $ifdormant = 0; |
73 | my $ifexclude =0 ; | 75 | my $ifexclude = 0 ; |
76 | my $ifunused = 0; | ||
74 | my $ifmessage = ""; | 77 | my $ifmessage = ""; |
75 | my $snmp_version = 1; | 78 | my $snmp_version = 1; |
76 | my $ifXTable; | 79 | my $ifXTable; |
77 | my $opt_h ; | 80 | my $opt_h ; |
78 | my $opt_V ; | 81 | my $opt_V ; |
82 | my $opt_u; | ||
79 | my $opt_x ; | 83 | my $opt_x ; |
80 | my %excluded ; | 84 | my %excluded ; |
85 | my @unused_ports ; | ||
81 | 86 | ||
82 | 87 | ||
83 | 88 | ||
@@ -101,7 +106,8 @@ $status = GetOptions( | |||
101 | "p=i" =>\$port, "port=i" => \$port, | 106 | "p=i" =>\$port, "port=i" => \$port, |
102 | "H=s" => \$hostname, "hostname=s" => \$hostname, | 107 | "H=s" => \$hostname, "hostname=s" => \$hostname, |
103 | "I" => \$ifXTable, "ifmib" => \$ifXTable, | 108 | "I" => \$ifXTable, "ifmib" => \$ifXTable, |
104 | "x:s" => \$opt_x, "exclude:s" => \$opt_x); | 109 | "x:s" => \$opt_x, "exclude:s" => \$opt_x, |
110 | "u=s" => \$opt_u, "unused_ports=s" => \$opt_u); | ||
105 | 111 | ||
106 | if ($status == 0) | 112 | if ($status == 0) |
107 | { | 113 | { |
@@ -122,11 +128,10 @@ if ($opt_h) { | |||
122 | 128 | ||
123 | 129 | ||
124 | if (defined $opt_x) { | 130 | if (defined $opt_x) { |
125 | my @x = split(",", $opt_x); | 131 | my @x = split(/,/, $opt_x); |
126 | my $x; | ||
127 | if ( @x) { | 132 | if ( @x) { |
128 | foreach $x (@x){ | 133 | foreach $key (@x){ |
129 | $excluded{$x} = 1; | 134 | $excluded{$key} = 1; |
130 | } | 135 | } |
131 | }else{ | 136 | }else{ |
132 | $excluded{23} = 1; # default PPP(23) if empty list - note (AIX seems to think PPP is 22 according to a post) | 137 | $excluded{23} = 1; # default PPP(23) if empty list - note (AIX seems to think PPP is 22 according to a post) |
@@ -136,6 +141,13 @@ if (defined $opt_x) { | |||
136 | # { print "key = $x val = $excluded{$x}\n";} | 141 | # { print "key = $x val = $excluded{$x}\n";} |
137 | } | 142 | } |
138 | 143 | ||
144 | if ($opt_u) { | ||
145 | @unused_ports = split(/,/,$opt_u); | ||
146 | foreach $key (@unused_ports) { | ||
147 | $ifStatus{$key}{'notInUse'}++ ; | ||
148 | } | ||
149 | } | ||
150 | |||
139 | if (! utils::is_hostname($hostname)){ | 151 | if (! utils::is_hostname($hostname)){ |
140 | usage(); | 152 | usage(); |
141 | exit $ERRORS{"UNKNOWN"}; | 153 | exit $ERRORS{"UNKNOWN"}; |
@@ -210,53 +222,58 @@ $session->close; | |||
210 | 222 | ||
211 | foreach $key (keys %ifStatus) { | 223 | foreach $key (keys %ifStatus) { |
212 | 224 | ||
213 | # check only if interface is administratively up | 225 | # skip unused interfaces |
226 | if (!defined($ifStatus{$key}{'notInUse'})) { | ||
227 | # check only if interface is administratively up | ||
214 | if ($ifStatus{$key}{$snmpIfAdminStatus} == 1 ) { | 228 | if ($ifStatus{$key}{$snmpIfAdminStatus} == 1 ) { |
215 | 229 | ||
216 | # check only if interface type is not listed in %excluded | 230 | # check only if interface type is not listed in %excluded |
217 | 231 | if (!defined $excluded{$ifStatus{$key}{$snmpIfType}} ) { | |
218 | if (!defined $excluded{$ifStatus{$key}{$snmpIfType}} ) { | 232 | if ($ifStatus{$key}{$snmpIfOperStatus} == 1 ) { $ifup++ ;} |
219 | if ($ifStatus{$key}{$snmpIfOperStatus} == 1 ) { $ifup++ ;} | 233 | if ($ifStatus{$key}{$snmpIfOperStatus} == 2 ) { |
220 | if ($ifStatus{$key}{$snmpIfOperStatus} == 2 ) { | 234 | $ifdown++ ; |
221 | $ifdown++ ; | 235 | if (defined $ifXTable) { |
222 | if (defined $ifXTable) { | 236 | $ifmessage .= sprintf("%s: down -> %s<BR>", |
223 | $ifmessage .= sprintf("%s: down -> %s<BR>", | ||
224 | $ifStatus{$key}{$snmpIfName}, | 237 | $ifStatus{$key}{$snmpIfName}, |
225 | $ifStatus{$key}{$snmpIfAlias}); | 238 | $ifStatus{$key}{$snmpIfAlias}); |
226 | }else{ | 239 | }else{ |
227 | $ifmessage .= sprintf("%s: down <BR>", | 240 | $ifmessage .= sprintf("%s: down <BR>", |
228 | $ifStatus{$key}{$snmpIfDescr}); | 241 | $ifStatus{$key}{$snmpIfDescr}); |
229 | } | 242 | } |
243 | } | ||
244 | if ($ifStatus{$key}{$snmpIfOperStatus} == 5 ) { $ifdormant++ ;} | ||
245 | }else{ | ||
246 | $ifexclude++; | ||
230 | } | 247 | } |
231 | if ($ifStatus{$key}{$snmpIfOperStatus} == 5 ) { $ifdormant++ ;} | ||
232 | }else{ | ||
233 | $ifexclude++; | ||
234 | } | ||
235 | 248 | ||
249 | } | ||
250 | }else{ | ||
251 | $ifunused++; | ||
236 | } | 252 | } |
237 | |||
238 | } | 253 | } |
239 | 254 | ||
240 | if ($ifdown > 0) { | 255 | if ($ifdown > 0) { |
241 | $state = 'CRITICAL'; | 256 | $state = 'CRITICAL'; |
242 | $answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d, excluded: %d<BR>", | 257 | $answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d, excluded: %d, unused: %d<BR>", |
243 | $hostname, | 258 | $hostname, |
244 | $ifup, | 259 | $ifup, |
245 | $ifdown, | 260 | $ifdown, |
246 | $ifdormant, | 261 | $ifdormant, |
247 | $ifexclude); | 262 | $ifexclude, |
263 | $ifunused); | ||
248 | $answer = $answer . $ifmessage . "\n"; | 264 | $answer = $answer . $ifmessage . "\n"; |
249 | } | 265 | } |
250 | else { | 266 | else { |
251 | $state = 'OK'; | 267 | $state = 'OK'; |
252 | $answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d, excluded: %d", | 268 | $answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d, excluded: %d, unused: %d", |
253 | $hostname, | 269 | $hostname, |
254 | $ifup, | 270 | $ifup, |
255 | $ifdown, | 271 | $ifdown, |
256 | $ifdormant, | 272 | $ifdormant, |
257 | $ifexclude); | 273 | $ifexclude, |
274 | $ifunused); | ||
258 | } | 275 | } |
259 | my $perfdata = sprintf("up:%d,down:%d,dormant:%d,excluded:%d",$ifup,$ifdown,$ifdormant,$ifexclude); | 276 | my $perfdata = sprintf("up:%d,down:%d,dormant:%d,excluded:%d,unused:%d",$ifup,$ifdown,$ifdormant,$ifexclude,$ifunused); |
260 | print ("$state: $answer |$perfdata\n"); | 277 | print ("$state: $answer |$perfdata\n"); |
261 | exit $ERRORS{$state}; | 278 | exit $ERRORS{$state}; |
262 | 279 | ||