Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. #!/usr/local/bin/perl -w
  2.  
  3. use strict;
  4. use warnings;
  5. use lib "/usr/local/nagios/libexec/";
  6. use Getopt::Long qw(:config no_ignore_case getopt_compat);
  7. use vars qw($opt_H $opt_s $opt_w $opt_c $opt_h $opt_d);
  8.  
  9. my $stateOK=0;
  10. my $stateWARNING=1;
  11. my $stateCRITICAL=2;
  12. my $stateUNKNOWN=3;
  13.  
  14. sub help () {
  15. print "\nUsage:\n";
  16. print " check_snmp_sensor -H <host> -s <service name> -w <warning threshold> -c <critical threshold> [-d]\n";
  17. print " check_snmp_sensor [-h | --help]\n";
  18. print "\nOptions:\n";
  19. print " -H, --host\n";
  20. print " The address of the host\n";
  21. print " -s, --sensorName\n";
  22. print " The ILOM sensor to check\n";
  23. print " -w, --warning\n";
  24. print " Warning threshold\n";
  25. print " -c, --critical\n";
  26. print " Critical threshold\n";
  27. print " -h, --help\n";
  28. print " Show this help screen\n";
  29. print " -d, --debug\n";
  30. print " Print debug output to help diagnose problems\n";
  31. }
  32.  
  33. if (!GetOptions
  34. (
  35. "H|host=s" => \$opt_H,
  36. "s|sensorName=s" => \$opt_s,
  37. "w|warning=i" => \$opt_w,
  38. "c|critical=i" => \$opt_c,
  39. "h|help" => \$opt_h,
  40. "d|debug" => \$opt_d,
  41. )
  42. )
  43. {
  44. print("Supply valid options - see plugin help\n");
  45. exit $stateUNKNOWN;
  46. }
  47.  
  48. if ($opt_h)
  49. {
  50. help();
  51. exit $stateUNKNOWN;
  52. }
  53.  
  54. if(!defined $opt_H ||
  55. !defined $opt_s ||
  56. !defined $opt_w ||
  57. !defined $opt_c)
  58. {
  59. help();
  60. exit $stateUNKNOWN;
  61. }
  62.  
  63. my $sensorIndex = `snmpwalk -v 2c -c public $opt_H .1.3.6.1.2.1.47.1.1.1.1.7 | grep \"$opt_s\" | sed -e 's/\\./ /g' | awk '{print \$8}' 2>&1`;
  64.  
  65. if ($opt_d)
  66. {
  67. print "Prechomped Sensor Index:(".$sensorIndex.")\n";
  68. }
  69. chomp($sensorIndex);
  70. if ($opt_d)
  71. {
  72. print "Sensor Index:(".$sensorIndex.")\n";
  73. }
  74.  
  75. if ($sensorIndex eq "")
  76. {
  77. print("Sensor ($opt_s) not found on host ($opt_H) - is SNMP v2c enabled?\n");
  78. exit $stateUNKNOWN;
  79. }
  80.  
  81. if ( $? == -1 )
  82. {
  83. print("command failed: $!\n");
  84. exit $stateUNKNOWN;
  85. }
  86. else
  87. {
  88. system("/usr/local/nagios/libexec/check_snmp -H $opt_H -o .1.3.6.1.4.1.42.2.70.101.1.1.8.1.4.$sensorIndex -C public -P 2c -w $opt_w -c $opt_c");
  89. my $sensorValueResult = $? >> 8;
  90.  
  91. if ($opt_d)
  92. {
  93. print "Sensor Return:(".$sensorValueResult.")\n";
  94. }
  95. if ( $? == -1 )
  96. {
  97. print("command failed: $!\n");
  98. exit $stateUNKNOWN;
  99. }
  100. else
  101. {
  102. exit $sensorValueResult;
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement