summaryrefslogtreecommitdiffstats
path: root/plugins-scripts
diff options
context:
space:
mode:
authorMatthias Eble <psychotrahe@gmx.de>2009-06-11 02:29:13 +0200
committerMatthias Eble <psychotrahe@gmx.de>2009-06-11 02:29:13 +0200
commit8b8a30716a85206941d96b1a40b5966432a0ddb0 (patch)
tree6a28aabf9ca0f781d020667355a5c086076a44a7 /plugins-scripts
parent08deb7470450627eb669d10e5359b7c36ac3f848 (diff)
downloadmonitoring-plugins-8b8a30716a85206941d96b1a40b5966432a0ddb0.tar.gz
check_ifoperstatus is now more user friendly in case of missing arguments
Added proper usage messages in case of missing arguments. Removed accidently committed Data::Dumper call. Minor whitespace fixes.
Diffstat (limited to 'plugins-scripts')
-rwxr-xr-xplugins-scripts/check_ifoperstatus.pl54
1 files changed, 25 insertions, 29 deletions
diff --git a/plugins-scripts/check_ifoperstatus.pl b/plugins-scripts/check_ifoperstatus.pl
index 88782f52..e137e7fd 100755
--- a/plugins-scripts/check_ifoperstatus.pl
+++ b/plugins-scripts/check_ifoperstatus.pl
@@ -43,18 +43,19 @@ use Getopt::Long;
43 43
44my $PROGNAME = "check_ifoperstatus"; 44my $PROGNAME = "check_ifoperstatus";
45sub print_help (); 45sub print_help ();
46sub usage (); 46sub usage ($);
47sub print_usage ();
47sub process_arguments (); 48sub process_arguments ();
48 49
49my $timeout; 50my $timeout;
50my $status; 51my $status;
51my %ifOperStatus = ('1','up', 52my %ifOperStatus = ('1','up',
52 '2','down', 53 '2','down',
53 '3','testing', 54 '3','testing',
54 '4','unknown', 55 '4','unknown',
55 '5','dormant', 56 '5','dormant',
56 '6','notPresent', 57 '6','notPresent',
57 '7','lowerLayerDown'); # down due to the state of lower layer interface(s) 58 '7','lowerLayerDown'); # down due to the state of lower layer interface(s)
58 59
59my $state = "UNKNOWN"; 60my $state = "UNKNOWN";
60my $answer = ""; 61my $answer = "";
@@ -96,7 +97,6 @@ my %session_opts;
96$status = process_arguments(); 97$status = process_arguments();
97 98
98 99
99use Data::Dumper;
100# Just in case of problems, let's not hang Nagios 100# Just in case of problems, let's not hang Nagios
101$SIG{'ALRM'} = sub { 101$SIG{'ALRM'} = sub {
102 print ("ERROR: No snmp response from $hostname (alarm)\n"); 102 print ("ERROR: No snmp response from $hostname (alarm)\n");
@@ -105,7 +105,6 @@ $SIG{'ALRM'} = sub {
105 105
106alarm($timeout); 106alarm($timeout);
107 107
108print Dumper(\%session_opts);
109($session, $error) = Net::SNMP->session(%session_opts); 108($session, $error) = Net::SNMP->session(%session_opts);
110 109
111 110
@@ -269,8 +268,13 @@ sub fetch_ifindex {
269 return $snmpkey; 268 return $snmpkey;
270} 269}
271 270
272sub usage() { 271sub usage($) {
273 printf "\nMissing arguments!\n"; 272 print "$_[0]\n";
273 print_usage();
274 exit $ERRORS{"UNKNOWN"};
275}
276
277sub print_usage() {
274 printf "\n"; 278 printf "\n";
275 printf "usage: \n"; 279 printf "usage: \n";
276 printf "check_ifoperstatus -k <IF_KEY> -H <HOSTNAME> [-C <community>]\n"; 280 printf "check_ifoperstatus -k <IF_KEY> -H <HOSTNAME> [-C <community>]\n";
@@ -279,10 +283,11 @@ sub usage() {
279 printf "This programm is licensed under the terms of the "; 283 printf "This programm is licensed under the terms of the ";
280 printf "GNU General Public License\n(check source code for details)\n"; 284 printf "GNU General Public License\n(check source code for details)\n";
281 printf "\n\n"; 285 printf "\n\n";
282 exit $ERRORS{"UNKNOWN"};
283} 286}
284 287
285sub print_help() { 288sub print_help() {
289 print_revision($PROGNAME, '@NP_VERSION@');
290 print_usage();
286 printf "check_ifoperstatus plugin for Nagios monitors operational \n"; 291 printf "check_ifoperstatus plugin for Nagios monitors operational \n";
287 printf "status of a particular network interface on the target host\n"; 292 printf "status of a particular network interface on the target host\n";
288 printf "\nUsage:\n"; 293 printf "\nUsage:\n";
@@ -323,7 +328,6 @@ sub print_help() {
323 printf "intensive. Use it sparingly or not at all. -n is used to match against\n"; 328 printf "intensive. Use it sparingly or not at all. -n is used to match against\n";
324 printf "a much more descriptive ifName value in the IfXTable to verify that the\n"; 329 printf "a much more descriptive ifName value in the IfXTable to verify that the\n";
325 printf "snmpkey has not changed to some other network interface after a reboot.\n\n"; 330 printf "snmpkey has not changed to some other network interface after a reboot.\n\n";
326 print_revision($PROGNAME, '@NP_VERSION@');
327 331
328} 332}
329 333
@@ -371,14 +375,11 @@ sub process_arguments() {
371 } 375 }
372 376
373 if (! utils::is_hostname($hostname)){ 377 if (! utils::is_hostname($hostname)){
374 usage(); 378 usage("Hostname invalid or not given");
375 exit $ERRORS{"UNKNOWN"};
376 } 379 }
377 380
378 unless ($snmpkey > 0 || defined $ifdescr || defined $iftype){ 381 unless ($snmpkey > 0 || defined $ifdescr || defined $iftype){
379 printf "Either a valid snmpkey key (-k) or a ifDescr (-d) must be provided)\n"; 382 usage("Either a valid snmpkey key (-k) or a ifDescr (-d) must be provided");
380 usage();
381 exit $ERRORS{"UNKNOWN"};
382 } 383 }
383 384
384 if (defined $name) { 385 if (defined $name) {
@@ -419,21 +420,18 @@ sub process_arguments() {
419 420
420 # Must define a security level even though defualt is noAuthNoPriv 421 # Must define a security level even though defualt is noAuthNoPriv
421 unless ( grep /^$seclevel$/, qw(noAuthNoPriv authNoPriv authPriv) ) { 422 unless ( grep /^$seclevel$/, qw(noAuthNoPriv authNoPriv authPriv) ) {
422 usage(); 423 usage("Must define a security level even though default is noAuthNoPriv");
423 exit $ERRORS{"UNKNOWN"};
424 } 424 }
425 425
426 # Authentication wanted 426 # Authentication wanted
427 if ( $seclevel eq 'authNoPriv' || $seclevel eq 'authPriv' ) { 427 if ( $seclevel eq 'authNoPriv' || $seclevel eq 'authPriv' ) {
428 unless ( $authproto eq 'MD5' || $authproto eq 'SHA1' ) { 428 if (defined $authproto && $authproto ne 'MD5' && $authproto ne 'SHA1') {
429 usage(); 429 usage("Auth protocol can be either MD5 or SHA1");
430 exit $ERRORS{"UNKNOWN"};
431 } 430 }
432 $session_opts{'-authprotocol'} = $authproto if(defined $authproto); 431 $session_opts{'-authprotocol'} = $authproto if(defined $authproto);
433 432
434 if ( !defined $authpass) { 433 if ( !defined $authpass) {
435 usage(); 434 usage("Auth password/key is not defined");
436 exit $ERRORS{"UNKNOWN"};
437 }else{ 435 }else{
438 if ($authpass =~ /^0x/ ) { 436 if ($authpass =~ /^0x/ ) {
439 $session_opts{'-authkey'} = $authpass ; 437 $session_opts{'-authkey'} = $authpass ;
@@ -446,8 +444,7 @@ sub process_arguments() {
446 # Privacy (DES encryption) wanted 444 # Privacy (DES encryption) wanted
447 if ($seclevel eq 'authPriv' ) { 445 if ($seclevel eq 'authPriv' ) {
448 if (! defined $privpass) { 446 if (! defined $privpass) {
449 usage(); 447 usage("Privacy passphrase/key is not defined");
450 exit $ERRORS{"UNKNOWN"};
451 }else{ 448 }else{
452 if ($privpass =~ /^0x/){ 449 if ($privpass =~ /^0x/){
453 $session_opts{'-privkey'} = $privpass; 450 $session_opts{'-privkey'} = $privpass;
@@ -465,8 +462,7 @@ sub process_arguments() {
465 } 462 }
466 463
467 }else { 464 }else {
468 usage(); 465 usage("Security level or name is not defined");
469 exit $ERRORS{'UNKNOWN'}; ;
470 } 466 }
471 } # end snmpv3 467 } # end snmpv3
472 468