Compatibility SNMPv3
This commit is contained in:
parent
102625e7b0
commit
92d74efee2
|
@ -12,8 +12,8 @@
|
|||
# help : ./check_snmp_storage -h
|
||||
|
||||
use strict;
|
||||
use Net::SNMP;
|
||||
use Getopt::Long;
|
||||
require "@NAGIOS_PLUGINS@/Centreon/SNMP/Utils.pm";
|
||||
|
||||
# Nagios specific
|
||||
|
||||
|
@ -22,6 +22,16 @@ use utils qw(%ERRORS $TIMEOUT);
|
|||
#my $TIMEOUT = 15;
|
||||
#my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
|
||||
|
||||
my %OPTION = (
|
||||
"host" => undef,
|
||||
"snmp-community" => "public", "snmp-version" => 1, "snmp-port" => 161,
|
||||
"snmp-auth-key" => undef, "snmp-auth-user" => undef, "snmp-auth-password" => undef, "snmp-auth-protocol" => "MD5",
|
||||
"snmp-priv-key" => undef, "snmp-priv-password" => undef, "snmp-priv-protocol" => "DES",
|
||||
"maxrepetitions" => undef,
|
||||
"64-bits" => undef,
|
||||
);
|
||||
my $session_params;
|
||||
|
||||
# SNMP Datas
|
||||
my $storage_table= '1.3.6.1.2.1.25.2.3.1';
|
||||
my $storagetype_table = '1.3.6.1.2.1.25.2.3.1.2';
|
||||
|
@ -59,10 +69,6 @@ $hrStorage{"1.3.6.1.2.1.25.2.1.10"} = 'NetworkDisk';
|
|||
my $Name='check_snmp_storage';
|
||||
my $Version='1.3.3';
|
||||
|
||||
my $o_host = undef; # hostname
|
||||
my $o_community = undef; # community
|
||||
my $o_port = 161; # port
|
||||
my $o_version2 = undef; #use snmp v2c
|
||||
my $o_descr = undef; # description filter
|
||||
my $o_storagetype = undef; # parse storage type also
|
||||
my $o_warn = undef; # warning limit
|
||||
|
@ -82,22 +88,13 @@ my $o_short= undef; # Short output parameters
|
|||
my @o_shortL= undef; # output type,where,cut
|
||||
my $o_reserve= 0; # % reserved blocks (A. Greiner-Bär patch)
|
||||
my $o_giga= undef; # output and levels in gigabytes instead of megabytes
|
||||
# SNMPv3 specific
|
||||
my $o_login= undef; # Login for snmpv3
|
||||
my $o_passwd= undef; # Pass for snmpv3
|
||||
my $v3protocols=undef; # V3 protocol list.
|
||||
my $o_authproto='md5'; # Auth protocol
|
||||
my $o_privproto='des'; # Priv protocol
|
||||
my $o_privpass= undef; # priv password
|
||||
# SNMP Message size parameter (Makina Corpus contrib)
|
||||
my $o_octetlength=undef;
|
||||
|
||||
# functions
|
||||
|
||||
sub p_version { print "$Name version : $Version\n"; }
|
||||
|
||||
sub print_usage {
|
||||
print "Usage: $Name [-v] -H <host> -C <snmp_community> [-2] | (-l login -x passwd [-X pass -L <authp>,<privp>]) [-p <port>] -m <name in desc_oid> [-q storagetype] -w <warn_level> -c <crit_level> [-t <timeout>] [-T pl|pu|bl|bu ] [-r -s -i -G] [-e] [-S 0|1[,1,<car>]] [-o <octet_length>] [-R <% reserved>]\n";
|
||||
print "Usage: $Name [-v] -H <host> -C <snmp_community> [-2] | (-l login -x passwd) [-p <port>] -m <name in desc_oid> [-q storagetype] -w <warn_level> -c <crit_level> [-t <timeout>] [-T pl|pu|bl|bu ] [-r -s -i -G] [-e] [-S 0|1[,1,<car>]] [-o <octet_length>] [-R <% reserved>]\n";
|
||||
}
|
||||
|
||||
sub round ($$) {
|
||||
|
@ -105,21 +102,21 @@ sub round ($$) {
|
|||
}
|
||||
|
||||
sub is_pattern_valid { # Test for things like "<I\s*[^>" or "+5-i"
|
||||
my $pat = shift;
|
||||
if (!defined($pat)) { $pat=" ";} # Just to get rid of compilation time warnings
|
||||
return eval { "" =~ /$pat/; 1 } || 0;
|
||||
my $pat = shift;
|
||||
if (!defined($pat)) { $pat=" ";} # Just to get rid of compilation time warnings
|
||||
return eval { "" =~ /$pat/; 1 } || 0;
|
||||
}
|
||||
|
||||
# Get the alarm signal (just in case snmp timout screws up)
|
||||
$SIG{'ALRM'} = sub {
|
||||
print ("ERROR: General time-out (Alarm signal)\n");
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
print ("ERROR: General time-out (Alarm signal)\n");
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
};
|
||||
|
||||
sub isnnum { # Return true if arg is not a number
|
||||
my $num = shift;
|
||||
if ( $num =~ /^-?(\d+\.?\d*)|(^\.\d+)$/ ) { return 0 ;}
|
||||
return 1;
|
||||
my $num = shift;
|
||||
if ( $num =~ /^-?(\d+\.?\d*)|(^\.\d+)$/ ) { return 0 ;}
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub help {
|
||||
|
@ -137,18 +134,9 @@ warn if %used > warn and critical if %used > crit
|
|||
name or IP address of host to check
|
||||
-C, --community=COMMUNITY NAME
|
||||
community name for the host's SNMP agent (implies SNMP v1)
|
||||
-2, --v2c
|
||||
Use snmp v2c
|
||||
-l, --login=LOGIN ; -x, --passwd=PASSWD
|
||||
Login and auth password for snmpv3 authentication
|
||||
If no priv password exists, implies AuthNoPriv
|
||||
-X, --privpass=PASSWD
|
||||
Priv password for snmpv3 (AuthPriv protocol)
|
||||
-L, --protocols=<authproto>,<privproto>
|
||||
<authproto> : Authentication protocol (md5|sha : default md5)
|
||||
<privproto> : Priv protocole (des|aes : default des)
|
||||
-x, --passwd=PASSWD
|
||||
Password for snmpv3 authentication
|
||||
-p, --port=PORT
|
||||
SNMP port (Default 161)
|
||||
-m, --name=NAME
|
||||
|
@ -229,32 +217,36 @@ sub verb { my $t=shift; print $t,"\n" if defined($o_verb) ; }
|
|||
sub check_options {
|
||||
Getopt::Long::Configure ("bundling");
|
||||
GetOptions(
|
||||
'v' => \$o_verb, 'verbose' => \$o_verb,
|
||||
"H|hostname|host=s" => \$OPTION{'host'},
|
||||
"C|community=s" => \$OPTION{'snmp-community'},
|
||||
"snmp|snmp-version=s" => \$OPTION{'snmp-version'},
|
||||
"p|port|P|snmpport|snmp-port=i" => \$OPTION{'snmp-port'},
|
||||
"l|login|username=s" => \$OPTION{'snmp-auth-user'},
|
||||
"x|passwd|authpassword|password=s" => \$OPTION{'snmp-auth-password'},
|
||||
"k|authkey=s" => \$OPTION{'snmp-auth-key'},
|
||||
"authprotocol=s" => \$OPTION{'snmp-auth-protocol'},
|
||||
"privpassword=s" => \$OPTION{'snmp-priv-password'},
|
||||
"privkey=s" => \$OPTION{'snmp-priv-key'},
|
||||
"privprotocol=s" => \$OPTION{'snmp-priv-protocol'},
|
||||
"maxrepetitions=s" => \$OPTION{'maxrepetitions'},
|
||||
"64-bits" => \$OPTION{'64-bits'},
|
||||
'v' => \$o_verb, 'verbose' => \$o_verb,
|
||||
'h' => \$o_help, 'help' => \$o_help,
|
||||
'H:s' => \$o_host, 'hostname:s' => \$o_host,
|
||||
'p:i' => \$o_port, 'port:i' => \$o_port,
|
||||
'C:s' => \$o_community, 'community:s' => \$o_community,
|
||||
'2' => \$o_version2, 'v2c' => \$o_version2,
|
||||
'l:s' => \$o_login, 'login:s' => \$o_login,
|
||||
'x:s' => \$o_passwd, 'passwd:s' => \$o_passwd,
|
||||
'X:s' => \$o_privpass, 'privpass:s' => \$o_privpass,
|
||||
'L:s' => \$v3protocols, 'protocols:s' => \$v3protocols,
|
||||
'c:s' => \$o_crit, 'critical:s' => \$o_crit,
|
||||
'w:s' => \$o_warn, 'warn:s' => \$o_warn,
|
||||
't:i' => \$o_timeout, 'timeout:i' => \$o_timeout,
|
||||
't:i' => \$o_timeout, 'timeout:i' => \$o_timeout,
|
||||
'm:s' => \$o_descr, 'name:s' => \$o_descr,
|
||||
'T:s' => \$o_type, 'type:s' => \$o_type,
|
||||
'T:s' => \$o_type, 'type:s' => \$o_type,
|
||||
'r' => \$o_noreg, 'noregexp' => \$o_noreg,
|
||||
's' => \$o_sum, 'sum' => \$o_sum,
|
||||
'i' => \$o_index, 'index' => \$o_index,
|
||||
'e' => \$o_negate, 'exclude' => \$o_negate,
|
||||
'V' => \$o_version, 'version' => \$o_version,
|
||||
'q:s' => \$o_storagetype, 'storagetype:s'=> \$o_storagetype,
|
||||
'S:s' => \$o_short, 'short:s' => \$o_short,
|
||||
'o:i' => \$o_octetlength, 'octetlength:i' => \$o_octetlength,
|
||||
'f' => \$o_perf, 'perfparse' => \$o_perf,
|
||||
'R:i' => \$o_reserve, 'reserved:i' => \$o_reserve,
|
||||
'G' => \$o_giga, 'gigabyte' => \$o_giga
|
||||
'S:s' => \$o_short, 'short:s' => \$o_short,
|
||||
'f' => \$o_perf, 'perfparse' => \$o_perf,
|
||||
'R:i' => \$o_reserve, 'reserved:i' => \$o_reserve,
|
||||
'G' => \$o_giga, 'gigabyte' => \$o_giga
|
||||
);
|
||||
if (defined($o_help) ) { help(); exit $ERRORS{"UNKNOWN"}};
|
||||
if (defined($o_version) ) { p_version(); exit $ERRORS{"UNKNOWN"}};
|
||||
|
@ -262,23 +254,12 @@ sub check_options {
|
|||
if (!is_pattern_valid($o_descr))
|
||||
{ print "Bad pattern for mount point !\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
# check snmp information
|
||||
if ( !defined($o_community) && (!defined($o_login) || !defined($o_passwd)) )
|
||||
{ print "Put snmp login info!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
if ((defined($o_login) || defined($o_passwd)) && (defined($o_community) || defined($o_version2)) )
|
||||
{ print "Can't mix snmp v1,2c,3 protocols!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
if (defined ($v3protocols)) {
|
||||
if (!defined($o_login)) { print "Put snmp V3 login info with protocols!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
my @v3proto=split(/,/,$v3protocols);
|
||||
if ((defined ($v3proto[0])) && ($v3proto[0] ne "")) {$o_authproto=$v3proto[0]; } # Auth protocol
|
||||
if (defined ($v3proto[1])) {$o_privproto=$v3proto[1]; } # Priv protocol
|
||||
if ((defined ($v3proto[1])) && (!defined($o_privpass))) {
|
||||
print "Put snmp V3 priv login info with priv protocols!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
|
||||
}
|
||||
($session_params) = Centreon::SNMP::Utils::check_snmp_options($ERRORS{'UNKNOWN'}, \%OPTION);
|
||||
# Check types
|
||||
if ( !defined($o_type) ) { $o_type="pu" ;}
|
||||
if ( ! grep( /^$o_type$/ ,@o_typeok) ) { print_usage(); exit $ERRORS{"UNKNOWN"}};
|
||||
# Check compulsory attributes
|
||||
if ( ! defined($o_descr) || ! defined($o_host) || !defined($o_warn) ||
|
||||
if ( ! defined($o_descr) || !defined($o_warn) ||
|
||||
!defined($o_crit)) { print_usage(); exit $ERRORS{"UNKNOWN"}};
|
||||
# Get rid of % sign if any
|
||||
$o_warn =~ s/\%//;
|
||||
|
@ -311,10 +292,6 @@ sub check_options {
|
|||
if (defined ($o_shortL[2]) && isnnum($o_shortL[2]))
|
||||
{print "-S last option must be an integer\n";print_usage(); exit $ERRORS{"UNKNOWN"};}
|
||||
}
|
||||
#### octet length checks
|
||||
if (defined ($o_octetlength) && (isnnum($o_octetlength) || $o_octetlength > 65535 || $o_octetlength < 484 )) {
|
||||
print "octet lenght must be < 65535 and > 484\n";print_usage(); exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
#### reserved blocks checks (A. Greiner-Bär patch).
|
||||
if (defined ($o_reserve) && (isnnum($o_reserve) || $o_reserve > 99 || $o_reserve < 0 )) {
|
||||
print "reserved blocks must be < 100 and >= 0\n";print_usage(); exit $ERRORS{"UNKNOWN"};
|
||||
|
@ -327,114 +304,26 @@ check_options();
|
|||
|
||||
# Check gobal timeout
|
||||
if (defined($TIMEOUT)) {
|
||||
verb("Alarm at $TIMEOUT");
|
||||
alarm($TIMEOUT);
|
||||
verb("Alarm at $TIMEOUT");
|
||||
alarm($TIMEOUT);
|
||||
} else {
|
||||
verb("no timeout defined : $o_timeout + 10");
|
||||
alarm ($o_timeout+10);
|
||||
verb("no timeout defined : $o_timeout + 10");
|
||||
alarm ($o_timeout+10);
|
||||
}
|
||||
|
||||
# Connect to host
|
||||
my ($session,$error);
|
||||
if ( defined($o_login) && defined($o_passwd)) {
|
||||
# SNMPv3 login
|
||||
verb("SNMPv3 login");
|
||||
if (!defined ($o_privpass)) {
|
||||
verb("SNMPv3 AuthNoPriv login : $o_login, $o_authproto");
|
||||
($session, $error) = Net::SNMP->session(
|
||||
-hostname => $o_host,
|
||||
-version => '3',
|
||||
-username => $o_login,
|
||||
-authpassword => $o_passwd,
|
||||
-authprotocol => $o_authproto,
|
||||
-port => $o_port,
|
||||
-timeout => $o_timeout
|
||||
);
|
||||
} else {
|
||||
verb("SNMPv3 AuthPriv login : $o_login, $o_authproto, $o_privproto");
|
||||
($session, $error) = Net::SNMP->session(
|
||||
-hostname => $o_host,
|
||||
-version => '3',
|
||||
-username => $o_login,
|
||||
-authpassword => $o_passwd,
|
||||
-authprotocol => $o_authproto,
|
||||
-privpassword => $o_privpass,
|
||||
-privprotocol => $o_privproto,
|
||||
-port => $o_port,
|
||||
-timeout => $o_timeout
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (defined ($o_version2)) {
|
||||
# SNMPv2 Login
|
||||
verb("SNMP v2c login");
|
||||
($session, $error) = Net::SNMP->session(
|
||||
-hostname => $o_host,
|
||||
-version => 2,
|
||||
-community => $o_community,
|
||||
-port => $o_port,
|
||||
-timeout => $o_timeout
|
||||
);
|
||||
} else {
|
||||
# SNMPV1 login
|
||||
verb("SNMP v1 login");
|
||||
($session, $error) = Net::SNMP->session(
|
||||
-hostname => $o_host,
|
||||
-community => $o_community,
|
||||
-port => $o_port,
|
||||
-timeout => $o_timeout
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!defined($session)) {
|
||||
printf("ERROR: %s.\n", $error);
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
|
||||
if (defined($o_octetlength)) {
|
||||
my $oct_resultat=undef;
|
||||
my $oct_test= $session->max_msg_size();
|
||||
verb(" actual max octets:: $oct_test");
|
||||
$oct_resultat = $session->max_msg_size($o_octetlength);
|
||||
if (!defined($oct_resultat)) {
|
||||
printf("ERROR: Session settings : %s.\n", $session->error);
|
||||
$session->close;
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
$oct_test= $session->max_msg_size();
|
||||
verb(" new max octets:: $oct_test");
|
||||
}
|
||||
|
||||
my $session = Centreon::SNMP::Utils::connection($ERRORS{'UNKNOWN'}, $session_params);
|
||||
my $resultat=undef;
|
||||
my $stype=undef;
|
||||
# Get rid of UTF8 translation in case of accentuated caracters (thanks to Dimo Velev).
|
||||
$session->translate(Net::SNMP->TRANSLATE_NONE);
|
||||
|
||||
if (defined ($o_index)){
|
||||
if (Net::SNMP->VERSION < 4) {
|
||||
$resultat = $session->get_table($index_table);
|
||||
} else {
|
||||
$resultat = $session->get_table(Baseoid => $index_table);
|
||||
}
|
||||
$resultat = Centreon::SNMP::Utils::get_snmp_table($index_table, $session, $ERRORS{'UNKNOWN'}, \%OPTION);
|
||||
} else {
|
||||
if (Net::SNMP->VERSION < 4) {
|
||||
$resultat = $session->get_table($descr_table);
|
||||
} else {
|
||||
$resultat = $session->get_table(Baseoid => $descr_table);
|
||||
}
|
||||
$resultat = Centreon::SNMP::Utils::get_snmp_table($descr_table, $session, $ERRORS{'UNKNOWN'}, \%OPTION);
|
||||
}
|
||||
#get storage typetable for reference
|
||||
if (defined($o_storagetype)){
|
||||
if (Net::SNMP->VERSION < 4) {
|
||||
$stype = $session->get_table($storagetype_table);
|
||||
} else {
|
||||
$stype = $session->get_table(Baseoid => $storagetype_table);
|
||||
}
|
||||
}
|
||||
if (!defined($resultat) | (!defined($stype) && defined($o_storagetype))) {
|
||||
printf("ERROR: Description/Type table : %s.\n", $session->error);
|
||||
$session->close;
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
$stype = Centreon::SNMP::Utils::get_snmp_table($storagetype_table, $session, $ERRORS{'UNKNOWN'}, \%OPTION);
|
||||
}
|
||||
|
||||
my @tindex = undef;
|
||||
|
@ -450,83 +339,64 @@ my $perf_out= undef;
|
|||
verb("Filter : $o_descr");
|
||||
|
||||
foreach my $key ( keys %$resultat) {
|
||||
verb("OID : $key, Desc : $$resultat{$key}");
|
||||
# test by regexp or exact match / include or exclude
|
||||
if (defined($o_negate)) {
|
||||
$test = defined($o_noreg)
|
||||
? $$resultat{$key} ne $o_descr
|
||||
: $$resultat{$key} !~ /$o_descr/;
|
||||
} else {
|
||||
$test = defined($o_noreg)
|
||||
? $$resultat{$key} eq $o_descr
|
||||
: $$resultat{$key} =~ /$o_descr/;
|
||||
}
|
||||
if ($test) {
|
||||
# get the index number of the interface
|
||||
my @oid_list = split (/\./,$key);
|
||||
$tindex[$num_int] = pop (@oid_list);
|
||||
# Check if storage type is OK
|
||||
if (defined($o_storagetype)) {
|
||||
my($skey)=$storagetype_table.".".$tindex[$num_int];
|
||||
verb(" OID : $skey, Storagetype: $hrStorage{$$stype{$skey}} ?= $o_storagetype");
|
||||
if ( $hrStorage{$$stype{$skey}} !~ $o_storagetype) {
|
||||
$test=undef;
|
||||
}
|
||||
}
|
||||
if ($test) {
|
||||
# get the full description
|
||||
$descr[$num_int]=$$resultat{$key};
|
||||
# put the oid in an array
|
||||
$oids[$count_oid++]=$size_table . $tindex[$num_int];
|
||||
$oids[$count_oid++]=$used_table . $tindex[$num_int];
|
||||
$oids[$count_oid++]=$alloc_units . $tindex[$num_int];
|
||||
verb("OID : $key, Desc : $$resultat{$key}");
|
||||
# test by regexp or exact match / include or exclude
|
||||
if (defined($o_negate)) {
|
||||
$test = defined($o_noreg)
|
||||
? $$resultat{$key} ne $o_descr
|
||||
: $$resultat{$key} !~ /$o_descr/;
|
||||
} else {
|
||||
$test = defined($o_noreg)
|
||||
? $$resultat{$key} eq $o_descr
|
||||
: $$resultat{$key} =~ /$o_descr/;
|
||||
}
|
||||
if ($test) {
|
||||
# get the index number of the interface
|
||||
my @oid_list = split (/\./,$key);
|
||||
$tindex[$num_int] = pop (@oid_list);
|
||||
# Check if storage type is OK
|
||||
if (defined($o_storagetype)) {
|
||||
my($skey)=$storagetype_table.".".$tindex[$num_int];
|
||||
verb(" OID : $skey, Storagetype: $hrStorage{$$stype{$skey}} ?= $o_storagetype");
|
||||
if ( $hrStorage{$$stype{$skey}} !~ $o_storagetype) {
|
||||
$test=undef;
|
||||
}
|
||||
}
|
||||
if ($test) {
|
||||
# get the full description
|
||||
$descr[$num_int]=$$resultat{$key};
|
||||
# put the oid in an array
|
||||
$oids[$count_oid++]=$size_table . $tindex[$num_int];
|
||||
$oids[$count_oid++]=$used_table . $tindex[$num_int];
|
||||
$oids[$count_oid++]=$alloc_units . $tindex[$num_int];
|
||||
|
||||
verb(" Name : $descr[$num_int], Index : $tindex[$num_int]");
|
||||
$num_int++;
|
||||
verb(" Name : $descr[$num_int], Index : $tindex[$num_int]");
|
||||
$num_int++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
verb("storages selected : $num_int");
|
||||
if ( $num_int == 0 ) { print "Unknown storage : $o_descr : ERROR\n" ; exit $ERRORS{"UNKNOWN"};}
|
||||
|
||||
my $result=undef;
|
||||
|
||||
if (Net::SNMP->VERSION < 4) {
|
||||
$result = $session->get_request(@oids);
|
||||
} else {
|
||||
if ($session->version == 0) {
|
||||
# snmpv1
|
||||
$result = $session->get_request(Varbindlist => \@oids);
|
||||
} else {
|
||||
# snmp v2c or v3 : get_bulk_request is not really good for this, so do simple get
|
||||
$result = $session->get_request(Varbindlist => \@oids);
|
||||
foreach my $key ( keys %$result) { verb("$key : $$result{$key}"); }
|
||||
}
|
||||
}
|
||||
|
||||
if (!defined($result)) { printf("ERROR: Size table :%s.\n", $session->error); $session->close;
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
|
||||
$session->close;
|
||||
my $result = Centreon::SNMP::Utils::get_snmp_leef(\@oids, $session, $ERRORS{'UNKNOWN'});
|
||||
|
||||
# Only a few ms left...
|
||||
alarm(0);
|
||||
|
||||
# Sum everything if -s and more than one storage
|
||||
if ( defined ($o_sum) && ($num_int > 1) ) {
|
||||
verb("Adding all entries");
|
||||
$$result{$size_table . $tindex[0]} *= $$result{$alloc_units . $tindex[0]};
|
||||
$$result{$used_table . $tindex[0]} *= $$result{$alloc_units . $tindex[0]};
|
||||
$$result{$alloc_units . $tindex[0]} = 1;
|
||||
for (my $i=1;$i<$num_int;$i++) {
|
||||
$$result{$size_table . $tindex[0]} += ($$result{$size_table . $tindex[$i]}
|
||||
* $$result{$alloc_units . $tindex[$i]});
|
||||
$$result{$used_table . $tindex[0]} += ($$result{$used_table . $tindex[$i]}
|
||||
* $$result{$alloc_units . $tindex[$i]});
|
||||
}
|
||||
$num_int=1;
|
||||
$descr[0]="Sum of all $o_descr";
|
||||
verb("Adding all entries");
|
||||
$$result{$size_table . $tindex[0]} *= $$result{$alloc_units . $tindex[0]};
|
||||
$$result{$used_table . $tindex[0]} *= $$result{$alloc_units . $tindex[0]};
|
||||
$$result{$alloc_units . $tindex[0]} = 1;
|
||||
for (my $i=1;$i<$num_int;$i++) {
|
||||
$$result{$size_table . $tindex[0]} += ($$result{$size_table . $tindex[$i]}
|
||||
* $$result{$alloc_units . $tindex[$i]});
|
||||
$$result{$used_table . $tindex[0]} += ($$result{$used_table . $tindex[$i]}
|
||||
* $$result{$alloc_units . $tindex[$i]});
|
||||
}
|
||||
$num_int=1;
|
||||
$descr[0]="Sum of all $o_descr";
|
||||
}
|
||||
|
||||
my $i=undef;
|
||||
|
@ -538,93 +408,93 @@ my $output_metric_val = 1024**2;
|
|||
my $output_metric = "M";
|
||||
# Set the metric
|
||||
if (defined($o_giga)) {
|
||||
$output_metric_val *= 1024;
|
||||
$output_metric='G';
|
||||
$output_metric_val *= 1024;
|
||||
$output_metric='G';
|
||||
}
|
||||
|
||||
for ($i=0;$i<$num_int;$i++) {
|
||||
verb("Descr : $descr[$i]");
|
||||
verb("Size : $$result{$size_table . $tindex[$i]}");
|
||||
verb("Used : $$result{$used_table . $tindex[$i]}");
|
||||
verb("Alloc : $$result{$alloc_units . $tindex[$i]}");
|
||||
if (!defined($$result{$size_table . $tindex[$i]}) ||
|
||||
!defined($$result{$used_table . $tindex[$i]}) ||
|
||||
!defined ($$result{$alloc_units . $tindex[$i]})) {
|
||||
print "Data not fully defined for storage ",$descr[$i]," : UNKNOWN\n";
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
my $to = $$result{$size_table . $tindex[$i]} * ( ( 100 - $o_reserve ) / 100 ) * $$result{$alloc_units . $tindex[$i]} / $output_metric_val;
|
||||
my $pu=undef;
|
||||
if ( $$result{$used_table . $tindex[$i]} != 0 ) {
|
||||
$pu = $$result{$used_table . $tindex[$i]}* 100 / ( $$result{$size_table . $tindex[$i]} * ( 100 - $o_reserve ) / 100 );
|
||||
}else {
|
||||
$pu=0;
|
||||
}
|
||||
my $bu = $$result{$used_table . $tindex[$i]} * $$result{$alloc_units . $tindex[$i]} / $output_metric_val;
|
||||
my $pl = 100 - $pu;
|
||||
my $bl = ( ( $$result{$size_table . $tindex[$i]} * ( ( 100 - $o_reserve ) / 100 ) - ( $$result{$used_table . $tindex[$i]} ) ) * $$result{$alloc_units . $tindex[$i]} / $output_metric_val );
|
||||
# add a ' ' if some data exists in $perf_out
|
||||
$perf_out .= " " if (defined ($perf_out)) ;
|
||||
##### Ouputs and checks
|
||||
# Keep complete description fot performance output (in MB)
|
||||
my $Pdescr=$descr[$i];
|
||||
$Pdescr =~ s/[`~!\$%\^&\*'"<>|\?,\(= )]/_/g;
|
||||
##### TODO : subs "," with something
|
||||
if (defined($o_shortL[2])) {
|
||||
if ($o_shortL[2] < 0) {$descr[$i]=substr($descr[$i],$o_shortL[2]);}
|
||||
else {$descr[$i]=substr($descr[$i],0,$o_shortL[2]);}
|
||||
}
|
||||
if ($o_type eq "pu") { # Checks % used
|
||||
my $locstate=0;
|
||||
$p_warn=$o_warn*$to/100;$p_crit=$o_crit*$to/100;
|
||||
verb("Descr : $descr[$i]");
|
||||
verb("Size : $$result{$size_table . $tindex[$i]}");
|
||||
verb("Used : $$result{$used_table . $tindex[$i]}");
|
||||
verb("Alloc : $$result{$alloc_units . $tindex[$i]}");
|
||||
if (!defined($$result{$size_table . $tindex[$i]}) ||
|
||||
!defined($$result{$used_table . $tindex[$i]}) ||
|
||||
!defined ($$result{$alloc_units . $tindex[$i]})) {
|
||||
print "Data not fully defined for storage ",$descr[$i]," : UNKNOWN\n";
|
||||
exit $ERRORS{"UNKNOWN"};
|
||||
}
|
||||
my $to = $$result{$size_table . $tindex[$i]} * ( ( 100 - $o_reserve ) / 100 ) * $$result{$alloc_units . $tindex[$i]} / $output_metric_val;
|
||||
my $pu=undef;
|
||||
if ( $$result{$used_table . $tindex[$i]} != 0 ) {
|
||||
$pu = $$result{$used_table . $tindex[$i]}* 100 / ( $$result{$size_table . $tindex[$i]} * ( 100 - $o_reserve ) / 100 );
|
||||
}else {
|
||||
$pu=0;
|
||||
}
|
||||
my $bu = $$result{$used_table . $tindex[$i]} * $$result{$alloc_units . $tindex[$i]} / $output_metric_val;
|
||||
my $pl = 100 - $pu;
|
||||
my $bl = ( ( $$result{$size_table . $tindex[$i]} * ( ( 100 - $o_reserve ) / 100 ) - ( $$result{$used_table . $tindex[$i]} ) ) * $$result{$alloc_units . $tindex[$i]} / $output_metric_val );
|
||||
# add a ' ' if some data exists in $perf_out
|
||||
$perf_out .= " " if (defined ($perf_out)) ;
|
||||
##### Ouputs and checks
|
||||
# Keep complete description fot performance output (in MB)
|
||||
my $Pdescr=$descr[$i];
|
||||
$Pdescr =~ s/[`~!\$%\^&\*'"<>|\?,\(= )]/_/g;
|
||||
##### TODO : subs "," with something
|
||||
if (defined($o_shortL[2])) {
|
||||
if ($o_shortL[2] < 0) {$descr[$i]=substr($descr[$i],$o_shortL[2]);}
|
||||
else {$descr[$i]=substr($descr[$i],0,$o_shortL[2]);}
|
||||
}
|
||||
if ($o_type eq "pu") { # Checks % used
|
||||
my $locstate=0;
|
||||
$p_warn=$o_warn*$to/100;$p_crit=$o_crit*$to/100;
|
||||
(($pu >= $o_crit) && ($locstate=$crit_state=1))
|
||||
|| (($pu >= $o_warn) && ($locstate=$warn_state=1));
|
||||
if (defined($o_shortL[2])) {}
|
||||
if (!defined($o_shortL[0]) || ($locstate==1)) { # print full output if warn or critical state
|
||||
$output.=sprintf ("%s: %.0f%%used(%.0f%sB/%.0f%sB) ",$descr[$i],$pu,$bu,$output_metric,$to,$output_metric);
|
||||
} elsif ($o_shortL[0] == 1) {
|
||||
$output.=sprintf ("%s: %.0f%% ",$descr[$i],$pu);
|
||||
}
|
||||
}
|
||||
|
||||
if ($o_type eq 'bu') { # Checks MBytes used
|
||||
my $locstate=0;
|
||||
$p_warn=$o_warn;$p_crit=$o_crit;
|
||||
( ($bu >= $o_crit) && ($locstate=$crit_state=1) )
|
||||
|| ( ($bu >= $o_warn) && ($locstate=$warn_state=1) );
|
||||
if (!defined($o_shortL[0]) || ($locstate==1)) { # print full output if warn or critical state
|
||||
$output.=sprintf("%s: %.0f%sBused/%.0f%sB (%.0f%%) ",$descr[$i],$bu,$output_metric,$to,$output_metric,$pu);
|
||||
} elsif ($o_shortL[0] == 1) {
|
||||
$output.=sprintf("%s: %.0f%sB ",$descr[$i],$bu,$output_metric);
|
||||
}
|
||||
}
|
||||
|
||||
if ($o_type eq 'bl') {
|
||||
my $locstate=0;
|
||||
$p_warn=$to-$o_warn;$p_crit=$to-$o_crit;
|
||||
( ($bl <= $o_crit) && ($locstate=$crit_state=1) )
|
||||
|| ( ($bl <= $o_warn) && ($locstate=$warn_state=1) );
|
||||
if (!defined($o_shortL[0]) || ($locstate==1)) { # print full output if warn or critical state
|
||||
$output.=sprintf ("%s: %.0f%sBleft/%.0f%sB (%.0f%%) ",$descr[$i],$bl,$output_metric,$to,$output_metric,$pl);
|
||||
} elsif ($o_shortL[0] == 1) {
|
||||
$output.=sprintf ("%s: %.0f%sB ",$descr[$i],$bl,$output_metric);
|
||||
}
|
||||
}
|
||||
|
||||
if ($o_type eq 'pl') {
|
||||
my $locstate=0;
|
||||
$p_warn=(100-$o_warn)*$to/100;$p_crit=(100-$o_crit)*$to/100;
|
||||
( ($pl <= $o_crit) && ($locstate=$crit_state=1) )
|
||||
|| ( ($pl <= $o_warn) && ($locstate=$warn_state=1) );
|
||||
if (!defined($o_shortL[0]) || ($locstate==1)) { # print full output if warn or critical state
|
||||
$output.=sprintf ("%s: %.0f%%left(%.0f%sB/%.0f%sB) ",$descr[$i],$pl,$bl,$output_metric,$to,$output_metric);
|
||||
} elsif ($o_shortL[0] == 1) {
|
||||
$output.=sprintf ("%s: %.0f%% ",$descr[$i],$pl);
|
||||
}
|
||||
}
|
||||
# Performance output (in MB)
|
||||
$perf_out .= "'".$Pdescr. "'=" . round($bu,0) . $output_metric ."B;" . round($p_warn,0)
|
||||
. ";" . round($p_crit,0) . ";0;" . round($to,0);
|
||||
|| (($pu >= $o_warn) && ($locstate=$warn_state=1));
|
||||
if (defined($o_shortL[2])) {}
|
||||
if (!defined($o_shortL[0]) || ($locstate==1)) { # print full output if warn or critical state
|
||||
$output.=sprintf ("%s: %.0f%%used(%.0f%sB/%.0f%sB) ",$descr[$i],$pu,$bu,$output_metric,$to,$output_metric);
|
||||
} elsif ($o_shortL[0] == 1) {
|
||||
$output.=sprintf ("%s: %.0f%% ",$descr[$i],$pu);
|
||||
}
|
||||
}
|
||||
|
||||
if ($o_type eq 'bu') { # Checks MBytes used
|
||||
my $locstate=0;
|
||||
$p_warn=$o_warn;$p_crit=$o_crit;
|
||||
( ($bu >= $o_crit) && ($locstate=$crit_state=1) )
|
||||
|| ( ($bu >= $o_warn) && ($locstate=$warn_state=1) );
|
||||
if (!defined($o_shortL[0]) || ($locstate==1)) { # print full output if warn or critical state
|
||||
$output.=sprintf("%s: %.0f%sBused/%.0f%sB (%.0f%%) ",$descr[$i],$bu,$output_metric,$to,$output_metric,$pu);
|
||||
} elsif ($o_shortL[0] == 1) {
|
||||
$output.=sprintf("%s: %.0f%sB ",$descr[$i],$bu,$output_metric);
|
||||
}
|
||||
}
|
||||
|
||||
if ($o_type eq 'bl') {
|
||||
my $locstate=0;
|
||||
$p_warn=$to-$o_warn;$p_crit=$to-$o_crit;
|
||||
( ($bl <= $o_crit) && ($locstate=$crit_state=1) )
|
||||
|| ( ($bl <= $o_warn) && ($locstate=$warn_state=1) );
|
||||
if (!defined($o_shortL[0]) || ($locstate==1)) { # print full output if warn or critical state
|
||||
$output.=sprintf ("%s: %.0f%sBleft/%.0f%sB (%.0f%%) ",$descr[$i],$bl,$output_metric,$to,$output_metric,$pl);
|
||||
} elsif ($o_shortL[0] == 1) {
|
||||
$output.=sprintf ("%s: %.0f%sB ",$descr[$i],$bl,$output_metric);
|
||||
}
|
||||
}
|
||||
|
||||
if ($o_type eq 'pl') {
|
||||
my $locstate=0;
|
||||
$p_warn=(100-$o_warn)*$to/100;$p_crit=(100-$o_crit)*$to/100;
|
||||
( ($pl <= $o_crit) && ($locstate=$crit_state=1) )
|
||||
|| ( ($pl <= $o_warn) && ($locstate=$warn_state=1) );
|
||||
if (!defined($o_shortL[0]) || ($locstate==1)) { # print full output if warn or critical state
|
||||
$output.=sprintf ("%s: %.0f%%left(%.0f%sB/%.0f%sB) ",$descr[$i],$pl,$bl,$output_metric,$to,$output_metric);
|
||||
} elsif ($o_shortL[0] == 1) {
|
||||
$output.=sprintf ("%s: %.0f%% ",$descr[$i],$pl);
|
||||
}
|
||||
}
|
||||
# Performance output (in MB)
|
||||
$perf_out .= "'".$Pdescr. "'=" . round($bu,0) . $output_metric ."B;" . round($p_warn,0)
|
||||
. ";" . round($p_crit,0) . ";0;" . round($to,0);
|
||||
}
|
||||
|
||||
verb ("Perf data : $perf_out");
|
||||
|
@ -641,27 +511,27 @@ if (!defined ($output)) { $output="All selected storages "; }
|
|||
if ( $crit_state == 1) {
|
||||
$comp_oper = ($comp_oper eq "<") ? ">" : "<"; # Inverse comp operator
|
||||
if (defined($o_shortL[1])) {
|
||||
print "CRITICAL : (",$comp_oper,$o_crit,$comp_unit,") ",$output;
|
||||
} else {
|
||||
print $output,"(",$comp_oper,$o_crit,$comp_unit,") : CRITICAL";
|
||||
}
|
||||
(defined($o_perf)) ? print " | ",$perf_out,"\n" : print "\n";
|
||||
exit $ERRORS{"CRITICAL"};
|
||||
print "CRITICAL : (",$comp_oper,$o_crit,$comp_unit,") ",$output;
|
||||
} else {
|
||||
print $output,"(",$comp_oper,$o_crit,$comp_unit,") : CRITICAL";
|
||||
}
|
||||
(defined($o_perf)) ? print " | ",$perf_out,"\n" : print "\n";
|
||||
exit $ERRORS{"CRITICAL"};
|
||||
}
|
||||
if ( $warn_state == 1) {
|
||||
$comp_oper = ($comp_oper eq "<") ? ">" : "<"; # Inverse comp operator
|
||||
if (defined($o_shortL[1])) {
|
||||
print "WARNING : (",$comp_oper,$o_warn,$comp_unit,") ",$output;
|
||||
} else {
|
||||
print $output,"(",$comp_oper,$o_warn,$comp_unit,") : WARNING";
|
||||
}
|
||||
(defined($o_perf)) ? print " | ",$perf_out,"\n" : print "\n";
|
||||
exit $ERRORS{"WARNING"};
|
||||
}
|
||||
print "WARNING : (",$comp_oper,$o_warn,$comp_unit,") ",$output;
|
||||
} else {
|
||||
print $output,"(",$comp_oper,$o_warn,$comp_unit,") : WARNING";
|
||||
}
|
||||
(defined($o_perf)) ? print " | ",$perf_out,"\n" : print "\n";
|
||||
exit $ERRORS{"WARNING"};
|
||||
}
|
||||
if (defined($o_shortL[1])) {
|
||||
print "OK : (",$comp_oper,$o_warn,$comp_unit,") ",$output;
|
||||
print "OK : (",$comp_oper,$o_warn,$comp_unit,") ",$output;
|
||||
} else {
|
||||
print $output,"(",$comp_oper,$o_warn,$comp_unit,") : OK";
|
||||
print $output,"(",$comp_oper,$o_warn,$comp_unit,") : OK";
|
||||
}
|
||||
(defined($o_perf)) ? print " | ",$perf_out,"\n" : print "\n";
|
||||
|
||||
|
|
Loading…
Reference in New Issue