snmp V3
git-svn-id: http://svn.centreon.com/Plugins/Dev@2364 6bcd3966-0018-0410-8128-fd23d134de7e
This commit is contained in:
parent
b697eaba99
commit
1bbd7380c3
|
@ -40,7 +40,7 @@ if (eval "require oreon" ) {
|
|||
}
|
||||
use vars qw($PROGNAME);
|
||||
use Getopt::Long;
|
||||
use vars qw($opt_V $opt_h $opt_v $opt_C $opt_H $opt_D $snmp);
|
||||
use vars qw($opt_V $opt_h $opt_v $opt_C $opt_H $opt_D $snmp $opt_k $opt_u $opt_p);
|
||||
|
||||
# Plugin var init
|
||||
|
||||
|
@ -53,6 +53,9 @@ sub print_usage ();
|
|||
Getopt::Long::Configure('bundling');
|
||||
GetOptions
|
||||
("h" => \$opt_h, "help" => \$opt_h,
|
||||
"u=s" => \$opt_u, "username=s" => \$opt_u,
|
||||
"p=s" => \$opt_p, "password=s" => \$opt_p,
|
||||
"k=s" => \$opt_k, "key=s" => \$opt_k,
|
||||
"V" => \$opt_V, "version" => \$opt_V,
|
||||
"v=s" => \$opt_v, "snmp=s" => \$opt_v,
|
||||
"C=s" => \$opt_C, "community=s" => \$opt_C,
|
||||
|
@ -72,11 +75,26 @@ if (!$opt_H) {
|
|||
print_usage();
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
|
||||
my $snmp = "1";
|
||||
if ($opt_v && $opt_v =~ /(\d)/) {
|
||||
if ($opt_v && $opt_v =~ /^[0-9]$/) {
|
||||
$snmp = $opt_v;
|
||||
}
|
||||
|
||||
if ($snmp eq "3") {
|
||||
if (!$opt_u) {
|
||||
print "Option -u (--username) is required for snmpV3\n";
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
if (!$opt_p && !$opt_k) {
|
||||
print "Option -k (--key) or -p (--password) is required for snmpV3\n";
|
||||
exit $ERRORS{'OK'};
|
||||
}elsif ($opt_p && $opt_k) {
|
||||
print "Only option -k (--key) or -p (--password) is needed for snmpV3\n";
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
}
|
||||
|
||||
if (!$opt_C) {
|
||||
$opt_C = "public";
|
||||
}
|
||||
|
@ -92,11 +110,26 @@ my $OID_CPULOAD_1 =$oreon{UNIX}{CPU_LOAD_1M};
|
|||
my $OID_CPULOAD_5 =$oreon{UNIX}{CPU_LOAD_5M};
|
||||
my $OID_CPULOAD_15 =$oreon{UNIX}{CPU_LOAD_15M};
|
||||
|
||||
my ( $session, $error ) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp);
|
||||
if ( !defined($session) ) {
|
||||
print("UNKNOWN: $error");
|
||||
my ($session, $error);
|
||||
if ($snmp eq "1" || $snmp eq "2") {
|
||||
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp);
|
||||
if (!defined($session)) {
|
||||
print("UNKNOWN: SNMP Session : $error\n");
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
}elsif ($opt_k) {
|
||||
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k);
|
||||
if (!defined($session)) {
|
||||
print("UNKNOWN: SNMP Session : $error\n");
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
}elsif ($opt_p) {
|
||||
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authpassword => $opt_p);
|
||||
if (!defined($session)) {
|
||||
print("UNKNOWN: SNMP Session : $error\n");
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
}
|
||||
|
||||
my $result = $session->get_request(
|
||||
-varbindlist => [$OID_CPULOAD_1, $OID_CPULOAD_5, $OID_CPULOAD_15 ]
|
||||
|
|
|
@ -41,7 +41,7 @@ if (eval "require oreon" ) {
|
|||
|
||||
use vars qw($PROGNAME);
|
||||
use Getopt::Long;
|
||||
use vars qw($opt_V $opt_h $opt_v $opt_C $opt_p $opt_H $opt_n $result @result %process_list %STATUS);
|
||||
use vars qw($opt_V $opt_h $opt_v $opt_C $opt_p $opt_H $opt_n $opt_k $opt_u $opt_x $result @result %process_list %STATUS);
|
||||
|
||||
# Plugin var init
|
||||
|
||||
|
@ -51,12 +51,14 @@ $PROGNAME = "check_graph_process";
|
|||
sub print_help ();
|
||||
sub print_usage ();
|
||||
|
||||
|
||||
%STATUS=(1=>'running',2=>'runnable',3=>'notRunnable',4=>'invalid');
|
||||
|
||||
Getopt::Long::Configure('bundling');
|
||||
GetOptions
|
||||
("h" => \$opt_h, "help" => \$opt_h,
|
||||
"u=s" => \$opt_u, "username=s" => \$opt_u,
|
||||
"x=s" => \$opt_x, "password=s" => \$opt_x,
|
||||
"k=s" => \$opt_k, "key=s" => \$opt_k,
|
||||
"V" => \$opt_V, "version" => \$opt_V,
|
||||
"n" => \$opt_n, "number" => \$opt_n,
|
||||
"v=s" => \$opt_v, "snmp=s" => \$opt_v,
|
||||
|
@ -79,9 +81,24 @@ print_usage();
|
|||
exit $ERRORS{'OK'};
|
||||
}
|
||||
my $snmp = "1";
|
||||
if ($opt_v && $opt_v =~ /(\d)/) {
|
||||
if ($opt_v && $opt_v =~ /^[0-9]$/) {
|
||||
$snmp = $opt_v;
|
||||
}
|
||||
|
||||
if ($snmp eq "3") {
|
||||
if (!$opt_u) {
|
||||
print "Option -u (--username) is required for snmpV3\n";
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
if (!$opt_x && !$opt_k) {
|
||||
print "Option -k (--key) or -x (--password) is required for snmpV3\n";
|
||||
exit $ERRORS{'OK'};
|
||||
}elsif ($opt_x && $opt_k) {
|
||||
print "Only option -k (--key) or -x (--password) is needed for snmpV3\n";
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
}
|
||||
|
||||
if (!$opt_C) {
|
||||
$opt_C = "public";
|
||||
}
|
||||
|
@ -104,11 +121,26 @@ my $OID_SW_RunName = $oreon{MIB2}{SW_RUNNAME};
|
|||
my $OID_SW_RunIndex =$oreon{MIB2}{SW_RUNINDEX};
|
||||
my $OID_SW_RunStatus =$oreon{MIB2}{SW_RUNSTATUS};
|
||||
|
||||
my ( $session, $error ) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp);
|
||||
if ( !defined($session) ) {
|
||||
print("UNKNOWN: $error");
|
||||
my ($session, $error);
|
||||
if ($snmp eq "1" || $snmp eq "2") {
|
||||
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp);
|
||||
if (!defined($session)) {
|
||||
print("UNKNOWN: SNMP Session : $error\n");
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
}elsif ($opt_k) {
|
||||
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k);
|
||||
if (!defined($session)) {
|
||||
print("UNKNOWN: SNMP Session : $error\n");
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
}elsif ($opt_x) {
|
||||
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authpassword => $opt_x);
|
||||
if (!defined($session)) {
|
||||
print("UNKNOWN: SNMP Session : $error\n");
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
}
|
||||
|
||||
$result = $session->get_table(Baseoid => $OID_SW_RunName);
|
||||
if (!defined($result)) {
|
||||
|
|
|
@ -40,7 +40,7 @@ if (eval "require oreon" ) {
|
|||
}
|
||||
use vars qw($PROGNAME);
|
||||
use Getopt::Long;
|
||||
use vars qw($opt_V $opt_h $opt_v $opt_f $opt_C $opt_d $opt_n $opt_w $opt_c $opt_H $opt_s @test);
|
||||
use vars qw($opt_V $opt_h $opt_v $opt_f $opt_C $opt_d $opt_k $opt_u $opt_p $opt_n $opt_w $opt_c $opt_H $opt_s @test);
|
||||
|
||||
# Plugin var init
|
||||
|
||||
|
@ -55,6 +55,9 @@ sub print_usage ();
|
|||
Getopt::Long::Configure('bundling');
|
||||
GetOptions
|
||||
("h" => \$opt_h, "help" => \$opt_h,
|
||||
"u=s" => \$opt_u, "username=s" => \$opt_u,
|
||||
"p=s" => \$opt_p, "password=s" => \$opt_p,
|
||||
"k=s" => \$opt_k, "key=s" => \$opt_k,
|
||||
"V" => \$opt_V, "version" => \$opt_V,
|
||||
"s" => \$opt_s, "show" => \$opt_s,
|
||||
"v=s" => \$opt_v, "snmp=s" => \$opt_v,
|
||||
|
@ -86,10 +89,24 @@ if ($opt_n && !$opt_d) {
|
|||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
my $snmp = "1";
|
||||
if ($opt_v && $opt_v =~ /(\d)/) {
|
||||
if ($opt_v && $opt_v =~ /^[0-9]$/) {
|
||||
$snmp = $opt_v;
|
||||
}
|
||||
|
||||
if ($snmp eq "3") {
|
||||
if (!$opt_u) {
|
||||
print "Option -u (--username) is required for snmpV3\n";
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
if (!$opt_p && !$opt_k) {
|
||||
print "Option -k (--key) or -p (--password) is required for snmpV3\n";
|
||||
exit $ERRORS{'OK'};
|
||||
}elsif ($opt_p && $opt_k) {
|
||||
print "Only option -k (--key) or -p (--password) is needed for snmpV3\n";
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
}
|
||||
|
||||
if (!$opt_C) {
|
||||
$opt_C = "public";
|
||||
}
|
||||
|
@ -133,10 +150,25 @@ my $OID_hrStorageSize =$oreon{MIB2}{HR_STORAGE_SIZE};
|
|||
my $OID_hrStorageUsed =$oreon{MIB2}{HR_STORAGE_USED};
|
||||
|
||||
# create a SNMP session
|
||||
my ( $session, $error ) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp);
|
||||
if ( !defined($session) ) {
|
||||
print("CRITICAL: SNMP Session : $error");
|
||||
exit $ERRORS{'CRITICAL'};
|
||||
my ($session, $error);
|
||||
if ($snmp eq "1" || $snmp eq "2") {
|
||||
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp);
|
||||
if (!defined($session)) {
|
||||
print("UNKNOWN: SNMP Session : $error\n");
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
}elsif ($opt_k) {
|
||||
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k);
|
||||
if (!defined($session)) {
|
||||
print("UNKNOWN: SNMP Session : $error\n");
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
}elsif ($opt_p) {
|
||||
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authpassword => $opt_p);
|
||||
if (!defined($session)) {
|
||||
print("UNKNOWN: SNMP Session : $error\n");
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
}
|
||||
|
||||
#getting partition using its name instead of its oid index
|
||||
|
|
|
@ -40,7 +40,7 @@ if (eval "require oreon" ) {
|
|||
}
|
||||
use vars qw($PROGNAME);
|
||||
use Getopt::Long;
|
||||
use vars qw($opt_V $opt_h $opt_v $opt_C $opt_b $opt_H $opt_D $opt_i $opt_n $opt_w $opt_c $opt_s $opt_T);
|
||||
use vars qw($opt_V $opt_h $opt_v $opt_C $opt_b $opt_k $opt_u $opt_p $opt_H $opt_D $opt_i $opt_n $opt_w $opt_c $opt_s $opt_T);
|
||||
|
||||
# Plugin var init
|
||||
|
||||
|
@ -53,6 +53,9 @@ sub print_usage ();
|
|||
Getopt::Long::Configure('bundling');
|
||||
GetOptions
|
||||
("h" => \$opt_h, "help" => \$opt_h,
|
||||
"u=s" => \$opt_u, "username=s" => \$opt_u,
|
||||
"p=s" => \$opt_p, "password=s" => \$opt_p,
|
||||
"k=s" => \$opt_k, "key=s" => \$opt_k,
|
||||
"s" => \$opt_s, "show" => \$opt_s,
|
||||
"V" => \$opt_V, "version" => \$opt_V,
|
||||
"i=s" => \$opt_i, "interface=s" => \$opt_i,
|
||||
|
@ -73,6 +76,8 @@ if ($opt_V) {
|
|||
if ($opt_h) {
|
||||
print_help();
|
||||
exit $ERRORS{'OK'};
|
||||
|
||||
Getopt::Long::Configure('bundling');
|
||||
}
|
||||
|
||||
##################################################
|
||||
|
@ -84,10 +89,24 @@ print_usage();
|
|||
exit $ERRORS{'OK'};
|
||||
}
|
||||
my $snmp = "1";
|
||||
if ($opt_v && $opt_v =~ /(\d)/) {
|
||||
if ($opt_v && $opt_v =~ /^[0-9]$/) {
|
||||
$snmp = $opt_v;
|
||||
}
|
||||
|
||||
if ($snmp eq "3") {
|
||||
if (!$opt_u) {
|
||||
print "Option -u (--username) is required for snmpV3\n";
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
if (!$opt_p && !$opt_k) {
|
||||
print "Option -k (--key) or -p (--password) is required for snmpV3\n";
|
||||
exit $ERRORS{'OK'};
|
||||
}elsif ($opt_p && $opt_k) {
|
||||
print "Only option -k (--key) or -p (--password) is needed for snmpV3\n";
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
}
|
||||
|
||||
if ($opt_n && !$opt_i) {
|
||||
print "Option -n (--name) need option -i (--interface)\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
|
@ -137,12 +156,26 @@ if ($critical <= $warning){
|
|||
my $OID_DESC =$oreon{MIB2}{IF_DESC};
|
||||
|
||||
# create a SNMP session
|
||||
|
||||
my ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp);
|
||||
my ($session, $error);
|
||||
if ($snmp eq "1" || $snmp eq "2") {
|
||||
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp);
|
||||
if (!defined($session)) {
|
||||
print("UNKNOWN: SNMP Session : $error");
|
||||
print("UNKNOWN: SNMP Session : $error\n");
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
}elsif ($opt_k) {
|
||||
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k);
|
||||
if (!defined($session)) {
|
||||
print("UNKNOWN: SNMP Session : $error\n");
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
}elsif ($opt_p) {
|
||||
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authpassword => $opt_p);
|
||||
if (!defined($session)) {
|
||||
print("UNKNOWN: SNMP Session : $error\n");
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
}
|
||||
|
||||
#getting interface using its name instead of its oid index
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ use utils qw($TIMEOUT %ERRORS &print_revision &support);
|
|||
|
||||
use vars qw($PROGNAME);
|
||||
use Getopt::Long;
|
||||
use vars qw($opt_h $opt_V $opt_H $opt_C $opt_v $opt_o $opt_c $opt_w $opt_t);
|
||||
use vars qw($opt_h $opt_V $opt_H $opt_C $opt_v $opt_o $opt_c $opt_w $opt_t $opt_p $opt_k $opt_u);
|
||||
|
||||
$PROGNAME = $0;
|
||||
sub print_help ();
|
||||
|
@ -42,11 +42,14 @@ sub print_usage ();
|
|||
Getopt::Long::Configure('bundling');
|
||||
GetOptions
|
||||
("h" => \$opt_h, "help" => \$opt_h,
|
||||
"u=s" => \$opt_u, "username=s" => \$opt_u,
|
||||
"p=s" => \$opt_p, "password=s" => \$opt_p,
|
||||
"k=s" => \$opt_k, "key=s" => \$opt_k,
|
||||
"V" => \$opt_V, "version" => \$opt_V,
|
||||
"v=s" => \$opt_v, "snmp=s" => \$opt_v,
|
||||
"C=s" => \$opt_C, "community=s" => \$opt_C,
|
||||
"o=s" => \$opt_o, "oid=s" => \$opt_o,
|
||||
"t=s" => \$opt_t, "type=s" => \$opt_t,
|
||||
"o=s" => \$opt_o, "oid=s" => \$opt_o,
|
||||
"t=s" => \$opt_t, "type=s" => \$opt_t,
|
||||
"w=s" => \$opt_w, "warning=s" => \$opt_w,
|
||||
"c=s" => \$opt_c, "critical=s" => \$opt_c,
|
||||
"H=s" => \$opt_H, "hostname=s" => \$opt_H);
|
||||
|
@ -66,7 +69,21 @@ $opt_H = shift unless ($opt_H);
|
|||
|
||||
my $snmp = "1";
|
||||
if ($opt_v && $opt_v =~ /^[0-9]$/) {
|
||||
$snmp = $opt_v;
|
||||
$snmp = $opt_v;
|
||||
}
|
||||
|
||||
if ($snmp eq "3") {
|
||||
if (!$opt_u) {
|
||||
print "Option -u (--username) is required for snmpV3\n";
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
if (!$opt_p && !$opt_k) {
|
||||
print "Option -k (--key) or -p (--password) is required for snmpV3\n";
|
||||
exit $ERRORS{'OK'};
|
||||
}elsif ($opt_p && $opt_k) {
|
||||
print "Only option -k (--key) or -p (--password) is needed for snmpV3\n";
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
}
|
||||
|
||||
($opt_C) || ($opt_C = shift) || ($opt_C = "public");
|
||||
|
@ -105,10 +122,25 @@ my $day = 0;
|
|||
|
||||
#=== create a SNMP session ====
|
||||
|
||||
my ($session, $error) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp);
|
||||
my ($session, $error);
|
||||
if ($snmp eq "1" || $snmp eq "2") {
|
||||
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp);
|
||||
if (!defined($session)) {
|
||||
print("CRITICAL: $error");
|
||||
exit $ERRORS{'CRITICAL'};
|
||||
print("UNKNOWN: SNMP Session : $error\n");
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
}elsif ($opt_k) {
|
||||
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k);
|
||||
if (!defined($session)) {
|
||||
print("UNKNOWN: SNMP Session : $error\n");
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
}elsif ($opt_p) {
|
||||
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authpassword => $opt_p);
|
||||
if (!defined($session)) {
|
||||
print("UNKNOWN: SNMP Session : $error\n");
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
}
|
||||
|
||||
my $result = $session->get_request(-varbindlist => [$opt_o]);
|
||||
|
@ -123,6 +155,10 @@ my $return_result = $result->{$opt_o};
|
|||
#=== Plugin return code ====
|
||||
|
||||
if (defined($return_result)){
|
||||
if ($return_result !~ /^[0-9]$/) {
|
||||
print "Snmp return value isn't numeric.\n";
|
||||
exit $ERRORS{'OK'};
|
||||
}
|
||||
if ($opt_w && $opt_c && $return_result < $opt_w){
|
||||
print "Ok value : " . $return_result . "|value=".$return_result.";".$opt_w.";".$opt_c.";;\n";
|
||||
exit $ERRORS{'OK'};
|
||||
|
|
Loading…
Reference in New Issue