[Nagiosplug-checkins] CVS: nagiosplug/plugins-scripts check_ifstatus.pl,1.4,1.5
Subhendu Ghosh
sghosh at users.sourceforge.net
Fri Apr 11 15:37:02 CEST 2003
Update of /cvsroot/nagiosplug/nagiosplug/plugins-scripts
In directory sc8-pr-cvs1:/tmp/cvs-serv8980/plugins-scripts
Modified Files:
check_ifstatus.pl
Log Message:
added feature -u (list of unused ifIndex)
Index: check_ifstatus.pl
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins-scripts/check_ifstatus.pl,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** check_ifstatus.pl 11 Apr 2003 22:09:48 -0000 1.4
--- check_ifstatus.pl 11 Apr 2003 22:36:05 -0000 1.5
***************
*** 6,9 ****
--- 6,11 ----
# Copyright (C) 2000 Christoph Kron
# Modified 5/2002 to conform to updated Nagios Plugin Guidelines (S. Ghosh)
+ # Added -x option (4/2003)
+ # Added -u option (4/2003)
#
# This program is free software; you can redistribute it and/or
***************
*** 71,75 ****
my $ifdown =0;
my $ifdormant = 0;
! my $ifexclude =0 ;
my $ifmessage = "";
my $snmp_version = 1;
--- 73,78 ----
my $ifdown =0;
my $ifdormant = 0;
! my $ifexclude = 0 ;
! my $ifunused = 0;
my $ifmessage = "";
my $snmp_version = 1;
***************
*** 77,82 ****
--- 80,87 ----
my $opt_h ;
my $opt_V ;
+ my $opt_u;
my $opt_x ;
my %excluded ;
+ my @unused_ports ;
***************
*** 102,106 ****
"H=s" => \$hostname, "hostname=s" => \$hostname,
"I" => \$ifXTable, "ifmib" => \$ifXTable,
! "x:s" => \$opt_x, "exclude:s" => \$opt_x);
if ($status == 0)
--- 107,112 ----
"H=s" => \$hostname, "hostname=s" => \$hostname,
"I" => \$ifXTable, "ifmib" => \$ifXTable,
! "x:s" => \$opt_x, "exclude:s" => \$opt_x,
! "u=s" => \$opt_u, "unused_ports=s" => \$opt_u);
if ($status == 0)
***************
*** 123,131 ****
if (defined $opt_x) {
! my @x = split(",", $opt_x);
! my $x;
if ( @x) {
! foreach $x (@x){
! $excluded{$x} = 1;
}
}else{
--- 129,136 ----
if (defined $opt_x) {
! my @x = split(/,/, $opt_x);
if ( @x) {
! foreach $key (@x){
! $excluded{$key} = 1;
}
}else{
***************
*** 137,140 ****
--- 142,152 ----
}
+ if ($opt_u) {
+ @unused_ports = split(/,/,$opt_u);
+ foreach $key (@unused_ports) {
+ $ifStatus{$key}{'notInUse'}++ ;
+ }
+ }
+
if (! utils::is_hostname($hostname)){
usage();
***************
*** 211,261 ****
foreach $key (keys %ifStatus) {
! # check only if interface is administratively up
if ($ifStatus{$key}{$snmpIfAdminStatus} == 1 ) {
! # check only if interface type is not listed in %excluded
!
! if (!defined $excluded{$ifStatus{$key}{$snmpIfType}} ) {
! if ($ifStatus{$key}{$snmpIfOperStatus} == 1 ) { $ifup++ ;}
! if ($ifStatus{$key}{$snmpIfOperStatus} == 2 ) {
! $ifdown++ ;
! if (defined $ifXTable) {
! $ifmessage .= sprintf("%s: down -> %s<BR>",
$ifStatus{$key}{$snmpIfName},
$ifStatus{$key}{$snmpIfAlias});
! }else{
! $ifmessage .= sprintf("%s: down <BR>",
$ifStatus{$key}{$snmpIfDescr});
! }
}
- if ($ifStatus{$key}{$snmpIfOperStatus} == 5 ) { $ifdormant++ ;}
- }else{
- $ifexclude++;
- }
}
-
}
if ($ifdown > 0) {
$state = 'CRITICAL';
! $answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d, excluded: %d<BR>",
$hostname,
$ifup,
$ifdown,
$ifdormant,
! $ifexclude);
$answer = $answer . $ifmessage . "\n";
}
else {
$state = 'OK';
! $answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d, excluded: %d",
$hostname,
$ifup,
$ifdown,
$ifdormant,
! $ifexclude);
}
! my $perfdata = sprintf("up:%d,down:%d,dormant:%d,excluded:%d",$ifup,$ifdown,$ifdormant,$ifexclude);
print ("$state: $answer |$perfdata\n");
exit $ERRORS{$state};
--- 223,278 ----
foreach $key (keys %ifStatus) {
! # skip unused interfaces
! if (!defined($ifStatus{$key}{'notInUse'})) {
! # check only if interface is administratively up
if ($ifStatus{$key}{$snmpIfAdminStatus} == 1 ) {
! # check only if interface type is not listed in %excluded
! if (!defined $excluded{$ifStatus{$key}{$snmpIfType}} ) {
! if ($ifStatus{$key}{$snmpIfOperStatus} == 1 ) { $ifup++ ;}
! if ($ifStatus{$key}{$snmpIfOperStatus} == 2 ) {
! $ifdown++ ;
! if (defined $ifXTable) {
! $ifmessage .= sprintf("%s: down -> %s<BR>",
$ifStatus{$key}{$snmpIfName},
$ifStatus{$key}{$snmpIfAlias});
! }else{
! $ifmessage .= sprintf("%s: down <BR>",
$ifStatus{$key}{$snmpIfDescr});
! }
! }
! if ($ifStatus{$key}{$snmpIfOperStatus} == 5 ) { $ifdormant++ ;}
! }else{
! $ifexclude++;
}
+ }
+ }else{
+ $ifunused++;
}
}
if ($ifdown > 0) {
$state = 'CRITICAL';
! $answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d, excluded: %d, unused: %d<BR>",
$hostname,
$ifup,
$ifdown,
$ifdormant,
! $ifexclude,
! $ifunused);
$answer = $answer . $ifmessage . "\n";
}
else {
$state = 'OK';
! $answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d, excluded: %d, unused: %d",
$hostname,
$ifup,
$ifdown,
$ifdormant,
! $ifexclude,
! $ifunused);
}
! my $perfdata = sprintf("up:%d,down:%d,dormant:%d,excluded:%d,unused:%d",$ifup,$ifdown,$ifdormant,$ifexclude,$ifunused);
print ("$state: $answer |$perfdata\n");
exit $ERRORS{$state};
More information about the Commits
mailing list